2 * Copyright (c) 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.openo.gso.gui.servicegateway.roa.impl;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.ws.rs.core.Response;
24 import org.openo.baseservice.remoteservice.exception.ServiceException;
25 import org.openo.baseservice.util.RestUtils;
26 import org.openo.gso.gui.servicegateway.constant.Constant;
27 import org.openo.gso.gui.servicegateway.exception.HttpCode;
28 import org.openo.gso.gui.servicegateway.roa.inf.IServiceGatewayRoaModule;
29 import org.openo.gso.gui.servicegateway.service.impl.ServiceGatewayImpl;
30 import org.openo.gso.gui.servicegateway.service.inf.IServiceGateway;
31 import org.openo.gso.gui.servicegateway.util.http.ResponseUtils;
32 import org.openo.gso.gui.servicegateway.util.validate.ValidateUtil;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * Implement class for restful interface.<br/>
42 * @version GSO 0.5 2016/8/4
44 public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule {
49 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceGatewayRoaModuleImpl.class);
54 private IServiceGateway serviceGateway = new ServiceGatewayImpl();
57 * Create service instance.<br/>
59 * @param servletReq http request
61 * @throws ServiceException when operate database or parameter is wrong.
65 public Response createService(HttpServletRequest servletReq) {
66 Map<String, Object> operateStatus = null;
67 Map<String, Object> result = null;
68 String serviceId = null;
70 // 1. Check validation
71 String reqContent = RestUtils.getRequestBody(servletReq);
72 ValidateUtil.assertStringNotNull(reqContent);
73 LOGGER.info("Received a request form the NBI the reqContent is :"+ reqContent);
76 serviceId = serviceGateway.createService(reqContent, servletReq);
77 } catch(ServiceException exception) {
78 LOGGER.error("Fail to create service instance.");
79 operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_FAIL, exception,
80 String.valueOf(exception.getHttpCode()));
81 result = ResponseUtils.setResult(serviceId, operateStatus);
83 return Response.accepted().entity(result).build();
86 operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_SUCCESS, null,
87 String.valueOf(HttpCode.RESPOND_OK));
88 result = ResponseUtils.setResult(serviceId, operateStatus);
90 return Response.accepted().entity(result).build();
94 * Delete service instance.<br/>
96 * @param serviceId service instance id
97 * @param servletReq http request
99 * @throws ServiceException when operate database or parameter is wrong.
103 public Response deleteService(String serviceId, HttpServletRequest servletReq) {
104 Map<String, Object> result = null;
106 // 1. Check validation
107 String reqContent = RestUtils.getRequestBody(servletReq);
108 ValidateUtil.assertStringNotNull(reqContent);
111 result = serviceGateway.deleteService(serviceId, servletReq);
112 } catch(ServiceException exception) {
113 LOGGER.error("Fail to delete service instance.");
114 return Response.serverError().build();
116 return Response.accepted().entity(result).build();
119 public IServiceGateway getServiceGateway()
121 return serviceGateway;
124 public void setServiceGateway(IServiceGateway serviceGateway)
126 this.serviceGateway = serviceGateway;