use of com.evolveum.midpoint.model.impl.scripting.PipelineData in project midpoint by Evolveum.
the class TestResourceExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
PipelineData output = PipelineData.createEmpty();
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof ResourceType) {
PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue) value).asPrismObject();
ResourceType resourceType = resourceTypePrismObject.asObjectable();
long started = operationsHelper.recordStart(context, resourceType);
Throwable exception = null;
OperationResult testResult;
try {
testResult = modelService.testResource(resourceTypePrismObject.getOid(), context.getTask());
operationsHelper.recordEnd(context, resourceType, started, null);
} catch (ObjectNotFoundException | RuntimeException e) {
operationsHelper.recordEnd(context, resourceType, started, e);
exception = processActionException(e, NAME, value, context);
testResult = new OperationResult(TestResourceExecutor.class.getName() + ".testResource");
testResult.recordFatalError(e);
}
result.addSubresult(testResult);
context.println("Tested " + resourceTypePrismObject + ": " + testResult.getStatus() + exceptionSuffix(exception));
try {
PrismObjectValue<ResourceType> resourceValue = operationsHelper.getObject(ResourceType.class, resourceTypePrismObject.getOid(), false, context, result).getValue();
output.add(new PipelineItem(resourceValue, item.getResult()));
} catch (ExpressionEvaluationException e) {
throw new ScriptExecutionException("Error getting resource " + resourceTypePrismObject.getOid() + ": " + e.getMessage(), e);
}
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return output;
}
Aggregations