Skip to content

Commit

Permalink
adding repoId to schema. GUI search changed from sarch by eventIdenti…
Browse files Browse the repository at this point in the history
…fier to repoId
  • Loading branch information
katkav committed Apr 27, 2021
1 parent 9aacd03 commit aba1d48
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 33 deletions.
Expand Up @@ -146,19 +146,10 @@ private void initAuditModel() {
@Override
protected AuditEventRecordType load() {

String eventIdentifier = getEventIdentifierParameter();
AuditEventStageType stageType = getStageTypeParameter();
Long eventIdentifier = getEventIdentifierParameter();
S_MatchingRuleEntry filter = getPrismContext().queryFor(AuditEventRecordType.class)
.item(AuditEventRecordType.F_EVENT_IDENTIFIER)
.item(AuditEventRecordType.F_REPO_ID)
.eq(eventIdentifier);
//TODO: remove when we will be able to query according to "repo id".
// it is here, because there was a bug, that raw (execute_changes_raw) changes
// were executed with same eventIdentifier for both request and execution stage
if (stageType != null) {
filter = filter.and()
.item(AuditEventRecordType.F_EVENT_STAGE)
.eq(stageType);
}
ObjectQuery query = filter.build();
OperationResult result = new OperationResult(OPERATION_LOAD_AUDIT_RECORD);
SearchResultList<AuditEventRecordType> records = null;
Expand Down Expand Up @@ -187,24 +178,12 @@ protected AuditEventRecordType load() {
};
}

private String getEventIdentifierParameter() {
private Long getEventIdentifierParameter() {
StringValue param = getPageParameters().get(OnePageParameterEncoder.PARAMETER);
if (param == null) {
return null;
}
return param.toString();
}

private AuditEventStageType getStageTypeParameter() {
StringValue param = getPageParameters().get(PageAuditLogDetails.PARAMETER_STAGE);
if (param == null) {
return null;
}
String stage = param.toString();
if (stage == null) {
return null;
}
return AuditEventStageType.fromValue(stage);
return Long.valueOf(param.toString());
}

private void initLayout() {
Expand Down
Expand Up @@ -475,11 +475,8 @@ public boolean isEnabled(IModel<SelectableBean<AuditEventRecordType>> rowModel)
public void onClick(IModel<SelectableBean<AuditEventRecordType>> rowModel) {
AuditEventRecordType record = unwrapModel(rowModel);
PageParameters parameters = new PageParameters();
parameters.add(OnePageParameterEncoder.PARAMETER, record.getEventIdentifier());
if (AuditEventTypeType.EXECUTE_CHANGES_RAW == record.getEventType()) {
parameters.add(PageAuditLogDetails.PARAMETER_STAGE, record.getEventStage().value());
}
getPageBase().navigateToNext(new PageAuditLogDetails(parameters));
parameters.add(OnePageParameterEncoder.PARAMETER, record.getRepoId());
getPageBase().navigateToNext(PageAuditLogDetails.class, parameters);
}
};
}
Expand Down
11 changes: 11 additions & 0 deletions infra/schema/src/main/resources/xml/ns/public/common/audit-3.xsd
Expand Up @@ -389,6 +389,17 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="repoId" type="xsd:long" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Repository ID. This is the ID generated by and stored in DB.
</xsd:documentation>
<xsd:appinfo>
<a:since>4.3.1</a:since>
<a:displayName>AuditEventRecordType.repoId</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="auditEventRecord" type="tns:AuditEventRecordType" />
Expand Down
Expand Up @@ -6,7 +6,6 @@
*/
package com.evolveum.midpoint.audit.api;

import java.beans.Transient;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.*;
Expand Down Expand Up @@ -451,7 +450,6 @@ public void setParameter(String parameter) {
this.parameter = parameter;
}

@Transient
public Long getRepoId() {
return repoId;
}
Expand Down Expand Up @@ -542,6 +540,7 @@ public AuditEventRecordType createAuditEventRecordType() {

public AuditEventRecordType createAuditEventRecordType(boolean tolerateInconsistencies) {
AuditEventRecordType auditRecordType = new AuditEventRecordType();
auditRecordType.setRepoId(repoId);
auditRecordType.setChannel(channel);
auditRecordType.setEventIdentifier(eventIdentifier);
auditRecordType.setEventStage(AuditEventStage.toSchemaValue(eventStage));
Expand Down Expand Up @@ -615,6 +614,7 @@ public AuditEventRecordType createAuditEventRecordType(boolean tolerateInconsist
@SuppressWarnings("MethodDoesntCallSuperMethod") // it's wrong, but intended
public AuditEventRecord clone() {
AuditEventRecord clone = new AuditEventRecord();
clone.repoId = this.repoId;
clone.channel = this.channel;
clone.deltas.addAll(MiscSchemaUtil.cloneObjectDeltaOperationCollection(this.deltas));
clone.eventIdentifier = this.eventIdentifier;
Expand Down
Expand Up @@ -59,6 +59,7 @@ public class AuditSearchTest extends BaseSQLRepoTest {
private String targetOid;
private String targetOwnerOid;
private String record1EventIdentifier;
private Long record1RepoId;

@Override
public void initSystem() throws Exception {
Expand Down Expand Up @@ -204,7 +205,9 @@ public void test110SearchByEventIdentifier() throws SchemaException {

then("all audit events are returned");
assertThat(result).hasSize(1);
assertThat(result.get(0).getEventIdentifier()).isEqualTo(record1EventIdentifier);
AuditEventRecordType auditEventRecord1 = result.get(0);
assertThat(auditEventRecord1.getEventIdentifier()).isEqualTo(record1EventIdentifier);
record1RepoId = auditEventRecord1.getRepoId();
}

@Test
Expand Down Expand Up @@ -1233,6 +1236,18 @@ public void test558SearchByCustomColumnPropertyWithNullValue() throws SchemaExce
.isEmpty();
}

@Test
public void test600SearchById() throws SchemaException {
when("searching audit using ALL filter");
SearchResultList<AuditEventRecordType> result = searchObjects(
prismContext.queryFor(AuditEventRecordType.class)
.item(AuditEventRecordType.F_REPO_ID).eq(record1RepoId)
.build());

assertThat(result).hasSize(1);
assertThat(result.get(0).getEventIdentifier()).isEqualTo(record1EventIdentifier);
}

@Test
public void test800SearchWithAllFilter() throws SchemaException {
when("searching audit using ALL filter");
Expand Down
Expand Up @@ -62,6 +62,7 @@ public AuditEventRecordType toSchemaObject(MAuditEventRecord row) throws SchemaE
private AuditEventRecordType mapSimpleAttributes(MAuditEventRecord row) {
// prismContext in constructor ensures complex type definition
return new AuditEventRecordType(transformerSupport.prismContext())
.repoId(row.id)
.channel(row.channel)
.eventIdentifier(row.eventIdentifier)
.eventStage(auditEventStageTypeFromRepo(row.eventStage))
Expand Down
Expand Up @@ -37,6 +37,7 @@ private QAuditEventRecordMapping() {
super(TABLE_NAME, DEFAULT_ALIAS_NAME,
AuditEventRecordType.class, QAuditEventRecord.class);

addItemMapping(F_REPO_ID, longMapper(q -> q.id));
addItemMapping(F_CHANNEL, stringMapper(q -> q.channel));
addItemMapping(F_EVENT_IDENTIFIER, stringMapper(q -> q.eventIdentifier));
addItemMapping(F_EVENT_STAGE, EnumOrdinalItemFilterProcessor.mapper(
Expand Down
Expand Up @@ -121,6 +121,17 @@ public <MS> ItemSqlMapper<MS, Q, R> integerMapper(
new SimpleItemFilterProcessor<>(ctx, rootToQueryItem), rootToQueryItem);
}

/**
* Returns the mapper creating the long filter processor from context.
*
* @param <MS> mapped schema type, see javadoc for the class
*/
public <MS> ItemSqlMapper<MS, Q, R> longMapper(
Function<Q, NumberPath<Long>> rootToQueryItem) {
return new ItemSqlMapper<>(ctx ->
new SimpleItemFilterProcessor<>(ctx, rootToQueryItem), rootToQueryItem);
}

/**
* Returns the mapper creating the boolean filter processor from context.
*
Expand Down

0 comments on commit aba1d48

Please sign in to comment.