1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
package org.openecomp.sdc.be.datamodel.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.be.ui.model.UiComponentMetadata;
import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer;
import org.openecomp.sdc.be.ui.model.UiResourceMetadata;
import org.openecomp.sdc.be.ui.model.UiServiceDataTransfer;
import org.openecomp.sdc.be.ui.model.UiServiceMetadata;
public class UiComponentDataConverter {
public static void setUiTranferDataByFieldName(UiComponentDataTransfer dataTransfer, Component component, String fieldName) {
switch (ComponentFieldsEnum.findByValue(fieldName)) {
case INPUTS:
if(component.getInputs() == null){
dataTransfer.setInputs(new ArrayList<>());
} else {
dataTransfer.setInputs(component.getInputs());
}
break;
case COMPONENT_INSTANCE_RELATION:
if(component.getComponentInstancesRelations() == null){
dataTransfer.setComponentInstancesRelations(new ArrayList<>());
} else {
dataTransfer.setComponentInstancesRelations(component.getComponentInstancesRelations());
}
break;
case GROUPS:
if(component.getGroups() == null){
dataTransfer.setGroups(new ArrayList<>());
} else {
dataTransfer.setGroups(component.getGroups());
}
break;
case COMPONENT_INSTANCES:
if(component.getComponentInstances() == null) {
dataTransfer.setComponentInstances(new ArrayList<>());
} else {
dataTransfer.setComponentInstances(component.getComponentInstances());
}
break;
case COMPONENT_INSTANCES_PROPERTIES:
if(component.getComponentInstancesProperties() == null) {
dataTransfer.setComponentInstancesProperties(new HashMap<>());
} else {
dataTransfer.setComponentInstancesProperties(component.getComponentInstancesProperties());
}
break;
case CAPABILITIES:
if(component.getCapabilities() == null) {
dataTransfer.setCapabilities(new HashMap<>());
} else {
dataTransfer.setCapabilities(component.getCapabilities());
}
break;
case REQUIREMENTS:
if(component.getRequirements() == null) {
dataTransfer.setRequirements(new HashMap<>());
} else {
dataTransfer.setRequirements(component.getRequirements());
}
break;
case DEPLOYMENT_ARTIFACTS:
if(component.getDeploymentArtifacts() == null) {
dataTransfer.setDeploymentArtifacts(new HashMap<>());
} else {
dataTransfer.setDeploymentArtifacts(component.getDeploymentArtifacts());
}
break;
case TOSCA_ARTIFACTS:
if(component.getToscaArtifacts() == null) {
dataTransfer.setToscaArtifacts(new HashMap<>());
} else {
dataTransfer.setToscaArtifacts(component.getToscaArtifacts());
}
break;
case ARTIFACTS:
if(component.getArtifacts() == null) {
dataTransfer.setArtifacts(new HashMap<>());
} else {
dataTransfer.setArtifacts(component.getArtifacts());
}
break;
case COMPONENT_INSTANCES_ATTRIBUTES:
if(component.getComponentInstancesAttributes() == null) {
dataTransfer.setComponentInstancesAttributes(new HashMap<>());
} else {
dataTransfer.setComponentInstancesAttributes(component.getComponentInstancesAttributes());
}
break;
case COMPONENT_INSTANCE_INPUTS:
if(component.getComponentInstancesInputs() == null) {
dataTransfer.setComponentInstancesInputs(new HashMap<>());
} else {
dataTransfer.setComponentInstancesInputs(component.getComponentInstancesInputs());
}
break;
default:
break;
}
}
public static UiComponentDataTransfer getUiDataTransferFromResourceByParams(Resource resource, List<String> paramsToReturn) {
UiResourceDataTransfer dataTransfer = new UiResourceDataTransfer();
for(String fieldName: paramsToReturn){
switch (ComponentFieldsEnum.findByValue(fieldName)) {
case PROPERTIES:
if(resource.getProperties() == null) {
dataTransfer.setProperties(new ArrayList<>());
} else {
dataTransfer.setProperties(resource.getProperties());
}
break;
case INTERFACES:
if(resource.getInterfaces() == null) {
dataTransfer.setInterfaces(new HashMap<>());
} else {
dataTransfer.setInterfaces(resource.getInterfaces());
}
break;
case DERIVED_FROM:
if(resource.getDerivedFrom() == null) {
dataTransfer.setDerivedFrom(new ArrayList<>());
} else {
dataTransfer.setDerivedFrom(resource.getDerivedFrom());
}
break;
case ATTRIBUTES:
if(resource.getAttributes() == null) {
dataTransfer.setAttributes(new ArrayList<>());
} else {
dataTransfer.setAttributes(resource.getAttributes());
}
break;
case ADDITIONAL_INFORMATION:
if(resource.getAdditionalInformation() == null) {
dataTransfer.setAdditionalInformation(new ArrayList<>());
} else {
dataTransfer.setAdditionalInformation(resource.getAdditionalInformation());
}
break;
case METADATA:
UiResourceMetadata metadata = new UiResourceMetadata(resource.getCategories(), resource.getDerivedFrom(), (ResourceMetadataDataDefinition) resource.getComponentMetadataDefinition().getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
break;
default:
setUiTranferDataByFieldName(dataTransfer, resource, fieldName);
}
}
return dataTransfer;
}
public static UiComponentDataTransfer getUiDataTransferFromServiceByParams(Service service, List<String> paramsToReturn) {
UiServiceDataTransfer dataTransfer = new UiServiceDataTransfer();
for(String fieldName: paramsToReturn){
switch (ComponentFieldsEnum.findByValue(fieldName)) {
case SERVICE_API_ARTIFACTS:
if(service.getServiceApiArtifacts() == null) {
dataTransfer.setServiceApiArtifacts(new HashMap<>());
} else {
dataTransfer.setServiceApiArtifacts(service.getServiceApiArtifacts());
}
break;
case METADATA:
UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(), (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition().getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
break;
default:
setUiTranferDataByFieldName(dataTransfer, service, fieldName);
}
}
return dataTransfer;
}
public static UiComponentMetadata convertToUiComponentMetadata(Component component) {
UiComponentMetadata uiComponentMetadata = null;
switch (component.getComponentType()) {
case RESOURCE:
Resource resource = (Resource)component;
uiComponentMetadata = new UiResourceMetadata(component.getCategories(), resource.getDerivedFrom(), (ResourceMetadataDataDefinition) resource.getComponentMetadataDefinition().getMetadataDataDefinition());
break;
case SERVICE:
uiComponentMetadata = new UiServiceMetadata(component.getCategories(), (ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition());
default:
}
return uiComponentMetadata;
}
}
|