2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
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.apex.model.policymodel.concepts;
23 import java.util.List;
25 import javax.persistence.Column;
26 import javax.persistence.EmbeddedId;
27 import javax.persistence.Entity;
28 import javax.persistence.Table;
29 import javax.xml.bind.annotation.XmlAccessType;
30 import javax.xml.bind.annotation.XmlAccessorType;
31 import javax.xml.bind.annotation.XmlElement;
32 import javax.xml.bind.annotation.XmlRootElement;
33 import javax.xml.bind.annotation.XmlType;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
37 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
38 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
39 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
40 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
41 import org.onap.policy.apex.model.utilities.Assertions;
44 * This class is used to specify the configuration parameters that may be passed to a task
45 * {@link AxTask}. Task parameters are read from a configuration file when Apex starts and are
46 * passed to the task by the Apex engine when a task is executed. Each task parameter has a key and
47 * a default value. If the task parameter is not set in a configuration file, the task uses its
52 @Table(name = "AxTaskParameter")
54 @XmlAccessorType(XmlAccessType.FIELD)
55 @XmlRootElement(name = "apexTaskParameter", namespace = "http://www.onap.org/policy/apex-pdp")
56 @XmlType(name = "AxTaskParameter", namespace = "http://www.onap.org/policy/apex-pdp",
57 propOrder = {"key", "defaultValue"})
59 public class AxTaskParameter extends AxConcept {
60 private static final long serialVersionUID = 7351688156934099977L;
63 @XmlElement(name = "key", required = true)
64 private AxReferenceKey key;
66 @Column(name = "defaultValue")
68 private String defaultValue;
71 * The Default Constructor creates a task parameter with a null reference key and a null default
74 public AxTaskParameter() {
75 this(new AxReferenceKey());
81 * @param copyConcept the concept to copy from
83 public AxTaskParameter(final AxTaskParameter copyConcept) {
88 * The Keyed Constructor creates a task parameter with the given reference key and a null
91 * @param taskParameterKey the task parameter key
93 public AxTaskParameter(final AxReferenceKey taskParameterKey) {
94 this(taskParameterKey, "");
98 * The Default Constructor creates a task parameter with the given reference key and default
101 * @param key the reference key of the task parameter
102 * @param defaultValue the default value of the task parameter
104 public AxTaskParameter(final AxReferenceKey key, final String defaultValue) {
106 Assertions.argumentNotNull(key, "key may not be null");
107 Assertions.argumentNotNull(defaultValue, "defaultValue may not be null");
110 this.defaultValue = defaultValue.trim();
116 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
119 public AxReferenceKey getKey() {
126 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
129 public List<AxKey> getKeys() {
130 return key.getKeys();
134 * Sets the reference key of the task parameter.
136 * @param key the reference key of the task parameter
138 public void setKey(final AxReferenceKey key) {
139 Assertions.argumentNotNull(key, "key may not be null");
144 * Gets the default value of the task parameter.
146 * @return the default value of the task parameter
148 public String getTaskParameterValue() {
153 * Sets the default value of the task parameter.
155 * @param defaultValue the default value of the task parameter
157 public void setDefaultValue(final String defaultValue) {
158 Assertions.argumentNotNull(defaultValue, "defaultValue may not be null");
159 this.defaultValue = defaultValue.trim();
166 * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
167 * basicmodel.concepts.AxValidationResult)
170 public AxValidationResult validate(final AxValidationResult resultIn) {
171 AxValidationResult result = resultIn;
173 if (key.equals(AxReferenceKey.getNullKey())) {
174 result.addValidationMessage(
175 new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
178 result = key.validate(result);
180 if (defaultValue.trim().length() == 0) {
181 result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING,
182 "no defaultValue specified, defaultValue is blank"));
191 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
194 public void clean() {
196 defaultValue = defaultValue.trim();
202 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
205 public String toString() {
206 final StringBuilder builder = new StringBuilder();
207 builder.append(this.getClass().getSimpleName());
208 builder.append(":(");
209 builder.append("key=");
211 builder.append(",defaultValue=");
212 builder.append(defaultValue);
214 return builder.toString();
221 * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
222 * basicmodel.concepts.AxConcept)
225 public AxConcept copyTo(final AxConcept targetObject) {
226 Assertions.argumentNotNull(targetObject, "target may not be null");
228 final Object copyObject = targetObject;
229 Assertions.instanceOf(copyObject, AxTaskParameter.class);
231 final AxTaskParameter copy = ((AxTaskParameter) copyObject);
232 copy.setKey(new AxReferenceKey(key));
233 copy.setDefaultValue(defaultValue);
241 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
244 public int hashCode() {
245 final int prime = 31;
247 result = prime * result + key.hashCode();
248 result = prime * result + defaultValue.hashCode();
255 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
258 public boolean equals(final Object obj) {
265 if (getClass() != obj.getClass()) {
269 final AxTaskParameter other = (AxTaskParameter) obj;
270 if (!key.equals(other.key)) {
273 return defaultValue.equals(other.defaultValue);
279 * @see java.lang.Comparable#compareTo(java.lang.Object)
282 public int compareTo(final AxConcept otherObj) {
283 if (otherObj == null) {
286 if (this == otherObj) {
289 if (getClass() != otherObj.getClass()) {
290 return this.hashCode() - otherObj.hashCode();
293 final AxTaskParameter other = (AxTaskParameter) otherObj;
294 if (!key.equals(other.key)) {
295 return key.compareTo(other.key);
297 return defaultValue.compareTo(other.defaultValue);