beb27308656592363123a8c8b0454be3d20b9017
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.controlloop.participant.dcae.main.parameters;
22
23 import javax.validation.constraints.NotBlank;
24 import lombok.Getter;
25 import org.apache.commons.lang3.StringUtils;
26 import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
27 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
28 import org.onap.policy.common.parameters.BeanValidationResult;
29 import org.onap.policy.common.parameters.ParameterGroupImpl;
30 import org.onap.policy.common.parameters.ValidationStatus;
31 import org.onap.policy.common.parameters.annotations.NotNull;
32 import org.onap.policy.common.parameters.annotations.Valid;
33 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
34
35 /**
36  * Class to hold all parameters needed for the participant dcae.
37  *
38  */
39 @NotNull
40 @NotBlank
41 @Getter
42 public class ParticipantDcaeParameters extends ParameterGroupImpl {
43     @Valid
44     private RestServerParameters clampClientParameters;
45
46     @Valid
47     private RestServerParameters consulClientParameters;
48
49     private ParticipantIntermediaryParameters intermediaryParameters;
50     private PolicyModelsProviderParameters databaseProviderParameters;
51
52     /**
53      * Create the participant dcae parameter group.
54      *
55      * @param name the parameter group name
56      */
57     public ParticipantDcaeParameters(final String name) {
58         super(name);
59     }
60
61     /**
62      * {@inheritDoc}.
63      */
64     @Override
65     public BeanValidationResult validate() {
66         BeanValidationResult result = super.validate();
67         if (result.isValid()) {
68             result.addResult(checkMissingMandatoryParams(clampClientParameters));
69             result.addResult(checkMissingMandatoryParams(consulClientParameters));
70         }
71         return result;
72     }
73
74     private BeanValidationResult checkMissingMandatoryParams(RestServerParameters clientParameters) {
75         BeanValidationResult result = new BeanValidationResult(clientParameters.getName(), clientParameters);
76         if (StringUtils.isBlank(clientParameters.getHost())) {
77             result.addResult("Host", clientParameters.getHost(), ValidationStatus.INVALID, "is blank");
78         }
79         if (StringUtils.isBlank(clientParameters.getName())) {
80             result.addResult("Name", clientParameters.getName(), ValidationStatus.INVALID, "is blank");
81         }
82         if (StringUtils.isBlank(clientParameters.getPassword())) {
83             result.addResult("Password", clientParameters.getPassword(), ValidationStatus.INVALID, "is blank");
84         }
85         if (StringUtils.isBlank(clientParameters.getUserName())) {
86             result.addResult("UserName", clientParameters.getUserName(), ValidationStatus.INVALID, "is blank");
87         }
88         if (clientParameters.getPort() <= 0 || clientParameters.getPort() >= 65535) {
89             result.addResult("Port", clientParameters.getPort(), ValidationStatus.INVALID, "is not valid");
90         }
91         return result;
92     }
93 }