TCA: Support for VES/A&AI enrichment
[dcaegen2/analytics/tca.git] / dcae-analytics-tca / src / main / java / org / openecomp / dcae / apod / analytics / tca / processor / TCACEFPolicyDomainFilter.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.tca.processor;\r
22 \r
23 import org.openecomp.dcae.apod.analytics.model.domain.cef.Domain;\r
24 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;\r
25 \r
26 /**\r
27  * <p>\r
28  *     TCA Processor which acts like a filter to filter out messages which does not belong to TCA Policy Domain\r
29  *     <br>\r
30  *     Pre Conditions: CEF Event Listener must be present\r
31  * </p>\r
32  *\r
33  * @author Rajiv Singla . Creation Date: 11/7/2016.\r
34  */\r
35 public class TCACEFPolicyDomainFilter extends AbstractTCAECEFPolicyProcessor {\r
36 \r
37 \r
38     private static final long serialVersionUID = 1L;\r
39 \r
40     @Override\r
41     public String getProcessorDescription() {\r
42         return "Filters out CEF Messages which does not match TCAPolicy Domain";\r
43     }\r
44 \r
45     @Override\r
46     public TCACEFProcessorContext processMessage(TCACEFProcessorContext processorContext) {\r
47 \r
48         // Safe to get event Listener here without null check as pre processor will validate if\r
49         // event listener is indeed present\r
50         final EventListener eventListener = processorContext.getCEFEventListener();\r
51 \r
52         Domain cefMessageDomain;\r
53 \r
54         // Extract CEF domain as it is must be present as per CEF Schema\r
55         if (eventListener.getEvent() != null &&\r
56                 eventListener.getEvent().getCommonEventHeader() != null &&\r
57                 eventListener.getEvent().getCommonEventHeader().getDomain() != null) {\r
58             cefMessageDomain = eventListener.getEvent().getCommonEventHeader().getDomain();\r
59 \r
60         } else {\r
61             final String terminatingMessage = "Invalid CEF Message.Common Event Header Domain not present.";\r
62             setTerminatingProcessingMessage(terminatingMessage, processorContext);\r
63             return processorContext;\r
64         }\r
65 \r
66         // Get Policy Domain. TCA Policy Validation must ensure that Domain is indeed present\r
67         // no null check will be required here\r
68         final String policyDomain = processorContext.getTCAPolicy().getDomain();\r
69 \r
70         // If Policy domain matches CEF message domain then continue processing\r
71         if (cefMessageDomain.toString().equalsIgnoreCase(policyDomain)) {\r
72             final String finishMessage = String.format("Policy Domain and CEF Message Domain match successful." +\r
73                     " Message Domain: %s, Policy Domain: %s", cefMessageDomain, policyDomain);\r
74             setFinishedProcessingMessage(finishMessage, processorContext);\r
75         } else {\r
76             // If policy domain does not match with CEF message terminate processing chain\r
77             final String terminatingMessage = String.format("Policy Domain and CEF Message Domain match unsuccessful." +\r
78                     " Message Domain: %s, Policy Domain: %s", cefMessageDomain, policyDomain);\r
79             setTerminatingProcessingMessage(terminatingMessage, processorContext);\r
80         }\r
81 \r
82         return processorContext;\r
83     }\r
84 }\r