Search in sources :

Example 36 with ModelExecuteOptions

use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.

the class TestMiscellaneous method test105RequesterCommentImmediate.

@Test
public void test105RequesterCommentImmediate() throws Exception {
    login(userAdministrator);
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    given();
    dummyAuditService.clear();
    OperationBusinessContextType businessContext = new OperationBusinessContextType();
    final String REQUESTER_COMMENT = "req.comment";
    businessContext.setComment(REQUESTER_COMMENT);
    ObjectDelta<UserType> userDelta = createAssignmentUserDelta(userJackOid, ROLE_CAPTAIN.oid, RoleType.COMPLEX_TYPE, null, null, null, true);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    ModelExecuteOptions options = executeOptions().requestBusinessContext(businessContext);
    options.executeImmediatelyAfterApproval(true);
    modelService.executeChanges(deltas, options, task, result);
    assertNotAssignedRole(userJackOid, ROLE_CAPTAIN.oid, result);
    CaseWorkItemType workItem = getWorkItem(task, result);
    display("Work item", workItem);
    when();
    caseManager.completeWorkItem(WorkItemId.of(workItem), ApprovalUtils.createApproveOutput(prismContext).comment("OK"), null, task, result);
    then();
    CaseType aCase = getCase(CaseWorkItemUtil.getCaseRequired(workItem).getOid());
    display("workflow context", aCase.getApprovalContext());
    List<? extends CaseEventType> events = aCase.getEvent();
    assertEquals("Wrong # of events", 2, events.size());
    CaseCreationEventType event1 = (CaseCreationEventType) events.get(0);
    display("Event 1", event1);
    assertEquals("Wrong requester comment", REQUESTER_COMMENT, ApprovalContextUtil.getBusinessContext(aCase).getComment());
    WorkItemEventType event2 = (WorkItemEventType) events.get(1);
    display("Event 2", event2);
    assertNotNull("Original assignee is null", event2.getOriginalAssigneeRef());
    assertEquals("Wrong original assignee OID", USER_SCOTT.oid, event2.getOriginalAssigneeRef().getOid());
    displayDumpable("audit", dummyAuditService);
    List<AuditEventRecord> records = dummyAuditService.getRecordsOfType(AuditEventType.WORKFLOW_PROCESS_INSTANCE);
    assertEquals("Wrong # of process instance audit records", 2, records.size());
    for (int i = 0; i < records.size(); i++) {
        AuditEventRecord record = records.get(i);
        assertEquals("Wrong requester comment in audit record #" + i, Collections.singleton(REQUESTER_COMMENT), record.getPropertyValues(AuditingConstants.AUDIT_REQUESTER_COMMENT));
    }
    CaseType parentCase = getCase(aCase.getParentRef().getOid());
    waitForCaseClose(parentCase);
    AssignmentType assignment = assertAssignedRole(userJackOid, ROLE_CAPTAIN.oid, result);
    display("assignment after creation", assignment);
    MetadataType metadata = assignment.getMetadata();
    assertNotNull("Null request timestamp in metadata", metadata.getRequestTimestamp());
    assertRefEquals("Wrong requestorRef in metadata", ObjectTypeUtil.createObjectRef(userAdministrator, prismContext), metadata.getRequestorRef());
    assertEquals("Wrong requestorComment in metadata", REQUESTER_COMMENT, metadata.getRequestorComment());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) Test(org.testng.annotations.Test)

Example 37 with ModelExecuteOptions

use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.

the class PageDebugView method savePerformed.

public void savePerformed(AjaxRequestTarget target) {
    if (StringUtils.isEmpty(objectViewDtoModel.getObject().getXml())) {
        error(getString("pageDebugView.message.cantSaveEmpty"));
        target.add(getFeedbackPanel());
        return;
    }
    Task task = createSimpleTask(OPERATION_SAVE_OBJECT);
    OperationResult result = task.getResult();
    try {
        PrismObject<? extends ObjectType> oldObject = objectViewDtoModel.getObject().getObject();
        oldObject.revive(getPrismContext());
        Holder<? extends ObjectType> objectHolder = new Holder<>(null);
        validateObject(result, (Holder) objectHolder);
        if (result.isAcceptable()) {
            PrismObject<? extends ObjectType> newObject = objectHolder.getValue().asPrismObject();
            ObjectDelta<? extends ObjectType> delta = oldObject.diff((PrismObject) newObject, EquivalenceStrategy.LITERAL);
            if (delta.getPrismContext() == null) {
                LOGGER.warn("No prism context in delta {} after diff, adding it", delta);
                delta.revive(getPrismContext());
            }
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Delta to be applied:\n{}", delta.debugDump());
            }
            // quick fix for now (MID-1910), maybe it should be somewhere in objectViewModel..
            // if (isReport(oldObject)){
            // ReportTypeUtil.applyConfigurationDefinition((PrismObject)newObject, delta, getPrismContext());
            // }
            Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
            ModelExecuteOptions options = ModelExecuteOptions.create(getPrismContext());
            if (isTrue(DebugViewOptions.ID_SAVE_AS_RAW)) {
                options.raw(true);
            }
            if (isTrue(DebugViewOptions.ID_REEVALUATE_SEARCH_FILTERS)) {
                options.reevaluateSearchFilters(true);
            }
            if (!isTrue(DebugViewOptions.ID_ENCRYPT)) {
                options.noCrypt(true);
            }
            getModelService().executeChanges(deltas, options, task, result);
            result.computeStatus();
        }
    } catch (Exception ex) {
        result.recordFatalError(getString("WebModelUtils.couldntSaveObject"), ex);
    }
    if (result.isError()) {
        showResult(result);
        target.add(getFeedbackPanel());
    } else {
        showResult(result);
        // to handle returning back to list objects page instead of edit object page
        if (getBreadcrumbs().size() >= 3) {
            redirectBack(3);
        } else {
            redirectBack();
        }
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) Holder(com.evolveum.midpoint.util.Holder) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 38 with ModelExecuteOptions

use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.

the class ProgressAwareChangesExecutorImpl method executeChanges.

public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, Task task, OperationResult result, AjaxRequestTarget target) {
    ModelExecuteOptions options = createOptions(executeOptions, previewOnly);
    LOGGER.debug("Using execute options {}.", options);
    if (executeOptions.isSaveInBackground() && !previewOnly) {
        return executeChangesInBackground(deltas, options, task, result, target);
    }
    return executeChanges(deltas, previewOnly, options, task, result, target);
}
Also used : ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions)

Example 39 with ModelExecuteOptions

use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.

the class PageUser method getDelegationPreviewOptions.

private ModelExecuteOptions getDelegationPreviewOptions() {
    ModelExecuteOptions options = getProgressPanel().getExecuteOptions().createOptions(getPrismContext());
    options.getOrCreatePartialProcessing().setApprovals(PartialProcessingTypeType.PROCESS);
    return options;
}
Also used : ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions)

Example 40 with ModelExecuteOptions

use of com.evolveum.midpoint.model.api.ModelExecuteOptions in project midpoint by Evolveum.

the class AbstractRoleMemberPanel method executeMemberOperation.

protected void executeMemberOperation(Task operationalTask, QName type, ObjectQuery memberQuery, ObjectDelta delta, String category, AjaxRequestTarget target) {
    OperationResult parentResult = operationalTask.getResult();
    try {
        ModelExecuteOptions options = TaskCategory.EXECUTE_CHANGES.equals(category) ? // This was originally in ExecuteChangesTaskHandler, now it's transferred through task extension.
        ModelExecuteOptions.createReconcile() : null;
        TaskType task = WebComponentUtil.createSingleRecurrenceTask(parentResult.getOperation(), type, memberQuery, delta, options, category, getPageBase());
        WebModelServiceUtils.runTask(task, operationalTask, parentResult, getPageBase());
    } catch (SchemaException e) {
        parentResult.recordFatalError(parentResult.getOperation(), e);
        LoggingUtils.logUnexpectedException(LOGGER, "Failed to execute operation " + parentResult.getOperation(), e);
        target.add(getPageBase().getFeedbackPanel());
    }
    target.add(getPageBase().getFeedbackPanel());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)80 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)47 Task (com.evolveum.midpoint.task.api.Task)45 Test (org.testng.annotations.Test)30 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 RestartResponseException (org.apache.wicket.RestartResponseException)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)3 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3 ExecuteChangeOptionsDto (com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto)3 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)3 NotNull (org.jetbrains.annotations.NotNull)3