private ItemDelta<?, ?> deleteExtensionPropertyAndPrepareDelta(QName itemName, PrismPropertyDefinition definition, Collection<? extends PrismPropertyValue> values) throws SchemaException { ItemDelta delta = deltaFactory().property().create(ItemPath.create(TaskType.F_EXTENSION, itemName), definition); delta.addValuesToDelete(values); Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1); modifications.add(delta); ItemDeltaCollectionsUtil.applyTo(modifications, taskPrism); // i.e. here we apply changes only locally (in memory) return isPersistent() ? delta : null; }
private ItemDelta<?, ?> addExtensionPropertyAndPrepareDelta(QName itemName, PrismPropertyDefinition definition, Collection<? extends PrismPropertyValue> values) throws SchemaException { ItemDelta delta = deltaFactory().property().create(ItemPath.create(TaskType.F_EXTENSION, itemName), definition); delta.addValuesToAdd(values); Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1); modifications.add(delta); ItemDeltaCollectionsUtil.applyTo(modifications, taskPrism); // i.e. here we apply changes only locally (in memory) return isPersistent() ? delta : null; }
PropertyDelta resultingDelta = prismContext.deltaFactory().property().create(propertyDelta.getPath(), propertyDelta.getPropertyDefinition()); resultingDelta.setValuesToReplace(currentValues); return new PropertyModificationOperation(resultingDelta);
PrismProperty item = shadow.findProperty(employeeTypePath); PropertyDelta deleteDelta = prismContext.deltaFactory().property().create(ShadowType.F_ATTRIBUTES, item.getDefinition().getName(), item.getDefinition());
OperationResult result = task.getResult(); PropertyDelta<String> givenNameDelta = prismContext.deltaFactory().property().create( ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(RESOURCE_OPENDJ_NS, "givenName")), null); PropertyDelta<String> titleDelta = prismContext.deltaFactory().property().create( ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(RESOURCE_OPENDJ_NS, "title")), null);
PropertyDelta<byte[]> jpegPhotoDelta = prismContext.deltaFactory().property().create(ItemPath.create(ShadowType.F_ATTRIBUTES, jpegPhotoQName), null); jpegPhotoDelta.setRealValuesToReplace(bytesIn);
PropertyDelta<String> delta1 = prismContext.deltaFactory().property().create(descDefinition); delta1.addRealValuesToAdd("add1"); assertPath(delta1, UserType.F_DESCRIPTION); DOMUtil.XSD_STRING); ItemPath itemPathAssDescNoId = ItemPath.create(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION); PropertyDelta<String> propDelta2 = prismContext.deltaFactory().property().create(itemPathAssDescNoId, descDefinition); assertPath(propDelta2, itemPathAssDescNoId); PropertyDelta<String> propDelta3 = prismContext.deltaFactory().property().create(itemPathAssDesc1Id, descDefinition); assertPath(propDelta3, itemPathAssDesc1Id);
private <T> void recordDelta(ValueMatcher<T> valueMatcher, LensProjectionContext projCtx, ItemPath parentPath, PrismPropertyDefinition<T> attrDef, ModificationType changeType, T value, ObjectType originObject, String reason) throws SchemaException { ItemDelta existingDelta = null; if (projCtx.getSecondaryDelta() != null) { existingDelta = projCtx.getSecondaryDelta().findItemDelta( ItemPath.create(parentPath, attrDef.getName())); } if (LOGGER.isTraceEnabled()) { LOGGER.trace(" reconciliation will {} value of attribute {}: {} because {}", changeType, PrettyPrinter.prettyPrint(attrDef.getName()), value, reason); } PropertyDelta<T> attrDelta = prismContext.deltaFactory().property().create(parentPath, attrDef.getName(), attrDef); PrismPropertyValue<T> pValue = prismContext.itemFactory().createPropertyValue(value, OriginType.RECONCILIATION, originObject); if (changeType == ModificationType.ADD) { attrDelta.addValueToAdd(pValue); } else if (changeType == ModificationType.DELETE) { if (!isToBeDeleted(existingDelta, valueMatcher, value)){ attrDelta.addValueToDelete(pValue); } } else if (changeType == ModificationType.REPLACE) { attrDelta.setValueToReplace(pValue); } else { throw new IllegalArgumentException("Unknown change type " + changeType); } LensUtil.setDeltaOldValue(projCtx, attrDelta); projCtx.swallowToSecondaryDelta(attrDelta); }
@Test public void test130ExtensionModify() throws Exception { final String TEST_NAME = "test130ExtensionModify"; TestUtil.displayTestTitle(TEST_NAME); File userFile = new File(TEST_DIR, "user-with-extension.xml"); //add first user PrismObject<UserType> user = prismContext.parseObject(userFile); OperationResult result = new OperationResult("test extension modify"); final String oid = repositoryService.addObject(user, null, result); user = prismContext.parseObject(userFile); PrismObject<UserType> readUser = repositoryService.getObject(UserType.class, oid, null, result); AssertJUnit.assertTrue("User was not saved correctly", user.diff(readUser).isEmpty()); String lastVersion = readUser.getVersion(); Collection<ItemDelta> modifications = new ArrayList<>(); ItemPath path = ItemPath.create(UserType.F_EXTENSION, QNAME_LOOT); PrismProperty loot = user.findProperty(path); PropertyDelta lootDelta = prismContext.deltaFactory().property().create(path, loot.getDefinition()); lootDelta.setRealValuesToReplace(456); modifications.add(lootDelta); repositoryService.modifyObject(UserType.class, oid, modifications, getModifyOptions(), result); //check read after modify operation user = prismContext.parseObject(userFile); loot = user.findProperty(ItemPath.create(UserType.F_EXTENSION, QNAME_LOOT)); loot.setRealValue(456); readUser = repositoryService.getObject(UserType.class, oid, null, result); AssertJUnit.assertTrue("User was not modified correctly", user.diff(readUser).isEmpty()); SqlRepoTestUtil.assertVersionProgress(lastVersion, readUser.getVersion()); }
@Override protected void finish(H handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException { super.finish(handler, runResult, task, opResult); if (task.canRun()) { /* * We want to update last scan timestamp only if the task has finished its current duties. * Otherwise we might skip e.g. some triggers or validity boundaries - those that the task * has not reached yet. They would be left unprocessed forever. See MID-4474. * * Note this is not the whole solution. It is necessary to review AbstractSearchIterativeResultHandler.handle() * and shouldStop() methods and use 'stop' flag at this place as well. Hopefully such stopping is (very probably) * not requested by any scanner task handlers. */ PrismPropertyDefinition<XMLGregorianCalendar> lastScanTimestampDef = prismContext.definitionFactory().createPropertyDefinition( SchemaConstants.MODEL_EXTENSION_LAST_SCAN_TIMESTAMP_PROPERTY_NAME, DOMUtil.XSD_DATETIME); PropertyDelta<XMLGregorianCalendar> lastScanTimestampDelta = prismContext.deltaFactory().property().create( ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_LAST_SCAN_TIMESTAMP_PROPERTY_NAME), lastScanTimestampDef); lastScanTimestampDelta.setRealValuesToReplace(handler.getThisScanTimestamp()); task.modifyExtension(lastScanTimestampDelta); } }
protected void modifyAssignmentValidity(LensContext<UserType> context, UserType jack, XMLGregorianCalendar validFrom, XMLGregorianCalendar validTo) throws SchemaException { assertEquals("jack's assignments", 1, jack.getAssignment().size()); PrismContainerDefinition<ActivationType> activationDef = prismContext.getSchemaRegistry() .findObjectDefinitionByCompileTimeClass(UserType.class) .findContainerDefinition(ItemPath.create(UserType.F_ASSIGNMENT, AssignmentType.F_ACTIVATION)); assertNotNull("no activationDef", activationDef); Long assignmentId = jack.getAssignment().get(0).getId(); PrismPropertyDefinition<XMLGregorianCalendar> validFromDef = activationDef.findPropertyDefinition(ActivationType.F_VALID_FROM); PropertyDelta<XMLGregorianCalendar> validFromDelta = prismContext.deltaFactory().property().create( ItemPath.create(UserType.F_ASSIGNMENT, assignmentId, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_FROM), validFromDef); validFromDelta.setRealValuesToReplace(validFrom); PrismPropertyDefinition<XMLGregorianCalendar> validToDef = activationDef.findPropertyDefinition(ActivationType.F_VALID_TO); PropertyDelta<XMLGregorianCalendar> validToDelta = prismContext.deltaFactory().property().create( ItemPath.create(UserType.F_ASSIGNMENT, assignmentId, AssignmentType.F_ACTIVATION, ActivationType.F_VALID_TO), validToDef); validToDelta.setRealValuesToReplace(validTo); ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().create(UserType.class, ChangeType.MODIFY); userDelta.setOid(USER_JACK_OID); userDelta.addModification(validFromDelta); userDelta.addModification(validToDelta); addFocusDeltaToContext(context, userDelta); }
protected <T> ObjectDelta<ShadowType> createAccountDelta(LensProjectionContext accCtx, String accountOid, String attributeLocalName, T... propertyValues) throws SchemaException { ResourceType resourceType = accCtx.getResource(); QName attrQName = new QName(ResourceTypeUtil.getResourceNamespace(resourceType), attributeLocalName); ItemPath attrPath = ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName); RefinedObjectClassDefinition refinedAccountDefinition = accCtx.getCompositeObjectClassDefinition(); RefinedAttributeDefinition attrDef = refinedAccountDefinition.findAttributeDefinition(attrQName); assertNotNull("No definition of attribute "+attrQName+" in account def "+refinedAccountDefinition, attrDef); ObjectDelta<ShadowType> accountDelta = prismContext.deltaFactory().object() .createEmptyModifyDelta(ShadowType.class, accountOid); PropertyDelta<T> attrDelta = prismContext.deltaFactory().property().create(attrPath, attrDef); attrDelta.setValuesToReplace(PrismValueCollectionsUtil.createCollection(prismContext, propertyValues)); accountDelta.addModification(attrDelta); return accountDelta; }
@Override public <T> void setExtensionPropertyValueTransient(QName propertyName, T value) throws SchemaException { PrismContext prismContext = getPrismContext(); //noinspection unchecked PrismPropertyDefinition<T> propertyDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(propertyName); if (propertyDef == null) { throw new SchemaException("Unknown property " + propertyName); } PropertyDelta<T> delta = prismContext.deltaFactory().property().create(ItemPath.create(TaskType.F_EXTENSION, propertyName), propertyDef); //noinspection unchecked delta.setRealValuesToReplace(value); ItemDeltaCollectionsUtil.applyTo(singletonList(delta), taskPrism); }
private PropertyModificationOperation createAddAttributeChange(String propertyName, String propertyValue) { PrismProperty property = createProperty(propertyName, propertyValue); ItemPath propertyPath = ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(ResourceTypeUtil.getResourceNamespace(resourceType), propertyName)); PropertyDelta delta = prismContext.deltaFactory().property().create(propertyPath, property.getDefinition()); delta.addRealValuesToAdd(propertyValue); PropertyModificationOperation attributeModification = new PropertyModificationOperation(delta); return attributeModification; }
private PropertyDelta<String> createNameDelta(Name name, ResourceAttributeDefinition nameDefinition) { PropertyDelta<String> uidDelta = prismContext.deltaFactory().property().create(ItemPath.create(ShadowType.F_ATTRIBUTES, nameDefinition.getName()), nameDefinition); uidDelta.setRealValuesToReplace(name.getNameValue()); return uidDelta; }
private ItemDelta<?, ?> setExtensionPropertyAndPrepareDelta(QName itemName, PrismPropertyDefinition definition, Collection<? extends PrismPropertyValue> values) throws SchemaException { ItemDelta delta = deltaFactory().property().create(ItemPath.create(TaskType.F_EXTENSION, itemName), definition); return setExtensionItemAndPrepareDeltaCommon(delta, values); }
private PropertyModificationOperation createReplaceAttributeChange(String propertyName, String propertyValue) { PrismProperty property = createProperty(propertyName, propertyValue); ItemPath propertyPath = ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(ResourceTypeUtil.getResourceNamespace(resourceType), propertyName)); PropertyDelta delta = prismContext.deltaFactory().property().create(propertyPath, property.getDefinition()); delta.setRealValuesToReplace(propertyValue); PropertyModificationOperation attributeModification = new PropertyModificationOperation(delta); return attributeModification; }
private <T> PropertyDelta<T> createPendingOperationDelta(PrismContainerDefinition<PendingOperationType> containerDefinition, ItemPath containerPath, QName propName, T valueToReplace) { PrismPropertyDefinition<T> propDef = containerDefinition.findPropertyDefinition(ItemName.fromQName(propName)); PropertyDelta<T> propDelta = prismContext.deltaFactory().property().create(containerPath.append(propName), propDef); if (valueToReplace == null) { propDelta.setValueToReplace(); } else { propDelta.setRealValuesToReplace(valueToReplace); } return propDelta; }
private PropertyDelta<String> createUidDelta(Uid uid, ResourceAttributeDefinition uidDefinition) { PropertyDelta<String> uidDelta = prismContext.deltaFactory().property().create(ItemPath.create(ShadowType.F_ATTRIBUTES, uidDefinition.getName()), uidDefinition); uidDelta.setRealValuesToReplace(uid.getUidValue()); return uidDelta; }
private PropertyModificationOperation createDeleteAttributeChange(String propertyName, String propertyValue) { PrismProperty property = createProperty(propertyName, propertyValue); ItemPath propertyPath = ItemPath.create(ShadowType.F_ATTRIBUTES, new QName(ResourceTypeUtil.getResourceNamespace(resourceType), propertyName)); PropertyDelta delta = prismContext.deltaFactory().property().create(propertyPath, property.getDefinition()); delta.addRealValuesToDelete(propertyValue); PropertyModificationOperation attributeModification = new PropertyModificationOperation(delta); return attributeModification; }