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.ArrayList;
24 import java.util.List;
26 import javax.ws.rs.core.Response;
29 import lombok.EqualsAndHashCode;
31 import org.onap.policy.common.utils.validation.Assertions;
32 import org.onap.policy.models.base.PfConcept;
33 import org.onap.policy.models.base.PfConceptKey;
34 import org.onap.policy.models.base.PfKey;
35 import org.onap.policy.models.base.PfModel;
36 import org.onap.policy.models.base.PfModelRuntimeException;
37 import org.onap.policy.models.base.PfValidationResult;
40 @EqualsAndHashCode(callSuper = true)
41 public class DummyPfModel extends PfModel {
42 private static final long serialVersionUID = 8800599637708309945L;
44 private List<PfKey> keyList;
47 * The Default Constructor creates a {@link DummyPfModel} object with a null concept key and
48 * creates an empty TOSCA model.
50 public DummyPfModel() {
52 super.setKey(new PfConceptKey());
53 this.keyList = new ArrayList<PfKey>();
57 * The Key Constructor creates a {@link DummyPfModel} object with the given concept key and
58 * creates an empty TOSCA model.
60 * @param key the TOSCA model key
62 public DummyPfModel(final PfConceptKey key) {
64 this.keyList = new ArrayList<PfKey>();
68 * Constructor that initiates a {@link ToscaModel} with all its fields.
70 * @param key the TOSCA model key
71 * @param keyList the service templates in the event model
73 public DummyPfModel(final PfConceptKey key, final List<PfKey> keyList) {
75 this.keyList = keyList;
81 * @param copyConcept the concept to copy from
83 public DummyPfModel(final DummyPfModel copyConcept) {
88 public void register() {
92 public List<PfKey> getKeys() {
93 final List<PfKey> listOfKeys = super.getKeys();
95 listOfKeys.addAll(keyList);
101 public void clean() {
103 for (PfKey pfKey : keyList) {
109 public PfValidationResult validate(final PfValidationResult resultIn) {
110 PfValidationResult result = super.validate(resultIn);
112 for (PfKey pfKey : keyList) {
113 result = pfKey.validate(result);
120 public int compareTo(final PfConcept otherConcept) {
121 if (super.compareTo(otherConcept) != 0) {
122 return super.compareTo(otherConcept);
125 if (otherConcept == null) {
129 if (this == otherConcept) {
133 if (getClass() != otherConcept.getClass()) {
134 return this.hashCode() - otherConcept.hashCode();
137 final DummyPfModel other = (DummyPfModel) otherConcept;
138 if (!super.equals(other)) {
139 return super.compareTo(other);
142 if (!keyList.equals(other.keyList)) {
143 return (keyList.hashCode() - other.keyList.hashCode());
150 public PfConcept copyTo(final PfConcept targetObject) {
151 super.copyTo(targetObject);
153 Assertions.instanceOf(targetObject, DummyPfModel.class);
155 final DummyPfModel copy = ((DummyPfModel) targetObject);
157 final List<PfKey> newKeyList = new ArrayList<>();
158 for (final PfKey pfKey : keyList) {
161 newPfKey = pfKey.getClass().newInstance();
162 } catch (final Exception e) {
163 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
164 "error copying concept key: " + e.getMessage(), e);
166 newPfKey.copyTo(pfKey);
167 newKeyList.add(newPfKey);
169 copy.setKeyList(newKeyList);