aboutsummaryrefslogtreecommitdiffstats
path: root/models/src
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-17 10:54:33 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2023-01-17 11:06:12 +0000
commita991c1a124824e9976aecfc52c34148bf1cd9e11 (patch)
treeafaeff39b2b240a36f13b6f199b1572ed0ad169b /models/src
parentadfe6d2d2e5b11a24208b3bce5383f1c38cec61e (diff)
Remove FilterRepository in ACM
As part of participantId refactoring, FilterRepository and related implementation could be removed. Issue-ID: POLICY-4522 Change-Id: Idb078989871f1f65615a7df90aea69f7cd822dae Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java21
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java40
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java45
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java4
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java33
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java86
-rw-r--r--models/src/test/resources/META-INF/persistence.xml55
7 files changed, 17 insertions, 267 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
index 91766807f..fa8979d58 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
@@ -46,19 +46,6 @@ public class ParticipantProvider {
private final ParticipantRepository participantRepository;
/**
- * Get participants.
- *
- * @param name the name of the participant to get, null to get all participants
- * @param version the version of the participant to get, null to get all participants
- * @return the participants found
- */
- @Transactional(readOnly = true)
- public List<Participant> getParticipants(final String name, final String version) {
-
- return ProviderUtils.asEntityList(participantRepository.getFiltered(JpaParticipant.class, name, version));
- }
-
- /**
* Get all participants.
*
* @return the participants found
@@ -76,8 +63,8 @@ public class ParticipantProvider {
* @throws PfModelException on errors getting participant
*/
@Transactional(readOnly = true)
- public Participant getParticipantById(String participantId) {
- var participant = participantRepository.findByParticipantId(participantId);
+ public Participant getParticipantById(UUID participantId) {
+ var participant = participantRepository.findByParticipantId(participantId.toString());
if (participant.isEmpty()) {
throw new PfModelRuntimeException(Status.NOT_FOUND,
"Participant Not Found with ID: " + participantId);
@@ -132,8 +119,8 @@ public class ParticipantProvider {
* @param participantId the Id of the participant to delete
* @return the participant deleted
*/
- public Participant deleteParticipant(@NonNull final ToscaConceptIdentifier participantId) {
- var jpaDeleteParticipantOpt = participantRepository.findById(participantId.asConceptKey());
+ public Participant deleteParticipant(@NonNull final UUID participantId) {
+ var jpaDeleteParticipantOpt = participantRepository.findByParticipantId(participantId.toString());
if (jpaDeleteParticipantOpt.isEmpty()) {
String errorMessage =
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java
deleted file mode 100644
index fb4c0bc48..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.models.acm.persistence.repository;
-
-import java.util.List;
-import org.onap.policy.models.base.PfConcept;
-
-public interface FilterRepository {
-
- /**
- * Get an object from the database, referred to by concept key.
- *
- * @param <T> the type of the object to get, a subclass of {@link PfConcept}
- * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts
- * of type T are returned, if name is not null and version is null, all versions of that concept matching the
- * name are returned.
- * @param name the name of the object to get, null returns all objects
- * @param version the version the object to get, null returns all objects for a specified name
- * @return the objects that was retrieved from the database
- */
- <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java
deleted file mode 100644
index 470f05379..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.models.acm.persistence.repository;
-
-import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.onap.policy.models.base.PfConcept;
-import org.onap.policy.models.dao.PfDao;
-import org.onap.policy.models.dao.impl.ProxyDao;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public class FilterRepositoryImpl implements FilterRepository {
-
- @PersistenceContext
- private EntityManager entityManager;
-
- protected PfDao getPfDao() {
- return new ProxyDao(entityManager);
- }
-
- @Override
- public <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version) {
- return getPfDao().getFiltered(someClass, name, version);
- }
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java
index 67ea18870..b448731ba 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java
@@ -27,7 +27,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
-public interface ParticipantRepository extends JpaRepository<JpaParticipant, PfConceptKey>, FilterRepository {
+public interface ParticipantRepository extends JpaRepository<JpaParticipant, PfConceptKey> {
- Optional<JpaParticipant> findByParticipantId(String compositionId);
+ Optional<JpaParticipant> findByParticipantId(String participantId);
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
index 6e6637c7e..ccb20ea8e 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
@@ -24,13 +24,13 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
+import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.Participant;
@@ -60,7 +60,7 @@ class ParticipantProviderTest {
}
@Test
- void testParticipantSave() throws Exception {
+ void testParticipantSave() {
var participantRepository = mock(ParticipantRepository.class);
for (var participant : jpaParticipantList) {
when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion())))
@@ -78,7 +78,7 @@ class ParticipantProviderTest {
}
@Test
- void testParticipantUpdate() throws Exception {
+ void testParticipantUpdate() {
var participantRepository = mock(ParticipantRepository.class);
for (var participant : jpaParticipantList) {
when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion())))
@@ -97,22 +97,10 @@ class ParticipantProviderTest {
}
@Test
- void testGetAutomationCompositions() throws Exception {
+ void testGetAutomationCompositions() {
var participantRepository = mock(ParticipantRepository.class);
var participantProvider = new ParticipantProvider(participantRepository);
- // Return empty list when no data present in db
- List<Participant> getResponse = participantProvider.getParticipants(null, null);
- assertThat(getResponse).isEmpty();
-
- String name = inputParticipants.get(0).getName();
- String version = inputParticipants.get(0).getVersion();
- when(participantRepository.getFiltered(any(), eq(name), eq(version)))
- .thenReturn(List.of(jpaParticipantList.get(0)));
- assertEquals(1, participantProvider.getParticipants(name, version).size());
-
- assertThat(participantProvider.getParticipants("invalid_name", "1.0.1")).isEmpty();
-
assertThat(participantProvider.findParticipant(INVALID_ID)).isEmpty();
when(participantRepository.findAll()).thenReturn(jpaParticipantList);
@@ -122,23 +110,24 @@ class ParticipantProviderTest {
Optional.ofNullable(jpaParticipantList.get(0)));
var participant = participantProvider.getParticipantById(inputParticipants.get(0)
- .getParticipantId().toString());
+ .getParticipantId());
assertThat(participant).isEqualTo(inputParticipants.get(0));
}
@Test
- void testDeleteParticipant() throws Exception {
+ void testDeleteParticipant() {
var participantRepository = mock(ParticipantRepository.class);
var participantProvider = new ParticipantProvider(participantRepository);
- assertThatThrownBy(() -> participantProvider.deleteParticipant(INVALID_ID))
+ var participantId = UUID.randomUUID();
+ assertThatThrownBy(() -> participantProvider.deleteParticipant(participantId))
.hasMessageMatching(".*.failed, participant does not exist");
- when(participantRepository.findById(any())).thenReturn(Optional.of(jpaParticipantList.get(0)));
+ when(participantRepository.findByParticipantId(participantId.toString()))
+ .thenReturn(Optional.of(jpaParticipantList.get(0)));
- Participant deletedParticipant =
- participantProvider.deleteParticipant(inputParticipants.get(0).getDefinition());
+ var deletedParticipant = participantProvider.deleteParticipant(participantId);
assertEquals(inputParticipants.get(0), deletedParticipant);
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java
deleted file mode 100644
index c441c2fe8..000000000
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.models.acm.persistence.repository;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
-import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.dao.PfDao;
-import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.provider.impl.ModelsProvider;
-
-class FilterRepositoryImplTest {
- private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json";
- private final List<Participant> inputParticipants = new ArrayList<>();
- private List<JpaParticipant> jpaParticipantList;
- private final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
- private static final Coder CODER = new StandardCoder();
-
- private static final AtomicInteger dbNameCounter = new AtomicInteger();
- private PfDao pfDao;
-
- @BeforeEach
- void beforeSetupDao() throws Exception {
- var parameters = new PolicyModelsProviderParameters();
- parameters.setDatabaseDriver("org.h2.Driver");
- parameters.setName("PolicyProviderParameterGroup");
- parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
- parameters.setDatabaseUrl("jdbc:h2:mem:automationCompositionProviderTestDb" + dbNameCounter.getAndDecrement());
- parameters.setDatabaseUser("policy");
- parameters.setDatabasePassword("P01icY");
- parameters.setPersistenceUnit("ToscaConceptTest");
-
- pfDao = ModelsProvider.init(parameters);
- inputParticipants.add(CODER.decode(originalJson, Participant.class));
- jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant");
- pfDao.createCollection(jpaParticipantList);
- }
-
- @Test
- void testGetPfDao() {
- assertThat(new FilterRepositoryImpl().getPfDao()).isNotNull();
- }
-
- @Test
- void testGetFilteredParams() {
- var filterRepositoryImpl = new FilterRepositoryImpl() {
- @Override
- protected PfDao getPfDao() {
- return pfDao;
- }
- };
- var result = filterRepositoryImpl.getFiltered(JpaParticipant.class, null, null);
- assertThat(result).hasSize(1);
-
- result = filterRepositoryImpl.getFiltered(JpaParticipant.class, jpaParticipantList.get(0).getName(), null);
- assertThat(result).hasSize(1);
- }
-}
diff --git a/models/src/test/resources/META-INF/persistence.xml b/models/src/test/resources/META-INF/persistence.xml
deleted file mode 100644
index 3c570b11e..000000000
--- a/models/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2021-2022 Nordix Foundation.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
- <persistence-unit name="ToscaConceptTest" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.models.base.PfConceptKey</class>
- <class>org.onap.policy.models.dao.converters.CDataConditioner</class>
- <class>org.onap.policy.models.dao.converters.Uuid2String</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.StringToServiceTemplateConverter</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.StringToMapConverter</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant</class>
-
- <properties>
- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
- <property name="eclipselink.ddl-generation.output-mode" value="database" />
- <property name="eclipselink.logging.level" value="INFO" />
-
-
- <!--property name="eclipselink.logging.level" value="ALL" />
- <property name="eclipselink.logging.level.jpa" value="ALL" />
- <property name="eclipselink.logging.level.ddl" value="ALL" />
- <property name="eclipselink.logging.level.connection" value="ALL" />
- <property name="eclipselink.logging.level.sql" value="ALL" />
- <property name="eclipselink.logging.level.transaction" value="ALL" />
- <property name="eclipselink.logging.level.sequencing" value="ALL" />
- <property name="eclipselink.logging.level.server" value="ALL" />
- <property name="eclipselink.logging.level.query" value="ALL" />
- <property name="eclipselink.logging.level.properties" value="ALL" /-->
-
- </properties>
- </persistence-unit>
-</persistence>
-