Search in sources :

Example 11 with ContainerDelta

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

the class PageRole method prepareObjectForAdd.

@Override
protected void prepareObjectForAdd(PrismObject<RoleType> focus) throws SchemaException {
    // TODO policyConstraints
    super.prepareObjectForAdd(focus);
    getObjectWrapper().getObjectOld().findOrCreateContainer(RoleType.F_POLICY_CONSTRAINTS);
    ObjectDelta<RoleType> delta = getObjectWrapper().getObjectOld().diff(getObjectWrapper().getObject());
    ContainerDelta<PolicyConstraintsType> policyConstraintsDelta = delta.findContainerDelta(new ItemPath(RoleType.F_POLICY_CONSTRAINTS));
    if (policyConstraintsDelta != null) {
        policyConstraintsDelta.applyTo(focus);
        return;
    }
    ContainerDelta maxAssignes = delta.findContainerDelta(new ItemPath(RoleType.F_POLICY_CONSTRAINTS, PolicyConstraintsType.F_MAX_ASSIGNEES));
    if (maxAssignes != null) {
        maxAssignes.applyTo(focus);
    }
    ContainerDelta minAssignes = delta.findContainerDelta(new ItemPath(RoleType.F_POLICY_CONSTRAINTS, PolicyConstraintsType.F_MIN_ASSIGNEES));
    if (minAssignes != null) {
        minAssignes.applyTo(focus);
    }
}
Also used : PolicyConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 12 with ContainerDelta

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

the class PageRole method prepareObjectDeltaForModify.

@Override
protected void prepareObjectDeltaForModify(ObjectDelta<RoleType> focusDelta) throws SchemaException {
    super.prepareObjectDeltaForModify(focusDelta);
    ObjectDelta<RoleType> delta = getObjectWrapper().getObjectOld().diff(getObjectWrapper().getObject());
    ContainerDelta<PolicyConstraintsType> policyConstraintsDelta = delta.findContainerDelta(new ItemPath(RoleType.F_POLICY_CONSTRAINTS));
    if (policyConstraintsDelta != null) {
        focusDelta.addModification(policyConstraintsDelta);
        return;
    }
    ContainerDelta maxAssignes = delta.findContainerDelta(new ItemPath(RoleType.F_POLICY_CONSTRAINTS, PolicyConstraintsType.F_MAX_ASSIGNEES));
    if (maxAssignes != null) {
        focusDelta.addModification(maxAssignes);
    }
    ContainerDelta minAssignes = delta.findContainerDelta(new ItemPath(RoleType.F_POLICY_CONSTRAINTS, PolicyConstraintsType.F_MIN_ASSIGNEES));
    if (minAssignes != null) {
        focusDelta.addModification(minAssignes);
    }
}
Also used : PolicyConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 13 with ContainerDelta

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

the class PageRequestRole method handleAssignmentDeltas.

protected ContainerDelta handleAssignmentDeltas(ObjectDelta<UserType> focusDelta, List<AssignmentEditorDto> assignments, PrismContainerDefinition def) throws SchemaException {
    ContainerDelta assDelta = new ContainerDelta(new ItemPath(), def.getName(), def, getPrismContext());
    for (AssignmentEditorDto assDto : assignments) {
        PrismContainerValue newValue = assDto.getNewValue(getPrismContext());
        switch(assDto.getStatus()) {
            case ADD:
                newValue.applyDefinition(def, false);
                assDelta.addValueToAdd(newValue.clone());
                break;
            case DELETE:
                PrismContainerValue oldValue = assDto.getOldValue();
                oldValue.applyDefinition(def);
                assDelta.addValueToDelete(oldValue.clone());
                break;
            case MODIFY:
                if (!assDto.isModified(getPrismContext())) {
                    LOGGER.trace("Assignment '{}' not modified.", new Object[] { assDto.getName() });
                    continue;
                }
                handleModifyAssignmentDelta(assDto, def, newValue, focusDelta);
                break;
            default:
                warn(getString("pageAdminUser.message.illegalAssignmentState", assDto.getStatus()));
        }
    }
    if (!assDelta.isEmpty()) {
        assDelta = focusDelta.addModification(assDelta);
    }
    return assDelta;
}
Also used : AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 14 with ContainerDelta

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

the class AssignmentTablePanel method handleAssignmentDeltas.

public ContainerDelta handleAssignmentDeltas(ObjectDelta<T> userDelta, PrismContainerDefinition def, QName assignmentPath) throws SchemaException {
    ContainerDelta assDelta = new ContainerDelta(new ItemPath(), assignmentPath, def, // hoping that def contains a prism
    def.getPrismContext());
    // context!
    // PrismObject<OrgType> org =
    // (PrismObject<OrgType>)getModel().getObject().getAssignmentParent();
    // PrismObjectDefinition orgDef = org.getDefinition();
    // PrismContainerDefinition assignmentDef =
    // def.findContainerDefinition(assignmentPath);
    List<AssignmentEditorDto> assignments = getAssignmentModel().getObject();
    for (AssignmentEditorDto assDto : assignments) {
        PrismContainerValue newValue = assDto.getNewValue(getPageBase().getPrismContext());
        switch(assDto.getStatus()) {
            case ADD:
                newValue.applyDefinition(def, false);
                assDelta.addValueToAdd(newValue.clone());
                break;
            case DELETE:
                PrismContainerValue oldValue = assDto.getOldValue();
                oldValue.applyDefinition(def);
                assDelta.addValueToDelete(oldValue.clone());
                break;
            case MODIFY:
                if (!assDto.isModified(getPageBase().getPrismContext())) {
                    LOGGER.trace("Assignment '{}' not modified.", new Object[] { assDto.getName() });
                    continue;
                }
                handleModifyAssignmentDelta(assDto, def, newValue, userDelta);
                break;
            default:
                warn(getString("pageUser.message.illegalAssignmentState", assDto.getStatus()));
        }
    }
    if (!assDelta.isEmpty()) {
        assDelta = userDelta.addModification(assDelta);
    }
    // todo remove this block [lazyman] after model is updated - it has to
    // remove resource from accountConstruction
    Collection<PrismContainerValue> values = assDelta.getValues(PrismContainerValue.class);
    for (PrismContainerValue value : values) {
        AssignmentType ass = new AssignmentType();
        ass.setupContainerValue(value);
        removeResourceFromAccConstruction(ass);
    }
    return assDelta;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with ContainerDelta

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

the class LookupTableHelper method updateLookupTableData.

public void updateLookupTableData(Session session, String tableOid, Collection<? extends ItemDelta> modifications) throws SchemaException {
    if (modifications.isEmpty()) {
        return;
    }
    for (ItemDelta delta : modifications) {
        if (delta.getPath().size() == 1) {
            // whole row add/delete/replace
            if (!(delta instanceof ContainerDelta)) {
                throw new IllegalStateException("Wrong table delta sneaked into updateLookupTableData: class=" + delta.getClass() + ", path=" + delta.getPath());
            }
            // one "table" container modification
            ContainerDelta containerDelta = (ContainerDelta) delta;
            if (containerDelta.getValuesToDelete() != null) {
                // todo do 'bulk' delete like delete from ... where oid=? and id in (...)
                for (PrismContainerValue<LookupTableRowType> value : (Collection<PrismContainerValue>) containerDelta.getValuesToDelete()) {
                    if (value.getId() != null) {
                        deleteRowById(session, tableOid, value.getId());
                    } else if (value.asContainerable().getKey() != null) {
                        deleteRowByKey(session, tableOid, value.asContainerable().getKey());
                    } else {
                    // ignore (or throw an exception?)
                    }
                }
            }
            if (containerDelta.getValuesToAdd() != null) {
                int currentId = generalHelper.findLastIdInRepo(session, tableOid, "get.lookupTableLastId") + 1;
                addLookupTableRows(session, tableOid, containerDelta.getValuesToAdd(), currentId, true);
            }
            if (containerDelta.getValuesToReplace() != null) {
                deleteLookupTableRows(session, tableOid);
                addLookupTableRows(session, tableOid, containerDelta.getValuesToReplace(), 1, false);
            }
        } else if (delta.getPath().size() == 3) {
            // row segment modification (structure is already checked)
            List<ItemPathSegment> segments = delta.getPath().getSegments();
            Long rowId = ((IdItemPathSegment) segments.get(1)).getId();
            QName name = ((NameItemPathSegment) segments.get(2)).getName();
            RLookupTableRow row = (RLookupTableRow) session.get(RLookupTableRow.class, new RContainerId(RUtil.toInteger(rowId), tableOid));
            LookupTableRowType rowType = row.toJAXB();
            delta.setParentPath(ItemPath.EMPTY_PATH);
            delta.applyTo(rowType.asPrismContainerValue());
            if (!QNameUtil.match(name, LookupTableRowType.F_LAST_CHANGE_TIMESTAMP)) {
                // in order to get filled in via toRepo call below
                rowType.setLastChangeTimestamp(null);
            }
            RLookupTableRow rowUpdated = RLookupTableRow.toRepo(tableOid, rowType);
            session.merge(rowUpdated);
        }
    }
}
Also used : RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) QName(javax.xml.namespace.QName) Collection(java.util.Collection) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ArrayList(java.util.ArrayList) List(java.util.List) RContainerId(com.evolveum.midpoint.repo.sql.data.common.id.RContainerId) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)

Aggregations

ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)19 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)5 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 Collection (java.util.Collection)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismReference (com.evolveum.midpoint.prism.PrismReference)2 Trace (com.evolveum.midpoint.util.logging.Trace)2 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)2 PolicyConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType)2 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)2