2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
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.api.main.parameters;
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ParameterGroup;
28 import org.onap.policy.common.parameters.ValidationStatus;
29 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
32 * Class to hold all parameters needed for api rest server.
35 public class RestServerParameters implements ParameterGroup {
39 private String userName;
40 private String password;
41 private boolean https;
45 * Constructor for instantiating RestServerParameters.
47 * @param host the host name
48 * @param port the port
49 * @param userName the user name
50 * @param password the password
52 public RestServerParameters(final String host, final int port, final String userName, final String password) {
56 this.userName = userName;
57 this.password = password;
63 * Constructor for instantiating RestServerParameters.
65 * @param host the host name
66 * @param port the port
67 * @param userName the user name
68 * @param password the password
69 * @param https the https
72 public RestServerParameters(final String host, final int port, final String userName, final String password,
73 final boolean https, final boolean aaf) {
77 this.userName = userName;
78 this.password = password;
84 * Return the name of this RestServerParameters instance.
86 * @return name the name of this RestServerParameters
89 public String getName() {
94 * Return the host of this RestServerParameters instance.
98 public String getHost() {
103 * Return the port of this RestServerParameters instance.
107 public int getPort() {
112 * Return the user name of this RestServerParameters instance.
114 * @return the userName
116 public String getUserName() {
121 * Return the password of this RestServerParameters instance.
123 * @return the password
125 public String getPassword() {
130 * Return the https flag of this RestServerParameters instance.
133 public boolean isHttps() {
138 * Return the aaf flag of this RestServerParameters instance.
141 public boolean isAaf() {
146 * Set the name of this RestServerParameters instance.
148 * @param name the name to set
150 public void setName(final String name) {
155 * Validate the rest server parameters.
157 * @return the result of the validation
160 public GroupValidationResult validate() {
161 final GroupValidationResult validationResult = new GroupValidationResult(this);
162 if (!ParameterValidationUtils.validateStringParameter(host)) {
163 validationResult.setResult("host", ValidationStatus.INVALID,
164 "must be a non-blank string containing hostname/ipaddress of the api rest server");
166 if (!ParameterValidationUtils.validateStringParameter(userName)) {
167 validationResult.setResult("userName", ValidationStatus.INVALID,
168 "must be a non-blank string containing userName for api rest server credentials");
170 if (!ParameterValidationUtils.validateStringParameter(password)) {
171 validationResult.setResult("password", ValidationStatus.INVALID,
172 "must be a non-blank string containing password for api rest server credentials");
174 if (!ParameterValidationUtils.validateIntParameter(port)) {
175 validationResult.setResult("port", ValidationStatus.INVALID,
176 "must be a positive integer containing port of the api rest server");
178 return validationResult;