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