Search in sources :

Example 11 with ItemDelta

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

the class ProjectionValuesProcessor method cleanupContext.

/**
	 * Remove the intermediate results of values processing such as secondary deltas.
	 */
private void cleanupContext(LensProjectionContext accountContext) throws SchemaException {
    // We must NOT clean up activation computation. This has happened before, it will not happen again
    // and it does not depend on iteration
    ObjectDelta<ShadowType> secondaryDelta = accountContext.getSecondaryDelta();
    if (secondaryDelta != null) {
        Collection<? extends ItemDelta> modifications = secondaryDelta.getModifications();
        if (modifications != null) {
            Iterator<? extends ItemDelta> iterator = modifications.iterator();
            while (iterator.hasNext()) {
                ItemDelta modification = iterator.next();
                if (!new ItemPath(FocusType.F_ACTIVATION).equivalent(modification.getParentPath())) {
                    iterator.remove();
                }
            }
        }
        if (secondaryDelta.isEmpty()) {
            accountContext.setSecondaryDelta(null);
        }
    }
    accountContext.clearIntermediateResults();
    accountContext.recompute();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 12 with ItemDelta

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

the class ReconciliationProcessor method recordDelta.

private <T> void recordDelta(ValueMatcher<T> valueMatcher, LensProjectionContext projCtx, ItemPath parentPath, PrismPropertyDefinition<T> attrDef, ModificationType changeType, T value, ObjectType originObject, String reason) throws SchemaException {
    ItemDelta existingDelta = null;
    if (projCtx.getSecondaryDelta() != null) {
        existingDelta = projCtx.getSecondaryDelta().findItemDelta(new ItemPath(parentPath, attrDef.getName()));
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Reconciliation will {} value of attribute {}: {} because {}", changeType, PrettyPrinter.prettyPrint(attrDef.getName()), value, reason);
    }
    PropertyDelta<T> attrDelta = new PropertyDelta<>(parentPath, attrDef.getName(), attrDef, prismContext);
    PrismPropertyValue<T> pValue = new PrismPropertyValue<>(value, OriginType.RECONCILIATION, originObject);
    if (changeType == ModificationType.ADD) {
        attrDelta.addValueToAdd(pValue);
    } else if (changeType == ModificationType.DELETE) {
        if (!isToBeDeleted(existingDelta, valueMatcher, value)) {
            attrDelta.addValueToDelete(pValue);
        }
    } else if (changeType == ModificationType.REPLACE) {
        attrDelta.setValueToReplace(pValue);
    } else {
        throw new IllegalArgumentException("Unknown change type " + changeType);
    }
    projCtx.swallowToSecondaryDelta(attrDelta);
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 13 with ItemDelta

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

the class FocusConstraintsChecker method clearCacheForDelta.

public static void clearCacheForDelta(Collection<? extends ItemDelta> modifications) {
    if (modifications == null) {
        return;
    }
    for (ItemDelta itemDelta : modifications) {
        if (new ItemPath(ObjectType.F_NAME).equivalent(itemDelta.getPath())) {
            // these may present a conflict
            clearCacheForValues(itemDelta.getValuesToAdd());
            // so do these
            clearCacheForValues(itemDelta.getValuesToReplace());
        }
    }
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 14 with ItemDelta

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

the class PageTaskController method savePerformed.

void savePerformed(AjaxRequestTarget target) {
    LOGGER.debug("Saving new task.");
    OperationResult result = new OperationResult(PageTaskEdit.OPERATION_SAVE_TASK);
    TaskDto dto = parentPage.getTaskDto();
    Task operationTask = parentPage.createSimpleTask(PageTaskEdit.OPERATION_SAVE_TASK);
    try {
        List<ItemDelta<?, ?>> itemDeltas = getDeltasToExecute(dto);
        ObjectDelta<TaskType> delta = ObjectDelta.createModifyDelta(dto.getOid(), itemDeltas, TaskType.class, parentPage.getPrismContext());
        final Collection<ObjectDelta<? extends ObjectType>> deltas = Collections.<ObjectDelta<? extends ObjectType>>singletonList(delta);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Saving task modifications:\n{}", DebugUtil.debugDump(deltas));
        }
        parentPage.getModelService().executeChanges(deltas, null, operationTask, result);
        result.recomputeStatus();
    } catch (Exception ex) {
        result.recomputeStatus();
        result.recordFatalError("Couldn't save task.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save task modifications", ex);
    }
    afterSave(target, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) TaskDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskDto) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 15 with ItemDelta

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

the class PageTaskController method getDeltasToExecute.

private List<ItemDelta<?, ?>> getDeltasToExecute(TaskDto dto) throws SchemaException {
    List<ItemDelta<?, ?>> rv = new ArrayList<>();
    TaskEditableState orig = dto.getOriginalEditableState();
    TaskEditableState curr = dto.getCurrentEditableState();
    if (!StringUtils.equals(orig.getName(), curr.getName())) {
        String name = curr.getName() != null ? curr.getName() : "";
        addDelta(rv, TaskType.F_NAME, new PolyString(name));
    }
    if (!StringUtils.equals(orig.getDescription(), curr.getDescription())) {
        addDelta(rv, TaskType.F_DESCRIPTION, curr.getDescription());
    }
    ScheduleType origSchedule = orig.getScheduleType();
    ScheduleType currSchedule = curr.getScheduleType();
    if (!origSchedule.equals(currSchedule)) {
        if (dto.getTaskType().getSchedule() != null) {
            currSchedule.setLatestFinishTime(dto.getTaskType().getSchedule().getLatestFinishTime());
        }
        addDelta(rv, TaskType.F_SCHEDULE, currSchedule);
    }
    if (orig.isRecurring() != curr.isRecurring()) {
        addDelta(rv, TaskType.F_RECURRENCE, curr.isRecurring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
    }
    if (orig.isBound() != curr.isBound()) {
        addDelta(rv, TaskType.F_BINDING, curr.isBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);
    }
    if (orig.getThreadStopActionType() != curr.getThreadStopActionType()) {
        addDelta(rv, TaskType.F_THREAD_STOP_ACTION, curr.getThreadStopActionType());
    }
    if (!ObjectUtils.equals(orig.getWorkerThreads(), curr.getWorkerThreads())) {
        SchemaRegistry registry = parentPage.getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORKER_THREADS);
        rv.add(DeltaBuilder.deltaFor(TaskType.class, parentPage.getPrismContext()).item(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_WORKER_THREADS), def).replace(curr.getWorkerThreads()).asItemDelta());
    }
    rv.addAll(dto.getHandlerDto().getDeltasToExecute(orig.getHandlerSpecificState(), curr.getHandlerSpecificState(), parentPage.getPrismContext()));
    return rv;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) TaskEditableState(com.evolveum.midpoint.web.page.admin.server.dto.TaskEditableState) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) 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