protected void notifyEvent(String eventId, DocumentModel source, Map<String, Serializable> options, String comment, CoreSession session) { DocumentEventContext docCtx = new DocumentEventContext(session, session.getPrincipal(), source); options.put("category", RelationEvents.CATEGORY); options.put("comment", comment); EventProducer evtProducer = Framework.getService(EventProducer.class); evtProducer.fireEvent(docCtx.newEvent(eventId)); }
protected void notifyEvent(String eventId, DocumentModel source, Map<String, Serializable> options, String comment) { EventProducer evtProducer = null; try { evtProducer = Framework.getService(EventProducer.class); } catch (Exception e) { log.error("Unable to get EventProducer to send event notification", e); } DocumentEventContext docCtx = new DocumentEventContext(documentManager, documentManager.getPrincipal(), source); options.put("category", RelationEvents.CATEGORY); options.put("comment", comment); try { evtProducer.fireEvent(docCtx.newEvent(eventId)); } catch (ClientException e) { log.error("Error while trying to send notification message", e); } }
/** * Sends an event that triggers a notification that sends emails to all selected entities. * * @param user * @param theMailSubject * @param theMailContent */ private void sendNotificationEvent(String recipient, String theMailSubject, String theMailContent) { Map<String, Serializable> options = new HashMap<String, Serializable>(); // options for confirmation email options.put(NotificationConstants.RECIPIENTS_KEY, new String[] { recipient }); options.put("mailSubject", theMailSubject); options.put("mailContent", theMailContent); options.put("category", DocumentEventCategories.EVENT_CLIENT_NOTIF_CATEGORY); NuxeoPrincipal currentUser = (NuxeoPrincipal) FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal(); DocumentEventContext ctx = new DocumentEventContext(documentManager, currentUser, navigationContext.getCurrentDocument()); ctx.setProperties(options); Event event = ctx.newEvent(DocumentEventTypes.EMAIL_DOCUMENT_SEND); EventProducer evtProducer = Framework.getService(EventProducer.class); evtProducer.fireEvent(event); }
static public void fireEvent(CoreSession coreSession, DocumentRouteElement element, Map<String, Serializable> eventProperties, String eventName) { if (eventProperties == null) { eventProperties = new HashMap<String, Serializable>(); } eventProperties.put(DocumentRoutingConstants.DOCUMENT_ELEMENT_EVENT_CONTEXT_KEY, element); eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentRoutingConstants.ROUTING_CATEGORY); DocumentEventContext envContext = new DocumentEventContext(coreSession, coreSession.getPrincipal(), element.getDocument()); envContext.setProperties(eventProperties); getEventProducer().fireEvent(envContext.newEvent(eventName)); }
public static void notifyEvent(CoreSession session, String eventName, DocumentModel document, Map<String, Serializable> properties) throws ClientException { NuxeoPrincipal principal = (NuxeoPrincipal) session.getPrincipal(); DocumentEventContext ctx = new DocumentEventContext(session, principal, document); // initialise les propriétés if (null != properties) { for (String property : properties.keySet()) { ctx.setProperty(property, properties.get(property)); } } // emet l'évènement getEventProducer().fireEvent(ctx.newEvent(eventName)); }
public static void notifyEvent(CoreSession session, String eventName, DocumentModel document, Map<String, Serializable> properties) throws NuxeoException { NuxeoPrincipal principal = (NuxeoPrincipal) session.getPrincipal(); DocumentEventContext ctx = new DocumentEventContext(session, principal, document); // initialise les propriétés if (null != properties) { for (String property : properties.keySet()) { ctx.setProperty(property, properties.get(property)); } } // emet l'évènement getEventProducer().fireEvent(ctx.newEvent(eventName)); }
private void raiseConfirmationEvent(NuxeoPrincipal principal, DocumentModel doc, String username, String notification) { Map<String, Serializable> options = new HashMap<>(); // Name of the current repository options.put(CoreEventConstants.REPOSITORY_NAME, doc.getRepositoryName()); // Add the session ID options.put(CoreEventConstants.SESSION_ID, doc.getSessionId()); // options for confirmation email options.put("recipients", username); options.put("notifName", notification); CoreSession session = doc.getCoreSession(); DocumentEventContext ctx = new DocumentEventContext(session, principal, doc); ctx.setCategory(DocumentEventCategories.EVENT_CLIENT_NOTIF_CATEGORY); ctx.setProperties(options); Event event = ctx.newEvent(DocumentEventTypes.SUBSCRIPTION_ASSIGNED); doFireEvent(event); }
protected static void fireEvent(String eventName, Map<String, Serializable> eventProperties, DocumentRoute route, CoreSession session) { eventProperties.put(DocumentRoutingConstants.DOCUMENT_ELEMENT_EVENT_CONTEXT_KEY, route); eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentRoutingConstants.ROUTING_CATEGORY); DocumentEventContext envContext = new DocumentEventContext(session, session.getPrincipal(), route.getDocument()); envContext.setProperties(eventProperties); EventProducer eventProducer = Framework.getService(EventProducer.class); eventProducer.fireEvent(envContext.newEvent(eventName)); }
/** * @since 10.3 */ protected void notifyPublishedEvent(DocumentModel doc) { Map<String, Serializable> properties = new HashMap<>(); properties.put(CoreEventConstants.REPOSITORY_NAME, doc.getRepositoryName()); properties.put(CoreEventConstants.SESSION_ID, session.getSessionId()); properties.put(CoreEventConstants.DOC_LIFE_CYCLE, doc.getCurrentLifeCycleState()); DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), doc); ctx.setProperties(properties); ctx.setCategory(DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); Event event = ctx.newEvent(DocumentEventTypes.DOCUMENT_PUBLISHED); Framework.getService(EventProducer.class).fireEvent(event); }
static public void fireEvent(CoreSession coreSession, DocumentRouteElement element, Map<String, Serializable> eventProperties, String eventName, DocumentModel doc) { if (eventProperties == null) { eventProperties = new HashMap<String, Serializable>(); } eventProperties.put(DocumentRoutingConstants.TASK_ROUTE_INSTANCE_DOCUMENT_ID_KEY, element.getDocumentRoute(coreSession).getDocument().getId()); eventProperties.put(DocumentRoutingConstants.DOCUMENT_ELEMENT_EVENT_CONTEXT_KEY, element); eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); DocumentEventContext envContext = new DocumentEventContext(coreSession, coreSession.getPrincipal(), doc); envContext.setProperties(eventProperties); getEventProducer().fireEvent(envContext.newEvent(eventName)); }
/** * Fires an event in the category 'routing' for every document in the list * * @since 5.7.2 */ static public void fireEvent(CoreSession coreSession, List<DocumentModel> docs, Map<String, Serializable> eventProperties, String eventName) { if (eventProperties == null) { eventProperties = new HashMap<String, Serializable>(); } eventProperties.put(DocumentEventContext.CATEGORY_PROPERTY_KEY, DocumentRoutingConstants.ROUTING_CATEGORY); for (DocumentModel doc : docs) { DocumentEventContext envContext = new DocumentEventContext(coreSession, coreSession.getPrincipal(), doc); envContext.setProperties(eventProperties); getEventProducer().fireEvent(envContext.newEvent(eventName)); } }
protected void createTask(DocumentModel document, CoreSession session, NuxeoPrincipal principal) { String[] actorIds = getValidatorsFor(document); Map<String, String> variables = new HashMap<String, String>(); variables.put(Task.TaskVariableName.needi18n.name(), "true"); variables.put(Task.TaskVariableName.taskType.name(), PUBLISH_TASK_TYPE); variables.put(TaskService.VariableName.documentId.name(), document.getId()); variables.put(TaskService.VariableName.documentRepositoryName.name(), document.getRepositoryName()); variables.put(TaskService.VariableName.initiator.name(), principal.getName()); getTaskService().createTask(session, principal, document, TASK_NAME, Arrays.asList(actorIds), false, TASK_NAME, null, null, variables, null); DocumentEventContext ctx = new DocumentEventContext(session, principal, document); ctx.setProperty(NotificationConstants.RECIPIENTS_KEY, actorIds); getEventProducer().fireEvent(ctx.newEvent(TaskEventNames.WORKFLOW_TASK_START)); }
protected void notifyEvent(String eventId, Map<String, Serializable> properties, String comment, String category, DocumentModel dm, CoreSession coreSession) { // Default category if (category == null) { category = DocumentEventCategories.EVENT_DOCUMENT_CATEGORY; } if (properties == null) { properties = new HashMap<String, Serializable>(); } properties.put(CoreEventConstants.REPOSITORY_NAME, dm.getRepositoryName()); properties.put(CoreEventConstants.SESSION_ID, coreSession.getSessionId()); properties.put(CoreEventConstants.DOC_LIFE_CYCLE, dm.getCurrentLifeCycleState()); DocumentEventContext ctx = new DocumentEventContext(coreSession, coreSession.getPrincipal(), dm); ctx.setProperties(properties); ctx.setComment(comment); ctx.setCategory(category); Event event = ctx.newEvent(eventId); getEventProducer().fireEvent(event); }
public static void notifyEvent(CoreSession session, String eventId, Map<String, Serializable> properties, String comment, String category, DocumentModel dm) { // Default category if (category == null) { category = DocumentEventCategories.EVENT_DOCUMENT_CATEGORY; } if (properties == null) { properties = new HashMap<>(); } properties.put(CoreEventConstants.REPOSITORY_NAME, session.getRepositoryName()); properties.put(CoreEventConstants.SESSION_ID, session.getSessionId()); properties.put(CoreEventConstants.DOC_LIFE_CYCLE, dm.getCurrentLifeCycleState()); DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), dm); ctx.setProperties(properties); ctx.setComment(comment); ctx.setCategory(category); EventProducer evtProducer = Framework.getService(EventProducer.class); Event event = ctx.newEvent(eventId); evtProducer.fireEvent(event); }
/** * Fire a {@code PICTURE_VIEWS_GENERATION_DONE_EVENT} event when no other PictureViewsGenerationWork is scheduled * for this document. * * @since 5.8 */ protected void firePictureViewsGenerationDoneEvent(DocumentModel doc) { WorkManager workManager = Framework.getService(WorkManager.class); List<String> workIds = workManager.listWorkIds(CATEGORY_PICTURE_GENERATION, null); int worksCount = 0; for (String workId : workIds) { if (workId.equals(getId())) { if (++worksCount > 1) { // another work scheduled return; } } } DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), doc); Event event = ctx.newEvent(PICTURE_VIEWS_GENERATION_DONE_EVENT); Framework.getService(EventService.class).fireEvent(event); }
/** * Fire a {@code VIDEO_CONVERSIONS_DONE_EVENT} event when no other VideoConversionWork is scheduled for this * document. * * @since 5.8 */ protected void fireVideoConversionsDoneEvent(DocumentModel doc) { WorkManager workManager = Framework.getService(WorkManager.class); List<String> workIds = workManager.listWorkIds(CATEGORY_VIDEO_CONVERSION, null); String idPrefix = computeIdPrefix(repositoryName, docId); int worksCount = 0; for (String workId : workIds) { if (workId.startsWith(idPrefix) && ++worksCount > 1) { // another work scheduled return; } } DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), doc); Event event = ctx.newEvent(VIDEO_CONVERSIONS_DONE_EVENT); Framework.getService(EventService.class).fireEvent(event); }
protected void fireUpdateEvent(CoreSession session, String docId) { DocumentRef documentRef = new IdRef(docId); if (session.exists(documentRef)) { DocumentModel documentModel = session.getDocument(documentRef); DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), documentModel); Event event = ctx.newEvent(DocumentEventTypes.DOCUMENT_TAG_UPDATED); Framework.getService(EventService.class).fireEvent(event); } }
protected void notifyEvent(CoreSession session, String eventId, DocumentModel doc, boolean immediate) { DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), doc); ctx.setProperties(new HashMap<>(doc.getContextData())); ctx.setCategory(DocumentEventCategories.EVENT_DOCUMENT_CATEGORY); ctx.setProperty(CoreEventConstants.REPOSITORY_NAME, session.getRepositoryName()); ctx.setProperty(CoreEventConstants.SESSION_ID, session.getSessionId()); Event event = ctx.newEvent(eventId); event.setInline(false); event.setImmediate(immediate); EventService eventService = Framework.getService(EventService.class); eventService.fireEvent(event); }
protected void fireEvent(CoreSession session, String eventId, Collection<DocumentRef> refs) { EventService eventService = Framework.getService(EventService.class); DocumentModelList docs = session.getDocuments(refs.toArray(new DocumentRef[0])); docs.forEach(d -> { DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), d); ctx.setProperty(REPOSITORY_NAME, session.getRepositoryName()); ctx.setProperty(SESSION_ID, session.getSessionId()); ctx.setCategory(EVENT_DOCUMENT_CATEGORY); Event event = ctx.newEvent(eventId); event.setImmediate(false); event.setInline(false); eventService.fireEvent(event); }); } }
protected void sendEvent(CoreSession session, Document doc, String previousLifecycleState, Map<String, Serializable> options) { String sid = session.getSessionId(); DocumentModel docModel = DocumentModelFactory.createDocumentModel(doc, sid, null); DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), docModel); ctx.setProperty(TRANSTION_EVENT_OPTION_FROM, previousLifecycleState); ctx.setProperty(TRANSTION_EVENT_OPTION_TO, doc.getLifeCycleState()); ctx.setProperty(TRANSTION_EVENT_OPTION_TRANSITION, BACK_TO_PROJECT_TRANSITION); ctx.setProperty(REPOSITORY_NAME, session.getRepositoryName()); ctx.setProperty(SESSION_ID, sid); ctx.setProperty(DOC_LIFE_CYCLE, BACK_TO_PROJECT_TRANSITION); ctx.setProperty(CATEGORY, DocumentEventCategories.EVENT_LIFE_CYCLE_CATEGORY); ctx.setProperty(COMMENT, options.get(COMMENT)); Framework.getService(EventService.class).fireEvent(ctx.newEvent(TRANSITION_EVENT)); }