diff --git a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/shadowmanager/ShadowDeltaComputer.java b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/shadowmanager/ShadowDeltaComputer.java index 43835d7fe2e..058f10c25cf 100644 --- a/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/shadowmanager/ShadowDeltaComputer.java +++ b/provisioning/provisioning-impl/src/main/java/com/evolveum/midpoint/provisioning/impl/shadowmanager/ShadowDeltaComputer.java @@ -210,19 +210,20 @@ private void processResourceAttribute(ObjectDelta computedShadowDelt PrismProperty oldRepoAttributeProperty = oldRepoAttributes.findProperty(attrDef.getItemName()); if (oldRepoAttributeProperty == null) { PropertyDelta attrAddDelta = currentResourceAttrProperty.createDelta(); - List> currentValues = currentResourceAttrProperty.getValues(); - // This is a brutal hack: For extension attributes the ADD operation is slow when using large # of - // values to add. So let's do REPLACE instead (this is OK if there are no existing values). - // TODO Move this logic to repository. Here it is only for PoC purposes. - if (currentValues.size() >= 100) { - Object[] currentValuesNormalized = new Object[currentValues.size()]; - for (int i = 0; i < currentValues.size(); i++) { - currentValuesNormalized[i] = matchingRule.normalize(currentValues.get(i).getValue()); - } - attrAddDelta.setRealValuesToReplace(currentValuesNormalized); + List> valuesOnResource = currentResourceAttrProperty.getValues(); + if (attrDef.isIndexOnly()) { + // We don't know what is in the repository. We simply want to replace everything with the current values. + setNormalizedValuesToReplace(attrAddDelta, valuesOnResource, matchingRule); } else { - for (PrismPropertyValue pval : currentValues) { - attrAddDelta.addRealValuesToAdd(matchingRule.normalize(pval.getValue())); + // This is a brutal hack: For extension attributes the ADD operation is slow when using large # of + // values to add. So let's do REPLACE instead (this is OK if there are no existing values). + // TODO Move this logic to repository. Here it is only for PoC purposes. + if (valuesOnResource.size() >= 100) { + setNormalizedValuesToReplace(attrAddDelta, valuesOnResource, matchingRule); + } else { + for (PrismPropertyValue pval : valuesOnResource) { + attrAddDelta.addRealValuesToAdd(matchingRule.normalize(pval.getValue())); + } } } if (attrAddDelta.getDefinition().getTypeName() == null) { @@ -270,6 +271,15 @@ private void processResourceAttribute(ObjectDelta computedShadowDelt } } + private void setNormalizedValuesToReplace(PropertyDelta attrAddDelta, List> currentValues, + MatchingRule matchingRule) throws SchemaException { + Object[] currentValuesNormalized = new Object[currentValues.size()]; + for (int i = 0; i < currentValues.size(); i++) { + currentValuesNormalized[i] = matchingRule.normalize(currentValues.get(i).getValue()); + } + attrAddDelta.setRealValuesToReplace(currentValuesNormalized); + } + private void compareUpdateProperty(ObjectDelta shadowDelta, ItemPath itemPath, PrismObject currentResourceShadow, PrismObject oldRepoShadow) { PrismProperty currentProperty = currentResourceShadow.findProperty(itemPath);