[SDC] rebase 1710 code
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / ResponseParser.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.ci.tests.utils.rest;
22
23 import java.io.IOException;
24 import java.text.ParseException;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Optional;
32
33 import org.apache.commons.codec.binary.Base64;
34 import org.apache.log4j.Logger;
35 import org.codehaus.jackson.JsonParseException;
36 import org.codehaus.jackson.Version;
37 import org.codehaus.jackson.map.DeserializationConfig;
38 import org.codehaus.jackson.map.JsonDeserializer;
39 import org.codehaus.jackson.map.JsonMappingException;
40 import org.codehaus.jackson.map.ObjectMapper;
41 import org.codehaus.jackson.map.module.SimpleModule;
42 import org.json.JSONArray;
43 import org.json.JSONException;
44 import org.json.simple.JSONObject;
45 import org.json.simple.JSONValue;
46 import org.openecomp.sdc.be.model.ArtifactDefinition;
47 import org.openecomp.sdc.be.model.Component;
48 import org.openecomp.sdc.be.model.ComponentInstance;
49 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
50 import org.openecomp.sdc.be.model.Product;
51 import org.openecomp.sdc.be.model.PropertyConstraint;
52 import org.openecomp.sdc.be.model.Resource;
53 import org.openecomp.sdc.be.model.Service;
54 import org.openecomp.sdc.be.model.category.CategoryDefinition;
55 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserialiser;
56 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
57 import org.openecomp.sdc.ci.tests.datatypes.ResourceAssetStructure;
58 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
59 import org.openecomp.sdc.ci.tests.datatypes.ResourceRespJavaObject;
60 import org.openecomp.sdc.ci.tests.datatypes.ServiceDistributionStatus;
61 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
62 import org.openecomp.sdc.ci.tests.utils.Utils;
63 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
64
65 import com.fasterxml.jackson.databind.DeserializationFeature;
66 import com.google.gson.Gson;
67 import com.google.gson.JsonArray;
68 import com.google.gson.JsonElement;
69 import com.google.gson.JsonObject;
70 import com.google.gson.JsonParser;
71
72 public class ResponseParser {
73
74         // comment by Andrey, for test only
75         // public static void main(String[] args) {
76         // String response =
77         // "{\"uniqueId\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2\",\"resourceName\":\"importResource4test\",\"resourceVersion\":\"0.1\",\"creatorUserId\":\"jh0003\",\"creatorFullName\":\"Jimmy
78         // Hendrix\",\"lastUpdaterUserId\":\"jh0003\",\"lastUpdaterFullName\":\"Jimmy
79         // Hendrix\",\"creationDate\":1446742241514,\"lastUpdateDate\":1446742241514,\"description\":\"Represents
80         // a generic software component that can be managed and run by a Compute
81         // Node
82         // Type.\",\"icon\":\"defaulticon\",\"tags\":[\"importResource4test\"],\"category\":\"Generic/Infrastructure\",\"lifecycleState\":\"NOT_CERTIFIED_CHECKOUT\",\"derivedFrom\":[\"tosca.nodes.Root\"],\"artifacts\":{},\"deploymentArtifacts\":{},\"properties\":[{\"uniqueId\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2.port\",\"type\":\"integer\",\"required\":false,\"description\":\"the
83         // port the DBMS service will listen to for data and
84         // requests\",\"password\":false,\"name\":\"port\",\"parentUniqueId\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2\",\"definition\":true},{\"uniqueId\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2.root_password\",\"type\":\"string\",\"required\":false,\"description\":\"the
85         // optional root password for the DBMS
86         // service\",\"password\":false,\"name\":\"root_password\",\"parentUniqueId\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2\",\"definition\":true}],\"interfaces\":{\"standard\":{\"type\":\"tosca.interfaces.node.lifecycle.Standard\",\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard\",\"operations\":{\"stop\":{\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard.stop\",\"description\":\"Standard
87         // lifecycle stop
88         // operation.\",\"definition\":false},\"start\":{\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard.start\",\"description\":\"Standard
89         // lifecycle start
90         // operation.\",\"definition\":false},\"delete\":{\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard.delete\",\"description\":\"Standard
91         // lifecycle delete
92         // operation.\",\"definition\":false},\"create\":{\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard.create\",\"description\":\"Standard
93         // lifecycle create
94         // operation.\",\"definition\":false},\"configure\":{\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard.configure\",\"description\":\"Standard
95         // lifecycle configure
96         // operation.\",\"definition\":false}},\"definition\":false}},\"capabilities\":{\"feature\":{\"uniqueId\":\"capability.8313348e-3623-4f4a-9b8f-d2fbadaf9a31.feature\",\"type\":\"tosca.capabilities.Node\"},\"feature2\":{\"uniqueId\":\"capability.52eb0139-a855-47b9-a0e6-c90f0a90b1d2.feature2\",\"type\":\"tosca.capabilities.Node\"}},\"requirements\":{\"dependency\":{\"uniqueId\":\"8313348e-3623-4f4a-9b8f-d2fbadaf9a31.dependency\",\"capability\":\"tosca.capabilities.Node\",\"node\":\"tosca.nodes.Root\",\"relationship\":\"tosca.relationships.DependsOn\"},\"dependency2\":{\"uniqueId\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2.dependency2\",\"capability\":\"tosca.capabilities.Node\",\"node\":\"tosca.nodes.importResource4test\",\"relationship\":\"tosca.relationships.DependsOn\"}},\"vendorName\":\"ATT
97         // (Tosca)\",\"vendorRelease\":\"1.0.0.wd03\",\"contactId\":\"jh0003\",\"systemName\":\"Importresource4test\",\"additionalInformation\":[{\"uniqueId\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2.additionalinformation\",\"lastCreatedCounter\":0,\"parentUniqueId\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2\",\"parameters\":[]}],\"allVersions\":{\"0.1\":\"52eb0139-a855-47b9-a0e6-c90f0a90b1d2\"},\"abstract\":false,\"highestVersion\":true,\"uuid\":\"2e91a2df-b066-49bb-abde-4c1c01e409db\"}";
98         // convertResourceResponseToJavaObject(response);
99         // }
100
101         private static final String INVARIANT_UUID = "invariantUUID";
102         public static final String UNIQUE_ID = "uniqueId";
103         public static final String VERSION = "version";
104         public static final String UUID = "uuid";
105         public static final String NAME = "name";
106         public static final String ORIGIN_TYPE = "originType";
107         public static final String TOSCA_RESOURCE_NAME = "toscaResourceName";
108
109         static Logger logger = Logger.getLogger(ResponseParser.class.getName());
110
111         public static String getValueFromJsonResponse(String response, String fieldName) {
112                 try {
113                         JSONObject jsonResp = (JSONObject) JSONValue.parse(response);
114                         Object fieldValue = jsonResp.get(fieldName);
115                         return fieldValue.toString();
116
117                 } catch (Exception e) {
118                         return null;
119                 }
120
121         }
122
123         public static String getUniqueIdFromResponse(RestResponse response) {
124                 return getValueFromJsonResponse(response.getResponse(), UNIQUE_ID);
125         }
126
127         public static String getInvariantUuid(RestResponse response) {
128                 return getValueFromJsonResponse(response.getResponse(), INVARIANT_UUID);
129         }
130
131         public static String getUuidFromResponse(RestResponse response) {
132                 return getValueFromJsonResponse(response.getResponse(), UUID);
133         }
134
135         public static String getNameFromResponse(RestResponse response) {
136                 return getValueFromJsonResponse(response.getResponse(), NAME);
137         }
138
139         public static String getVersionFromResponse(RestResponse response) {
140                 return ResponseParser.getValueFromJsonResponse(response.getResponse(), VERSION);
141         }
142
143         public static String getComponentTypeFromResponse(RestResponse response) {
144                 return ResponseParser.getValueFromJsonResponse(response.getResponse(), ORIGIN_TYPE);
145         }
146
147         public static String getToscaResourceNameFromResponse(RestResponse response) {
148                 return getValueFromJsonResponse(response.getResponse(), TOSCA_RESOURCE_NAME);
149         }
150
151         @SuppressWarnings("unchecked")
152         public static ResourceRespJavaObject parseJsonListReturnResourceDetailsObj(RestResponse restResponse,
153                         String resourceType, String searchPattern, String expectedResult) throws Exception {
154
155                 // Gson gson = new Gson;
156
157                 JsonElement jElement = new JsonParser().parse(restResponse.getResponse());
158                 JsonObject jObject = jElement.getAsJsonObject();
159                 JsonArray arrayOfObjects = (JsonArray) jObject.get(resourceType);
160                 Gson gson = new Gson();
161                 Map<String, Object> map = new HashMap<String, Object>();
162                 ResourceRespJavaObject jsonToJavaObject = new ResourceRespJavaObject();
163
164                 for (int counter = 0; counter < arrayOfObjects.size(); counter++) {
165                         JsonObject jHitObject = (JsonObject) arrayOfObjects.get(counter);
166
167                         map = (Map<String, Object>) gson.fromJson(jHitObject.toString(), map.getClass());
168                         if (map.get(searchPattern).toString().contains(expectedResult)) {
169
170                                 jsonToJavaObject = gson.fromJson(jObject, ResourceRespJavaObject.class);
171                                 break;
172                         }
173                 }
174                 return jsonToJavaObject;
175
176         }
177
178         public static Resource convertResourceResponseToJavaObject(String response) {
179
180                 ObjectMapper mapper = new ObjectMapper();
181                 final SimpleModule module = new SimpleModule("customerSerializationModule",
182                                 new Version(1, 0, 0, "static version"));
183                 JsonDeserializer<PropertyConstraint> deserializer = new PropertyConstraintJacksonDeserialiser();
184                 addDeserializer(module, PropertyConstraint.class, deserializer);
185
186                 mapper.registerModule(module);
187                 Resource resource = null;
188                 try {
189 //                      TODO Andrey L. uncomment line below in case to ignore on unknown properties, not recommended  
190 //                      mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
191                         resource = mapper.readValue(response, Resource.class);
192                         
193                         logger.debug(resource.toString());
194                 } catch (IOException e) {
195                         try {
196                                 List<Resource> resources = Arrays.asList(mapper.readValue(response.toString(), Resource[].class));
197                                 resource = resources.get(0);
198                         } catch (Exception e1) {
199                                 // TODO Auto-generated catch block
200                                 e1.printStackTrace();
201                         }
202                 }
203
204                 return resource;
205         }
206
207         public static ComponentInstanceProperty convertPropertyResponseToJavaObject(String response) {
208
209                 ObjectMapper mapper = new ObjectMapper();
210                 final SimpleModule module = new SimpleModule("customerSerializationModule",
211                                 new Version(1, 0, 0, "static version"));
212                 JsonDeserializer<PropertyConstraint> desrializer = new PropertyConstraintJacksonDeserialiser();
213                 addDeserializer(module, PropertyConstraint.class, desrializer);
214
215                 mapper.registerModule(module);
216                 ComponentInstanceProperty propertyDefinition = null;
217                 try {
218                         propertyDefinition = mapper.readValue(response, ComponentInstanceProperty.class);
219                         logger.debug(propertyDefinition.toString());
220                 } catch (IOException e) {
221                         // TODO Auto-generated catch block
222                         e.printStackTrace();
223                 }
224                 return propertyDefinition;
225         }
226
227         public static String toJson(Object object) {
228                 Gson gson = new Gson();
229                 return gson.toJson(object);
230         }
231
232         public static ArtifactDefinition convertArtifactDefinitionResponseToJavaObject(String response) {
233                 ObjectMapper mapper = new ObjectMapper();
234                 ArtifactDefinition artifactDefinition = null;
235                 try {
236
237                         artifactDefinition = mapper.readValue(response, ArtifactDefinition.class);
238                         logger.debug(artifactDefinition.toString());
239                 } catch (IOException e) {
240                         // TODO Auto-generated catch block
241                         e.printStackTrace();
242                 }
243
244                 return artifactDefinition;
245
246         }
247
248         public static ArtifactReqDetails convertArtifactReqDetailsToJavaObject(String response) {
249
250                 ArtifactReqDetails artifactReqDetails = null;
251                 Gson gson = new Gson();
252                 artifactReqDetails = gson.fromJson(response, ArtifactReqDetails.class);
253                 return artifactReqDetails;
254         }
255
256         public static <T> T parseToObject(String json, Class<T> clazz) {
257                 Gson gson = new Gson();
258                 T object;
259                 try {
260                         object = gson.fromJson(json, clazz);
261                 } catch (Exception e) {
262                         object = parseToObjectUsingMapper(json, clazz);
263                 }
264                 return object;
265         }
266
267         public static <T> T parseToObjectUsingMapper(String json, Class<T> clazz) {
268                 // Generic convert
269                 ObjectMapper mapper = new ObjectMapper();
270                 T object = null;
271                 final SimpleModule module = new SimpleModule("customerSerializationModule",
272                                 new Version(1, 0, 0, "static version"));
273                 JsonDeserializer<PropertyConstraint> desrializer = new PropertyConstraintJacksonDeserialiser();
274                 addDeserializer(module, PropertyConstraint.class, desrializer);
275                 mapper.registerModule(module);
276                 try {
277                         object = mapper.readValue(json, clazz);
278                         // System.out.println("Class: "+clazz.getSimpleName()+", json:
279                         // "+json);
280                 } catch (IOException e) {
281                         // TODO Auto-generated catch block
282                         e.printStackTrace();
283                 }
284
285                 return object;
286         }
287
288         public static ArtifactReqDetails convertArtifactDefinitionToArtifactReqDetailsObject(
289                         ArtifactDefinition artifactDefinition) {
290
291                 ArtifactReqDetails artifactReqDetails = null;
292                 Gson gson = new Gson();
293                 String artDef = gson.toJson(artifactDefinition);
294                 artifactReqDetails = gson.fromJson(artDef, ArtifactReqDetails.class);
295                 return artifactReqDetails;
296         }
297
298         public static <T> void addDeserializer(SimpleModule module, Class<T> clazz,
299                         final JsonDeserializer<T> deserializer) {
300                 module.addDeserializer(clazz, deserializer);
301         }
302
303         public static Service convertServiceResponseToJavaObject(String response) {
304
305                 ObjectMapper mapper = new ObjectMapper();
306                 final SimpleModule module = new SimpleModule("customerSerializationModule",
307                                 new Version(1, 0, 0, "static version"));
308                 JsonDeserializer<PropertyConstraint> deserializer = new PropertyConstraintJacksonDeserialiser();
309                 addDeserializer(module, PropertyConstraint.class, deserializer);
310
311                 mapper.registerModule(module);
312                 Service service = null;
313                 try {
314                         service = mapper.readValue(response, Service.class);
315                         logger.debug(service.toString());
316                 } catch (IOException e) {
317                         // TODO Auto-generated catch block
318                         e.printStackTrace();
319                 }
320
321                 return service;
322         }
323
324         public static Product convertProductResponseToJavaObject(String response) {
325
326                 ObjectMapper mapper = new ObjectMapper();
327                 
328                 final SimpleModule module = new SimpleModule("customerSerializationModule",
329                                 new Version(1, 0, 0, "static version"));
330                 JsonDeserializer<PropertyConstraint> desrializer = new PropertyConstraintJacksonDeserialiser();
331                 addDeserializer(module, PropertyConstraint.class, desrializer);
332
333                 mapper.registerModule(module);
334                 
335                 Product product = null;
336                 try {
337                         product = mapper.readValue(response, Product.class);
338                         logger.debug(product.toString());
339                 } catch (IOException e) {
340                         // TODO Auto-generated catch block
341                         e.printStackTrace();
342                 }
343
344                 return product;
345         }
346
347         public static ComponentInstance convertComponentInstanceResponseToJavaObject(String response) {
348
349                 ObjectMapper mapper = new ObjectMapper();
350                 final SimpleModule module = new SimpleModule("customerSerializationModule",
351                                 new Version(1, 0, 0, "static version"));
352                 JsonDeserializer<PropertyConstraint> desrializer = new PropertyConstraintJacksonDeserialiser();
353                 addDeserializer(module, PropertyConstraint.class, desrializer);
354
355                 mapper.registerModule(module);
356                 ComponentInstance componentInstance = null;
357                 try {
358                         componentInstance = mapper.readValue(response, ComponentInstance.class);
359                         logger.debug(componentInstance.toString());
360                 } catch (IOException e) {
361                         // TODO Auto-generated catch block
362                         e.printStackTrace();
363                 }
364
365                 return componentInstance;
366         }
367
368         public static List<String> getValuesFromJsonArray(RestResponse message) throws Exception {
369                 List<String> artifactTypesArrayFromApi = new ArrayList<String>();
370
371                 org.json.JSONObject responseObject = new org.json.JSONObject(message.getResponse());
372                 JSONArray jArr = responseObject.getJSONArray("artifactTypes");
373
374                 for (int i = 0; i < jArr.length(); i++) {
375                         org.json.JSONObject jObj = jArr.getJSONObject(i);
376                         String value = jObj.get("name").toString();
377
378                         artifactTypesArrayFromApi.add(value);
379                 }
380                 return artifactTypesArrayFromApi;
381         }
382
383         public static String calculateMD5Header(ArtifactReqDetails artifactDetails) {
384                 Gson gson = new Gson();
385                 String jsonBody = gson.toJson(artifactDetails);
386                 // calculate MD5 for json body
387                 return calculateMD5(jsonBody);
388
389         }
390
391         public static String calculateMD5(String data) {
392                 String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data);
393                 // encode base-64 result
394                 byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes());
395                 String encodeBase64Str = new String(encodeBase64);
396                 return encodeBase64Str;
397
398         }
399
400         public static List<Map<String, Object>> getAuditFromMessage(Map auditingMessage) {
401                 List<Map<String, Object>> auditList = new ArrayList<Map<String, Object>>();
402                 // JsonElement jElement = new JsonParser().parse(auditingMessage);
403                 // JsonObject jObject = jElement.getAsJsonObject();
404                 // JsonObject hitsObject = (JsonObject) jObject.get("hits");
405                 // JsonArray hitsArray = (JsonArray) hitsObject.get("hits");
406                 //
407                 // Iterator<JsonElement> hitsIterator = hitsArray.iterator();
408                 // while(hitsIterator.hasNext())
409                 // {
410                 // JsonElement nextHit = hitsIterator.next();
411                 // JsonObject jHitObject = nextHit.getAsJsonObject();
412                 // JsonObject jSourceObject = (JsonObject) jHitObject.get("_source");
413                 //
414                 // Gson gson=new Gson();
415                 // String auditUnparsed = jSourceObject.toString();
416                 //
417                 // Map<String,Object> map = new HashMap<String,Object>();
418                 // map = (Map<String,Object>) gson.fromJson(auditUnparsed,
419                 // map.getClass());
420
421                 auditList.add(auditingMessage);
422                 // }
423                 return auditList;
424         }
425
426         public static List<CategoryDefinition> parseCategories(RestResponse getAllCategoriesRest) {
427
428                 List<CategoryDefinition> categories = new ArrayList<>();
429                 try {
430                         JsonElement jElement = new JsonParser().parse(getAllCategoriesRest.getResponse());
431                         JsonArray cagegories = jElement.getAsJsonArray();
432                         Iterator<JsonElement> iter = cagegories.iterator();
433                         while (iter.hasNext()) {
434                                 JsonElement next = iter.next();
435                                 CategoryDefinition category = ResponseParser.parseToObject(next.toString(), CategoryDefinition.class);
436                                 categories.add(category);
437                         }
438
439                 } catch (Exception e) {
440                         e.printStackTrace();
441                 }
442
443                 return categories;
444         }
445
446         public static JSONArray getListFromJson(RestResponse res, String field) throws JSONException {
447                 String valueFromJsonResponse = getValueFromJsonResponse(res.getResponse(), field);
448                 JSONArray jArr = new JSONArray(valueFromJsonResponse);
449
450                 return jArr;
451         }
452
453         public static List<String> getDerivedListFromJson(RestResponse res) throws JSONException {
454                 JSONArray listFromJson = getListFromJson(res, "derivedList");
455                 List<String> lst = new ArrayList<String>();
456                 for (int i = 0; i < listFromJson.length(); i++) {
457                         lst.add(listFromJson.getString(i));
458                 }
459
460                 return lst;
461         }
462
463         public static Map<String, Object> convertStringToMap(String obj) {
464                 Map<String, Object> object = (Map<String, Object>) JSONValue.parse(obj);
465                 return object;
466         }
467
468         public static List<Map<String, Object>> getListOfMapsFromJson(RestResponse res, String field) throws Exception {
469                 List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
470                 JSONArray listFromJson = getListFromJson(res, field);
471                 for (int i = 0; i < listFromJson.length(); i++) {
472                         Map<String, Object> convertStringToMap = convertStringToMap(listFromJson.getString(i));
473                         list.add(convertStringToMap);
474                 }
475                 return list;
476
477         }
478
479         public static Map<String, Object> getJsonValueAsMap(RestResponse response, String key) {
480                 String valueField = getValueFromJsonResponse(response.getResponse(), key);
481                 Map<String, Object> convertToMap = convertStringToMap(valueField);
482                 return convertToMap;
483         }
484
485         public static String getJsonObjectValueByKey(String metadata, String key) {
486                 JsonElement jelement = new JsonParser().parse(metadata);
487
488                 JsonObject jobject = jelement.getAsJsonObject();
489                 Object obj = jobject.get(key);
490                 if (obj == null) {
491                         return null;
492                 } else {
493                         return obj.toString();
494                 }
495         }
496
497         public static Map<String, List<Component>> convertCatalogResponseToJavaObject(String response) {
498
499                 // Map<String, ArrayList<Component>> map = new HashMap<String,
500                 // ArrayList<Component>>();
501                 Map<String, List<Component>> map = new HashMap<String, List<Component>>();
502
503                 JsonElement jElement = new JsonParser().parse(response);
504                 JsonObject jObject = jElement.getAsJsonObject();
505                 JsonArray jArrReousrces = jObject.getAsJsonArray("resources");
506                 JsonArray jArrServices = jObject.getAsJsonArray("services");
507                 JsonArray jArrProducts = jObject.getAsJsonArray("products");
508                 
509                 if (jArrReousrces != null && jArrServices != null && jArrProducts != null){
510                         
511                 
512                 //////// RESOURCE/////////////////////////////
513                 ArrayList<Component> restResponseArray = new ArrayList<>();
514                 Component component = null;
515                 for (int i = 0; i < jArrReousrces.size(); i++) {
516                         String resourceString = (String) jArrReousrces.get(i).toString();
517                         component = ResponseParser.convertResourceResponseToJavaObject(resourceString);
518                         restResponseArray.add(component);
519                 }
520
521                 map.put("resources", restResponseArray);
522
523                 ///////// SERVICE/////////////////////////////
524
525                 restResponseArray = new ArrayList<>();
526                 component = null;
527                 for (int i = 0; i < jArrServices.size(); i++) {
528                         String resourceString = (String) jArrServices.get(i).toString();
529                         component = ResponseParser.convertServiceResponseToJavaObject(resourceString);
530                         restResponseArray.add(component);
531                 }
532
533                 map.put("services", restResponseArray);
534
535                 ///////// PRODUCT/////////////////////////////
536                 restResponseArray = new ArrayList<>();
537                 component = null;
538                 for (int i = 0; i < jArrProducts.size(); i++) {
539                         String resourceString = (String) jArrProducts.get(i).toString();
540                         component = ResponseParser.convertProductResponseToJavaObject(resourceString);
541                         restResponseArray.add(component);
542                 }
543
544                 map.put("products", restResponseArray);
545                 
546         }
547                 else {
548                         map.put("resources", new ArrayList<>());
549                         map.put("services", new ArrayList<>());
550                         map.put("products", new ArrayList<>());
551                 }
552
553                 return map;
554
555         }
556         
557         
558         public static Map<Long, ServiceDistributionStatus> convertServiceDistributionStatusToObject(String response) throws ParseException {
559
560                 Map<Long, ServiceDistributionStatus> serviceDistributionStatusMap = new HashMap<Long, ServiceDistributionStatus>();
561                 ServiceDistributionStatus serviceDistributionStatusObject = null;
562                 
563                 JsonElement jElement = new JsonParser().parse(response);
564                 JsonObject jObject = jElement.getAsJsonObject();
565                 JsonArray jDistrStatusArray = jObject.getAsJsonArray("distributionStatusOfServiceList");
566                 
567                 for (int i = 0; i < jDistrStatusArray.size(); i++){
568                         Gson gson = new Gson();
569                         String servDistrStatus = gson.toJson(jDistrStatusArray.get(i));
570                         serviceDistributionStatusObject = gson.fromJson(servDistrStatus, ServiceDistributionStatus.class);
571                         serviceDistributionStatusMap.put(Utils.getEpochTimeFromUTC(serviceDistributionStatusObject.getTimestamp()), serviceDistributionStatusObject);
572                 }
573
574                 return serviceDistributionStatusMap;
575                 
576         }
577         
578         public static Map<String, String> getPropertiesNameType(RestResponse restResponse)
579                         throws JSONException {
580                 Map<String, String> propertiesMap = new HashMap<String, String>();
581                 JSONArray propertiesList = getListFromJson(restResponse, "properties");
582                 for (int i = 0; i < propertiesList.length() ; i ++){
583                         JSONObject  prop = (JSONObject) JSONValue.parse(propertiesList.get(i).toString());
584                         String propName = prop.get("name").toString();
585                         String propType = prop.get("type").toString();
586                         propertiesMap.put(propName, propType);
587                 }
588                 
589                 return propertiesMap;
590         }
591         
592         public static ResourceAssetStructure getDataOutOfSearchExternalAPIResponseForResourceName(String response, String resourceName) {
593                 Gson gson = new Gson();
594                 JsonElement jsonElement = new JsonParser().parse(response);
595                 JsonArray jsonArray = jsonElement.getAsJsonArray();
596                 for(JsonElement jElement: jsonArray) {
597                         ResourceAssetStructure parsedResponse = gson.fromJson(jElement, ResourceAssetStructure.class);
598                         
599                         if(resourceName.contains(parsedResponse.getName()) && parsedResponse.getName().contains(resourceName)) {
600                                 return parsedResponse;
601                         }
602                 }
603                 
604                 return null;
605         }
606 }