Changes for checkstyle 8.32
[policy/apex-pdp.git] / plugins / plugins-event / plugins-event-carrier / plugins-event-carrier-restrequestor / src / main / java / org / onap / policy / apex / plugins / event / carrier / restrequestor / RestRequestorCarrierTechnologyParameters.java
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.restrequestor;
23
24 import java.util.regex.Matcher;
25 import lombok.Getter;
26 import lombok.Setter;
27 import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.common.parameters.ValidationStatus;
30
31 // @formatter:off
32 /**
33  * Apex parameters for REST as an event carrier technology with Apex issuing a REST request and receiving a REST
34  * response.
35  *
36  * <p>The parameters for this plugin are:
37  * <ol>
38  * <li>url: The URL that the Apex Rest Requestor will connect to over REST for REST request sending.
39  * This parameter is mandatory.
40  * <li>httpMethod: The HTTP method to use when making requests over REST, legal values are GET (default),
41  *  POST, PUT, and DELETE.
42  * <li>httpHeaders, the HTTP headers to send on REST requests, optional parameter, defaults to none.
43  * <li>httpCodeFilter: a regular expression filter for returned HTTP codes, if the returned HTTP code passes this
44  * filter, then the request is assumed to have succeeded by the plugin, optional, defaults to allowing 2xx codes
45  * through, that is a regular expression of "[2][0-9][0-9]"
46  * </ol>
47  *
48  * @author Liam Fallon (liam.fallon@ericsson.com)
49  */
50 //@formatter:on
51 @Getter
52 @Setter
53 public class RestRequestorCarrierTechnologyParameters extends RestPluginCarrierTechnologyParameters {
54
55     /** The default HTTP method for request events. */
56     public static final HttpMethod DEFAULT_REQUESTOR_HTTP_METHOD = HttpMethod.GET;
57
58     /** The default timeout for REST requests. */
59     public static final long DEFAULT_REST_REQUEST_TIMEOUT = 500;
60
61     /**
62      * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
63      * service.
64      */
65     public RestRequestorCarrierTechnologyParameters() {
66         super();
67
68         // Set the carrier technology properties for the REST requestor carrier technology
69         this.setLabel("RESTREQUESTOR");
70         this.setEventProducerPluginClass(ApexRestRequestorProducer.class.getName());
71         this.setEventConsumerPluginClass(ApexRestRequestorConsumer.class.getName());
72     }
73
74     // @formatter:off
75     /**
76      * Validate the URL.
77      *
78      * <p>Checks:
79      * http://www.blah.com/{par1/somethingelse (Missing end tag) use  {[^\\{}]*$
80      * http://www.blah.com/{par1/{some}thingelse (Nested tag) use {[^}]*{
81      * http://www.blah.com/{par1}/some}thingelse (Missing start tag1) use }[^{}]*.}
82      * http://www.blah.com/par1}/somethingelse (Missing start tag2) use }[^{}]*}
83      * http://www.blah.com/{}/somethingelse (Empty tag) use {[\s]*}
84      * @param result the result of the validation
85      */
86     // @formatter:on
87     @Override
88     public GroupValidationResult validateUrl(final GroupValidationResult result) {
89         // URL is only set on Requestor consumers
90         if (getUrl() == null) {
91             return result;
92         }
93
94         Matcher matcher = patternErrorKey.matcher(getUrl());
95         if (matcher.find()) {
96             result.setResult("url", ValidationStatus.INVALID,
97                     "no proper URL has been set for event sending on REST requestor");
98         }
99
100         return result;
101     }
102 }