2 * Copyright 2016 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.res.common.util.response;
19 import java.util.HashMap;
20 import java.util.List;
23 import org.onap.vfc.nfvo.res.common.constant.HttpConstant;
24 import org.onap.vfc.nfvo.res.common.constant.ParamConstant;
25 import org.onap.vfc.nfvo.res.common.constant.ResponseConstant;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import net.sf.json.JSONObject;
34 * Utility for generate Roa get/add/update/delete method status
38 * @version NFVO 0.5 2016-3-17
40 public final class RoaResponseUtil {
42 private static final Logger LOGGER = LoggerFactory.getLogger(RoaResponseUtil.class);
44 private RoaResponseUtil() {
49 * Generate get method response<br/>
52 * The basic response for get method
53 * @return JSONObject The response for http request
56 public static <T> JSONObject get(List<T> list) {
57 Map<String, Object> map = new HashMap<String, Object>(10);
58 map.put(ParamConstant.PARAM_DATA, list);
59 LOGGER.info("function=get; msg=get map:{}", map.toString());
60 return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.QUERY_SUCESS_MSG, map);
64 * Generate different response by different parameter for add method <br/>
71 public static JSONObject add(int result) {
72 LOGGER.info("function=add; msg=add result{}", result);
74 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.ADD_FAIL_MSG);
76 return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.ADD_SUCESS_MSG);
81 * Generate different response by different parameter for update method <br/>
85 * @return JSONObject The response for http request
88 public static JSONObject update(int result) {
89 LOGGER.info("function=update; msg=update result{}", result);
91 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.MOD_FAIL_MSG);
93 return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.MOD_SUCESS_MSG);
98 * Generate different response by different parameter for delete method <br/>
102 * @return delete JSONObject of the response for http request
105 public static JSONObject delete(int result) {
106 LOGGER.info("function=delete; msg=delete result{}", result);
108 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.DEL_FAIL_MSG);
110 return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.DEL_SUCESS_MSG);