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