use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestDeltaConverter method testRefWithObject.
@Test
public void testRefWithObject() throws SchemaException, IOException, JAXBException {
System.out.println("===[ testRefWithObject ]====");
ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "user-modify-add-account.xml"), ObjectModificationType.COMPLEX_TYPE);
ObjectDelta<UserType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, UserType.class, getPrismContext());
System.out.println("delta: " + objectDelta.debugDump());
assertNotNull("No object delta", objectDelta);
objectDelta.checkConsistence();
assertEquals("Wrong OID", "c0c010c0-d34d-b33f-f00d-111111111111", objectDelta.getOid());
ReferenceDelta accoutRefDelta = objectDelta.findReferenceModification(UserType.F_LINK_REF);
assertNotNull("No accountRef delta", accoutRefDelta);
Collection<PrismReferenceValue> valuesToAdd = accoutRefDelta.getValuesToAdd();
assertEquals("Wrong number of values to add", 1, valuesToAdd.size());
PrismReferenceValue accountRefVal = valuesToAdd.iterator().next();
assertNotNull("No object in accountRef value", accountRefVal.getObject());
objectDelta.assertDefinitions();
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestDeltaConverter method testModifyInducement.
@Test
public void testModifyInducement() throws Exception {
System.out.println("===[ testModifyInducement ]====");
ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "role-modify-inducement.xml"), ObjectModificationType.COMPLEX_TYPE);
// WHEN
ObjectDelta<RoleType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, RoleType.class, getPrismContext());
System.out.println("Delta:");
System.out.println(objectDelta.debugDump());
// THEN
assertNotNull("No object delta", objectDelta);
objectDelta.checkConsistence();
assertEquals("Wrong OID", "00000000-8888-6666-0000-100000000005", objectDelta.getOid());
ReferenceDelta targetRefDelta = objectDelta.findReferenceModification(new ItemPath(new NameItemPathSegment(RoleType.F_INDUCEMENT), new IdItemPathSegment(5L), new NameItemPathSegment(AssignmentType.F_TARGET_REF)));
assertNotNull("No targetRef delta", targetRefDelta);
Collection<PrismReferenceValue> valuesToAdd = targetRefDelta.getValuesToAdd();
assertEquals("Wrong number of values to add", 1, valuesToAdd.size());
PrismReferenceValue targetRefVal = valuesToAdd.iterator().next();
assertNotNull("Null value in targetRef delta", targetRefVal);
assertEquals("wrong OID in targetRef", "12345678-d34d-b33f-f00d-987987987987", targetRefVal.getOid());
assertEquals("wrong target type in targetRef", RoleType.COMPLEX_TYPE, targetRefVal.getTargetType());
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class ResourceContentPanel method changeOwner.
private void changeOwner(ShadowType selected, AjaxRequestTarget target, FocusType ownerToChange, Operation operation) {
List<ShadowType> selectedShadow = getSelectedShadowsList(selected);
Collection<? extends ItemDelta> modifications = new ArrayList<>();
ReferenceDelta delta = null;
switch(operation) {
case REMOVE:
for (ShadowType shadow : selectedShadow) {
modifications = new ArrayList<>();
FocusType owner = loadShadowOwner(shadow.getOid());
if (owner != null) {
delta = ReferenceDelta.createModificationDelete(FocusType.F_LINK_REF, getFocusDefinition(), ObjectTypeUtil.createObjectRef(shadow).asReferenceValue());
((Collection) modifications).add(delta);
changeOwnerInternal(owner.getOid(), modifications, target);
}
}
break;
case MODIFY:
if (!isSatisfyConstraints(selectedShadow)) {
break;
}
ShadowType shadow = selectedShadow.iterator().next();
FocusType owner = loadShadowOwner(shadow.getOid());
if (owner != null) {
delta = ReferenceDelta.createModificationDelete(FocusType.F_LINK_REF, getFocusDefinition(), ObjectTypeUtil.createObjectRef(shadow).asReferenceValue());
((Collection) modifications).add(delta);
changeOwnerInternal(owner.getOid(), modifications, target);
}
modifications = new ArrayList<>();
delta = ReferenceDelta.createModificationAdd(FocusType.F_LINK_REF, getFocusDefinition(), ObjectTypeUtil.createObjectRef(shadow).asReferenceValue());
((Collection) modifications).add(delta);
changeOwnerInternal(ownerToChange.getOid(), modifications, target);
break;
}
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class OperationalDataManager method applyMetadataModify.
public <T extends ObjectType, F extends ObjectType> void applyMetadataModify(ObjectDelta<T> objectDelta, LensElementContext<T> objectContext, Class objectTypeClass, XMLGregorianCalendar now, Task task, LensContext<F> context, OperationResult result) throws SchemaException {
String channel = LensUtil.getChannel(context, task);
PrismObjectDefinition<T> def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(objectTypeClass);
ItemDelta.mergeAll(objectDelta.getModifications(), createModifyMetadataDeltas(context, new ItemPath(ObjectType.F_METADATA), def, now, task));
List<PrismReferenceValue> approverReferenceValues = new ArrayList<PrismReferenceValue>();
if (workflowManager != null) {
for (ObjectReferenceType approverRef : workflowManager.getApprovedBy(task, result)) {
approverReferenceValues.add(new PrismReferenceValue(approverRef.getOid()));
}
}
if (!approverReferenceValues.isEmpty()) {
ReferenceDelta refDelta = ReferenceDelta.createModificationReplace((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF)), def, approverReferenceValues);
((Collection) objectDelta.getModifications()).add(refDelta);
} else {
if (objectContext != null && objectContext.getObjectOld() != null) {
if (objectContext.getObjectOld().asObjectable().getMetadata() != null) {
List<ObjectReferenceType> existingModifyApproverRefs = objectContext.getObjectOld().asObjectable().getMetadata().getModifyApproverRef();
LOGGER.trace("Original values of MODIFY_APPROVER_REF: {}", existingModifyApproverRefs);
if (!existingModifyApproverRefs.isEmpty()) {
List<PrismReferenceValue> valuesToDelete = new ArrayList<PrismReferenceValue>();
for (ObjectReferenceType approverRef : objectContext.getObjectOld().asObjectable().getMetadata().getModifyApproverRef()) {
valuesToDelete.add(approverRef.asReferenceValue().clone());
}
ReferenceDelta refDelta = ReferenceDelta.createModificationDelete((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF)), def, valuesToDelete);
((Collection) objectDelta.getModifications()).add(refDelta);
}
}
}
}
if (FocusType.class.isAssignableFrom(objectTypeClass)) {
applyAssignmentMetadataDelta((LensContext) context, (ObjectDelta) objectDelta, now, task, result);
}
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta 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));
}
}
}
}
}
Aggregations