use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.
the class ItemDeltaItem method findIdi.
public <IV extends PrismValue, ID extends ItemDefinition> ItemDeltaItem<IV, ID> findIdi(ItemPath path) {
if (path.isEmpty()) {
return (ItemDeltaItem<IV, ID>) this;
}
Item<IV, ID> subItemOld = null;
ItemPath subResidualPath = null;
ItemPath newResolvePath = resolvePath.subPath(path);
if (itemOld != null) {
PartiallyResolvedItem<IV, ID> partialItemOld = itemOld.findPartial(path);
if (partialItemOld != null) {
subItemOld = partialItemOld.getItem();
subResidualPath = partialItemOld.getResidualPath();
}
}
Item<IV, ID> subItemNew = null;
if (itemNew != null) {
PartiallyResolvedItem<IV, ID> partialItemNew = itemNew.findPartial(path);
if (partialItemNew != null) {
subItemNew = partialItemNew.getItem();
if (subResidualPath == null) {
subResidualPath = partialItemNew.getResidualPath();
}
}
}
ItemDelta<IV, ID> subDelta = null;
if (delta != null) {
if (delta instanceof ContainerDelta<?>) {
subDelta = (ItemDelta<IV, ID>) ((ContainerDelta<?>) delta).getSubDelta(path);
} else {
CompareResult compareComplex = delta.getPath().compareComplex(newResolvePath);
if (compareComplex == CompareResult.EQUIVALENT || compareComplex == CompareResult.SUBPATH) {
subDelta = (ItemDelta<IV, ID>) delta;
}
}
}
ItemDeltaItem<IV, ID> subIdi = new ItemDeltaItem<IV, ID>(subItemOld, subDelta, subItemNew);
subIdi.setResidualPath(subResidualPath);
subIdi.resolvePath = newResolvePath;
if (subItemDeltas != null) {
Item<IV, ID> subAnyItem = subIdi.getAnyItem();
Collection<ItemDelta<?, ?>> subSubItemDeltas = new ArrayList<>();
for (ItemDelta<?, ?> subItemDelta : subItemDeltas) {
CompareResult compareComplex = subItemDelta.getPath().compareComplex(subAnyItem.getPath());
if (compareComplex == CompareResult.EQUIVALENT || compareComplex == CompareResult.SUBPATH) {
subSubItemDeltas.add(subItemDelta);
}
}
if (!subSubItemDeltas.isEmpty()) {
// Niceness optimization
if (subDelta == null && subSubItemDeltas.size() == 1) {
ItemDelta<?, ?> subSubItemDelta = subSubItemDeltas.iterator().next();
if (subSubItemDelta.isApplicableTo(subAnyItem)) {
subDelta = (ItemDelta<IV, ID>) subSubItemDelta;
subIdi.setDelta(subDelta);
} else {
subIdi.setSubItemDeltas(subSubItemDeltas);
}
} else {
subIdi.setSubItemDeltas(subSubItemDeltas);
}
}
}
return subIdi;
}
use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.
the class AddAssignmentAspect method assignmentToDelta.
// creates an ObjectDelta that will be executed after successful approval of the given assignment
@SuppressWarnings("unchecked")
private ObjectDelta<? extends FocusType> assignmentToDelta(ModelContext<?> modelContext, AssignmentType assignmentType, String objectOid) {
PrismObject<FocusType> focus = (PrismObject<FocusType>) modelContext.getFocusContext().getObjectNew();
PrismContainerDefinition<AssignmentType> prismContainerDefinition = focus.getDefinition().findContainerDefinition(FocusType.F_ASSIGNMENT);
ItemDelta<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> addRoleDelta = new ContainerDelta<>(new ItemPath(), FocusType.F_ASSIGNMENT, prismContainerDefinition, prismContext);
PrismContainerValue<AssignmentType> assignmentValue = assignmentType.asPrismContainerValue().clone();
addRoleDelta.addValueToAdd(assignmentValue);
Class focusClass = primaryChangeAspectHelper.getFocusClass(modelContext);
return ObjectDelta.createModifyDelta(objectOid, addRoleDelta, focusClass, modelContext.getPrismContext());
}
use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.
the class ResourceObjectConverter method executeEntitlementChangesModify.
private PrismObject<ShadowType> executeEntitlementChangesModify(ProvisioningContext ctx, PrismObject<ShadowType> subjectShadowBefore, PrismObject<ShadowType> subjectShadowAfter, OperationProvisioningScriptsType scripts, Collection<? extends ItemDelta> subjectDeltas, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ConfigurationException, ObjectAlreadyExistsException, ExpressionEvaluationException {
Map<ResourceObjectDiscriminator, ResourceObjectOperations> roMap = new HashMap<>();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("executeEntitlementChangesModify, old shadow:\n{}", subjectShadowBefore.debugDump(1));
}
for (ItemDelta subjectDelta : subjectDeltas) {
ItemPath subjectItemPath = subjectDelta.getPath();
if (new ItemPath(ShadowType.F_ASSOCIATION).equivalent(subjectItemPath)) {
ContainerDelta<ShadowAssociationType> containerDelta = (ContainerDelta<ShadowAssociationType>) subjectDelta;
subjectShadowAfter = entitlementConverter.collectEntitlementsAsObjectOperation(ctx, roMap, containerDelta, subjectShadowBefore, subjectShadowAfter, parentResult);
} else {
ContainerDelta<ShadowAssociationType> associationDelta = ContainerDelta.createDelta(ShadowType.F_ASSOCIATION, subjectShadowBefore.getDefinition());
PrismContainer<ShadowAssociationType> associationContainer = subjectShadowBefore.findContainer(ShadowType.F_ASSOCIATION);
if (associationContainer == null || associationContainer.isEmpty()) {
LOGGER.trace("No shadow association container in old shadow. Skipping processing entitlements change for {}.", subjectItemPath);
continue;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing association container in old shadow for {}:\n{}", subjectItemPath, associationContainer.debugDump(1));
}
// For these that do not, it is harmful, so it must be skipped.
for (PrismContainerValue<ShadowAssociationType> associationValue : associationContainer.getValues()) {
QName associationName = associationValue.asContainerable().getName();
if (associationName == null) {
throw new IllegalStateException("No association name in " + associationValue);
}
RefinedAssociationDefinition associationDefinition = ctx.getObjectClassDefinition().findAssociationDefinition(associationName);
if (associationDefinition == null) {
throw new IllegalStateException("No association definition for " + associationValue);
}
if (!associationDefinition.requiresExplicitReferentialIntegrity()) {
continue;
}
QName valueAttributeName = associationDefinition.getResourceObjectAssociationType().getValueAttribute();
if (!ShadowUtil.matchesAttribute(subjectItemPath, valueAttributeName)) {
continue;
}
LOGGER.trace("Processing association {} on rename", associationName);
associationDelta.addValuesToDelete(associationValue.clone());
associationDelta.addValuesToAdd(associationValue.clone());
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Resulting association delta for {}:\n{}", subjectItemPath, associationDelta.debugDump(1));
}
if (!associationDelta.isEmpty()) {
entitlementConverter.collectEntitlementsAsObjectOperation(ctx, roMap, associationDelta, subjectShadowBefore, subjectShadowAfter, parentResult);
}
// shadowAfter.findOrCreateContainer(ShadowType.F_ASSOCIATION).addAll((Collection) association.getClonedValues());
// entitlementConverter.processEntitlementsAdd(resource, shadowAfter, objectClassDefinition);
}
}
executeEntitlements(ctx, roMap, parentResult);
return subjectShadowAfter;
}
use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.
the class ResourceObjectConverter method collectAttributeAndEntitlementChanges.
private void collectAttributeAndEntitlementChanges(ProvisioningContext ctx, Collection<? extends ItemDelta> objectChange, Collection<Operation> operations, PrismObject<ShadowType> shadow, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
if (operations == null) {
operations = new ArrayList<Operation>();
}
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
for (ItemDelta itemDelta : objectChange) {
if (isAttributeDelta(itemDelta) || SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
if (itemDelta instanceof PropertyDelta) {
PropertyModificationOperation attributeModification = new PropertyModificationOperation((PropertyDelta) itemDelta);
RefinedAttributeDefinition<Object> attrDef = objectClassDefinition.findAttributeDefinition(itemDelta.getElementName());
if (attrDef != null) {
attributeModification.setMatchingRuleQName(attrDef.getMatchingRuleQName());
if (itemDelta.getDefinition() == null) {
itemDelta.setDefinition(attrDef);
}
}
operations.add(attributeModification);
} else if (itemDelta instanceof ContainerDelta) {
// - it is processed earlier
continue;
} else {
throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
}
} else if (SchemaConstants.PATH_ACTIVATION.equivalent(itemDelta.getParentPath())) {
Collection<Operation> activationOperations = determineActivationChange(ctx, shadow.asObjectable(), objectChange, result);
if (activationOperations != null) {
operations.addAll(activationOperations);
}
} else if (new ItemPath(ShadowType.F_ASSOCIATION).equivalent(itemDelta.getPath())) {
if (itemDelta instanceof ContainerDelta) {
entitlementConverter.collectEntitlementChange(ctx, (ContainerDelta<ShadowAssociationType>) itemDelta, operations);
} else {
throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
}
} else if (new ItemPath(ShadowType.F_AUXILIARY_OBJECT_CLASS).equivalent(itemDelta.getPath())) {
if (itemDelta instanceof PropertyDelta) {
PropertyModificationOperation attributeModification = new PropertyModificationOperation((PropertyDelta) itemDelta);
operations.add(attributeModification);
} else {
throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
}
} else {
LOGGER.trace("Skip converting item delta: {}. It's not resource object change, but it is shadow change.", itemDelta);
}
}
}
use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createReplaceAccountConstructionUserDelta.
protected ObjectDelta<UserType> createReplaceAccountConstructionUserDelta(String userOid, Long id, ConstructionType newValue) throws SchemaException {
PrismContainerDefinition pcd = getAssignmentDefinition().findContainerDefinition(AssignmentType.F_CONSTRUCTION);
ContainerDelta<ConstructionType> acDelta = new ContainerDelta<ConstructionType>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)), pcd, prismContext);
// ContainerDelta.createDelta(prismContext, ConstructionType.class, AssignmentType.F_CONSTRUCTION);
acDelta.setValueToReplace(newValue.asPrismContainerValue());
// PropertyDelta.createModificationReplaceProperty(
// new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)),
// ppd,
// newValue);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add(acDelta);
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
return userDelta;
}
Aggregations