2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.policymodel.concepts;
24 import java.util.List;
26 import javax.persistence.Column;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Table;
30 import javax.xml.bind.annotation.XmlAccessType;
31 import javax.xml.bind.annotation.XmlAccessorType;
32 import javax.xml.bind.annotation.XmlElement;
33 import javax.xml.bind.annotation.XmlRootElement;
34 import javax.xml.bind.annotation.XmlType;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
37 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
38 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
39 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
40 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
41 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
42 import org.onap.policy.common.utils.validation.Assertions;
45 * This class is used to specify the configuration parameters that may be passed to a task
46 * {@link AxTask}. Task parameters are read from a configuration file when Apex starts and are
47 * passed to the task by the Apex engine when a task is executed. Each task parameter has a key and
48 * a default value. If the task parameter is not set in a configuration file, the task uses its
53 @Table(name = "AxTaskParameter")
55 @XmlAccessorType(XmlAccessType.FIELD)
56 @XmlRootElement(name = "apexTaskParameter", namespace = "http://www.onap.org/policy/apex-pdp")
57 @XmlType(name = "AxTaskParameter", namespace = "http://www.onap.org/policy/apex-pdp",
58 propOrder = {"key", "defaultValue"})
60 public class AxTaskParameter extends AxConcept {
61 private static final long serialVersionUID = 7351688156934099977L;
64 @XmlElement(name = "key", required = true)
65 private AxReferenceKey key;
67 @Column(name = "defaultValue")
69 private String defaultValue;
72 * The Default Constructor creates a task parameter with a null reference key and a null default
75 public AxTaskParameter() {
76 this(new AxReferenceKey());
82 * @param copyConcept the concept to copy from
84 public AxTaskParameter(final AxTaskParameter copyConcept) {
89 * The Keyed Constructor creates a task parameter with the given reference key and a null
92 * @param taskParameterKey the task parameter key
94 public AxTaskParameter(final AxReferenceKey taskParameterKey) {
95 this(taskParameterKey, "");
99 * The Default Constructor creates a task parameter with the given reference key and default
102 * @param key the reference key of the task parameter
103 * @param defaultValue the default value of the task parameter
105 public AxTaskParameter(final AxReferenceKey key, final String defaultValue) {
107 Assertions.argumentNotNull(key, "key may not be null");
108 Assertions.argumentNotNull(defaultValue, "defaultValue may not be null");
111 this.defaultValue = defaultValue.trim();
117 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
120 public AxReferenceKey getKey() {
127 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
130 public List<AxKey> getKeys() {
131 return key.getKeys();
135 * Sets the reference key of the task parameter.
137 * @param key the reference key of the task parameter
139 public void setKey(final AxReferenceKey key) {
140 Assertions.argumentNotNull(key, "key may not be null");
145 * Gets the default value of the task parameter.
147 * @return the default value of the task parameter
149 public String getTaskParameterValue() {
154 * Sets the default value of the task parameter.
156 * @param defaultValue the default value of the task parameter
158 public void setDefaultValue(final String defaultValue) {
159 Assertions.argumentNotNull(defaultValue, "defaultValue may not be null");
160 this.defaultValue = defaultValue.trim();
167 * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
168 * basicmodel.concepts.AxValidationResult)
171 public AxValidationResult validate(final AxValidationResult resultIn) {
172 AxValidationResult result = resultIn;
174 if (key.equals(AxReferenceKey.getNullKey())) {
175 result.addValidationMessage(
176 new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
179 result = key.validate(result);
181 if (defaultValue.trim().length() == 0) {
182 result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING,
183 "no defaultValue specified, defaultValue is blank"));
192 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
195 public void clean() {
197 defaultValue = defaultValue.trim();
203 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
206 public String toString() {
207 final StringBuilder builder = new StringBuilder();
208 builder.append(this.getClass().getSimpleName());
209 builder.append(":(");
210 builder.append("key=");
212 builder.append(",defaultValue=");
213 builder.append(defaultValue);
215 return builder.toString();
222 * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
223 * basicmodel.concepts.AxConcept)
226 public AxConcept copyTo(final AxConcept targetObject) {
227 Assertions.argumentNotNull(targetObject, "target may not be null");
229 final Object copyObject = targetObject;
230 Assertions.instanceOf(copyObject, AxTaskParameter.class);
232 final AxTaskParameter copy = ((AxTaskParameter) copyObject);
233 copy.setKey(new AxReferenceKey(key));
234 copy.setDefaultValue(defaultValue);
242 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
245 public int hashCode() {
246 final int prime = 31;
248 result = prime * result + key.hashCode();
249 result = prime * result + defaultValue.hashCode();
256 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
259 public boolean equals(final Object obj) {
266 if (getClass() != obj.getClass()) {
270 final AxTaskParameter other = (AxTaskParameter) obj;
271 if (!key.equals(other.key)) {
274 return defaultValue.equals(other.defaultValue);
280 * @see java.lang.Comparable#compareTo(java.lang.Object)
283 public int compareTo(final AxConcept otherObj) {
284 if (otherObj == null) {
287 if (this == otherObj) {
290 if (getClass() != otherObj.getClass()) {
291 return this.hashCode() - otherObj.hashCode();
294 final AxTaskParameter other = (AxTaskParameter) otherObj;
295 if (!key.equals(other.key)) {
296 return key.compareTo(other.key);
298 return defaultValue.compareTo(other.defaultValue);