2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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.pap.main.parameters;
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ParameterGroup;
25 import org.onap.policy.common.parameters.ValidationStatus;
26 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
29 * Class to hold all parameters needed for pap rest server.
31 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
33 public class RestServerParameters implements ParameterGroup {
37 private String userName;
38 private String password;
39 private boolean https;
43 * Constructor for instantiating RestServerParameters.
45 * @param host the host name
46 * @param port the port
47 * @param userName the user name
48 * @param password the password
49 * @param https the https flag
50 * @param aaf the aaf flag
52 public RestServerParameters(final String host, final int port, final String userName, final String password,
53 final boolean https, final boolean aaf) {
57 this.userName = userName;
58 this.password = password;
64 * Return the name of this RestServerParameters instance.
66 * @return name the name of this RestServerParameters
69 public String getName() {
74 * Return the host of this RestServerParameters instance.
78 public String getHost() {
83 * Return the port of this RestServerParameters instance.
87 public int getPort() {
92 * Return the user name of this RestServerParameters instance.
94 * @return the userName
96 public String getUserName() {
101 * Return the password of this RestServerParameters instance.
103 * @return the password
105 public String getPassword() {
110 * Return the https flag of this RestServerParameters instance.
112 * @return the https flag
114 public boolean isHttps() {
119 * Return the aaf flag of this RestServerParameters instance.
121 * @return the aaf flag
123 public boolean isAaf() {
128 * Set the name of this RestServerParameters instance.
130 * @param name the name to set
133 public void setName(final String name) {
138 * Validate the rest server parameters.
140 * @return the result of the validation
143 public GroupValidationResult validate() {
144 final GroupValidationResult validationResult = new GroupValidationResult(this);
145 if (!ParameterValidationUtils.validateStringParameter(host)) {
146 validationResult.setResult("host", ValidationStatus.INVALID,
147 "must be a non-blank string containing hostname/ipaddress of the pap rest server");
149 if (!ParameterValidationUtils.validateStringParameter(userName)) {
150 validationResult.setResult("userName", ValidationStatus.INVALID,
151 "must be a non-blank string containing userName for pap rest server credentials");
153 if (!ParameterValidationUtils.validateStringParameter(password)) {
154 validationResult.setResult("password", ValidationStatus.INVALID,
155 "must be a non-blank string containing password for pap rest server credentials");
157 if (!ParameterValidationUtils.validateIntParameter(port)) {
158 validationResult.setResult("port", ValidationStatus.INVALID,
159 "must be a positive integer containing port of the pap rest server");
161 return validationResult;