Search in sources :

Example 1 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class TestStrings method test202FourDaysLater.

@Test
public void test202FourDaysLater() throws Exception {
    final String TEST_NAME = "test202FourDaysLater";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = createTask(TestStrings.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    // WHEN
    clock.overrideDuration("P4D");
    waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
    // THEN
    List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
    List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
    List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
    display("work items lifecycle notifications", lifecycleMessages);
    display("work items allocation notifications", allocationMessages);
    display("processes notifications", processMessages);
    dummyTransport.clearMessages();
    assertNull("lifecycle messages", lifecycleMessages);
    assertEquals("Wrong # of work items allocation messages", 1, allocationMessages.size());
    assertMessage(allocationMessages.get(0), "guybrush@evolveum.com", "Work item will be automatically escalated in 1 day", "Stage: Line managers (1/3)", "Allocated to (before escalation): Guybrush Threepwood (guybrush)");
    assertNull("process messages", processMessages);
    display("audit", dummyAuditService);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 2 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class TestEscalation method test220Reject.

@Test
public void test220Reject() throws Exception {
    final String TEST_NAME = "test220Reject";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userAdministrator);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    // WHEN
    clock.resetOverride();
    // at 5D there's a deadline with auto-rejection
    clock.overrideDuration("P5DT20M");
    waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
    // THEN
    SearchResultList<WorkItemType> workItems = getWorkItems(task, result);
    displayWorkItems("Work items after deadline", workItems);
    assertEquals("Wrong # of work items", 0, workItems.size());
    PrismObject<TaskType> wfTask = getTask(approvalTaskOid);
    display("workflow task", wfTask);
    assertEquals("Wrong # of triggers", 0, wfTask.asObjectable().getTrigger().size());
    Map<String, WorkItemCompletionEventType> eventMap = new HashMap<>();
    for (CaseEventType event : wfTask.asObjectable().getWorkflowContext().getEvent()) {
        if (event instanceof WorkItemCompletionEventType) {
            WorkItemCompletionEventType c = (WorkItemCompletionEventType) event;
            eventMap.put(c.getExternalWorkItemId(), c);
            assertNotNull("No result in " + c, c.getOutput());
            assertEquals("Wrong outcome in " + c, WorkItemOutcomeType.REJECT, ApprovalUtils.fromUri(c.getOutput().getOutcome()));
            assertNotNull("No cause in " + c, c.getCause());
            assertEquals("Wrong cause type in " + c, WorkItemEventCauseTypeType.TIMED_ACTION, c.getCause().getType());
            assertEquals("Wrong cause name in " + c, "auto-reject", c.getCause().getName());
            assertEquals("Wrong cause display name in " + c, "Automatic rejection at deadline", c.getCause().getDisplayName());
        }
    }
    assertEquals("Wrong # of completion events", 2, eventMap.size());
    displayCollection("audit records", dummyAuditService.getRecords());
    List<AuditEventRecord> workItemAuditRecords = dummyAuditService.getRecordsOfType(AuditEventType.WORK_ITEM);
    assertEquals("Wrong # of work item audit records", 2, workItemAuditRecords.size());
    for (AuditEventRecord r : workItemAuditRecords) {
        assertEquals("Wrong causeType in " + r, Collections.singleton("timedAction"), r.getPropertyValues(WorkflowConstants.AUDIT_CAUSE_TYPE));
        assertEquals("Wrong causeName in " + r, Collections.singleton("auto-reject"), r.getPropertyValues(WorkflowConstants.AUDIT_CAUSE_NAME));
        assertEquals("Wrong causeDisplayName in " + r, Collections.singleton("Automatic rejection at deadline"), r.getPropertyValues(WorkflowConstants.AUDIT_CAUSE_DISPLAY_NAME));
        assertEquals("Wrong result in " + r, "Rejected", r.getResult());
    }
    displayCollection("notifications - process", dummyTransport.getMessages("dummy:simpleWorkflowNotifier-Processes"));
    List<Message> notifications = dummyTransport.getMessages("dummy:simpleWorkflowNotifier-WorkItems");
    displayCollection("notifications - work items", notifications);
    for (Message notification : notifications) {
        assertContains(notification, "Reason: Automatic rejection at deadline (timed action)");
        assertContains(notification, "Result: REJECTED");
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) HashMap(java.util.HashMap) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) Test(org.testng.annotations.Test)

Example 3 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class CustomNotifier method processEvent.

@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult parentResult) throws SchemaException {
    OperationResult result = parentResult.createSubresult(CustomNotifier.class.getName() + ".processEvent");
    logStart(getLogger(), event, eventHandlerType);
    boolean applies = aggregatedEventHandler.processEvent(event, eventHandlerType, notificationManager, task, result);
    if (applies) {
        CustomNotifierType config = (CustomNotifierType) eventHandlerType;
        ExpressionVariables variables = getDefaultVariables(event, result);
        if (event instanceof ModelEvent) {
            ((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, ENTERING));
        }
        List<String> transports = new ArrayList<>(config.getTransport());
        if (transports.isEmpty()) {
            transports.add(customTransport.getName());
        }
        try {
            for (String transportName : config.getTransport()) {
                variables.addVariableDefinition(SchemaConstants.C_TRANSPORT_NAME, transportName);
                Transport transport = notificationManager.getTransport(transportName);
                Message message = getMessageFromExpression(config, variables, task, result);
                if (message != null) {
                    getLogger().trace("Sending notification via transport {}:\n{}", transportName, message);
                    transport.send(message, transportName, event, task, result);
                } else {
                    getLogger().debug("No message for transport {}, won't send anything", transportName);
                }
            }
        } finally {
            if (event instanceof ModelEvent) {
                ((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, result));
            }
        }
    }
    logEnd(getLogger(), event, eventHandlerType, applies);
    result.computeStatusIfUnknown();
    // not-applicable notifiers do not stop processing of other notifiers
    return true;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ProgressInformation(com.evolveum.midpoint.model.api.ProgressInformation) Message(com.evolveum.midpoint.notifications.api.transports.Message) ArrayList(java.util.ArrayList) CustomNotifierType(com.evolveum.midpoint.xml.ns._public.common.common_3.CustomNotifierType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Transport(com.evolveum.midpoint.notifications.api.transports.Transport) CustomTransport(com.evolveum.midpoint.notifications.impl.api.transports.CustomTransport) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Example 4 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class GeneralNotifier method processEvent.

@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult parentResult) throws SchemaException {
    OperationResult result = parentResult.createSubresult(GeneralNotifier.class.getName() + ".processEvent");
    logStart(getLogger(), event, eventHandlerType);
    boolean applies = aggregatedEventHandler.processEvent(event, eventHandlerType, notificationManager, task, result);
    if (applies) {
        GeneralNotifierType generalNotifierType = (GeneralNotifierType) eventHandlerType;
        if (!quickCheckApplicability(event, generalNotifierType, result)) {
        // nothing to do -- an appropriate message has to be logged in quickCheckApplicability method
        } else {
            if (!checkApplicability(event, generalNotifierType, result)) {
            // nothing to do -- an appropriate message has to be logged in checkApplicability method
            } else if (generalNotifierType.getTransport().isEmpty()) {
                getLogger().warn("No transports for this notifier, exiting without sending any notifications.");
            } else {
                ExpressionVariables variables = getDefaultVariables(event, result);
                if (event instanceof ModelEvent) {
                    ((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, ENTERING));
                }
                try {
                    for (String transportName : generalNotifierType.getTransport()) {
                        variables.addVariableDefinition(SchemaConstants.C_TRANSPORT_NAME, transportName);
                        Transport transport = notificationManager.getTransport(transportName);
                        List<String> recipientsAddresses = getRecipientsAddresses(event, generalNotifierType, variables, getDefaultRecipient(event, generalNotifierType, result), transportName, transport, task, result);
                        if (!recipientsAddresses.isEmpty()) {
                            String body = getBodyFromExpression(event, generalNotifierType, variables, task, result);
                            String subject = getSubjectFromExpression(event, generalNotifierType, variables, task, result);
                            String from = getFromFromExpression(event, generalNotifierType, variables, task, result);
                            String contentType = getContentTypeFromExpression(event, generalNotifierType, variables, task, result);
                            if (body == null) {
                                body = getBody(event, generalNotifierType, transportName, task, result);
                            }
                            if (subject == null) {
                                subject = generalNotifierType.getSubjectPrefix() != null ? generalNotifierType.getSubjectPrefix() : "";
                                subject += getSubject(event, generalNotifierType, transportName, task, result);
                            }
                            Message message = new Message();
                            message.setBody(body != null ? body : "");
                            if (contentType != null) {
                                message.setContentType(contentType);
                            } else if (generalNotifierType.getContentType() != null) {
                                message.setContentType(generalNotifierType.getContentType());
                            }
                            message.setSubject(subject);
                            if (from != null) {
                                message.setFrom(from);
                            }
                            message.setTo(recipientsAddresses);
                            message.setCc(getCcBccAddresses(generalNotifierType.getCcExpression(), variables, "notification cc-expression", task, result));
                            message.setBcc(getCcBccAddresses(generalNotifierType.getBccExpression(), variables, "notification bcc-expression", task, result));
                            getLogger().trace("Sending notification via transport {}:\n{}", transportName, message);
                            transport.send(message, transportName, event, task, result);
                        } else {
                            getLogger().info("No recipients addresses for transport " + transportName + ", message corresponding to event " + event.getId() + " will not be send.");
                        }
                    }
                } finally {
                    if (event instanceof ModelEvent) {
                        ((ModelEvent) event).getModelContext().reportProgress(new ProgressInformation(NOTIFICATIONS, result));
                    }
                }
            }
        }
    }
    logEnd(getLogger(), event, eventHandlerType, applies);
    result.computeStatusIfUnknown();
    // not-applicable notifiers do not stop processing of other notifiers
    return true;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ProgressInformation(com.evolveum.midpoint.model.api.ProgressInformation) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ArrayList(java.util.ArrayList) List(java.util.List) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Transport(com.evolveum.midpoint.notifications.api.transports.Transport) ModelEvent(com.evolveum.midpoint.notifications.api.events.ModelEvent)

Example 5 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class TestEscalation method test120EscalateAgain.

@Test
public void test120EscalateAgain() throws Exception {
    login(getUserFromRepo(USER_ADMINISTRATOR_OID));
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyTransport.clearMessages();
    // WHEN
    when();
    clock.resetOverride();
    // second escalation is at P3D
    clock.overrideDuration("P4D");
    waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    List<AccessCertificationCaseType> caseList = queryHelper.searchCases(campaignOid, null, null, result);
    display("caseList", caseList);
    checkAllCasesSanity(caseList);
    AccessCertificationCaseType ceoCase = findCase(caseList, USER_JACK_OID, ROLE_CEO_OID);
    display("CEO case after escalation", ceoCase);
    AccessCertificationWorkItemType workItem = CertCampaignTypeUtil.findWorkItem(ceoCase, 1, 1, USER_ELAINE_OID);
    assertNotNull("No work item found", workItem);
    assertObjectRefs("assignees", false, workItem.getAssigneeRef(), USER_ELAINE_OID);
    assertEquals("Wrong originalAssignee OID", USER_ADMINISTRATOR_OID, workItem.getOriginalAssigneeRef().getOid());
    final WorkItemEscalationLevelType OLD_ESCALATION_LEVEL = new WorkItemEscalationLevelType().number(1).name("jack-level");
    final WorkItemEscalationLevelType NEW_ESCALATION_LEVEL = new WorkItemEscalationLevelType().number(2).name("elaine-level");
    assertEquals("Wrong escalation info", NEW_ESCALATION_LEVEL, workItem.getEscalationLevel());
    assertEquals("Wrong # of events", 2, ceoCase.getEvent().size());
    WorkItemEscalationEventType event = (WorkItemEscalationEventType) ceoCase.getEvent().get(1);
    assertNotNull("No timestamp in event", event.getTimestamp());
    assertEquals("Wrong initiatorRef OID", USER_ADMINISTRATOR_OID, event.getInitiatorRef().getOid());
    assertEquals("Wrong workItemId", workItem.getId(), event.getWorkItemId());
    assertObjectRefs("assigneeBefore", false, event.getAssigneeBefore(), USER_ADMINISTRATOR_OID, USER_JACK_OID);
    assertObjectRefs("delegatedTo", false, event.getDelegatedTo(), USER_ELAINE_OID);
    assertEquals("Wrong delegationMethod", WorkItemDelegationMethodType.REPLACE_ASSIGNEES, event.getDelegationMethod());
    assertEquals("Wrong old escalation level", OLD_ESCALATION_LEVEL, event.getEscalationLevel());
    assertEquals("Wrong new escalation level", NEW_ESCALATION_LEVEL, event.getNewEscalationLevel());
    AccessCertificationCaseType superuserCase = findCase(caseList, USER_ADMINISTRATOR_OID, ROLE_SUPERUSER_OID);
    AccessCertificationWorkItemType superuserWorkItem = CertCampaignTypeUtil.findWorkItem(superuserCase, 1, 1, USER_ADMINISTRATOR_OID);
    // noinspection SimplifiedTestNGAssertion
    assertEquals("Escalation info present even if it shouldn't be", null, superuserWorkItem.getEscalationLevel());
    AccessCertificationCampaignType campaign = getCampaignWithCases(campaignOid);
    // 1 reviewer per case (always administrator)
    assertPercentCompleteAll(campaign, Math.round(100.0f / 7.0f), Math.round(100.0f / 7.0f), Math.round(100.0f / 7.0f));
    AccessCertificationStageType currentStage = CertCampaignTypeUtil.getCurrentStage(campaign);
    assertNotNull(currentStage);
    assertEquals("Wrong new stage escalation level", NEW_ESCALATION_LEVEL, currentStage.getEscalationLevel());
    display("campaign after escalation", campaign);
    // completion
    assertEquals("Wrong # of triggers", 1, campaign.getTrigger().size());
    displayDumpable("dummy transport", dummyTransport);
    List<Message> messages = dummyTransport.getMessages("dummy:simpleReviewerNotifier");
    // new approver
    assertEquals("Wrong # of dummy notifications", 1, messages.size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

Message (com.evolveum.midpoint.notifications.api.transports.Message)49 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)41 Test (org.testng.annotations.Test)39 Task (com.evolveum.midpoint.task.api.Task)32 CustomEventImpl (com.evolveum.midpoint.notifications.impl.events.CustomEventImpl)8 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)8 ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)4 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ArrayList (java.util.ArrayList)3 ProgressInformation (com.evolveum.midpoint.model.api.ProgressInformation)2 NotificationManager (com.evolveum.midpoint.notifications.api.NotificationManager)2 ModelEvent (com.evolveum.midpoint.notifications.api.events.ModelEvent)2 Transport (com.evolveum.midpoint.notifications.api.transports.Transport)2 TransportService (com.evolveum.midpoint.notifications.api.transports.TransportService)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)2 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)2