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