Skip to content

Commit

Permalink
Added m_resource.abstract column for Native repo
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Mar 22, 2023
1 parent 253523b commit 77bd7e2
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
4 changes: 4 additions & 0 deletions config/sql/native-new/postgres-new-upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ ALTER INDEX m_ref_object_modify_approverTargetOidRelationId_idx
RENAME TO m_ref_object_modify_approver_targetOidRelationId_idx;
$aa$);

-- Making resource.abstract queryable
call apply_change(15, $aa$
ALTER TABLE m_resource ADD abstract BOOLEAN;
$aa$);

-- WRITE CHANGES ABOVE ^^
-- IMPORTANT: update apply_change number at the end of postgres-new.sql
Expand Down
7 changes: 4 additions & 3 deletions config/sql/native-new/postgres-new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ CREATE TABLE m_resource (
connectorRefTargetOid UUID,
connectorRefTargetType ObjectType,
connectorRefRelationId INTEGER REFERENCES m_uri(id),
template BOOLEAN
template BOOLEAN,
abstract BOOLEAN
)
INHERITS (m_assignment_holder);

Expand Down Expand Up @@ -1742,7 +1743,7 @@ CREATE TABLE m_assignment (
containerType ContainerType NOT NULL CHECK (containerType IN ('ASSIGNMENT', 'INDUCEMENT')),
ownerType ObjectType NOT NULL,
lifecycleState TEXT,
orderValue INTEGER,
orderValue INTEGER, -- item "order"
orgRefTargetOid UUID,
orgRefTargetType ObjectType,
orgRefRelationId INTEGER REFERENCES m_uri(id),
Expand Down Expand Up @@ -2084,4 +2085,4 @@ END $$;

-- Initializing the last change number used in postgres-new-upgrade.sql.
-- This is important to avoid applying any change more than once.
call apply_change(14, $$ SELECT 1 $$, true);
call apply_change(15, $$ SELECT 1 $$, true);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -28,4 +28,5 @@ public class MResource extends MObject {
public MObjectType connectorRefTargetType;
public Integer connectorRefRelationId;
public Boolean template;
public Boolean _abstract;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -43,6 +43,7 @@ public class QResource extends QAssignmentHolder<MResource> {
public static final ColumnMetadata CONNECTOR_REF_RELATION_ID =
ColumnMetadata.named("connectorRefRelationId").ofType(Types.INTEGER);
public static final ColumnMetadata TEMPLATE = ColumnMetadata.named("template").ofType(Types.BOOLEAN);
public static final ColumnMetadata ABSTRACT = ColumnMetadata.named("abstract").ofType(Types.BOOLEAN);

public final EnumPath<ResourceAdministrativeStateType> businessAdministrativeState =
createEnum("businessAdministrativeState", ResourceAdministrativeStateType.class,
Expand All @@ -62,6 +63,7 @@ public class QResource extends QAssignmentHolder<MResource> {
public final NumberPath<Integer> connectorRefRelationId =
createInteger("connectorRefRelationId", CONNECTOR_REF_RELATION_ID);
public final BooleanPath template = createBoolean("template", TEMPLATE);
public final BooleanPath _abstract = createBoolean("_abstract", ABSTRACT);

public QResource(String variable) {
this(variable, DEFAULT_SCHEMA_NAME, TABLE_NAME);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -68,6 +68,7 @@ private QResourceMapping(@NotNull SqaleRepoContext repositoryContext) {
q -> q.connectorRefRelationId,
QConnectorMapping::get);
addItemMapping(F_TEMPLATE, booleanMapper(q -> q.template));
addItemMapping(F_ABSTRACT, booleanMapper(q -> q._abstract));
}

@Override
Expand Down Expand Up @@ -106,6 +107,7 @@ public MResource newRowObject() {
t -> row.connectorRefTargetType = t,
r -> row.connectorRefRelationId = r);
row.template = schemaObject.isTemplate();
row._abstract = schemaObject.isAbstract();

return row;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,9 @@ protected final <T extends ObjectType> SearchResultList<T> searchObjects(
}

protected SearchResultList<UserType> searchUsersTest(String description,
Function<S_FilterEntryOrEmpty, S_QueryExit> filter, String... expectedOids)
Function<S_FilterEntryOrEmpty, S_QueryExit> filterFunction, String... expectedOids)
throws SchemaException {
return searchObjectTest(description, UserType.class, filter, expectedOids);
return searchObjectTest(description, UserType.class, filterFunction, expectedOids);
}

/**
Expand All @@ -467,13 +467,13 @@ protected SearchResultList<UserType> searchUsersTest(String description,
*/
protected <T extends ObjectType> SearchResultList<T> searchObjectTest(
String description, Class<T> type,
Function<S_FilterEntryOrEmpty, S_QueryExit> filter, String... expectedOids)
Function<S_FilterEntryOrEmpty, S_QueryExit> filterFunction, String... expectedOids)
throws SchemaException {
String typeName = type.getSimpleName().replaceAll("Type$", "").toLowerCase();
when("searching for " + typeName + "(s) " + description);
OperationResult operationResult = createOperationResult();
SearchResultList<T> result = searchObjects(type,
filter.apply(prismContext.queryFor(type)).build(),
filterFunction.apply(prismContext.queryFor(type)).build(),
operationResult);

then(typeName + "(s) " + description + " are returned");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand Down Expand Up @@ -1300,7 +1300,8 @@ public void test810ResourceAndItsBusinessApproverReferences() throws Exception {
.administrativeAvailabilityStatus(AdministrativeAvailabilityStatusType.MAINTENANCE))
.connectorRef(connectorOid.toString(),
ConnectorType.COMPLEX_TYPE, connectorRelation)
.template(false);
.template(false)
._abstract(false);

when("adding it to the repository");
repositoryService.addObject(resource.asPrismObject(), null, result);
Expand All @@ -1319,6 +1320,7 @@ public void test810ResourceAndItsBusinessApproverReferences() throws Exception {
assertThat(row.connectorRefTargetType).isEqualTo(MObjectType.CONNECTOR);
assertCachedUri(row.connectorRefRelationId, connectorRelation);
assertThat(row.template).isFalse();
assertThat(row._abstract).isFalse();

QObjectReference<?> ref = QObjectReferenceMapping
.getForResourceBusinessConfigurationApprover().defaultAlias();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,14 @@ public void test922SearchFocusTypeFindsOnlyFocusObjects()
assertThat(result).hasSizeLessThan((int) count(QAssignmentHolder.CLASS));
}

@Test
public void test930ResourceQuery() throws SchemaException {
expect("resource query with abstract and template conditions works");
searchObjectTest("by abstract and template items", ResourceType.class,
f -> f.item(ResourceType.F_ABSTRACT).eq(true)
.and().item(ResourceType.F_TEMPLATE).eq(true));
}

@Test
public void test950SearchOperationUpdatesPerformanceMonitor() throws SchemaException {
OperationResult operationResult = createOperationResult();
Expand Down

0 comments on commit 77bd7e2

Please sign in to comment.