Catalog alignment
[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 org.apache.commons.collections.MapUtils;
24 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
25 import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
26 import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
27 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
28 import org.openecomp.sdc.common.log.api.ILogConfiguration;
29 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
30
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36 public class ComponentInstance extends ComponentInstanceDataDefinition implements PropertiesOwner{
37
38     private Map<String, List<CapabilityDefinition>> capabilities;
39     private Map<String, List<RequirementDefinition>> requirements;
40     private Map<String, ArtifactDefinition> deploymentArtifacts;
41     private Map<String, ArtifactDefinition> artifacts;
42     private List<GroupInstance> groupInstances;
43     private Map<String, Object> interfaces;
44     private List<PropertyDefinition> properties;
45     private CINodeFilterDataDefinition nodeFilter;
46     private List<InputDefinition> inputs;
47
48     public ComponentInstance() {
49         super();
50     }
51
52     public ComponentInstance(ComponentInstanceDataDefinition r) {
53         super(r);
54     }
55
56     public Map<String, List<CapabilityDefinition>> getCapabilities() {
57         return capabilities;
58     }
59
60     public void setCapabilities(Map<String, List<CapabilityDefinition>> capabilities) {
61         this.capabilities = capabilities;
62     }
63
64     public Map<String, List<RequirementDefinition>> getRequirements() {
65         return requirements;
66     }
67
68     public void setRequirements(Map<String, List<RequirementDefinition>> requirements) {
69         this.requirements = requirements;
70     }
71
72     public Map<String, ArtifactDefinition> getDeploymentArtifacts() {
73         return deploymentArtifacts;
74     }
75
76     public Map<String, ArtifactDefinition> safeGetDeploymentArtifacts() {
77         return deploymentArtifacts == null ? Collections.emptyMap() : deploymentArtifacts;
78     }
79
80     public Map<String, ArtifactDefinition> safeGetInformationalArtifacts() {
81         return artifacts == null ? Collections.emptyMap() : deploymentArtifacts;
82     }
83
84     public void setDeploymentArtifacts(Map<String, ArtifactDefinition> deploymentArtifacts) {
85         this.deploymentArtifacts = deploymentArtifacts;
86     }
87
88     public Map<String, ArtifactDefinition> getArtifacts() {
89         return artifacts;
90     }
91
92     public Map<String, ArtifactDefinition> safeGetArtifacts() {
93         return artifacts == null ? Collections.emptyMap() : artifacts;
94     }
95
96     public void setArtifacts(Map<String, ArtifactDefinition> artifacts) {
97         this.artifacts = artifacts;
98     }
99
100     public List<GroupInstance> getGroupInstances() {
101         return groupInstances;
102     }
103
104     public void setGroupInstances(List<GroupInstance> groupInstances) {
105         this.groupInstances = groupInstances;
106     }
107
108     public String getActualComponentUid() {
109         return getIsProxy() ? getSourceModelUid() : getComponentUid();
110     }
111
112     public boolean isArtifactExists(ArtifactGroupTypeEnum groupType, String artifactLabel) {
113         if (ArtifactGroupTypeEnum.DEPLOYMENT == groupType) {
114             return safeGetDeploymentArtifacts().get(artifactLabel) != null;
115         }
116         return safeGetInformationalArtifacts().get(artifactLabel) != null;
117     }
118
119     public Map<String, Object> getInterfaces() {
120         return interfaces;
121     }
122
123     public void setInterfaces(Map<String, Object> interfaces) {
124         this.interfaces = interfaces;
125     }
126
127     public void addInterface(String interfaceName, Object interfaceDefinition) {
128         if(MapUtils.isEmpty(this.interfaces)) {
129             this.interfaces = new HashMap<>();
130         }
131
132         this.interfaces.put(interfaceName, interfaceDefinition);
133     }
134
135     public List<PropertyDefinition> getProperties() {
136         return properties;
137     }
138
139     public void setProperties(List<PropertyDefinition> properties) {
140         this.properties = properties;
141     }
142
143     public CINodeFilterDataDefinition getNodeFilter() {
144         return nodeFilter;
145     }
146
147     public void setNodeFilter(CINodeFilterDataDefinition nodeFilter) {
148         this.nodeFilter = nodeFilter;
149     }
150
151     //supportability log method return map of component metadata teddy.h
152     public Map<String,String> getComponentMetadataForSupportLog(){
153         Map<String,String>componentMetadata=new HashMap<>();
154         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME,getName());
155         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION,getVersion());
156         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID, getSourceModelUuid());
157         return componentMetadata;
158     }
159
160     public boolean isCreatedFromCsar(){
161         return CreatedFrom.CSAR.equals(this.getCreatedFrom());
162     }
163
164     public List<InputDefinition> getInputs() {
165         return inputs;
166     }
167
168     public void setInputs(List<InputDefinition> inputs) {
169         this.inputs = inputs;
170     }
171
172 }