2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.base.testconcepts;
24 import java.util.List;
26 import javax.persistence.EmbeddedId;
29 import lombok.EqualsAndHashCode;
30 import lombok.NonNull;
32 import org.apache.commons.lang3.ObjectUtils;
33 import org.onap.policy.common.utils.validation.Assertions;
34 import org.onap.policy.models.base.PfAuthorative;
35 import org.onap.policy.models.base.PfConcept;
36 import org.onap.policy.models.base.PfConceptKey;
37 import org.onap.policy.models.base.PfKey;
38 import org.onap.policy.models.base.PfValidationMessage;
39 import org.onap.policy.models.base.PfValidationResult;
40 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
43 @EqualsAndHashCode(callSuper = false)
44 public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuthorativeConcept> {
45 private static final long serialVersionUID = 1L;
47 private PfConceptKey key;
49 private String description;
53 * The Default Constructor creates a {@link DummyPfConcept} object with a null key.
55 public DummyPfConcept() {
56 this(new PfConceptKey());
60 * The Key Constructor creates a {@link DummyPfConcept} object with the given concept key.
64 public DummyPfConcept(@NonNull final PfConceptKey key) {
71 * @param copyConcept the concept to copy from
73 public DummyPfConcept(final DummyPfConcept copyConcept) {
78 public DummyAuthorativeConcept toAuthorative() {
79 DummyAuthorativeConcept dac = new DummyAuthorativeConcept();
80 dac.setName(key.getName());
81 dac.setVersion(key.getVersion());
82 dac.setDescription(description);
88 public void fromAuthorative(DummyAuthorativeConcept dac) {
89 key.setName(dac.getName());
90 key.setVersion(dac.getVersion());
91 description = dac.getDescription();
95 public List<PfKey> getKeys() {
96 return getKey().getKeys();
100 public void clean() {
103 description = (description != null ? description.trim() : null);
107 public PfValidationResult validate(PfValidationResult resultIn) {
108 PfValidationResult result = resultIn;
110 if (key.isNullKey()) {
111 result.addValidationMessage(
112 new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
115 result = key.validate(result);
117 if (description != null && description.trim().length() == 0) {
118 result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
119 "property description may not be blank"));
126 public int compareTo(final PfConcept otherConcept) {
127 if (otherConcept == null) {
130 if (this == otherConcept) {
133 if (getClass() != otherConcept.getClass()) {
134 return this.hashCode() - otherConcept.hashCode();
137 final DummyPfConcept other = (DummyPfConcept) otherConcept;
138 if (!key.equals(other.key)) {
139 return key.compareTo(other.key);
142 return ObjectUtils.compare(description, other.description);
146 public PfConcept copyTo(@NonNull PfConcept target) {
147 final Object copyObject = target;
148 Assertions.instanceOf(copyObject, PfConcept.class);
150 final DummyPfConcept copy = ((DummyPfConcept) copyObject);
151 copy.setKey(new PfConceptKey(key));
152 copy.setDescription(description);