diff --git a/repo/repo-sqale/sql/pgnew-repo.sql b/repo/repo-sqale/sql/pgnew-repo.sql index b791ba8084d..9498ce1bd49 100644 --- a/repo/repo-sqale/sql/pgnew-repo.sql +++ b/repo/repo-sqale/sql/pgnew-repo.sql @@ -1093,19 +1093,19 @@ CREATE INDEX iCaseTypeRequestorRefTargetOid ON m_case(requestorRef_targetOid); CREATE INDEX iCaseTypeCloseTimestamp ON m_case(closeTimestamp); CREATE TABLE m_case_wi ( - id INTEGER NOT NULL, - owner_oid UUID NOT NULL, - closeTimestamp TIMESTAMPTZ, - createTimestamp TIMESTAMPTZ, - deadline TIMESTAMPTZ, - originalAssigneeRef_relation VARCHAR(157), - originalAssigneeRef_targetOid UUID, - originalAssigneeRef_targetType INTEGER, - outcome TEXT, - performerRef_relation VARCHAR(157), - performerRef_targetOid UUID, - performerRef_targetType INTEGER, - stageNumber INTEGER, + id INTEGER NOT NULL, + owner_oid UUID NOT NULL, + closeTimestamp TIMESTAMPTZ, + createTimestamp TIMESTAMPTZ, + deadline TIMESTAMPTZ, + originalAssigneeRefTargetOid UUID, + originalAssigneeRefTargetType ObjectType, + originalAssigneeRefRelationId INTEGER REFERENCES m_uri(id), + outcome TEXT, + performerRefTargetOid UUID, + performerRefTargetType ObjectType, + performerRefRelationId INTEGER REFERENCES m_uri(id), + stageNumber INTEGER, PRIMARY KEY (owner_oid, id) ); diff --git a/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/QCaseMapping.java b/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/QCaseMapping.java index dbf13db3fbd..df780cc9273 100644 --- a/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/QCaseMapping.java +++ b/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/QCaseMapping.java @@ -6,19 +6,15 @@ */ package com.evolveum.midpoint.repo.sqale.qmodel.cases; -import static com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType.*; - -import com.evolveum.midpoint.repo.sqale.qmodel.task.MTask; - +import com.evolveum.midpoint.repo.sqale.SqaleRepoContext; +import com.evolveum.midpoint.repo.sqale.qmodel.object.QObjectMapping; import com.evolveum.midpoint.repo.sqlbase.JdbcSession; - import com.evolveum.midpoint.util.MiscUtil; +import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType; import org.jetbrains.annotations.NotNull; -import com.evolveum.midpoint.repo.sqale.SqaleRepoContext; -import com.evolveum.midpoint.repo.sqale.qmodel.object.QObjectMapping; -import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType; +import static com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType.*; /** * Mapping between {@link QCase} and {@link CaseType}. diff --git a/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/MCaseWorkItem.java b/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/MCaseWorkItem.java new file mode 100644 index 00000000000..fbf629657a7 --- /dev/null +++ b/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/MCaseWorkItem.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2010-2021 Evolveum and contributors + * + * This work is dual-licensed under the Apache License 2.0 + * and European Union Public License. See LICENSE file for details. + */ +package com.evolveum.midpoint.repo.sqale.qmodel.cases.workitem; + +import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainer; +import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType; + +import java.time.Instant; +import java.util.UUID; + +/** + * Querydsl "row bean" type related to {@link QCaseWorkItem}. + */ +public class MCaseWorkItem extends MContainer { + + public Instant closeTimestamp; + public Instant createTimestamp; + public Instant deadline; + public UUID originalAssigneeRefTargetOid; + public MObjectType originalAssigneeRefTargetType; + public Integer originalAssigneeRefRelationId; + public String outcome; + public UUID performerRefTargetOid; + public MObjectType performerRefTargetType; + public Integer performerRefRelationId; + public Integer stageNumber; +} diff --git a/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/QCaseWorkItem.java b/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/QCaseWorkItem.java new file mode 100644 index 00000000000..ec24d0b0035 --- /dev/null +++ b/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/QCaseWorkItem.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2010-2021 Evolveum and contributors + * + * This work is dual-licensed under the Apache License 2.0 + * and European Union Public License. See LICENSE file for details. + */ +package com.evolveum.midpoint.repo.sqale.qmodel.cases.workitem; + +import com.evolveum.midpoint.repo.sqale.qmodel.assignment.MAssignment; +import com.evolveum.midpoint.repo.sqale.qmodel.cases.MCase; +import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainer; +import com.evolveum.midpoint.repo.sqale.qmodel.object.MObject; +import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType; +import com.evolveum.midpoint.repo.sqlbase.querydsl.JsonbPath; +import com.evolveum.midpoint.repo.sqlbase.querydsl.UuidPath; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.TimeIntervalStatusType; + +import com.querydsl.core.types.dsl.*; +import com.querydsl.sql.ColumnMetadata; + +import java.sql.Types; +import java.time.Instant; + +import static com.evolveum.midpoint.repo.sqlbase.querydsl.JsonbPath.JSONB_TYPE; + +/** + * Querydsl query type for {@value #TABLE_NAME} table. + */ +@SuppressWarnings("unused") +public class QCaseWorkItem extends QContainer { + + private static final long serialVersionUID = 341727922218837393L; + + /** + * If `QCaseWorkItem.class` is not enough because of generics, try `QCaseWorkItem.CLASS`. + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static final Class> CLASS = (Class) QContainer.class; + + public static final String TABLE_NAME = "m_case_wi"; + + public static final ColumnMetadata CLOSE_TIMESTAMP = + ColumnMetadata.named("closeTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE); + public static final ColumnMetadata CREATE_TIMESTAMP = + ColumnMetadata.named("createTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE); + public static final ColumnMetadata DEADLINE = + ColumnMetadata.named("deadline").ofType(Types.TIMESTAMP_WITH_TIMEZONE); + public static final ColumnMetadata ORIGINAL_ASSIGNEE_REF_TARGET_OID = + ColumnMetadata.named("originalAssigneeRefTargetOid").ofType(UuidPath.UUID_TYPE); + public static final ColumnMetadata ORIGINAL_ASSIGNEE_REF_TARGET_TYPE = + ColumnMetadata.named("originalAssigneeRefTargetType").ofType(Types.OTHER); + public static final ColumnMetadata ORIGINAL_ASSIGNEE_REF_RELATION_ID = + ColumnMetadata.named("originalAssigneeRefRelationId").ofType(Types.INTEGER); + public static final ColumnMetadata OUTCOME = + ColumnMetadata.named("outcome").ofType(Types.VARCHAR); + public static final ColumnMetadata PERFORMER_REF_TARGET_OID = + ColumnMetadata.named("performerRefTargetOid").ofType(UuidPath.UUID_TYPE); + public static final ColumnMetadata PERFORMER_REF_TARGET_TYPE = + ColumnMetadata.named("performerRefTargetType").ofType(Types.OTHER); + public static final ColumnMetadata PERFORMER_REF_RELATION_ID = + ColumnMetadata.named("performerRefRelationId").ofType(Types.INTEGER); + public static final ColumnMetadata STAGE_NUMBER = + ColumnMetadata.named("stageNumber").ofType(Types.INTEGER); + + // attributes + + public final DateTimePath closeTimestamp = + createInstant("closeTimestamp", CLOSE_TIMESTAMP); + public final DateTimePath createTimestamp = + createInstant("createTimestamp", CREATE_TIMESTAMP); + public final DateTimePath deadline = + createInstant("deadline", DEADLINE); + public final UuidPath originalAssigneeRefTargetOid = + createUuid("originalAssigneeRefTargetOid", ORIGINAL_ASSIGNEE_REF_TARGET_OID); + public final EnumPath originalAssigneeRefTargetType = + createEnum("originalAssigneeRefTargetType", MObjectType.class, ORIGINAL_ASSIGNEE_REF_TARGET_TYPE); + public final NumberPath originalAssigneeRefRelationId = + createInteger("originalAssigneeRefRelationId", ORIGINAL_ASSIGNEE_REF_RELATION_ID); + public final StringPath outcome = createString("outcome", OUTCOME); + public final UuidPath performerRefTargetOid = + createUuid("performerRefTargetOid", PERFORMER_REF_TARGET_OID); + public final EnumPath performerRefTargetType = + createEnum("performerRefTargetType", MObjectType.class, PERFORMER_REF_TARGET_TYPE); + public final NumberPath performerRefRelationId = + createInteger("performerRefRelationId", PERFORMER_REF_RELATION_ID); + public final NumberPath stageNumber = + createInteger("stageNumber", STAGE_NUMBER); + + + public QCaseWorkItem(String variable) { + this(variable, DEFAULT_SCHEMA_NAME, TABLE_NAME); + } + + public QCaseWorkItem(String variable, String schema, String table) { + super(MCaseWorkItem.class, variable, schema, table); + } + + @Override + public BooleanExpression isOwnedBy(OR ownerRow) { + return ownerOid.eq(ownerRow.oid); + } +} diff --git a/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/QCaseWorkItemMapping.java b/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/QCaseWorkItemMapping.java new file mode 100644 index 00000000000..01007405659 --- /dev/null +++ b/repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/qmodel/cases/workitem/QCaseWorkItemMapping.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2010-2021 Evolveum and contributors + * + * This work is dual-licensed under the Apache License 2.0 + * and European Union Public License. See LICENSE file for details. + */ +package com.evolveum.midpoint.repo.sqale.qmodel.cases.workitem; + +import com.evolveum.midpoint.repo.sqale.SqaleRepoContext; +import com.evolveum.midpoint.repo.sqale.qmodel.cases.MCase; +import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerType; +import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerMapping; +import com.evolveum.midpoint.repo.sqlbase.JdbcSession; +import com.evolveum.midpoint.util.MiscUtil; +import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType; + +import org.jetbrains.annotations.NotNull; + +import static com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType.*; + +/** + * Mapping between {@link QCaseWorkItem} and {@link CaseWorkItemType}. + * + * @param type of the owner row + */ +public class QCaseWorkItemMapping + extends QContainerMapping, MCaseWorkItem, OR> { + + public static final String DEFAULT_ALIAS_NAME = "cswi"; + + private final MContainerType containerType; + + // We can't declare Class>.class, so we cheat a bit. + @SuppressWarnings({ "unchecked", "rawtypes" }) + private QCaseWorkItemMapping( + @NotNull MContainerType containerType, + @NotNull SqaleRepoContext repositoryContext) { + super(QCaseWorkItem.TABLE_NAME, DEFAULT_ALIAS_NAME, + CaseWorkItemType.class, (Class) QCaseWorkItem.class, repositoryContext); + this.containerType = containerType; + + addItemMapping(F_CLOSE_TIMESTAMP, timestampMapper(q -> q.closeTimestamp)); + addItemMapping(F_CREATE_TIMESTAMP, timestampMapper(q -> q.createTimestamp)); + addItemMapping(F_DEADLINE, timestampMapper(q -> q.deadline)); + + addItemMapping(F_ORIGINAL_ASSIGNEE_REF, refMapper( + q -> q.originalAssigneeRefTargetOid, + q -> q.originalAssigneeRefTargetType, + q -> q.originalAssigneeRefRelationId)); + + // TODO: OUTCOME +// addItemMapping(F_OUTCOME, stringMapper(q -> q.outcome)); + + addItemMapping(F_PERFORMER_REF, refMapper( + q -> q.performerRefTargetOid, + q -> q.performerRefTargetType, + q -> q.performerRefRelationId)); + + addItemMapping(F_STAGE_NUMBER, integerMapper(q -> q.stageNumber)); + + } + + @Override + protected QCaseWorkItem newAliasInstance(String alias) { + return new QCaseWorkItem<>(alias); + } + + @Override + public MCaseWorkItem newRowObject() { + MCaseWorkItem row = new MCaseWorkItem(); + row.containerType = this.containerType; + return row; + } + + @Override + public MCaseWorkItem newRowObject(OR ownerRow) { + MCaseWorkItem row = newRowObject(); + row.ownerOid = ownerRow.oid; + return row; + } + + // about duplication see the comment in QObjectMapping.toRowObjectWithoutFullObject + @SuppressWarnings("DuplicatedCode") + @Override + public MCaseWorkItem insert(CaseWorkItemType workItem, OR ownerRow, JdbcSession jdbcSession) { + MCaseWorkItem row = initRowObject(workItem, ownerRow); + + row.closeTimestamp = MiscUtil.asInstant(workItem.getCloseTimestamp()); + row.createTimestamp = MiscUtil.asInstant(workItem.getCreateTimestamp()); + row.deadline = MiscUtil.asInstant(workItem.getDeadline()); + setReference(workItem.getOriginalAssigneeRef(), + o -> row.originalAssigneeRefTargetOid = o, + t -> row.originalAssigneeRefTargetType = t, + r -> row.originalAssigneeRefRelationId = r); + + // TODO: Outcome + + setReference(workItem.getPerformerRef(), + o -> row.performerRefTargetOid = o, + t -> row.performerRefTargetType = t, + r -> row.performerRefRelationId = r); + row.stageNumber = workItem.getStageNumber(); + + insert(row, jdbcSession); + + return row; + } +}