da478f0dd2ca46745f006949e428ae5fd47166bf
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.testsuites.integration.context.entities;
24
25 import java.util.Arrays;
26 import java.util.List;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Table;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
32 import lombok.AllArgsConstructor;
33 import lombok.EqualsAndHashCode;
34 import lombok.Getter;
35 import lombok.Setter;
36 import lombok.ToString;
37 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
38 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
39 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
40 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
41 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
42
43 /**
44  * The Class ReferenceKeyTestEntity provides a reference key test concept.
45  */
46 @Entity
47 @Table(name = "ReferenceKeyTestEntity")
48 @Getter
49 @Setter
50 @ToString
51 @EqualsAndHashCode(callSuper = false)
52 @AllArgsConstructor
53 public class ReferenceKeyTestEntity extends AxConcept {
54     private static final long serialVersionUID = -2962570563281067895L;
55
56     @EmbeddedId()
57     @XmlElement(name = "key", required = true)
58     @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
59     protected AxReferenceKey key;
60
61     private double doubleValue;
62
63     /**
64      * Instantiates a new reference key test entity.
65      */
66     public ReferenceKeyTestEntity() {
67         this.key = new AxReferenceKey();
68         this.doubleValue = 0;
69     }
70
71     /**
72      * Instantiates a new reference key test entity.
73      *
74      * @param doubleValue the double value
75      */
76     public ReferenceKeyTestEntity(final Double doubleValue) {
77         this.key = new AxReferenceKey();
78         this.doubleValue = doubleValue;
79     }
80
81     /**
82      * {@inheritDoc}.
83      */
84     @Override
85     public List<AxKey> getKeys() {
86         return Arrays.asList((AxKey) getKey());
87     }
88
89     /**
90      * Check set key.
91      *
92      * @return true, if successful
93      */
94     public boolean checkSetKey() {
95         return (this.key != null);
96     }
97
98     /**
99      * {@inheritDoc}.
100      */
101     @Override
102     public AxValidationResult validate(final AxValidationResult result) {
103         return key.validate(result);
104     }
105
106     /**
107      * {@inheritDoc}.
108      */
109     @Override
110     public void clean() {
111         key.clean();
112     }
113
114     /**
115      * {@inheritDoc}.
116      */
117     @Override
118     public AxConcept copyTo(final AxConcept target) {
119         final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
120         if (copyObject instanceof ReferenceKeyTestEntity) {
121             final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
122             if (this.checkSetKey()) {
123                 copy.setKey(new AxReferenceKey(key));
124             } else {
125                 copy.key = null;
126             }
127             copy.doubleValue = doubleValue;
128             return copy;
129         } else {
130             return null;
131         }
132     }
133
134     /**
135      * {@inheritDoc}.
136      */
137     @Override
138     public int compareTo(final AxConcept otherObj) {
139         if (otherObj == null) {
140             return -1;
141         }
142         if (this == otherObj) {
143             return 0;
144         }
145         if (getClass() != otherObj.getClass()) {
146             return -1;
147         }
148         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
149         if (key == null) {
150             if (other.key != null) {
151                 return 1;
152             }
153         } else if (!key.equals(other.key)) {
154             return key.compareTo(other.key);
155         }
156         return Double.compare(doubleValue, other.doubleValue);
157     }
158 }