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);
}
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);
}
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"));
}
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);
}
}
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);
}
}
Aggregations