3c0011c24f945ac330b0432813b49b17a1af07af
[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  * <p>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(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 eventProtocolLabel the name of the event protocol for this plugin
80      */
81     public YamlEventProtocolParameters(final String eventProtocolLabel) {
82         super();
83
84         // Set the event protocol properties for the YAML event protocol
85         this.setLabel(eventProtocolLabel);
86
87         // Set the delimiter token for text blocks of YAML events
88         this.setStartDelimiterToken(YAML_START_TEXT_DELIMITER_TOKEN);
89         this.setEndDelimiterToken(YAML_END_TEXT_DELIMITER_TOKEN);
90
91         // Set the event protocol plugin class
92         this.setEventProtocolPluginClass(Apex2YamlEventConverter.class.getCanonicalName());
93     }
94
95     /**
96      * Gets the name alias.
97      *
98      * @return the name alias
99      */
100     public String getNameAlias() {
101         return nameAlias;
102     }
103
104     /**
105      * Gets the version alias.
106      *
107      * @return the version alias
108      */
109     public String getVersionAlias() {
110         return versionAlias;
111     }
112
113     /**
114      * Gets the name space alias.
115      *
116      * @return the name space alias
117      */
118     public String getNameSpaceAlias() {
119         return nameSpaceAlias;
120     }
121
122     /**
123      * Gets the source alias.
124      *
125      * @return the source alias
126      */
127     public String getSourceAlias() {
128         return sourceAlias;
129     }
130
131     /**
132      * Gets the target alias.
133      *
134      * @return the target alias
135      */
136     public String getTargetAlias() {
137         return targetAlias;
138     }
139     
140     /**
141      * Gets the YAML field name.
142      *
143      * @return the YAML field name
144      */
145     public String getYamlFieldName() {
146         return yamlFieldName;
147     }
148
149     /**
150      * Sets the name alias.
151      *
152      * @param nameAlias the new name alias
153      */
154     public void setNameAlias(String nameAlias) {
155         this.nameAlias = nameAlias;
156     }
157
158     /**
159      * Sets the version alias.
160      *
161      * @param versionAlias the new version alias
162      */
163     public void setVersionAlias(String versionAlias) {
164         this.versionAlias = versionAlias;
165     }
166
167     /**
168      * Sets the name space alias.
169      *
170      * @param nameSpaceAlias the new name space alias
171      */
172     public void setNameSpaceAlias(String nameSpaceAlias) {
173         this.nameSpaceAlias = nameSpaceAlias;
174     }
175
176     /**
177      * Sets the source alias.
178      *
179      * @param sourceAlias the new source alias
180      */
181     public void setSourceAlias(String sourceAlias) {
182         this.sourceAlias = sourceAlias;
183     }
184
185     /**
186      * Sets the target alias.
187      *
188      * @param targetAlias the new target alias
189      */
190     public void setTargetAlias(String targetAlias) {
191         this.targetAlias = targetAlias;
192     }
193
194     /**
195      * Sets the encapsulating object name.
196      *
197      * @param yamlFieldName
198      *        the new YAML field name
199      */
200     public void setYamlFieldName(String yamlFieldName) {
201         this.yamlFieldName = yamlFieldName;
202     }
203 }