Remove topic.properties and incorporate into overall config file for xacml
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / parameters / XacmlPdpParameterGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 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 org.onap.policy.common.endpoints.parameters.RestServerParameters;
25 import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ParameterGroup;
28 import org.onap.policy.common.parameters.ValidationStatus;
29 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
30
31 /**
32  * Class to hold all parameters needed for xacml pdp component.
33  *
34  */
35 public class XacmlPdpParameterGroup implements ParameterGroup {
36     private static final String PARAM_REST_SERVER = "restServerParameters";
37     private static final String PARAM_TOPIC_PARAMETER_GROUP = "topicParameterGroup";
38     private static final String PARAM_APPLICATION_PATH = "applicationPath";
39     private String name;
40     private RestServerParameters restServerParameters;
41     private TopicParameterGroup topicParameterGroup;
42     private String applicationPath;
43
44     /**
45      * Create the xacml pdp parameter group.
46      *
47      * @param name the parameter group name
48      */
49     public XacmlPdpParameterGroup(final String name, final RestServerParameters restServerParameters,
50             final TopicParameterGroup topicParameterGroup, final String applicationPath) {
51         this.name = name;
52         this.restServerParameters = restServerParameters;
53         this.topicParameterGroup = topicParameterGroup;
54         this.applicationPath = applicationPath;
55     }
56
57     /**
58      * Return the name of this parameter group instance.
59      *
60      * @return name the parameter group name
61      */
62     @Override
63     public String getName() {
64         return name;
65     }
66
67     /**
68      * Set the name of this parameter group instance.
69      *
70      * @param name the parameter group name
71      */
72     @Override
73     public void setName(String name) {
74         this.name = name;
75     }
76
77     /**
78      * Return the restServerParameters of this parameter group instance.
79      *
80      * @return the restServerParameters
81      */
82     public RestServerParameters getRestServerParameters() {
83         return restServerParameters;
84     }
85
86     /**
87      * Return the topicParameterGroup of this parameter group instance.
88      *
89      * @return the topicParameterGroup
90      */
91     public TopicParameterGroup getTopicParameterGroup() {
92         return topicParameterGroup;
93     }
94
95     /**
96      * Returns the path where applications will store their data.
97      *
98      * @return String to the path
99      */
100     public String getApplicationPath() {
101         return applicationPath;
102     }
103
104     /**
105      * Validate the parameter group.
106      *
107      * @return the result of the validation
108      */
109     @Override
110     public GroupValidationResult validate() {
111         final GroupValidationResult validationResult = new GroupValidationResult(this);
112         if (!ParameterValidationUtils.validateStringParameter(name)) {
113             validationResult.setResult("name", ValidationStatus.INVALID, "must be a non-blank string");
114         }
115         if (restServerParameters == null) {
116             validationResult.setResult(PARAM_REST_SERVER, ValidationStatus.INVALID,
117                     "must have restServerParameters to configure xacml pdp rest server");
118         } else {
119             validationResult.setResult(PARAM_REST_SERVER, restServerParameters.validate());
120         }
121         if (topicParameterGroup == null) {
122             validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, ValidationStatus.INVALID,
123                     "must have topicParameterGroup to configure xacml pdp topic sink and source");
124         } else {
125             validationResult.setResult(PARAM_TOPIC_PARAMETER_GROUP, topicParameterGroup.validate());
126         }
127         //
128         // Validate the application path directory
129         //
130         if (applicationPath == null || applicationPath.isEmpty()) {
131             validationResult.setResult(PARAM_APPLICATION_PATH, ValidationStatus.INVALID,
132                     "must have application path for applications to store policies and data.");
133         }
134         return validationResult;
135     }
136 }