Initial OpenECOMP SDC commit
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / ResourceMetadataData.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 java.util.Map;
24
25 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
26 import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
27 import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
30
31 public class ResourceMetadataData extends ComponentMetadataData {
32
33         public ResourceMetadataData() {
34                 super(NodeTypeEnum.Resource, new ResourceMetadataDataDefinition());
35         }
36
37         public ResourceMetadataData(ComponentMetadataDataDefinition metadataDataDefinition) {
38                 super(NodeTypeEnum.Resource, metadataDataDefinition);
39         }
40
41         public ResourceMetadataData(Map<String, Object> properties) {
42                 super(NodeTypeEnum.Resource, new ResourceMetadataDataDefinition(), properties);
43                 ((ResourceMetadataDataDefinition) metadataDataDefinition)
44                                 .setVendorName((String) properties.get(GraphPropertiesDictionary.VENDOR_NAME.getProperty()));
45                 ((ResourceMetadataDataDefinition) metadataDataDefinition)
46                                 .setVendorRelease((String) properties.get(GraphPropertiesDictionary.VENDOR_RELEASE.getProperty()));
47                 ((ResourceMetadataDataDefinition) metadataDataDefinition).setResourceType(ResourceTypeEnum
48                                 .valueOf((String) properties.get(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty())));
49                 ((ResourceMetadataDataDefinition) metadataDataDefinition)
50                                 .setAbstract((Boolean) properties.get(GraphPropertiesDictionary.IS_ABSTRACT.getProperty()));
51                 ((ResourceMetadataDataDefinition) metadataDataDefinition)
52                                 .setCost((String) properties.get(GraphPropertiesDictionary.COST.getProperty()));
53                 ((ResourceMetadataDataDefinition) metadataDataDefinition)
54                                 .setLicenseType((String) properties.get(GraphPropertiesDictionary.LICENSE_TYPE.getProperty()));
55                 ((ResourceMetadataDataDefinition) metadataDataDefinition).setToscaResourceName(
56                                 (String) properties.get(GraphPropertiesDictionary.TOSCA_RESOURCE_NAME.getProperty()));
57
58         }
59
60         @Override
61         public Map<String, Object> toGraphMap() {
62                 Map<String, Object> graphMap = super.toGraphMap();
63                 addIfExists(graphMap, GraphPropertiesDictionary.VENDOR_NAME,
64                                 ((ResourceMetadataDataDefinition) metadataDataDefinition).getVendorName());
65                 addIfExists(graphMap, GraphPropertiesDictionary.VENDOR_RELEASE,
66                                 ((ResourceMetadataDataDefinition) metadataDataDefinition).getVendorRelease());
67                 addIfExists(graphMap, GraphPropertiesDictionary.RESOURCE_TYPE,
68                                 ((ResourceMetadataDataDefinition) metadataDataDefinition).getResourceType().name());
69                 addIfExists(graphMap, GraphPropertiesDictionary.IS_ABSTRACT,
70                                 ((ResourceMetadataDataDefinition) metadataDataDefinition).isAbstract());
71                 addIfExists(graphMap, GraphPropertiesDictionary.COST,
72                                 ((ResourceMetadataDataDefinition) metadataDataDefinition).getCost());
73                 addIfExists(graphMap, GraphPropertiesDictionary.LICENSE_TYPE,
74                                 ((ResourceMetadataDataDefinition) metadataDataDefinition).getLicenseType());
75                 addIfExists(graphMap, GraphPropertiesDictionary.TOSCA_RESOURCE_NAME,
76                                 ((ResourceMetadataDataDefinition) metadataDataDefinition).getToscaResourceName());
77                 return graphMap;
78         }
79
80 }