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