Search in sources :

Example 36 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class PageReport method saveAndRunPerformed.

public void saveAndRunPerformed(AjaxRequestTarget target) {
    try {
        processingOfSaveAndRun = true;
        OperationResult saveResult = new OperationResult(OPERATION_SAVE);
        Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = saveOrPreviewPerformed(target, saveResult, false);
        if (!saveResult.isError()) {
            PrismObject<ReportType> report = getReport(executedDeltas);
            if (!ReportOperationalButtonsPanel.hasParameters(report.asObjectable())) {
                runReport(report, null);
            } else {
                RunReportPopupPanel runReportPopupPanel = new RunReportPopupPanel(getMainPopupBodyId(), report.asObjectable()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public StringResourceModel getTitle() {
                        return createStringResource("PageReport.reportPreview");
                    }

                    protected void runConfirmPerformed(AjaxRequestTarget target, PrismObject<ReportType> report, PrismContainer<ReportParameterType> reportParam) {
                        runReport(report, reportParam);
                        hideMainPopup(target);
                    }
                };
                showMainPopup(runReportPopupPanel, target);
            }
        }
    } finally {
        processingOfSaveAndRun = false;
    }
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RunReportPopupPanel(com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel)

Example 37 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class ProgressPanel method executeChangesSync.

private void executeChangesSync(ProgressReporter reporter, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
    try {
        MidPointApplication application = MidPointApplication.get();
        if (previewOnly) {
            ModelInteractionService service = application.getModelInteractionService();
            ModelContext previewResult = service.previewChanges(deltas, options, task, result);
            reporter.setPreviewResult(previewResult);
        } else {
            ModelService service = application.getModel();
            Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = service.executeChanges(deltas, options, task, result);
            reporter.setObjectDeltaOperation(executedDeltas);
        }
        result.computeStatusIfUnknown();
    } catch (CommonException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Error executing changes", e);
        if (!result.isFatalError()) {
            // just to be sure the exception is recorded into the result
            result.recordFatalError(e.getMessage(), e);
        }
    }
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) CommonException(com.evolveum.midpoint.util.exception.CommonException) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 38 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class ModelCrudService method addObject.

/**
 * <p>
 * Add new object.
 * </p>
 * <p>
 * The OID provided in the input message may be empty. In that case the OID
 * will be assigned by the implementation of this method and it will be
 * provided as return value.
 * </p>
 * <p>
 * This operation should fail if such object already exists (if object with
 * the provided OID already exists).
 * </p>
 * <p>
 * The operation may fail if provided OID is in an unusable format for the
 * storage. Generating own OIDs and providing them to this method is not
 * recommended for normal operation.
 * </p>
 * <p>
 * Should be atomic. Should not allow creation of two objects with the same
 * OID (even if created in parallel).
 * </p>
 * <p>
 * The operation may fail if the object to be created does not conform to
 * the underlying schema of the storage system or the schema enforced by the
 * implementation.
 * </p>
 *
 * @param object
 *            object to create
 * @param parentResult
 *            parent OperationResult (in/out)
 * @return OID assigned to the created object
 * @throws ObjectAlreadyExistsException
 *             object with specified identifiers already exists, cannot add
 * @throws ObjectNotFoundException
 *             object required to complete the operation was not found (e.g.
 *             appropriate connector or resource definition)
 * @throws SchemaException
 *             error dealing with resource schema, e.g. created object does
 *             not conform to schema
 * @throws ExpressionEvaluationException
 *                 evaluation of expression associated with the object has failed
 * @throws CommunicationException
 * @throws ConfigurationException
 * @throws PolicyViolationException
 *                 Policy violation was detected during processing of the object
 * @throws IllegalArgumentException
 *             wrong OID format, etc.
 * @throws SystemException
 *             unknown error from underlying layers or other unexpected
 *             state
 */
@SuppressWarnings("JavaDoc")
public <T extends ObjectType> String addObject(PrismObject<T> object, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    Validate.notNull(object, "Object must not be null.");
    Validate.notNull(parentResult, "Result type must not be null.");
    object.checkConsistence();
    T objectType = object.asObjectable();
    prismContext.adopt(objectType);
    OperationResult result = parentResult.createSubresult(ADD_OBJECT);
    result.addParam(OperationResult.PARAM_OBJECT, object);
    ModelImplUtils.resolveReferences(object, repository, false, false, EvaluationTimeType.IMPORT, true, prismContext, result);
    String oid;
    RepositoryCache.enterLocalCaches(cacheConfigurationManager);
    try {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Entering addObject with {}", object);
            LOGGER.trace(object.debugDump());
        }
        if (options == null) {
            if (StringUtils.isNotEmpty(objectType.getVersion())) {
                options = ModelExecuteOptions.create(prismContext).overwrite();
            }
        }
        ObjectDelta<T> objectDelta = DeltaFactory.Object.createAddDelta(object);
        Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
        Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = modelService.executeChanges(deltas, options, task, result);
        oid = ObjectDeltaOperation.findAddDeltaOid(executedChanges, object);
        result.computeStatus();
        result.cleanupResult();
    } catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | SecurityViolationException | ConfigurationException | RuntimeException ex) {
        ModelImplUtils.recordFatalError(result, ex);
        throw ex;
    } finally {
        RepositoryCache.exitLocalCaches();
    }
    return oid;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation)

Example 39 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class TestStrings method test222FormApproveByCheese.

/**
 * Cheese approves, filling-in a form.
 */
@Test
public void test222FormApproveByCheese() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    given();
    login(userAdministrator);
    SearchResultList<CaseWorkItemType> workItems = getWorkItems(task, result);
    CaseWorkItemType workItem = sortByOriginalAssignee(workItems).get(USER_CHEESE.oid);
    assertNotNull("No work item for cheese", workItem);
    when();
    PrismObject<UserType> cheese = getUserFromRepo(USER_CHEESE.oid);
    login(cheese);
    ObjectDelta<UserType> formDelta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("Hello").asObjectDelta(USER_BOB.oid);
    caseService.completeWorkItem(WorkItemId.of(workItem), ApprovalUtils.createApproveOutput(prismContext).comment("OK. LeChuck"), formDelta, task, result);
    then();
    login(userAdministrator);
    workItems = getWorkItems(task, result);
    displayWorkItems("Work item after 2nd approval", workItems);
    assertEquals("Wrong # of work items after 2nd approval", 0, workItems.size());
    CaseType aCase = getCase(CaseWorkItemUtil.getCaseRequired(workItem).getOid());
    display("aCase after 2nd approval", aCase);
    assertStage(aCase, 2, 2, "Role approvers (first)", null);
    // notifications
    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);
    // audit
    displayDumpable("audit", dummyAuditService);
    List<AuditEventRecord> records = dummyAuditService.getRecords();
    if (records.size() != 4 && records.size() != 5) {
        fail("Wrong # of audit records: " + records.size() + " (expected 4 or 5)");
    }
    AuditEventRecord record = records.get(0);
    Collection<ObjectDeltaOperation<? extends ObjectType>> deltas = record.getDeltas();
    assertEquals("Wrong # of deltas in audit record", 1, deltas.size());
    ObjectDeltaOperation<? extends ObjectType> delta = deltas.iterator().next();
    assertEquals("Wrong # of modifications in audit record delta", 2, delta.getObjectDelta().getModifications().size());
    ItemDelta<?, ?> itemDelta = delta.getObjectDelta().getModifications().stream().filter(d -> UserType.F_DESCRIPTION.equivalent(d.getPath())).findFirst().orElse(null);
    assertNotNull("No user.description item delta found", itemDelta);
    assertEquals("Wrong value in delta", "Hello", itemDelta.getValuesToReplace().iterator().next().getRealValue());
    // record #1, #2: cancellation of work items of other approvers
    // record #3: finishing process execution
    // optional #4: asynchronous execution in task
    CaseType rootCase = getCase(aCase.getParentRef().getOid());
    waitForCaseClose(rootCase, CASE_WAIT_TIMEOUT);
    assertAssignedRole(getUser(USER_BOB.oid), ROLE_A_TEST_4.oid);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) Test(org.testng.annotations.Test)

Example 40 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class AsynchronousScriptExecutor method submitTask.

private void submitTask(OperationResult result, TaskType newTask) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    Set<ObjectDelta<? extends ObjectType>> deltas = singleton(DeltaFactory.Object.createAddDelta(newTask.asPrismObject()));
    ModelExecuteOptions options = new ModelExecuteOptions(actx.beans.prismContext).preAuthorized();
    Collection<ObjectDeltaOperation<? extends ObjectType>> operations = actx.beans.modelService.executeChanges(deltas, options, actx.task, result);
    String oid = ObjectDeltaOperation.findAddDeltaOid(operations, newTask.asPrismObject());
    result.setAsynchronousOperationReference(oid);
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)51 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)24 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)15 Task (com.evolveum.midpoint.task.api.Task)12 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)11 Test (org.testng.annotations.Test)11 ArrayList (java.util.ArrayList)9 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 ModelService (com.evolveum.midpoint.model.api.ModelService)3 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 CommonException (com.evolveum.midpoint.util.exception.CommonException)3 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2