re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / ProductMetadataData.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 com.google.gson.reflect.TypeToken;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.datatypes.elements.ProductMetadataDataDefinition;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27
28 import java.lang.reflect.Type;
29 import java.util.List;
30 import java.util.Map;
31
32 public class ProductMetadataData extends ComponentMetadataData {
33
34         public ProductMetadataData() {
35                 super(NodeTypeEnum.Product, new ProductMetadataDataDefinition());
36         }
37
38         public ProductMetadataData(ProductMetadataDataDefinition metadataDataDefinition) {
39                 super(NodeTypeEnum.Product, metadataDataDefinition);
40         }
41
42         public ProductMetadataData(Map<String, Object> properties) {
43                 super(NodeTypeEnum.Product, new ProductMetadataDataDefinition(), properties);
44                 ((ProductMetadataDataDefinition) metadataDataDefinition)
45                                 .setFullName((String) properties.get(GraphPropertiesDictionary.FULL_NAME.getProperty()));
46                 Type listType = new TypeToken<List<String>>() {
47                 }.getType();
48                 List<String> contactsfromJson = getGson()
49                                 .fromJson((String) properties.get(GraphPropertiesDictionary.CONTACTS.getProperty()), listType);
50                 ((ProductMetadataDataDefinition) metadataDataDefinition).setContacts(contactsfromJson);
51                 ((ProductMetadataDataDefinition) metadataDataDefinition)
52                                 .setIsActive((Boolean) properties.get(GraphPropertiesDictionary.IS_ACTIVE.getProperty()));
53         }
54
55         @Override
56         public String getUniqueIdKey() {
57                 return GraphPropertiesDictionary.UNIQUE_ID.getProperty();
58         }
59
60         @Override
61         public Map<String, Object> toGraphMap() {
62                 Map<String, Object> graphMap = super.toGraphMap();
63                 addIfExists(graphMap, GraphPropertiesDictionary.FULL_NAME,
64                                 ((ProductMetadataDataDefinition) metadataDataDefinition).getFullName());
65                 addIfExists(graphMap, GraphPropertiesDictionary.CONTACTS,
66                                 ((ProductMetadataDataDefinition) metadataDataDefinition).getContacts());
67                 addIfExists(graphMap, GraphPropertiesDictionary.IS_ACTIVE,
68                                 ((ProductMetadataDataDefinition) metadataDataDefinition).getIsActive());
69                 return graphMap;
70         }
71
72         @Override
73         public String toString() {
74                 return "ProductMetadataData [metadataDataDefinition=" + metadataDataDefinition + "]";
75         }
76 }