Search in sources :

Example 11 with ScriptExecutionException

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);
            }
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 12 with ScriptExecutionException

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;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException)

Example 13 with ScriptExecutionException

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;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 14 with ScriptExecutionException

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;
}
Also used : ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ActionParameterValueType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem)

Example 15 with ScriptExecutionException

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;
}
Also used : PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)25 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)11 PrismValue (com.evolveum.midpoint.prism.PrismValue)8 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)5 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)3 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)3 ActionParameterValueType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType)3 ScriptExecutionResult (com.evolveum.midpoint.model.api.ScriptExecutionResult)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2