Search in sources :

Example 21 with ScriptExecutionException

use of com.evolveum.midpoint.model.api.ScriptExecutionException in project midpoint by Evolveum.

the class DiscoverConnectorsExecutor method determineConnectorMappings.

private void determineConnectorMappings(Map<String, String> rebindMap, ConnectorType connectorType, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Finding obsolete versions for connector: {}", connectorType.asPrismObject().debugDump());
    }
    ObjectQuery query = QueryBuilder.queryFor(ConnectorType.class, prismContext).item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(connectorType.getFramework()).and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(connectorType.getConnectorType()).build();
    List<PrismObject<ConnectorType>> foundConnectors;
    try {
        foundConnectors = modelService.searchObjects(ConnectorType.class, query, null, null, result);
    } catch (SchemaException | ConfigurationException | ObjectNotFoundException | CommunicationException | SecurityViolationException | ExpressionEvaluationException e) {
        throw new ScriptExecutionException("Couldn't get connectors of type: " + connectorType.getConnectorType() + ": " + e.getMessage(), e);
    }
    for (PrismObject<ConnectorType> foundConnector : foundConnectors) {
        ConnectorType foundConnectorType = foundConnector.asObjectable();
        // TODO temporary hack. fix it after MID-3355 is implemented.
        if (connectorType.getConnectorHost() != null) {
            if (foundConnectorType.getConnectorHost() == null) {
                connectorType.setConnectorHostRef(ObjectTypeUtil.createObjectRef(connectorType.getConnectorHost().getOid(), ObjectTypes.CONNECTOR_HOST));
                connectorType.setConnectorHost(null);
            }
        }
        if (connectorType.getConnectorHostRef().equals(foundConnectorType.getConnectorHostRef()) && foundConnectorType.getConnectorVersion() != null && !foundConnectorType.getConnectorVersion().equals(connectorType.getConnectorVersion())) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Found obsolete connector: {}", foundConnectorType.asPrismObject().debugDump());
            }
            rebindMap.put(foundConnectorType.getOid(), connectorType.getOid());
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 22 with ScriptExecutionException

use of com.evolveum.midpoint.model.api.ScriptExecutionException 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;
}
Also used : PolicyItemsDefinitionType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemsDefinitionType) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) PolicyItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemDefinitionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) PolicyItemTargetType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemTargetType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with ScriptExecutionException

use of com.evolveum.midpoint.model.api.ScriptExecutionException 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;
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) 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) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 24 with ScriptExecutionException

use of com.evolveum.midpoint.model.api.ScriptExecutionException 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;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 25 with ScriptExecutionException

use of com.evolveum.midpoint.model.api.ScriptExecutionException in project midpoint by Evolveum.

the class PageBulkAction method startPerformed.

private void startPerformed(AjaxRequestTarget target) {
    Task task = createSimpleTask(OPERATION_PERFORM_BULK);
    OperationResult result = new OperationResult(OPERATION_PERFORM_BULK);
    BulkActionDto bulkActionDto = model.getObject();
    if (StringUtils.isEmpty(bulkActionDto.getScript())) {
        warn(getString("PageBulkAction.message.emptyString"));
        target.add(getFeedbackPanel());
        return;
    }
    Object parsed = null;
    try {
        parsed = getPrismContext().parserFor(bulkActionDto.getScript()).parseRealValue();
        if (parsed == null) {
            result.recordFatalError("No bulk action object was provided.");
        } else if (!(parsed instanceof ExecuteScriptType) && !(parsed instanceof ScriptingExpressionType)) {
            result.recordFatalError("Provided text is not a bulk action object. An instance of {scripting-3}ScriptingExpressionType is expected; you have provided " + parsed.getClass() + " instead.");
        }
    } catch (SchemaException | RuntimeException e) {
        result.recordFatalError("Couldn't parse bulk action object", e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't parse bulk action object", e);
    }
    if (parsed != null) {
        if (bulkActionDto.isAsync()) {
            try {
                if (parsed instanceof ExecuteScriptType) {
                    getScriptingService().evaluateExpressionInBackground((ExecuteScriptType) parsed, task, result);
                } else {
                    //noinspection ConstantConditions
                    getScriptingService().evaluateExpressionInBackground((ScriptingExpressionType) parsed, task, result);
                }
                result.recordStatus(OperationResultStatus.IN_PROGRESS, task.getName() + " has been successfully submitted to execution");
            } catch (SchemaException | SecurityViolationException e) {
                result.recordFatalError("Couldn't submit bulk action to execution", e);
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't submit bulk action to execution", e);
            }
        } else {
            try {
                //noinspection ConstantConditions
                ScriptExecutionResult executionResult = parsed instanceof ExecuteScriptType ? getScriptingService().evaluateExpression((ExecuteScriptType) parsed, task, result) : getScriptingService().evaluateExpression((ScriptingExpressionType) parsed, task, result);
                result.recordStatus(OperationResultStatus.SUCCESS, "Action executed. Returned " + executionResult.getDataOutput().size() + " item(s). Console and data output available via 'Export to XML' function.");
                result.addReturn("console", executionResult.getConsoleOutput());
                result.addCollectionOfSerializablesAsReturn("data", executionResult.getDataOutput());
            } catch (ScriptExecutionException | SchemaException | SecurityViolationException e) {
                result.recordFatalError("Couldn't execute bulk action", e);
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute bulk action", e);
            }
        }
    }
    showResult(result);
    target.add(getFeedbackPanel());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExecuteScriptType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ScriptExecutionResult(com.evolveum.midpoint.model.api.ScriptExecutionResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ScriptingExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType) BulkActionDto(com.evolveum.midpoint.web.page.admin.configuration.dto.BulkActionDto)

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