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());
}
}
}
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;
}
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;
}
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;
}
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());
}
Aggregations