d5bca3f5a3aca4a70a983b592c452cca4b1d148f
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019-2020 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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.plugins.event.carrier.restclient;
23
24 import lombok.Getter;
25 import lombok.Setter;
26 import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
27 import org.onap.policy.common.parameters.GroupValidationResult;
28 import org.onap.policy.common.parameters.ValidationStatus;
29
30 // @formatter:off
31 /**
32  * Apex parameters for REST as an event carrier technology with Apex as a REST client.
33  *
34  * <p>The parameters for this plugin are:
35  * <ol>
36  * <li>url: The URL that the Apex Rest client will connect to over REST for event reception or event sending. This
37  * parameter is mandatory.
38  * <li>httpMethod: The HTTP method to use when sending events over REST, legal values are POST (default) and PUT. When
39  * receiving events, the REST client plugin always uses the HTTP GET method.
40  * <li>httpHeaders, the HTTP headers to send on REST requests, optional parameter, defaults to none.
41  * <li>httpCodeFilter: a regular expression filter for returned HTTP codes, if the returned HTTP code passes this
42  * filter, then the request is assumed to have succeeded by the plugin, optional, defaults to allowing 2xx codes
43  * through, that is a regular expression of "[2][0-9][0-9]"
44  * </ol>
45  *
46  * @author Joss Armstrong (joss.armstrong@ericsson.com)
47  */
48 //@formatter:on
49 @Setter
50 @Getter
51 public class RestClientCarrierTechnologyParameters extends RestPluginCarrierTechnologyParameters {
52
53     /**
54      * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
55      * service.
56      */
57     public RestClientCarrierTechnologyParameters() {
58         super();
59
60         this.setLabel("RESTCLIENT");
61         this.setEventProducerPluginClass(ApexRestClientProducer.class.getName());
62         this.setEventConsumerPluginClass(ApexRestClientConsumer.class.getName());
63     }
64
65     /**
66      * {@inheritDoc}
67      */
68     @Override
69     public GroupValidationResult validateUrl(final GroupValidationResult result) {
70         // Check if the URL has been set for event output
71         final String urlNullMessage = "no URL has been set for event sending on " + getLabel();
72         if (getUrl() == null) {
73             result.setResult("url", ValidationStatus.INVALID, urlNullMessage);
74             return result;
75         }
76
77         return super.validateUrl(result);
78     }
79 }