Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Oct 8, 2021
2 parents 3914ec9 + 1d7f4e7 commit 1d34ffb
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ExtensionItemSqlMapper(
}

@Override
public @Nullable Expression<?> itemOrdering(Q entityPath, ItemDefinition<?> definition)
public @Nullable Expression<?> primaryPath(Q entityPath, ItemDefinition<?> definition)
throws QueryException {
JsonbPath path = rootToExtensionPath.apply(entityPath);
ExtItemInfo info = new ExtensionProcessor(repositoryContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.delta.item.SinglePathItemDeltaProcessor;
import com.evolveum.midpoint.repo.sqale.mapping.QOwnedByMapping;
import com.evolveum.midpoint.repo.sqale.mapping.SqaleItemSqlMapper;
import com.evolveum.midpoint.repo.sqale.mapping.SqaleTableMapping;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;
import com.evolveum.midpoint.repo.sqlbase.filtering.item.SimpleItemFilterProcessor;
import com.evolveum.midpoint.util.exception.SchemaException;

/**
Expand Down Expand Up @@ -47,11 +51,16 @@ protected QContainerMapping(

// OWNER_OID does not need to be mapped, it is handled by InOidFilterProcessor
// CID is not mapped directly, it is used by path resolver elsewhere
addItemMapping(PrismConstants.T_ID, new SqaleItemSqlMapper<>(
ctx -> new SimpleItemFilterProcessor<>(ctx, p -> p.cid ),
ctx -> new SinglePathItemDeltaProcessor<>(ctx, p -> p.cid),
p -> p.cid));
}

/**
* Implemented for searchable containers that do not use fullObject for their recreation.
*/
@Override
public S toSchemaObject(R row) {
throw new UnsupportedOperationException(
"Container search not supported for schema type " + schemaType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private BooleanExpression appendConditions(QLookupTableRow alias, BooleanExpress
return base;
}
String value = queryDef.getSearchValue();
StringPath path = (StringPath) QLookupTableRowMapping.get().getItemMapper(queryDef.getColumn()).itemOrdering(alias, null);
StringPath path = (StringPath) QLookupTableRowMapping.get().getItemMapper(queryDef.getColumn()).primaryPath(alias, null);
BooleanExpression right;
if (LookupTableRowType.F_LABEL.equals(queryDef.getColumn())) {
path = alias.labelNorm;
Expand Down Expand Up @@ -184,11 +184,12 @@ private <R> SQLQuery<R> pagingAndOrdering(SQLQuery<R> query, RelationalValueSear
}
for (ObjectOrdering ordering : paging.getOrderingInstructions()) {
Order direction = ordering.getDirection() == OrderDirection.DESCENDING ? Order.DESC : Order.ASC;
if (ordering.getOrderBy() == null || !ordering.getOrderBy().isSingleName()) {
throw new SystemException("Only single name order path is supported");
var mapper = rowMapping.itemMapper(ordering.getOrderBy().firstToQName());
if (mapper == null) {
throw new QueryException("Incorrect orderBy path " + ordering.getOrderBy());
}
@SuppressWarnings("rawtypes")
Expression path = rowMapping.itemMapper(ordering.getOrderBy().firstToQName()).itemOrdering(alias, null);
Expression path = mapper.primaryPath(alias, null);
if (ItemPath.equivalent(LookupTableRowType.F_LABEL, ordering.getOrderBy())) {
// old repository uses normalized form for ordering
path = alias.labelNorm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
Expand Down Expand Up @@ -191,6 +192,28 @@ public void test123LookupLanguagesGetByKeyContainingWithPaging() throws Exceptio
checkLookupResult(lookup, new String[] { "sk_SK", "sk", "Slovak" });
}

@Test
public void test123LookupLanguagesOrderById() throws Exception {
given();
OperationResult result = createOperationResult();

when();
GetOperationOptionsBuilder optionsBuilder = SchemaService.get().getOperationOptionsBuilder()
.item(LookupTableType.F_ROW)
.retrieveQuery()
.item(LookupTableRowType.F_KEY)
.contains("_")
.offset(2)
.maxSize(1)
.asc(PrismConstants.T_ID)
.end();
PrismObject<LookupTableType> lookup = repositoryService.getObject(LookupTableType.class, LOOKUP_LANGUAGES_OID, optionsBuilder.build(), result);

then();
result.computeStatus();
TestUtil.assertSuccess(result);
}

@Test
public void test124LookupLanguagesGetByKeyContainingReturningNothing() throws Exception {
given();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private <CQ extends FlexibleRelationalPathBase<CR>, CR> Expression<?> orderingPa
: null;

ItemSqlMapper<CQ, CR> mapper = mapping.itemMapper(first);
return mapper.itemOrdering(context.path(), definition);
return mapper.primaryPath(context.path(), definition);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public DefaultItemSqlMapper(
}

@Override
public @Nullable Path<?> itemOrdering(Q root, ItemDefinition<?> unused) {
public @Nullable Path<?> primaryPath(Q root, ItemDefinition<?> unused) {
return primaryItemMapping != null ? primaryItemMapping.apply(root) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public interface ItemSqlMapper<Q extends FlexibleRelationalPathBase<R>, R> {

/** Returns primary path for provided entity path - usable for ordering. */
@Nullable Expression<?> itemOrdering(Q entityPath, ItemDefinition<?> definition)
@Nullable Expression<?> primaryPath(Q entityPath, ItemDefinition<?> definition)
throws QueryException;

/**
Expand Down

0 comments on commit 1d34ffb

Please sign in to comment.