Search in sources :

Example 46 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class TestMappingDynamicSysVar method testScriptSystemVariablesConditionEmptyFalse.

public void testScriptSystemVariablesConditionEmptyFalse(final String TEST_NAME, String filename) throws Exception {
    System.out.println("===[ " + TEST_NAME + "]===");
    // GIVEN
    ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, evaluator.toPath("name"), evaluator.getPrismContext(), PrismTestUtil.createPolyString("Jack"));
    Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping(filename, TEST_NAME, "title", delta);
    PrismObject<UserType> user = (PrismObject<UserType>) mapping.getSourceContext().getOldObject();
    user.asObjectable().getEmployeeType().add("SAILOR");
    user.asObjectable().setEmployeeNumber("666");
    mapping.getSourceContext().recompute();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    assertNull("Unexpected value in outputTriple: " + outputTriple, outputTriple);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 47 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class TestMappingDynamicSysVar method testScriptSystemVariablesConditionFalseToTrue.

public void testScriptSystemVariablesConditionFalseToTrue(String filename) throws Exception {
    // GIVEN
    final String TEST_NAME = "testScriptSystemVariablesConditionFalseToTrue";
    System.out.println("===[ " + TEST_NAME + "]===");
    ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, evaluator.toPath("name"), evaluator.getPrismContext(), PrismTestUtil.createPolyString("Jack"));
    delta.addModificationAddProperty(evaluator.toPath("employeeType"), "CAPTAIN");
    Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping(filename, TEST_NAME, "title", delta);
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, PrismTestUtil.createPolyString("Captain Jack"));
    PrismAsserts.assertTripleNoMinus(outputTriple);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 48 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class TestMappingDynamicSysVar method testScriptSystemVariablesConditionTrueToFalse.

public void testScriptSystemVariablesConditionTrueToFalse(String filename) throws Exception {
    // GIVEN
    final String TEST_NAME = "testScriptSystemVariablesConditionTrueToFalse";
    System.out.println("===[ " + TEST_NAME + "]===");
    ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, evaluator.toPath("name"), evaluator.getPrismContext(), "Jack");
    delta.addModificationDeleteProperty(evaluator.toPath("employeeType"), "CAPTAIN");
    Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping(filename, TEST_NAME, "title", delta);
    PrismObject<UserType> user = (PrismObject<UserType>) mapping.getSourceContext().getOldObject();
    user.asObjectable().getEmployeeType().add("CAPTAIN");
    mapping.getSourceContext().recompute();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleMinus(outputTriple, PrismTestUtil.createPolyString("Captain jack"));
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 49 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class AbstractSearchIterativeResultHandler method processRequest.

private void processRequest(ProcessingRequest request, Task workerTask, OperationResult parentResult) {
    PrismObject<O> object = request.object;
    String objectName = PolyString.getOrig(object.getName());
    String objectDisplayName = getDisplayName(object);
    OperationResult result = parentResult.createSubresult(taskOperationPrefix + ".handle");
    result.addParam("object", object);
    boolean cont;
    long startTime = System.currentTimeMillis();
    try {
        RepositoryCache.enter();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("{} starting for {} {}", getProcessShortNameCapitalized(), object, getContextDesc());
        }
        if (isRecordIterationStatistics()) {
            workerTask.recordIterativeOperationStart(objectName, objectDisplayName, null, /* TODO */
            object.getOid());
        }
        // The meat
        cont = handleObject(object, workerTask, result);
        // We do not want to override the result set by handler. This is just a fallback case
        if (result.isUnknown() || result.isInProgress()) {
            result.computeStatus();
        }
        if (result.isError()) {
            // Alternative way how to indicate an error.
            if (isRecordIterationStatistics()) {
                workerTask.recordIterativeOperationEnd(objectName, objectDisplayName, null, /* TODO */
                object.getOid(), startTime, getException(result));
            }
            cont = processError(object, null, result);
        } else {
            if (isRecordIterationStatistics()) {
                workerTask.recordIterativeOperationEnd(objectName, objectDisplayName, null, /* TODO */
                object.getOid(), startTime, null);
            }
            if (result.isSuccess()) {
                // FIXME: hack. Hardcoded ugly summarization of successes. something like
                // AbstractSummarizingResultHandler [lazyman]
                result.getSubresults().clear();
            }
        }
    } catch (CommonException | RuntimeException e) {
        if (isRecordIterationStatistics()) {
            workerTask.recordIterativeOperationEnd(objectName, objectDisplayName, null, /* TODO */
            object.getOid(), startTime, e);
        }
        cont = processError(object, e, result);
    } finally {
        RepositoryCache.exit();
        long duration = System.currentTimeMillis() - startTime;
        long total = totalTimeProcessing.addAndGet(duration);
        int progress = objectsProcessed.incrementAndGet();
        result.addContext(OperationResult.CONTEXT_PROGRESS, progress);
        // parentResult is worker-thread-specific result (because of concurrency issues)
        // or parentResult as obtained in handle(..) method in single-thread scenario
        parentResult.summarize();
        synchronized (coordinatorTask) {
            coordinatorTask.setProgress(progress);
            if (requestQueue != null) {
                workerTask.setProgress(workerTask.getProgress() + 1);
            }
            // todo report current op result?
            if (shouldReportProgress()) {
                coordinatorTask.storeOperationStats();
            // includes savePendingModifications - this is necessary for the progress to be immediately available in GUI
            }
        }
        if (logObjectProgress) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("{} object {} {} done with status {} (this one: {} ms, avg: {} ms) (total progress: {}, wall clock avg: {} ms)", getProcessShortNameCapitalized(), object, getContextDesc(), result.getStatus(), duration, total / progress, progress, (System.currentTimeMillis() - this.startTime) / progress);
            }
        }
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("{} finished for {} {}, result:\n{}", getProcessShortNameCapitalized(), object, getContextDesc(), result.debugDump());
    }
    if (!cont) {
        stopRequestedByAnyWorker.set(true);
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 50 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class AbstractSearchIterativeResultHandler method createWorkerThreads.

public void createWorkerThreads(Task coordinatorTask, OperationResult opResult) {
    Integer threadsCount = getWorkerThreadsCount(coordinatorTask);
    if (threadsCount == null || threadsCount == 0) {
        // nothing to do
        return;
    }
    // actually, size of threadsCount should be sufficient but it doesn't hurt if queue is larger
    int queueSize = threadsCount * 2;
    requestQueue = new ArrayBlockingQueue<>(queueSize);
    workerSpecificResults = new ArrayList<>(threadsCount);
    for (int i = 0; i < threadsCount; i++) {
        // we intentionally do not put worker specific result under main operation result until the handler is done
        // (because of concurrency issues - adding subresults vs e.g. putting main result into the task)
        OperationResult workerSpecificResult = new OperationResult(taskOperationPrefix + ".handleAsynchronously");
        workerSpecificResult.addContext("subtask", i);
        workerSpecificResults.add(workerSpecificResult);
        Task subtask = coordinatorTask.createSubtask(new WorkerHandler(workerSpecificResult));
        if (isEnableIterationStatistics()) {
            subtask.resetIterativeTaskInformation(null);
        }
        if (isEnableSynchronizationStatistics()) {
            subtask.resetSynchronizationInformation(null);
        }
        if (isEnableActionsExecutedStatistics()) {
            subtask.resetActionsExecutedInformation(null);
        }
        subtask.setCategory(coordinatorTask.getCategory());
        subtask.setResult(new OperationResult(taskOperationPrefix + ".executeWorker", OperationResultStatus.IN_PROGRESS, null));
        subtask.setName("Worker thread " + (i + 1) + " of " + threadsCount);
        subtask.startLightweightHandler();
        LOGGER.trace("Worker subtask {} created", subtask);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3475 Test (org.testng.annotations.Test)2435 Task (com.evolveum.midpoint.task.api.Task)2390 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1059 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)725 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)637 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)414 PrismObject (com.evolveum.midpoint.prism.PrismObject)388 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)376 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)320 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)288 ArrayList (java.util.ArrayList)262 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)252 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)250 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)231 QName (javax.xml.namespace.QName)198 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)197 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)182 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)171 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)149