37b18c1133c1d3661c132104222a4f27f6fcdfdc
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / DummyTimestampEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  *  Modifications Copyright (C) 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 java.util.ArrayList;
25 import java.util.List;
26 import javax.persistence.Column;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Table;
30 import lombok.Data;
31 import lombok.EqualsAndHashCode;
32 import lombok.NonNull;
33 import org.onap.policy.common.parameters.BeanValidationResult;
34 import org.onap.policy.models.base.PfConcept;
35 import org.onap.policy.models.base.PfKey;
36 import org.onap.policy.models.base.PfTimestampKey;
37
38 @Entity
39 @Table(name = "DummyTimestampEntity")
40 @Data
41 @EqualsAndHashCode(callSuper = false)
42 public class DummyTimestampEntity extends PfConcept {
43     private static final long serialVersionUID = -2962570563281067895L;
44
45     @EmbeddedId()
46     @NonNull
47     private PfTimestampKey key;
48
49     @Column
50     private double doubleValue;
51
52     /**
53      * Default constructor.
54      */
55     public DummyTimestampEntity() {
56         this.key = new PfTimestampKey();
57         this.doubleValue = 123.45;
58     }
59
60     public DummyTimestampEntity(DummyTimestampEntity source) {
61         this.key = source.key;
62         this.doubleValue = source.doubleValue;
63     }
64
65     /**
66      * Constructor.
67      *
68      * @param key the key
69      * @param doubleValue the double value
70      */
71     public DummyTimestampEntity(final PfTimestampKey key, final double doubleValue) {
72         this.key = key;
73         this.doubleValue = doubleValue;
74     }
75
76     @Override
77     public List<PfKey> getKeys() {
78         final List<PfKey> keyList = new ArrayList<>();
79         keyList.add(getKey());
80         return keyList;
81     }
82
83     @Override
84     public BeanValidationResult validate(@NonNull String fieldName) {
85         BeanValidationResult result = new BeanValidationResult(fieldName, this);
86         result.addResult(key.validate("key"));
87         return result;
88     }
89
90     @Override
91     public void clean() {
92         key.clean();
93     }
94
95     @Override
96     public int compareTo(@NonNull final PfConcept otherObj) {
97         if (this == otherObj) {
98             return 0;
99         }
100         if (getClass() != otherObj.getClass()) {
101             return this.getClass().getName().compareTo(otherObj.getClass().getName());
102         }
103
104         final DummyTimestampEntity other = (DummyTimestampEntity) otherObj;
105
106         return Double.compare(doubleValue, other.doubleValue);
107     }
108 }