2 * ===============================LICENSE_START======================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============================LICENSE_END===========================================
21 package org.openecomp.dcae.apod.analytics.tca.processor;
23 import org.openecomp.dcae.apod.analytics.model.domain.cef.Domain;
24 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
28 * TCA Processor which acts like a filter to filter out messages which does not belong to TCA Policy Domain
30 * Pre Conditions: CEF Event Listener must be present
33 * @author Rajiv Singla . Creation Date: 11/7/2016.
35 public class TCACEFPolicyDomainFilter extends AbstractTCAECEFPolicyProcessor {
38 private static final long serialVersionUID = 1L;
41 public String getProcessorDescription() {
42 return "Filters out CEF Messages which does not match TCAPolicy Domain";
46 public TCACEFProcessorContext processMessage(TCACEFProcessorContext processorContext) {
48 // Safe to get event Listener here without null check as pre processor will validate if
49 // event listener is indeed present
50 final EventListener eventListener = processorContext.getCEFEventListener();
52 Domain cefMessageDomain;
54 // Extract CEF domain as it is must be present as per CEF Schema
55 if (eventListener.getEvent() != null &&
56 eventListener.getEvent().getCommonEventHeader() != null &&
57 eventListener.getEvent().getCommonEventHeader().getDomain() != null) {
58 cefMessageDomain = eventListener.getEvent().getCommonEventHeader().getDomain();
61 final String terminatingMessage = "Invalid CEF Message.Common Event Header Domain not present.";
62 setTerminatingProcessingMessage(terminatingMessage, processorContext);
63 return processorContext;
66 // Get Policy Domain. TCA Policy Validation must ensure that Domain is indeed present
67 // no null check will be required here
68 final String policyDomain = processorContext.getTCAPolicy().getDomain();
70 // If Policy domain matches CEF message domain then continue processing
71 if (cefMessageDomain.toString().equalsIgnoreCase(policyDomain)) {
72 final String finishMessage = String.format("Policy Domain and CEF Message Domain match successful." +
73 " Message Domain: %s, Policy Domain: %s", cefMessageDomain, policyDomain);
74 setFinishedProcessingMessage(finishMessage, processorContext);
76 // If policy domain does not match with CEF message terminate processing chain
77 final String terminatingMessage = String.format("Policy Domain and CEF Message Domain match unsuccessful." +
78 " Message Domain: %s, Policy Domain: %s", cefMessageDomain, policyDomain);
79 setTerminatingProcessingMessage(terminatingMessage, processorContext);
82 return processorContext;