summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Sandler <alexey.sandler@intl.att.com>2020-01-01 14:23:00 +0200
committerIttay Stern <ittay.stern@att.com>2020-01-01 15:30:33 +0000
commit0dbffafcc772e363fa6318c982a4b298ddab88cb (patch)
tree55f089ebebc0fe4bd5c6f5caee0da3a65248904d
parentd0bbdebeede7de26bccbb9f79809a460da89e46d (diff)
Add DB query for all model-service-ids which have a template
Issue-ID: VID-739 Change-Id: Ib401f1fd312afb9652793854d49c8c7e5e115149 Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/dal/AsyncInstantiationRepository.kt17
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java11
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java1
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<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()
+ }
}
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
@@ -103,6 +107,13 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest
}
@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());
assertThat(serviceInfoListResult, is(empty()));
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";