Search in sources :

Example 26 with RepositoryService

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);
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QueryFactory(com.evolveum.midpoint.prism.query.QueryFactory) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) PrismObject(com.evolveum.midpoint.prism.PrismObject) DeleteOptions(com.evolveum.midpoint.ninja.opts.DeleteOptions) InputStreamReader(java.io.InputStreamReader) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) InOidFilter(com.evolveum.midpoint.prism.query.InOidFilter) Modifier(java.lang.reflect.Modifier) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) BufferedReader(java.io.BufferedReader) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 27 with RepositoryService

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.");
    }
}
Also used : GetOperationOptions.createReadOnlyCollection(com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection) java.util(java.util) ExpressionEvaluatorProfile(com.evolveum.midpoint.schema.expression.ExpressionEvaluatorProfile) CacheInvalidationContext(com.evolveum.midpoint.CacheInvalidationContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) Cache(com.evolveum.midpoint.repo.api.Cache) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) PreDestroy(javax.annotation.PreDestroy) ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile) AccessDecision(com.evolveum.midpoint.schema.AccessDecision) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException) ScriptExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType) PrismContext(com.evolveum.midpoint.prism.PrismContext) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) CacheRegistry(com.evolveum.midpoint.repo.api.CacheRegistry) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) FunctionLibraryType(com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType) SingleCacheStateInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType) CustomFunctions(com.evolveum.midpoint.model.common.expression.functions.CustomFunctions) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) PostConstruct(javax.annotation.PostConstruct) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FunctionLibraryType(com.evolveum.midpoint.xml.ns._public.common.common_3.FunctionLibraryType) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ScriptExpressionProfile(com.evolveum.midpoint.schema.expression.ScriptExpressionProfile) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) CustomFunctions(com.evolveum.midpoint.model.common.expression.functions.CustomFunctions) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)

Aggregations

RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)27 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)20 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 PrismContext (com.evolveum.midpoint.prism.PrismContext)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 Test (org.testng.annotations.Test)8 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)7 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)4 List (java.util.List)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 Trace (com.evolveum.midpoint.util.logging.Trace)3 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3