Catalog alignment
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / ComponentMetadataData.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.resources.data;
22
23 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor;
26 import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
28
29 import java.util.HashMap;
30 import java.util.Map;
31
32 public abstract class ComponentMetadataData extends GraphNode {
33
34         protected ComponentMetadataDataDefinition metadataDataDefinition;
35         protected Integer componentInstanceCounter;
36
37         public ComponentMetadataData(NodeTypeEnum label, ComponentMetadataDataDefinition metadataDataDefinition) {
38                 super(label);
39                 this.metadataDataDefinition = metadataDataDefinition;
40                 this.componentInstanceCounter = 0;
41         }
42
43         public ComponentMetadataData(NodeTypeEnum label, ComponentMetadataDataDefinition metadataDataDefinition, GraphPropertiesDictionaryExtractor extractor) {
44                 this(label, metadataDataDefinition);
45                 metadataDataDefinition.setUniqueId(extractor.getUniqueId());
46                 metadataDataDefinition.setCreationDate(extractor.getCreationDate());
47                 metadataDataDefinition.setDescription(extractor.getDescription());
48                 metadataDataDefinition.setConformanceLevel(extractor.getConformanceLevel());
49                 metadataDataDefinition.setIcon(extractor.getIcon());
50                 metadataDataDefinition.setHighestVersion(extractor.isHighestVersion());
51                 metadataDataDefinition.setLastUpdateDate(extractor.getLastUpdateDate());
52                 metadataDataDefinition.setName(extractor.getName());
53                 metadataDataDefinition.setState(extractor.getState());
54                 metadataDataDefinition.setTags(extractor.getTags());
55                 metadataDataDefinition.setVersion(extractor.getVersion());
56                 metadataDataDefinition.setContactId(extractor.getContactId());
57                 metadataDataDefinition.setUUID(extractor.getUUID());
58                 metadataDataDefinition.setNormalizedName(extractor.getNormalizedName());
59                 metadataDataDefinition.setSystemName(extractor.getSystemName());
60                 metadataDataDefinition.setIsDeleted(extractor.isDeleted());
61                 metadataDataDefinition.setProjectCode(extractor.getProjectCode());
62                 metadataDataDefinition.setCsarUUID(extractor.getCsarUuid());
63                 metadataDataDefinition.setCsarVersion(extractor.getCsarVersion());
64                 metadataDataDefinition.setImportedToscaChecksum(extractor.getImportedToscaChecksum());
65                 metadataDataDefinition.setInvariantUUID(extractor.getInvariantUuid());
66                 componentInstanceCounter = extractor.getInstanceCounter();
67         }
68
69         @Override
70         public Map<String, Object> toGraphMap() {
71                 Map<String, Object> map = new HashMap<>();
72
73                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, metadataDataDefinition.getUniqueId());
74                 addIfExists(map, GraphPropertiesDictionary.VERSION, metadataDataDefinition.getVersion());
75                 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, metadataDataDefinition.getCreationDate());
76                 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, metadataDataDefinition.getDescription());
77                 addIfExists(map, GraphPropertiesDictionary.CONFORMANCE_LEVEL, metadataDataDefinition.getConformanceLevel());
78                 addIfExists(map, GraphPropertiesDictionary.ICON, metadataDataDefinition.getIcon());
79                 addIfExists(map, GraphPropertiesDictionary.IS_HIGHEST_VERSION, metadataDataDefinition.isHighestVersion());
80                 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, metadataDataDefinition.getLastUpdateDate());
81                 addIfExists(map, GraphPropertiesDictionary.STATE, metadataDataDefinition.getState());
82                 addIfExists(map, GraphPropertiesDictionary.TAGS, metadataDataDefinition.getTags());
83                 addIfExists(map, GraphPropertiesDictionary.CONTACT_ID, metadataDataDefinition.getContactId());
84                 addIfExists(map, GraphPropertiesDictionary.NAME, metadataDataDefinition.getName());
85                 addIfExists(map, GraphPropertiesDictionary.UUID, metadataDataDefinition.getUUID());
86                 addIfExists(map, GraphPropertiesDictionary.NORMALIZED_NAME, metadataDataDefinition.getNormalizedName());
87                 addIfExists(map, GraphPropertiesDictionary.SYSTEM_NAME, metadataDataDefinition.getSystemName());
88                 addIfExists(map, GraphPropertiesDictionary.IS_DELETED, metadataDataDefinition.isDeleted());
89                 addIfExists(map, GraphPropertiesDictionary.INSTANCE_COUNTER, componentInstanceCounter);
90                 addIfExists(map, GraphPropertiesDictionary.PROJECT_CODE, metadataDataDefinition.getProjectCode());
91                 addIfExists(map, GraphPropertiesDictionary.CSAR_UUID, metadataDataDefinition.getCsarUUID());
92                 addIfExists(map, GraphPropertiesDictionary.CSAR_VERSION, metadataDataDefinition.getCsarVersion());
93                 addIfExists(map, GraphPropertiesDictionary.IMPORTED_TOSCA_CHECKSUM, metadataDataDefinition.getImportedToscaChecksum());
94                 addIfExists(map, GraphPropertiesDictionary.INVARIANT_UUID, metadataDataDefinition.getInvariantUUID());
95                 return map;
96         }
97
98         @Override
99         public String getUniqueId() {
100                 return metadataDataDefinition.getUniqueId();
101         }
102
103         public ComponentMetadataDataDefinition getMetadataDataDefinition() {
104                 return metadataDataDefinition;
105         }
106
107         public void setMetadataDataDefinition(ComponentMetadataDataDefinition metadataDataDefinition) {
108                 this.metadataDataDefinition = metadataDataDefinition;
109         }
110
111         public Integer getComponentInstanceCounter() {
112                 return componentInstanceCounter;
113         }
114
115         public void setComponentInstanceCounter(Integer componentInstanceCounter) {
116                 this.componentInstanceCounter = componentInstanceCounter;
117         }
118
119         public Integer increaseAndGetComponentInstanceCounter() {
120                 return ++componentInstanceCounter;
121         }
122
123         @Override
124         public String toString() {
125                 return "ComponentMetadataData [metadataDataDefinition=" + metadataDataDefinition + ", componentInstanceCounter=" + componentInstanceCounter + "]";
126         }
127
128 }