861e9cd8f25ec28bad341951a24297430fa6dc9c
[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.protocol.yaml;
22
23 import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTokenDelimitedParameters;
24
25 /**
26  * Event protocol parameters for YAML as an event protocol.
27  *
28  * The parameters for this plugin are:
29  * <ol>
30  * <li>nameAlias: The field in a YAML event to use as an alias for the event name. This parameter is
31  * optional.
32  * <li>versionAlias: The field in a YAML event to use as an alias for the event version. This
33  * parameter is optional.
34  * <li>nameSpaceAlias: The field in a YAML event to use as an alias for the event name space. This
35  * parameter is optional.
36  * <li>sourceAlias: The field in a YAML event to use as an alias for the event source. This
37  * parameter is optional.
38  * <li>targetAlias: The field in a YAML event to use as an alias for the event target. This
39  * parameter is optional.
40  * <li>yamlFieldName: The name of the field in the APEX event that will contain the unmarshaled YAML object. The
41  * parameter is optional and defaults to the value "yaml_field".
42  * </ol>
43  * 
44  * @author Liam Fallon (liam.fallon@ericsson.com)
45  */
46 public class YamlEventProtocolParameters extends EventProtocolTextTokenDelimitedParameters {
47     /** The label of this event protocol. */
48     public static final String YAML_EVENT_PROTOCOL_LABEL = "YAML";
49
50     // Constants for text block delimiters
51     private static final String YAML_START_TEXT_DELIMITER_TOKEN = "---";
52     private static final String YAML_END_TEXT_DELIMITER_TOKEN = "...";
53
54     // Default parameter values
55     private static final String DEFAULT_YAML_FIELD_NAME = "yaml_field";
56
57     // Aliases for Apex event header fields
58     // @formatter:off
59     private String nameAlias      = null;
60     private String versionAlias   = null;
61     private String nameSpaceAlias = null;
62     private String sourceAlias    = null;
63     private String targetAlias    = null;
64     private String yamlFieldName  = DEFAULT_YAML_FIELD_NAME;
65     // @formatter:on
66
67     /**
68      * Constructor to create a YAML event protocol parameter instance and register the instance with
69      * the parameter service.
70      */
71     public YamlEventProtocolParameters() {
72         this(YamlEventProtocolParameters.class.getCanonicalName(), YAML_EVENT_PROTOCOL_LABEL);
73     }
74
75     /**
76      * Constructor to create an event protocol parameters instance with the name of a sub class of
77      * this class.
78      *
79      * @param parameterClassName the class name of a sub class of this class
80      * @param eventProtocolLabel the name of the event protocol for this plugin
81      */
82     public YamlEventProtocolParameters(final String parameterClassName, final String eventProtocolLabel) {
83         super(parameterClassName);
84
85         // Set the event protocol properties for the YAML event protocol
86         this.setLabel(eventProtocolLabel);
87
88         // Set the delimiter token for text blocks of YAML events
89         this.setStartDelimiterToken(YAML_START_TEXT_DELIMITER_TOKEN);
90         this.setEndDelimiterToken(YAML_END_TEXT_DELIMITER_TOKEN);
91
92         // Set the event protocol plugin class
93         this.setEventProtocolPluginClass(Apex2YamlEventConverter.class.getCanonicalName());
94     }
95
96     /**
97      * Gets the name alias.
98      *
99      * @return the name alias
100      */
101     public String getNameAlias() {
102         return nameAlias;
103     }
104
105     /**
106      * Gets the version alias.
107      *
108      * @return the version alias
109      */
110     public String getVersionAlias() {
111         return versionAlias;
112     }
113
114     /**
115      * Gets the name space alias.
116      *
117      * @return the name space alias
118      */
119     public String getNameSpaceAlias() {
120         return nameSpaceAlias;
121     }
122
123     /**
124      * Gets the source alias.
125      *
126      * @return the source alias
127      */
128     public String getSourceAlias() {
129         return sourceAlias;
130     }
131
132     /**
133      * Gets the target alias.
134      *
135      * @return the target alias
136      */
137     public String getTargetAlias() {
138         return targetAlias;
139     }
140     
141     /**
142      * Gets the YAML field name.
143      *
144      * @return the YAML field name
145      */
146     public String getYamlFieldName() {
147         return yamlFieldName;
148     }
149
150     /**
151      * Sets the name alias.
152      *
153      * @param nameAlias the new name alias
154      */
155     public void setNameAlias(String nameAlias) {
156         this.nameAlias = nameAlias;
157     }
158
159     /**
160      * Sets the version alias.
161      *
162      * @param versionAlias the new version alias
163      */
164     public void setVersionAlias(String versionAlias) {
165         this.versionAlias = versionAlias;
166     }
167
168     /**
169      * Sets the name space alias.
170      *
171      * @param nameSpaceAlias the new name space alias
172      */
173     public void setNameSpaceAlias(String nameSpaceAlias) {
174         this.nameSpaceAlias = nameSpaceAlias;
175     }
176
177     /**
178      * Sets the source alias.
179      *
180      * @param sourceAlias the new source alias
181      */
182     public void setSourceAlias(String sourceAlias) {
183         this.sourceAlias = sourceAlias;
184     }
185
186     /**
187      * Sets the target alias.
188      *
189      * @param targetAlias the new target alias
190      */
191     public void setTargetAlias(String targetAlias) {
192         this.targetAlias = targetAlias;
193     }
194
195     /**
196      * Sets the encapsulating object name.
197      *
198      * @param yamlFieldName
199      *        the new YAML field name
200      */
201     public void setYamlFieldName(String yamlFieldName) {
202         this.yamlFieldName = yamlFieldName;
203     }
204 }