fix GetEntity API method returning a map rather than a list
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / tosca / parser / elements / EntityDetails.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdc-tosca
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.tosca.parser.elements;
22
23 import org.onap.sdc.tosca.parser.api.IEntityDetails;
24 import org.onap.sdc.tosca.parser.enums.EntityTemplateType;
25 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
26 import org.onap.sdc.toscaparser.api.EntityTemplate;
27 import org.onap.sdc.toscaparser.api.Property;
28 import org.onap.sdc.toscaparser.api.RequirementAssignment;
29
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.stream.Collectors;
34
35 public abstract class EntityDetails implements IEntityDetails {
36
37     private final EntityTemplate entityTemplate;
38     private final IEntityDetails parentNodeTemplate;
39
40     EntityDetails(EntityTemplate entityTemplate) {
41         this.entityTemplate = entityTemplate;
42         this.parentNodeTemplate = EntityDetailsFactory.createEntityDetails(EntityTemplateType.NODE_TEMPLATE, entityTemplate.getParentNodeTemplate());
43     }
44
45     @Override
46     public String getName() {
47         return entityTemplate.getName();
48     }
49
50     EntityTemplate getEntityTemplate() {
51         return entityTemplate;
52     }
53
54     @Override
55     public Map<String, Property> getProperties() {
56         return entityTemplate.getProperties();
57     }
58
59     @Override
60     public List<IEntityDetails> getMemberNodes() {
61         return Collections.emptyList();
62     }
63
64     @Override
65     public IEntityDetails getParent() {
66         return parentNodeTemplate;
67     }
68
69     @Override
70     public List<RequirementAssignment> getRequirements() {
71         return entityTemplate.getRequirements()
72                 .getAll();
73     }
74
75     @Override
76     public List<CapabilityAssignment> getCapabilities() {
77         return entityTemplate.getCapabilities()
78                 .getAll();
79     }
80
81     @Override
82     public List<String> getTargets() {
83         return Collections.emptyList();
84     }
85
86     @Override
87     public List<IEntityDetails> getTargetEntities() {
88         return Collections.emptyList();
89     }
90
91     @Override
92     public String getPath() {
93         StringBuilder pathBld = new StringBuilder("");
94         EntityTemplate currentEntityParent = entityTemplate.getParentNodeTemplate();
95
96         while (currentEntityParent != null) {
97             if (pathBld.length() != 0) {
98                 pathBld.insert(0,"#");
99             }
100             pathBld.insert(0, currentEntityParent.getName());
101             currentEntityParent = currentEntityParent.getParentNodeTemplate();
102         }
103         return pathBld.toString();
104     }
105
106     @Override
107     public String getToscaType() {
108         return entityTemplate.getType();
109     }
110
111     @Override
112     public List<String> getMembers() { return Collections.emptyList(); }
113
114
115
116 }