Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaEventFilter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Model
4  * ================================================================================
5  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019-2020, 2023 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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  * SPDX-License-Identifier: Apache-2.0
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.policy.models.tosca.simple.concepts;
25
26 import jakarta.persistence.Column;
27 import jakarta.persistence.EmbeddedId;
28 import jakarta.persistence.Entity;
29 import jakarta.persistence.Inheritance;
30 import jakarta.persistence.InheritanceType;
31 import jakarta.persistence.Table;
32 import java.io.Serial;
33 import java.util.List;
34 import lombok.Data;
35 import lombok.EqualsAndHashCode;
36 import lombok.NonNull;
37 import org.apache.commons.lang3.ObjectUtils;
38 import org.onap.policy.common.parameters.annotations.NotBlank;
39 import org.onap.policy.common.parameters.annotations.NotNull;
40 import org.onap.policy.models.base.PfConcept;
41 import org.onap.policy.models.base.PfConceptKey;
42 import org.onap.policy.models.base.PfKey;
43 import org.onap.policy.models.base.PfReferenceKey;
44 import org.onap.policy.models.base.validation.annotations.VerifyKey;
45
46 /**
47  * Class to represent the EventFilter in TOSCA definition.
48  *
49  * @author Chenfei Gao (cgao@research.att.com)
50  * @author Liam Fallon (liam.fallon@est.tech)
51  */
52 @Entity
53 @Table(name = "ToscaEventFilter")
54 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
55 @Data
56 @EqualsAndHashCode(callSuper = false)
57 public class JpaToscaEventFilter extends PfConcept {
58     @Serial
59     private static final long serialVersionUID = 8769020537228210247L;
60
61     @EmbeddedId
62     @VerifyKey
63     @NotNull
64     private PfReferenceKey key;
65
66     @Column
67     @VerifyKey
68     @NotNull
69     private PfConceptKey node;
70
71     @Column
72     @NotBlank
73     private String requirement;
74
75     @Column
76     @NotBlank
77     private String capability;
78
79     /**
80      * The Default Constructor creates a {@link JpaToscaEventFilter} object with a null key.
81      */
82     public JpaToscaEventFilter() {
83         this(new PfReferenceKey());
84     }
85
86     /**
87      * The Key Constructor creates a {@link JpaToscaEventFilter} object with the given concept key.
88      *
89      * @param key the key
90      */
91     public JpaToscaEventFilter(@NonNull final PfReferenceKey key) {
92         this(key, new PfConceptKey());
93     }
94
95     /**
96      * The full Constructor creates a {@link JpaToscaEventFilter} object with the given concept key and node.
97      *
98      * @param key the key
99      */
100     public JpaToscaEventFilter(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey node) {
101         this.key = key;
102         this.node = node;
103     }
104
105     /**
106      * Copy constructor.
107      *
108      * @param copyConcept the concept to copy from
109      */
110     public JpaToscaEventFilter(final JpaToscaEventFilter copyConcept) {
111         super(copyConcept);
112         this.key = new PfReferenceKey(copyConcept.key);
113         this.node = new PfConceptKey(copyConcept.node);
114         this.requirement = copyConcept.requirement;
115         this.capability = copyConcept.capability;
116     }
117
118     @Override
119     public List<PfKey> getKeys() {
120         final List<PfKey> keyList = getKey().getKeys();
121         keyList.addAll(node.getKeys());
122         return keyList;
123     }
124
125     @Override
126     public void clean() {
127         key.clean();
128         node.clean();
129
130         requirement = (requirement != null ? requirement.trim() : requirement);
131         capability = (capability != null ? capability.trim() : capability);
132     }
133
134     @Override
135     public int compareTo(final PfConcept otherConcept) {
136         if (otherConcept == null) {
137             return -1;
138         }
139         if (this == otherConcept) {
140             return 0;
141         }
142         if (getClass() != otherConcept.getClass()) {
143             return getClass().getName().compareTo(otherConcept.getClass().getName());
144         }
145
146         final JpaToscaEventFilter other = (JpaToscaEventFilter) otherConcept;
147         int result = key.compareTo(other.key);
148         if (result != 0) {
149             return result;
150         }
151
152         result = node.compareTo(other.node);
153         if (result != 0) {
154             return result;
155         }
156
157         result = ObjectUtils.compare(requirement, other.requirement);
158         if (result != 0) {
159             return result;
160         }
161
162         return ObjectUtils.compare(capability, other.capability);
163     }
164 }