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