mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
MNT-23210 Fix audit min-max query (#2545)
This commit is contained in:
@@ -318,13 +318,13 @@
|
|||||||
<select id="select_MinMaxAuditEntryId" parameterMap="parameter_IdMinMaxMap" resultMap="result_minMaxMap">
|
<select id="select_MinMaxAuditEntryId" parameterMap="parameter_IdMinMaxMap" resultMap="result_minMaxMap">
|
||||||
select
|
select
|
||||||
<if test="max != null">
|
<if test="max != null">
|
||||||
max(alf_audit_entry.id)
|
max(alf_audit_entry.id) as max
|
||||||
</if>
|
</if>
|
||||||
<if test="max != null and min != null">
|
<if test="max != null and min != null">
|
||||||
,
|
,
|
||||||
</if>
|
</if>
|
||||||
<if test="min != null">
|
<if test="min != null">
|
||||||
min(alf_audit_entry.id)
|
min(alf_audit_entry.id) as min
|
||||||
</if>
|
</if>
|
||||||
from
|
from
|
||||||
alf_audit_entry
|
alf_audit_entry
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
@@ -36,6 +36,7 @@ import java.util.HashMap;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import jakarta.transaction.UserTransaction;
|
import jakarta.transaction.UserTransaction;
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ import org.alfresco.util.GUID;
|
|||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.alfresco.util.testing.category.DBTests;
|
import org.alfresco.util.testing.category.DBTests;
|
||||||
import org.apache.commons.lang3.mutable.MutableInt;
|
import org.apache.commons.lang3.mutable.MutableInt;
|
||||||
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
@@ -157,30 +159,41 @@ public class AuditDAOTest extends TestCase
|
|||||||
doAuditEntryImpl(1000);
|
doAuditEntryImpl(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAuditMinMaxByApp() throws Exception
|
||||||
|
{
|
||||||
|
final String[] expectedExtremes = {"min", "max"};
|
||||||
|
final AuditApplicationInfo appInfo = doAuditEntryImpl(12);
|
||||||
|
|
||||||
|
final Map<String, Long> minMax = auditDAO.getAuditMinMaxByApp(appInfo.getId(), List.of(expectedExtremes));
|
||||||
|
|
||||||
|
assertEquals(Set.of(expectedExtremes), minMax.keySet());
|
||||||
|
assertNotNull(minMax.get(expectedExtremes[0]));
|
||||||
|
assertNotNull(minMax.get(expectedExtremes[1]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the name of the application
|
* @return Returns the name of the application
|
||||||
*/
|
*/
|
||||||
private String doAuditEntryImpl(final int count) throws Exception
|
private AuditApplicationInfo doAuditEntryImpl(final int count) throws Exception
|
||||||
{
|
{
|
||||||
final File file = AbstractContentTransformerTest.loadQuickTestFile("pdf");
|
final File file = AbstractContentTransformerTest.loadQuickTestFile("pdf");
|
||||||
assertNotNull(file);
|
assertNotNull(file);
|
||||||
final URL url = new URL("file:" + file.getAbsolutePath());
|
final URL url = new URL("file:" + file.getAbsolutePath());
|
||||||
final String appName = getName() + "." + System.currentTimeMillis();
|
final String appName = getName() + "." + System.currentTimeMillis();
|
||||||
|
|
||||||
RetryingTransactionCallback<Long> createAppCallback = new RetryingTransactionCallback<Long>()
|
RetryingTransactionCallback<AuditApplicationInfo> createAppCallback = () ->
|
||||||
{
|
{
|
||||||
public Long execute() throws Throwable
|
AuditApplicationInfo appInfo = auditDAO.getAuditApplication(appName);
|
||||||
|
if (appInfo == null)
|
||||||
{
|
{
|
||||||
AuditApplicationInfo appInfo = auditDAO.getAuditApplication(appName);
|
Long modelId = auditDAO.getOrCreateAuditModel(url).getFirst();
|
||||||
if (appInfo == null)
|
appInfo = auditDAO.createAuditApplication(appName, modelId);
|
||||||
{
|
|
||||||
Long modelId = auditDAO.getOrCreateAuditModel(url).getFirst();
|
|
||||||
appInfo = auditDAO.createAuditApplication(appName, modelId);
|
|
||||||
}
|
|
||||||
return appInfo.getId();
|
|
||||||
}
|
}
|
||||||
|
return appInfo;
|
||||||
};
|
};
|
||||||
final Long sessionId = txnHelper.doInTransaction(createAppCallback);
|
final AuditApplicationInfo appInfo = txnHelper.doInTransaction(createAppCallback);
|
||||||
|
final Long sessionId = appInfo.getId();
|
||||||
|
|
||||||
final String username = "alexi";
|
final String username = "alexi";
|
||||||
RetryingTransactionCallback<Void> createEntryCallback = new RetryingTransactionCallback<Void>()
|
RetryingTransactionCallback<Void> createEntryCallback = new RetryingTransactionCallback<Void>()
|
||||||
@@ -203,7 +216,7 @@ public class AuditDAOTest extends TestCase
|
|||||||
"Time for " + count + " entry creations was " +
|
"Time for " + count + " entry creations was " +
|
||||||
((double)(after - before)/(10E6)) + "ms");
|
((double)(after - before)/(10E6)) + "ms");
|
||||||
// Done
|
// Done
|
||||||
return appName;
|
return appInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void testAuditQuery() throws Exception
|
public synchronized void testAuditQuery() throws Exception
|
||||||
@@ -476,7 +489,7 @@ public class AuditDAOTest extends TestCase
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Some entries
|
// Some entries
|
||||||
final String appName = doAuditEntryImpl(1);
|
final String appName = doAuditEntryImpl(1).getName();
|
||||||
|
|
||||||
final AuditQueryParameters params = new AuditQueryParameters();
|
final AuditQueryParameters params = new AuditQueryParameters();
|
||||||
params.setApplicationName(appName);
|
params.setApplicationName(appName);
|
||||||
@@ -501,8 +514,8 @@ public class AuditDAOTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public void testAuditDeleteEntriesForApplication() throws Exception
|
public void testAuditDeleteEntriesForApplication() throws Exception
|
||||||
{
|
{
|
||||||
final String app1 = doAuditEntryImpl(6);
|
final String app1 = doAuditEntryImpl(6).getName();
|
||||||
final String app2 = doAuditEntryImpl(18);
|
final String app2 = doAuditEntryImpl(18).getName();
|
||||||
|
|
||||||
final AuditQueryCallbackImpl resultsCallback = new AuditQueryCallbackImpl();
|
final AuditQueryCallbackImpl resultsCallback = new AuditQueryCallbackImpl();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user