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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
}
Aggregations