Skip to content

Commit

Permalink
MID-7581: During delta update of extension / attribute delete reverse…
Browse files Browse the repository at this point in the history
… cardinality

During delta update (we know final cardinality) delete index of reverse cardinality
of the same attribute in question.

If it is item delete this ensures both indices are deleted.
  • Loading branch information
tonydamage committed Jan 20, 2022
1 parent ff15f61 commit aa0d7fd
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.repo.sqale.ExtensionProcessor;
import com.evolveum.midpoint.repo.sqale.delta.ItemDeltaProcessor;
import com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem;
import com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItemCardinality;
import com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItemHolderType;
import com.evolveum.midpoint.repo.sqale.update.ExtensionUpdateContext;
import com.evolveum.midpoint.repo.sqale.update.SqaleUpdateContext;
Expand Down Expand Up @@ -57,6 +59,11 @@ public void process(ItemDelta<?, ?> modification) throws RepositoryException, Sc
return; // not-indexed, no action
}

// If the extension is single value (and we know it now, we should proceed with deletion of
// multivalue variant and vice-versa (this variants may be indroduced during raw import
// or changes in multiplicity of extension definition or resource definition
context.deleteItem(reverseCardinality(extProcessor, extItemInfo.item));

if (realValues == null || realValues.isEmpty()) {
context.deleteItem(extItemInfo.getId());
return;
Expand All @@ -65,4 +72,16 @@ public void process(ItemDelta<?, ?> modification) throws RepositoryException, Sc
// changed value
context.setChangedItem(extItemInfo.getId(), extProcessor.extItemValue(item, extItemInfo));
}

private String reverseCardinality(ExtensionProcessor extProcessor, MExtItem extItem) {
var reverseCardinality = MExtItemCardinality.SCALAR.equals(extItem.cardinality) ? MExtItemCardinality.ARRAY : MExtItemCardinality.SCALAR;
var reverseKey = new MExtItem.Key();
reverseKey.cardinality = reverseCardinality;
reverseKey.itemName = extItem.itemName;
reverseKey.valueType = extItem.valueType;
reverseKey.holderType = extItem.holderType;
// FIXME: Use search rather (do not create additional MExtItem)
var reverseItem = context.repositoryContext().resolveExtensionItem(reverseKey);
return String.valueOf(reverseItem.id);
}
}

0 comments on commit aa0d7fd

Please sign in to comment.