use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType in project midpoint by Evolveum.
the class AddExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean raw = getParamRaw(expression, input, context, globalResult);
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
for (PipelineItem item : input.getData()) {
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
PrismValue value = item.getValue();
if (value instanceof PrismObjectValue) {
@SuppressWarnings({ "unchecked", "raw" }) PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
operationsHelper.applyDelta(createAddDelta(objectType), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
exception = processActionException(ex, NAME, value, context);
}
context.println((exception != null ? "Attempted to add " : "Added ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + 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.xml.ns._public.model.scripting_3.ActionExpressionType in project midpoint by Evolveum.
the class DiscoverConnectorsExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean rebind = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_REBIND_RESOURCES, input, context, false, PARAM_REBIND_RESOURCES, globalResult);
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 ConnectorHostType) {
PrismObject<ConnectorHostType> connectorHostTypePrismObject = ((PrismObjectValue) value).asPrismObject();
Set<ConnectorType> newConnectors;
long started = operationsHelper.recordStart(context, connectorHostTypePrismObject.asObjectable());
Throwable exception = null;
try {
newConnectors = modelService.discoverConnectors(connectorHostTypePrismObject.asObjectable(), context.getTask(), result);
operationsHelper.recordEnd(context, connectorHostTypePrismObject.asObjectable(), started, null);
} catch (CommunicationException | SecurityViolationException | SchemaException | ConfigurationException | ObjectNotFoundException | RuntimeException e) {
operationsHelper.recordEnd(context, connectorHostTypePrismObject.asObjectable(), started, e);
exception = processActionException(e, NAME, value, context);
newConnectors = Collections.emptySet();
}
context.println((exception != null ? "Attempted to discover " : "Discovered " + newConnectors.size()) + " new connector(s) from " + connectorHostTypePrismObject + exceptionSuffix(exception));
for (ConnectorType connectorType : newConnectors) {
output.addValue(connectorType.asPrismObject().getValue(), item.getResult());
}
try {
if (rebind) {
rebindConnectors(newConnectors, context, result);
}
} catch (ScriptExecutionException e) {
//noinspection ThrowableNotThrown
// TODO better message
processActionException(e, NAME, value, context);
}
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Input item is not a PrismObject<ConnectorHost>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
// TODO configurable output (either connector hosts or discovered connectors)
return output;
}
use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionExpressionType 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.xml.ns._public.model.scripting_3.ActionExpressionType 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.xml.ns._public.model.scripting_3.ActionExpressionType 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