c452c758911b5ceb6cf942032c3b719159f0fb05
[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     private boolean https;
39     private boolean aaf;
40
41     /**
42      * Constructor for instantiating RestServerParameters.
43      *
44      * @param builder the RestServer builder
45      */
46     public RestServerParameters(final RestServerBuilder builder) {
47         super();
48         this.host = builder.getHost();
49         this.port = builder.getPort();
50         this.userName = builder.getUserName();
51         this.password = builder.getPassword();
52         this.https = builder.isHttps();
53         this.aaf = builder.isAaf();
54     }
55
56     /**
57      * Return the name of this RestServerParameters instance.
58      *
59      * @return name the name of this RestServerParameters
60      */
61     @Override
62     public String getName() {
63         return name;
64     }
65
66     /**
67      * Return the host of this RestServerParameters instance.
68      *
69      * @return the host
70      */
71     public String getHost() {
72         return host;
73     }
74
75     /**
76      * Return the port of this RestServerParameters instance.
77      *
78      * @return the port
79      */
80     public int getPort() {
81         return port;
82     }
83
84     /**
85      * Return the user name of this RestServerParameters instance.
86      *
87      * @return the userName
88      */
89     public String getUserName() {
90         return userName;
91     }
92
93     /**
94      * Return the password of this RestServerParameters instance.
95      *
96      * @return the password
97      */
98     public String getPassword() {
99         return password;
100     }
101
102     /**
103      * Return the https flag of this RestServerParameters instance.
104      *
105      * @return the https flag
106      */
107     public boolean isHttps() {
108         return https;
109     }
110
111     /**
112      * Return the aaf flag of this RestServerParameters instance.
113      *
114      * @return the aaf flag
115      */
116     public boolean isAaf() {
117         return aaf;
118     }
119
120     /**
121      * Set the name of this RestServerParameters instance.
122      *
123      * @param name the name to set
124      */
125     @Override
126     public void setName(final String name) {
127         this.name = name;
128     }
129
130     /**
131      * Validate the rest server parameters.
132      *
133      * @return the result of the validation
134      */
135     @Override
136     public GroupValidationResult validate() {
137         final GroupValidationResult validationResult = new GroupValidationResult(this);
138         if (!ParameterValidationUtils.validateStringParameter(host)) {
139             validationResult.setResult("host", ValidationStatus.INVALID,
140                     "must be a non-blank string containing hostname/ipaddress of the xacml pdp rest server");
141         }
142         if (!ParameterValidationUtils.validateStringParameter(userName)) {
143             validationResult.setResult("userName", ValidationStatus.INVALID,
144                     "must be a non-blank string containing userName for xacml pdp rest server credentials");
145         }
146         if (!ParameterValidationUtils.validateStringParameter(password)) {
147             validationResult.setResult("password", ValidationStatus.INVALID,
148                     "must be a non-blank string containing password for xacml pdp rest server credentials");
149         }
150         if (!ParameterValidationUtils.validateIntParameter(port)) {
151             validationResult.setResult("port", ValidationStatus.INVALID,
152                     "must be a positive integer containing port of the xacml pdp rest server");
153         }
154         return validationResult;
155     }
156 }