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