Change RestServerParameters to BusTopicParams
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / parameters / XacmlPdpParameterGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
4  * Modifications Copyright (C) 2019 Nordix Foundation.
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.pdpx.main.parameters;
23
24 import lombok.Getter;
25 import lombok.Setter;
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
28 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
29 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
30 import org.onap.policy.common.parameters.GroupValidationResult;
31 import org.onap.policy.common.parameters.ParameterGroup;
32 import org.onap.policy.common.parameters.ValidationStatus;
33 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
34
35 /**
36  * Class to hold all parameters needed for xacml pdp component.
37  *
38  */
39 @Getter
40 public class XacmlPdpParameterGroup implements ParameterGroup {
41     private static final String PARAM_REST_SERVER = "restServerParameters";
42     private static final String PARAM_POLICY_API = "policyApiParameters";
43     private static final String PARAM_TOPIC_PARAMETER_GROUP = "topicParameterGroup";
44     private static final String PARAM_APPLICATION_PATH = "applicationPath";
45
46     private static final String ERROR_MSG = "must be a non-blank string";
47
48     @Setter
49     private String name;
50
51     private String pdpGroup;
52     private String pdpType;
53     private RestServerParameters restServerParameters;
54     private BusTopicParams policyApiParameters;
55     private TopicParameterGroup topicParameterGroup;
56     private String applicationPath;
57
58     /**
59      * Create the xacml pdp parameter group.
60      *
61      * @param name the parameter group name
62      * @param pdpGroup the pdp group name
63      */
64     public XacmlPdpParameterGroup(final String name, final String pdpGroup, final String pdpType,
65             final RestServerParameters restServerParameters, final BusTopicParams policyApiParameters,
66             final TopicParameterGroup topicParameterGroup, final String applicationPath) {
67         this.name = name;
68         this.pdpGroup = pdpGroup;
69         this.pdpType = pdpType;
70         this.restServerParameters = restServerParameters;
71         this.policyApiParameters = policyApiParameters;
72         this.topicParameterGroup = topicParameterGroup;
73         this.applicationPath = applicationPath;
74     }
75
76     /**
77      * Validate the parameter group.
78      *
79      * @return the result of the validation
80      */
81     @Override
82     public GroupValidationResult validate() {
83         final GroupValidationResult validationResult = new GroupValidationResult(this);
84         if (!ParameterValidationUtils.validateStringParameter(name)) {
85             validationResult.setResult("name", ValidationStatus.INVALID, ERROR_MSG);
86         }
87         if (!ParameterValidationUtils.validateStringParameter(pdpGroup)) {
88             validationResult.setResult("pdpGroup", ValidationStatus.INVALID, ERROR_MSG);
89         }
90         if (!ParameterValidationUtils.validateStringParameter(pdpType)) {
91             validationResult.setResult("pdpType", ValidationStatus.INVALID, ERROR_MSG);
92         }
93         if (restServerParameters == null) {
94             validationResult.setResult(PARAM_REST_SERVER, ValidationStatus.INVALID,
95                     "must have restServerParameters to configure xacml pdp rest server");
96         } else {
97             validationResult.setResult(PARAM_REST_SERVER, restServerParameters.validate());
98         }
99         if (policyApiParameters == null) {
100             validationResult.setResult(PARAM_POLICY_API, ValidationStatus.INVALID,
101                             "must have policyApiParameters to configure xacml pdp rest server");
102         } else if (StringUtils.isBlank(policyApiParameters.getHostname())) {
103             validationResult.setResult(PARAM_POLICY_API, ValidationStatus.INVALID,
104                             "must have hostname to configure xacml pdp api client");
105         }
106         if (topicParameterGroup == null) {
107             validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, ValidationStatus.INVALID,
108                     "must have topicParameterGroup to configure xacml pdp topic sink and source");
109         } else {
110             validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, topicParameterGroup.validate());
111         }
112         //
113         // Validate the application path directory
114         //
115         if (applicationPath == null || applicationPath.isEmpty()) {
116             validationResult.setResult(PARAM_APPLICATION_PATH, ValidationStatus.INVALID,
117                     "must have application path for applications to store policies and data.");
118         }
119         return validationResult;
120     }
121 }