Skip to content

Commit

Permalink
repo-sqale: ordering related code cleanup, added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Aug 17, 2021
1 parent 5fe093f commit e517d85
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@

import static com.querydsl.core.types.dsl.Expressions.stringTemplate;

import static com.evolveum.midpoint.repo.sqale.filtering.ExtensionItemFilterProcessor.*;

import java.util.function.Function;

import com.querydsl.core.types.Expression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.query.ValueFilter;
import com.evolveum.midpoint.repo.sqale.ExtUtils;
import com.evolveum.midpoint.repo.sqale.ExtensionProcessor;
import com.evolveum.midpoint.repo.sqale.ExtensionProcessor.ExtItemInfo;
import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.delta.ItemDeltaProcessor;
import com.evolveum.midpoint.repo.sqale.delta.item.ExtensionItemDeltaProcessor;
import com.evolveum.midpoint.repo.sqale.filtering.ExtensionItemFilterProcessor;
import com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath;
import com.evolveum.midpoint.repo.sqale.jsonb.JsonbUtils;
import com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem;
import com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItemHolderType;
import com.evolveum.midpoint.repo.sqale.update.SqaleUpdateContext;
import com.evolveum.midpoint.repo.sqlbase.QueryException;
import com.evolveum.midpoint.repo.sqlbase.SqlQueryContext;
import com.evolveum.midpoint.repo.sqlbase.filtering.item.ItemValueFilterProcessor;
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase;
Expand All @@ -44,7 +51,7 @@ public class ExtensionItemSqlMapper<Q extends FlexibleRelationalPathBase<R>, R>

private final Function<Q, JsonbPath> rootToExtensionPath;
private final MExtItemHolderType holderType;
private @NotNull SqaleRepoContext repositoryContext;
private final SqaleRepoContext repositoryContext;

public ExtensionItemSqlMapper(
@NotNull Function<Q, JsonbPath> rootToExtensionPath,
Expand All @@ -56,14 +63,29 @@ public ExtensionItemSqlMapper(
}

@Override
public @Nullable Expression<?> itemOrdering(Q entityPath, ItemDefinition<?> definition) {

public @Nullable Expression<?> itemOrdering(Q entityPath, ItemDefinition<?> definition)
throws QueryException {
JsonbPath path = rootToExtensionPath.apply(entityPath);
ExtItemInfo info = new ExtensionProcessor(repositoryContext).findExtensionItem(definition, holderType);
// TODO: Is polystring ordered by normalized or original form?
return stringTemplate("{0}->'{1s}'", path, info.getId());
}
ExtItemInfo info = new ExtensionProcessor(repositoryContext)
.findExtensionItem(definition, holderType);
if (info == null) {
throw new QueryException("Extension property " + definition
+ " is not indexed and cannot be used for ordering.");
}

MExtItem extItem = info.item;
if (extItem.valueType.equals(STRING_TYPE)
|| ExtUtils.isEnumDefinition((PrismPropertyDefinition<?>) definition)
|| extItem.valueType.equals(DATETIME_TYPE)) {
return stringTemplate("{0}->>'{1s}'",
path, info.getId());
} else if (extItem.valueType.equals(POLY_STRING_TYPE)) {
return stringTemplate("{0}->'{1s}'->>'" + JsonbUtils.JSONB_POLY_ORIG_KEY + "'",
path, info.getId());
} else {
return stringTemplate("{0}->'{1s}'", path, info.getId());
}
}

@Override
public @Nullable <T extends ValueFilter<?, ?>> ItemValueFilterProcessor<T> createFilterProcessor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public void test206AddObjectWithMultivalueRefsOnAssignment()
QName approverRelation = QName.valueOf("{https://random.org/ns}conn-rel");
UserType user = new UserType(prismContext)
.name(userName)
.assignment(new AssignmentType()
.assignment(new AssignmentType(prismContext)
.metadata(new MetadataType()
.createApproverRef(approverRef1.toString(),
UserType.COMPLEX_TYPE, approverRelation)
Expand Down Expand Up @@ -571,9 +571,9 @@ public void test208AddObjectWithRefWithoutTypeImpliedByDefault()
public void test290DuplicateCidInsideOneContainerIsCaughtByPrism() {
expect("object construction with duplicate CID inside container fails immediately");
assertThatThrownBy(() -> new UserType(prismContext)
.assignment(new AssignmentType()
.assignment(new AssignmentType(prismContext)
.targetRef("ref1", RoleType.COMPLEX_TYPE).id(1L))
.assignment(new AssignmentType()
.assignment(new AssignmentType(prismContext)
.targetRef("ref2", RoleType.COMPLEX_TYPE).id(1L)))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Attempt to add a container value with an id that already exists: 1");
Expand All @@ -587,7 +587,7 @@ public void test291DuplicateCidInDifferentContainersIsCaughtByRepo() {
given("object with duplicate CID in different containers");
UserType user = new UserType(prismContext)
.name("user" + getTestNumber())
.assignment(new AssignmentType().id(1L))
.assignment(new AssignmentType(prismContext).id(1L))
.operationExecution(new OperationExecutionType().id(1L));

expect("adding object to repository throws exception");
Expand Down Expand Up @@ -1135,7 +1135,7 @@ public void test803ContainerAssignment() throws Exception {
.modifyChannel("modify-channel")
.modifyTimestamp(MiscUtil.asXMLGregorianCalendar(2L))))
// one more just to see it stores multiple assignments
.assignment(new AssignmentType().order(1));
.assignment(new AssignmentType(prismContext).order(1));

when("adding it to the repository");
repositoryService.addObject(object.asPrismObject(), null, result);
Expand Down Expand Up @@ -1537,11 +1537,11 @@ public void test821ArchetypeAndInducement() throws Exception {
.identifier("identifier")
.requestable(false)
.riskLevel("extremely-high")
// we don't need all attributes here, this is tested in TODO
.inducement(new AssignmentType()
// we don't need all attributes here, this is tested in test803ContainerAssignment
.inducement(new AssignmentType(prismContext)
.order(2)
.targetRef(UUID.randomUUID().toString(), RoleType.COMPLEX_TYPE))
.inducement(new AssignmentType()
.inducement(new AssignmentType(prismContext)
.order(3)
.targetRef(UUID.randomUUID().toString(), RoleType.COMPLEX_TYPE));
// this is no additional attribute specific for archetype
Expand Down Expand Up @@ -1821,8 +1821,7 @@ public void test842AccessCertificationCampaign() throws Exception {
.validFrom(MiscUtil.asXMLGregorianCalendar(validFrom))
.validTo(MiscUtil.asXMLGregorianCalendar(validTo))
.validityChangeTimestamp(MiscUtil.asXMLGregorianCalendar(validityChangeTimestamp))
.validityStatus(TimeIntervalStatusType.IN)
)
.validityStatus(TimeIntervalStatusType.IN))
.currentStageOutcome(case1CurrentStageOutcome)
// TODO campaignIteration
.iteration(case1Iteration)
Expand All @@ -1841,30 +1840,26 @@ public void test842AccessCertificationCampaign() throws Exception {
// TODO: iteration -> campaignIteration
.iteration(81)
.output(new AbstractWorkItemOutputType()
.outcome("almost, but not quite, entirely done")
)
.outcome("almost, but not quite, entirely done"))
.outputChangeTimestamp(MiscUtil.asXMLGregorianCalendar(wi1OutputChangeTimestamp))
.performerRef(performer1Oid.toString(), UserType.COMPLEX_TYPE, performer1Relation)
.stageNumber(21)
.assigneeRef(wi1AssigneeRef1Oid.toString(), UserType.COMPLEX_TYPE, wi1AssigneeRef1Relation)
.assigneeRef(wi1AssigneeRef2Oid.toString(), UserType.COMPLEX_TYPE, wi1AssigneeRef2Relation)
.candidateRef(wi1CandidateRef1Oid.toString(), UserType.COMPLEX_TYPE, wi1CandidateRef1Relation)
)
.candidateRef(wi1CandidateRef1Oid.toString(), UserType.COMPLEX_TYPE, wi1CandidateRef1Relation))
.workItem(new AccessCertificationWorkItemType(prismContext)
.id(56L)
.closeTimestamp(MiscUtil.asXMLGregorianCalendar(wi2CloseTimestamp))
// TODO: iteration -> campaignIteration
.iteration(82)
.output(new AbstractWorkItemOutputType()
.outcome("A tad more than almost, but not quite, entirely done")
)
.outcome("A tad more than almost, but not quite, entirely done"))
.outputChangeTimestamp(MiscUtil.asXMLGregorianCalendar(wi2OutputChangeTimestamp))
.performerRef(performer2Oid.toString(), UserType.COMPLEX_TYPE, performer2Relation)
.stageNumber(22)
.assigneeRef(wi2AssigneeRef1Oid.toString(), UserType.COMPLEX_TYPE, wi2AssigneeRef1Relation)
.candidateRef(wi2CandidateRef1Oid.toString(), UserType.COMPLEX_TYPE, wi2CandidateRef1Relation)
.candidateRef(wi2CandidateRef2Oid.toString(), OrgType.COMPLEX_TYPE, wi2CandidateRef2Relation)
))
.candidateRef(wi2CandidateRef2Oid.toString(), OrgType.COMPLEX_TYPE, wi2CandidateRef2Relation)))
._case(new AccessCertificationCaseType(prismContext)
.id(49L)
.currentStageOutcome(case2CurrentStageOutcome)
Expand All @@ -1880,14 +1875,12 @@ public void test842AccessCertificationCampaign() throws Exception {
// TODO: iteration -> campaignIteration
.iteration(83)
.output(new AbstractWorkItemOutputType()
.outcome("certainly not quite done")
)
.outcome("certainly not quite done"))
.outputChangeTimestamp(MiscUtil.asXMLGregorianCalendar(wi3OutputChangeTimestamp))
.performerRef(performer3Oid.toString(), UserType.COMPLEX_TYPE, performer3Relation)
.stageNumber(21)
.assigneeRef(wi3AssigneeRef1Oid.toString(), UserType.COMPLEX_TYPE, wi3AssigneeRef1Relation)
.candidateRef(wi3CandidateRef1Oid.toString(), OrgType.COMPLEX_TYPE, wi3CandidateRef1Relation)
));
.candidateRef(wi3CandidateRef1Oid.toString(), OrgType.COMPLEX_TYPE, wi3CandidateRef1Relation)));

when("adding it to the repository");
repositoryService.addObject(accessCertificationCampaign.asPrismObject(), null, result);
Expand Down

0 comments on commit e517d85

Please sign in to comment.