GSO-26 Modify the response structure for deleting service to be consistent with the...
authorLuji7 <lu.ji3@zte.com.cn>
Fri, 21 Oct 2016 06:13:44 +0000 (14:13 +0800)
committerLuji7 <lu.ji3@zte.com.cn>
Fri, 21 Oct 2016 06:13:44 +0000 (14:13 +0800)
Change-Id: Ic6a4fa300e914be8bb6016e5022d548940fed29e
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/roa/impl/ServiceGatewayRoaModuleImpl.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/impl/ServiceGatewayImpl.java
servicegateway/service/src/main/java/org/openo/gso/gui/servicegateway/service/inf/IServiceGateway.java

index 7d2e072..cca5f60 100644 (file)
@@ -101,7 +101,6 @@ public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule {
      */
     @Override
     public Response deleteService(String serviceId, HttpServletRequest servletReq) {
-        Map<String, Object> operateStatus = null;
         Map<String, Object> result = null;
         try {
             // 1. Check validation
@@ -109,20 +108,11 @@ public class ServiceGatewayRoaModuleImpl implements IServiceGatewayRoaModule {
             ValidateUtil.assertStringNotNull(reqContent);
 
             // 2. Delete service
-            serviceGateway.deleteService(serviceId, servletReq);
+            result = serviceGateway.deleteService(serviceId, servletReq);
         } catch(ServiceException exception) {
             LOGGER.error("Fail to delete service instance.");
-            operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_FAIL, exception,
-                    String.valueOf(exception.getHttpCode()));
-            result = ResponseUtils.setResult(serviceId, operateStatus);
-
-            return Response.accepted().entity(result).build();
+            return Response.serverError().build();
         }
-
-        operateStatus = ResponseUtils.setOperateStatus(Constant.RESPONSE_STATUS_SUCCESS, null,
-                String.valueOf(HttpCode.RESPOND_OK));
-        result = ResponseUtils.setResult(serviceId, operateStatus);
-
         return Response.accepted().entity(result).build();
     }
 
index 3ff4f89..bc716d5 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.openo.gso.gui.servicegateway.service.impl;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
@@ -130,7 +131,7 @@ public class ServiceGatewayImpl implements IServiceGateway {
      * @since GSO 0.5
      */
     @Override
-    public void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException {
+    public Map<String, Object> deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException {
        if(httpRequest == null)
        {               
                LOGGER.error("ServiceGatewayImpl.deleteService httpRequest is null");
@@ -153,16 +154,26 @@ public class ServiceGatewayImpl implements IServiceGateway {
         // call the restful
         try {
             RestfulResponse restfulRsp = null;
+            Map<String, Object> result = new HashMap<String, Object>();
             if(Constant.SERVICE_DELETE_OPERATION.equalsIgnoreCase(operation)) {
                 restfulRsp = RestfulFactory.getRestInstance("http").delete(gatewayUri,
                         getRestfulParameters(JsonUtil.marshal(requestBody)));
+                result.put(Constant.RESPONSE_STATUS, "success");
+                result.put(Constant.RESPONSE_STATUS_DESCRIPTION, "It is deleting.");
+                result.put(Constant.RESPONSE_ERRORCODE, "202");
             } else {
                 restfulRsp = RestfulFactory.getRestInstance("http").post(gatewayUri,
                         getRestfulParameters(JsonUtil.marshal(requestBody)));
+                if (null != restfulRsp) {
+                    String jobId = restfulRsp.getRespHeaderStr(Constant.JOB_ID);
+                    result.put(Constant.JOB_ID, jobId);
+                }
             }
             if (null != restfulRsp) {
                 LOGGER.info("restful call result:", restfulRsp.getStatus());
+                LOGGER.info("restful call content:", restfulRsp.getResponseContent());
             }
+            return result;
         } catch(ServiceException e) {
             LOGGER.error("service gateway delete restful call result:", e);
             throw e;
index 9e18cb1..cba925c 100644 (file)
@@ -21,6 +21,8 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.openo.baseservice.remoteservice.exception.ServiceException;
 
+import java.util.Map;
+
 /**
  * Interface to operate service.<br/>
  * <p>
@@ -50,6 +52,6 @@ public interface IServiceGateway {
      * @throws ServiceException operate DB or parameter is wrong.
      * @since GSO 0.5
      */
-    void deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException;
+    Map<String, Object> deleteService(String serviceId, HttpServletRequest httpRequest) throws ServiceException;
 
 }