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