Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 24, 2022
2 parents 68831ea + ce9a772 commit f71c8fb
Show file tree
Hide file tree
Showing 16 changed files with 330 additions and 247 deletions.
19 changes: 19 additions & 0 deletions config/sql/native-new/postgres-new-upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ CREATE INDEX m_message_template_createTimestamp_idx ON m_message_template (creat
CREATE INDEX m_message_template_modifyTimestamp_idx ON m_message_template (modifyTimestamp);
$aa$);

-- MID-7487 Identity matching
call apply_change(4, $aa$
CREATE TYPE CorrelationSituationType AS ENUM ('UNCERTAIN', 'EXISTING_OWNER', 'NO_OWNER', 'ERROR');
$aa$);

call apply_change(5, $aa$
ALTER TABLE m_shadow
ADD COLUMN correlationStartTimestamp TIMESTAMPTZ,
ADD COLUMN correlationEndTimestamp TIMESTAMPTZ,
ADD COLUMN correlationCaseOpenTimestamp TIMESTAMPTZ,
ADD COLUMN correlationCaseCloseTimestamp TIMESTAMPTZ,
ADD COLUMN correlationSituation CorrelationSituationType;

CREATE INDEX m_shadow_correlationStartTimestamp_idx ON m_shadow (correlationStartTimestamp);
CREATE INDEX m_shadow_correlationEndTimestamp_idx ON m_shadow (correlationEndTimestamp);
CREATE INDEX m_shadow_correlationCaseOpenTimestamp_idx ON m_shadow (correlationCaseOpenTimestamp);
CREATE INDEX m_shadow_correlationCaseCloseTimestamp_idx ON m_shadow (correlationCaseCloseTimestamp);
$aa$);

-- WRITE CHANGES ABOVE ^^
-- IMPORTANT: update apply_change number at the end of postgres-new.sql
-- to match the number used in the last change here!
16 changes: 14 additions & 2 deletions config/sql/native-new/postgres-new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ CREATE TYPE ActivationStatusType AS ENUM ('ENABLED', 'DISABLED', 'ARCHIVED');

CREATE TYPE AvailabilityStatusType AS ENUM ('DOWN', 'UP', 'BROKEN');

CREATE TYPE CorrelationSituationType AS ENUM ('UNCERTAIN', 'EXISTING_OWNER', 'NO_OWNER', 'ERROR');

CREATE TYPE LockoutStatusType AS ENUM ('NORMAL', 'LOCKED');

CREATE TYPE NodeOperationalStateType AS ENUM ('UP', 'DOWN', 'STARTING');
Expand Down Expand Up @@ -875,7 +877,13 @@ CREATE TABLE m_shadow (
primaryIdentifierValue TEXT,
synchronizationSituation SynchronizationSituationType,
synchronizationTimestamp TIMESTAMPTZ,
attributes JSONB
attributes JSONB,
-- correlation
correlationStartTimestamp TIMESTAMPTZ,
correlationEndTimestamp TIMESTAMPTZ,
correlationCaseOpenTimestamp TIMESTAMPTZ,
correlationCaseCloseTimestamp TIMESTAMPTZ,
correlationSituation CorrelationSituationType
)
INHERITS (m_object);

Expand All @@ -899,6 +907,10 @@ CREATE INDEX m_shadow_fullTextInfo_idx ON m_shadow USING gin (fullTextInfo gin_t
CREATE INDEX m_shadow_resourceRefTargetOid_idx ON m_shadow (resourceRefTargetOid);
CREATE INDEX m_shadow_createTimestamp_idx ON m_shadow (createTimestamp);
CREATE INDEX m_shadow_modifyTimestamp_idx ON m_shadow (modifyTimestamp);
CREATE INDEX m_shadow_correlationStartTimestamp_idx ON m_shadow (correlationStartTimestamp);
CREATE INDEX m_shadow_correlationEndTimestamp_idx ON m_shadow (correlationEndTimestamp);
CREATE INDEX m_shadow_correlationCaseOpenTimestamp_idx ON m_shadow (correlationCaseOpenTimestamp);
CREATE INDEX m_shadow_correlationCaseCloseTimestamp_idx ON m_shadow (correlationCaseCloseTimestamp);

/*
TODO: reconsider, especially boolean things like dead (perhaps WHERE in other indexes?)
Expand Down Expand Up @@ -1889,4 +1901,4 @@ END $$;
-- endregion

-- Initializing the last change number used in postgres-new-upgrade.sql.
call apply_change(3, $$ SELECT 1 $$, true);
call apply_change(5, $$ SELECT 1 $$, true);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 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 @@ -29,7 +29,6 @@ public class ExtItemCache {

private final Map<Integer, MExtItem> idToExtItem = new ConcurrentHashMap<>();
private final Map<MExtItem.Key, MExtItem> keyToExtItem = new ConcurrentHashMap<>();
private final Map<MExtItem.ItemNameKey, MExtItem> itemNameToExtItem = new ConcurrentHashMap<>();

// WARNING: Each .get() creates new connection, always use in try-with-resource block!
private Supplier<JdbcSession> jdbcSessionSupplier;
Expand All @@ -44,7 +43,6 @@ public synchronized void initialize(Supplier<JdbcSession> jdbcSessionSupplier) {
// this can be called repeatedly in tests, so the clear may be necessary
idToExtItem.clear();
keyToExtItem.clear();
itemNameToExtItem.clear();

QExtItem uri = QExtItem.DEFAULT;
List<MExtItem> result;
Expand All @@ -65,7 +63,6 @@ public synchronized void initialize(Supplier<JdbcSession> jdbcSessionSupplier) {
private void updateMaps(MExtItem row) {
idToExtItem.put(row.id, row);
keyToExtItem.put(row.key(), row);
itemNameToExtItem.put(row.itemNameKey(), row);
}

public synchronized @NotNull MExtItem resolveExtensionItem(@NotNull MExtItem.Key extItemKey) {
Expand Down Expand Up @@ -121,32 +118,6 @@ private MExtItem retrieveFromDb(@NotNull MExtItem.Key key) {
return row;
}

public @Nullable MExtItem getExtensionItem(@NotNull MExtItem.ItemNameKey extItemKey) {
if (jdbcSessionSupplier == null) {
throw new IllegalStateException("Ext item cache was not initialized yet!");
}

MExtItem extItem = itemNameToExtItem.get(extItemKey);
if (extItem != null) {
return extItem;
}

try (JdbcSession jdbcSession = jdbcSessionSupplier.get().startReadOnlyTransaction()) {
extItem = jdbcSession.newQuery()
.from(QExtItem.DEFAULT)
.select(QExtItem.DEFAULT)
.where(QExtItem.DEFAULT.itemName.eq(extItemKey.itemName)
.and(QExtItem.DEFAULT.holderType.eq(extItemKey.holderType)))
// TODO let's consider fetchOne that throws if count > 1, right now we're not confident enough to do so.
.fetchFirst();
}

if (extItem != null) {
updateMaps(extItem);
}
return extItem;
}

public @Nullable MExtItem getExtensionItem(Integer id) {
if (jdbcSessionSupplier == null) {
throw new IllegalStateException("Ext item cache was not initialized yet!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 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 @@ -71,12 +71,13 @@ public SqaleRepoContext(
querydslConfig.register(new EnumAsObjectType<>(AvailabilityStatusType.class));
querydslConfig.register(new EnumAsObjectType<>(ChangeType.class)); // used in old audit
querydslConfig.register(new EnumAsObjectType<>(ChangeTypeType.class));
querydslConfig.register(new EnumAsObjectType<>(CorrelationSituationType.class));
querydslConfig.register(new EnumAsObjectType<>(LockoutStatusType.class));
querydslConfig.register(new EnumAsObjectType<>(MContainerType.class));
querydslConfig.register(new EnumAsObjectType<>(MExtItemHolderType.class));
querydslConfig.register(new EnumAsObjectType<>(MExtItemCardinality.class));
querydslConfig.register(new EnumAsObjectType<>(MObjectType.class));
querydslConfig.register(new EnumAsObjectType<>(MReferenceType.class));
querydslConfig.register(new EnumAsObjectType<>(LockoutStatusType.class));
querydslConfig.register(new EnumAsObjectType<>(NodeOperationalStateType.class));
querydslConfig.register(new EnumAsObjectType<>(OperationExecutionRecordTypeType.class));
querydslConfig.register(new EnumAsObjectType<>(OperationResultStatusType.class));
Expand Down Expand Up @@ -159,10 +160,6 @@ public QName resolveUriIdToQName(Integer uriId) {
return extItemCache.resolveExtensionItem(extItemKey);
}

public @Nullable MExtItem getExtensionItem(@NotNull MExtItem.ItemNameKey extItemKey) {
return extItemCache.getExtensionItem(extItemKey);
}

public @Nullable MExtItem getExtensionItem(Integer id) {
return extItemCache.getExtensionItem(id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 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 All @@ -9,10 +9,7 @@
import java.util.Objects;
import javax.xml.namespace.QName;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

Expand Down Expand Up @@ -51,13 +48,6 @@ public Key key() {
return key;
}

public ItemNameKey itemNameKey() {
ItemNameKey key = new ItemNameKey();
key.itemName = this.itemName;
key.holderType = this.holderType;
return key;
}

public static class Key {
public String itemName;
public String valueType;
Expand Down Expand Up @@ -86,30 +76,6 @@ public int hashCode() {
}
}

public static class ItemNameKey {
public String itemName;
public MExtItemHolderType holderType;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ItemNameKey key = (ItemNameKey) o;

return Objects.equals(itemName, key.itemName)
&& holderType == key.holderType;
}

@Override
public int hashCode() {
return Objects.hash(itemName, holderType);
}
}

/** Creates ext item key from item definition and holder type. */
public static Key keyFrom(ItemDefinition<?> definition, MExtItemHolderType holderType) {
return keyFrom(definition, holderType,
Expand All @@ -127,13 +93,6 @@ public static Key keyFrom(ItemDefinition<?> definition, MExtItemHolderType holde
return key;
}

public static @NotNull ItemNameKey itemNameKey(ItemName elementName, MExtItemHolderType type) {
ItemNameKey ret = new ItemNameKey();
ret.itemName = QNameUtil.qNameToUri(elementName);
ret.holderType = type;
return ret;
}

@Override
public String toString() {
return "MExtItem{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 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 All @@ -12,6 +12,7 @@
import com.evolveum.midpoint.repo.sqale.jsonb.Jsonb;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObject;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CorrelationSituationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType;

Expand All @@ -35,4 +36,10 @@ public class MShadow extends MObject {
public SynchronizationSituationType synchronizationSituation;
public Instant synchronizationTimestamp;
public Jsonb attributes;
// correlation
public Instant correlationStartTimestamp;
public Instant correlationEndTimestamp;
public Instant correlationCaseOpenTimestamp;
public Instant correlationCaseCloseTimestamp;
public CorrelationSituationType correlationSituation;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 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 All @@ -18,6 +18,7 @@
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.evolveum.midpoint.xml.ns._public.common.common_3.CorrelationSituationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType;

Expand Down Expand Up @@ -60,6 +61,17 @@ public class QShadow extends QObject<MShadow> {
ColumnMetadata.named("synchronizationTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);
public static final ColumnMetadata ATTRIBUTES =
ColumnMetadata.named("attributes").ofType(JSONB_TYPE);
// correlation
public static final ColumnMetadata CORRELATION_START_TIMESTAMP =
ColumnMetadata.named("correlationStartTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);
public static final ColumnMetadata CORRELATION_END_TIMESTAMP =
ColumnMetadata.named("correlationEndTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);
public static final ColumnMetadata CORRELATION_CASE_OPEN_TIMESTAMP =
ColumnMetadata.named("correlationCaseOpenTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);
public static final ColumnMetadata CORRELATION_CASE_CLOSE_TIMESTAMP =
ColumnMetadata.named("correlationCaseCloseTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);
public static final ColumnMetadata CORRELATION_SITUATION =
ColumnMetadata.named("correlationSituation").ofType(Types.OTHER);

// columns and relations

Expand Down Expand Up @@ -89,6 +101,17 @@ public class QShadow extends QObject<MShadow> {
createInstant("synchronizationTimestamp", SYNCHRONIZATION_TIMESTAMP);
public final JsonbPath attributes =
addMetadata(add(new JsonbPath(forProperty("attributes"))), ATTRIBUTES);
// correlation
public final DateTimePath<Instant> correlationStartTimestamp =
createInstant("correlationStartTimestamp", CORRELATION_START_TIMESTAMP);
public final DateTimePath<Instant> correlationEndTimestamp =
createInstant("correlationEndTimestamp", CORRELATION_END_TIMESTAMP);
public final DateTimePath<Instant> correlationCaseOpenTimestamp =
createInstant("correlationCaseOpenTimestamp", CORRELATION_CASE_OPEN_TIMESTAMP);
public final DateTimePath<Instant> correlationCaseCloseTimestamp =
createInstant("correlationCaseCloseTimestamp", CORRELATION_CASE_CLOSE_TIMESTAMP);
public final EnumPath<CorrelationSituationType> correlationSituation =
createEnum("correlationSituation", CorrelationSituationType.class, CORRELATION_SITUATION);

public QShadow(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-2021 Evolveum and contributors
* Copyright (C) 2010-2022 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 All @@ -8,13 +8,8 @@

import static com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Objects;
import javax.xml.namespace.QName;

import com.querydsl.core.Tuple;
Expand Down Expand Up @@ -46,6 +41,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowCorrelationStateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

/**
Expand Down Expand Up @@ -91,6 +87,17 @@ private QShadowMapping(@NotNull SqaleRepoContext repositoryContext) {
addItemMapping(F_SYNCHRONIZATION_TIMESTAMP,
timestampMapper(q -> q.synchronizationTimestamp));
addExtensionMapping(F_ATTRIBUTES, MExtItemHolderType.ATTRIBUTES, q -> q.attributes);
addNestedMapping(F_CORRELATION, ShadowCorrelationStateType.class)
.addItemMapping(ShadowCorrelationStateType.F_CORRELATION_START_TIMESTAMP,
timestampMapper(q -> q.correlationStartTimestamp))
.addItemMapping(ShadowCorrelationStateType.F_CORRELATION_END_TIMESTAMP,
timestampMapper(q -> q.correlationEndTimestamp))
.addItemMapping(ShadowCorrelationStateType.F_CORRELATION_CASE_OPEN_TIMESTAMP,
timestampMapper(q -> q.correlationCaseOpenTimestamp))
.addItemMapping(ShadowCorrelationStateType.F_CORRELATION_CASE_CLOSE_TIMESTAMP,
timestampMapper(q -> q.correlationCaseCloseTimestamp))
.addItemMapping(ShadowCorrelationStateType.F_SITUATION,
enumMapper(q -> q.correlationSituation));

// Item mapping to update the count, relation resolver for query with EXISTS filter.
addItemMapping(F_PENDING_OPERATION, new SqaleItemSqlMapper<>(
Expand Down Expand Up @@ -131,6 +138,14 @@ public MShadow newRowObject() {
row.synchronizationSituation = shadow.getSynchronizationSituation();
row.synchronizationTimestamp = MiscUtil.asInstant(shadow.getSynchronizationTimestamp());
row.attributes = processExtensions(shadow.getAttributes(), MExtItemHolderType.ATTRIBUTES);
ShadowCorrelationStateType correlation = shadow.getCorrelation();
if (correlation != null) {
row.correlationStartTimestamp = MiscUtil.asInstant(correlation.getCorrelationStartTimestamp());
row.correlationEndTimestamp = MiscUtil.asInstant(correlation.getCorrelationEndTimestamp());
row.correlationCaseOpenTimestamp = MiscUtil.asInstant(correlation.getCorrelationCaseOpenTimestamp());
row.correlationCaseCloseTimestamp = MiscUtil.asInstant(correlation.getCorrelationCaseCloseTimestamp());
row.correlationSituation = correlation.getSituation();
}
return row;
}

Expand Down

0 comments on commit f71c8fb

Please sign in to comment.