2 * Copyright (c) 2016, Huawei Technologies Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.openo.gso.gui.servicegateway.roa.impl;
\r
19 import java.util.Map;
\r
21 import javax.servlet.http.HttpServletRequest;
\r
22 import javax.ws.rs.core.Response;
\r
24 import org.openo.baseservice.remoteservice.exception.ServiceException;
\r
25 import org.openo.baseservice.util.RestUtils;
\r
26 import org.openo.gso.gui.servicegateway.constant.Constant;
\r
27 import org.openo.gso.gui.servicegateway.exception.HttpCode;
\r
28 import org.openo.gso.gui.servicegateway.roa.inf.IServiceGatewayRoaModule;
\r
29 import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl;
\r
30 import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway;
\r
31 import org.openo.gso.gui.servicegateway.util.http.ResponseUtils;
\r
32 import org.openo.gso.gui.servicegateway.util.validate.ValidateUtil;
\r
33 import org.slf4j.Logger;
\r
34 import org.slf4j.LoggerFactory;
\r
37 * Implement class for restful interface.<br/>
\r
42 * @version GSO 0.5 2016/8/4
\r
44 public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule {
\r
49 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceGatewayRoaModuleImpl.class);
\r
54 private IServiceGateway serviceGateway = new ServiceGatewayImpl();
\r
57 * Create service instance.<br/>
\r
59 * @param servletReq http request
\r
61 * @throws ServiceException when operate database or parameter is wrong.
\r
65 public Response createService(HttpServletRequest servletReq) {
\r
66 Map<String, Object> operateStatus = null;
\r
67 Map<String, Object> result = null;
\r
68 String serviceId = null;
\r
70 // 1. Check validation
\r
71 String reqContent = RestUtils.getRequestBody(servletReq);
\r
72 ValidateUtil.assertStringNotNull(reqContent);
\r
74 // 2. Create service
\r
75 serviceId = serviceGateway.createService(reqContent, servletReq);
\r
76 } catch(ServiceException exception) {
\r
77 LOGGER.error("Fail to create service instance.");
\r
78 operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_FAIL, exception,
\r
79 String.valueOf(exception.getHttpCode()));
\r
80 result = ResponseUtils.setResult(serviceId, operateStatus);
\r
82 return Response.accepted().entity(result).build();
\r
85 operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_SUCCESS, null,
\r
86 String.valueOf(HttpCode.RESPOND_OK));
\r
87 result = ResponseUtils.setResult(serviceId, operateStatus);
\r
89 return Response.accepted().entity(result).build();
\r
93 * Delete service instance.<br/>
\r
95 * @param serviceId service instance id
\r
96 * @param servletReq http request
\r
98 * @throws ServiceException when operate database or parameter is wrong.
\r
102 public Response deleteService(String serviceId, HttpServletRequest servletReq) {
\r