mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merge 7.0.0-A8 changes to new projects:
alfresco-remote-api 8.238 alfresco-repository 8.286 alfresco-data-model 8.158 alfresco-core 8.50 MNT-21936 : Audit query Rest API does not return the correct totalItems (#838) * MNT-21936 : Audit query Rest API does not return the correct totalItems Retrieve audit entries count if it has more items Require new release of alfresco-repository. * MNT-21936 : introduced skipTotalItems property for AuditImpl#listAuditEntries * MNT-21936 : Change skipTotalItems to omitTotalItems to align with API Spec * update alfresco-repository dependency (cherry picked from commit 91c49be12a21b23a87cd04b7584c230b2ec4b569) Bump dependency.webscripts.version from 8.8 to 8.10 (#1252) Bumps `dependency.webscripts.version` from 8.8 to 8.10. Updates `spring-surf-core-configservice` from 8.8 to 8.10 Updates `spring-webscripts` from 8.8 to 8.10 - [Release notes](https://github.com/Alfresco/surf-webscripts/releases) - [Commits](https://github.com/Alfresco/surf-webscripts/compare/spring-surf-webscripts-parent-8.8...spring-surf-webscripts-parent-8.10) Updates `spring-webscripts-api` from 8.8 to 8.10 Updates `spring-webscripts` from 8.8 to 8.10 - [Release notes](https://github.com/Alfresco/surf-webscripts/releases) - [Commits](https://github.com/Alfresco/surf-webscripts/compare/spring-surf-webscripts-parent-8.8...spring-surf-webscripts-parent-8.10) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> (cherry picked from commit 8434f5f06fbd973c24688e5c7ec3d54b8513d858) MNT-21936 : Audit query Rest API does not return the correct totalItems (#1253) * MNT-21936 : Audit query Rest API does not return the correct totalItems Add CountAuditEntryId select, that provides the total number of items for a specific auditApp Add getAuditEntriesCountByApp(long appId) in AuditDAO interface and its implementation in AuditDAOImpl Add getAuditEntriesCountByApp(String applicationName) in AuditComponent interface and its implementation in AuditComponentImpl Add getAuditEntriesCountByApp(String applicationName) in AuditService interface and its implementation in AuditServiceImpl * MNT-21936 : Added default implementation for getAuditEntriesCountByApp() in AuditComponent AuditService and AuditDAOImpl (cherry picked from commit 706251642bb5ef6dbb0a059bf6a0cd4f7b72ab43)
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -63,7 +63,7 @@
|
|||||||
<dependency.cxf.version>3.3.7</dependency.cxf.version>
|
<dependency.cxf.version>3.3.7</dependency.cxf.version>
|
||||||
<dependency.opencmis.version>1.0.0</dependency.opencmis.version>
|
<dependency.opencmis.version>1.0.0</dependency.opencmis.version>
|
||||||
<dependency.pdfbox.version>2.0.21</dependency.pdfbox.version>
|
<dependency.pdfbox.version>2.0.21</dependency.pdfbox.version>
|
||||||
<dependency.webscripts.version>8.8</dependency.webscripts.version>
|
<dependency.webscripts.version>8.10</dependency.webscripts.version>
|
||||||
<dependency.bouncycastle.version>1.66</dependency.bouncycastle.version>
|
<dependency.bouncycastle.version>1.66</dependency.bouncycastle.version>
|
||||||
<dependency.mockito-core.version>3.5.11</dependency.mockito-core.version>
|
<dependency.mockito-core.version>3.5.11</dependency.mockito-core.version>
|
||||||
<dependency.org-json.version>20090211</dependency.org-json.version>
|
<dependency.org-json.version>20090211</dependency.org-json.version>
|
||||||
|
@@ -280,21 +280,28 @@ public class AuditImpl implements Audit
|
|||||||
|
|
||||||
// clear null elements
|
// clear null elements
|
||||||
entriesAudit.removeAll(Collections.singleton(null));
|
entriesAudit.removeAll(Collections.singleton(null));
|
||||||
int totalItems = entriesAudit.size();
|
int totalRetrievedItems = entriesAudit.size();
|
||||||
|
int end = Math.min(limit - 1, totalRetrievedItems);
|
||||||
|
boolean hasMoreItems = totalRetrievedItems > end;
|
||||||
|
|
||||||
if (skipCount >= totalItems)
|
String omitTotalItemsParameter = parameters.getParameter("omitTotalItems");
|
||||||
|
boolean omitTotalItems = (null != omitTotalItemsParameter) && Boolean.parseBoolean(omitTotalItemsParameter);
|
||||||
|
|
||||||
|
Integer totalItems;
|
||||||
|
|
||||||
|
if (omitTotalItems)
|
||||||
{
|
{
|
||||||
List<AuditEntry> empty = Collections.emptyList();
|
totalItems = null;
|
||||||
return CollectionWithPagingInfo.asPaged(paging, empty, false, totalItems);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int end = Math.min(limit - 1, totalItems);
|
totalItems = hasMoreItems ? getAuditEntriesCountByApp(auditApplication) : totalRetrievedItems;
|
||||||
boolean hasMoreItems = totalItems > end;
|
|
||||||
|
|
||||||
entriesAudit = entriesAudit.subList(skipCount, end);
|
|
||||||
return CollectionWithPagingInfo.asPaged(paging, entriesAudit, hasMoreItems, totalItems);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entriesAudit = (skipCount >= totalRetrievedItems)
|
||||||
|
? Collections.emptyList()
|
||||||
|
: entriesAudit.subList(skipCount, end);
|
||||||
|
return CollectionWithPagingInfo.asPaged(paging, entriesAudit, hasMoreItems, totalItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -882,4 +889,10 @@ public class AuditImpl implements Audit
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAuditEntriesCountByApp(AuditService.AuditApplication auditApplication)
|
||||||
|
{
|
||||||
|
final String applicationName = auditApplication.getKey().substring(1);
|
||||||
|
return auditService.getAuditEntriesCountByApp(applicationName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
package org.alfresco.rest.api.tests;
|
package org.alfresco.rest.api.tests;
|
||||||
|
|
||||||
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull;
|
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
@@ -405,6 +406,31 @@ public class AuditAppTest extends AbstractSingleNetworkSiteTest
|
|||||||
validateAuditEntryFields(ae, auditApp);
|
validateAuditEntryFields(ae, auditApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MNT-21936 Audit query Rest API does not return the correct totalItems
|
||||||
|
int auditEntriesTotalItems = auditEntries.getPaging().getTotalItems();
|
||||||
|
|
||||||
|
// set maxItems to 1
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("maxItems","1");
|
||||||
|
|
||||||
|
auditEntries = auditAppsProxy.getAuditAppEntries(auditApp.getId(), params,
|
||||||
|
HttpServletResponse.SC_OK);
|
||||||
|
|
||||||
|
int AuditEntriesTotalItemsAfterLimit = auditEntries.getPaging().getTotalItems();
|
||||||
|
int retrievedAuditEntriesCount = auditEntries.getPaging().getCount();
|
||||||
|
// When totalItems are retrieved using getAuditEntriesCountByApp() method that was introduced in MNT-21936
|
||||||
|
// 2 audit entries will be created.
|
||||||
|
assertEquals(auditEntriesTotalItems + 2, AuditEntriesTotalItemsAfterLimit);
|
||||||
|
assertEquals(1, retrievedAuditEntriesCount);
|
||||||
|
|
||||||
|
// set omitTotalItems to true.
|
||||||
|
params.put("omitTotalItems", "true");
|
||||||
|
auditEntries = auditAppsProxy.getAuditAppEntries(auditApp.getId(), params,
|
||||||
|
HttpServletResponse.SC_OK);
|
||||||
|
|
||||||
|
// verify that totalItems is null.
|
||||||
|
assertNull(auditEntries.getPaging().getTotalItems());
|
||||||
|
|
||||||
// Negative tests
|
// Negative tests
|
||||||
// 401
|
// 401
|
||||||
setRequestContext(networkOne.getId(), networkAdmin, "wrongPassword");
|
setRequestContext(networkOne.getId(), networkAdmin, "wrongPassword");
|
||||||
|
@@ -261,4 +261,15 @@ public interface AuditComponent
|
|||||||
* @return a map containing min/max and the associated value
|
* @return a map containing min/max and the associated value
|
||||||
*/
|
*/
|
||||||
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes);
|
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issue an audit query to retrieve count of records for a given application.
|
||||||
|
*
|
||||||
|
* @param applicationName the name of the application
|
||||||
|
* @return a map containing min/max and the associated value
|
||||||
|
*/
|
||||||
|
default int getAuditEntriesCountByApp(String applicationName)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -941,4 +941,18 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
|
|
||||||
return auditDAO.getAuditMinMaxByApp(applicationId, extremes);
|
return auditDAO.getAuditMinMaxByApp(applicationId, extremes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAuditEntriesCountByApp(String applicationName)
|
||||||
|
{
|
||||||
|
// Get the id for the application
|
||||||
|
AuditApplication app = auditModelRegistry.getAuditApplicationByName(applicationName);
|
||||||
|
Long applicationId = app.getApplicationId();
|
||||||
|
if (applicationId == null)
|
||||||
|
{
|
||||||
|
throw new AuditException("No persisted instance exists for audit application: " + app);
|
||||||
|
}
|
||||||
|
|
||||||
|
return auditDAO.getAuditEntriesCountByApp(applicationId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -177,4 +177,13 @@ public class AuditServiceImpl implements AuditService
|
|||||||
{
|
{
|
||||||
return auditComponent.getAuditMinMaxByApp(applicationName, extremes);
|
return auditComponent.getAuditMinMaxByApp(applicationName, extremes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getAuditEntriesCountByApp(String applicationName)
|
||||||
|
{
|
||||||
|
return auditComponent.getAuditEntriesCountByApp(applicationName);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -233,4 +233,15 @@ public interface AuditDAO
|
|||||||
* @return a map containing min/max and the associated value
|
* @return a map containing min/max and the associated value
|
||||||
*/
|
*/
|
||||||
HashMap<String, Long> getAuditMinMaxByApp(long appId, List<String> extremes);
|
HashMap<String, Long> getAuditMinMaxByApp(long appId, List<String> extremes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issue an audit query to retrieve count of records for a given application.
|
||||||
|
*
|
||||||
|
* @param applicationId the database id of the application
|
||||||
|
* @return a map containing min/max and the associated value
|
||||||
|
*/
|
||||||
|
default int getAuditEntriesCountByApp(long applicationId)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -65,6 +65,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
|
|||||||
private static final String DELETE_ENTRIES_BY_ID = "alfresco.audit.delete_AuditEntriesById";
|
private static final String DELETE_ENTRIES_BY_ID = "alfresco.audit.delete_AuditEntriesById";
|
||||||
private static final String INSERT_ENTRY = "alfresco.audit.insert.insert_AuditEntry";
|
private static final String INSERT_ENTRY = "alfresco.audit.insert.insert_AuditEntry";
|
||||||
private static final String SELECT_MINMAX_ENTRY_FOR_APP = "alfresco.audit.select_MinMaxAuditEntryId";
|
private static final String SELECT_MINMAX_ENTRY_FOR_APP = "alfresco.audit.select_MinMaxAuditEntryId";
|
||||||
|
private static final String SELECT_COUNT_ENTRIES_FOR_APP = "alfresco.audit.select_CountAuditEntryId";
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static final String SELECT_ENTRIES_SIMPLE = "alfresco.audit.select_AuditEntriesSimple";
|
private static final String SELECT_ENTRIES_SIMPLE = "alfresco.audit.select_AuditEntriesSimple";
|
||||||
@@ -223,6 +224,17 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAuditEntriesCountByApp(long applicationId)
|
||||||
|
{
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("auditAppId", applicationId);
|
||||||
|
|
||||||
|
int result = template.selectOne(SELECT_COUNT_ENTRIES_FOR_APP, params);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
protected void findAuditEntries(
|
protected void findAuditEntries(
|
||||||
|
@@ -241,4 +241,15 @@ public interface AuditService
|
|||||||
* @return a map containing min/max and the associated value
|
* @return a map containing min/max and the associated value
|
||||||
*/
|
*/
|
||||||
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes);
|
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issue an audit query to retrieve min / max audit record id for a given application.
|
||||||
|
*
|
||||||
|
* @param applicationName the name of the application
|
||||||
|
* @return a map containing min/max and the associated value
|
||||||
|
*/
|
||||||
|
default int getAuditEntriesCountByApp(String applicationName)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -60,6 +60,10 @@
|
|||||||
<parameter property="max" jdbcType="VARCHAR" javaType="String"/>
|
<parameter property="max" jdbcType="VARCHAR" javaType="String"/>
|
||||||
</parameterMap>
|
</parameterMap>
|
||||||
|
|
||||||
|
<parameterMap id="parameter_AuditAppId" type="map">
|
||||||
|
<parameter property="auditAppId" jdbcType="BIGINT" javaType="Long"/>
|
||||||
|
</parameterMap>
|
||||||
|
|
||||||
<!-- -->
|
<!-- -->
|
||||||
<!-- SQL Snippets -->
|
<!-- SQL Snippets -->
|
||||||
<!-- -->
|
<!-- -->
|
||||||
@@ -277,6 +281,16 @@
|
|||||||
<include refid="select_AuditEntriesOrderBySnippet"/>
|
<include refid="select_AuditEntriesOrderBySnippet"/>
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<!-- Get the count of audit entries for application -->
|
||||||
|
<select id="select_CountAuditEntryId" parameterMap="parameter_AuditAppId" resultType="int">
|
||||||
|
select
|
||||||
|
COUNT(id)
|
||||||
|
from
|
||||||
|
alf_audit_entry
|
||||||
|
where
|
||||||
|
alf_audit_entry.audit_app_id = #{auditAppId}
|
||||||
|
</select>
|
||||||
|
|
||||||
<!-- Get the maximum/minimum audit entry id for application -->
|
<!-- Get the maximum/minimum audit entry id for application -->
|
||||||
<select id="select_MinMaxAuditEntryId" parameterMap="parameter_IdMinMaxMap" resultMap="result_minMaxMap">
|
<select id="select_MinMaxAuditEntryId" parameterMap="parameter_IdMinMaxMap" resultMap="result_minMaxMap">
|
||||||
select
|
select
|
||||||
|
Reference in New Issue
Block a user