Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-tca / src / main / java / org / openecomp / dcae / apod / analytics / tca / processor / AbstractTCAECEFPolicyProcessor.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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===========================================
19  */
20
21 package org.openecomp.dcae.apod.analytics.tca.processor;
22
23 import org.openecomp.dcae.apod.analytics.common.exception.MessageProcessingException;
24 import org.openecomp.dcae.apod.analytics.common.service.processor.AbstractMessageProcessor;
25 import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import javax.annotation.Nonnull;
30
31 /**
32  * <p>
33  *     Encapsulates common functionality for all TCA CEF Policy Processors
34  * </p>
35  *
36  * @author Rajiv Singla . Creation Date: 11/9/2016.
37  */
38 public abstract class AbstractTCAECEFPolicyProcessor extends AbstractMessageProcessor<TCACEFProcessorContext> {
39
40     private static final Logger LOG = LoggerFactory.getLogger(AbstractTCAECEFPolicyProcessor.class);
41
42     /**
43      * For all TCA Policy Processor the pre processor ensures that {@link EventListener} object is
44      * present
45      *
46      * @param processorContext incoming Processor Context
47      * @return Pre processed Processor Context
48      */
49     @Override
50     public TCACEFProcessorContext preProcessor(@Nonnull TCACEFProcessorContext processorContext) {
51         // validates CEF Event Listener is Present
52         final EventListener cefEventListener = processorContext.getCEFEventListener();
53         if (cefEventListener == null) {
54             final String errorMessage = String.format(
55                     "CEF Event Listener is not Present.Invalid use of Processor: %s. CEF Message: %s",
56                     getProcessorInfo().getProcessorName(), processorContext.getMessage());
57             throw new MessageProcessingException(errorMessage, LOG, new IllegalArgumentException(errorMessage));
58         }
59         return super.preProcessor(processorContext);
60     }
61 }