86c8bb4cfeeec212ec57eeeb93bc5d43ac223734
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-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.apex.plugins.event.carrier.restclient;
22
23 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
24 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ValidationStatus;
26
27 /**
28  * Apex parameters for REST as an event carrier technology with Apex as a REST client.
29  *
30  * <p>The parameters for this plugin are:
31  * <ol>
32  * <li>url: The URL that the Apex Rest client will connect to over REST for event reception or event sending. This
33  * parameter is mandatory.
34  * <li>httpMethod: The HTTP method to use when sending events over REST, legal values are POST (default) and PUT. When
35  * receiving events, the REST client plugin always uses the HTTP GET method.
36  * </ol>
37  *
38  * @author Joss Armstrong (joss.armstrong@ericsson.com)
39  */
40 public class RestClientCarrierTechnologyParameters extends CarrierTechnologyParameters {
41
42     /** The label of this carrier technology. */
43     public static final String RESTCLIENT_CARRIER_TECHNOLOGY_LABEL = "RESTCLIENT";
44
45     /** The producer plugin class for the REST carrier technology. */
46     public static final String RESTCLIENT_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestClientProducer.class.getCanonicalName();
47
48     /** The consumer plugin class for the REST carrier technology. */
49     public static final String RESTCLIENT_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestClientConsumer.class.getCanonicalName();
50
51     /** The default HTTP method for output of events. */
52     public static final String DEFAULT_PRODUCER_HTTP_METHOD = "POST";
53
54     /** The HTTP method for input of events. */
55     public static final String CONSUMER_HTTP_METHOD = "GET";
56
57     private String url = null;
58     private String httpMethod = null;
59
60     /**
61      * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
62      * service.
63      */
64     public RestClientCarrierTechnologyParameters() {
65         super();
66
67         // Set the carrier technology properties for the web socket carrier technology
68         this.setLabel(RESTCLIENT_CARRIER_TECHNOLOGY_LABEL);
69         this.setEventProducerPluginClass(RESTCLIENT_EVENT_PRODUCER_PLUGIN_CLASS);
70         this.setEventConsumerPluginClass(RESTCLIENT_EVENT_CONSUMER_PLUGIN_CLASS);
71
72     }
73
74     /**
75      * Gets the URL for the REST request.
76      *
77      * @return the URL
78      */
79     public String getUrl() {
80         return url;
81     }
82
83     /**
84      * Sets the URL for the REST request.
85      *
86      * @param incomingUrl the URL
87      */
88     public void setUrl(final String incomingUrl) {
89         this.url = incomingUrl;
90     }
91
92     /**
93      * Gets the HTTP method to use for the REST request.
94      *
95      * @return the HTTP method
96      */
97     public String getHttpMethod() {
98         return httpMethod;
99     }
100
101     /**
102      * Sets the HTTP method to use for the REST request.
103      *
104      * @param httpMethod the HTTP method
105      */
106     public void setHttpMethod(final String httpMethod) {
107         this.httpMethod = httpMethod;
108     }
109
110     /*
111      * (non-Javadoc)
112      *
113      * @see java.lang.Object#toString()
114      */
115     @Override
116     public String toString() {
117         return "RESTClientCarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + "]";
118     }
119
120     /*
121      *
122      * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
123      */
124     @Override
125     public GroupValidationResult validate() {
126         final GroupValidationResult result = super.validate();
127
128         // Check if the URL has been set for event output
129         if (getUrl() == null) {
130             result.setResult("url", ValidationStatus.INVALID, "no URL has been set for event sending on REST client");
131         }
132
133         return result;
134     }
135 }