Search in sources :

Example 21 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class ReindexResultHandler method handleObject.

@Override
protected boolean handleObject(PrismObject<ObjectType> object, Task workerTask, OperationResult parentResult) throws CommonException {
    OperationResult result = parentResult.createMinorSubresult(CLASS_DOT + "handleObject");
    repositoryService.modifyObject(object.asObjectable().getClass(), object.getOid(), new ArrayList<ItemDelta>(), RepoModifyOptions.createExecuteIfNoChanges(), result);
    result.computeStatusIfUnknown();
    return true;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 22 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class ChangeExecutor method executeAddition.

private <T extends ObjectType, F extends ObjectType> void executeAddition(ObjectDelta<T> change, final LensContext<F> context, LensElementContext<T> objectContext, ModelExecuteOptions options, ResourceType resource, Task task, OperationResult result) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    PrismObject<T> objectToAdd = change.getObjectToAdd();
    if (change.getModifications() != null) {
        for (ItemDelta delta : change.getModifications()) {
            delta.applyTo(objectToAdd);
        }
        change.getModifications().clear();
    }
    OwnerResolver ownerResolver = createOwnerResolver(context, task, result);
    try {
        securityEnforcer.authorize(ModelAuthorizationAction.ADD.getUrl(), AuthorizationPhaseType.EXECUTION, objectToAdd, null, null, ownerResolver, result);
        T objectTypeToAdd = objectToAdd.asObjectable();
        metadataManager.applyMetadataAdd(context, objectToAdd, clock.currentTimeXMLGregorianCalendar(), task, result);
        if (options == null && context != null) {
            options = context.getOptions();
        }
        String oid;
        if (objectTypeToAdd instanceof TaskType) {
            oid = addTask((TaskType) objectTypeToAdd, result);
        } else if (objectTypeToAdd instanceof NodeType) {
            throw new UnsupportedOperationException("NodeType cannot be added using model interface");
        } else if (ObjectTypes.isManagedByProvisioning(objectTypeToAdd)) {
            ProvisioningOperationOptions provisioningOptions = getProvisioningOptions(context, options);
            oid = addProvisioningObject(objectToAdd, context, objectContext, provisioningOptions, resource, task, result);
            if (oid == null) {
                throw new SystemException("Provisioning addObject returned null OID while adding " + objectToAdd);
            }
            result.addReturn("createdAccountOid", oid);
        } else {
            FocusConstraintsChecker.clearCacheFor(objectToAdd.asObjectable().getName());
            RepoAddOptions addOpt = new RepoAddOptions();
            if (ModelExecuteOptions.isOverwrite(options)) {
                addOpt.setOverwrite(true);
            }
            if (ModelExecuteOptions.isNoCrypt(options)) {
                addOpt.setAllowUnencryptedValues(true);
            }
            oid = cacheRepositoryService.addObject(objectToAdd, addOpt, result);
            if (oid == null) {
                throw new SystemException("Repository addObject returned null OID while adding " + objectToAdd);
            }
        }
        change.setOid(oid);
        task.recordObjectActionExecuted(objectToAdd, objectToAdd.getCompileTimeClass(), oid, ChangeType.ADD, context.getChannel(), null);
    } catch (Throwable t) {
        task.recordObjectActionExecuted(objectToAdd, objectToAdd.getCompileTimeClass(), null, ChangeType.ADD, context.getChannel(), t);
        throw t;
    }
}
Also used : OwnerResolver(com.evolveum.midpoint.security.api.OwnerResolver) ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) RepoAddOptions(com.evolveum.midpoint.repo.api.RepoAddOptions)

Example 23 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class PageAssignmentsList method handleModifyAssignmentDelta.

private void handleModifyAssignmentDelta(AssignmentEditorDto assDto, PrismContainerDefinition assignmentDef, PrismContainerValue newValue, ObjectDelta<UserType> focusDelta) throws SchemaException {
    LOGGER.debug("Handling modified assignment '{}', computing delta.", new Object[] { assDto.getName() });
    PrismValue oldValue = assDto.getOldValue();
    Collection<? extends ItemDelta> deltas = oldValue.diff(newValue);
    for (ItemDelta delta : deltas) {
        ItemPath deltaPath = delta.getPath().rest();
        ItemDefinition deltaDef = assignmentDef.findItemDefinition(deltaPath);
        delta.setParentPath(WebComponentUtil.joinPath(oldValue.getPath(), delta.getPath().allExceptLast()));
        delta.applyDefinition(deltaDef);
        focusDelta.addModification(delta);
    }
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 24 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class ShadowIntegrityCheckResultHandler method deleteShadows.

// shadowsToDelete do not contain 'already deleted shadows'
private void deleteShadows(DuplicateShadowsTreatmentInstruction instruction, StringBuilder sb, Task task, OperationResult result) {
    LOGGER.trace("Going to delete shadows:\n{}", instruction);
    if (instruction == null || instruction.getShadowsToDelete() == null) {
        return;
    }
    Collection<PrismObject<ShadowType>> shadowsToDelete = instruction.getShadowsToDelete();
    String shadowOidToReplaceDeleted = instruction.getShadowOidToReplaceDeletedOnes();
    for (PrismObject<ShadowType> shadowToDelete : shadowsToDelete) {
        LOGGER.info("Deleting redundant shadow{} {}", skippedForDryRun(), ObjectTypeUtil.toShortString(shadowToDelete));
        sb.append("   --> deleted redundant shadow").append(skippedForDryRun()).append(" ").append(ObjectTypeUtil.toShortString(shadowToDelete)).append("\n");
        String oid = shadowToDelete.getOid();
        List<PrismObject<FocusType>> owners;
        if (checkOwners) {
            owners = (List) shadowToDelete.getUserData(KEY_OWNERS);
        } else {
            owners = searchOwners(shadowToDelete, result);
        }
        if (!dryRun) {
            try {
                repositoryService.deleteObject(ShadowType.class, oid, result);
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, null);
                duplicateShadowsDeleted.add(oid);
            } catch (ObjectNotFoundException e) {
                // suspicious, but not a big deal
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
                LoggingUtils.logExceptionAsWarning(LOGGER, "Shadow {} couldn't be deleted, because it does not exist anymore", e, ObjectTypeUtil.toShortString(shadowToDelete));
                continue;
            } catch (RuntimeException e) {
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
                LoggingUtils.logUnexpectedException(LOGGER, "Shadow {} couldn't be deleted because of an unexpected exception", e, ObjectTypeUtil.toShortString(shadowToDelete));
                continue;
            }
        }
        if (owners == null || owners.isEmpty()) {
            continue;
        }
        for (PrismObject owner : owners) {
            List<ItemDelta> modifications = new ArrayList<>(2);
            ReferenceDelta deleteDelta = ReferenceDelta.createModificationDelete(FocusType.F_LINK_REF, owner.getDefinition(), new PrismReferenceValue(oid, ShadowType.COMPLEX_TYPE));
            modifications.add(deleteDelta);
            if (shadowOidToReplaceDeleted != null) {
                ReferenceDelta addDelta = ReferenceDelta.createModificationAdd(FocusType.F_LINK_REF, owner.getDefinition(), new PrismReferenceValue(shadowOidToReplaceDeleted, ShadowType.COMPLEX_TYPE));
                modifications.add(addDelta);
            }
            LOGGER.info("Executing modify delta{} for owner {}:\n{}", skippedForDryRun(), ObjectTypeUtil.toShortString(owner), DebugUtil.debugDump(modifications));
            if (!dryRun) {
                try {
                    repositoryService.modifyObject((Class) owner.getClass(), owner.getOid(), modifications, result);
                    task.recordObjectActionExecuted(owner, ChangeType.MODIFY, null);
                } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException | RuntimeException e) {
                    task.recordObjectActionExecuted(owner, ChangeType.MODIFY, e);
                    LoggingUtils.logUnexpectedException(LOGGER, "Focal object {} (owner of {}) couldn't be updated", e, ObjectTypeUtil.toShortString(owner), ObjectTypeUtil.toShortString(shadowToDelete));
                }
            }
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 25 with ItemDelta

use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.

the class ObjectMerger method computeItemDeltas.

private <O extends ObjectType> void computeItemDeltas(final ObjectDelta<O> leftObjectDelta, final PrismObject<O> objectLeft, final PrismObject<O> objectRight, final List<ItemPath> processedPaths, MergeConfigurationType mergeConfiguration, final String mergeConfigurationName, final Task task, final OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException {
    for (ItemRefMergeConfigurationType itemMergeConfig : mergeConfiguration.getItem()) {
        ItemPath itemPath = itemMergeConfig.getRef().getItemPath();
        processedPaths.add(itemPath);
        ItemDelta itemDelta = mergeItem(objectLeft, objectRight, mergeConfigurationName, itemMergeConfig, itemPath, task, result);
        LOGGER.trace("Item {} delta: {}", itemPath, itemDelta);
        if (itemDelta != null && !itemDelta.isEmpty()) {
            leftObjectDelta.addModification(itemDelta);
        }
    }
}
Also used : ItemRefMergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ItemRefMergeConfigurationType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)185 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)87 Test (org.testng.annotations.Test)66 ArrayList (java.util.ArrayList)64 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)56 Task (com.evolveum.midpoint.task.api.Task)40 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)33 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)30 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)26 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)21 QName (javax.xml.namespace.QName)21 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)20 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)19 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)15 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)14 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)14 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)12