Wait for pdp-pap topic in xacml-pdp
[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.NoArgsConstructor;
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.policy.common.endpoints.parameters.RestClientParameters;
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.BeanValidationResult;
31 import org.onap.policy.common.parameters.ParameterGroupImpl;
32 import org.onap.policy.common.parameters.ValidationStatus;
33 import org.onap.policy.common.parameters.annotations.Min;
34 import org.onap.policy.common.parameters.annotations.NotBlank;
35 import org.onap.policy.common.parameters.annotations.NotNull;
36 import org.onap.policy.common.parameters.annotations.Valid;
37 import org.onap.policy.models.base.Validated;
38
39 /**
40  * Class to hold all parameters needed for xacml pdp component.
41  *
42  */
43 @Getter
44 @NotNull
45 @NotBlank
46 @NoArgsConstructor
47 public class XacmlPdpParameterGroup extends ParameterGroupImpl {
48     public static final String PARAM_POLICY_API = "policyApiParameters";
49
50     private String pdpGroup;
51     private String pdpType;
52     @Valid
53     private RestServerParameters restServerParameters;
54     @Valid
55     private RestClientParameters policyApiParameters;
56     @Valid
57     private TopicParameterGroup topicParameterGroup;
58     @Valid
59     private XacmlApplicationParameters applicationParameters;
60     /**
61      * Frequency, in seconds, with which to probe the heartbeat topic before sending the
62      * first heartbeat. Set to zero to disable probing.
63      */
64     @Min(0)
65     private long probeHeartbeatTopicSec = 4;
66
67
68     /**
69      * Create the xacml pdp parameter group.
70      *
71      * @param name the parameter group name
72      * @param pdpGroup the pdp group name
73      */
74     public XacmlPdpParameterGroup(final String name, final String pdpGroup, final String pdpType,
75             final RestServerParameters restServerParameters, final RestClientParameters policyApiParameters,
76             final TopicParameterGroup topicParameterGroup, final XacmlApplicationParameters applicationParameters) {
77         super(name);
78         this.pdpGroup = pdpGroup;
79         this.pdpType = pdpType;
80         this.restServerParameters = restServerParameters;
81         this.policyApiParameters = policyApiParameters;
82         this.topicParameterGroup = topicParameterGroup;
83         this.applicationParameters = applicationParameters;
84     }
85
86     /**
87      * Validate the parameter group.
88      *
89      * @return the result of the validation
90      */
91     @Override
92     public BeanValidationResult validate() {
93         final BeanValidationResult validationResult = super.validate();
94
95         if (policyApiParameters != null && StringUtils.isBlank(policyApiParameters.getHostname())) {
96             var sub = new BeanValidationResult(PARAM_POLICY_API, policyApiParameters);
97             sub.addResult("hostname", policyApiParameters.getHostname(), ValidationStatus.INVALID, Validated.IS_NULL);
98             validationResult.addResult(sub);
99         }
100
101         return validationResult;
102     }
103 }