use of com.evolveum.midpoint.util.exception.ScriptExecutionException in project midpoint by Evolveum.
the class ResolveExecutor method resolveReference.
private void resolveReference(ExecutionContext context, Collection<SelectorOptions<GetOperationOptions>> options, PipelineData output, PipelineItem item, PrismValue value, OperationResult result) throws ScriptExecutionException {
if (value instanceof PrismReferenceValue) {
PrismReferenceValue prismReferenceValue = (PrismReferenceValue) value;
String oid = prismReferenceValue.getOid();
QName targetTypeQName = prismReferenceValue.getTargetType();
if (targetTypeQName == null) {
throw new ScriptExecutionException("Couldn't resolve reference, because target type is unknown: " + prismReferenceValue);
}
Class<? extends ObjectType> type = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeQName);
if (type == null) {
throw new ScriptExecutionException("Couldn't resolve reference, because target type class is unknown for target type " + targetTypeQName);
}
try {
PrismObjectValue<? extends ObjectType> resolved = modelService.getObject(type, oid, options, context.getTask(), result).getValue();
output.add(new PipelineItem(resolved, item.getResult()));
} catch (Throwable e) {
// noinspection ThrowableNotThrown
processActionException(e, NAME, value, context);
// to keep track of failed item (may trigger exceptions downstream)
output.add(item);
}
} else {
// noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Value is not a reference"), NAME, value, context);
// to keep track of failed item (may trigger exceptions downstream)
output.add(item);
}
}
use of com.evolveum.midpoint.util.exception.ScriptExecutionException in project midpoint by Evolveum.
the class ValidateExecutor 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, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue<?>) value).asObjectable() instanceof ResourceType) {
// noinspection unchecked
PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue<ResourceType>) value).asPrismObject();
ResourceType resourceType = resourceTypePrismObject.asObjectable();
Operation op = operationsHelper.recordStart(context, resourceType);
try {
ValidationResult validationResult = resourceValidator.validate(resourceTypePrismObject, Scope.THOROUGH, null, context.getTask(), result);
PrismContainerDefinition<ValidationResultType> pcd = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(SchemaConstantsGenerated.C_VALIDATION_RESULT);
PrismContainer<ValidationResultType> pc = pcd.instantiate();
// noinspection unchecked
pc.add(validationResult.toValidationResultType().asPrismContainerValue());
context.println("Validated " + resourceTypePrismObject + ": " + validationResult.getIssues().size() + " issue(s)");
operationsHelper.recordEnd(context, op, null, result);
output.add(new PipelineItem(pc.getValue(), item.getResult()));
} catch (SchemaException | RuntimeException e) {
operationsHelper.recordEnd(context, op, e, result);
context.println("Error validation " + resourceTypePrismObject + ": " + e.getMessage());
// noinspection ThrowableNotThrown
processActionException(e, NAME, value, context);
output.add(item);
}
} else {
// noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, item.getResult());
}
return output;
}
use of com.evolveum.midpoint.util.exception.ScriptExecutionException in project midpoint by Evolveum.
the class SelectEvaluator method evaluate.
public PipelineData evaluate(SelectExpressionType selectExpression, PipelineData input, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
if (selectExpression.getPath() == null) {
return input;
}
ItemPath path = selectExpression.getPath().getItemPath();
PipelineData output = PipelineData.createEmpty();
for (PipelineItem item : input.getData()) {
Object o = item.getValue().find(path);
if (o != null) {
if (o instanceof Item) {
List<? extends PrismValue> values = ((Item<? extends PrismValue, ?>) o).getValues();
values.forEach((v) -> output.addValue(v, item.getResult().clone(), item.getVariables()));
} else {
throw new ScriptExecutionException("In 'select' commands, only property/container/reference selection is supported for now. Select on '" + path + "' returned this instead: " + o);
}
}
}
return output;
}
use of com.evolveum.midpoint.util.exception.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(createStringResource("PageBulkAction.message.startPerformed.fatalError.provided").getString());
} else if (!(parsed instanceof ExecuteScriptType) && !(parsed instanceof ScriptingExpressionType)) {
result.recordFatalError(createStringResource("PageBulkAction.message.startPerformed.fatalError.notBulkAction", "{scripting-3}ScriptingExpressionType", parsed.getClass()).getString());
}
} catch (SchemaException | RuntimeException e) {
result.recordFatalError(createStringResource("PageBulkAction.message.startPerformed.fatalError.parse").getString(), 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, createStringResource("PageBulkAction.message.startPerformed.inProgress", task.getName()).getString());
} catch (SchemaException | SecurityViolationException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | ClassCastException e) {
result.recordFatalError(createStringResource("PageBulkAction.message.startPerformed.fatalError.submit").getString(), 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, VariablesMap.emptyMap(), false, task, result) : getScriptingService().evaluateExpression((ScriptingExpressionType) parsed, task, result);
result.recordStatus(OperationResultStatus.SUCCESS, createStringResource("PageBulkAction.message.startPerformed.success", executionResult.getDataOutput().size()).getString());
result.addReturn("console", executionResult.getConsoleOutput());
result.addArbitraryObjectCollectionAsReturn("data", executionResult.getDataOutput());
} catch (ScriptExecutionException | SchemaException | SecurityViolationException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | ClassCastException e) {
result.recordFatalError(createStringResource("PageBulkAction.message.startPerformed.fatalError.execute").getString(), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute bulk action", e);
}
}
}
showResult(result);
target.add(getFeedbackPanel());
}
use of com.evolveum.midpoint.util.exception.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 = prismContext.queryFor(ConnectorType.class).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.getConnectorHostRef() != null && connectorType.getConnectorHostRef().asReferenceValue().getObject() != null) {
String connectorHostOid = connectorType.getConnectorHostRef().getOid();
connectorType.getConnectorHostRef().asReferenceValue().setObject(null);
connectorType.getConnectorHostRef().setOid(connectorHostOid);
}
if (connectorType.getConnectorHostRef().equals(foundConnectorType.getConnectorHostRef()) && foundConnectorType.getConnectorVersion() != null && !foundConnectorType.getConnectorVersion().equals(connectorType.getConnectorVersion())) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Found obsolete connector:\n{}", foundConnectorType.asPrismObject().debugDump(1));
}
rebindMap.put(foundConnectorType.getOid(), connectorType.getOid());
}
}
}
Aggregations