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
 
   9  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  17  * SPDX-License-Identifier: Apache-2.0
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.policy.distribution.reception.handling.sdc;
 
  23 import java.util.List;
 
  24 import java.util.UUID;
 
  26 import org.onap.policy.common.parameters.GroupValidationResult;
 
  27 import org.onap.policy.common.parameters.ValidationStatus;
 
  28 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
 
  29 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
 
  32  * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
 
  33  * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
 
  35 public class SdcReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
 
  37     private String asdcAddress;
 
  38     private List<String> messageBusAddress;
 
  40     private String password;
 
  41     private int pollingInterval;
 
  42     private int pollingTimeout;
 
  43     private String consumerId;
 
  44     private List<String> artifactTypes;
 
  45     private String consumerGroup;
 
  46     private String environmentName;
 
  47     private String keyStorePath;
 
  48     private String keyStorePassword;
 
  49     private boolean activeServerTlsAuth;
 
  50     private boolean isFilterInEmptyResources;
 
  51     private boolean isUseHttpsWithDmaap;
 
  54      * The constructor for instantiating {@link SdcReceptionHandlerConfigurationParameterGroup} class.
 
  56      * @param builder the SDC configuration builder
 
  58     public SdcReceptionHandlerConfigurationParameterGroup(
 
  59             final SdcReceptionHandlerConfigurationParameterBuilder builder) {
 
  60         asdcAddress = builder.getAsdcAddress();
 
  61         messageBusAddress = builder.getMessageBusAddress();
 
  62         user = builder.getUser();
 
  63         password = builder.getPassword();
 
  64         pollingInterval = builder.getPollingInterval();
 
  65         pollingTimeout = builder.getPollingTimeout();
 
  66         consumerId = builder.getConsumerId();
 
  67         artifactTypes = builder.getArtifactTypes();
 
  68         consumerGroup = builder.getConsumerGroup();
 
  69         environmentName = builder.getEnvironmentName();
 
  70         keyStorePath = builder.getKeystorePath();
 
  71         keyStorePassword = builder.getKeystorePassword();
 
  72         activeServerTlsAuth = builder.isActiveserverTlsAuth();
 
  73         isFilterInEmptyResources = builder.isFilterinEmptyResources();
 
  74         isUseHttpsWithDmaap = builder.getIsUseHttpsWithDmaap();
 
  78     public String getAsdcAddress() {
 
  82     public List<String> getMessageBusAddress() {
 
  83         return messageBusAddress;
 
  86     public String getUser() {
 
  90     public String getPassword() {
 
  94     public int getPollingInterval() {
 
  95         return pollingInterval;
 
  98     public int getPollingTimeout() {
 
  99         return pollingTimeout;
 
 102     public String getConsumerId() {
 
 106     public List<String> getArtifactTypes() {
 
 107         return artifactTypes;
 
 110     public String getConsumerGroup() {
 
 111         return consumerGroup;
 
 114     public String getEnvironmentName() {
 
 115         return environmentName;
 
 118     public String getKeyStorePassword() {
 
 119         return keyStorePassword;
 
 122     public boolean isActiveServerTlsAuth() {
 
 123         return activeServerTlsAuth;
 
 126     public String getKeyStorePath() {
 
 130     public boolean isFilterInEmptyResources() {
 
 131         return isFilterInEmptyResources;
 
 134     public boolean isUseHttpsWithDmaap() {
 
 135         return isUseHttpsWithDmaap;
 
 139      * Set the name of this group.
 
 141      * @param name the name to set.
 
 144     public void setName(final String name) {
 
 145         super.setName(name + "_" + UUID.randomUUID().toString());
 
 152     public GroupValidationResult validate() {
 
 153         final GroupValidationResult validationResult = new GroupValidationResult(this);
 
 154         validateStringElement(validationResult, asdcAddress, "asdcAddress");
 
 155         validateStringElement(validationResult, user, "user");
 
 156         validateStringElement(validationResult, consumerId, "consumerId");
 
 157         validateStringElement(validationResult, consumerGroup, "consumerGroup");
 
 158         validateStringElement(validationResult, keyStorePath, "keyStorePath");
 
 159         validateStringElement(validationResult, keyStorePassword, "keyStorePassword");
 
 160         validateIntElement(validationResult, pollingInterval, "pollingInterval");
 
 161         validateIntElement(validationResult, pollingTimeout, "pollingTimeout");
 
 162         validateStringListElement(validationResult, messageBusAddress, "messageBusAddress");
 
 163         validateStringListElement(validationResult, artifactTypes, "artifactTypes");
 
 164         return validationResult;
 
 168      * Validate the integer Element.
 
 170      * @param validationResult the result object
 
 171      * @param element the element to validate
 
 172      * @param elementName the element name for error message
 
 174     private void validateIntElement(final GroupValidationResult validationResult, final int element,
 
 175             final String elementName) {
 
 176         if (!ParameterValidationUtils.validateIntParameter(element)) {
 
 177             validationResult.setResult(elementName, ValidationStatus.INVALID,
 
 178                     elementName + " must be a positive integer");
 
 183      * Validate the String List Element.
 
 185      * @param validationResult the result object
 
 186      * @param element the element to validate
 
 187      * @param elementName the element name for error message
 
 189     private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element,
 
 190             final String elementName) {
 
 191         for (final String temp : element) {
 
 192             if (!ParameterValidationUtils.validateStringParameter(temp)) {
 
 193                 validationResult.setResult(elementName, ValidationStatus.INVALID,
 
 194                         "the string of " + elementName + "must be a non-blank string");
 
 200      * Validate the string element.
 
 202      * @param validationResult the result object
 
 203      * @param element the element to validate
 
 204      * @param elementName the element name for error message
 
 206     private void validateStringElement(final GroupValidationResult validationResult, final String element,
 
 207             final String elementName) {
 
 208         if (!ParameterValidationUtils.validateStringParameter(element)) {
 
 209             validationResult.setResult(elementName, ValidationStatus.INVALID,
 
 210                     elementName + " must be a non-blank string");