2 * ============LICENSE_START=======================================================
3 * Copyright (C) 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.distribution.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 distribution rest server.
31 * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
33 public class RestServerParameters implements ParameterGroup {
37 private String userName;
38 private String password;
39 private boolean https;
42 * Constructor for instantiating RestServerParameters.
44 * @param host the host name
45 * @param port the port
46 * @param userName the user name
47 * @param password the password
48 * @param https the https
50 public RestServerParameters(final String host, final int port, final String userName, final String password,
51 final boolean https) {
55 this.userName = userName;
56 this.password = password;
61 * Return the name of this RestServerParameters instance.
63 * @return name the name of this RestServerParameters
66 public String getName() {
71 * Return the host of this RestServerParameters instance.
75 public String getHost() {
80 * Return the port of this RestServerParameters instance.
84 public int getPort() {
89 * Return the user name of this RestServerParameters instance.
91 * @return the userName
93 public String getUserName() {
98 * Return the password of this RestServerParameters instance.
100 * @return the password
102 public String getPassword() {
107 * Return the https of this RestServerParameters instance.
109 * @return the password
111 public boolean isHttps() {
116 * Set the name of this RestServerParameters instance.
118 * @param name the name to set
120 public void setName(final String name) {
125 * Validate the rest server parameters.
127 * @return the result of the validation
130 public GroupValidationResult validate() {
131 final GroupValidationResult validationResult = new GroupValidationResult(this);
132 if (!ParameterValidationUtils.validateStringParameter(host)) {
133 validationResult.setResult("host", ValidationStatus.INVALID,
134 "must be a non-blank string containing hostname/ipaddress of the distribution rest server");
136 if (!ParameterValidationUtils.validateStringParameter(userName)) {
137 validationResult.setResult("userName", ValidationStatus.INVALID,
138 "must be a non-blank string containing userName for distribution rest server credentials");
140 if (!ParameterValidationUtils.validateStringParameter(password)) {
141 validationResult.setResult("password", ValidationStatus.INVALID,
142 "must be a non-blank string containing password for distribution rest server credentials");
144 if (!ParameterValidationUtils.validateIntParameter(port)) {
145 validationResult.setResult("port", ValidationStatus.INVALID,
146 "must be a positive integer containing port of the distribution rest server");
148 return validationResult;