Add query param option for filtering services info by service model id 89/98989/4
authorSara Weiss <sara.weiss@intl.att.com>
Mon, 2 Dec 2019 07:05:58 +0000 (09:05 +0200)
committerEylon Malin <eylon.malin@intl.att.com>
Mon, 2 Dec 2019 07:58:15 +0000 (07:58 +0000)
Issue-ID: VID-724
Signed-off-by: Sara Weiss <sara.weiss@intl.att.com>
Change-Id: I72c78dd3c0e156688092ce4ac3793bc3e8c37352

vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt
vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java

index 6bd98ff..706985f 100644 (file)
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.UUID;
 import javax.servlet.http.HttpServletRequest;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.vid.dal.AsyncInstantiationRepository;
 import org.onap.vid.exceptions.AccessDeniedException;
 import org.onap.vid.model.JobAuditStatus;
 import org.onap.vid.model.ServiceInfo;
@@ -53,6 +54,7 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
     public static final String ASYNC_INSTANTIATION = "asyncInstantiation";
 
     protected final AsyncInstantiationBusinessLogic asyncInstantiationBL;
+    protected final AsyncInstantiationRepository asyncInstantiationRepository;
     private final SystemPropertiesWrapper systemPropertiesWrapper;
 
     private final RoleProvider roleProvider;
@@ -63,8 +65,11 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
     protected AuditService auditService;
 
     @Autowired
-    public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL, RoleProvider roleProvider, FeatureManager featureManager, SystemPropertiesWrapper systemPropertiesWrapper) {
+    public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL,
+        AsyncInstantiationRepository asyncInstantiationRepository, RoleProvider roleProvider,
+        FeatureManager featureManager, SystemPropertiesWrapper systemPropertiesWrapper) {
         this.asyncInstantiationBL = asyncInstantiationBL;
+        this.asyncInstantiationRepository = asyncInstantiationRepository;
         this.roleProvider = roleProvider;
         this.featureManager = featureManager;
         this.systemPropertiesWrapper = systemPropertiesWrapper;
@@ -76,8 +81,13 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
      * @return the services list
      */
     @RequestMapping(method = RequestMethod.GET)
-    public List<ServiceInfo> getServicesInfo(HttpServletRequest request) {
-        return asyncInstantiationBL.getAllServicesInfo();
+    public List<ServiceInfo> getServicesInfo(HttpServletRequest request,
+        @RequestParam(value = "serviceModelId", required = false) UUID serviceModelId) {
+        if (serviceModelId == null) {
+            return asyncInstantiationBL.getAllServicesInfo();
+        } else {
+            return  asyncInstantiationRepository.listServicesByServiceModelId(serviceModelId);
+        }
     }
 
     @RequestMapping(value = "bulk", method = RequestMethod.POST)
index 43d5016..c26b88a 100644 (file)
@@ -154,6 +154,6 @@ class AsyncInstantiationRepository @Autowired constructor(val dataAccessService:
         return dataAccessService.getList(className, " WHERE $condition", orderBy, null) as List<T>
     }
 
-    fun listServicesByServiceModelId(modelUuid: UUID): List<ServiceInfo> =
-            dataAccessService.getList(ServiceInfo::class.java, filterByServiceModelId(modelUuid), orderByCreatedDateAndStatus(), null) as List<ServiceInfo>;
+    fun listServicesByServiceModelId(serviceModelId: UUID): List<ServiceInfo> =
+            dataAccessService.getList(ServiceInfo::class.java, filterByServiceModelId(serviceModelId), orderByCreatedDateAndStatus(), null) as List<ServiceInfo>;
 }
index 8fe0580..78257b3 100644 (file)
@@ -2,6 +2,7 @@ package org.onap.vid.api;
 
 import static java.util.Collections.emptyMap;
 import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toSet;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.hasItems;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -50,6 +51,9 @@ import org.onap.vid.model.asyncInstantiation.JobAuditStatus.SourceStatus;
 import org.onap.vid.model.asyncInstantiation.ServiceInfo;
 import org.onap.vid.more.LoggerFormatTest;
 import org.onap.vid.more.LoggerFormatTest.LogName;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -121,6 +125,27 @@ public class AsyncInstantiationALaCarteApiTest extends AsyncInstantiationBase {
         assertAuditStatuses(jobId, vidAuditStatusesCompleted(jobId), msoAuditStatusesCompleted(jobId));
     }
 
+    @Test
+    public void deployTwoServicesGetServicesFilterByModelId() {
+        final ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> names = ImmutableMap
+            .of(SERVICE_NAME, "calazixide85");
+
+        final List<String> uuids1 = createBulkOfInstances(false, 2, names, CREATE_BULK_OF_ALACARTE_REQUEST);
+        final List<String> uuids2 = createBulkOfInstances(false, 1, names, DELETE_BULK_OF_ALACARTE_REQUEST);
+
+        String SERVICE_MODEL_UUID = "e3c34d88-a216-4f1d-a782-9af9f9588705";
+        ResponseEntity<List<ServiceInfo>> response = restTemplate.exchange(
+            getServiceInfoUrl() + "?serviceModelId=" + SERVICE_MODEL_UUID,
+            HttpMethod.GET,
+            null,
+            new ParameterizedTypeReference<List<ServiceInfo>>() {
+            });
+        assertThat(response.getBody().stream().map(x -> x.serviceModelId).collect(toSet()),
+            contains(SERVICE_MODEL_UUID));
+
+    }
+
+
     @Test
     public void deleteServiceWithTwoVnfGroups_andRetry() {
         String parentServiceInstanceId = "service-instance-id";