Add DB query for all model-service-ids which have a template 60/99960/5
authorAlexey Sandler <alexey.sandler@intl.att.com>
Wed, 1 Jan 2020 12:23:00 +0000 (14:23 +0200)
committerIttay Stern <ittay.stern@att.com>
Wed, 1 Jan 2020 15:30:33 +0000 (15:30 +0000)
Issue-ID: VID-739
Change-Id: Ib401f1fd312afb9652793854d49c8c7e5e115149
Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com>
vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt
vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java
vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java

index e262472..b638a03 100644 (file)
@@ -90,12 +90,16 @@ class AsyncInstantiationRepository @Autowired constructor(val dataAccessService:
                 "   and created >= '" + filterDate + "' "
     }
 
-    private fun filterInstantiatedServiceByServiceModelId(serviceModelUuid: UUID): String {
+    private fun filterByInstantiateActionStatus(): String{
         return filterServicesByNotHiddenAndNotDeleted() +
-                " and SERVICE_MODEL_ID = '$serviceModelUuid'" +
                 " and ACTION  = 'INSTANTIATE'"
     }
 
+    private fun filterInstantiatedServiceByServiceModelId(serviceModelUuid: UUID): String {
+        return filterByInstantiateActionStatus() +
+                " and SERVICE_MODEL_ID = '$serviceModelUuid'"
+    }
+
     private fun filterServicesByNotHiddenAndNotDeleted(): String {
         return " WHERE" +
                 "   hidden = false" +
@@ -157,4 +161,13 @@ class AsyncInstantiationRepository @Autowired constructor(val dataAccessService:
 
     fun listInstantiatedServicesByServiceModelId(serviceModelId: UUID): List<ServiceInfo> =
             dataAccessService.getList(ServiceInfo::class.java, filterInstantiatedServiceByServiceModelId(serviceModelId), orderByCreatedDateAndStatus(), null) as List<ServiceInfo>;
+
+    fun getAllTemplatesServiceModelIds(): Set<String> {
+        val allTemplatesInfo =
+                dataAccessService.getList(ServiceInfo::class.java, filterByInstantiateActionStatus(), null, null) as List<ServiceInfo>
+
+        return allTemplatesInfo
+                .map { it.serviceModelId }
+                .toHashSet()
+    }
 }
index 27be3fb..5f425fa 100644 (file)
@@ -32,10 +32,12 @@ import static org.hamcrest.core.IsEqual.equalTo;
 import static org.onap.vid.job.Job.JobStatus.COMPLETED;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 import java.time.LocalDateTime;
 import java.time.ZonedDateTime;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 import javax.inject.Inject;
 import org.onap.portalsdk.core.service.DataAccessService;
@@ -84,6 +86,8 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest
             MODEL_UUID, ServiceAction.INSTANTIATE);
         addNewServiceInfoWithAction(UUID.randomUUID(), "abc", "hidden", NOW, NOW, COMPLETED, true, false,
             MODEL_UUID, ServiceAction.INSTANTIATE);
+        addNewServiceInfoWithAction(UUID.randomUUID(), "abc", "4", NOW, NOW, COMPLETED, false, false,
+            MODEL_UUID_3, ServiceAction.UPDATE);
     }
 
     @DataProvider
@@ -102,6 +106,13 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest
             contains(expectedResult));
     }
 
+    @Test
+    public void getAllTemplatesServiceModelIds_givenDbWithSeveralModelIDs_2ReturnedAnd1OmittedAndDuplicatesRemoved() {
+            Set<String> actual = asyncInstantiationRepository.getAllTemplatesServiceModelIds();
+            // MODEL_UUID3 is Action=UPDATE, therefore omitted
+            assertThat(actual, equalTo(ImmutableSet.of(MODEL_UUID, MODEL_UUID_2)));
+    }
+
     @Test
     public void whenFilterServiceByNotExistUUID_emptyListIsReturned() {
         List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.listInstantiatedServicesByServiceModelId(UUID.randomUUID());
index 7c0abbe..b953500 100644 (file)
@@ -79,6 +79,7 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
 
     public static final String MODEL_UUID = "337be3fc-293e-43ec-af0b-cf932dad07e6";
     public static final String MODEL_UUID_2 = "ce052844-22ba-4030-a838-822f2b39eb9b";
+    public static final String MODEL_UUID_3 = "47a071cd-99f7-49bb-bc8b-f957979d6fe1";
 
     public static final String OWNING_ENTITY_ID = "038d99af-0427-42c2-9d15-971b99b9b489";
     public static final String JULIO_ERICKSON = "JULIO ERICKSON";