b4983449b02cf04a1a9726d294bb8709dcbc1f39
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / DummyReferenceTimestampEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.dao;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import javax.persistence.Column;
26 import javax.persistence.EmbeddedId;
27 import javax.persistence.Entity;
28 import javax.persistence.Table;
29 import lombok.Data;
30 import lombok.EqualsAndHashCode;
31 import lombok.NonNull;
32 import org.onap.policy.common.parameters.BeanValidationResult;
33 import org.onap.policy.models.base.PfConcept;
34 import org.onap.policy.models.base.PfKey;
35 import org.onap.policy.models.base.PfReferenceTimestampKey;
36
37 @Entity
38 @Table(name = "DummyReferenceTimestampEntity")
39 @Data
40 @EqualsAndHashCode(callSuper = false)
41 public class DummyReferenceTimestampEntity extends PfConcept {
42     private static final long serialVersionUID = -2962570563281067895L;
43
44     @EmbeddedId()
45     @NonNull
46     private PfReferenceTimestampKey key;
47
48     @Column
49     private double doubleValue;
50
51     /**
52      * Default constructor.
53      */
54     public DummyReferenceTimestampEntity() {
55         this.key = new PfReferenceTimestampKey();
56     }
57
58     public DummyReferenceTimestampEntity(DummyReferenceTimestampEntity source) {
59         this.key = source.key;
60     }
61
62     /**
63      * Constructor.
64      *
65      * @param key the key
66      */
67     public DummyReferenceTimestampEntity(final PfReferenceTimestampKey key) {
68         this.key = key;
69     }
70
71     @Override
72     public List<PfKey> getKeys() {
73         final List<PfKey> keyList = new ArrayList<>();
74         keyList.add(getKey());
75         return keyList;
76     }
77
78     @Override
79     public BeanValidationResult validate(@NonNull String fieldName) {
80         BeanValidationResult result = new BeanValidationResult(fieldName, this);
81         result.addResult(key.validate("key"));
82         return result;
83     }
84
85     @Override
86     public void clean() {
87         key.clean();
88     }
89
90     @Override
91     public int compareTo(@NonNull final PfConcept otherObj) {
92         if (this == otherObj) {
93             return 0;
94         }
95         if (getClass() != otherObj.getClass()) {
96             return this.getClass().getName().compareTo(otherObj.getClass().getName());
97         }
98
99         final DummyReferenceTimestampEntity other = (DummyReferenceTimestampEntity) otherObj;
100
101         return key.compareTo(other.key);
102     }
103 }