2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.models.tosca.simple.concepts;
26 import java.util.List;
28 import javax.persistence.EmbeddedId;
29 import javax.ws.rs.core.Response;
32 import lombok.EqualsAndHashCode;
33 import lombok.NonNull;
35 import org.onap.policy.models.base.PfConcept;
36 import org.onap.policy.models.base.PfKey;
37 import org.onap.policy.models.base.PfModelRuntimeException;
38 import org.onap.policy.models.base.PfReferenceKey;
39 import org.onap.policy.models.base.PfValidationMessage;
40 import org.onap.policy.models.base.PfValidationResult;
41 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
44 * Immutable class to represent the Constraint of property in TOSCA definition.
46 * @author Chenfei Gao (cgao@research.att.com)
47 * @author Liam Fallon (liam.fallon@est.tech)
50 @EqualsAndHashCode(callSuper = false)
51 public abstract class JpaToscaConstraint extends PfConcept {
52 private static final long serialVersionUID = 6426438089914347734L;
55 private final PfReferenceKey key;
58 * The Default Constructor creates a {@link JpaToscaConstraint} object with a null key.
60 public JpaToscaConstraint() {
61 this(new PfReferenceKey());
65 * The Key Constructor creates a {@link JpaToscaConstraint} object with the given concept key.
69 public JpaToscaConstraint(@NonNull final PfReferenceKey key) {
76 * @param copyConcept the concept to copy from
78 public JpaToscaConstraint(@NonNull final JpaToscaConstraint copyConcept) {
79 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
83 public List<PfKey> getKeys() {
84 return getKey().getKeys();
93 public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
94 PfValidationResult result = resultIn;
96 if (key.isNullKey()) {
97 result.addValidationMessage(
98 new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
101 return key.validate(result);
105 public int compareTo(final PfConcept otherConcept) {
106 if (otherConcept == null) {
109 if (this == otherConcept) {
112 if (getClass() != otherConcept.getClass()) {
113 return this.hashCode() - otherConcept.hashCode();
116 final JpaToscaConstraint other = (JpaToscaConstraint) otherConcept;
118 return key.compareTo(other.key);
122 public PfConcept copyTo(@NonNull final PfConcept target) {
123 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");