private void emitPolicyEvent(@SuppressWarnings("unused") NotificationPolicyActionType action, EvaluatedPolicyRule rule, ModelContext<?> context, Task task, OperationResult result) { PolicyRuleEvent ruleEvent = createRuleEvent(rule, context, task); notificationManager.processEvent(ruleEvent, task, result); }
protected void prepareNotifications() { notificationManager.setDisabled(false); dummyTransport.clearMessages(); }
private boolean notificationsEnabled() { if (notificationManager.isDisabled()) { LOGGER.trace("Notifications are temporarily disabled, exiting the hook."); return false; } else { return true; } }
@Test public void test507ScriptingUsersInBackgroundAssign() throws Exception { final String TEST_NAME = "test507ScriptingUsersInBackgroundAssign"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = createTask(DOT_CLASS + TEST_NAME); task.setOwner(getUser(USER_ADMINISTRATOR_OID)); OperationResult result = task.getResult(); ExecuteScriptType exec = prismContext.parserFor(SCRIPTING_USERS_IN_BACKGROUND_ASSIGN_FILE).parseRealValue(); // WHEN task.setExtensionPropertyValue(SchemaConstants.SE_EXECUTE_SCRIPT, exec); task.setHandlerUri(ModelPublicConstants.SCRIPT_EXECUTION_TASK_HANDLER_URI); dummyTransport.clearMessages(); boolean notificationsDisabled = notificationManager.isDisabled(); notificationManager.setDisabled(false); taskManager.switchToBackground(task, result); waitForTaskFinish(task.getOid(), false); task.refresh(result); // THEN display(task.getResult()); TestUtil.assertSuccess(task.getResult()); PrismObject<UserType> admin = getUser(USER_ADMINISTRATOR_OID); display("admin after operation", admin); assertAssignedRole(admin, ROLE_EMPTY_OID); display("dummy transport", dummyTransport); notificationManager.setDisabled(notificationsDisabled); assertEquals("Wrong # of messages in dummy transport", 1, emptyIfNull(dummyTransport.getMessages("dummy:simpleUserNotifier")).size()); }
@PostConstruct public void init() { notificationManager.registerTransport(NAME, this); }
for (String transportName : config.getTransport()) { variables.addVariableDefinition(SchemaConstants.C_TRANSPORT_NAME, transportName); Transport transport = notificationManager.getTransport(transportName);
boolean notificationsDisabled = notificationManager.isDisabled(); notificationManager.setDisabled(false); notificationManager.setDisabled(notificationsDisabled);
@PostConstruct public void init() { notificationManager.registerTransport(NAME, this); }
Transport transport = notificationManager.getTransport(transportName);
@Override public void initSystem(Task initTask, OperationResult initResult) throws Exception { LOGGER.trace("initSystem"); dummyResourceCollection = new DummyResourceCollection(modelService); startResources(); dummyAuditService = DummyAuditService.getInstance(); InternalsConfig.reset(); InternalsConfig.setAvoidLoggingChange(true); // Make sure the checks are turned on InternalsConfig.turnOnAllChecks(); // By default, notifications are turned off because of performance implications. Individual tests turn them on for themselves. if (notificationManager != null) { notificationManager.setDisabled(true); } }
private void emitModelEvent(@NotNull ModelContext<?> context, @NotNull Task task, @NotNull OperationResult result) { PrismObject<?> object = getObject(context); if (object == null) { LOGGER.trace("Focus context object is null, not sending the notification."); return; } ModelEvent event = createModelEvent(object, context, task); notificationManager.processEvent(event, task, result); }
@PostConstruct public void init() { notificationManager.registerTransport(NAME, this); }
@Override public HookOperationMode invoke(@NotNull ModelContext context, @NotNull Task task, @NotNull OperationResult result) { // todo in the future we should perhaps act in POSTEXECUTION state, but currently the clockwork skips this state if (context.getState() != ModelState.FINAL) { return HookOperationMode.FOREGROUND; } if (notificationManager.isDisabled()) { LOGGER.trace("Notifications are temporarily disabled, exiting the hook."); return HookOperationMode.FOREGROUND; } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Notification change hook called with model context: " + context.debugDump()); } if (context.getFocusContext() == null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Focus context is null, exiting the hook."); } return HookOperationMode.FOREGROUND; } emitModelEvent(context, task, result); emitPolicyRulesEvents(context, task, result); return HookOperationMode.FOREGROUND; }
notificationManager.setDisabled(true); checkDummyTransportMessages("byte-attachment", 1);
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult result) { if (eventHandlerType.getForked().isEmpty()) { return true; } logStart(LOGGER, event, eventHandlerType); for (EventHandlerType branchHandlerType : eventHandlerType.getForked()) { notificationManager.processEvent(event, branchHandlerType, task, result); } logEnd(LOGGER, event, eventHandlerType, true); return true; }
@PostConstruct public void init() { notificationManager.registerTransport(NAME, this); }
notificationManager.setDisabled(true); checkDummyTransportMessages("string-attachment", 1);
private void processEvent(WorkflowEvent event, OperationResult result) { try { notificationManager.processEvent(event); } 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(); }
@PostConstruct public void init() { if (notificationManager != null) { notificationManager.registerTransport(NAME, this); } else { LOGGER.info("NotificationManager is not available, skipping the registration."); } }
@Test public void test420AttachmentFromFile() throws Exception { final String TEST_NAME = "test420AttachmentFromFile"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + "." + TEST_NAME); OperationResult result = task.getResult(); preTestCleanup(AssignmentPolicyEnforcementType.FULL); // WHEN TestUtil.displayWhen(TEST_NAME); PrismObject<UserType> user = new UserType(prismContext) .name("testAttachmentFromFileUser") .asPrismObject(); addObject(user); // THEN TestUtil.displayThen(TEST_NAME); result.computeStatus(); TestUtil.assertSuccess("addObject result", result); // Check notifications display("Notifications", dummyTransport); notificationManager.setDisabled(true); checkDummyTransportMessages("attachment-from-file", 1); Message message = dummyTransport.getMessages("dummy:attachment-from-file").get(0); assertEquals("Wrong # of attachments", 1, message.getAttachments().size()); assertEquals("Wrong contentType of attachment", "image/png", message.getAttachments().get(0).getContentType()); assertEquals("Wrong fileName of attachments", "alf.png", message.getAttachments().get(0).getFileName()); assertEquals("Wrong fileName of attachments", "/home/user/example.png", message.getAttachments().get(0).getContentFromFile()); assertEquals("Wrong fileName of attachments", null, message.getAttachments().get(0).getContent()); }