Java 17 Upgrade
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / DummyConceptEntity.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.dao;
23
24 import jakarta.persistence.Column;
25 import jakarta.persistence.EmbeddedId;
26 import jakarta.persistence.Entity;
27 import jakarta.persistence.Table;
28 import java.io.Serial;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.UUID;
32 import lombok.Data;
33 import lombok.EqualsAndHashCode;
34 import lombok.NonNull;
35 import org.onap.policy.common.parameters.BeanValidationResult;
36 import org.onap.policy.common.utils.validation.Assertions;
37 import org.onap.policy.models.base.PfConcept;
38 import org.onap.policy.models.base.PfConceptKey;
39 import org.onap.policy.models.base.PfKey;
40
41 @Entity
42 @Table(name = "DummyConceptEntity")
43 @Data
44 @EqualsAndHashCode(callSuper = false)
45 public class DummyConceptEntity extends PfConcept {
46     @Serial
47     private static final long serialVersionUID = -2962570563281067894L;
48
49     @EmbeddedId()
50     @NonNull
51     private PfConceptKey key;
52
53     @Column
54     @NonNull
55     private UUID uuid;
56
57     @Column
58     @NonNull
59     private String description;
60
61     public DummyConceptEntity() {
62         this.key = new PfConceptKey();
63     }
64
65     /**
66      * Copy constructor.
67      *
68      * @param source object from which to copy
69      */
70     public DummyConceptEntity(DummyConceptEntity source) {
71         this.key = source.key;
72         this.uuid = source.uuid;
73         this.description = source.description;
74     }
75
76     public DummyConceptEntity(final Double doubleValue) {
77         this.key = new PfConceptKey();
78     }
79
80     public DummyConceptEntity(final PfConceptKey key, final Double doubleValue) {
81         this.key = key;
82     }
83
84     /**
85      * Constructor.
86      *
87      * @param key the key
88      * @param uuid the uuid
89      * @param description the description
90      */
91     public DummyConceptEntity(PfConceptKey key, UUID uuid, String description) {
92         this.key = key;
93         this.uuid = uuid;
94         this.description = description;
95     }
96
97     @Override
98     public List<PfKey> getKeys() {
99         final List<PfKey> keyList = new ArrayList<>();
100         keyList.add(getKey());
101         return keyList;
102     }
103
104     @Override
105     public BeanValidationResult validate(@NonNull String fieldName) {
106         BeanValidationResult result = new BeanValidationResult(fieldName, this);
107         result.addResult(key.validate("key"));
108         return result;
109     }
110
111     @Override
112     public void clean() {
113         key.clean();
114     }
115
116     @Override
117     public int compareTo(final PfConcept otherObj) {
118         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
119
120         if (this == otherObj) {
121             return 0;
122         }
123         if (getClass() != otherObj.getClass()) {
124             return this.hashCode() - otherObj.hashCode();
125         }
126
127         final DummyConceptEntity other = (DummyConceptEntity) otherObj;
128
129         if (!key.equals(other.key)) {
130             return key.compareTo(other.key);
131         }
132         if (!uuid.equals(other.uuid)) {
133             return uuid.compareTo(other.uuid);
134         }
135         return description.compareTo(other.description);
136     }
137 }