use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class DeleteRepositoryAction method deleteByFilter.
private void deleteByFilter(ObjectTypes type, ObjectQuery query, OperationStatus operation, OperationResult result) throws SchemaException {
ResultHandler<?> handler = (prismObject, operationResult) -> {
try {
State state = options.isAsk() ? askForState(prismObject) : State.DELETE;
switch(state) {
case SKIP:
operation.incrementSkipped();
return true;
case STOP:
return false;
case DELETE:
default:
}
RepositoryService repository = context.getRepository();
repository.deleteObject(prismObject.getCompileTimeClass(), prismObject.getOid(), operationResult);
operation.incrementTotal();
} catch (ObjectNotFoundException ex) {
// object was already gone
} catch (IOException ex) {
context.getLog().error("Couldn't delete object {}, reason: {}", ex, prismObject, ex.getMessage());
operation.incrementError();
}
return true;
};
Collection<SelectorOptions<GetOperationOptions>> opts = new ArrayList<>();
if (options.isRaw()) {
opts.add(new SelectorOptions<>(GetOperationOptions.createRaw()));
}
RepositoryService repository = context.getRepository();
repository.searchObjectsIterative(type.getClassDefinition(), query, handler, opts, true, result);
}
use of com.evolveum.midpoint.repo.api.RepositoryService in project midpoint by Evolveum.
the class ScriptExpressionFactory method initializeCustomFunctionsLibraryCache.
private void initializeCustomFunctionsLibraryCache(ExpressionFactory expressionFactory, OperationResult result) throws ExpressionSyntaxException {
if (repositoryService != null) {
OperationResult subResult = result.createMinorSubresult(ScriptExpressionFactory.class.getName() + ".searchCustomFunctions");
ResultHandler<FunctionLibraryType> functionLibraryHandler = (object, parentResult) -> {
// TODO: determine profile from function library archetype
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
FunctionLibrary customLibrary = new FunctionLibrary();
customLibrary.setVariableName(object.getName().getOrig());
customLibrary.setGenericFunctions(new CustomFunctions(object.asObjectable(), expressionFactory, expressionProfile));
customLibrary.setNamespace(MidPointConstants.NS_FUNC_CUSTOM);
customFunctionLibraryCache.put(object.getName().getOrig(), customLibrary);
return true;
};
try {
repositoryService.searchObjectsIterative(FunctionLibraryType.class, null, functionLibraryHandler, createReadOnlyCollection(), true, subResult);
subResult.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException e) {
subResult.recordFatalError("Failed to initialize custom functions", e);
throw new ExpressionSyntaxException("An error occurred during custom libraries initialization. " + e.getMessage(), e);
}
} else {
LOGGER.warn("No repository service set for ScriptExpressionFactory; custom functions will not be loaded. This" + " can occur during low-level testing; never during standard system execution.");
}
}
Aggregations