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