Fix instance instantiation for SOTN 63/72363/1
authorguochuyicmri <guochuyi@chinamobile.com>
Sat, 10 Nov 2018 11:02:01 +0000 (19:02 +0800)
committerguochuyicmri <guochuyi@chinamobile.com>
Sat, 10 Nov 2018 11:02:11 +0000 (19:02 +0800)
Change-Id: Ib22c7c369fadd1af05bf620c0f32c9213c835864
Issue-ID: USECASEUI-167
Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
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/DefaultServiceInstanceService.java
server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java

index 6b76dcf..3210ff0 100644 (file)
@@ -52,8 +52,8 @@ public interface AAIService {
             "Accept: application/json"
     })
 //    @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances")
-    @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances")
-    Call<ServiceInstanceRsp> listServiceInstances(@Path("global-customer-id") String customerId, @Path("service-type") String serviceType);
+    @GET("/api/aai-business/v13/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances")
+    Call<ResponseBody> listServiceInstances(@Path("global-customer-id") String customerId, @Path("service-type") String serviceType);
 
     @Headers({
             "X-TransactionId: 7777",
index 5939f8f..9c42051 100644 (file)
@@ -33,12 +33,14 @@ import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer;
 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAIServiceSubscription;
 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstanceRsp;
 import org.onap.usecaseui.server.util.RestfulServices;
+import org.onap.usecaseui.server.util.UuiCommonUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Service;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -81,11 +83,12 @@ public class DefaultServiceInstanceService implements ServiceInstanceService {
     public List<String> listServiceInstances(String customerId, String serviceType) {
        List<String> result = new ArrayList<>();
         try {
-            Response<ServiceInstanceRsp> response = aaiService.listServiceInstances(customerId, serviceType).execute();
+            Response<ResponseBody> response = aaiService.listServiceInstances(customerId, serviceType).execute();
             if (response.isSuccessful()) {
-               List<String> serviceInstances = response.body().getServiceInstances();
-               if(serviceInstances.size()>0){
-                       result=this.parseServiceInstance(serviceInstances, customerId, serviceType);
+               String resultStr=new String(response.body().bytes());
+               JSONObject object = JSONObject.parseObject(resultStr);
+               if(UuiCommonUtil.isNotNullOrEmpty(object)){
+                       result=this.parseServiceInstance(object, customerId, serviceType);
                }
                 return result;
             } else {
@@ -98,11 +101,12 @@ public class DefaultServiceInstanceService implements ServiceInstanceService {
         }
     }
     
-       private List<String> parseServiceInstance(List<String> list,String customerId,String serviceType) throws JsonProcessingException{
+       private List<String> parseServiceInstance(JSONObject objects,String customerId,String serviceType) throws JsonProcessingException{
        ObjectMapper mapper = new ObjectMapper();
        List<String> result = new ArrayList<>();
-       for(String serviceInstance:list){
-                       JSONObject object =  JSON.parseObject(serviceInstance);
+       JSONArray serviceInstances=objects.getJSONArray("service-instance");
+       for(Object serviceInstance:serviceInstances){
+                       JSONObject object =  JSON.parseObject(serviceInstance+"");
                        String serviceInstanceId=object.get("service-instance-id").toString();
                        ServiceBean serviceBean = serviceLcmService.getServiceBeanByServiceInStanceId(serviceInstanceId);
                        String serviceDomain = serviceBean.getServiceDomain();
index c63bf71..4db301e 100644 (file)
@@ -42,7 +42,7 @@ public class DefaultServiceInstanceServiceTest {
         List<String> instances = Collections.singletonList("{\"service-instance-id\":\"35e88f8e-473f-4d88-92f8-6739a42baa23\",\"service-instance-name\":\"SDWANVPNInfra1\",\"service-type\":\"E2E Service\",\"service-role\":\"E2E Service\",\"model-invariant-id\":\"88dcb2f0-085b-4548-8b93-0882e37d25d8\",\"model-version-id\":\"462f84e5-f0e5-44c5-ab95-38fb4bf77064\",\"resource-version\":\"1535687551051\",\"input-parameters\":\"{\\n    \\\"service\\\":{\\n        \\\"name\\\":\\\"SDWANVPNInfra\\\",\\n        \\\"description\\\":\\\"SDWANVPNInfra\\\",\\n        \\\"serviceInvariantUuid\\\":\\\"88dcb2f0-085b-4548-8b93-0882e37d25d8\\\",\\n        \\\"serviceUuid\\\":\\\"462f84e5-f0e5-44c5-ab95-38fb4bf77064\\\",\\n        \\\"globalSubscriberId\\\":\\\"Demonstration\\\",\\n        \\\"serviceType\\\":\\\"CCVPN\\\",\\n        \\\"parameters\\\":{\\n            \\\"locationConstraints\\\":[\\n\\n            ],\\n            \\\"resources\\\":[\\n                {\\n                    \\\"resourceName\\\":\\\"SDWANConnectivity 0\\\",\\n                    \\\"resourceInvariantUuid\\\":\\\"f99a9a23-c88e-44ff-a4dc-22b88675d278\\\",\\n                    \\\"resourceUuid\\\":\\\"7baa7742-3a13-4288-8330-868015adc340\\\",\\n                    \\\"resourceCustomizationUuid\\\":\\\"94ec574b-2306-4cbd-8214-09662b040f73\\\",\\n                    \\\"parameters\\\":{\\n                        \\\"locationConstraints\\\":[\\n\\n                        ],\\n                        \\\"resources\\\":[\\n\\n                        ],\\n                        \\\"requestInputs\\\":{\\n\\n                        }\\n                    }\\n                },\\n                {\\n                    \\\"resourceName\\\":\\\"SPPartnerVF 0\\\",\\n                    \\\"resourceInvariantUuid\\\":\\\"072f9238-15b0-4bc5-a5f5-f18548739470\\\",\\n                    \\\"resourceUuid\\\":\\\"81b9430b-8abe-45d6-8bf9-f41a8f5c735f\\\",\\n                    \\\"resourceCustomizationUuid\\\":\\\"a7baba5d-6ac3-42b5-b47d-070841303ab1\\\",\\n                    \\\"parameters\\\":{\\n                        \\\"locationConstraints\\\":[\\n\\n                        ],\\n                        \\\"resources\\\":[\\n\\n                        ],\\n                        \\\"requestInputs\\\":{\\n\\n                        }\\n                    }\\n                }\\n            ],\\n            \\\"requestInputs\\\":{\\n                \\\"sdwanconnectivity0_name\\\":\\\"CMCCVPN\\\",\\n                \\\"sdwanconnectivity0_topology\\\":\\\"hub-spoke\\\"\\n            }\\n        }\\n    }\\n}\",\"relationship-list\":{\"relationship\":[{\"related-to\":\"sdwan-vpn\",\"relationship-label\":\"org.onap.relationships.inventory.PartOf\",\"related-link\":\"/aai/v13/network/sdwan-vpns/sdwan-vpn/4efe6dff-acfc-4d13-a3fd-1177d3c08e89\",\"relationship-data\":[{\"relationship-key\":\"sdwan-vpn.sdwan-vpn-id\",\"relationship-value\":\"4efe6dff-acfc-4d13-a3fd-1177d3c08e89\"}],\"related-to-property\":[{\"property-key\":\"sdwan-vpn.sdwan-vpn-name\",\"property-value\":\"vdfvpn\"}]},{\"related-to\":\"sp-partner\",\"relationship-label\":\"org.onap.relationships.inventory.PartOf\",\"related-link\":\"/aai/v13/business/sp-partners/sp-partner/1b9c677d-fddf-4b70-938b-925a7fa57d00\",\"relationship-data\":[{\"relationship-key\":\"sp-partner.sp-partner-id\",\"relationship-value\":\"1b9c677d-fddf-4b70-938b-925a7fa57d00\"}],\"related-to-property\":[{\"property-key\":\"sp-partner.sp-partner-id\",\"property-value\":\"1b9c677d-fddf-4b70-938b-925a7fa57d00\"}]},{\"related-to\":\"allotted-resource\",\"relationship-label\":\"org.onap.relationships.inventory.Uses\",\"related-link\":\"/aai/v13/business/customers/customer/Democcy/service-subscriptions/service-subscription/CCVPN/service-instances/service-instance/189b87a5-72fe-4197-a307-6929c3831f81/allotted-resources/allotted-resource/2214feec-1aef-4890-abba-f8f3a906935f\",\"relationship-data\":[{\"relationship-key\":\"customer.global-customer-id\",\"relationship-value\":\"Democcy\"},{\"relationship-key\":\"service-subscription.service-type\",\"relationship-value\":\"CCVPN\"},{\"relationship-key\":\"service-instance.service-instance-id\",\"relationship-value\":\"189b87a5-72fe-4197-a307-6929c3831f81\"},{\"relationship-key\":\"allotted-resource.id\",\"relationship-value\":\"2214feec-1aef-4890-abba-f8f3a906935f\"}],\"related-to-property\":[{\"property-key\":\"allotted-resource.description\",\"property-value\":\"2214feec-1aef-4890-abba-f8f3a906935f\"},{\"property-key\":\"allotted-resource.allotted-resource-name\",\"property-value\":\"sdwan ar\"}]},{\"related-to\":\"allotted-resource\",\"relationship-label\":\"org.onap.relationships.inventory.Uses\",\"related-link\":\"/aai/v13/business/customers/customer/Democcy/service-subscriptions/service-subscription/CCVPN/service-instances/service-instance/089b87a5-72fe-4197-a307-6929c3831f80/allotted-resources/allotted-resource/1114feec-1aef-4890-abba-f8f3a906935f\",\"relationship-data\":[{\"relationship-key\":\"customer.global-customer-id\",\"relationship-value\":\"Democcy\"},{\"relationship-key\":\"service-subscription.service-type\",\"relationship-value\":\"CCVPN\"},{\"relationship-key\":\"service-instance.service-instance-id\",\"relationship-value\":\"089b87a5-72fe-4197-a307-6929c3831f80\"},{\"relationship-key\":\"allotted-resource.id\",\"relationship-value\":\"1114feec-1aef-4890-abba-f8f3a906935f\"}],\"related-to-property\":[{\"property-key\":\"allotted-resource.description\",\"property-value\":\"1114feec-1aef-4890-abba-f8f3a906935f\"},{\"property-key\":\"allotted-resource.allotted-resource-name\",\"property-value\":\"sdwan ar\"}]}]}}");
         ServiceInstanceRsp rsp = new ServiceInstanceRsp();
         rsp.setServiceInstances(instances);
-        when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(successfulCall(rsp));
+        //when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(successfulCall(rsp));
 
         ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);