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.
*
* @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);
* @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 =
+++ /dev/null
-/*-
- * ============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);
-}
+++ /dev/null
-/*-
- * ============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);
- }
-}
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);
}
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;
}
@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())))
}
@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())))
}
@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);
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);
}
}
+++ /dev/null
-/*-
- * ============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);
- }
-}
+++ /dev/null
-<?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>
-
@Override
public ResponseEntity<ParticipantInformation> getParticipant(UUID participantId, UUID requestId) {
ParticipantInformation participantInformation = acmParticipantProvider
- .getParticipantById(participantId.toString());
+ .getParticipantById(participantId);
return ResponseEntity.ok().body(participantInformation);
}
@Override
public ResponseEntity<Void> orderParticipantReport(UUID participantId, UUID requestId) {
- acmParticipantProvider.sendParticipantStatusRequest(participantId.toString());
+ acmParticipantProvider.sendParticipantStatusRequest(participantId);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
}
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantStatusReqPublisher;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantInformation;
* @param participantId The UUID of the participant to get
* @return The participant
*/
- public ParticipantInformation getParticipantById(String participantId) {
+ public ParticipantInformation getParticipantById(UUID participantId) {
Participant participant = this.participantProvider.getParticipantById(participantId);
ParticipantInformation participantInformation = new ParticipantInformation();
participantInformation.setParticipant(participant);
*
* @param participantId The UUID of the participant to send request to
*/
- public void sendParticipantStatusRequest(String participantId) {
+ public void sendParticipantStatusRequest(UUID participantId) {
Participant participant = this.participantProvider.getParticipantById(participantId);
ToscaConceptIdentifier id = participant.getKey().asIdentifier();
var participant = new Participant();
participant.setName(PARTICIPANT_NAME);
participant.setVersion(PARTICIPANT_VERSION);
- when(participantProvider.getParticipants(null, null)).thenReturn(List.of(participant));
+ when(participantProvider.getParticipants()).thenReturn(List.of(participant));
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);