bd954d8fb65704a902ff1a30acc22494d0468918
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.distribution.forwarding.apex.pdp;
23
24 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ValidationStatus;
26 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
27 import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
28
29 /**
30  * Holds the parameters for the{@link ApexPdpPolicyForwarder}.
31  */
32 public class ApexPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
33     public static final String POLICY_FORWARDER_PLUGIN_CLASS = ApexPdpPolicyForwarder.class.getName();
34
35     private String hostname;
36     private int port;
37     private boolean ignoreConflicts;
38     private boolean forceUpdate;
39
40     /**
41      * Constructor for instantiating {@link ApexPdpPolicyForwarderParameterGroup} class.
42      *
43      * @param builder the apex forwarder parameter builder
44      */
45     public ApexPdpPolicyForwarderParameterGroup(final ApexPdpPolicyForwarderParameterBuilder builder) {
46         this.hostname = builder.getHostname();
47         this.port = builder.getPort();
48         this.ignoreConflicts = builder.isIgnoreConflicts();
49         this.forceUpdate = builder.isForceUpdate();
50     }
51
52     public String getHostname() {
53         return hostname;
54     }
55
56     public int getPort() {
57         return port;
58     }
59
60     public boolean isIgnoreConflicts() {
61         return ignoreConflicts;
62     }
63
64     public boolean isForceUpdate() {
65         return forceUpdate;
66     }
67
68     @Override
69     public GroupValidationResult validate() {
70         final GroupValidationResult validationResult = new GroupValidationResult(this);
71         if (!ParameterValidationUtils.validateStringParameter(hostname)) {
72             validationResult.setResult("hostname", ValidationStatus.INVALID,
73                     "must be a non-blank string containing hostname/ipaddress");
74         }
75         if (!ParameterValidationUtils.validateIntParameter(port)) {
76             validationResult.setResult("port", ValidationStatus.INVALID, "must be a positive integer containing port");
77         }
78         return validationResult;
79     }
80 }