2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.utils.rest;
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;
31 import java.util.Optional;
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;
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;
72 public class ResponseParser {
74 // comment by Andrey, for test only
75 // public static void main(String[] args) {
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
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
88 // operation.\",\"definition\":false},\"start\":{\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard.start\",\"description\":\"Standard
90 // operation.\",\"definition\":false},\"delete\":{\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard.delete\",\"description\":\"Standard
92 // operation.\",\"definition\":false},\"create\":{\"uniqueId\":\"tosca.interfaces.node.lifecycle.standard.create\",\"description\":\"Standard
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);
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";
109 static Logger logger = Logger.getLogger(ResponseParser.class.getName());
111 public static String getValueFromJsonResponse(String response, String fieldName) {
113 JSONObject jsonResp = (JSONObject) JSONValue.parse(response);
114 Object fieldValue = jsonResp.get(fieldName);
115 return fieldValue.toString();
117 } catch (Exception e) {
123 public static String getUniqueIdFromResponse(RestResponse response) {
124 return getValueFromJsonResponse(response.getResponse(), UNIQUE_ID);
127 public static String getInvariantUuid(RestResponse response) {
128 return getValueFromJsonResponse(response.getResponse(), INVARIANT_UUID);
131 public static String getUuidFromResponse(RestResponse response) {
132 return getValueFromJsonResponse(response.getResponse(), UUID);
135 public static String getNameFromResponse(RestResponse response) {
136 return getValueFromJsonResponse(response.getResponse(), NAME);
139 public static String getVersionFromResponse(RestResponse response) {
140 return ResponseParser.getValueFromJsonResponse(response.getResponse(), VERSION);
143 public static String getComponentTypeFromResponse(RestResponse response) {
144 return ResponseParser.getValueFromJsonResponse(response.getResponse(), ORIGIN_TYPE);
147 public static String getToscaResourceNameFromResponse(RestResponse response) {
148 return getValueFromJsonResponse(response.getResponse(), TOSCA_RESOURCE_NAME);
151 @SuppressWarnings("unchecked")
152 public static ResourceRespJavaObject parseJsonListReturnResourceDetailsObj(RestResponse restResponse,
153 String resourceType, String searchPattern, String expectedResult) throws Exception {
155 // Gson gson = new Gson;
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();
164 for (int counter = 0; counter < arrayOfObjects.size(); counter++) {
165 JsonObject jHitObject = (JsonObject) arrayOfObjects.get(counter);
167 map = (Map<String, Object>) gson.fromJson(jHitObject.toString(), map.getClass());
168 if (map.get(searchPattern).toString().contains(expectedResult)) {
170 jsonToJavaObject = gson.fromJson(jObject, ResourceRespJavaObject.class);
174 return jsonToJavaObject;
178 public static Resource convertResourceResponseToJavaObject(String response) {
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);
186 mapper.registerModule(module);
187 Resource resource = null;
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);
193 logger.debug(resource.toString());
194 } catch (IOException e) {
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();
207 public static ComponentInstanceProperty convertPropertyResponseToJavaObject(String response) {
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);
215 mapper.registerModule(module);
216 ComponentInstanceProperty propertyDefinition = null;
218 mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
219 propertyDefinition = mapper.readValue(response, ComponentInstanceProperty.class);
220 logger.debug(propertyDefinition.toString());
221 } catch (IOException e) {
222 // TODO Auto-generated catch block
225 return propertyDefinition;
228 public static String toJson(Object object) {
229 Gson gson = new Gson();
230 return gson.toJson(object);
233 public static ArtifactDefinition convertArtifactDefinitionResponseToJavaObject(String response) {
234 ObjectMapper mapper = new ObjectMapper();
235 ArtifactDefinition artifactDefinition = null;
237 mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
238 artifactDefinition = mapper.readValue(response, ArtifactDefinition.class);
239 logger.debug(artifactDefinition.toString());
240 } catch (IOException e) {
241 // TODO Auto-generated catch block
245 return artifactDefinition;
249 public static ArtifactReqDetails convertArtifactReqDetailsToJavaObject(String response) {
251 ArtifactReqDetails artifactReqDetails = null;
252 Gson gson = new Gson();
253 artifactReqDetails = gson.fromJson(response, ArtifactReqDetails.class);
254 return artifactReqDetails;
257 public static <T> T parseToObject(String json, Class<T> clazz) {
258 Gson gson = new Gson();
261 object = gson.fromJson(json, clazz);
262 } catch (Exception e) {
263 object = parseToObjectUsingMapper(json, clazz);
268 public static <T> T parseToObjectUsingMapper(String json, Class<T> clazz) {
270 ObjectMapper mapper = new ObjectMapper();
272 final SimpleModule module = new SimpleModule("customerSerializationModule",
273 new Version(1, 0, 0, "static version"));
274 JsonDeserializer<PropertyConstraint> desrializer = new PropertyConstraintJacksonDeserialiser();
275 addDeserializer(module, PropertyConstraint.class, desrializer);
276 mapper.registerModule(module);
277 mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
279 object = mapper.readValue(json, clazz);
280 // System.out.println("Class: "+clazz.getSimpleName()+", json:
282 } catch (IOException e) {
283 // TODO Auto-generated catch block
290 public static ArtifactReqDetails convertArtifactDefinitionToArtifactReqDetailsObject(
291 ArtifactDefinition artifactDefinition) {
293 ArtifactReqDetails artifactReqDetails = null;
294 Gson gson = new Gson();
295 String artDef = gson.toJson(artifactDefinition);
296 artifactReqDetails = gson.fromJson(artDef, ArtifactReqDetails.class);
297 return artifactReqDetails;
300 public static <T> void addDeserializer(SimpleModule module, Class<T> clazz,
301 final JsonDeserializer<T> deserializer) {
302 module.addDeserializer(clazz, deserializer);
305 public static Service convertServiceResponseToJavaObject(String response) {
307 ObjectMapper mapper = new ObjectMapper();
308 final SimpleModule module = new SimpleModule("customerSerializationModule",
309 new Version(1, 0, 0, "static version"));
310 JsonDeserializer<PropertyConstraint> deserializer = new PropertyConstraintJacksonDeserialiser();
311 addDeserializer(module, PropertyConstraint.class, deserializer);
313 mapper.registerModule(module);
314 Service service = null;
316 // TODO Andrey L. uncomment line below in case to ignore on unknown properties, not recommended, added by Matvey
317 mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
318 service = mapper.readValue(response, Service.class);
319 logger.debug(service.toString());
320 } catch (IOException e) {
321 // TODO Auto-generated catch block
328 public static Product convertProductResponseToJavaObject(String response) {
330 ObjectMapper mapper = new ObjectMapper();
332 final SimpleModule module = new SimpleModule("customerSerializationModule",
333 new Version(1, 0, 0, "static version"));
334 JsonDeserializer<PropertyConstraint> desrializer = new PropertyConstraintJacksonDeserialiser();
335 addDeserializer(module, PropertyConstraint.class, desrializer);
337 mapper.registerModule(module);
339 Product product = null;
341 mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
342 product = mapper.readValue(response, Product.class);
343 logger.debug(product.toString());
344 } catch (IOException e) {
345 // TODO Auto-generated catch block
352 public static ComponentInstance convertComponentInstanceResponseToJavaObject(String response) {
354 ObjectMapper mapper = new ObjectMapper();
355 final SimpleModule module = new SimpleModule("customerSerializationModule",
356 new Version(1, 0, 0, "static version"));
357 JsonDeserializer<PropertyConstraint> desrializer = new PropertyConstraintJacksonDeserialiser();
358 addDeserializer(module, PropertyConstraint.class, desrializer);
360 mapper.registerModule(module);
361 ComponentInstance componentInstance = null;
363 mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
364 componentInstance = mapper.readValue(response, ComponentInstance.class);
365 logger.debug(componentInstance.toString());
366 } catch (IOException e) {
367 // TODO Auto-generated catch block
371 return componentInstance;
374 public static List<String> getValuesFromJsonArray(RestResponse message) throws Exception {
375 List<String> artifactTypesArrayFromApi = new ArrayList<String>();
377 org.json.JSONObject responseObject = new org.json.JSONObject(message.getResponse());
378 JSONArray jArr = responseObject.getJSONArray("artifactTypes");
380 for (int i = 0; i < jArr.length(); i++) {
381 org.json.JSONObject jObj = jArr.getJSONObject(i);
382 String value = jObj.get("name").toString();
384 artifactTypesArrayFromApi.add(value);
386 return artifactTypesArrayFromApi;
389 public static String calculateMD5Header(ArtifactReqDetails artifactDetails) {
390 Gson gson = new Gson();
391 String jsonBody = gson.toJson(artifactDetails);
392 // calculate MD5 for json body
393 return calculateMD5(jsonBody);
397 public static String calculateMD5(String data) {
398 String calculatedMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(data);
399 // encode base-64 result
400 byte[] encodeBase64 = Base64.encodeBase64(calculatedMd5.getBytes());
401 String encodeBase64Str = new String(encodeBase64);
402 return encodeBase64Str;
406 public static List<Map<String, Object>> getAuditFromMessage(Map auditingMessage) {
407 List<Map<String, Object>> auditList = new ArrayList<Map<String, Object>>();
408 // JsonElement jElement = new JsonParser().parse(auditingMessage);
409 // JsonObject jObject = jElement.getAsJsonObject();
410 // JsonObject hitsObject = (JsonObject) jObject.get("hits");
411 // JsonArray hitsArray = (JsonArray) hitsObject.get("hits");
413 // Iterator<JsonElement> hitsIterator = hitsArray.iterator();
414 // while(hitsIterator.hasNext())
416 // JsonElement nextHit = hitsIterator.next();
417 // JsonObject jHitObject = nextHit.getAsJsonObject();
418 // JsonObject jSourceObject = (JsonObject) jHitObject.get("_source");
420 // Gson gson=new Gson();
421 // String auditUnparsed = jSourceObject.toString();
423 // Map<String,Object> map = new HashMap<String,Object>();
424 // map = (Map<String,Object>) gson.fromJson(auditUnparsed,
427 auditList.add(auditingMessage);
432 public static List<CategoryDefinition> parseCategories(RestResponse getAllCategoriesRest) {
434 List<CategoryDefinition> categories = new ArrayList<>();
436 JsonElement jElement = new JsonParser().parse(getAllCategoriesRest.getResponse());
437 JsonArray cagegories = jElement.getAsJsonArray();
438 Iterator<JsonElement> iter = cagegories.iterator();
439 while (iter.hasNext()) {
440 JsonElement next = iter.next();
441 CategoryDefinition category = ResponseParser.parseToObject(next.toString(), CategoryDefinition.class);
442 categories.add(category);
445 } catch (Exception e) {
452 public static JSONArray getListFromJson(RestResponse res, String field) throws JSONException {
453 String valueFromJsonResponse = getValueFromJsonResponse(res.getResponse(), field);
454 JSONArray jArr = new JSONArray(valueFromJsonResponse);
459 public static List<String> getDerivedListFromJson(RestResponse res) throws JSONException {
460 JSONArray listFromJson = getListFromJson(res, "derivedList");
461 List<String> lst = new ArrayList<String>();
462 for (int i = 0; i < listFromJson.length(); i++) {
463 lst.add(listFromJson.getString(i));
469 public static Map<String, Object> convertStringToMap(String obj) {
470 Map<String, Object> object = (Map<String, Object>) JSONValue.parse(obj);
474 public static List<Map<String, Object>> getListOfMapsFromJson(RestResponse res, String field) throws Exception {
475 List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
476 JSONArray listFromJson = getListFromJson(res, field);
477 for (int i = 0; i < listFromJson.length(); i++) {
478 Map<String, Object> convertStringToMap = convertStringToMap(listFromJson.getString(i));
479 list.add(convertStringToMap);
485 public static Map<String, Object> getJsonValueAsMap(RestResponse response, String key) {
486 String valueField = getValueFromJsonResponse(response.getResponse(), key);
487 Map<String, Object> convertToMap = convertStringToMap(valueField);
491 public static String getJsonObjectValueByKey(String metadata, String key) {
492 JsonElement jelement = new JsonParser().parse(metadata);
494 JsonObject jobject = jelement.getAsJsonObject();
495 Object obj = jobject.get(key);
499 return obj.toString();
503 public static Map<String, List<Component>> convertCatalogResponseToJavaObject(String response) {
505 // Map<String, ArrayList<Component>> map = new HashMap<String,
506 // ArrayList<Component>>();
507 Map<String, List<Component>> map = new HashMap<String, List<Component>>();
509 JsonElement jElement = new JsonParser().parse(response);
510 JsonObject jObject = jElement.getAsJsonObject();
511 JsonArray jArrReousrces = jObject.getAsJsonArray("resources");
512 JsonArray jArrServices = jObject.getAsJsonArray("services");
513 JsonArray jArrProducts = jObject.getAsJsonArray("products");
515 if (jArrReousrces != null && jArrServices != null && jArrProducts != null){
518 //////// RESOURCE/////////////////////////////
519 ArrayList<Component> restResponseArray = new ArrayList<>();
520 Component component = null;
521 for (int i = 0; i < jArrReousrces.size(); i++) {
522 String resourceString = (String) jArrReousrces.get(i).toString();
523 component = ResponseParser.convertResourceResponseToJavaObject(resourceString);
524 restResponseArray.add(component);
527 map.put("resources", restResponseArray);
529 ///////// SERVICE/////////////////////////////
531 restResponseArray = new ArrayList<>();
533 for (int i = 0; i < jArrServices.size(); i++) {
534 String resourceString = (String) jArrServices.get(i).toString();
535 component = ResponseParser.convertServiceResponseToJavaObject(resourceString);
536 restResponseArray.add(component);
539 map.put("services", restResponseArray);
541 ///////// PRODUCT/////////////////////////////
542 restResponseArray = new ArrayList<>();
544 for (int i = 0; i < jArrProducts.size(); i++) {
545 String resourceString = (String) jArrProducts.get(i).toString();
546 component = ResponseParser.convertProductResponseToJavaObject(resourceString);
547 restResponseArray.add(component);
550 map.put("products", restResponseArray);
554 map.put("resources", new ArrayList<>());
555 map.put("services", new ArrayList<>());
556 map.put("products", new ArrayList<>());
564 public static Map<Long, ServiceDistributionStatus> convertServiceDistributionStatusToObject(String response) throws ParseException {
566 Map<Long, ServiceDistributionStatus> serviceDistributionStatusMap = new HashMap<Long, ServiceDistributionStatus>();
567 ServiceDistributionStatus serviceDistributionStatusObject = null;
569 JsonElement jElement = new JsonParser().parse(response);
570 JsonObject jObject = jElement.getAsJsonObject();
571 JsonArray jDistrStatusArray = jObject.getAsJsonArray("distributionStatusOfServiceList");
573 for (int i = 0; i < jDistrStatusArray.size(); i++){
574 Gson gson = new Gson();
575 String servDistrStatus = gson.toJson(jDistrStatusArray.get(i));
576 serviceDistributionStatusObject = gson.fromJson(servDistrStatus, ServiceDistributionStatus.class);
577 serviceDistributionStatusMap.put(Utils.getEpochTimeFromUTC(serviceDistributionStatusObject.getTimestamp()), serviceDistributionStatusObject);
580 return serviceDistributionStatusMap;
584 public static Map<String, String> getPropertiesNameType(RestResponse restResponse)
585 throws JSONException {
586 Map<String, String> propertiesMap = new HashMap<String, String>();
587 JSONArray propertiesList = getListFromJson(restResponse, "properties");
588 for (int i = 0; i < propertiesList.length() ; i ++){
589 JSONObject prop = (JSONObject) JSONValue.parse(propertiesList.get(i).toString());
590 String propName = prop.get("name").toString();
591 String propType = prop.get("type").toString();
592 propertiesMap.put(propName, propType);
595 return propertiesMap;
598 public static ResourceAssetStructure getDataOutOfSearchExternalAPIResponseForResourceName(String response, String resourceName) {
599 Gson gson = new Gson();
600 JsonElement jsonElement = new JsonParser().parse(response);
601 JsonArray jsonArray = jsonElement.getAsJsonArray();
602 for(JsonElement jElement: jsonArray) {
603 ResourceAssetStructure parsedResponse = gson.fromJson(jElement, ResourceAssetStructure.class);
605 if(resourceName.contains(parsedResponse.getName()) && parsedResponse.getName().contains(resourceName)) {
606 return parsedResponse;