Skip to content

Commit

Permalink
repo-sqale: update context findItem() changed to findValueOrItem()
Browse files Browse the repository at this point in the history
Now it can also obtain PCVs by their path and check whether they are
even available when modified which now throws better exception, not NPE.
  • Loading branch information
virgo47 committed Aug 11, 2021
1 parent bea915b commit b408049
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ExtensionItemDeltaProcessor(
@Override
public void process(ItemDelta<?, ?> modification) throws RepositoryException, SchemaException {
ItemPath itemPath = modification.getPath();
Item<PrismValue, ?> item = context.findItem(itemPath);
Item<PrismValue, ?> item = context.findValueOrItem(itemPath);
Collection<?> realValues = item != null ? item.getRealValues() : null;
ItemDefinition<?> definition = modification.getDefinition();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public <Q extends FlexibleRelationalPathBase<R>, R> FinalValueDeltaProcessor(

@Override
public void process(ItemDelta<?, ?> modification) throws RepositoryException, SchemaException {
Item<PrismValue, ?> item = context.findItem(modification.getPath());
Item<PrismValue, ?> item = context.findValueOrItem(modification.getPath());
Collection<?> realValues = item != null ? item.getRealValues() : null;

if (realValues == null || realValues.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerMapping;
import com.evolveum.midpoint.repo.sqale.update.ContainerTableUpdateContext;
import com.evolveum.midpoint.repo.sqale.update.SqaleUpdateContext;
import com.evolveum.midpoint.repo.sqlbase.RepositoryException;
import com.evolveum.midpoint.repo.sqlbase.mapping.TableRelationResolver;
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase;

Expand All @@ -45,20 +46,21 @@ public ContainerTableRelationResolver(

@Override
public ContainerTableUpdateContext<TS, TQ, TR, R> resolve(
SqaleUpdateContext<?, Q, R> context, ItemPath itemPath) {
SqaleUpdateContext<?, Q, R> context, ItemPath itemPath) throws RepositoryException {
if (itemPath == null || itemPath.size() != 2 || !(itemPath.getSegment(1) instanceof Long)) {
throw new IllegalArgumentException(
"Item path provided for container table relation resolver must have two"
+ " segments with PCV ID as the second");
}
if (context.findValueOrItem(itemPath) == null) {
throw new RepositoryException("Container for path '" + itemPath + "' does not exist!");
}

QContainerMapping<TS, TQ, TR, R> containerMapping =
(QContainerMapping<TS, TQ, TR, R>) targetMappingSupplier.get();
TR row = containerMapping.newRowObject(context.row());
//noinspection ConstantConditions
row.cid = (long) itemPath.getSegment(1);
// TODO check actual container existence? E.g. run test332ModifiedCertificationCaseStoresIt
// isolated and it ignores the missing container here and later fails with NPE.
// Funny thing is, that modification.applyTo(prism) only logs WARN and doesn't care anymore.
return new ContainerTableUpdateContext<>(context, containerMapping, row);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void afterModify(

@SuppressWarnings({ "unchecked", "rawtypes" })
PrismContainer<AccessCertificationCaseType> caseContainer =
(PrismContainer) updateContext.findItem(AccessCertificationCampaignType.F_CASE);
(PrismContainer) updateContext.findValueOrItem(AccessCertificationCampaignType.F_CASE);
// row in context already knows its CID
PrismContainerValue<AccessCertificationCaseType> caseContainerValue =
caseContainer.findValue(updateContext.row().cid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ public void finishExecutionOwn() throws SchemaException, RepositoryException {
}

@Override
public <V extends PrismValue> Item<V, ?> findItem(@NotNull ItemPath path) {
return object.asPrismObject().findItem(path);
public <O> O findValueOrItem(@NotNull ItemPath path) {
//noinspection unchecked
return (O) object.asPrismObject().find(path);
}

public SQLUpdateClause update() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import com.querydsl.core.types.Path;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
Expand Down Expand Up @@ -166,11 +164,11 @@ protected final void finishExecution() throws SchemaException, RepositoryExcepti

protected abstract void finishExecutionOwn() throws SchemaException, RepositoryException;

public <V extends PrismValue> Item<V, ?> findItem(@NotNull ItemPath path) {
public <O> O findValueOrItem(@NotNull ItemPath path) {
if (parentContext == null) {
throw new UnsupportedOperationException(
"findItem() is unsupported on non-root update context");
}
return parentContext.findItem(path);
return parentContext.findValueOrItem(path);
}
}

0 comments on commit b408049

Please sign in to comment.