001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 */ 018package org.nuxeo.ecm.platform.routing.core.impl; 019 020import java.io.Serializable; 021import java.util.HashMap; 022import java.util.Map; 023 024import org.nuxeo.ecm.core.api.CoreSession; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.api.event.DocumentEventCategories; 027import org.nuxeo.ecm.core.event.EventProducer; 028import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 029import org.nuxeo.ecm.platform.routing.api.DocumentRouteElement; 030import org.nuxeo.ecm.platform.routing.api.DocumentRoutingConstants; 031import org.nuxeo.runtime.api.Framework; 032 033/** 034 * Fire events for Route audit logs (used by previous route content view) 035 * 036 * @since 5.6 037 */ 038public class AuditEventFirer { 039 040 static public void fireEvent(CoreSession coreSession, DocumentRouteElement element, 041 Map<String, Serializable> eventProperties, String eventName, DocumentModel doc) { 042 if (eventProperties == null) { 043 eventProperties = new HashMap<String, Serializable>(); 044 } 045 eventProperties.put(DocumentRoutingConstants.TASK_ROUTE_INSTANCE_DOCUMENT_ID_KEY, 046 element.getDocumentRoute(coreSession).getDocument().getId()); 047 eventProperties.put(DocumentRoutingConstants.DOCUMENT_ELEMENT_EVENT_CONTEXT_KEY, element); 048 eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); 049 DocumentEventContext envContext = new DocumentEventContext(coreSession, coreSession.getPrincipal(), doc); 050 envContext.setProperties(eventProperties); 051 getEventProducer().fireEvent(envContext.newEvent(eventName)); 052 } 053 054 static protected EventProducer getEventProducer() { 055 return Framework.getService(EventProducer.class); 056 } 057 058}