use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class DeleteExecutor 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()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue) {
PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
operationsHelper.applyDelta(createDeleteDelta(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 delete " : "Deleted ") + 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.prism.PrismValue in project midpoint by Evolveum.
the class EnableDisableExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean isEnable = NAME_ENABLE.equals(expression.getType());
boolean raw = getParamRaw(expression, input, context, globalResult);
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
result.addParam("operation", expression.getType());
context.checkTaskStop();
if (value instanceof PrismObjectValue) {
PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
if (objectType instanceof FocusType) {
operationsHelper.applyDelta(createEnableDisableDelta((FocusType) objectType, isEnable), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
} else if (objectType instanceof ShadowType) {
operationsHelper.applyDelta(createEnableDisableDelta((ShadowType) objectType, isEnable), context, result);
} else {
throw new ScriptExecutionException("Item is not a FocusType nor ShadowType: " + value.toString());
}
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
exception = processActionException(ex, expression.getType(), value, context);
}
context.println((exception != null ? "Attempted to " + expression.getType() : (isEnable ? "Enabled " : "Disabled ")) + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject"), expression.getType(), value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class RecomputeExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && FocusType.class.isAssignableFrom(((PrismObjectValue) value).asPrismObject().getCompileTimeClass())) {
PrismObject<FocusType> focalPrismObject = ((PrismObjectValue) value).asPrismObject();
FocusType focusType = focalPrismObject.asObjectable();
long started = operationsHelper.recordStart(context, focusType);
Throwable exception = null;
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Recomputing object {} with dryRun={}: context:\n{}", focalPrismObject, dryRun);
}
ObjectDelta<? extends FocusType> emptyDelta = ObjectDelta.createEmptyDelta(focusType.getClass(), focusType.getOid(), prismContext, ChangeType.MODIFY);
operationsHelper.applyDelta(emptyDelta, ModelExecuteOptions.createReconcile(), dryRun, context, result);
LOGGER.trace("Recomputing of object {}: {}", focalPrismObject, result.getStatus());
operationsHelper.recordEnd(context, focusType, started, null);
} catch (Throwable e) {
operationsHelper.recordEnd(context, focusType, started, e);
exception = processActionException(e, NAME, value, context);
}
context.println((exception != null ? "Attempted to recompute " : "Recomputed ") + focalPrismObject.toString() + drySuffix(dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject<FocusType>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class ObjectMerger method evaluateValueExpression.
private <O extends ObjectType> Collection<PrismValue> evaluateValueExpression(PrismObject<O> objectLeft, PrismObject<O> objectRight, String side, PrismValue origValue, Expression<PrismValue, ItemDefinition> valueExpression, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(ExpressionConstants.VAR_SIDE, side);
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT_LEFT, side);
variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT_RIGHT, side);
variables.addVariableDefinition(ExpressionConstants.VAR_INPUT, origValue);
variables.addVariableDefinition(ExpressionConstants.VAR_VALUE, origValue);
ExpressionEvaluationContext exprContext = new ExpressionEvaluationContext(null, variables, "for value " + origValue, task, result);
PrismValueDeltaSetTriple<PrismValue> triple = valueExpression.evaluate(exprContext);
if (triple == null) {
return null;
}
return triple.getNonNegativeValues();
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class LazyXPathVariableResolver method convertToXml.
// May return primitive types or DOM Node
public static Object convertToXml(Object variableValue, QName variableName, final PrismContext prismContext, String contextDescription) throws SchemaException {
try {
if (variableValue instanceof Objectable) {
variableValue = ((Objectable) variableValue).asPrismObject();
}
if (variableValue instanceof PrismObject) {
PrismObject<?> prismObject = (PrismObject<?>) variableValue;
variableValue = prismObject.getPrismContext().domSerializer().serialize(prismObject);
} else if (variableValue instanceof PrismProperty<?>) {
PrismProperty<?> prismProperty = (PrismProperty<?>) variableValue;
final List<Element> elementList = new ArrayList<Element>();
for (PrismPropertyValue<?> value : prismProperty.getValues()) {
Element valueElement = prismContext.domSerializer().serialize(value, prismProperty.getElementName());
elementList.add(valueElement);
}
NodeList nodeList = new AdHocNodeList(elementList);
variableValue = nodeList;
} else if (variableValue instanceof PrismValue) {
PrismValue pval = (PrismValue) variableValue;
if (pval.getParent() == null) {
// Set a fake parent to allow serialization
pval.setParent(new AdHocItemable(prismContext));
}
variableValue = prismContext.domSerializer().serialize(pval, variableName);
}
if (!((variableValue instanceof Node) || variableValue instanceof NodeList) && !(variableValue.getClass().getPackage().getName().startsWith("java."))) {
throw new SchemaException("Unable to convert value of variable " + variableName + " to XML, still got " + variableValue.getClass().getName() + ":" + variableValue + " value at the end");
}
return variableValue;
} catch (SchemaException e) {
if (variableValue != null && variableValue instanceof DebugDumpable) {
LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
}
throw new SchemaException(e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
} catch (RuntimeException e) {
if (variableValue != null && variableValue instanceof DebugDumpable) {
LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
}
throw new RuntimeException(e.getClass().getName() + ": " + e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
}
}
Aggregations