aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/main/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-17 09:56:52 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-01-23 15:22:35 +0000
commitc5e57c1b1cd0e778ebf47edd20fd9a340471ab72 (patch)
treef567d2bc52cf070bcccb83bad0f4ab5f70d2415f /models/src/main/java
parenta263a250f7185fd9ddc4b600d96452fdbf21fffb (diff)
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 <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java25
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java12
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java100
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java12
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java5
10 files changed, 37 insertions, 136 deletions
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<Participant> {
+@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<Participant>
@NonNull
private Map<UUID, ParticipantSupportedElementType> 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<AutomationCompositionElement> 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<Participant>, Serializable {
+public class JpaParticipant extends Validated
+ implements PfAuthorative<Participant>, Comparable<JpaParticipant>, 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<Participa
* The Default Constructor creates a {@link JpaParticipant} object with a null key.
*/
public JpaParticipant() {
- this(new PfConceptKey());
- }
-
- /**
- * The Key Constructor creates a {@link JpaParticipant} object with the given concept key.
- *
- * @param key the key
- */
- public JpaParticipant(@NonNull final PfConceptKey key) {
- this(UUID.randomUUID().toString(), key, new PfConceptKey(), ParticipantState.ON_LINE, new ArrayList<>());
+ 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<JpaParticipantSupportedElementType> supportedAcElementTypes) {
- this.key = key;
- this.definition = definition;
- this.participantState = participantState;
+ public JpaParticipant(@NonNull String participantId, @NonNull final ParticipantState participantState,
+ @NonNull final List<JpaParticipantSupportedElementType> supportedElements) {
this.participantId = participantId;
- this.supportedElements = supportedAcElementTypes;
+ this.participantState = participantState;
+ this.supportedElements = supportedElements;
}
/**
@@ -142,9 +112,6 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
* @param copyConcept the concept to copy from
*/
public JpaParticipant(@NonNull final JpaParticipant copyConcept) {
- super(copyConcept);
- this.key = new PfConceptKey(copyConcept.key);
- this.definition = new PfConceptKey(copyConcept.definition);
this.participantState = copyConcept.participantState;
this.description = copyConcept.description;
this.participantType = copyConcept.participantType;
@@ -165,11 +132,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
public Participant toAuthorative() {
var participant = new Participant();
- participant.setName(key.getName());
- participant.setVersion(key.getVersion());
- participant.setDefinition(new ToscaConceptIdentifier(definition));
participant.setParticipantState(participantState);
- participant.setDescription(description);
participant.setParticipantType(new ToscaConceptIdentifier(participantType));
participant.setParticipantId(UUID.fromString(participantId));
participant.setParticipantSupportedElementTypes(new LinkedHashMap<>(this.supportedElements.size()));
@@ -183,13 +146,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
@Override
public void fromAuthorative(@NonNull final Participant participant) {
- if (this.key == null || this.getKey().isNullKey()) {
- this.setKey(new PfConceptKey(participant.getName(), participant.getVersion()));
- }
-
- this.definition = participant.getDefinition().asConceptKey();
this.setParticipantState(participant.getParticipantState());
- this.setDescription(participant.getDescription());
this.participantType = participant.getParticipantType().asConceptKey();
this.participantId = participant.getParticipantId().toString();
this.supportedElements = new ArrayList<>(participant.getParticipantSupportedElementTypes().size());
@@ -203,42 +160,15 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
}
@Override
- public List<PfKey> getKeys() {
- List<PfKey> 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<Participant> findParticipant(@NonNull final ToscaConceptIdentifier participantId) {
- return participantRepository.findById(participantId.asConceptKey()).map(JpaParticipant::toAuthorative);
+ public Optional<Participant> 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<JpaParticipant, PfConceptKey> {
+public interface ParticipantRepository extends JpaRepository<JpaParticipant, String> {
- Optional<JpaParticipant> findByParticipantId(String participantId);
}