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 propertyDefinition = mapper.readValue(response, ComponentInstanceProperty.class);
219 logger.debug(propertyDefinition.toString());
220 } catch (IOException e) {
221 // TODO Auto-generated catch block
224 return propertyDefinition;
227 public static String toJson(Object object) {
228 Gson gson = new Gson();
229 return gson.toJson(object);
232 public static ArtifactDefinition convertArtifactDefinitionResponseToJavaObject(String response) {
233 ObjectMapper mapper = new ObjectMapper();
234 ArtifactDefinition artifactDefinition = null;
237 artifactDefinition = mapper.readValue(response, ArtifactDefinition.class);
238 logger.debug(artifactDefinition.toString());
239 } catch (IOException e) {
240 // TODO Auto-generated catch block
244 return artifactDefinition;
248 public static ArtifactReqDetails convertArtifactReqDetailsToJavaObject(String response) {
250 ArtifactReqDetails artifactReqDetails = null;
251 Gson gson = new Gson();
252 artifactReqDetails = gson.fromJson(response, ArtifactReqDetails.class);
253 return artifactReqDetails;
256 public static <T> T parseToObject(String json, Class<T> clazz) {
257 Gson gson = new Gson();
260 object = gson.fromJson(json, clazz);
261 } catch (Exception e) {
262 object = parseToObjectUsingMapper(json, clazz);
267 public static <T> T parseToObjectUsingMapper(String json, Class<T> clazz) {
269 ObjectMapper mapper = new ObjectMapper();
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);
277 object = mapper.readValue(json, clazz);
278 // System.out.println("Class: "+clazz.getSimpleName()+", json:
280 } catch (IOException e) {
281 // TODO Auto-generated catch block
288 public static ArtifactReqDetails convertArtifactDefinitionToArtifactReqDetailsObject(
289 ArtifactDefinition artifactDefinition) {
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;
298 public static <T> void addDeserializer(SimpleModule module, Class<T> clazz,
299 final JsonDeserializer<T> deserializer) {
300 module.addDeserializer(clazz, deserializer);
303 public static Service convertServiceResponseToJavaObject(String response) {
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);
311 mapper.registerModule(module);
312 Service service = null;
314 service = mapper.readValue(response, Service.class);
315 logger.debug(service.toString());
316 } catch (IOException e) {
317 // TODO Auto-generated catch block
324 public static Product convertProductResponseToJavaObject(String response) {
326 ObjectMapper mapper = new ObjectMapper();
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);
333 mapper.registerModule(module);
335 Product product = null;
337 product = mapper.readValue(response, Product.class);
338 logger.debug(product.toString());
339 } catch (IOException e) {
340 // TODO Auto-generated catch block
347 public static ComponentInstance convertComponentInstanceResponseToJavaObject(String response) {
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);
355 mapper.registerModule(module);
356 ComponentInstance componentInstance = null;
358 componentInstance = mapper.readValue(response, ComponentInstance.class);
359 logger.debug(componentInstance.toString());
360 } catch (IOException e) {
361 // TODO Auto-generated catch block
365 return componentInstance;
368 public static List<String> getValuesFromJsonArray(RestResponse message) throws Exception {
369 List<String> artifactTypesArrayFromApi = new ArrayList<String>();
371 org.json.JSONObject responseObject = new org.json.JSONObject(message.getResponse());
372 JSONArray jArr = responseObject.getJSONArray("artifactTypes");
374 for (int i = 0; i < jArr.length(); i++) {
375 org.json.JSONObject jObj = jArr.getJSONObject(i);
376 String value = jObj.get("name").toString();
378 artifactTypesArrayFromApi.add(value);
380 return artifactTypesArrayFromApi;
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);
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;
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");
407 // Iterator<JsonElement> hitsIterator = hitsArray.iterator();
408 // while(hitsIterator.hasNext())
410 // JsonElement nextHit = hitsIterator.next();
411 // JsonObject jHitObject = nextHit.getAsJsonObject();
412 // JsonObject jSourceObject = (JsonObject) jHitObject.get("_source");
414 // Gson gson=new Gson();
415 // String auditUnparsed = jSourceObject.toString();
417 // Map<String,Object> map = new HashMap<String,Object>();
418 // map = (Map<String,Object>) gson.fromJson(auditUnparsed,
421 auditList.add(auditingMessage);
426 public static List<CategoryDefinition> parseCategories(RestResponse getAllCategoriesRest) {
428 List<CategoryDefinition> categories = new ArrayList<>();
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);
439 } catch (Exception e) {
446 public static JSONArray getListFromJson(RestResponse res, String field) throws JSONException {
447 String valueFromJsonResponse = getValueFromJsonResponse(res.getResponse(), field);
448 JSONArray jArr = new JSONArray(valueFromJsonResponse);
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));
463 public static Map<String, Object> convertStringToMap(String obj) {
464 Map<String, Object> object = (Map<String, Object>) JSONValue.parse(obj);
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);
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);
485 public static String getJsonObjectValueByKey(String metadata, String key) {
486 JsonElement jelement = new JsonParser().parse(metadata);
488 JsonObject jobject = jelement.getAsJsonObject();
489 Object obj = jobject.get(key);
493 return obj.toString();
497 public static Map<String, List<Component>> convertCatalogResponseToJavaObject(String response) {
499 // Map<String, ArrayList<Component>> map = new HashMap<String,
500 // ArrayList<Component>>();
501 Map<String, List<Component>> map = new HashMap<String, List<Component>>();
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");
509 if (jArrReousrces != null && jArrServices != null && jArrProducts != null){
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);
521 map.put("resources", restResponseArray);
523 ///////// SERVICE/////////////////////////////
525 restResponseArray = new ArrayList<>();
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);
533 map.put("services", restResponseArray);
535 ///////// PRODUCT/////////////////////////////
536 restResponseArray = new ArrayList<>();
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);
544 map.put("products", restResponseArray);
548 map.put("resources", new ArrayList<>());
549 map.put("services", new ArrayList<>());
550 map.put("products", new ArrayList<>());
558 public static Map<Long, ServiceDistributionStatus> convertServiceDistributionStatusToObject(String response) throws ParseException {
560 Map<Long, ServiceDistributionStatus> serviceDistributionStatusMap = new HashMap<Long, ServiceDistributionStatus>();
561 ServiceDistributionStatus serviceDistributionStatusObject = null;
563 JsonElement jElement = new JsonParser().parse(response);
564 JsonObject jObject = jElement.getAsJsonObject();
565 JsonArray jDistrStatusArray = jObject.getAsJsonArray("distributionStatusOfServiceList");
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);
574 return serviceDistributionStatusMap;
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);
589 return propertiesMap;
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);
599 if(resourceName.contains(parsedResponse.getName()) && parsedResponse.getName().contains(resourceName)) {
600 return parsedResponse;