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