use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class LookupTableTest method test245AddDuplicateRows.
@Test
public void test245AddDuplicateRows() throws Exception {
OperationResult result = new OperationResult("test245AddDuplicateRows");
LookupTableRowType rowNoId = new LookupTableRowType(prismContext);
rowNoId.setKey("key new");
rowNoId.setValue("value new NEW");
LookupTableRowType row4 = new LookupTableRowType(prismContext);
row4.setId(4L);
row4.setKey("key 4");
row4.setValue("value 4 NEW");
List<ItemDelta<?, ?>> modifications = DeltaBuilder.deltaFor(LookupTableType.class, prismContext).item(F_ROW).add(rowNoId, row4).asItemDeltas();
executeAndCheckModification(modifications, result, 0, keysOf(rowNoId, row4), keysOf(rowNoId, row4));
// beware, ID for row4 was re-generated -- using client-provided IDs is not recommended anyway
}
use of com.evolveum.midpoint.prism.delta.ItemDelta 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.ItemDelta 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.ItemDelta in project midpoint by Evolveum.
the class SqlRepositoryServiceImpl method modifyObject.
@Override
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, RepoModifyOptions options, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
Validate.notNull(modifications, "Modifications must not be null.");
Validate.notNull(type, "Object class in delta must not be null.");
Validate.notEmpty(oid, "Oid must not null or empty.");
Validate.notNull(result, "Operation result must not be null.");
OperationResult subResult = result.createSubresult(MODIFY_OBJECT);
subResult.addParam("type", type.getName());
subResult.addParam("oid", oid);
subResult.addCollectionOfSerializablesAsParam("modifications", modifications);
if (modifications.isEmpty() && !RepoModifyOptions.isExecuteIfNoChanges(options)) {
LOGGER.debug("Modification list is empty, nothing was modified.");
subResult.recordStatus(OperationResultStatus.SUCCESS, "Modification list is empty, nothing was modified.");
return;
}
if (InternalsConfig.encryptionChecks) {
CryptoUtil.checkEncrypted(modifications);
}
if (InternalsConfig.consistencyChecks) {
ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
} else {
ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.MANDATORY_CHECKS_ONLY);
}
if (LOGGER.isTraceEnabled()) {
for (ItemDelta modification : modifications) {
if (modification instanceof PropertyDelta<?>) {
PropertyDelta<?> propDelta = (PropertyDelta<?>) modification;
if (propDelta.getPath().equivalent(new ItemPath(ObjectType.F_NAME))) {
Collection<PrismPropertyValue<PolyString>> values = propDelta.getValues(PolyString.class);
for (PrismPropertyValue<PolyString> pval : values) {
PolyString value = pval.getValue();
LOGGER.trace("NAME delta: {} - {}", value.getOrig(), value.getNorm());
}
}
}
}
}
final String operation = "modifying";
int attempt = 1;
SqlPerformanceMonitor pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart("modifyObject");
try {
while (true) {
try {
objectUpdater.modifyObjectAttempt(type, oid, modifications, options, subResult);
return;
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(oid, operation, attempt, ex, subResult);
pm.registerOperationNewTrial(opHandle, attempt);
}
}
} finally {
pm.registerOperationFinish(opHandle, attempt);
}
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class AbstractOrgClosureTest method addOrgParent.
// TODO generalzie to addObjectParent
protected void addOrgParent(OrgType org, ObjectReferenceType parentOrgRef, boolean useReplace, OperationResult opResult) throws Exception {
List<ItemDelta> modifications = new ArrayList<>();
PrismReferenceValue existingValue = parentOrgRef.asReferenceValue();
ItemDelta itemDelta;
if (!useReplace) {
itemDelta = ReferenceDelta.createModificationAdd(OrgType.class, OrgType.F_PARENT_ORG_REF, prismContext, existingValue.clone());
} else {
List<PrismReferenceValue> newValues = new ArrayList<>();
for (ObjectReferenceType ort : org.getParentOrgRef()) {
newValues.add(ort.asReferenceValue().clone());
}
newValues.add(existingValue.clone());
PrismObjectDefinition objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(OrgType.class);
itemDelta = ReferenceDelta.createModificationReplace(new ItemPath(OrgType.F_PARENT_ORG_REF), objectDefinition, newValues);
}
modifications.add(itemDelta);
repositoryService.modifyObject(OrgType.class, org.getOid(), modifications, opResult);
orgGraph.addEdge(org.getOid(), existingValue.getOid());
}
Aggregations