Search in sources :

Example 26 with SKIP

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PartialProcessingTypeType.SKIP 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 SKIP

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PartialProcessingTypeType.SKIP in project midpoint by Evolveum.

the class AbstractScriptEvaluator method prepareScriptVariablesValueMap.

/**
 * Returns simple variable map: name -> value.
 */
protected Map<String, Object> prepareScriptVariablesValueMap(ScriptExpressionEvaluationContext context) throws ExpressionSyntaxException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Map<String, Object> scriptVariableMap = new HashMap<>();
    // Functions
    if (context.getFunctions() != null) {
        for (FunctionLibrary funcLib : context.getFunctions()) {
            scriptVariableMap.put(funcLib.getVariableName(), funcLib.getGenericFunctions());
        }
    }
    // Variables
    VariablesMap variables = context.getVariables();
    if (variables != null) {
        for (Entry<String, TypedValue> variableEntry : variables.entrySet()) {
            if (variableEntry.getKey() == null) {
                // This is the "root" node. We have no use for it in script expressions, just skip it
                continue;
            }
            String variableName = variableEntry.getKey();
            ValueVariableModeType valueVariableMode = ObjectUtils.defaultIfNull(context.getExpressionType().getValueVariableMode(), ValueVariableModeType.REAL_VALUE);
            // noinspection rawtypes
            TypedValue variableTypedValue = ExpressionUtil.convertVariableValue(variableEntry.getValue(), variableName, context.getObjectResolver(), context.getContextDescription(), context.getExpressionType().getObjectVariableMode(), valueVariableMode, prismContext, context.getTask(), context.getResult());
            scriptVariableMap.put(variableName, variableTypedValue.getValue());
            if (context.getTrace() != null && !variables.isAlias(variableName)) {
                ScriptVariableEvaluationTraceType variableTrace = new ScriptVariableEvaluationTraceType(prismContext);
                variableTrace.setName(new QName(variableName));
                Object clonedValue = cloneIfPossible(variableTypedValue.getValue());
                variableTrace.getValue().addAll(TraceUtil.toAnyValueTypeList(clonedValue, prismContext));
                variables.getAliases(variableName).forEach(alias -> variableTrace.getAlias().add(new QName(alias)));
                context.getTrace().getVariable().add(variableTrace);
            }
        }
    }
    putIfMissing(scriptVariableMap, ExpressionConstants.VAR_PRISM_CONTEXT, prismContext);
    putIfMissing(scriptVariableMap, ExpressionConstants.VAR_LOCALIZATION_SERVICE, localizationService);
    return scriptVariableMap;
}
Also used : ScriptVariableEvaluationTraceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptVariableEvaluationTraceType) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ValueVariableModeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValueVariableModeType) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) TypedValue(com.evolveum.midpoint.schema.expression.TypedValue)

Example 28 with SKIP

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PartialProcessingTypeType.SKIP in project midpoint by Evolveum.

the class ShadowedObjectFound method initializeInternal.

/**
 * Acquires repo shadow, updates it, and prepares the shadowedObject.
 * In emergency does a minimalistic processing aimed at acquiring a shadow.
 */
@Override
public void initializeInternal(Task task, OperationResult result) throws CommonException, NotApplicableException, EncryptionException {
    if (!initializationState.isInitialStateOk()) {
        // The object is somehow flawed. However, we try to create a shadow.
        // 
        // To avoid any harm, we are minimalistic here: If a shadow can be found, it is used "as is". No updates here.
        // If it cannot be found, it is created. We will skip kind/intent/tag determination.
        // Most probably these would not be correct anyway.
        shadowedObject = acquireRepoShadowInEmergency(result);
        return;
    }
    PrismObject<ShadowType> repoShadow = acquireRepoShadow(result);
    try {
        // This determines the definitions exactly. Now the repo shadow should have proper kind/intent.
        ProvisioningContext preciseCtx = ictx.localBeans.shadowCaretaker.applyAttributesDefinition(ictx.ctx, repoShadow);
        ictx.localBeans.shadowCaretaker.updateShadowState(preciseCtx, repoShadow);
        PrismObject<ShadowType> updatedRepoShadow = updateRepoShadow(preciseCtx, repoShadow, result);
        shadowedObject = createShadowedObject(preciseCtx, updatedRepoShadow, result);
    } catch (Exception e) {
        // No need to log stack trace now. It will be logged at the place where the exception is processed.
        LOGGER.error("Couldn't initialize {}. Continuing with previously acquired repo shadow: {}. Error: {}", resourceObject, repoShadow, getClassWithMessage(e));
        shadowedObject = repoShadow;
        throw e;
    }
}
Also used : ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) NotApplicableException(com.evolveum.midpoint.provisioning.impl.shadows.sync.NotApplicableException)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)7 Task (com.evolveum.midpoint.task.api.Task)6 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 QName (javax.xml.namespace.QName)5 SystemException (com.evolveum.midpoint.util.exception.SystemException)4 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)3 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)3 Trace (com.evolveum.midpoint.util.logging.Trace)3 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)3 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)3 CredentialsCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType)3 Collection (java.util.Collection)3 List (java.util.List)3 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)2