Skip to content

Commit

Permalink
Added support for search based on event-tag-refs in processed objects
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 18, 2023
1 parent cf6445f commit a4e11a3
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 3 deletions.
14 changes: 14 additions & 0 deletions config/sql/native-new/postgres-new-upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ $aa$);
call apply_change(12, $aa$
ALTER TYPE ObjectType ADD VALUE IF NOT EXISTS 'SIMULATION_RESULT' AFTER 'SHADOW';
ALTER TYPE ObjectType ADD VALUE IF NOT EXISTS 'TAG' AFTER 'SYSTEM_CONFIGURATION';
ALTER TYPE ReferenceType ADD VALUE IF NOT EXISTS 'PROCESSED_OBJECT_EVENT_TAG' AFTER 'PROJECTION';
ALTER TYPE ContainerType ADD VALUE IF NOT EXISTS 'SIMULATION_RESULT_PROCESSED_OBJECT' AFTER 'OPERATION_EXECUTION';
$aa$);

Expand All @@ -182,6 +183,7 @@ DROP TABLE IF EXISTS m_simulation_result CASCADE;
DROP TABLE IF EXISTS m_simulation_result_processed_object_default CASCADE;
DROP TABLE IF EXISTS m_simulation_result_processed_object CASCADE;
DROP TABLE IF EXISTS m_tag CASCADE;
DROP TABLE IF EXISTS m_processed_object_event_tag;
DROP TYPE IF EXISTS ObjectProcessingStateType;
-- TODO end of the block

Expand Down Expand Up @@ -283,6 +285,18 @@ CREATE TRIGGER m_tag_oid_delete_tr AFTER DELETE ON m_tag
FOR EACH ROW EXECUTE FUNCTION delete_object_oid();


CREATE TABLE m_processed_object_event_tag (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
ownerType ObjectType, -- GENERATED ALWAYS AS ('SIMULATION_RESULT') STORED,
processedObjectCid INTEGER NOT NULL,
referenceType ReferenceType GENERATED ALWAYS AS ('PROCESSED_OBJECT_EVENT_TAG') STORED,
targetOid UUID NOT NULL, -- soft-references m_object
targetType ObjectType NOT NULL,
relationId INTEGER NOT NULL REFERENCES m_uri(id)

) PARTITION BY LIST(ownerOid);

CREATE TABLE m_processed_object_event_tag_default PARTITION OF m_processed_object_event_tag DEFAULT;

$aa$, true); -- TODO remove `true` before M2 or before RC1! (Also, the first 3 table drops)

Expand Down
15 changes: 15 additions & 0 deletions config/sql/native-new/postgres-new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ CREATE TYPE ReferenceType AS ENUM (
'DELEGATED',
'INCLUDE',
'PROJECTION',
'PROCESSED_OBJECT_EVENT_TAG',
'OBJECT_CREATE_APPROVER',
'OBJECT_MODIFY_APPROVER',
'OBJECT_PARENT_ORG',
Expand Down Expand Up @@ -1954,6 +1955,20 @@ CREATE TRIGGER m_simulation_result_delete_partition BEFORE DELETE ON m_simulatio
FOR EACH ROW EXECUTE FUNCTION m_simulation_result_delete_partition();



CREATE TABLE m_processed_object_event_tag (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
ownerType ObjectType, -- GENERATED ALWAYS AS ('SIMULATION_RESULT') STORED,
processedObjectCid INTEGER NOT NULL,
referenceType ReferenceType GENERATED ALWAYS AS ('PROCESSED_OBJECT_EVENT_TAG') STORED,
targetOid UUID NOT NULL, -- soft-references m_object
targetType ObjectType NOT NULL,
relationId INTEGER NOT NULL REFERENCES m_uri(id)

) PARTITION BY LIST(ownerOid);

CREATE TABLE m_processed_object_event_tag_default PARTITION OF m_processed_object_event_tag DEFAULT;

-- endregion

-- region Tag
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.evolveum.midpoint.repo.sqale.qmodel.simulation;

import com.evolveum.midpoint.repo.sqale.qmodel.ref.MReference;

public class MProcessedObjectEventTagReference extends MReference {

public Long processedObjectCid;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.evolveum.midpoint.repo.sqale.qmodel.simulation;

import java.sql.Types;

import com.evolveum.midpoint.repo.sqale.qmodel.ref.QReference;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.NumberPath;
import com.querydsl.sql.ColumnMetadata;
import com.querydsl.sql.PrimaryKey;

public class QProcessedObjectEventTagReference extends QReference<MProcessedObjectEventTagReference, MProcessedObject> {

private static final long serialVersionUID = -4323954643404516391L;

public static final ColumnMetadata PROCESSED_OBJECT_CID =
ColumnMetadata.named("processedObjectCid").ofType(Types.BIGINT).notNull();

public final NumberPath<Long> processedObjectCid = createLong("processedObjectCid", PROCESSED_OBJECT_CID);

public final PrimaryKey<MProcessedObjectEventTagReference> pk =
createPrimaryKey(ownerOid, processedObjectCid, referenceType, relationId, targetOid);

public QProcessedObjectEventTagReference(String variable, String tableName) {
this(variable, DEFAULT_SCHEMA_NAME, tableName);
}

public QProcessedObjectEventTagReference(String variable, String schema, String table) {
super(MProcessedObjectEventTagReference.class, variable, schema, table);
}

@Override
public BooleanExpression isOwnedBy(MProcessedObject ownerRow) {
return ownerOid.eq(ownerRow.ownerOid)
.and(processedObjectCid.eq(ownerRow.cid));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.evolveum.midpoint.repo.sqale.qmodel.simulation;

import java.awt.desktop.QuitEvent;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Supplier;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObject;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType;
import com.evolveum.midpoint.repo.sqale.qmodel.object.QObject;
import com.evolveum.midpoint.repo.sqale.qmodel.ref.QReferenceMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.tag.QTagMapping;
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryTableMapping;
import com.querydsl.core.types.Predicate;

public class QProcessedObjectEventTagReferenceMapping extends QReferenceMapping<QProcessedObjectEventTagReference, MProcessedObjectEventTagReference,
QProcessedObject, MProcessedObject> {


private static final String TABLE_NAME = "m_processed_object_event_tag";

public static QProcessedObjectEventTagReferenceMapping instance;

public static QProcessedObjectEventTagReferenceMapping init(@NotNull SqaleRepoContext repositoryContext) {
if (needsInitialization(instance, repositoryContext)) {
instance = new QProcessedObjectEventTagReferenceMapping(
TABLE_NAME, "srpoet", repositoryContext,
QTagMapping::getInstance);
}
return getInstance();
}

public static QProcessedObjectEventTagReferenceMapping getInstance() {
return Objects.requireNonNull(instance);
}

protected <TQ extends QObject<TR>, TR extends MObject> QProcessedObjectEventTagReferenceMapping(
String tableName,
String defaultAliasName,
@NotNull SqaleRepoContext repositoryContext,
@NotNull Supplier<QueryTableMapping<?, TQ, TR>> targetMappingSupplier) {
super(tableName, defaultAliasName, QProcessedObjectEventTagReference.class,
repositoryContext, targetMappingSupplier);
}

@Override
protected QProcessedObjectEventTagReference newAliasInstance(String alias) {
return new QProcessedObjectEventTagReference(alias, TABLE_NAME);
}

@Override
public MProcessedObjectEventTagReference newRowObject(MProcessedObject ownerRow) {
var row = new MProcessedObjectEventTagReference();
row.ownerOid = ownerRow.ownerOid;
row.ownerType = MObjectType.SIMULATION_RESULT;
row.processedObjectCid = ownerRow.cid;
return row;
}

@Override
public BiFunction<QProcessedObject, QProcessedObjectEventTagReference, Predicate> correlationPredicate() {
return (a, r) -> a.ownerOid.eq(r.ownerOid)
.and(a.cid.eq(r.processedObjectCid));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public QProcessedObjectMapping(@NotNull SqaleRepoContext repositoryContext) {

addItemMapping(F_STATE, enumMapper(q -> q.state));
addItemMapping(F_METRIC_IDENTIFIER, multiStringMapper(q -> q.metricIdentifiers));
addRefMapping(F_EVENT_TAG_REF, QProcessedObjectEventTagReferenceMapping.init(repositoryContext));
}

/*
Expand Down Expand Up @@ -113,6 +114,8 @@ public MProcessedObject insert(SimulationResultProcessedObjectType object, MSimu

// Before / After not serialized
insert(row, jdbcSession);
// We store event tags
storeRefs(row, object.getEventTagRef(), QProcessedObjectEventTagReferenceMapping.getInstance(), jdbcSession);
return row;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.evolveum.midpoint.repo.sqale.qmodel.tag;

import java.util.Objects;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
Expand All @@ -21,11 +23,21 @@ public class QTagMapping
extends QAssignmentHolderMapping<TagType, QTag, MObject> {

public static final String DEFAULT_ALIAS_NAME = "tag";
private static QTagMapping instance;

public static QTagMapping init(@NotNull SqaleRepoContext repositoryContext) {
return new QTagMapping(repositoryContext);
if (needsInitialization(instance, repositoryContext)) {
instance = new QTagMapping(repositoryContext);
}
return getInstance();
}

public static QTagMapping getInstance() {
return Objects.requireNonNull(instance);
}



private QTagMapping(@NotNull SqaleRepoContext repositoryContext) {
super(QTag.TABLE_NAME, DEFAULT_ALIAS_NAME,
TagType.class, QTag.class, repositoryContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -19,6 +21,8 @@

public class SimulationsBaselineTest extends SqaleRepoBaseTest {

private static final String TEST_TAG_1 = "00000000-0000-0000-0000-000000001000";
private static final String TEST_TAG_2 = "00000000-0000-0000-0000-000000002000";

@Test
public void test100CreateSimulation() throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
Expand All @@ -35,10 +39,18 @@ public void test100CreateSimulation() throws ObjectAlreadyExistsException, Schem
.oid("00000000-0000-0000-0000-000000000001")
.name("System Configuration")
.state(ObjectProcessingStateType.UNMODIFIED)
.eventTagRef(TEST_TAG_1, TagType.COMPLEX_TYPE)
.eventTagRef(TEST_TAG_2, TagType.COMPLEX_TYPE)
.metricIdentifier("disabled")
.metricIdentifier("business")
.before(systemConfiguration.clone())
);
)
.processedObject(new SimulationResultProcessedObjectType()
.oid("00000000-0000-0000-0000-000000000002")
.name("Administrator")
.before(systemConfiguration.clone())
)
;

when("result is added to the repository");
@NotNull String oid = repositoryService.addObject(obj.asPrismObject(), null, result);
Expand All @@ -52,8 +64,16 @@ public void test100CreateSimulation() throws ObjectAlreadyExistsException, Schem
assertTrue(resultReadBack.asObjectable().getProcessedObject().isEmpty());

when("processed objects are retrieved explicitly");

// And we search TEST_TAG_1 owned by created result

ObjectQuery query = PrismContext.get().queryFor(SimulationResultProcessedObjectType.class)
.ownerId(oid)
.and()
.item(SimulationResultProcessedObjectType.F_EVENT_TAG_REF).ref(TEST_TAG_1)
.build();
SearchResultList<SimulationResultProcessedObjectType> processedObjects =
repositoryService.searchContainers(SimulationResultProcessedObjectType.class, null, null, result);
repositoryService.searchContainers(SimulationResultProcessedObjectType.class, query, null, result);

then("they are present");
assertNotNull(processedObjects);
Expand Down

0 comments on commit a4e11a3

Please sign in to comment.