Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / PropertyDataDefinitionAbstractBuilder.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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.components.utils;
22
23 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
24 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
25 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
26
27 import java.util.ArrayList;
28
29 public abstract class PropertyDataDefinitionAbstractBuilder<B extends PropertyDataDefinition, T extends PropertyDataDefinitionAbstractBuilder<B, T>> {
30
31     B propertyDefinition;
32
33     protected abstract PropertyDataDefinitionAbstractBuilder<B, T> self();
34
35     abstract B propertyDefinition();
36
37     PropertyDataDefinitionAbstractBuilder() {
38         propertyDefinition = propertyDefinition();
39     }
40
41     public PropertyDataDefinitionAbstractBuilder<B, T> setUniqueId(String id) {
42         this.propertyDefinition.setUniqueId(id);
43         return self();
44     }
45
46     public PropertyDataDefinitionAbstractBuilder<B, T> setName(String name) {
47         this.propertyDefinition.setName(name);
48         return self();
49     }
50
51     public PropertyDataDefinitionAbstractBuilder<B, T> setValue(String value) {
52         this.propertyDefinition.setValue(value);
53         return self();
54     }
55
56     public PropertyDataDefinitionAbstractBuilder<B, T> setDefaultValue(String value) {
57         this.propertyDefinition.setDefaultValue(value);
58         return self();
59     }
60
61     public PropertyDataDefinitionAbstractBuilder<B, T> setType(String type) {
62         this.propertyDefinition.setType(type);
63         return self();
64     }
65
66     public PropertyDataDefinitionAbstractBuilder<B, T> setOwnerId(String ownerId) {
67         this.propertyDefinition.setOwnerId(ownerId);
68         return self();
69     }
70
71     public PropertyDataDefinitionAbstractBuilder<B, T> setSchemaType(String type) {
72         if (propertyDefinition.getSchema() == null) {
73             propertyDefinition.setSchema(new SchemaDefinition());
74         }
75         if (propertyDefinition.getSchema().getProperty() == null) {
76             propertyDefinition.getSchema().setProperty(new PropertyDataDefinition());
77         }
78         propertyDefinition.getSchema().getProperty().setType(type);
79         return self();
80     }
81
82     public PropertyDataDefinitionAbstractBuilder<B, T> addGetInputValue(String inputName) {
83         GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
84         getInputValueDataDefinition.setInputName(inputName);
85         getInputValueDataDefinition.setInputId(inputName);
86         if (propertyDefinition.getGetInputValues() == null) {
87             propertyDefinition.setGetInputValues(new ArrayList<>());
88         }
89         propertyDefinition.getGetInputValues().add(getInputValueDataDefinition);
90         return self();
91     }
92
93     public PropertyDataDefinitionAbstractBuilder<B, T> setIsRequired(boolean required) {
94         this.propertyDefinition.setRequired(required);
95         return self();
96     }
97
98     public PropertyDataDefinitionAbstractBuilder<B, T> setDescription(String description) {
99         this.propertyDefinition.setDescription(description);
100         return self();
101     }
102
103     public PropertyDataDefinitionAbstractBuilder<B, T> setIsPassword(boolean isPassword) {
104         this.propertyDefinition.setRequired(isPassword);
105         return self();
106     }
107
108     public PropertyDataDefinitionAbstractBuilder<B, T> setStatus(String status) {
109         this.propertyDefinition.setStatus(status);
110         return self();
111     }
112
113     public abstract B build();
114 }