2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation.
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 java.util.UUID;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.Id;
27 import javax.persistence.Inheritance;
28 import javax.persistence.InheritanceType;
29 import javax.persistence.Table;
31 import lombok.EqualsAndHashCode;
32 import lombok.NonNull;
33 import org.apache.commons.lang3.ObjectUtils;
34 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
35 import org.onap.policy.common.parameters.annotations.NotNull;
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> {
53 private String participantId;
57 private String typeName;
61 private String typeVersion;
64 * The default Constructor creates a {@link JpaParticipantSupportedElementType} with a generated id.
67 public JpaParticipantSupportedElementType() {
68 this(UUID.randomUUID().toString());
72 * The Key Constructor creates a {@link JpaParticipantSupportedElementType} with just a generated id parameter.
74 * @param id the main id of the element type
76 public JpaParticipantSupportedElementType(@NonNull String id) {
77 this(id, UUID.randomUUID().toString());
81 * The Key Constructor creates a {@link JpaParticipantSupportedElementType} with id and participantId.
83 * @param id the main id of the element type
84 * @param participantId the participant id
86 public JpaParticipantSupportedElementType(@NonNull String id, @NonNull String participantId) {
87 this(id, participantId, "", "");
91 * The Key Constructor creates a {@link JpaParticipantSupportedElementType} object with all mandatory fields.
93 * @param id the main id of the element type
94 * @param participantId the participant id
95 * @param typeName the type name of the supported element
96 * @param typeVersion the type version of the supported element
98 public JpaParticipantSupportedElementType(@NonNull String id,
99 @NonNull String participantId,
100 @NonNull String typeName,
101 @NonNull String typeVersion) {
103 this.participantId = participantId;
104 this.typeName = typeName;
105 this.typeVersion = typeVersion;
111 * @param copyConcept the concept to copy from
113 public JpaParticipantSupportedElementType(@NonNull final JpaParticipantSupportedElementType copyConcept) {
114 this.id = copyConcept.id;
115 this.participantId = copyConcept.participantId;
116 this.typeName = copyConcept.typeName;
117 this.typeVersion = copyConcept.typeVersion;
121 * Authorative constructor.
123 * @param authorativeConcept the authorative concept to copy from
125 public JpaParticipantSupportedElementType(@NonNull final ParticipantSupportedElementType authorativeConcept) {
126 this.fromAuthorative(authorativeConcept);
130 public int compareTo(final JpaParticipantSupportedElementType other) {
138 var result = ObjectUtils.compare(participantId, other.participantId);
143 result = ObjectUtils.compare(typeName, other.typeName);
148 result = ObjectUtils.compare(id, other.id);
153 result = typeVersion.compareTo(other.typeVersion);
162 public ParticipantSupportedElementType toAuthorative() {
163 var element = new ParticipantSupportedElementType();
164 element.setId(UUID.fromString(id));
165 element.setTypeName(typeName);
166 element.setTypeVersion(typeVersion);
171 public void fromAuthorative(@NonNull ParticipantSupportedElementType participantSupportedElementType) {
172 this.id = participantSupportedElementType.getId().toString();
173 this.typeName = participantSupportedElementType.getTypeName();
174 this.typeVersion = participantSupportedElementType.getTypeVersion();