From c5e57c1b1cd0e778ebf47edd20fd9a340471ab72 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 17 Jan 2023 09:56:52 +0000 Subject: Refactor participantId as UUID As part of endpoint refactoring, refactor participantId as UUID in ACM. Issue-ID: POLICY-4521 Change-Id: I8ac652d9b2fadf9ce3220febb9c2c3ac0d3786cc Signed-off-by: FrancescoFioraEst --- .../acm/concepts/AutomationCompositionElement.java | 4 +- .../clamp/models/acm/concepts/Participant.java | 25 +----- .../models/acm/concepts/ParticipantDefinition.java | 3 +- .../models/acm/concepts/ParticipantUpdates.java | 4 +- .../dmaap/participant/ParticipantAckMessage.java | 4 +- .../dmaap/participant/ParticipantMessage.java | 4 +- .../concepts/JpaAutomationCompositionElement.java | 12 ++- .../acm/persistence/concepts/JpaParticipant.java | 100 ++++----------------- .../persistence/provider/ParticipantProvider.java | 12 +-- .../repository/ParticipantRepository.java | 5 +- 10 files changed, 37 insertions(+), 136 deletions(-) (limited to 'models/src/main/java') diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java index e5c85dd10..bea2278a8 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java @@ -50,7 +50,7 @@ public class AutomationCompositionElement { private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); @NonNull - private ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + private UUID participantId = UUID.randomUUID(); @NonNull private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED; @@ -75,7 +75,7 @@ public class AutomationCompositionElement { this.id = otherElement.id; this.definition = new ToscaConceptIdentifier(otherElement.definition); this.participantType = new ToscaConceptIdentifier(otherElement.participantType); - this.participantId = new ToscaConceptIdentifier(otherElement.participantId); + this.participantId = otherElement.participantId; this.state = otherElement.state; this.orderedState = otherElement.orderedState; this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment; 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 56c01837f..4741bafca 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 @@ -26,22 +26,18 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.NonNull; -import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * Class to represent details of a running participant instance. */ @NoArgsConstructor @Data -@EqualsAndHashCode(callSuper = true) -public class Participant extends ToscaEntity implements Comparable { +@EqualsAndHashCode +public class Participant { @NonNull private UUID participantId; - @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); @NonNull private ParticipantState participantState = ParticipantState.ON_LINE; @@ -52,29 +48,12 @@ public class Participant extends ToscaEntity implements Comparable @NonNull private Map participantSupportedElementTypes; - @Override - public String getType() { - return definition.getName(); - } - - @Override - public String getTypeVersion() { - return definition.getVersion(); - } - - @Override - public int compareTo(final Participant other) { - return compareNameVersion(this, other); - } - /** * Copy constructor. * * @param otherParticipant the participant to copy from */ public Participant(Participant otherParticipant) { - super(otherParticipant); - 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/concepts/ParticipantDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java index 949a7c47d..aff619873 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java @@ -22,6 +22,7 @@ package org.onap.policy.clamp.models.acm.concepts; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; @@ -38,7 +39,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @ToString public class ParticipantDefinition { - private ToscaConceptIdentifier participantId; + private UUID participantId; private ToscaConceptIdentifier participantType; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java index 1872a6144..031fd5c02 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java @@ -22,12 +22,12 @@ package org.onap.policy.clamp.models.acm.concepts; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** * Class to represent a participant definition update instance. @@ -38,7 +38,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @ToString public class ParticipantUpdates { - private ToscaConceptIdentifier participantId; + private UUID participantId; // List of AutomationCompositionElement values for a particular participant private List automationCompositionElementList = new ArrayList<>(); diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java index c6d56904d..8d847f8d4 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java @@ -55,7 +55,7 @@ public class ParticipantAckMessage { /** * Participant ID, or {@code null} for messages from participants. */ - private ToscaConceptIdentifier participantId; + private UUID participantId; /** * Participant State, or {@code null} for messages from participants. @@ -94,7 +94,7 @@ public class ParticipantAckMessage { * @return {@code true} if this message applies to this participant, {@code false} otherwise */ public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType, - @NonNull final ToscaConceptIdentifier participantId) { + @NonNull final UUID participantId) { // Broadcast message to all participants if (this.participantType == null) { return true; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java index c1ef4b416..525dab75f 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java @@ -55,7 +55,7 @@ public class ParticipantMessage { /** * Participant ID, or {@code null} for messages from participants. */ - private ToscaConceptIdentifier participantId; + private UUID participantId; /** * Automation Composition ID, or {@code null} for messages to participants. @@ -94,7 +94,7 @@ public class ParticipantMessage { * @return {@code true} if this message applies to this participant, {@code false} otherwise */ public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType, - @NonNull final ToscaConceptIdentifier participantId) { + @NonNull final UUID participantId) { // Broadcast message to all participants if (this.participantType == null) { return true; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java index 79576f6eb..23fc0a93e 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java @@ -85,11 +85,9 @@ public class JpaAutomationCompositionElement extends Validated @AttributeOverride(name = "version", column = @Column(name = "participant_type_version")) private PfConceptKey participantType; + @Column @NotNull - @AttributeOverride(name = "name", column = @Column(name = "participant_name")) - @AttributeOverride(name = "version", column = @Column(name = "participant_version")) - private PfConceptKey participantId; - // @formatter:on + private String participantId; @Column @NotNull @@ -154,7 +152,7 @@ public class JpaAutomationCompositionElement extends Validated this.instanceId = copyConcept.instanceId; this.definition = new PfConceptKey(copyConcept.definition); this.participantType = new PfConceptKey(copyConcept.participantType); - this.participantId = new PfConceptKey(copyConcept.participantId); + this.participantId = copyConcept.participantId; this.state = copyConcept.state; this.orderedState = copyConcept.orderedState; this.description = copyConcept.description; @@ -177,7 +175,7 @@ public class JpaAutomationCompositionElement extends Validated element.setId(UUID.fromString(elementId)); element.setDefinition(new ToscaConceptIdentifier(definition)); element.setParticipantType(new ToscaConceptIdentifier(participantType)); - element.setParticipantId(new ToscaConceptIdentifier(participantId)); + element.setParticipantId(UUID.fromString(participantId)); element.setState(state); element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); element.setDescription(description); @@ -190,7 +188,7 @@ public class JpaAutomationCompositionElement extends Validated public void fromAuthorative(@NonNull final AutomationCompositionElement element) { this.definition = element.getDefinition().asConceptKey(); this.participantType = element.getParticipantType().asConceptKey(); - this.participantId = element.getParticipantId().asConceptKey(); + this.participantId = element.getParticipantId().toString(); this.state = element.getState(); this.orderedState = element.getOrderedState(); this.description = element.getDescription(); 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 7d043ace0..b7e95cfa7 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 @@ -28,10 +28,10 @@ import java.util.UUID; import javax.persistence.AttributeOverride; import javax.persistence.CascadeType; import javax.persistence.Column; -import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.ForeignKey; +import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; @@ -46,10 +46,8 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.common.parameters.annotations.NotNull; import org.onap.policy.common.parameters.annotations.Valid; import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.base.Validated; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** @@ -62,28 +60,16 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data @EqualsAndHashCode(callSuper = false) -public class JpaParticipant extends PfConcept implements PfAuthorative, Serializable { +public class JpaParticipant extends Validated + implements PfAuthorative, Comparable, Serializable { private static final long serialVersionUID = -4697758484642403483L; - @Column + @Id @NotNull private String participantId; - @EmbeddedId - @VerifyKey - @NotNull - private PfConceptKey key; - - // @formatter:off - @VerifyKey @NotNull - @AttributeOverride(name = "name", column = @Column(name = "definition_name")) - @AttributeOverride(name = "version", column = @Column(name = "definition_version")) - private PfConceptKey definition; - // @formatter:on - - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "participant_type_name")) + @AttributeOverride(name = "name", column = @Column(name = "participant_type_name")) @AttributeOverride(name = "version", column = @Column(name = "participant_type_version")) private PfConceptKey participantType; @@ -104,36 +90,20 @@ public class JpaParticipant extends PfConcept implements PfAuthorative()); + this(UUID.randomUUID().toString(), ParticipantState.ON_LINE, new ArrayList<>()); } /** * 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(@NotNull String participantId, - @NonNull final PfConceptKey key, - @NonNull final PfConceptKey definition, - @NonNull final ParticipantState participantState, - @NonNull final List supportedAcElementTypes) { - this.key = key; - this.definition = definition; - this.participantState = participantState; + public JpaParticipant(@NonNull String participantId, @NonNull final ParticipantState participantState, + @NonNull final List supportedElements) { this.participantId = participantId; - this.supportedElements = supportedAcElementTypes; + this.participantState = participantState; + this.supportedElements = supportedElements; } /** @@ -142,9 +112,6 @@ public class JpaParticipant extends PfConcept implements PfAuthorative(this.supportedElements.size())); @@ -183,13 +146,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative(participant.getParticipantSupportedElementTypes().size()); @@ -203,42 +160,15 @@ public class JpaParticipant extends PfConcept implements PfAuthorative getKeys() { - List keyList = getKey().getKeys(); - - keyList.add(definition); - keyList.add(participantType); - - return keyList; - } - - @Override - public void clean() { - key.clean(); - definition.clean(); - description = (description == null ? null : description.trim()); - participantType.clean(); - } - - @Override - public int compareTo(final PfConcept otherConcept) { - if (otherConcept == null) { + public int compareTo(final JpaParticipant other) { + if (other == null) { return -1; } - if (this == otherConcept) { + if (this == other) { return 0; } - if (getClass() != otherConcept.getClass()) { - return getClass().getName().compareTo(otherConcept.getClass().getName()); - } - - final JpaParticipant other = (JpaParticipant) otherConcept; - int result = key.compareTo(other.key); - if (result != 0) { - return result; - } - result = definition.compareTo(other.definition); + var result = participantId.compareTo(other.participantId); if (result != 0) { return result; } 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 fa8979d58..7b8ebc038 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 @@ -29,9 +29,7 @@ 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; import org.springframework.transaction.annotation.Transactional; @@ -60,11 +58,10 @@ public class ParticipantProvider { * * @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(UUID participantId) { - var participant = participantRepository.findByParticipantId(participantId.toString()); + var participant = participantRepository.findById(participantId.toString()); if (participant.isEmpty()) { throw new PfModelRuntimeException(Status.NOT_FOUND, "Participant Not Found with ID: " + participantId); @@ -80,8 +77,8 @@ public class ParticipantProvider { * @return the participant found */ @Transactional(readOnly = true) - public Optional findParticipant(@NonNull final ToscaConceptIdentifier participantId) { - return participantRepository.findById(participantId.asConceptKey()).map(JpaParticipant::toAuthorative); + public Optional findParticipant(@NonNull final UUID participantId) { + return participantRepository.findById(participantId.toString()).map(JpaParticipant::toAuthorative); } /** @@ -91,7 +88,6 @@ 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")); @@ -120,7 +116,7 @@ public class ParticipantProvider { * @return the participant deleted */ public Participant deleteParticipant(@NonNull final UUID participantId) { - var jpaDeleteParticipantOpt = participantRepository.findByParticipantId(participantId.toString()); + var jpaDeleteParticipantOpt = participantRepository.findById(participantId.toString()); if (jpaDeleteParticipantOpt.isEmpty()) { String errorMessage = 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 b448731ba..310d9981c 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 @@ -20,14 +20,11 @@ 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; import org.springframework.stereotype.Repository; @Repository -public interface ParticipantRepository extends JpaRepository { +public interface ParticipantRepository extends JpaRepository { - Optional findByParticipantId(String participantId); } -- cgit 1.2.3-korg