use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class GenerateValueExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
PolicyItemsDefinitionType itemsDefinition = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAMETER_ITEMS, false, false, PARAMETER_ITEMS, input, context, PolicyItemsDefinitionType.class, globalResult);
if (itemsDefinition == null) {
itemsDefinition = new PolicyItemsDefinitionType().policyItemDefinition(new PolicyItemDefinitionType().target(new PolicyItemTargetType().path(new ItemPathType(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE)))).execute(false));
}
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue) {
PrismObject<? extends ObjectType> object = ((PrismObjectValue) value).asPrismObject();
ObjectType objectBean = object.asObjectable();
long started = operationsHelper.recordStart(context, objectBean);
Throwable exception = null;
try {
LOGGER.trace("Generating value(s) for {}", objectBean);
modelInteraction.generateValue(object, itemsDefinition, context.getTask(), result);
operationsHelper.recordEnd(context, objectBean, started, null);
} catch (Throwable e) {
operationsHelper.recordEnd(context, objectBean, started, e);
exception = processActionException(e, NAME, value, context);
}
context.println((exception != null ? "Attempted to generate value(s) for " : "Generated value(s) for ") + objectBean.toString() + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class NotifyExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
String subtype = expressionHelper.getArgumentAsString(expression.getParameter(), PARAM_SUBTYPE, input, context, null, PARAM_SUBTYPE, globalResult);
EventHandlerType handler = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_HANDLER, false, false, PARAM_HANDLER, input, context, EventHandlerType.class, globalResult);
EventStatusType status = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_STATUS, false, false, PARAM_STATUS, input, context, EventStatusType.class, globalResult);
EventOperationType operation = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_OPERATION, false, false, PARAM_OPERATION, input, context, EventOperationType.class, globalResult);
boolean forWholeInput = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_FOR_WHOLE_INPUT, input, context, false, PARAM_SUBTYPE, globalResult);
if (handler != null) {
// TODO explain that the reason is that handler is not null
checkRootAuthorization(globalResult, NAME);
}
if (status == null) {
status = EventStatusType.SUCCESS;
}
if (operation == null) {
operation = EventOperationType.ADD;
}
if (notificationManager == null) {
throw new IllegalStateException("Notification manager is unavailable");
}
int eventCount = 0;
if (forWholeInput) {
Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, input.getData(), operation, status, context.getChannel());
notificationManager.processEvent(event, context.getTask(), globalResult);
eventCount++;
} else {
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, value, operation, status, context.getChannel());
notificationManager.processEvent(event, context.getTask(), result);
eventCount++;
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
}
context.println("Produced " + eventCount + " event(s)");
return input;
}
use of com.evolveum.midpoint.model.api.PipelineItem 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;
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class FilterContentEvaluator method evaluate.
public PipelineData evaluate(FilterContentExpressionType expression, PipelineData input, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
List<ItemPath> keep = convert(expression.getKeep());
List<ItemPath> remove = convert(expression.getRemove());
if (keep.isEmpty() && remove.isEmpty()) {
// nothing to do here
return input;
}
for (PipelineItem pipelineItem : input.getData()) {
PrismValue value = pipelineItem.getValue();
if (!(value instanceof PrismContainerValue)) {
String message = "In 'select' commands in keep/remove mode, we can act only on prism container values, not on " + value;
if (context.isContinueOnAnyError()) {
LOGGER.error(message);
} else {
throw new ScriptExecutionException(message);
}
} else {
PrismContainerValue<?> pcv = (PrismContainerValue) value;
if (!keep.isEmpty()) {
pcv.keepPaths(keep);
} else {
pcv.removePaths(remove);
}
}
}
return input;
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class PipelineData method create.
public static PipelineData create(PrismValue value) {
PipelineData d = createEmpty();
d.add(new PipelineItem(value, newOperationResult()));
return d;
}
Aggregations