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); }
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); }
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; }
private void processEvent(CaseWorkItemEvent 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(); } }
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(); }
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(); } }
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult result) { if (eventHandlerType.getChained().isEmpty()) { return true; } logStart(LOGGER, event, eventHandlerType); boolean shouldContinue = true; for (EventHandlerType branchHandlerType : eventHandlerType.getChained()) { shouldContinue = notificationManager.processEvent(event, branchHandlerType, task, result); if (!shouldContinue) { break; } } logEnd(LOGGER, event, eventHandlerType, shouldContinue); return shouldContinue; } }
@Test public void test210SendSmsUsingPost() { final String TEST_NAME = "test210SendSmsUsingPost"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + "." + TEST_NAME); OperationResult result = task.getResult(); // WHEN TestUtil.displayWhen(TEST_NAME); Event event = new CustomEvent(lightweightIdentifierGenerator, "post", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null); notificationManager.processEvent(event, task, result); // THEN TestUtil.displayThen(TEST_NAME); result.computeStatus(); TestUtil.assertSuccess("processEvent result", result); assertNotNull("No http request found", httpHandler.lastRequest); assertEquals("Wrong HTTP method", "POST", httpHandler.lastRequest.method); assertEquals("Wrong URI", "/send", httpHandler.lastRequest.uri.toString()); assertEquals("Wrong Content-Type header", singletonList("application/x-www-form-urlencoded"), httpHandler.lastRequest.headers.get("content-type")); assertEquals("Wrong X-Custom header", singletonList("test"), httpHandler.lastRequest.headers.get("x-custom")); String username = "a9038321"; String password = "5ecr3t"; String expectedAuthorization = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1)); assertEquals("Wrong Authorization header", singletonList(expectedAuthorization), httpHandler.lastRequest.headers.get("authorization")); assertEquals("Wrong 1st line of body", "Body=\"hello+world\"&To=%2B421905123456&From=%2B421999000999", httpHandler.lastRequest.body.get(0)); }
@Test public void test215SendSmsUsingGeneralPost() { final String TEST_NAME = "test215SendSmsUsingGeneralPost"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + "." + TEST_NAME); OperationResult result = task.getResult(); // WHEN TestUtil.displayWhen(TEST_NAME); Event event = new CustomEvent(lightweightIdentifierGenerator, "general-post", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null); notificationManager.processEvent(event, task, result); // THEN TestUtil.displayThen(TEST_NAME); result.computeStatus(); TestUtil.assertSuccess("processEvent result", result); assertNotNull("No http request found", httpHandler.lastRequest); assertEquals("Wrong HTTP method", "POST", httpHandler.lastRequest.method); assertEquals("Wrong URI", "/send", httpHandler.lastRequest.uri.toString()); assertEquals("Wrong Content-Type header", singletonList("application/x-www-form-urlencoded"), httpHandler.lastRequest.headers.get("content-type")); assertEquals("Wrong X-Custom header", singletonList("test"), httpHandler.lastRequest.headers.get("x-custom")); String username = "a9038321"; String password = "5ecr3t"; String expectedAuthorization = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1)); assertEquals("Wrong Authorization header", singletonList(expectedAuthorization), httpHandler.lastRequest.headers.get("authorization")); assertEquals("Wrong 1st line of body", "Body=\"body\"&To=[%2B123, %2B456, %2B789]&From=from", httpHandler.lastRequest.body.get(0)); }
@Test public void test200SendSmsUsingGet() { final String TEST_NAME = "test200SendSmsUsingGet"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + "." + TEST_NAME); OperationResult result = task.getResult(); // WHEN TestUtil.displayWhen(TEST_NAME); Event event = new CustomEvent(lightweightIdentifierGenerator, "get", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null); notificationManager.processEvent(event, task, result); // THEN TestUtil.displayThen(TEST_NAME); result.computeStatus(); TestUtil.assertSuccess("processEvent result", result); assertNotNull("No http request found", httpHandler.lastRequest); assertEquals("Wrong HTTP method", "GET", httpHandler.lastRequest.method); assertEquals("Wrong URI", "/send?number=%2B421905123456&text=hello+world", httpHandler.lastRequest.uri.toString()); }
private void executeNotifyAny(OperationStatus status, ResourceOperationDescription operationDescription, Task task, OperationResult result) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("AccountOperationListener.notify ({}) called with operationDescription = {}", status, operationDescription.debugDump()); } if (operationDescription.getObjectDelta() == null) { LOGGER.warn("Object delta is null, exiting the change listener."); return; } if (operationDescription.getCurrentShadow() == null) { LOGGER.warn("Current shadow is null, exiting the change listener."); return; } // for the time being, we deal only with accounts here if (operationDescription.getObjectDelta().getObjectTypeClass() == null || !ShadowType.class.isAssignableFrom(operationDescription.getObjectDelta().getObjectTypeClass())) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Object that was changed was not an account, exiting the operation listener (class = {})", operationDescription.getObjectDelta().getObjectTypeClass()); } return; } ResourceObjectEvent request = createRequest(status, operationDescription, task, result); notificationManager.processEvent(request, task, result); }
private void createAndProcessEvent(Task task, TaskRunResult runResult, EventOperationType operationType) { TaskEvent event = new TaskEvent(lightweightIdentifierGenerator, task, runResult, operationType, task.getChannel()); if (task.getOwner() != null) { event.setRequester(new SimpleObjectRefImpl(notificationsUtil, task.getOwner().asObjectable())); event.setRequestee(new SimpleObjectRefImpl(notificationsUtil, task.getOwner().asObjectable())); } else { LOGGER.debug("No owner for task " + task + ", therefore no requester and requestee will be set for event " + event.getId()); } Task opTask = taskManager.createTaskInstance(OPERATION_PROCESS_EVENT); notificationManager.processEvent(event, opTask, opTask.getResult()); }
if (forWholeInput) { Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, input.getData(), operation, status, context.getChannel()); notificationManager.processEvent(event, context.getTask(), globalResult); eventCount++; } else { context.checkTaskStop(); Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, value, operation, status, context.getChannel()); notificationManager.processEvent(event, context.getTask(), result); eventCount++; operationsHelper.trimAndCloneResult(result, globalResult, context);
@Test public void test300CheckVariables() { final String TEST_NAME = "test300CheckVariables"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + "." + TEST_NAME); OperationResult result = task.getResult(); prepareNotifications(); // WHEN TestUtil.displayWhen(TEST_NAME); Event event = new CustomEvent(lightweightIdentifierGenerator, "check-variables", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null); notificationManager.processEvent(event, task, result); // THEN TestUtil.displayThen(TEST_NAME); result.computeStatus(); TestUtil.assertSuccess("processEvent result", result); displayAllNotifications(); assertSingleDummyTransportMessage("check-variables", "variables ok"); }