use of com.evolveum.midpoint.model.api.ScriptExecutionException in project midpoint by Evolveum.
the class DiscoverConnectorsExecutor method rebindResources.
private void rebindResources(Map<String, String> rebindMap, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
List<PrismObject<ResourceType>> resources;
try {
resources = modelService.searchObjects(ResourceType.class, null, null, null, result);
} catch (SchemaException | ConfigurationException | ObjectNotFoundException | CommunicationException | SecurityViolationException | ExpressionEvaluationException e) {
throw new ScriptExecutionException("Couldn't list resources: " + e.getMessage(), e);
}
for (PrismObject<ResourceType> resource : resources) {
if (resource.asObjectable().getConnectorRef() != null) {
String connectorOid = resource.asObjectable().getConnectorRef().getOid();
String newOid = rebindMap.get(connectorOid);
if (newOid != null) {
String msg = "resource " + resource + " from connector " + connectorOid + " to new one: " + newOid;
LOGGER.info("Rebinding " + msg);
ReferenceDelta refDelta = ReferenceDelta.createModificationReplace(ResourceType.F_CONNECTOR_REF, resource.getDefinition(), newOid);
ObjectDelta<ResourceType> objDelta = ObjectDelta.createModifyDelta(resource.getOid(), refDelta, ResourceType.class, prismContext);
operationsHelper.applyDelta(objDelta, context, result);
context.println("Rebound " + msg);
}
}
}
}
use of com.evolveum.midpoint.model.api.ScriptExecutionException in project midpoint by Evolveum.
the class PipelineData method getDataAsReferences.
public Collection<ObjectReferenceType> getDataAsReferences(QName defaultTargetType) throws ScriptExecutionException {
Collection<ObjectReferenceType> retval = new ArrayList<>(data.size());
for (PipelineItem item : data) {
PrismValue value = item.getValue();
if (value instanceof PrismObjectValue) {
PrismObjectValue objectValue = (PrismObjectValue) value;
ObjectReferenceType ref = new ObjectReferenceType();
// todo check the definition is present
ref.setType(objectValue.asPrismObject().getDefinition().getTypeName());
// todo check if oid is present
ref.setOid(objectValue.getOid());
retval.add(ref);
} else if (value instanceof PrismPropertyValue) {
Object realValue = ((PrismPropertyValue) value).getRealValue();
if (realValue instanceof String) {
ObjectReferenceType ref = new ObjectReferenceType();
ref.setType(defaultTargetType);
// todo implement search by name
ref.setOid((String) realValue);
retval.add(ref);
} else if (realValue instanceof ObjectReferenceType) {
retval.add((ObjectReferenceType) realValue);
} else {
throw new ScriptExecutionException("Unsupported reference type: " + value.getClass());
}
} else if (value instanceof PrismReferenceValue) {
PrismReferenceValue referenceValue = (PrismReferenceValue) value;
ObjectReferenceType ref = new ObjectReferenceType();
ref.setupReferenceValue(referenceValue);
retval.add(ref);
}
}
return retval;
}
use of com.evolveum.midpoint.model.api.ScriptExecutionException 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.model.api.ScriptExecutionException in project midpoint by Evolveum.
the class ModifyExecutor 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);
ActionParameterValueType deltaParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_DELTA, true, true, NAME);
PipelineData deltaData = expressionHelper.evaluateParameter(deltaParameterValue, ObjectDeltaType.class, 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 {
ObjectDelta<?> delta = createDelta(objectType, deltaData);
result.addParam("delta", delta);
operationsHelper.applyDelta(delta, 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 modify " : "Modified ") + 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.model.api.ScriptExecutionException in project midpoint by Evolveum.
the class PurgeSchemaExecutor 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<Objectable>) value).asObjectable() instanceof ResourceType) {
PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue) value).asPrismObject();
ResourceType resourceType = resourceTypePrismObject.asObjectable();
long started = operationsHelper.recordStart(context, resourceType);
ObjectDelta delta = createDelta(resourceTypePrismObject.asObjectable());
try {
if (delta != null) {
operationsHelper.applyDelta(delta, ModelExecuteOptions.createRaw(), context, result);
context.println("Purged schema information from " + resourceTypePrismObject);
output.addValue(operationsHelper.getObject(ResourceType.class, resourceTypePrismObject.getOid(), true, context, result).getValue(), item.getResult());
} else {
context.println("There's no schema information to be purged in " + value);
output.addValue(resourceTypePrismObject.getValue(), item.getResult());
}
operationsHelper.recordEnd(context, resourceType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, resourceType, started, ex);
Throwable exception = processActionException(ex, NAME, value, context);
context.println("Couldn't purge schema information from " + resourceTypePrismObject + exceptionSuffix(exception));
}
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return output;
}
Aggregations