Fix for substitution filter properties
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / ComponentInstance.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.sdc.be.model;
22
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import lombok.Getter;
28 import lombok.Setter;
29 import org.apache.commons.collections.MapUtils;
30 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
31 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
32 import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
33 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
34 import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
35 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
36 import org.openecomp.sdc.common.log.api.ILogConfiguration;
37
38 @Getter
39 @Setter
40 public class ComponentInstance extends ComponentInstanceDataDefinition implements PropertiesOwner {
41
42     private Map<String, List<CapabilityDefinition>> capabilities;
43     private Map<String, List<RequirementDefinition>> requirements;
44     private Map<String, ArtifactDefinition> deploymentArtifacts;
45     private Map<String, ArtifactDefinition> artifacts;
46     private List<GroupInstance> groupInstances;
47     private Map<String, Object> interfaces;
48     private List<PropertyDefinition> properties;
49     private CINodeFilterDataDefinition nodeFilter;
50     private List<InputDefinition> inputs;
51
52     public ComponentInstance() {
53         super();
54     }
55
56     public ComponentInstance(ComponentInstanceDataDefinition r) {
57         super(r);
58     }
59
60     public Map<String, ArtifactDefinition> safeGetDeploymentArtifacts() {
61         return deploymentArtifacts == null ? Collections.emptyMap() : deploymentArtifacts;
62     }
63
64     public Map<String, ArtifactDefinition> safeGetInformationalArtifacts() {
65         return artifacts == null ? Collections.emptyMap() : deploymentArtifacts;
66     }
67
68     public Map<String, ArtifactDefinition> safeGetArtifacts() {
69         return artifacts == null ? Collections.emptyMap() : artifacts;
70     }
71
72     public String getActualComponentUid() {
73         return getIsProxy() ? getSourceModelUid() : getComponentUid();
74     }
75
76     public boolean isArtifactExists(ArtifactGroupTypeEnum groupType, String artifactLabel) {
77         if (ArtifactGroupTypeEnum.DEPLOYMENT == groupType) {
78             return safeGetDeploymentArtifacts().get(artifactLabel) != null;
79         }
80         return safeGetInformationalArtifacts().get(artifactLabel) != null;
81     }
82
83     public void addInterface(String interfaceName, Object interfaceDefinition) {
84         if (MapUtils.isEmpty(this.interfaces)) {
85             this.interfaces = new HashMap<>();
86         }
87         this.interfaces.put(interfaceName, interfaceDefinition);
88     }
89
90     //supportability log method return map of component metadata teddy.h
91     public Map<String, String> getComponentMetadataForSupportLog() {
92         Map<String, String> componentMetadata = new HashMap<>();
93         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME, getName());
94         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION, getVersion());
95         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID, getSourceModelUuid());
96         return componentMetadata;
97     }
98
99     public boolean isCreatedFromCsar() {
100         return CreatedFrom.CSAR.equals(this.getCreatedFrom());
101     }
102
103 }