Add DAO module for Models
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / DummyConceptEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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 java.util.UUID;
26
27 import javax.persistence.Column;
28 import javax.persistence.EmbeddedId;
29 import javax.persistence.Entity;
30 import javax.persistence.Table;
31
32 import lombok.Data;
33 import lombok.EqualsAndHashCode;
34 import lombok.NonNull;
35
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 import org.onap.policy.models.base.PfValidationResult;
41
42 @Entity
43 @Table(name = "DummyConceptEntity")
44 @Data
45 @EqualsAndHashCode(callSuper = false)
46 public class DummyConceptEntity extends PfConcept {
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     public DummyConceptEntity(final Double doubleValue) {
66         this.key = new PfConceptKey();
67     }
68
69     public DummyConceptEntity(final PfConceptKey key, final Double doubleValue) {
70         this.key = key;
71     }
72
73     /**
74      * Constructor.
75      *
76      * @param key the key
77      * @param uuid the uuid
78      * @param description the description
79      */
80     public DummyConceptEntity(PfConceptKey key, UUID uuid, String description) {
81         this.key = key;
82         this.uuid = uuid;
83         this.description = description;
84     }
85
86     @Override
87     public List<PfKey> getKeys() {
88         final List<PfKey> keyList = new ArrayList<>();
89         keyList.add(getKey());
90         return keyList;
91     }
92
93     @Override
94     public PfValidationResult validate(final PfValidationResult result) {
95         return key.validate(result);
96     }
97
98     @Override
99     public void clean() {
100         key.clean();
101     }
102
103     @Override
104     public PfConcept copyTo(final PfConcept target) {
105         Assertions.argumentNotNull(target, "target may not be null");
106
107         final PfConcept copyObject = target;
108         Assertions.instanceOf(copyObject, DummyConceptEntity.class);
109
110         final DummyConceptEntity copy = ((DummyConceptEntity) copyObject);
111         copy.setKey(key);
112         copy.setUuid(uuid);
113         copy.setDescription(description);
114
115         return copyObject;
116     }
117
118     @Override
119     public int compareTo(final PfConcept otherObj) {
120         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
121
122         if (this == otherObj) {
123             return 0;
124         }
125         if (getClass() != otherObj.getClass()) {
126             return this.hashCode() - otherObj.hashCode();
127         }
128
129         final DummyConceptEntity other = (DummyConceptEntity) otherObj;
130
131         if (!key.equals(other.key)) {
132             return key.compareTo(other.key);
133         }
134         if (!uuid.equals(other.uuid)) {
135             return uuid.compareTo(other.uuid);
136         }
137         return description.compareTo(other.description);
138     }
139 }