add rest serve and distribution framework
[multicloud/framework.git] / artifactbroker / main / src / main / java / org / onap / policy / distribution / main / parameters / RestServerParameters.java
1 /*-
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
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.distribution.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 distribution rest server.
30  *
31  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
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
41     /**
42      * Constructor for instantiating RestServerParameters.
43      *
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
49      */
50     public RestServerParameters(final String host, final int port, final String userName, final String password,
51                                 final boolean https) {
52         super();
53         this.host = host;
54         this.port = port;
55         this.userName = userName;
56         this.password = password;
57         this.https = https;
58     }
59
60     /**
61      * Return the name of this RestServerParameters instance.
62      *
63      * @return name the name of this RestServerParameters
64      */
65     @Override
66     public String getName() {
67         return name;
68     }
69
70     /**
71      * Return the host of this RestServerParameters instance.
72      *
73      * @return the host
74      */
75     public String getHost() {
76         return host;
77     }
78
79     /**
80      * Return the port of this RestServerParameters instance.
81      *
82      * @return the port
83      */
84     public int getPort() {
85         return port;
86     }
87
88     /**
89      * Return the user name of this RestServerParameters instance.
90      *
91      * @return the userName
92      */
93     public String getUserName() {
94         return userName;
95     }
96
97     /**
98      * Return the password of this RestServerParameters instance.
99      *
100      * @return the password
101      */
102     public String getPassword() {
103         return password;
104     }
105
106     /**
107      * Return the https of this RestServerParameters instance.
108      *
109      * @return the password
110      */
111     public boolean isHttps() {
112         return https;
113     }
114
115     /**
116      * Set the name of this RestServerParameters instance.
117      *
118      * @param name the name to set
119      */
120     public void setName(final String name) {
121         this.name = name;
122     }
123
124     /**
125      * Validate the rest server parameters.
126      *
127      * @return the result of the validation
128      */
129     @Override
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");
135         }
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");
139         }
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");
143         }
144         if (!ParameterValidationUtils.validateIntParameter(port)) {
145             validationResult.setResult("port", ValidationStatus.INVALID,
146                     "must be a positive integer containing port of the distribution rest server");
147         }
148         return validationResult;
149     }
150 }