add SDC client and reception handle
[multicloud/framework.git] / artifactbroker / reception / src / main / java / org / onap / policy / distribution / reception / parameters / ReceptionHandlerParameters.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. 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.parameters;
22
23 import org.onap.policy.common.logging.flexlogger.FlexLogger;
24 import org.onap.policy.common.logging.flexlogger.Logger;
25 import org.onap.policy.common.parameters.GroupValidationResult;
26 import org.onap.policy.common.parameters.ParameterGroup;
27 import org.onap.policy.common.parameters.ValidationStatus;
28
29 /**
30  * Class to hold all the reception handler parameters.
31  *
32  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
33  */
34 public class ReceptionHandlerParameters implements ParameterGroup {
35
36     private static final Logger LOGGER = FlexLogger.getLogger(ReceptionHandlerParameters.class);
37
38     private String name;
39     private String receptionHandlerType;
40     private String receptionHandlerClassName;
41     private String receptionHandlerConfigurationName;
42     private PluginHandlerParameters pluginHandlerParameters;
43
44     /**
45      * Constructor for instantiating ReceptionHandlerParameters.
46      *
47      * @param receptionHandlerType the reception handler type
48      * @param receptionHandlerClassName the reception handler class name
49      * @param receptionHandlerConfigurationName the name of the configuration for the reception
50      *        handler
51      * @param pluginHandlerParameters the plugin handler parameters
52      */
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;
59     }
60
61     /**
62      * Return the receptionHandlerType of this ReceptionHandlerParameters instance.
63      *
64      * @return the receptionHandlerType
65      */
66     public String getReceptionHandlerType() {
67         return receptionHandlerType;
68     }
69
70     /**
71      * Return the receptionHandlerClassName of this ReceptionHandlerParameters instance.
72      *
73      * @return the receptionHandlerClassName
74      */
75     public String getReceptionHandlerClassName() {
76         return receptionHandlerClassName;
77     }
78
79     /**
80      * Return the name of the reception handler configuration for this ReceptionHandlerParameters
81      * instance.
82      *
83      * @return the PssdConfigurationParametersGroup
84      */
85     public String getReceptionHandlerConfigurationName() {
86         return receptionHandlerConfigurationName;
87     }
88
89     /**
90      * Return the pluginHandlerParameters of this ReceptionHandlerParameters instance.
91      *
92      * @return the pluginHandlerParameters
93      */
94     public PluginHandlerParameters getPluginHandlerParameters() {
95         return pluginHandlerParameters;
96     }
97
98     @Override
99     public String getName() {
100         return name + "_" + receptionHandlerType;
101     }
102
103     /**
104      * Validate the reception handler parameters.
105      *
106      */
107     @Override
108     public GroupValidationResult validate() {
109         final GroupValidationResult validationResult = new GroupValidationResult(this);
110         if (receptionHandlerType == null || receptionHandlerType.trim().length() == 0) {
111             validationResult.setResult("receptionHandlerType", ValidationStatus.INVALID, "must be a non-blank string");
112         }
113         if (receptionHandlerClassName == null || receptionHandlerClassName.trim().length() == 0) {
114             validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID,
115                     "must be a non-blank string containing full class name of the reception handler");
116         } else {
117             validateReceptionHandlerClass(validationResult);
118         }
119         if (pluginHandlerParameters == null) {
120             validationResult.setResult("pluginHandlerParameters", ValidationStatus.INVALID,
121                     "must have a plugin handler");
122         } else {
123             validationResult.setResult("pluginHandlerParameters", pluginHandlerParameters.validate());
124         }
125         return validationResult;
126     }
127
128     private void validateReceptionHandlerClass(final GroupValidationResult validationResult) {
129         try {
130             Class.forName(receptionHandlerClassName);
131         } catch (final ClassNotFoundException exp) {
132             LOGGER.error("reception handler class not found in classpath", exp);
133             validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID,
134                     "reception handler class not found in classpath");
135         }
136     }
137
138     /**
139      * Set the name of this group.
140      *
141      * @param name the name to set
142      */
143     @Override
144     public void setName(final String name) {
145         this.name = name;
146     }
147 }