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;
27 import javax.persistence.Column;
28 import javax.persistence.EmbeddedId;
29 import javax.persistence.Entity;
30 import javax.persistence.Inheritance;
31 import javax.persistence.InheritanceType;
32 import javax.persistence.Table;
34 import lombok.EqualsAndHashCode;
35 import lombok.NonNull;
36 import org.apache.commons.lang3.ObjectUtils;
37 import org.onap.policy.models.base.PfConcept;
38 import org.onap.policy.models.base.PfConceptKey;
39 import org.onap.policy.models.base.PfKey;
40 import org.onap.policy.models.base.PfReferenceKey;
41 import org.onap.policy.models.base.PfValidationMessage;
42 import org.onap.policy.models.base.PfValidationResult;
43 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
46 * Class to represent the EventFilter in TOSCA definition.
48 * @author Chenfei Gao (cgao@research.att.com)
49 * @author Liam Fallon (liam.fallon@est.tech)
52 @Table(name = "ToscaEventFilter")
53 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
55 @EqualsAndHashCode(callSuper = false)
56 public class JpaToscaEventFilter extends PfConcept {
57 private static final long serialVersionUID = 8769020537228210247L;
60 private PfReferenceKey key;
63 private PfConceptKey node;
66 private String requirement;
69 private String capability;
72 * The Default Constructor creates a {@link JpaToscaEventFilter} object with a null key.
74 public JpaToscaEventFilter() {
75 this(new PfReferenceKey());
79 * The Key Constructor creates a {@link JpaToscaEventFilter} object with the given concept key.
83 public JpaToscaEventFilter(@NonNull final PfReferenceKey key) {
84 this(key, new PfConceptKey());
88 * The full Constructor creates a {@link JpaToscaEventFilter} object with the given concept key and node.
92 public JpaToscaEventFilter(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey node) {
100 * @param copyConcept the concept to copy from
102 public JpaToscaEventFilter(final JpaToscaEventFilter copyConcept) {
104 this.key = new PfReferenceKey(copyConcept.key);
105 this.node = new PfConceptKey(copyConcept.node);
106 this.requirement = copyConcept.requirement;
107 this.capability = copyConcept.capability;
111 public List<PfKey> getKeys() {
112 final List<PfKey> keyList = getKey().getKeys();
113 keyList.addAll(node.getKeys());
118 public void clean() {
122 requirement = (requirement != null ? requirement.trim() : requirement);
123 capability = (capability != null ? capability.trim() : capability);
127 public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
128 PfValidationResult result = resultIn;
130 if (key.isNullKey()) {
131 result.addValidationMessage(
132 new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
135 result = key.validate(result);
137 if (node == null || node.isNullKey()) {
138 result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
139 "node on an event filter may not be null"));
142 if (requirement != null && requirement.trim().length() == 0) {
143 result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
144 "event filter requirement may not be blank"));
147 if (capability != null && capability.trim().length() == 0) {
148 result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
149 "event filter capability may not be blank"));
156 public int compareTo(final PfConcept otherConcept) {
157 if (otherConcept == null) {
160 if (this == otherConcept) {
163 if (getClass() != otherConcept.getClass()) {
164 return getClass().getName().compareTo(otherConcept.getClass().getName());
167 final JpaToscaEventFilter other = (JpaToscaEventFilter) otherConcept;
168 if (!key.equals(other.key)) {
169 return key.compareTo(other.key);
172 if (!node.equals(other.node)) {
173 return node.compareTo(other.node);
176 int result = ObjectUtils.compare(requirement, other.requirement);
181 return ObjectUtils.compare(capability, other.capability);