Skip to content

Commit

Permalink
QAccessCertificationCase/WorkItem mapping/resolve/owner row fixes
Browse files Browse the repository at this point in the history
Container table mapping for ACC.F_WORK_ITEM was added, but this flushed
out wrong owner row type for WI, it should be immediate container, not
owning object. This was now clarified in Javadoc as well.
  • Loading branch information
virgo47 committed Sep 14, 2021
1 parent 7115ceb commit 28d568d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
public interface QOwnedBy<OR> {

/** Returns predicate for where clause that matches only rows owned by the provided owner. */
/**
* Returns predicate for where clause that matches only rows owned by the provided owner.
* Owner row is immediate owner, so if the containers are nested, it is the owning container,
* not the top-level owning object.
*/
BooleanExpression isOwnedBy(OR ownerRow);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.*;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType.F_ACTIVATION;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.*;

import com.querydsl.core.Tuple;
import com.querydsl.core.types.Path;
Expand Down Expand Up @@ -129,6 +124,10 @@ private QAccessCertificationCaseMapping(@NotNull SqaleRepoContext repositoryCont
q -> q.tenantRefTargetType,
q -> q.tenantRefRelationId,
QOrgMapping::getOrgMapping);

addContainerTableMapping(F_WORK_ITEM,
QAccessCertificationWorkItemMapping.init(repositoryContext),
joinOn((c, wi) -> c.ownerOid.eq(wi.ownerOid)));
}

@Override
Expand Down Expand Up @@ -214,7 +213,7 @@ public MAccessCertificationCase insert(AccessCertificationCaseType acase,

insert(row, jdbcSession);

storeWorkItems(ownerRow, row, acase, jdbcSession);
storeWorkItems(row, acase, jdbcSession);

return row;
}
Expand All @@ -224,7 +223,6 @@ public void afterModify(
SqaleUpdateContext<AccessCertificationCaseType, QAccessCertificationCase, MAccessCertificationCase> updateContext)
throws SchemaException {

@SuppressWarnings({ "unchecked", "rawtypes" })
PrismContainer<AccessCertificationCaseType> caseContainer =
updateContext.findValueOrItem(AccessCertificationCampaignType.F_CASE);
// row in context already knows its CID
Expand All @@ -235,15 +233,14 @@ public void afterModify(
}

public void storeWorkItems(
@NotNull MAccessCertificationCampaign campaignRow,
@NotNull MAccessCertificationCase caseRow,
@NotNull AccessCertificationCaseType schemaObject,
@NotNull JdbcSession jdbcSession) throws SchemaException {

List<AccessCertificationWorkItemType> wis = schemaObject.getWorkItem();
if (!wis.isEmpty()) {
for (AccessCertificationWorkItemType wi : wis) {
QAccessCertificationWorkItemMapping.get().insert(wi, campaignRow, caseRow, jdbcSession);
QAccessCertificationWorkItemMapping.get().insert(wi, caseRow, jdbcSession);
}
}
}
Expand All @@ -262,12 +259,13 @@ public ResultListRowTransformer<AccessCertificationCaseType, QAccessCertificatio
cache.put(ownerOid, owner);
}
try {
// Container could be null (since it is skipItem in campain)
// Container could be null (since it is skipItem in campaign)
PrismContainer<AccessCertificationCaseType> container = owner.findOrCreateContainer(AccessCertificationCampaignType.F_CASE);
PrismContainerValue<AccessCertificationCaseType> value = container.findValue(cid);
if (value == null) {
// value is not present, load it from full object
AccessCertificationCaseType valueObj = toSchemaObject(tuple, entityPath, options);
//noinspection unchecked
value = valueObj.asPrismContainerValue();
container.add(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Querydsl query type for {@value #TABLE_NAME} table.
*/
@SuppressWarnings("unused")
public class QAccessCertificationWorkItem extends QContainer<MAccessCertificationWorkItem, MAccessCertificationCampaign> {
public class QAccessCertificationWorkItem extends QContainer<MAccessCertificationWorkItem, MAccessCertificationCase> {

private static final long serialVersionUID = -672265595179912120L;

Expand Down Expand Up @@ -76,7 +76,8 @@ public QAccessCertificationWorkItem(String variable, String schema, String table
}

@Override
public BooleanExpression isOwnedBy(MAccessCertificationCampaign ownerRow) {
return ownerOid.eq(ownerRow.oid);
public BooleanExpression isOwnedBy(MAccessCertificationCase caseRow) {
return ownerOid.eq(caseRow.ownerOid)
.and(accessCertCaseCid.eq(caseRow.cid));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Mapping between {@link QAccessCertificationWorkItem} and {@link AccessCertificationWorkItemType}.
*/
public class QAccessCertificationWorkItemMapping
extends QContainerMapping<AccessCertificationWorkItemType, QAccessCertificationWorkItem, MAccessCertificationWorkItem, MAccessCertificationCampaign> {
extends QContainerMapping<AccessCertificationWorkItemType, QAccessCertificationWorkItem, MAccessCertificationWorkItem, MAccessCertificationCase> {

public static final String DEFAULT_ALIAS_NAME = "acwi";

Expand Down Expand Up @@ -121,21 +121,20 @@ public MAccessCertificationWorkItem newRowObject() {
}

@Override
public MAccessCertificationWorkItem newRowObject(MAccessCertificationCampaign ownerRow) {
public MAccessCertificationWorkItem newRowObject(MAccessCertificationCase ownerRow) {
MAccessCertificationWorkItem row = newRowObject();
row.ownerOid = ownerRow.oid;
row.ownerOid = ownerRow.ownerOid;
row.accessCertCaseCid = ownerRow.cid;
return row;
}

// about duplication see the comment in QObjectMapping.toRowObjectWithoutFullObject
@SuppressWarnings("DuplicatedCode")
public MAccessCertificationWorkItem insert(
AccessCertificationWorkItemType workItem,
MAccessCertificationCampaign campaignRow,
MAccessCertificationCase caseRow,
JdbcSession jdbcSession) {
MAccessCertificationWorkItem row = initRowObject(workItem, campaignRow);
row.accessCertCaseCid = caseRow.cid;
MAccessCertificationWorkItem row = initRowObject(workItem, caseRow);

row.closeTimestamp = MiscUtil.asInstant(workItem.getCloseTimestamp());
// TODO: iteration -> campaignIteration
Expand Down Expand Up @@ -182,19 +181,19 @@ public ResultListRowTransformer<AccessCertificationWorkItemType, QAccessCertific
}
PrismContainer<AccessCertificationCaseType> caseContainer = owner.findContainer(AccessCertificationCampaignType.F_CASE);
if (caseContainer == null) {
throw new SystemException("Campaing" + owner + " has no cases even if it should have " + tuple);
throw new SystemException("Campaign" + owner + " has no cases even if it should have " + tuple);
}
PrismContainerValue<AccessCertificationCaseType> aCase = caseContainer .findValue(row.accessCertCaseCid);
PrismContainerValue<AccessCertificationCaseType> aCase = caseContainer.findValue(row.accessCertCaseCid);
if (aCase == null) {
throw new SystemException("Campaing " + owner + " has no cases with ID " + row.accessCertCaseCid);
throw new SystemException("Campaign " + owner + " has no cases with ID " + row.accessCertCaseCid);
}
PrismContainer<AccessCertificationWorkItemType> container = aCase.findContainer(AccessCertificationCaseType.F_WORK_ITEM);
if (container == null) {
throw new SystemException("Campaing " + owner + "has no work item for case with ID " + row.accessCertCaseCid);
throw new SystemException("Campaign " + owner + "has no work item for case with ID " + row.accessCertCaseCid);
}
PrismContainerValue<AccessCertificationWorkItemType> value = container.findValue(row.cid);
if (value == null) {
throw new SystemException("Campaing " + owner + "has no work item with ID " + row.cid);
throw new SystemException("Campaign " + owner + "has no work item with ID " + row.cid);
}
return value.asContainerable();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

/**
* Querydsl query type for {@value #TABLE_NAME} table.
*
* @param <R> type of this container row
* @param <OR> type of the owner row
*/
@SuppressWarnings("unused")
public class QContainer<R extends MContainer, OR> extends FlexibleRelationalPathBase<R>
Expand Down

0 comments on commit 28d568d

Please sign in to comment.