7d6aed4785e0307d6fcb41f17c714c3ed4b3e8c3
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / openecomp / mso / adapters / catalogdb / catalogrest / QueryResourceRecipe.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 package org.openecomp.mso.adapters.catalogdb.catalogrest;\r
21 \r
22 import java.util.HashMap;\r
23 import java.util.Map;\r
24 \r
25 import org.openecomp.mso.db.catalog.beans.Recipe;\r
26 \r
27 import com.fasterxml.jackson.core.JsonProcessingException;\r
28 import com.fasterxml.jackson.databind.ObjectMapper;\r
29 import com.fasterxml.jackson.databind.SerializationFeature;\r
30 \r
31 /**\r
32  * serivce csar query support \r
33  * <br>\r
34  * <p>\r
35  * </p>\r
36  * \r
37  * @author\r
38  * @version     ONAP Beijing Release  2018-02-28\r
39  */\r
40 public class QueryResourceRecipe extends CatalogQuery{\r
41     \r
42     private Recipe resourceRecipe;\r
43     \r
44     public QueryResourceRecipe(Recipe resourceRecipe){\r
45         this.resourceRecipe =resourceRecipe;\r
46     }\r
47 \r
48     @Override\r
49     public String toString() {\r
50 \r
51         return resourceRecipe.toString();\r
52     }\r
53 \r
54     @Override\r
55     public String JSON2(boolean isArray, boolean isEmbed) {     \r
56         \r
57         Map<String, String> valueMap = new HashMap<>();\r
58         valueMap.put("id",  null == resourceRecipe ? null :String.valueOf(resourceRecipe.getId()));\r
59         valueMap.put("action",  null == resourceRecipe ? null :resourceRecipe.getAction());\r
60         valueMap.put("orchestrationUri", null == resourceRecipe ? null : resourceRecipe.getOrchestrationUri());\r
61         valueMap.put("recipeTimeout", null == resourceRecipe ? null : String.valueOf(resourceRecipe.getRecipeTimeout()));\r
62         valueMap.put("paramXSD", null == resourceRecipe ? null : resourceRecipe.getParamXSD());\r
63         valueMap.put("description", null == resourceRecipe ? null : resourceRecipe.getDescription());\r
64         ObjectMapper mapper = new ObjectMapper();\r
65         mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);\r
66         String jsonStr = "";\r
67         try {\r
68             jsonStr = mapper.writeValueAsString(valueMap);\r
69         } catch(JsonProcessingException e) {\r
70 \r
71             e.printStackTrace();\r
72         }\r
73         return jsonStr;\r
74     }\r
75 \r
76 }\r