Skip to content

Commit

Permalink
SimulationResult: Add rootTaskRef, end, start timestamp to repository
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
  • Loading branch information
tonydamage committed Jan 19, 2023
1 parent cd02bd3 commit b3cd9e5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 3 deletions.
7 changes: 6 additions & 1 deletion config/sql/native-new/postgres-new-upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ CREATE TABLE m_simulation_result (
oid UUID NOT NULL PRIMARY KEY REFERENCES m_object_oid(oid),
objectType ObjectType GENERATED ALWAYS AS ('SIMULATION_RESULT') STORED
CHECK (objectType = 'SIMULATION_RESULT'),
partitioned boolean
partitioned boolean,
rootTaskRefTargetOid UUID,
rootTaskRefTargetType ObjectType,
rootTaskRefRelationId INTEGER REFERENCES m_uri(id),
startTimestamp TIMESTAMPTZ,
endTimestamp TIMESTAMPTZ
)
INHERITS (m_object);

Expand Down
7 changes: 6 additions & 1 deletion config/sql/native-new/postgres-new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,12 @@ CREATE TABLE m_simulation_result (
oid UUID NOT NULL PRIMARY KEY REFERENCES m_object_oid(oid),
objectType ObjectType GENERATED ALWAYS AS ('SIMULATION_RESULT') STORED
CHECK (objectType = 'SIMULATION_RESULT'),
partitioned boolean
partitioned boolean,
rootTaskRefTargetOid UUID,
rootTaskRefTargetType ObjectType,
rootTaskRefRelationId INTEGER REFERENCES m_uri(id),
startTimestamp TIMESTAMPTZ,
endTimestamp TIMESTAMPTZ
)
INHERITS (m_object);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
*/
package com.evolveum.midpoint.repo.sqale.qmodel.simulation;

import java.time.Instant;
import java.util.UUID;

import com.evolveum.midpoint.repo.sqale.qmodel.object.MObject;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType;

public class MSimulationResult extends MObject {

public Boolean partitioned;
public UUID rootTaskRefTargetOid;
public MObjectType rootTaskRefTargetType;
public Integer rootTaskRefRelationId;
public Instant startTimestamp;
public Instant endTimestamp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
package com.evolveum.midpoint.repo.sqale.qmodel.simulation;

import java.sql.Types;
import java.time.Instant;

import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType;
import com.evolveum.midpoint.repo.sqale.qmodel.object.QObject;
import com.evolveum.midpoint.repo.sqlbase.querydsl.UuidPath;
import com.querydsl.core.types.dsl.BooleanPath;
import com.querydsl.core.types.dsl.DateTimePath;
import com.querydsl.core.types.dsl.EnumPath;
import com.querydsl.core.types.dsl.NumberPath;
import com.querydsl.sql.ColumnMetadata;

public class QSimulationResult extends QObject<MSimulationResult> {
Expand All @@ -19,6 +25,19 @@ public class QSimulationResult extends QObject<MSimulationResult> {
public static final ColumnMetadata PARTITIONED =
ColumnMetadata.named("partitioned").ofType(Types.BOOLEAN);

public static final ColumnMetadata ROOT_TASK_REF_TARGET_OID =
ColumnMetadata.named("rootTaskRefTargetOid").ofType(UuidPath.UUID_TYPE);
public static final ColumnMetadata ROOT_TASK_REF_TARGET_TYPE =
ColumnMetadata.named("rootTaskRefTargetType").ofType(Types.OTHER);
public static final ColumnMetadata ROOT_TASK_REF_RELATION_ID =
ColumnMetadata.named("rootTaskRefRelationId").ofType(Types.INTEGER);

public static final ColumnMetadata START_TIMESTAMP =
ColumnMetadata.named("endTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);

public static final ColumnMetadata END_TIMESTAMP =
ColumnMetadata.named("endTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);

public QSimulationResult(String variable) {
this(variable, DEFAULT_SCHEMA_NAME, TABLE_NAME);
}
Expand All @@ -29,4 +48,14 @@ public QSimulationResult(String variable, String schema, String table) {

public final BooleanPath partitioned = createBoolean("partitioned", PARTITIONED);

public final DateTimePath<Instant> startTimestamp = createInstant("startTimestamp", START_TIMESTAMP);
public final DateTimePath<Instant> endTimestamp = createInstant("endTimestamp", END_TIMESTAMP);

public final UuidPath rootTaskRefTargetOid =
createUuid("rootTaskTargetOid", ROOT_TASK_REF_TARGET_OID);
public final EnumPath<MObjectType> rootTaskRefTargetType =
createEnum("rootTaskRefTargetType", MObjectType.class, ROOT_TASK_REF_TARGET_TYPE);
public final NumberPath<Integer> rootTaskRefRelationId =
createInteger("rootTaskRefRelationId", ROOT_TASK_REF_RELATION_ID);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.qmodel.accesscert.QAccessCertificationCaseMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.object.QObjectMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.task.QTaskMapping;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationResultProcessedObjectType;
Expand Down Expand Up @@ -42,6 +44,17 @@ private QSimulationResultMapping(@NotNull SqaleRepoContext repositoryContext) {
QProcessedObjectMapping.initProcessedResultMapping(repositoryContext),
joinOn((o, processed) -> o.oid.eq(processed.ownerOid)));
addItemMapping(F_USE_OWN_PARTITION_FOR_PROCESSED_OBJECTS, booleanMapper(q -> q.partitioned));

// startTimestamp
addItemMapping(F_START_TIMESTAMP, timestampMapper(q -> q.startTimestamp));
addItemMapping(F_END_TIMESTAMP, timestampMapper(q -> q.endTimestamp));

// endTimestamp
addRefMapping(F_ROOT_TASK_REF,
q -> q.rootTaskRefTargetOid,
q -> q.rootTaskRefTargetType,
q -> q.rootTaskRefRelationId,
QTaskMapping::get);
}

@Override
Expand All @@ -55,7 +68,16 @@ protected QSimulationResult newAliasInstance(String alias) {
JdbcSession jdbcSession) {
MSimulationResult row = super.toRowObjectWithoutFullObject(schemaObject, jdbcSession);

//row.partitioned = schemaObject.isUseOwnPartitionForProcessedObjects();
if (schemaObject.getDefinition() != null) {
row.partitioned = schemaObject.getDefinition().isUseOwnPartitionForProcessedObjects();
}

row.startTimestamp = MiscUtil.asInstant(schemaObject.getStartTimestamp());
row.endTimestamp = MiscUtil.asInstant(schemaObject.getEndTimestamp());
setReference(schemaObject.getRootTaskRef(),
o -> row.rootTaskRefTargetOid = o,
t -> row.rootTaskRefTargetType = t,
r -> row.rootTaskRefRelationId = r);
return row;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void test100CreateSimulation() throws ObjectAlreadyExistsException, Schem

SimulationResultType obj = new SimulationResultType()
.name("Test Simulation Result")
.rootTaskRef(TEST_TAG_1, TaskType.COMPLEX_TYPE)
.processedObject(new SimulationResultProcessedObjectType()
.oid("00000000-0000-0000-0000-000000000001")
.name("System Configuration")
Expand Down

0 comments on commit b3cd9e5

Please sign in to comment.