From 81c25b176b3c7e5206bf7d059e79d6cd00f9850e Mon Sep 17 00:00:00 2001 From: guochuyicmri Date: Tue, 2 Apr 2019 17:56:37 +0800 Subject: Add backend Code for customer/serviceType management UI page Change-Id: Ie1937cf1983c420231a8f4fb6ec5cba131f09d5a Issue-ID: USECASEUI-213 Signed-off-by: guochuyicmri --- server/pom.xml | 2 +- .../server/controller/lcm/CustomerController.java | 43 +++++- .../server/service/lcm/CustomerService.java | 18 +++ .../server/service/lcm/domain/aai/AAIService.java | 101 +++++++++++--- .../service/lcm/impl/DefaultCustomerService.java | 145 ++++++++++++++++++++- 5 files changed, 286 insertions(+), 23 deletions(-) diff --git a/server/pom.xml b/server/pom.xml index 6d575bba..5ef9f200 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -35,7 +35,7 @@ UTF-8 1.8 5.3.6.Final - 4.3.15.RELEASE + 4.3.4.RELEASE 1.0.2 1.4 2.9.0 diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java index 9d332e7b..22bda7e4 100644 --- a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/CustomerController.java @@ -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 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 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); + } } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/CustomerService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/CustomerService.java index 0bd3f323..2e906550 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/CustomerService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/CustomerService.java @@ -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 listCustomer(); + + JSONObject createOrUpdateCustomer(HttpServletRequest request,String customerId); + + JSONObject deleteCustomer(String customerId,String resourceVersion); + + JSONObject getCustomerById(String customerId); + List listServiceSubscriptions(String customerId); + + JSONObject createOrUpdateServiceType(HttpServletRequest request,String serviceType); + + JSONObject deleteServiceType(String customerId,String serviceType,String resourceVersion); + + JSONObject getServiceTypeById(String customerId,String serviceType); } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java index 1e898c06..58ce2cb5 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java @@ -16,7 +16,15 @@ 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 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 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 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 listOrchestrator(); - + @PUT("/api/aai-business/v13/customers/customer/{global-customer-id}") + Call 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 getOrchestrator(@Path("nfvo-id") String nfvoId); - + @DELETE("/api/aai-business/v13//customers/customer/{global-customer-id}") + Call 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 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 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 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 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 getServiceTypeById(@Path("global-customer-id") String customerId,@Path("service-type") String serviceType); + @Headers({ "X-TransactionId: 7777", "X-FromAppId: uui", diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java index 972dbedc..d75d101a 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java @@ -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 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 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 listServiceSubscriptions(String customerId) { + public JSONObject deleteCustomer(String customerId,String resourceVersion){ + JSONObject result = new JSONObject(); + try { + logger.info("aai deleteCustomer is starting!"); + Response 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 listServiceSubscriptions(String serviceType) { try { - Response response = this.aaiService.listServiceSubscriptions(customerId).execute(); + Response 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 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 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 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; + } } -- cgit 1.2.3-korg