Replaced all tabs with spaces in java and pom.xml
[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 import org.apache.commons.lang3.StringUtils;
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 <br>
34  * <p>
35  * </p>
36  * 
37  * @author
38  * @version ONAP Beijing Release 2018-02-28
39  */
40 public class QueryResourceRecipe extends CatalogQuery {
41     protected static Logger logger = LoggerFactory.getLogger(QueryResourceRecipe.class);
42
43     private Recipe resourceRecipe;
44
45     public QueryResourceRecipe(Recipe resourceRecipe) {
46         this.resourceRecipe = resourceRecipe;
47     }
48
49     @Override
50     public String toString() {
51
52         return resourceRecipe.toString();
53     }
54
55     @Override
56     public String JSON2(boolean isArray, boolean isEmbed) {
57         Map<String, String> valueMap = new HashMap<>();
58         valueMap.put("id", null == resourceRecipe || null == resourceRecipe.getId() ? StringUtils.EMPTY
59                 : String.valueOf(resourceRecipe.getId()));
60         valueMap.put("action", null == resourceRecipe || null == resourceRecipe.getAction() ? StringUtils.EMPTY
61                 : resourceRecipe.getAction());
62         valueMap.put("orchestrationUri",
63                 null == resourceRecipe || null == resourceRecipe.getOrchestrationUri() ? StringUtils.EMPTY
64                         : resourceRecipe.getOrchestrationUri());
65         valueMap.put("recipeTimeout",
66                 null == resourceRecipe || null == resourceRecipe.getRecipeTimeout() ? StringUtils.EMPTY
67                         : String.valueOf(resourceRecipe.getRecipeTimeout()));
68         valueMap.put("paramXSD", null == resourceRecipe || null == resourceRecipe.getParamXsd() ? StringUtils.EMPTY
69                 : resourceRecipe.getParamXsd());
70         valueMap.put("description",
71                 null == resourceRecipe || null == resourceRecipe.getDescription() ? StringUtils.EMPTY
72                         : resourceRecipe.getDescription());
73         ObjectMapper mapper = new ObjectMapper();
74         mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
75         String jsonStr = "";
76         try {
77             jsonStr = mapper.writeValueAsString(valueMap);
78         } catch (JsonProcessingException e) {
79             logger.error("Error creating JSON", e);
80         }
81         return jsonStr;
82     }
83
84 }