5b99f99bd22d1503addde35884d81ddf70e98d5e
[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 SubstitutionFilterDataDefinition substitutionFilter;
51     private List<InputDefinition> inputs;
52
53     public ComponentInstance() {
54         super();
55     }
56
57     public ComponentInstance(ComponentInstanceDataDefinition r) {
58         super(r);
59     }
60
61     public Map<String, ArtifactDefinition> safeGetDeploymentArtifacts() {
62         return deploymentArtifacts == null ? Collections.emptyMap() : deploymentArtifacts;
63     }
64
65     public Map<String, ArtifactDefinition> safeGetInformationalArtifacts() {
66         return artifacts == null ? Collections.emptyMap() : deploymentArtifacts;
67     }
68
69     public Map<String, ArtifactDefinition> safeGetArtifacts() {
70         return artifacts == null ? Collections.emptyMap() : artifacts;
71     }
72
73     public String getActualComponentUid() {
74         return getIsProxy() ? getSourceModelUid() : getComponentUid();
75     }
76
77     public boolean isArtifactExists(ArtifactGroupTypeEnum groupType, String artifactLabel) {
78         if (ArtifactGroupTypeEnum.DEPLOYMENT == groupType) {
79             return safeGetDeploymentArtifacts().get(artifactLabel) != null;
80         }
81         return safeGetInformationalArtifacts().get(artifactLabel) != null;
82     }
83
84     public void addInterface(String interfaceName, Object interfaceDefinition) {
85         if (MapUtils.isEmpty(this.interfaces)) {
86             this.interfaces = new HashMap<>();
87         }
88         this.interfaces.put(interfaceName, interfaceDefinition);
89     }
90
91     //supportability log method return map of component metadata teddy.h
92     public Map<String, String> getComponentMetadataForSupportLog() {
93         Map<String, String> componentMetadata = new HashMap<>();
94         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME, getName());
95         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION, getVersion());
96         componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID, getSourceModelUuid());
97         return componentMetadata;
98     }
99
100     public boolean isCreatedFromCsar() {
101         return CreatedFrom.CSAR.equals(this.getCreatedFrom());
102     }
103
104 }