From 7ded7cc8a1c4282e4cc84d4f82f73491f0bf3f08 Mon Sep 17 00:00:00 2001 From: c00149107 Date: Sat, 21 Apr 2018 15:40:05 +0800 Subject: Recipe param xsd support Recipe param xsd support Change-Id: I561d98358a76f1007b979cdf6753d2f3b7754991 Issue-ID: SO-583 Signed-off-by: c00149107 --- .../catalogdb/catalogrest/QueryResourceRecipe.java | 40 ++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'adapters/mso-catalog-db-adapter/src/main/java/org') diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipe.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipe.java index 5be6970554..7d6aed4785 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipe.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipe.java @@ -24,6 +24,10 @@ import java.util.Map; import org.openecomp.mso.db.catalog.beans.Recipe; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + /** * serivce csar query support *
@@ -41,16 +45,6 @@ public class QueryResourceRecipe extends CatalogQuery{ this.resourceRecipe =resourceRecipe; } - private final String template = - "\t{\n"+ - "\t\t\"id\" : ,\n"+ - "\t\t\"action\" : ,\n"+ - "\t\t\"orchestrationUri\" : ,\n"+ - "\t\t\"recipeTimeout\" : ,\n"+ - "\t\t\"paramXSD\" : ,\n"+ - "\t\t\"description\" : \n"+ - "\t}"; - @Override public String toString() { @@ -58,15 +52,25 @@ public class QueryResourceRecipe extends CatalogQuery{ } @Override - public String JSON2(boolean isArray, boolean isEmbed) { + public String JSON2(boolean isArray, boolean isEmbed) { + Map valueMap = new HashMap<>(); - put(valueMap, "ID", null == resourceRecipe ? null : resourceRecipe.getId()); - put(valueMap, "ACTION", null == resourceRecipe ? null : resourceRecipe.getAction()); - put(valueMap, "ORCHESTRATION_URI", null == resourceRecipe ? null : resourceRecipe.getOrchestrationUri()); - put(valueMap, "RECIPE_TIMEOUT", null == resourceRecipe ? null : resourceRecipe.getRecipeTimeout()); - put(valueMap, "PARAM_XSD", null == resourceRecipe ? null : resourceRecipe.getParamXSD()); - put(valueMap, "DESCRIPTION", null == resourceRecipe ? null : resourceRecipe.getDescription()); - return this.setTemplate(template, valueMap); + valueMap.put("id", null == resourceRecipe ? null :String.valueOf(resourceRecipe.getId())); + valueMap.put("action", null == resourceRecipe ? null :resourceRecipe.getAction()); + valueMap.put("orchestrationUri", null == resourceRecipe ? null : resourceRecipe.getOrchestrationUri()); + valueMap.put("recipeTimeout", null == resourceRecipe ? null : String.valueOf(resourceRecipe.getRecipeTimeout())); + valueMap.put("paramXSD", null == resourceRecipe ? null : resourceRecipe.getParamXSD()); + valueMap.put("description", null == resourceRecipe ? null : resourceRecipe.getDescription()); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); + String jsonStr = ""; + try { + jsonStr = mapper.writeValueAsString(valueMap); + } catch(JsonProcessingException e) { + + e.printStackTrace(); + } + return jsonStr; } } -- cgit 1.2.3-korg