add SDC client and reception handle
[multicloud/framework.git] / artifactbroker / forwarding / src / main / java / org / onap / policy / distribution / forwarding / parameters / ArtifactForwarderParameters.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.forwarding.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 Artifact forwarder parameters.
31  *
32  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
33  */
34 public class ArtifactForwarderParameters implements ParameterGroup {
35
36     private static final Logger LOGGER = FlexLogger.getLogger(ArtifactForwarderParameters.class);
37
38     private String forwarderType;
39     private String forwarderClassName;
40     private String forwarderConfigurationName;
41
42     /**
43      * Constructor for instantiating ArtifactForwarderParameters.
44      *
45      * @param forwarderType the Artifact forwarder type
46      * @param forwarderClassName the Artifact forwarder class name
47      * @param forwarderConfigurationName the name of the configuration for the Artifact forwarder
48      */
49     public ArtifactForwarderParameters(final String forwarderType, final String forwarderClassName,
50             final String forwarderConfigurationName) {
51         this.forwarderType = forwarderType;
52         this.forwarderClassName = forwarderClassName;
53         this.forwarderConfigurationName = forwarderConfigurationName;
54     }
55
56     /**
57      * Return the forwarderType of this ArtifactForwarderParameters instance.
58      *
59      * @return the forwarderType
60      */
61     public String getForwarderType() {
62         return forwarderType;
63     }
64
65     /**
66      * Return the forwarderClassName of this ArtifactForwarderParameters instance.
67      *
68      * @return the forwarderClassName
69      */
70     public String getForwarderClassName() {
71         return forwarderClassName;
72     }
73
74     /**
75      * Return the name of the forwarder configuration of this ArtifactForwarderParameters instance.
76      *
77      * @return the the name of the forwarder configuration
78      */
79     public String getForwarderConfigurationName() {
80         return forwarderConfigurationName;
81     }
82
83     /**
84      * {@inheritDoc}.
85      */
86     @Override
87     public String getName() {
88         return getForwarderType();
89     }
90
91     /**
92      * {@inheritDoc}.
93      */
94     @Override
95     public void setName(final String name) {
96         this.forwarderType = name;
97     }
98
99     /**
100      * {@inheritDoc}.
101      */
102     @Override
103     public GroupValidationResult validate() {
104         final GroupValidationResult validationResult = new GroupValidationResult(this);
105         if (forwarderType == null || forwarderType.trim().length() == 0) {
106             validationResult.setResult("forwarderType", ValidationStatus.INVALID, "must be a non-blank string");
107         }
108         if (forwarderClassName == null || forwarderClassName.trim().length() == 0) {
109             validationResult.setResult("forwarderClassName", ValidationStatus.INVALID,
110                     "must be a non-blank string containing full class name of the forwarder");
111         } else {
112             validateArtifactForwarderClass(validationResult);
113         }
114         return validationResult;
115     }
116
117     private void validateArtifactForwarderClass(final GroupValidationResult validationResult) {
118         try {
119             Class.forName(forwarderClassName);
120         } catch (final ClassNotFoundException exp) {
121             LOGGER.trace("Artifact forwarder class not found in classpath", exp);
122             validationResult.setResult("forwarderClassName", ValidationStatus.INVALID,
123                     "Artifact forwarder class not found in classpath");
124         }
125     }
126 }