Containerization feature of SO
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / onap / so / adapters / catalogdb / catalogrest / QueryResourceRecipe.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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 package org.onap.so.adapters.catalogdb.catalogrest;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.onap.so.db.catalog.beans.Recipe;
26
27 import com.fasterxml.jackson.core.JsonProcessingException;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import com.fasterxml.jackson.databind.SerializationFeature;
30
31 /**
32  * serivce csar query support 
33  * <br>
34  * <p>
35  * </p>
36  * 
37  * @author
38  * @version     ONAP Beijing Release  2018-02-28
39  */
40 public class QueryResourceRecipe extends CatalogQuery{
41     
42     private Recipe resourceRecipe;
43     
44     public QueryResourceRecipe(Recipe resourceRecipe){
45         this.resourceRecipe =resourceRecipe;
46     }
47
48     @Override
49     public String toString() {
50
51         return resourceRecipe.toString();
52     }
53
54     @Override
55     public String JSON2(boolean isArray, boolean isEmbed) {
56        Map<String, String> valueMap = new HashMap<>();
57         valueMap.put("id",  null == resourceRecipe ? null :String.valueOf(resourceRecipe.getId()));
58         valueMap.put("action",  null == resourceRecipe ? null :resourceRecipe.getAction());
59         valueMap.put("orchestrationUri", null == resourceRecipe ? null : resourceRecipe.getOrchestrationUri());
60         valueMap.put("recipeTimeout", null == resourceRecipe ? null : String.valueOf(resourceRecipe.getRecipeTimeout()));
61         valueMap.put("paramXSD", null == resourceRecipe ? null : resourceRecipe.getParamXsd());
62         valueMap.put("description", null == resourceRecipe ? null : resourceRecipe.getDescription());
63         ObjectMapper mapper = new ObjectMapper();
64         mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
65         String jsonStr = "";
66         try {
67             jsonStr = mapper.writeValueAsString(valueMap);
68         } catch(JsonProcessingException e) {
69
70             e.printStackTrace();
71         }
72         return jsonStr;
73     }
74
75 }