f9328f4187c508df358dc23114ed1ba3ae9c85d3
[policy/apex-pdp.git] / services / services-engine / src / main / java / org / onap / policy / apex / service / parameters / eventprotocol / EventProtocolTextTokenDelimitedParameters.java
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.service.parameters.eventprotocol;
22
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ValidationStatus;
25
26 /**
27  * An event protocol parameter class for token delimited textual event protocols that may be specialized by event
28  * protocol plugins that require plugin specific parameters.
29  *
30  * <p>The following parameters are defined:
31  * <ol>
32  * <li>startDelimiterToken: the token string that delimits the start of text blocks that contain events.
33  * <li>endDelimiterToken: the token string that delimits the end of text blocks that contain events, this parameter is
34  * optional and defaults to null.
35  * <li>delimiterAtStart: indicates if the first text block should have a delimiter at the start (true), or whether
36  * processing of the first block should begin at the start of the text (false). The parameter is optional and defaults
37  * to true.
38  * </ol>
39  *
40  * @author Liam Fallon (liam.fallon@ericsson.com)
41  */
42 public abstract class EventProtocolTextTokenDelimitedParameters extends EventProtocolParameters {
43     // The delimiter token for text blocks
44     private String startDelimiterToken = null;
45     private String endDelimiterToken = null;
46     private boolean delimiterAtStart = true;
47
48     /**
49      * Constructor to create an event protocol parameters instance with the name of a sub class of this class.
50      */
51     public EventProtocolTextTokenDelimitedParameters() {
52         super();
53     }
54
55     /**
56      * Gets the start delimiter token that delimits events in the text.
57      *
58      * @return the start delimiter token
59      */
60     public String getStartDelimiterToken() {
61         return startDelimiterToken;
62     }
63
64     /**
65      * Sets the start delimiter token that delimits events in the text.
66      *
67      * @param startDelimiterToken
68      *        delimiterToken the delimiter token
69      */
70     public void setStartDelimiterToken(final String startDelimiterToken) {
71         this.startDelimiterToken = startDelimiterToken;
72     }
73
74     /**
75      * Gets the end delimiter token that delimits events in the text.
76      *
77      * @return the end delimiter token
78      */
79     public String getEndDelimiterToken() {
80         return endDelimiterToken;
81     }
82
83     /**
84      * Sets the end delimiter token that delimits events in the text.
85      *
86      * @param endDelimiterToken
87      *        delimiterToken the delimiter token
88      */
89     public void setEndDelimiterToken(final String endDelimiterToken) {
90         this.endDelimiterToken = endDelimiterToken;
91     }
92
93     /**
94      * Check if there must be a delimiter at the start of the first text block.
95      * 
96      * @return true if there must be a delimiter at the start of the text block
97      */
98     public boolean isDelimiterAtStart() {
99         return delimiterAtStart;
100     }
101
102     /**
103      * Sets if there has to be a delimiter at the start of the first text block.
104      * 
105      * @param delimiterAtStart
106      *        true if there must be a delimiter at the start of the text block
107      */
108     public void setDelimiterAtStart(boolean delimiterAtStart) {
109         this.delimiterAtStart = delimiterAtStart;
110     }
111
112     @Override
113     public String toString() {
114         return "EventProtocolTextTokenDelimitedParameters [startDelimiterToken=" + startDelimiterToken
115                         + ", endDelimiterToken=" + endDelimiterToken + ", delimiterAtStart=" + delimiterAtStart + "]";
116     }
117
118     /**
119      * {@inheritDoc}.
120      */
121     @Override
122     public GroupValidationResult validate() {
123         final GroupValidationResult result = super.validate();
124
125         if (startDelimiterToken == null || startDelimiterToken.length() == 0) {
126             result.setResult("startDelimiterToken", ValidationStatus.INVALID,
127                             "text start delimiter token not specified or is blank\n");
128         }
129
130         return result;
131     }
132 }