2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2018 Ericsson. All rights reserved.
 
   4  *  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
 
  10  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  18  * SPDX-License-Identifier: Apache-2.0
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.policy.distribution.reception.parameters;
 
  24 import org.onap.policy.common.parameters.GroupValidationResult;
 
  25 import org.onap.policy.common.parameters.ParameterGroup;
 
  26 import org.onap.policy.common.parameters.ValidationStatus;
 
  27 import org.slf4j.Logger;
 
  28 import org.slf4j.LoggerFactory;
 
  31  * Class to hold all the reception handler parameters.
 
  33  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
 
  35 public class ReceptionHandlerParameters implements ParameterGroup {
 
  37     private static final Logger LOGGER = LoggerFactory.getLogger(ReceptionHandlerParameters.class);
 
  40     private String receptionHandlerType;
 
  41     private String receptionHandlerClassName;
 
  42     private String receptionHandlerConfigurationName;
 
  43     private PluginHandlerParameters pluginHandlerParameters;
 
  46      * Constructor for instantiating ReceptionHandlerParameters.
 
  48      * @param receptionHandlerType the reception handler type
 
  49      * @param receptionHandlerClassName the reception handler class name
 
  50      * @param receptionHandlerConfigurationName the name of the configuration for the reception handler
 
  51      * @param pluginHandlerParameters the plugin handler parameters
 
  53     public ReceptionHandlerParameters(final String receptionHandlerType, final String receptionHandlerClassName,
 
  54             final String receptionHandlerConfigurationName, final PluginHandlerParameters pluginHandlerParameters) {
 
  55         this.receptionHandlerType = receptionHandlerType;
 
  56         this.receptionHandlerClassName = receptionHandlerClassName;
 
  57         this.receptionHandlerConfigurationName = receptionHandlerConfigurationName;
 
  58         this.pluginHandlerParameters = pluginHandlerParameters;
 
  62      * Return the receptionHandlerType of this ReceptionHandlerParameters instance.
 
  64      * @return the receptionHandlerType
 
  66     public String getReceptionHandlerType() {
 
  67         return receptionHandlerType;
 
  71      * Return the receptionHandlerClassName of this ReceptionHandlerParameters instance.
 
  73      * @return the receptionHandlerClassName
 
  75     public String getReceptionHandlerClassName() {
 
  76         return receptionHandlerClassName;
 
  80      * Return the name of the reception handler configuration for this ReceptionHandlerParameters instance.
 
  82      * @return the PssdConfigurationParametersGroup
 
  84     public String getReceptionHandlerConfigurationName() {
 
  85         return receptionHandlerConfigurationName;
 
  89      * Return the pluginHandlerParameters of this ReceptionHandlerParameters instance.
 
  91      * @return the pluginHandlerParameters
 
  93     public PluginHandlerParameters getPluginHandlerParameters() {
 
  94         return pluginHandlerParameters;
 
  98     public String getName() {
 
  99         return name + "_" + receptionHandlerType;
 
 103      * Validate the reception handler parameters.
 
 107     public GroupValidationResult validate() {
 
 108         final GroupValidationResult validationResult = new GroupValidationResult(this);
 
 109         if (receptionHandlerType == null || receptionHandlerType.trim().length() == 0) {
 
 110             validationResult.setResult("receptionHandlerType", ValidationStatus.INVALID, "must be a non-blank string");
 
 112         if (receptionHandlerClassName == null || receptionHandlerClassName.trim().length() == 0) {
 
 113             validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID,
 
 114                     "must be a non-blank string containing full class name of the reception handler");
 
 116             validateReceptionHandlerClass(validationResult);
 
 118         if (pluginHandlerParameters == null) {
 
 119             validationResult.setResult("pluginHandlerParameters", ValidationStatus.INVALID,
 
 120                     "must have a plugin handler");
 
 122             validationResult.setResult("pluginHandlerParameters", pluginHandlerParameters.validate());
 
 124         return validationResult;
 
 127     private void validateReceptionHandlerClass(final GroupValidationResult validationResult) {
 
 129             Class.forName(receptionHandlerClassName);
 
 130         } catch (final ClassNotFoundException exp) {
 
 131             LOGGER.error("reception handler class not found in classpath", exp);
 
 132             validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID,
 
 133                     "reception handler class not found in classpath");
 
 138      * Set the name of this group.
 
 140      * @param name the name to set
 
 143     public void setName(final String name) {