Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-common / src / main / java / org / openecomp / dcae / apod / analytics / common / service / processor / AbstractProcessorContext.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\r
4  * ================================================================================\r
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  *  Licensed under the Apache License, Version 2.0 (the "License");\r
8  *  you may not use this file except in compliance with the License.\r
9  *   You may obtain a copy of the License at\r
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  *  Unless required by applicable law or agreed to in writing, software\r
14  *  distributed under the License is distributed on an "AS IS" BASIS,\r
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  *  See the License for the specific language governing permissions and\r
17  *  limitations under the License.\r
18  *  ============================LICENSE_END===========================================\r
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.common.service.processor;\r
22 \r
23 import com.google.common.base.Objects;\r
24 \r
25 import java.util.LinkedList;\r
26 import java.util.List;\r
27 \r
28 /**\r
29  * <p>\r
30  *      An abstract implementation for {@link ProcessorContext} which other DCAE Analytics Modules\r
31  *      can extend to add module specific functionality\r
32  * </p>\r
33  *\r
34  * @author Rajiv Singla . Creation Date: 11/7/2016.\r
35  */\r
36 public abstract class AbstractProcessorContext implements ProcessorContext {\r
37 \r
38     private final String message;\r
39     private List<? super MessageProcessor<? extends ProcessorContext>> messageProcessors;\r
40     private boolean canProcessingContinue;\r
41 \r
42     public AbstractProcessorContext(final String message,\r
43                                     boolean canProcessingContinue) {\r
44         this.message = message;\r
45         this.canProcessingContinue = canProcessingContinue;\r
46         this.messageProcessors = new LinkedList<>();\r
47     }\r
48 \r
49     /**\r
50      * Returns JSON String of incoming CEF Message that needs to be processed\r
51      *\r
52      * @return incoming CEF message that needs to be processed\r
53      */\r
54     @Override\r
55     public String getMessage() {\r
56         return message;\r
57     }\r
58 \r
59     /**\r
60      * Sets if it is ok to continue processing normally\r
61      *\r
62      * @return boolean which determines if it is ok to continue processing normally\r
63      */\r
64     @Override\r
65     public boolean canProcessingContinue() {\r
66         return canProcessingContinue;\r
67     }\r
68 \r
69 \r
70     /**\r
71      * Set if it is ok to continue processing normally\r
72      *\r
73      * @param canProcessingContinue sets boolean which determines if it is ok to continue processing normally\r
74      */\r
75     @Override\r
76     public void setProcessingContinueFlag(boolean canProcessingContinue) {\r
77         this.canProcessingContinue = canProcessingContinue;\r
78     }\r
79 \r
80     /**\r
81      * Provides List of message processors which were used in processing CEF message\r
82      *\r
83      * @return List of message processors which were used in processing CEF message\r
84      */\r
85     @Override\r
86     public List<? super MessageProcessor<? extends ProcessorContext>> getMessageProcessors() {\r
87         return messageProcessors;\r
88     }\r
89 \r
90     @Override\r
91     public String toString() {\r
92         return Objects.toStringHelper(this)\r
93                 .add("canProcessingContinue", canProcessingContinue)\r
94                 .toString();\r
95     }\r
96 }\r