Add policy metadataSet handling as node templates
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / DummyGeneratedIdEntity.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.Date;
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 javax.persistence.Temporal;
31 import javax.persistence.TemporalType;
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.models.base.PfConcept;
37 import org.onap.policy.models.base.PfGeneratedIdKey;
38 import org.onap.policy.models.base.PfKey;
39
40
41 @Entity
42 @Table(name = "DummyGeneratedIdEntity")
43 @Data
44 @EqualsAndHashCode(callSuper = false)
45 public class DummyGeneratedIdEntity extends PfConcept {
46     private static final long serialVersionUID = -2962570563281067896L;
47
48     @EmbeddedId()
49     @NonNull
50     private PfGeneratedIdKey key;
51
52     @Column(precision = 3)
53     @Temporal(TemporalType.TIMESTAMP)
54     private Date timeStamp;
55
56     @Column
57     private double doubleValue;
58
59     /**
60      * Default constructor.
61      */
62     public DummyGeneratedIdEntity() {
63         this.key = new PfGeneratedIdKey();
64         this.timeStamp = new Date();
65     }
66
67     public DummyGeneratedIdEntity(DummyGeneratedIdEntity source) {
68         this.key = source.key;
69         this.timeStamp = source.timeStamp;
70     }
71
72     /**
73      * Constructor.
74      *
75      * @param key the key
76      * @param timeStamp the date value
77      */
78     public DummyGeneratedIdEntity(final PfGeneratedIdKey key, final Date timeStamp) {
79         this.key = key;
80         this.timeStamp = timeStamp;
81     }
82
83     /**
84      * Constructor.
85      *
86      * @param key the key
87      * @param timeStamp the date value
88      * @param doubleValue the double value     *
89      */
90     public DummyGeneratedIdEntity(final PfGeneratedIdKey key, final Date timeStamp, final double doubleValue) {
91         this.key = key;
92         this.timeStamp = timeStamp;
93         this.doubleValue = doubleValue;
94     }
95
96     @Override
97     public List<PfKey> getKeys() {
98         final List<PfKey> keyList = new ArrayList<>();
99         keyList.add(getKey());
100         return keyList;
101     }
102
103     @Override
104     public BeanValidationResult validate(@NonNull String fieldName) {
105         BeanValidationResult result = new BeanValidationResult(fieldName, this);
106         result.addResult(key.validate("key"));
107         return result;
108     }
109
110     @Override
111     public void clean() {
112         key.clean();
113     }
114
115     @Override
116     public int compareTo(@NonNull final PfConcept otherObj) {
117         if (this == otherObj) {
118             return 0;
119         }
120
121         if (getClass() != otherObj.getClass()) {
122             return this.getClass().getName().compareTo(otherObj.getClass().getName());
123         }
124
125         final DummyGeneratedIdEntity other = (DummyGeneratedIdEntity) otherObj;
126         if (this.timeStamp != other.timeStamp) {
127             return  timeStamp.compareTo(other.timeStamp);
128         }
129         return  Double.compare(doubleValue, other.doubleValue);
130     }
131
132 }