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.onap.dcae.apod.analytics.tca.processor;
23 import org.onap.dcae.apod.analytics.common.exception.MessageProcessingException;
24 import org.onap.dcae.apod.analytics.common.service.processor.AbstractMessageProcessor;
25 import org.onap.dcae.apod.analytics.model.domain.cef.EventListener;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import javax.annotation.Nonnull;
33 * Encapsulates common functionality for all TCA CEF Policy Processors
36 * @author Rajiv Singla . Creation Date: 11/9/2016.
38 public abstract class AbstractTCAECEFPolicyProcessor extends AbstractMessageProcessor<TCACEFProcessorContext> {
40 private static final Logger LOG = LoggerFactory.getLogger(AbstractTCAECEFPolicyProcessor.class);
43 * For all TCA Policy Processor the pre processor ensures that {@link EventListener} object is
46 * @param processorContext incoming Processor Context
47 * @return Pre processed Processor Context
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));
59 return super.preProcessor(processorContext);