PDPX Healthcheck/Statistic RESTful API entry point
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / parameters / RestServerParameters.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 AT&T Intellectual Property. 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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pdpx.main.parameters;
22
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;
27
28 /**
29  * Class to hold all parameters needed for xacml pdp rest server.
30  *
31  */
32 public class RestServerParameters implements ParameterGroup {
33     private String name;
34     private String host;
35     private int port;
36     private String userName;
37     private String password;
38
39     /**
40      * Constructor for instantiating RestServerParameters.
41      *
42      * @param host the host name
43      * @param port the port
44      * @param userName the user name
45      * @param password the password
46      */
47     public RestServerParameters(final String host, final int port, final String userName, final String password) {
48         super();
49         this.host = host;
50         this.port = port;
51         this.userName = userName;
52         this.password = password;
53     }
54
55     /**
56      * Return the name of this RestServerParameters instance.
57      *
58      * @return name the name of this RestServerParameters
59      */
60     @Override
61     public String getName() {
62         return name;
63     }
64
65     /**
66      * Return the host of this RestServerParameters instance.
67      *
68      * @return the host
69      */
70     public String getHost() {
71         return host;
72     }
73
74     /**
75      * Return the port of this RestServerParameters instance.
76      *
77      * @return the port
78      */
79     public int getPort() {
80         return port;
81     }
82
83     /**
84      * Return the user name of this RestServerParameters instance.
85      *
86      * @return the userName
87      */
88     public String getUserName() {
89         return userName;
90     }
91
92     /**
93      * Return the password of this RestServerParameters instance.
94      *
95      * @return the password
96      */
97     public String getPassword() {
98         return password;
99     }
100
101     /**
102      * Set the name of this RestServerParameters instance.
103      *
104      * @param name the name to set
105      */
106     @Override
107     public void setName(final String name) {
108         this.name = name;
109     }
110
111     /**
112      * Validate the rest server parameters.
113      *
114      * @return the result of the validation
115      */
116     @Override
117     public GroupValidationResult validate() {
118         final GroupValidationResult validationResult = new GroupValidationResult(this);
119         if (!ParameterValidationUtils.validateStringParameter(host)) {
120             validationResult.setResult("host", ValidationStatus.INVALID,
121                     "must be a non-blank string containing hostname/ipaddress of the xacml pdp rest server");
122         }
123         if (!ParameterValidationUtils.validateStringParameter(userName)) {
124             validationResult.setResult("userName", ValidationStatus.INVALID,
125                     "must be a non-blank string containing userName for xacml pdp rest server credentials");
126         }
127         if (!ParameterValidationUtils.validateStringParameter(password)) {
128             validationResult.setResult("password", ValidationStatus.INVALID,
129                     "must be a non-blank string containing password for xacml pdp rest server credentials");
130         }
131         if (!ParameterValidationUtils.validateIntParameter(port)) {
132             validationResult.setResult("port", ValidationStatus.INVALID,
133                     "must be a positive integer containing port of the xacml pdp rest server");
134         }
135         return validationResult;
136     }
137 }