Java 17 Upgrade
[policy/models.git] / models-base / src / test / java / org / onap / policy / models / base / testconcepts / DummyPfConcept.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019, 2023 Nordix Foundation.
4  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.base.testconcepts;
23
24 import jakarta.persistence.EmbeddedId;
25 import java.io.Serial;
26 import java.util.List;
27 import lombok.Data;
28 import lombok.EqualsAndHashCode;
29 import lombok.NonNull;
30 import org.apache.commons.lang3.ObjectUtils;
31 import org.onap.policy.common.parameters.annotations.NotBlank;
32 import org.onap.policy.common.parameters.annotations.NotNull;
33 import org.onap.policy.models.base.PfAuthorative;
34 import org.onap.policy.models.base.PfConcept;
35 import org.onap.policy.models.base.PfConceptKey;
36 import org.onap.policy.models.base.PfKey;
37 import org.onap.policy.models.base.validation.annotations.VerifyKey;
38
39 @Data
40 @EqualsAndHashCode(callSuper = false)
41 public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuthorativeConcept> {
42     @Serial
43     private static final long serialVersionUID = 1L;
44
45     @EmbeddedId
46     @VerifyKey
47     @NotNull
48     private PfConceptKey key;
49
50     @NotBlank
51     private String description;
52
53
54     /**
55      * The Default Constructor creates a {@link DummyPfConcept} object with a null key.
56      */
57     public DummyPfConcept() {
58         this(new PfConceptKey());
59     }
60
61     /**
62      * The Key Constructor creates a {@link DummyPfConcept} object with the given concept key.
63      *
64      * @param key the key
65      */
66     public DummyPfConcept(@NonNull final PfConceptKey key) {
67         this.key = key;
68     }
69
70     /**
71      * Copy constructor.
72      *
73      * @param copyConcept the concept to copy from
74      */
75     public DummyPfConcept(final DummyPfConcept copyConcept) {
76         super(copyConcept);
77         this.key = new PfConceptKey(copyConcept.key);
78         this.description = copyConcept.description;
79     }
80
81     @Override
82     public DummyAuthorativeConcept toAuthorative() {
83         DummyAuthorativeConcept dac = new DummyAuthorativeConcept();
84         dac.setName(key.getName());
85         dac.setVersion(key.getVersion());
86         dac.setDescription(description);
87
88         return dac;
89     }
90
91     @Override
92     public void fromAuthorative(DummyAuthorativeConcept dac) {
93         key.setName(dac.getName());
94         key.setVersion(dac.getVersion());
95         description = dac.getDescription();
96     }
97
98     @Override
99     public List<PfKey> getKeys() {
100         return getKey().getKeys();
101     }
102
103     @Override
104     public void clean() {
105         key.clean();
106
107         description = (description != null ? description.trim() : null);
108     }
109
110     @Override
111     public int compareTo(final PfConcept otherConcept) {
112         if (otherConcept == null) {
113             return -1;
114         }
115         if (this == otherConcept) {
116             return 0;
117         }
118         if (getClass() != otherConcept.getClass()) {
119             return this.hashCode() - otherConcept.hashCode();
120         }
121
122         final DummyPfConcept other = (DummyPfConcept) otherConcept;
123         if (!key.equals(other.key)) {
124             return key.compareTo(other.key);
125         }
126
127         return ObjectUtils.compare(description, other.description);
128     }
129 }