/* * Copyright (c) 2010-2015 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.evolveum.midpoint.notifications.impl; import com.evolveum.midpoint.certification.api.AccessCertificationEventListener; import com.evolveum.midpoint.certification.api.CertificationManager; import com.evolveum.midpoint.notifications.api.NotificationManager; import com.evolveum.midpoint.notifications.api.events.AccessCertificationEvent; import com.evolveum.midpoint.notifications.api.events.CertCampaignEvent; import com.evolveum.midpoint.notifications.api.events.CertCampaignStageEvent; import com.evolveum.midpoint.notifications.api.events.CertReviewEvent; import com.evolveum.midpoint.notifications.impl.events.cert.CertEventFactory; import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.task.api.Task; import com.evolveum.midpoint.util.logging.LoggingUtils; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType; import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.List; /** * Listener that accepts events generated by certification module. * * @author mederly */ @Component public class CertificationListener implements AccessCertificationEventListener { private static final Trace LOGGER = TraceManager.getTrace(CertificationListener.class); //private static final String DOT_CLASS = WorkflowListener.class.getName() + "."; @Autowired private NotificationManager notificationManager; // CertificationManager is not required, because e.g. within model-test and model-intest we have no certifications. // However, during normal operation, it is expected to be available. @Autowired(required = false) private CertificationManager certificationManager; @Autowired private CertEventFactory certEventFactory; @PostConstruct public void init() { if (certificationManager != null) { certificationManager.registerCertificationEventListener(this); } else { LOGGER.warn("CertificationManager not present, notifications for certifications will not be enabled."); } } @Override public void onCampaignStart(AccessCertificationCampaignType campaign, Task task, OperationResult result) { CertCampaignEvent event = certEventFactory.createOnCampaignStartEvent(campaign, task, result); processEvent(event, task, result); } @Override public void onCampaignEnd(AccessCertificationCampaignType campaign, Task task, OperationResult result) { CertCampaignEvent event = certEventFactory.createOnCampaignEndEvent(campaign, task, result); processEvent(event, task, result); } @Override public void onCampaignStageStart(AccessCertificationCampaignType campaign, Task task, OperationResult result) { CertCampaignStageEvent event = certEventFactory.createOnCampaignStageStartEvent(campaign, task, result); processEvent(event, task, result); } @Override public void onCampaignStageDeadlineApproaching(AccessCertificationCampaignType campaign, Task task, OperationResult result) { CertCampaignStageEvent event = certEventFactory.createOnCampaignStageDeadlineApproachingEvent(campaign, task, result); processEvent(event, task, result); } @Override public void onCampaignStageEnd(AccessCertificationCampaignType campaign, Task task, OperationResult result) { CertCampaignStageEvent event = certEventFactory.createOnCampaignStageEndEvent(campaign, task, result); processEvent(event, task, result); } @Override public void onReviewRequested(ObjectReferenceType reviewerRef, List<AccessCertificationCaseType> cases, AccessCertificationCampaignType campaign, Task task, OperationResult result) { CertReviewEvent event = certEventFactory.createReviewRequestedEvent(reviewerRef, cases, campaign, task, result); processEvent(event, task, result); } @Override public void onReviewDeadlineApproaching(ObjectReferenceType reviewerRef, List<AccessCertificationCaseType> cases, AccessCertificationCampaignType campaign, Task task, OperationResult result) { CertReviewEvent event = certEventFactory.createReviewDeadlineApproachingEvent(reviewerRef, cases, campaign, task, result); processEvent(event, task, result); } private void processEvent(AccessCertificationEvent event, Task task, OperationResult result) { try { notificationManager.processEvent(event, task, result); } catch (RuntimeException e) { result.recordFatalError("An unexpected exception occurred when preparing and sending notifications: " + e.getMessage(), e); LoggingUtils.logUnexpectedException(LOGGER, "An unexpected exception occurred when preparing and sending notifications: " + e.getMessage(), e); } // todo work correctly with operationResult (in whole notification module) if (result.isUnknown()) { result.computeStatus(); } result.recordSuccessIfUnknown(); } }