From 0dbffafcc772e363fa6318c982a4b298ddab88cb Mon Sep 17 00:00:00 2001 From: Alexey Sandler Date: Wed, 1 Jan 2020 14:23:00 +0200 Subject: Add DB query for all model-service-ids which have a template Issue-ID: VID-739 Change-Id: Ib401f1fd312afb9652793854d49c8c7e5e115149 Signed-off-by: Alexey Sandler --- .../org/onap/vid/dal/AsyncInstantiationRepository.kt | 17 +++++++++++++++-- .../onap/vid/dal/AsyncInstantiationRepositoryTest.java | 11 +++++++++++ .../onap/vid/services/AsyncInstantiationBaseTest.java | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt b/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt index e26247281..b638a03e3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt +++ b/vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt @@ -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 = dataAccessService.getList(ServiceInfo::class.java, filterInstantiatedServiceByServiceModelId(serviceModelId), orderByCreatedDateAndStatus(), null) as List; + + fun getAllTemplatesServiceModelIds(): Set { + val allTemplatesInfo = + dataAccessService.getList(ServiceInfo::class.java, filterByInstantiateActionStatus(), null, null) as List + + return allTemplatesInfo + .map { it.serviceModelId } + .toHashSet() + } } diff --git a/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java b/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java index 27be3fb50..5f425fa3e 100644 --- a/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java @@ -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 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 serviceInfoListResult = asyncInstantiationRepository.listInstantiatedServicesByServiceModelId(UUID.randomUUID()); diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java index 7c0abbe6e..b9535000a 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java @@ -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"; -- cgit 1.2.3-korg