8670b78e15ee19b8f157d8c6d51c2ab52a98da2e
[so.git] /
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 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import com.fasterxml.jackson.core.JsonProcessingException;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import com.fasterxml.jackson.databind.SerializationFeature;
31
32 /**
33  * serivce csar query support 
34  * <br>
35  * <p>
36  * </p>
37  * 
38  * @author
39  * @version     ONAP Beijing Release  2018-02-28
40  */
41 public class QueryResourceRecipe extends CatalogQuery{
42     protected static Logger logger = LoggerFactory.getLogger(QueryResourceRecipe.class);
43     
44     private Recipe resourceRecipe;
45     
46     public QueryResourceRecipe(Recipe resourceRecipe){
47         this.resourceRecipe =resourceRecipe;
48     }
49
50     @Override
51     public String toString() {
52
53         return resourceRecipe.toString();
54     }
55
56     @Override
57     public String JSON2(boolean isArray, boolean isEmbed) {
58        Map<String, String> valueMap = new HashMap<>();
59         valueMap.put("id",  null == resourceRecipe ? null :String.valueOf(resourceRecipe.getId()));
60         valueMap.put("action",  null == resourceRecipe ? null :resourceRecipe.getAction());
61         valueMap.put("orchestrationUri", null == resourceRecipe ? null : resourceRecipe.getOrchestrationUri());
62         valueMap.put("recipeTimeout", null == resourceRecipe ? null : String.valueOf(resourceRecipe.getRecipeTimeout()));
63         valueMap.put("paramXSD", null == resourceRecipe ? null : resourceRecipe.getParamXsd());
64         valueMap.put("description", null == resourceRecipe ? null : resourceRecipe.getDescription());
65         ObjectMapper mapper = new ObjectMapper();
66         mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
67         String jsonStr = "";
68         try {
69             jsonStr = mapper.writeValueAsString(valueMap);
70         } catch(JsonProcessingException e) {
71             logger.error("Error creating JSON", e);
72         }
73         return jsonStr;
74     }
75
76 }