2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.sdc.tosca.parser.elements;
23 import org.onap.sdc.tosca.parser.api.IEntityDetails;
24 import org.onap.sdc.tosca.parser.enums.EntityTemplateType;
25 import org.onap.sdc.tosca.parser.enums.SdcTypes;
26 import org.onap.sdc.toscaparser.api.*;
27 import org.onap.sdc.toscaparser.api.parameters.Input;
29 import java.util.Collections;
30 import java.util.List;
33 import static java.util.stream.Collectors.toList;
35 public abstract class EntityDetails implements IEntityDetails {
37 private final EntityTemplate entityTemplate;
38 private final IEntityDetails parentNodeTemplate;
39 private static final String TYPE = "type";
41 EntityDetails(EntityTemplate entityTemplate) {
42 this.entityTemplate = entityTemplate;
43 this.parentNodeTemplate = EntityDetailsFactory.createEntityDetails(EntityTemplateType.NODE_TEMPLATE, entityTemplate.getParentNodeTemplate());
47 public String getName() {
48 return entityTemplate.getName();
51 EntityTemplate getEntityTemplate() {
52 return entityTemplate;
56 public Map<String, Property> getProperties() {
57 return entityTemplate.getProperties();
61 public List<IEntityDetails> getMemberNodes() {
62 return Collections.emptyList();
66 public IEntityDetails getParent() {
67 return parentNodeTemplate;
71 public List<RequirementAssignment> getRequirements() {
72 return entityTemplate.getRequirements()
77 public List<CapabilityAssignment> getCapabilities() {
78 return entityTemplate.getCapabilities()
83 public List<String> getTargets() {
84 return Collections.emptyList();
88 public List<IEntityDetails> getTargetEntities() {
89 return Collections.emptyList();
93 public String getPath() {
94 StringBuilder pathBld = new StringBuilder("");
95 EntityTemplate currentEntityParent = entityTemplate.getParentNodeTemplate();
97 while (currentEntityParent != null) {
98 if (pathBld.length() != 0) {
99 pathBld.insert(0,"#");
101 pathBld.insert(0, currentEntityParent.getName());
102 currentEntityParent = currentEntityParent.getParentNodeTemplate();
104 return pathBld.toString();
108 public String getToscaType() {
109 return entityTemplate.getType();
113 public List<String> getMembers()
114 { return Collections.emptyList(); }
117 public List<Input> getInputs(){
118 return Collections.emptyList();
122 public List<IEntityDetails> getMemberNodesCVFCWithVFC() {
123 return getMemberNodes().stream()
124 .filter(m -> SdcTypes.CVFC.getValue().equals(m.getMetadata().getValue(TYPE)))
125 .filter(this::isCvfcsWithVfc)
130 private boolean isCvfcsWithVfc(IEntityDetails member) {
131 List<NodeTemplate> children =((NodeTemplate) ((NodeTemplateEntityDetails)member).getEntityTemplate())
132 .getSubMappingToscaTemplate().getNodeTemplates();
133 List<NodeTemplate> vfcChildren = children.stream()
134 .filter(c -> SdcTypes.VFC.getValue().equals(c.getMetadata().getValue(TYPE)))
136 return !vfcChildren.isEmpty();