2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023-2026 OpenInfra Foundation Europe. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.models.acm.persistence.concepts;
23 import jakarta.persistence.Column;
24 import jakarta.persistence.Entity;
25 import jakarta.persistence.Id;
26 import jakarta.persistence.Inheritance;
27 import jakarta.persistence.InheritanceType;
28 import jakarta.persistence.Table;
29 import jakarta.validation.constraints.NotNull;
30 import java.util.UUID;
32 import lombok.EqualsAndHashCode;
33 import lombok.NonNull;
34 import org.apache.commons.lang3.ObjectUtils;
35 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
36 import org.onap.policy.models.base.PfAuthorative;
37 import org.onap.policy.models.base.Validated;
40 @Table(name = "ParticipantSupportedAcElements")
41 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
43 @EqualsAndHashCode(callSuper = false)
44 public class JpaParticipantSupportedElementType extends Validated
45 implements PfAuthorative<ParticipantSupportedElementType>, Comparable<JpaParticipantSupportedElementType> {
54 private String participantId;
58 private String typeName;
62 private String typeVersion;
65 * The default Constructor creates a {@link JpaParticipantSupportedElementType} with a generated id.
68 public JpaParticipantSupportedElementType() {
69 this(UUID.randomUUID().toString());
73 * The Key Constructor creates a {@link JpaParticipantSupportedElementType} with just a generated id parameter.
75 * @param id the main id of the element type
77 public JpaParticipantSupportedElementType(@NonNull String id) {
78 this(id, UUID.randomUUID().toString());
82 * The Key Constructor creates a {@link JpaParticipantSupportedElementType} with id and participantId.
84 * @param id the main id of the element type
85 * @param participantId the participant id
87 public JpaParticipantSupportedElementType(@NonNull String id, @NonNull String participantId) {
88 this(id, participantId, "", "");
92 * The Key Constructor creates a {@link JpaParticipantSupportedElementType} object with all mandatory fields.
94 * @param id the main id of the element type
95 * @param participantId the participant id
96 * @param typeName the type name of the supported element
97 * @param typeVersion the type version of the supported element
99 public JpaParticipantSupportedElementType(@NonNull String id,
100 @NonNull String participantId,
101 @NonNull String typeName,
102 @NonNull String typeVersion) {
104 this.participantId = participantId;
105 this.typeName = typeName;
106 this.typeVersion = typeVersion;
112 * @param copyConcept the concept to copy from
114 public JpaParticipantSupportedElementType(@NonNull final JpaParticipantSupportedElementType copyConcept) {
115 this.id = copyConcept.id;
116 this.participantId = copyConcept.participantId;
117 this.typeName = copyConcept.typeName;
118 this.typeVersion = copyConcept.typeVersion;
122 * Authorative constructor.
124 * @param authorativeConcept the authorative concept to copy from
126 public JpaParticipantSupportedElementType(@NonNull final ParticipantSupportedElementType authorativeConcept) {
127 this.fromAuthorative(authorativeConcept);
131 public int compareTo(final JpaParticipantSupportedElementType other) {
139 var result = ObjectUtils.compare(participantId, other.participantId);
144 result = ObjectUtils.compare(typeName, other.typeName);
149 result = ObjectUtils.compare(id, other.id);
154 result = typeVersion.compareTo(other.typeVersion);
163 public ParticipantSupportedElementType toAuthorative() {
164 var element = new ParticipantSupportedElementType();
165 element.setId(UUID.fromString(id));
166 element.setTypeName(typeName);
167 element.setTypeVersion(typeVersion);
172 public void fromAuthorative(@NonNull ParticipantSupportedElementType participantSupportedElementType) {
173 this.id = participantSupportedElementType.getId().toString();
174 this.typeName = participantSupportedElementType.getTypeName();
175 this.typeVersion = participantSupportedElementType.getTypeVersion();