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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pdpx.main.parameters;
26 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
27 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.common.parameters.ParameterGroup;
30 import org.onap.policy.common.parameters.ValidationStatus;
31 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
34 * Class to hold all parameters needed for xacml pdp component.
38 public class XacmlPdpParameterGroup implements ParameterGroup {
39 private static final String PARAM_REST_SERVER = "restServerParameters";
40 private static final String PARAM_POLICY_API = "policyApiParameters";
41 private static final String PARAM_TOPIC_PARAMETER_GROUP = "topicParameterGroup";
42 private static final String PARAM_APPLICATION_PATH = "applicationPath";
44 private static final String ERROR_MSG = "must be a non-blank string";
49 private String pdpGroup;
50 private String pdpType;
51 private RestServerParameters restServerParameters;
52 private RestServerParameters policyApiParameters;
53 private TopicParameterGroup topicParameterGroup;
54 private String applicationPath;
57 * Create the xacml pdp parameter group.
59 * @param name the parameter group name
60 * @param pdpGroup the pdp group name
62 public XacmlPdpParameterGroup(final String name, final String pdpGroup, final String pdpType,
63 final RestServerParameters restServerParameters, final RestServerParameters policyApiParameters,
64 final TopicParameterGroup topicParameterGroup, final String applicationPath) {
66 this.pdpGroup = pdpGroup;
67 this.pdpType = pdpType;
68 this.restServerParameters = restServerParameters;
69 this.policyApiParameters = policyApiParameters;
70 this.topicParameterGroup = topicParameterGroup;
71 this.applicationPath = applicationPath;
75 * Validate the parameter group.
77 * @return the result of the validation
80 public GroupValidationResult validate() {
81 final GroupValidationResult validationResult = new GroupValidationResult(this);
82 if (!ParameterValidationUtils.validateStringParameter(name)) {
83 validationResult.setResult("name", ValidationStatus.INVALID, ERROR_MSG);
85 if (!ParameterValidationUtils.validateStringParameter(pdpGroup)) {
86 validationResult.setResult("pdpGroup", ValidationStatus.INVALID, ERROR_MSG);
88 if (!ParameterValidationUtils.validateStringParameter(pdpType)) {
89 validationResult.setResult("pdpType", ValidationStatus.INVALID, ERROR_MSG);
91 if (restServerParameters == null) {
92 validationResult.setResult(PARAM_REST_SERVER, ValidationStatus.INVALID,
93 "must have restServerParameters to configure xacml pdp rest server");
95 validationResult.setResult(PARAM_REST_SERVER, restServerParameters.validate());
97 if (policyApiParameters == null) {
98 validationResult.setResult(PARAM_POLICY_API, ValidationStatus.INVALID,
99 "must have policyApiParameters to configure xacml pdp rest server");
101 // set the name - this only really matters for validation messages
102 policyApiParameters.setName(PARAM_POLICY_API);
103 validationResult.setResult(PARAM_POLICY_API, policyApiParameters.validate());
105 if (topicParameterGroup == null) {
106 validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, ValidationStatus.INVALID,
107 "must have topicParameterGroup to configure xacml pdp topic sink and source");
109 validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, topicParameterGroup.validate());
112 // Validate the application path directory
114 if (applicationPath == null || applicationPath.isEmpty()) {
115 validationResult.setResult(PARAM_APPLICATION_PATH, ValidationStatus.INVALID,
116 "must have application path for applications to store policies and data.");
118 return validationResult;