26fd2a5a493a299f71fd7eed22a827ad39b50d94
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Intel. All rights reserved.
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.distribution.reception.decoding.pdpx;
22
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ValidationStatus;
25 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
26 import org.onap.policy.distribution.reception.handling.sdc.SdcReceptionHandlerConfigurationParameterGroup;
27 import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup;
28
29 /**
30  * This class handles reading, parsing and validating of the paramaters for the
31  * {@link PolicyDecoderCsarPdpx}.
32  */
33 public class PolicyDecoderCsarPdpxConfigurationParameterGroup extends PolicyDecoderConfigurationParameterGroup {
34
35     private String policyNamePrefix;
36     private String onapName;
37     private String version;
38     private String priority;
39     private String riskType;
40     private String riskLevel;
41
42     /**
43      * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup}
44      * class.
45      *
46      * @param builder the SDC configuration builder
47      */
48     public PolicyDecoderCsarPdpxConfigurationParameterGroup(
49             final PolicyDecoderCsarPdpxConfigurationParameterBuilder builder) {
50         policyNamePrefix = builder.getPolicyNamePrefix();
51         onapName = builder.getOnapName();
52         version = builder.getVersion();
53         priority = builder.getPriority();
54         riskType = builder.getRiskType();
55         riskLevel = builder.getRiskLevel();
56     }
57
58     public String getPolicyNamePrefix() {
59         return policyNamePrefix;
60     }
61
62     public String getOnapName() {
63         return onapName;
64     }
65
66     public String getVersion() {
67         return version;
68     }
69
70     public String getPriority() {
71         return priority;
72     }
73
74     public String getRiskType() {
75         return riskType;
76     }
77
78     public String getRiskLevel() {
79         return riskLevel;
80     }
81
82     /**
83      * {@inheritDoc}.
84      */
85     @Override
86     public GroupValidationResult validate() {
87         final GroupValidationResult validationResult = new GroupValidationResult(this);
88         validateStringElement(validationResult, policyNamePrefix, "policyNamePrefix");
89         validateStringElement(validationResult, onapName, "onapName");
90         validateStringElement(validationResult, version, "version");
91         validateStringElement(validationResult, priority, "priority");
92         validateStringElement(validationResult, riskType, "riskType");
93         validateStringElement(validationResult, riskLevel, "riskLevel");
94         return validationResult;
95     }
96
97     /**
98      * Validate the string element.
99      *
100      * @param validationResult the result object
101      * @param element the element to validate
102      * @param elementName the element name for error message
103      */
104     private void validateStringElement(final GroupValidationResult validationResult, final String element,
105             final String elementName) {
106         if (!ParameterValidationUtils.validateStringParameter(element)) {
107             validationResult.setResult(elementName, ValidationStatus.INVALID,
108                     elementName + " must be a non-blank string");
109         }
110     }
111 }
112