re base code
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / PropertyDataDefinitionAbstractBuilder.java
1 package org.openecomp.sdc.be.components.utils;
2
3 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
4 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
5 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
6
7 import java.util.ArrayList;
8
9 public abstract class PropertyDataDefinitionAbstractBuilder<B extends PropertyDataDefinition, T extends PropertyDataDefinitionAbstractBuilder<B, T>> {
10
11     B propertyDefinition;
12
13     protected abstract PropertyDataDefinitionAbstractBuilder<B, T> self();
14
15     abstract B propertyDefinition();
16
17     PropertyDataDefinitionAbstractBuilder() {
18         propertyDefinition = propertyDefinition();
19     }
20
21     public PropertyDataDefinitionAbstractBuilder<B, T> setUniqueId(String id) {
22         this.propertyDefinition.setUniqueId(id);
23         return self();
24     }
25
26     public PropertyDataDefinitionAbstractBuilder<B, T> setName(String name) {
27         this.propertyDefinition.setName(name);
28         return self();
29     }
30
31     public PropertyDataDefinitionAbstractBuilder<B, T> setValue(String value) {
32         this.propertyDefinition.setValue(value);
33         return self();
34     }
35
36     public PropertyDataDefinitionAbstractBuilder<B, T> setDefaultValue(String value) {
37         this.propertyDefinition.setDefaultValue(value);
38         return self();
39     }
40
41     public PropertyDataDefinitionAbstractBuilder<B, T> setType(String type) {
42         this.propertyDefinition.setType(type);
43         return self();
44     }
45
46     public PropertyDataDefinitionAbstractBuilder<B, T> setOwnerId(String ownerId) {
47         this.propertyDefinition.setOwnerId(ownerId);
48         return self();
49     }
50
51     public PropertyDataDefinitionAbstractBuilder<B, T> setSchemaType(String type) {
52         if (propertyDefinition.getSchema() == null) {
53             propertyDefinition.setSchema(new SchemaDefinition());
54         }
55         if (propertyDefinition.getSchema().getProperty() == null) {
56             propertyDefinition.getSchema().setProperty(new PropertyDataDefinition());
57         }
58         propertyDefinition.getSchema().getProperty().setType(type);
59         return self();
60     }
61
62     public PropertyDataDefinitionAbstractBuilder<B, T> addGetInputValue(String inputName) {
63         GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
64         getInputValueDataDefinition.setInputName(inputName);
65         getInputValueDataDefinition.setInputId(inputName);
66         if (propertyDefinition.getGetInputValues() == null) {
67             propertyDefinition.setGetInputValues(new ArrayList<>());
68         }
69         propertyDefinition.getGetInputValues().add(getInputValueDataDefinition);
70         return self();
71     }
72
73     public PropertyDataDefinitionAbstractBuilder<B, T> setIsRequired(boolean required) {
74         this.propertyDefinition.setRequired(required);
75         return self();
76     }
77
78     public PropertyDataDefinitionAbstractBuilder<B, T> setDescription(String description) {
79         this.propertyDefinition.setDescription(description);
80         return self();
81     }
82
83     public PropertyDataDefinitionAbstractBuilder<B, T> setIsPassword(boolean isPassword) {
84         this.propertyDefinition.setRequired(isPassword);
85         return self();
86     }
87
88     public PropertyDataDefinitionAbstractBuilder<B, T> setStatus(String status) {
89         this.propertyDefinition.setStatus(status);
90         return self();
91     }
92
93     public abstract B build();
94 }