6b1e3f824db1708e6f5a4929449c7ecc0ee9028c
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / parameters / RestServerParameters.java
1 /*-
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
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.pap.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 pap rest server.
30  *
31  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
32  */
33 public class RestServerParameters implements ParameterGroup {
34     private String name;
35     private String host;
36     private int port;
37     private String userName;
38     private String password;
39     private boolean https;
40     private boolean aaf;
41
42     /**
43      * Constructor for instantiating RestServerParameters.
44      *
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
51      */
52     public RestServerParameters(final String host, final int port, final String userName, final String password,
53             final boolean https, final boolean aaf) {
54         super();
55         this.host = host;
56         this.port = port;
57         this.userName = userName;
58         this.password = password;
59         this.https = https;
60         this.aaf = aaf;
61     }
62
63     /**
64      * Return the name of this RestServerParameters instance.
65      *
66      * @return name the name of this RestServerParameters
67      */
68     @Override
69     public String getName() {
70         return name;
71     }
72
73     /**
74      * Return the host of this RestServerParameters instance.
75      *
76      * @return the host
77      */
78     public String getHost() {
79         return host;
80     }
81
82     /**
83      * Return the port of this RestServerParameters instance.
84      *
85      * @return the port
86      */
87     public int getPort() {
88         return port;
89     }
90
91     /**
92      * Return the user name of this RestServerParameters instance.
93      *
94      * @return the userName
95      */
96     public String getUserName() {
97         return userName;
98     }
99
100     /**
101      * Return the password of this RestServerParameters instance.
102      *
103      * @return the password
104      */
105     public String getPassword() {
106         return password;
107     }
108
109     /**
110      * Return the https flag of this RestServerParameters instance.
111      *
112      * @return the https flag
113      */
114     public boolean isHttps() {
115         return https;
116     }
117
118     /**
119      * Return the aaf flag of this RestServerParameters instance.
120      *
121      * @return the aaf flag
122      */
123     public boolean isAaf() {
124         return aaf;
125     }
126
127     /**
128      * Set the name of this RestServerParameters instance.
129      *
130      * @param name the name to set
131      */
132     @Override
133     public void setName(final String name) {
134         this.name = name;
135     }
136
137     /**
138      * Validate the rest server parameters.
139      *
140      * @return the result of the validation
141      */
142     @Override
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");
148         }
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");
152         }
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");
156         }
157         if (!ParameterValidationUtils.validateIntParameter(port)) {
158             validationResult.setResult("port", ValidationStatus.INVALID,
159                     "must be a positive integer containing port of the pap rest server");
160         }
161         return validationResult;
162     }
163 }