private <AH extends AssignmentHolderType> boolean pathMatches(ObjectDelta<?> delta, PrismObject<AH> objectOld, ItemPath path, boolean exactPathMatch) throws SchemaException { if (delta.isAdd()) { return delta.getObjectToAdd().containsItem(path, false); } else if (delta.isDelete()) { return objectOld != null && objectOld.containsItem(path, false); } else { return ItemDeltaCollectionsUtil.pathMatches(emptyIfNull(delta.getModifications()), path, 0, exactPathMatch); } }
private static PrismReferenceValue getAuditTarget(ObjectDelta<? extends ObjectType> delta, PrismContext prismContext) { PrismReferenceValue targetRef = prismContext.itemFactory().createReferenceValue(delta.getOid()); targetRef.setTargetType(ObjectTypes.getObjectType(delta.getObjectTypeClass()).getTypeQName()); if (delta.isAdd()) { targetRef.setObject(delta.getObjectToAdd()); } return targetRef; }
public <O extends ObjectType> boolean containsItem(ObjectDelta<O> delta, ItemPath itemPath) { if (delta.getChangeType() == ChangeType.ADD) { return containsItem(delta.getObjectToAdd(), itemPath); } else if (delta.getChangeType() == ChangeType.MODIFY) { return containsItemInModifications(delta.getModifications(), itemPath); } else { return false; } }
public static void asserHasDelta(String message, Collection<? extends ObjectDelta<? extends Objectable>> deltas, ChangeType expectedChangeType, Class<?> expectedClass) { for (ObjectDelta<?> delta: deltas) { if (delta.getObjectTypeClass() == expectedClass && delta.getChangeType() == expectedChangeType) { return; } } assert false : message+": Delta for "+expectedClass+" of type "+expectedChangeType+" was not found in collection "+deltas; }
public static void assertIsAdd(ObjectDelta<?> objectDelta) { assert objectDelta.isAdd() : "Expected that object delta "+objectDelta+" is ADD, but it is "+objectDelta.getChangeType(); assert objectDelta.getObjectToAdd() != null : "Object to add is null in add delta " + objectDelta; }
private <P extends ObjectType> boolean isShadowDeltaSignificant(ObjectDelta<P> delta) { if (delta == null || delta.isEmpty()) { return false; } if (delta.isAdd() || delta.isDelete()) { return true; } Collection<? extends ItemDelta<?,?>> attrDeltas = delta.findItemDeltasSubPath(ShadowType.F_ATTRIBUTES); if (attrDeltas != null && !attrDeltas.isEmpty()) { return true; } return false; }
@Test public void testAddDelta() throws SchemaException, SAXException, IOException { System.out.println("===[ testAddDelta ]==="); // WHEN ObjectDelta<UserType> userDelta = DiffUtil.diff(null,new File(TEST_DIR, "user-jack-after.xml"), UserType.class, getPrismContext()); //THEN System.out.println("DELTA:"); System.out.println(userDelta.debugDump()); userDelta.checkConsistence(); assertEquals("Wrong delta OID", "deadbeef-c001-f00d-1111-222233330001", userDelta.getOid()); assertEquals("Wrong change type", ChangeType.ADD, userDelta.getChangeType()); // TODO }
private MidPointPrincipal save(MidPointPrincipal person, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { UserType oldUserType = getUserByOid(person.getOid(), result); PrismObject<UserType> oldUser = oldUserType.asPrismObject(); PrismObject<UserType> newUser = person.getUser().asPrismObject(); ObjectDelta<UserType> delta = oldUser.diff(newUser); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Updating user {} with delta:\n{}", newUser, delta.debugDump()); } repositoryService.modifyObject(UserType.class, delta.getOid(), delta.getModifications(), new OperationResult(OPERATION_UPDATE_USER)); return person; }
private <F extends FocusType> void unlink(LensContext<F> context, FocusType persona, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { ObjectDelta<F> delta = context.getFocusContext().getObjectNew().createModifyDelta(); PrismReferenceValue refValue = prismContext.itemFactory().createReferenceValue(); refValue.setOid(persona.getOid()); refValue.setTargetType(persona.asPrismObject().getDefinition().getTypeName()); delta.addModificationDeleteReference(FocusType.F_PERSONA_REF, refValue); repositoryService.modifyObject(delta.getObjectTypeClass(), delta.getOid(), delta.getModifications(), result); }
private <F extends FocusType> void link(LensContext<F> context, FocusType persona, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { ObjectDelta<F> delta = context.getFocusContext().getObjectNew().createModifyDelta(); PrismReferenceValue refValue = prismContext.itemFactory().createReferenceValue(); refValue.setOid(persona.getOid()); refValue.setTargetType(persona.asPrismObject().getDefinition().getTypeName()); delta.addModificationAddReference(FocusType.F_PERSONA_REF, refValue); repositoryService.modifyObject(delta.getObjectTypeClass(), delta.getOid(), delta.getModifications(), result); }
public ObjectDelta<O> getWaveExecutableDelta(int wave) throws SchemaException { if (wave == 0) { if (getFixedPrimaryDelta() != null && getFixedPrimaryDelta().isAdd()) { ObjectDelta delta = getFixedPrimaryDelta().clone(); for (ObjectDelta<O> secondary : getSecondaryDeltas()) { if (secondary != null) { secondary.applyTo(delta.getObjectToAdd()); } } return delta; } } return getWaveDelta(wave); }
public boolean isProtected() { if ((currentShadow != null && ShadowUtil.isProtected(currentShadow)) || (oldShadow != null && ShadowUtil.isProtected(oldShadow))) { return true; } if (delta != null && delta.isAdd() && ShadowUtil.isProtected(delta.getObjectToAdd())) { return true; } return false; }
public <F extends FocusType> boolean wasAddExecuted() { for (LensObjectDeltaOperation<O> executedDeltaOperation : getExecutedDeltas()){ ObjectDelta<O> executedDelta = executedDeltaOperation.getObjectDelta(); if (!executedDelta.isAdd()){ continue; } else if (executedDelta.getObjectToAdd() != null && executedDelta.getObjectTypeClass().equals(getObjectTypeClass())){ return true; } } return false; }
public void addAssignmentApprovalMetadata(ObjectDelta<?> objectDelta, Task task, OperationResult result) throws SchemaException { if (objectDelta.isAdd()) { addAssignmentApprovalMetadataOnObjectAdd(objectDelta.getObjectToAdd(), task, result); } else if (objectDelta.isModify()) { addAssignmentApprovalMetadataOnObjectModify(objectDelta, task, result); } }
public static void assertModifications(String message, ObjectDelta<?> objectDelta, int expectedNumberOfModifications) { assertIsModify(objectDelta); assert objectDelta.getModifications().size() == expectedNumberOfModifications : (message == null ? "" : (message + ": ")) + "Wrong number of modifications in object delta " + objectDelta + ". Expected "+expectedNumberOfModifications+", was "+objectDelta.getModifications().size(); }
/** * Used to quickly and efficiently refresh shadow before GET operations. */ private PrismObject<ShadowType> refreshShadowQick(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, XMLGregorianCalendar now, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, EncryptionException { ObjectDelta<ShadowType> shadowDelta = repoShadow.createModifyDelta(); expirePendingOperations(ctx, repoShadow, shadowDelta, now, parentResult); if (!shadowDelta.isEmpty()) { shadowManager.modifyShadowAttributes(ctx, repoShadow, shadowDelta.getModifications(), parentResult); shadowDelta.applyTo(repoShadow); } repoShadow = cleanUpDeadShadow(ctx, repoShadow, now, task, parentResult); return repoShadow; }
protected void checkConsistence(ObjectDelta<O> delta, boolean requireOid, String contextDesc) { try { delta.checkConsistence(requireOid, true, true, ConsistencyCheckScope.THOROUGH); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(e.getMessage()+"; in "+contextDesc, e); } catch (IllegalStateException e) { throw new IllegalStateException(e.getMessage()+"; in "+contextDesc, e); } if (delta.isAdd()) { checkConsistence(delta.getObjectToAdd(), "add object", contextDesc); } }
private List<ApprovalRequest<T>> getApprovalRequests(ModelContext<?> modelContext, PcpAspectConfigurationType config, ObjectDelta<? extends ObjectType> change, Task taskFromModel, OperationResult result) { if (change.getChangeType() != ChangeType.ADD) { return null; } T objectType = (T) change.getObjectToAdd().asObjectable().clone(); if (objectType.getOid() == null) { String newOid = OidUtil.generateOid(); objectType.setOid(newOid); ((LensFocusContext<?>) modelContext.getFocusContext()).setOid(newOid); } change.setObjectToAdd(null); // make the change empty return Arrays.asList(createApprovalRequest(config, objectType, modelContext, taskFromModel, result)); }
private MidPointPrincipal save(MidPointPrincipal person, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { UserType oldUserType = getUserByOid(person.getOid(), result); PrismObject<UserType> oldUser = oldUserType.asPrismObject(); PrismObject<UserType> newUser = person.getUser().asPrismObject(); ObjectDelta<UserType> delta = oldUser.diff(newUser); repositoryService.modifyObject(UserType.class, delta.getOid(), delta.getModifications(), new OperationResult(OPERATION_UPDATE_USER)); return person; }