[SDC] rebase 1710 code
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / GroupDefinition.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.io.Serializable;
24 import java.util.List;
25 import java.util.stream.Collectors;
26
27 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
28 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
29
30 public class GroupDefinition extends GroupDataDefinition implements Serializable {
31         /**
32          * 
33          */
34         private static final long serialVersionUID = -852613634651112247L;
35
36         // properties (properties should be defined in the group type, the
37         // properties here are actually the value for the properties)
38         
39
40
41
42         // The unique id of the type of this group
43
44
45         public GroupDefinition() {
46                 super();
47         }
48
49         public GroupDefinition(GroupDataDefinition other) {
50                 super(other);
51         }
52
53         public GroupDefinition(GroupDefinition other) {
54                 this.setName(other.getName());
55                 this.setUniqueId(other.getUniqueId());
56                 this.setType(other.getType());
57                 this.setVersion(other.getVersion());
58                 this.setInvariantUUID(other.getInvariantUUID());
59                 this.setGroupUUID(other.getGroupUUID());
60                 this.setDescription(other.getDescription());
61                 this.setTypeUid(other.getTypeUid());
62                 this.setProperties(other.getProperties());
63                 
64         }
65
66         public List<GroupProperty> convertToGroupProperties() {
67                 List<GroupProperty> properties = null;
68                 List<PropertyDataDefinition> propList = super.getProperties();
69                 if(propList != null && !propList .isEmpty()){
70                          properties = propList.stream().map(pr -> new GroupProperty(pr)).collect(Collectors.toList());
71                 }
72                 return properties;
73         }
74
75         public void convertFromGroupProperties(List<GroupProperty> properties) {
76                 if(properties != null && !properties .isEmpty()){
77                         List<PropertyDataDefinition> propList = properties.stream().map(pr -> new PropertyDataDefinition(pr)).collect(Collectors.toList());
78                         super.setProperties(propList);
79                 }
80                 
81         }
82
83         //returns true iff groupName has the same prefix has the resource
84         public boolean isSamePrefix(String resourceName){
85                 String name = this.getName();
86                 if ( name != null  && name.toLowerCase().trim().startsWith(resourceName.toLowerCase()))
87                         return true;
88                 return false;
89         }
90
91 }