From a991c1a124824e9976aecfc52c34148bf1cd9e11 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 17 Jan 2023 10:54:33 +0000 Subject: 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 --- .../persistence/provider/ParticipantProvider.java | 21 +----- .../persistence/repository/FilterRepository.java | 40 ---------- .../repository/FilterRepositoryImpl.java | 45 ----------- .../repository/ParticipantRepository.java | 4 +- .../provider/ParticipantProviderTest.java | 33 +++------ .../repository/FilterRepositoryImplTest.java | 86 ---------------------- models/src/test/resources/META-INF/persistence.xml | 55 -------------- 7 files changed, 17 insertions(+), 267 deletions(-) delete mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java delete mode 100644 models/src/test/resources/META-INF/persistence.xml (limited to 'models/src') 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 @@ -45,19 +45,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 getParticipants(final String name, final String version) { - - return ProviderUtils.asEntityList(participantRepository.getFiltered(JpaParticipant.class, name, version)); - } - /** * Get all participants. * @@ -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 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 - */ - List getFiltered(Class 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 List getFiltered(Class 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, FilterRepository { +public interface ParticipantRepository extends JpaRepository { - Optional findByParticipantId(String compositionId); + Optional 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 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 inputParticipants = new ArrayList<>(); - private List 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 @@ - - - - - org.eclipse.persistence.jpa.PersistenceProvider - - org.onap.policy.models.base.PfConceptKey - org.onap.policy.models.dao.converters.CDataConditioner - org.onap.policy.models.dao.converters.Uuid2String - org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition - org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition - org.onap.policy.clamp.models.acm.persistence.concepts.StringToServiceTemplateConverter - org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement - org.onap.policy.clamp.models.acm.persistence.concepts.StringToMapConverter - org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant - - - - - - - - - - - - - -- cgit 1.2.3-korg