Merge "Fix the sonar issue and clm issue"
[multicloud/framework.git] / artifactbroker / plugins / forwarding-plugins / src / main / java / org / onap / policy / distribution / forwarding / xacml / pdp / XacmlPdpArtifactForwarderParameterGroup.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.forwarding.xacml.pdp;
22
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ValidationStatus;
25 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
26 import org.onap.policy.distribution.main.parameters.ArtifactForwarderConfigurationParameterGroup;
27
28 /**
29  * Holds the parameters for the{@link XacmlPdpArtifactForwarder}.
30  */
31 public class XacmlPdpArtifactForwarderParameterGroup extends ArtifactForwarderConfigurationParameterGroup {
32     public static final String POLICY_FORWARDER_PLUGIN_CLASS = XacmlPdpArtifactForwarder.class.getCanonicalName();
33
34     private boolean useHttps;
35     private String hostname;
36     private int port;
37     private String userName;
38     private String password;
39     private String clientAuth;
40     private boolean isManaged;
41     private String pdpGroup;
42
43     /**
44      * Construct an instance.
45      *
46      * @param builder the builder create the instance from
47      */
48     private XacmlPdpArtifactForwarderParameterGroup(final XacmlPdpArtifactForwarderParameterGroupBuilder builder) {
49         this.useHttps = builder.useHttps;
50         this.hostname = builder.hostname;
51         this.port = builder.port;
52         this.userName = builder.userName;
53         this.password = builder.password;
54         this.clientAuth = builder.clientAuth;
55         this.isManaged = builder.isManaged;
56         this.pdpGroup = builder.pdpGroup;
57     }
58
59     public boolean isUseHttps() {
60         return useHttps;
61     }
62
63     public String getHostname() {
64         return hostname;
65     }
66
67     public int getPort() {
68         return port;
69     }
70
71     public String getUserName() {
72         return userName;
73     }
74
75     public String getPassword() {
76         return password;
77     }
78
79     public String getClientAuth() {
80         return clientAuth;
81     }
82
83     public boolean isManaged() {
84         return isManaged;
85     }
86
87     public String getPdpGroup() {
88         return pdpGroup;
89     }
90
91     /**
92      * Builder for XacmlPdpArtifactForwarderParameterGroup.
93      */
94     public static class XacmlPdpArtifactForwarderParameterGroupBuilder {
95         private boolean useHttps = false;
96         private String hostname;
97         private int port;
98         private String userName;
99         private String password;
100         private String clientAuth;
101         private boolean isManaged = true;
102         private String pdpGroup;
103
104         public XacmlPdpArtifactForwarderParameterGroupBuilder setUseHttps(final boolean useHttps) {
105             this.useHttps = useHttps;
106             return this;
107         }
108
109         public XacmlPdpArtifactForwarderParameterGroupBuilder setHostname(final String hostname) {
110             this.hostname = hostname;
111             return this;
112         }
113
114         public XacmlPdpArtifactForwarderParameterGroupBuilder setPort(final int port) {
115             this.port = port;
116             return this;
117         }
118
119         public XacmlPdpArtifactForwarderParameterGroupBuilder setUserName(final String userName) {
120             this.userName = userName;
121             return this;
122         }
123
124         public XacmlPdpArtifactForwarderParameterGroupBuilder setPassword(final String password) {
125             this.password = password;
126             return this;
127         }
128
129         public XacmlPdpArtifactForwarderParameterGroupBuilder setClientAuth(final String clientAuth) {
130             this.clientAuth = clientAuth;
131             return this;
132         }
133
134         public XacmlPdpArtifactForwarderParameterGroupBuilder setIsManaged(final boolean isManaged) {
135             this.isManaged = isManaged;
136             return this;
137         }
138
139         public XacmlPdpArtifactForwarderParameterGroupBuilder setPdpGroup(final String pdpGroup) {
140             this.pdpGroup = pdpGroup;
141             return this;
142         }
143
144         /**
145          * Creates a new XacmlPapServletArtifactForwarderParameterGroup instance.
146          */
147         public XacmlPdpArtifactForwarderParameterGroup build() {
148             return new XacmlPdpArtifactForwarderParameterGroup(this);
149         }
150     }
151
152     @Override
153     public GroupValidationResult validate() {
154         final GroupValidationResult validationResult = new GroupValidationResult(this);
155         if (!ParameterValidationUtils.validateStringParameter(hostname)) {
156             validationResult.setResult("hostname", ValidationStatus.INVALID,
157                     "must be a non-blank string containing hostname/ipaddress");
158         }
159         if (!ParameterValidationUtils.validateIntParameter(port)) {
160             validationResult.setResult("port", ValidationStatus.INVALID, "must be a positive integer containing port");
161         }
162         if (!ParameterValidationUtils.validateStringParameter(userName)) {
163             validationResult.setResult("userName", ValidationStatus.INVALID,
164                     "must be a non-blank string containing userName");
165         }
166         if (!ParameterValidationUtils.validateStringParameter(password)) {
167             validationResult.setResult("password", ValidationStatus.INVALID,
168                     "must be a non-blank string containing password");
169         }
170         if (!ParameterValidationUtils.validateStringParameter(clientAuth)) {
171             validationResult.setResult("clientAuth", ValidationStatus.INVALID,
172                     "must be a non-blank string containing clientAuth");
173         }
174         if (!ParameterValidationUtils.validateStringParameter(pdpGroup)) {
175             validationResult.setResult("pdpGroup", ValidationStatus.INVALID,
176                     "must be a non-blank string containing pdpGroup");
177         }
178         return validationResult;
179     }
180
181 }