a8b90d17a116639c63c94792d0407eb3caa17aed
[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.apache.commons.lang3.builder.CompareToBuilder;
38 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
39 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
40 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
41 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
42 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
43
44 /**
45  * The Class ReferenceKeyTestEntity provides a reference key test concept.
46  */
47 @Entity
48 @Table(name = "ReferenceKeyTestEntity")
49 @Getter
50 @Setter
51 @ToString
52 @EqualsAndHashCode(callSuper = false)
53 @AllArgsConstructor
54 public class ReferenceKeyTestEntity extends AxConcept {
55     private static final long serialVersionUID = -2962570563281067895L;
56
57     @EmbeddedId()
58     @XmlElement(name = "key", required = true)
59     @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
60     protected AxReferenceKey key;
61
62     private double doubleValue;
63
64     /**
65      * Instantiates a new reference key test entity.
66      */
67     public ReferenceKeyTestEntity() {
68         this.key = new AxReferenceKey();
69         this.doubleValue = 0;
70     }
71
72     /**
73      * Instantiates a new reference key test entity.
74      *
75      * @param doubleValue the double value
76      */
77     public ReferenceKeyTestEntity(final Double doubleValue) {
78         this.key = new AxReferenceKey();
79         this.doubleValue = doubleValue;
80     }
81
82     /**
83      * {@inheritDoc}.
84      */
85     @Override
86     public List<AxKey> getKeys() {
87         return Arrays.asList((AxKey) getKey());
88     }
89
90     /**
91      * Check set key.
92      *
93      * @return true, if successful
94      */
95     public boolean checkSetKey() {
96         return (this.key != null);
97     }
98
99     /**
100      * {@inheritDoc}.
101      */
102     @Override
103     public AxValidationResult validate(final AxValidationResult result) {
104         return key.validate(result);
105     }
106
107     /**
108      * {@inheritDoc}.
109      */
110     @Override
111     public void clean() {
112         key.clean();
113     }
114
115     /**
116      * {@inheritDoc}.
117      */
118     @Override
119     public AxConcept copyTo(final AxConcept target) {
120         final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
121         if (copyObject instanceof ReferenceKeyTestEntity) {
122             final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
123             if (this.checkSetKey()) {
124                 copy.setKey(new AxReferenceKey(key));
125             } else {
126                 copy.key = null;
127             }
128             copy.doubleValue = doubleValue;
129             return copy;
130         } else {
131             return null;
132         }
133     }
134
135     /**
136      * {@inheritDoc}.
137      */
138     @Override
139     public int compareTo(final AxConcept otherObj) {
140         if (otherObj == null) {
141             return -1;
142         }
143         if (this == otherObj) {
144             return 0;
145         }
146         if (getClass() != otherObj.getClass()) {
147             return -1;
148         }
149         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
150         return new CompareToBuilder()
151                         .append(key, other.key)
152                         .append(doubleValue, other.doubleValue)
153                         .toComparison();
154     }
155 }