private boolean notificationsEnabled() { if (notificationManager.isDisabled()) { LOGGER.trace("Notifications are temporarily disabled, exiting the hook."); return false; } else { return true; } }
@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; }
@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()); }
boolean notificationsDisabled = notificationManager.isDisabled(); notificationManager.setDisabled(false);