Add backend Code for customer/serviceType management UI page 51/83951/1
authorguochuyicmri <guochuyi@chinamobile.com>
Tue, 2 Apr 2019 09:56:37 +0000 (17:56 +0800)
committerguochuyicmri <guochuyi@chinamobile.com>
Tue, 2 Apr 2019 09:56:47 +0000 (17:56 +0800)
Change-Id: Ie1937cf1983c420231a8f4fb6ec5cba131f09d5a
Issue-ID: USECASEUI-213
Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
server/pom.xml
server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java
server/src/main/java/org/onap/usecaseui/server/service/lcm/CustomerService.java
server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java
server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java

index 6d575bb..5ef9f20 100644 (file)
@@ -35,7 +35,7 @@
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <java.version>1.8</java.version>
         <hibernate.version>5.3.6.Final</hibernate.version>
-        <spring.version>4.3.15.RELEASE</spring.version>
+        <spring.version>4.3.4.RELEASE</spring.version>
         <javax.persistence.version>1.0.2</javax.persistence.version>
         <common.csv.version>1.4</common.csv.version>
         <jackson.version>2.9.0</jackson.version>
index 9d332e7..22bda7e 100644 (file)
@@ -23,9 +23,14 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import com.alibaba.fastjson.JSONObject;
+
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+
 import java.util.List;
 
 @Controller
@@ -45,10 +50,46 @@ public class CustomerController {
     public List<AAICustomer> getCustomers(){
         return customerService.listCustomer();
     }
-
+    
+    @ResponseBody
+    @RequestMapping(value={"/uui-lcm/customers/{customerId}"},method = RequestMethod.PUT,produces="application/json")
+    public JSONObject createOrUpdateCustomer(HttpServletRequest request,@PathVariable String customerId){
+       return customerService.createOrUpdateCustomer(request, customerId);
+    }
+    
+    @ResponseBody
+    @RequestMapping(value={"/uui-lcm/customers/{customerId}"},method = RequestMethod.GET,produces="application/json")
+    public JSONObject getCustomerById(@PathVariable String customerId){
+       return customerService.getCustomerById(customerId);
+    }
+    
+    @ResponseBody
+    @RequestMapping(value={"/uui-lcm/customers"},method = RequestMethod.DELETE,produces="application/json")
+    public JSONObject deleteCustomer(@RequestParam String customerId,@RequestParam String resourceVersion){
+       return customerService.deleteCustomer(customerId,resourceVersion);
+    }
+    
     @ResponseBody
     @RequestMapping(value = {"/uui-lcm/customers/{customerId}/service-subscriptions"}, method = RequestMethod.GET , produces = "application/json")
     public List<AAIServiceSubscription> getServiceSubscriptions(@PathVariable(value="customerId") String customerId){
         return customerService.listServiceSubscriptions(customerId);
     }
+    
+    @ResponseBody
+    @RequestMapping(value={"/uui-lcm/customers/{customerId}/service-subscriptions/{serviceType}"},method = RequestMethod.PUT,produces="application/json")
+    public JSONObject createOrUpdateServiceType(HttpServletRequest request,@PathVariable String serviceType){
+       return customerService.createOrUpdateServiceType(request, serviceType);
+    }
+    
+    @ResponseBody
+    @RequestMapping(value={"/uui-lcm/customers/{customerId}/service-subscriptions/{serviceType}"},method = RequestMethod.DELETE,produces="application/json")
+    public JSONObject deleteServiceType(@PathVariable String customerId,@PathVariable String serviceType,@RequestParam String resourceVersion){
+       return customerService.deleteServiceType(customerId,serviceType,resourceVersion);
+    }
+    
+    @ResponseBody
+    @RequestMapping(value={"/uui-lcm/customers/{customerId}/service-subscriptions/{serviceType}"},method = RequestMethod.GET,produces="application/json")
+    public JSONObject getServiceTypeById(@PathVariable String customerId,@PathVariable String serviceType){
+       return customerService.getServiceTypeById(customerId,serviceType);
+    }
 }
index 0bd3f32..2e90655 100644 (file)
@@ -18,9 +18,27 @@ package org.onap.usecaseui.server.service.lcm;
 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer;
 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAIServiceSubscription;
 
+import com.alibaba.fastjson.JSONObject;
+
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 public interface CustomerService {
+       
     List<AAICustomer> listCustomer();
+    
+    JSONObject createOrUpdateCustomer(HttpServletRequest request,String customerId);
+    
+    JSONObject deleteCustomer(String customerId,String resourceVersion);
+    
+    JSONObject getCustomerById(String customerId);
+    
     List<AAIServiceSubscription> listServiceSubscriptions(String customerId);
+    
+    JSONObject createOrUpdateServiceType(HttpServletRequest request,String serviceType);
+    
+    JSONObject deleteServiceType(String customerId,String serviceType,String resourceVersion);
+    
+    JSONObject getServiceTypeById(String customerId,String serviceType);
 }
index 1e898c0..58ce2cb 100644 (file)
 package org.onap.usecaseui.server.service.lcm.domain.aai;
 
 import org.onap.usecaseui.server.bean.sotn.PinterfaceRsp;
-import org.onap.usecaseui.server.service.lcm.domain.aai.bean.*;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomerRsp;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAIOrchestratorRsp;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAIServiceSubscription;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAISingleOrchestratorRsp;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.SDNCControllerRsp;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstanceRsp;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceSubscriptionRsp;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfoRsp;
 
 import okhttp3.RequestBody;
 import okhttp3.ResponseBody;
@@ -38,27 +46,54 @@ public interface AAIService {
             "Accept: application/json"
     })
 //    @GET("/api/aai-business/v11/customers")
-    @GET("/api/aai-business/v11/customers")
+    @GET("/api/aai-business/v13/customers")
     Call<AAICustomerRsp> listCustomer();
-
+    
     @Headers({
-            "X-TransactionId: 7777",
-            "X-FromAppId: uui",
-            "Authorization: Basic QUFJOkFBSQ==",
-            "Accept: application/json"
+        "X-TransactionId: 7777",
+        "X-FromAppId: uui",
+        "Authorization: Basic QUFJOkFBSQ==",
+        "Accept: application/json"
+       })
+       @GET("/api/aai-externalSystem/v16/esr-nfvo-list")
+       Call<AAIOrchestratorRsp> listOrchestrator();
+    
+    @Headers({
+        "X-TransactionId: 7777",
+        "X-FromAppId: uui",
+        "Authorization: Basic QUFJOkFBSQ==",
+        "Accept: application/json"
+       })
+       @GET("/api/aai-externalSystem/v16/esr-nfvo-list/esr-nfvo/{nfvo-id}?depth=all")
+       Call<AAISingleOrchestratorRsp> getOrchestrator(@Path("nfvo-id") String nfvoId);
+    
+    @Headers({
+        "X-TransactionId: 7777",
+        "X-FromAppId: uui",
+        "Authorization: Basic QUFJOkFBSQ==",
+        "Accept: application/json"
     })
-    @GET("/api/aai-externalSystem/v16/esr-nfvo-list")
-    Call<AAIOrchestratorRsp> listOrchestrator();
-
+    @PUT("/api/aai-business/v13/customers/customer/{global-customer-id}")
+    Call<ResponseBody> createOrUpdateCustomer(@Path("global-customer-id") String customerId,@Body RequestBody body);
+    
     @Headers({
-            "X-TransactionId: 7777",
-            "X-FromAppId: uui",
-            "Authorization: Basic QUFJOkFBSQ==",
-            "Accept: application/json"
+        "X-TransactionId: 7777",
+        "X-FromAppId: uui",
+        "Authorization: Basic QUFJOkFBSQ==",
+        "Accept: application/json"
     })
-    @GET("/api/aai-externalSystem/v16/esr-nfvo-list/esr-nfvo/{nfvo-id}?depth=all")
-    Call<AAISingleOrchestratorRsp> getOrchestrator(@Path("nfvo-id") String nfvoId);
-
+    @DELETE("/api/aai-business/v13//customers/customer/{global-customer-id}")
+    Call<ResponseBody> deleteCustomer(@Path("global-customer-id") String customerId,@Query("resource-version") String resourceVersion);
+    
+    @Headers({
+        "X-TransactionId: 7777",
+        "X-FromAppId: uui",
+        "Authorization: Basic QUFJOkFBSQ==",
+        "Accept: application/json"
+    })
+    @GET("/api/aai-business/v13//customers/customer/{global-customer-id}")
+    Call<AAICustomer> getCustomerById(@Path("global-customer-id") String customerId);
+    
     @Headers({
             "X-TransactionId: 7777",
             "X-FromAppId: uui",
@@ -88,7 +123,37 @@ public interface AAIService {
 //    @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions")
     @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions")
     Call<ServiceSubscriptionRsp> listServiceSubscriptions(@Path("global-customer-id") String customerId);
-
+    
+    @Headers({
+        "X-TransactionId: 7777",
+        "X-FromAppId: uui",
+        "Authorization: Basic QUFJOkFBSQ==",
+        "Accept: application/json"
+       })
+       //@GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions")
+       @PUT("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}")
+       Call<ResponseBody> createOrUpdateServiceType(@Path("global-customer-id") String customerId,@Path("service-type") String serviceType);
+    
+    @Headers({
+        "X-TransactionId: 7777",
+        "X-FromAppId: uui",
+        "Authorization: Basic QUFJOkFBSQ==",
+        "Accept: application/json"
+       })
+       //@GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions")
+       @PUT("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}")
+       Call<ResponseBody> deleteServiceType(@Path("global-customer-id") String customerId,@Path("service-type") String serviceType,@Query("resource-version") String resourceVersion);
+    
+    @Headers({
+        "X-TransactionId: 7777",
+        "X-FromAppId: uui",
+        "Authorization: Basic QUFJOkFBSQ==",
+        "Accept: application/json"
+       })
+       //@GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions")
+       @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}")
+       Call<AAIServiceSubscription> getServiceTypeById(@Path("global-customer-id") String customerId,@Path("service-type") String serviceType);
+    
     @Headers({
             "X-TransactionId: 7777",
             "X-FromAppId: uui",
index 972dbed..d75d101 100644 (file)
@@ -27,12 +27,21 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Service;
+
+import com.alibaba.fastjson.JSONObject;
+
+import okhttp3.RequestBody;
+import okhttp3.ResponseBody;
 import retrofit2.Response;
 
+import static org.onap.usecaseui.server.util.RestfulServices.extractBody;
+
 import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 @Service("CustomerService")
 @org.springframework.context.annotation.Configuration
 @EnableAspectJAutoProxy
@@ -65,11 +74,76 @@ public class DefaultCustomerService implements CustomerService {
             throw new AAIException("AAI is not available.", e);
         }
     }
-
+    
+    @Override
+    public JSONObject createOrUpdateCustomer(HttpServletRequest request,String customerId){
+               JSONObject result = new JSONObject();
+               try {
+                       logger.info("aai createOrUpdateCustomer is starting!");
+                       RequestBody requestBody = extractBody(request);
+                       Response<ResponseBody> response = this.aaiService.createOrUpdateCustomer(customerId,requestBody).execute();
+                       logger.info("aai createOrUpdateCustomer is finished!");
+                       if(response.isSuccessful()){
+                               result.put("status", "SUCCESS");
+                       }else{
+                               result.put("status", "FAILED");
+                               result.put("errorMessage",String.format("Can not get createOrUpdateCustomer[code=%s, message=%s]", response.code(), response.message()));
+                       }
+               } catch (IOException e) {
+                       result.put("status", "FAILED");
+                       result.put("errorMessage","createOrUpdateCustomer occur exception:"+e.getMessage());
+               }
+               return result;
+    }
+    
+    @Override
+    public JSONObject getCustomerById(String customerId){
+               JSONObject result = new JSONObject();
+               try {
+                       logger.info("aai getCustomerById is starting!");
+                       Response<AAICustomer> response = this.aaiService.getCustomerById(customerId).execute();
+                       logger.info("aai getCustomerById is finished!");
+                       if(response.isSuccessful()){
+                               result.put("status", "SUCCESS");
+                               result.put("result",response.body());
+                       }else{
+                               result.put("status", "FAILED");
+                               result.put("errorMessage",String.format("Can not get getCustomerById[code=%s, message=%s]", response.code(), response.message()));
+                       }
+               } catch (IOException e) {
+                       result.put("status", "FAILED");
+                       result.put("errorMessage","getCustomerById occur exception:"+e.getMessage());
+               }
+               return result;
+    }
+    
     @Override
-    public List<AAIServiceSubscription> listServiceSubscriptions(String customerId) {
+    public JSONObject deleteCustomer(String customerId,String resourceVersion){
+               JSONObject result = new JSONObject();
+               try {
+                       logger.info("aai deleteCustomer is starting!");
+                       Response<ResponseBody> response = this.aaiService.deleteCustomer(customerId,resourceVersion).execute();
+                       logger.info("aai deleteCustomer is finished!");
+                       if(response.isSuccessful()){
+                               result.put("status", "SUCCESS");
+                       }else{
+                               result.put("status", "FAILED");
+                               result.put("errorMessage",String.format("Can not get deleteCustomer[code=%s, message=%s]", response.code(), response.message()));
+                       }
+               } catch (IOException e) {
+                       result.put("status", "FAILED");
+                       if(e.getMessage().contains("204")){
+                               result.put("status", "SUCCESS");
+                       }
+                       result.put("errorMessage","deleteCustomer occur exception:"+e.getMessage());
+               }
+               return result;
+    }
+    
+    @Override
+    public List<AAIServiceSubscription> listServiceSubscriptions(String serviceType) {
         try {
-            Response<ServiceSubscriptionRsp> response = this.aaiService.listServiceSubscriptions(customerId).execute();
+            Response<ServiceSubscriptionRsp> response = this.aaiService.listServiceSubscriptions(serviceType).execute();
             if (response.isSuccessful()) {
                 return response.body().getServiceSubscriptions();
             } else {
@@ -81,4 +155,69 @@ public class DefaultCustomerService implements CustomerService {
             throw new AAIException("AAI is not available.", e);
         }
     }
+    
+    @Override
+    public JSONObject createOrUpdateServiceType(HttpServletRequest request,String serviceType){
+               JSONObject result = new JSONObject();
+               try {
+                       logger.info("aai createOrUpdateServiceType is starting!");
+                       RequestBody requestBody = extractBody(request);
+                       Response<ResponseBody> response = this.aaiService.createOrUpdateCustomer(serviceType,requestBody).execute();
+                       logger.info("aai createOrUpdateServiceType is finished!");
+                       if(response.isSuccessful()){
+                               result.put("status", "SUCCESS");
+                       }else{
+                               result.put("status", "FAILED");
+                               result.put("errorMessage",String.format("Can not get createOrUpdateServiceType[code=%s, message=%s]", response.code(), response.message()));
+                       }
+               } catch (IOException e) {
+                       result.put("status", "FAILED");
+                       result.put("errorMessage","createOrUpdateServiceType occur exception:"+e.getMessage());
+               }
+               return result;
+    }
+    
+    @Override
+    public JSONObject deleteServiceType(String customerId,String serviceType,String resourceVersion){
+               JSONObject result = new JSONObject();
+               try {
+                       logger.info("aai deleteServiceType is starting!");
+                       Response<ResponseBody> response = this.aaiService.deleteServiceType(customerId,serviceType,resourceVersion).execute();
+                       logger.info("aai deleteServiceType is finished!");
+                       if(response.isSuccessful()){
+                               result.put("status", "SUCCESS");
+                       }else{
+                               result.put("status", "FAILED");
+                               result.put("errorMessage",String.format("Can not get deleteServiceType[code=%s, message=%s]", response.code(), response.message()));
+                       }
+               } catch (IOException e) {
+                       result.put("status", "FAILED");
+                       if(e.getMessage().contains("204")){
+                               result.put("status", "SUCCESS");
+                       }
+                       result.put("errorMessage","deleteServiceType occur exception:"+e.getMessage());
+               }
+               return result;
+    }
+    
+    @Override
+    public JSONObject getServiceTypeById(String customerId,String serviceType){
+               JSONObject result = new JSONObject();
+               try {
+                       logger.info("aai getServiceTypeById is starting!");
+                       Response<AAIServiceSubscription> response = this.aaiService.getServiceTypeById(customerId,serviceType).execute();
+                       logger.info("aai getServiceTypeById is finished!");
+                       if(response.isSuccessful()){
+                               result.put("status", "SUCCESS");
+                               result.put("result",response.body());
+                       }else{
+                               result.put("status", "FAILED");
+                               result.put("errorMessage",String.format("Can not get getServiceTypeById[code=%s, message=%s]", response.code(), response.message()));
+                       }
+               } catch (IOException e) {
+                       result.put("status", "FAILED");
+                       result.put("errorMessage","getServiceTypeById occur exception:"+e.getMessage());
+               }
+               return result;
+    }
 }