2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.base.testconcepts;
23 import java.util.List;
25 import javax.persistence.EmbeddedId;
28 import lombok.EqualsAndHashCode;
29 import lombok.NonNull;
31 import org.apache.commons.lang3.ObjectUtils;
32 import org.onap.policy.common.utils.validation.Assertions;
33 import org.onap.policy.models.base.PfAuthorative;
34 import org.onap.policy.models.base.PfConcept;
35 import org.onap.policy.models.base.PfConceptKey;
36 import org.onap.policy.models.base.PfKey;
37 import org.onap.policy.models.base.PfValidationMessage;
38 import org.onap.policy.models.base.PfValidationResult;
39 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
42 @EqualsAndHashCode(callSuper = false)
43 public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuthorativeConcept> {
44 private static final long serialVersionUID = 1L;
46 private PfConceptKey key;
48 private String description;
52 public DummyAuthorativeConcept toAuthorative() {
53 DummyAuthorativeConcept dac = new DummyAuthorativeConcept();
54 dac.setName(key.getName());
55 dac.setVersion(key.getVersion());
56 dac.setDescription(description);
62 public void fromAuthorative(DummyAuthorativeConcept dac) {
63 key.setName(dac.getName());
64 key.setVersion(dac.getVersion());
65 description = dac.getDescription();
69 * The Default Constructor creates a {@link DummyPfConcept} object with a null key.
71 public DummyPfConcept() {
72 this(new PfConceptKey());
76 * The Key Constructor creates a {@link DummyPfConcept} object with the given concept key.
80 public DummyPfConcept(@NonNull final PfConceptKey key) {
87 * @param copyConcept the concept to copy from
89 public DummyPfConcept(final DummyPfConcept copyConcept) {
94 public List<PfKey> getKeys() {
95 final List<PfKey> keyList = 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);