2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.components.utils;
23 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
24 import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
25 import org.openecomp.sdc.be.model.GroupDefinition;
26 import org.openecomp.sdc.be.model.PropertyDefinition;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
33 public class GroupDefinitionBuilder {
34 private GroupDefinition groupDefinition;
36 private GroupDefinitionBuilder() {
37 this.groupDefinition = new GroupDefinition();
40 public static GroupDefinitionBuilder create() {
41 return new GroupDefinitionBuilder();
44 public GroupDefinitionBuilder setUniqueId(String uid) {
45 groupDefinition.setUniqueId(uid);
49 public GroupDefinitionBuilder setType(String type) {
50 groupDefinition.setType(type);
54 public GroupDefinition build() {
55 return groupDefinition;
58 public GroupDefinitionBuilder addMember(String name, String memberId) {
59 Map<String, String> groupMembers = getGroupMembers();
60 groupMembers.put(name, memberId);
64 public GroupDefinitionBuilder addMember(String memberId) {
65 Map<String, String> members = getGroupMembers();
66 members.put(memberId + "name", memberId);
70 private Map<String, String> getGroupMembers() {
71 Map<String, String> members = groupDefinition.getMembers();
72 if (members == null) {
73 members = new HashMap<>();
74 groupDefinition.setMembers(members);
79 public GroupDefinitionBuilder setInvariantName(String name) {
80 groupDefinition.setInvariantName(name);
84 public GroupDefinitionBuilder setInvariantUUID(String invariantUUID) {
85 groupDefinition.setInvariantUUID(invariantUUID);
89 public GroupDefinitionBuilder setGroupUUID(String groupUUID) {
90 groupDefinition.setGroupUUID(groupUUID);
94 public GroupDefinitionBuilder setName(String name) {
95 groupDefinition.setName(name);
99 public GroupDefinitionBuilder setVersion(String version) {
100 groupDefinition.setVersion(version);
104 public GroupDefinitionBuilder setCreatedFrom(CreatedFrom createdfrom) {
105 groupDefinition.setCreatedFrom(createdfrom);
109 public GroupDefinitionBuilder addProperty(String propertyName) {
110 List<PropertyDataDefinition> grpProps = getGroupProperties();
111 PropertyDefinition prop = new PropertyDataDefinitionBuilder()
112 .setName(propertyName)
118 private List<PropertyDataDefinition> getGroupProperties() {
119 List<PropertyDataDefinition> grpProps = groupDefinition.getProperties();
120 if (grpProps == null) {
121 grpProps = new ArrayList<>();
122 groupDefinition.setProperties(grpProps);