diff options
author | saul.gill <saul.gill@est.tech> | 2023-01-10 11:11:08 +0000 |
---|---|---|
committer | saul.gill <saul.gill@est.tech> | 2023-01-12 13:44:44 +0000 |
commit | adfe6d2d2e5b11a24208b3bce5383f1c38cec61e (patch) | |
tree | a9dd70e6e6a5f759bce1936201820aadb62ff280 /models/src/main/java/org | |
parent | 0b1764cac4b0071b66295cf14bf43b22ed3bc20d (diff) |
Add participant controller in ACM
Added participant controller
Altered openapi spec
Added participantId
Issue-ID: POLICY-4496
Change-Id: I0c0ea93dacb6927e6f16bd4638d03db6266be3bd
Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'models/src/main/java/org')
4 files changed, 60 insertions, 6 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java index 6a523fa75..c6da3c3d1 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java @@ -20,6 +20,7 @@ package org.onap.policy.clamp.models.acm.concepts; +import java.util.UUID; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -35,6 +36,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @Data @EqualsAndHashCode(callSuper = true) public class Participant extends ToscaEntity implements Comparable<Participant> { + + @NonNull + private UUID participantId; @NonNull private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); @@ -69,5 +73,6 @@ public class Participant extends ToscaEntity implements Comparable<Participant> this.definition = new ToscaConceptIdentifier(otherParticipant.definition); this.participantState = otherParticipant.participantState; this.participantType = otherParticipant.participantType; + this.participantId = otherParticipant.participantId; } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java index aec2d32d3..398daa245 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java @@ -22,6 +22,7 @@ package org.onap.policy.clamp.models.acm.persistence.concepts; import java.io.Serializable; import java.util.List; +import java.util.UUID; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.EmbeddedId; @@ -56,6 +57,10 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; public class JpaParticipant extends PfConcept implements PfAuthorative<Participant>, Serializable { private static final long serialVersionUID = -4697758484642403483L; + @Column + @NotNull + private String participantId; + @EmbeddedId @VerifyKey @NotNull @@ -94,21 +99,25 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa * @param key the key */ public JpaParticipant(@NonNull final PfConceptKey key) { - this(key, new PfConceptKey(), ParticipantState.ON_LINE); + this(UUID.randomUUID().toString(), key, new PfConceptKey(), ParticipantState.ON_LINE); } /** * The Key Constructor creates a {@link JpaParticipant} object with all mandatory fields. * + * @param participantId the participant id * @param key the key * @param definition the TOSCA definition of the participant * @param participantState the state of the participant */ - public JpaParticipant(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, - @NonNull final ParticipantState participantState) { + public JpaParticipant(@NotNull String participantId, + @NonNull final PfConceptKey key, + @NonNull final PfConceptKey definition, + @NonNull final ParticipantState participantState) { this.key = key; this.definition = definition; this.participantState = participantState; + this.participantId = participantId; } /** @@ -123,6 +132,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa this.participantState = copyConcept.participantState; this.description = copyConcept.description; this.participantType = copyConcept.participantType; + this.participantId = copyConcept.participantId; } /** @@ -144,6 +154,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa participant.setParticipantState(participantState); participant.setDescription(description); participant.setParticipantType(new ToscaConceptIdentifier(participantType)); + participant.setParticipantId(UUID.fromString(participantId)); return participant; } @@ -158,6 +169,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa this.setParticipantState(participant.getParticipantState()); this.setDescription(participant.getDescription()); this.participantType = participant.getParticipantType().asConceptKey(); + this.participantId = participant.getParticipantId().toString(); } @Override 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 3f7e297a4..91766807f 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 @@ -22,12 +22,14 @@ package org.onap.policy.clamp.models.acm.persistence.provider; import java.util.List; import java.util.Optional; +import java.util.UUID; import javax.ws.rs.core.Response.Status; import lombok.NonNull; import lombok.RequiredArgsConstructor; 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.repository.ParticipantRepository; +import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.springframework.stereotype.Service; @@ -69,6 +71,24 @@ public class ParticipantProvider { /** * Get participant. * + * @param participantId the id of the participant to get + * @return the participant found + * @throws PfModelException on errors getting participant + */ + @Transactional(readOnly = true) + public Participant getParticipantById(String participantId) { + var participant = participantRepository.findByParticipantId(participantId); + if (participant.isEmpty()) { + throw new PfModelRuntimeException(Status.NOT_FOUND, + "Participant Not Found with ID: " + participantId); + } else { + return participant.get().toAuthorative(); + } + } + + /** + * Get participant. + * * @param participantId the Id of the participant to get * @return the participant found */ @@ -84,8 +104,23 @@ public class ParticipantProvider { * @return the participant created */ public Participant saveParticipant(@NonNull final Participant participant) { + participant.setParticipantId(UUID.randomUUID()); + var result = participantRepository + .save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant")); + + // Return the saved participant + return result.toAuthorative(); + } + + /** + * Updates an existing participant. + * + * @param participant participant to update + * @return the participant updated + */ + public Participant updateParticipant(@NonNull final Participant participant) { var result = participantRepository - .save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant")); + .save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant")); // Return the saved participant return result.toAuthorative(); @@ -102,7 +137,7 @@ public class ParticipantProvider { if (jpaDeleteParticipantOpt.isEmpty()) { String errorMessage = - "delete of participant \"" + participantId + "\" failed, participant does not exist"; + "delete of participant \"" + participantId + "\" failed, participant does not exist"; throw new PfModelRuntimeException(Status.BAD_REQUEST, errorMessage); } participantRepository.delete(jpaDeleteParticipantOpt.get()); 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 2279a75cc..67ea18870 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ package org.onap.policy.clamp.models.acm.persistence.repository; +import java.util.Optional; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant; import org.onap.policy.models.base.PfConceptKey; import org.springframework.data.jpa.repository.JpaRepository; @@ -28,4 +29,5 @@ import org.springframework.stereotype.Repository; @Repository public interface ParticipantRepository extends JpaRepository<JpaParticipant, PfConceptKey>, FilterRepository { + Optional<JpaParticipant> findByParticipantId(String compositionId); } |