mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
MNT-22485: audit query with createdAt criteria returns correct totalI… (#1535)
* MNT-22485: audit query with createdAt criteria returns correct totalItems
This commit is contained in:
@@ -272,4 +272,16 @@ public interface AuditComponent
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an audit query to retrieve count of records for a given application and properties
|
||||
*
|
||||
* @param applicationName the name of the application
|
||||
* @param parameters audit parameters provided by the <code>where</code> clause on the ReST API
|
||||
* @return a map containing min/max and the associated value
|
||||
*/
|
||||
default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@@ -955,4 +955,11 @@ public class AuditComponentImpl implements AuditComponent
|
||||
|
||||
return auditDAO.getAuditEntriesCountByApp(applicationId);
|
||||
}
|
||||
|
||||
@Override public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
|
||||
{
|
||||
org.alfresco.repo.domain.audit.AuditQueryParameters dbParameters = new org.alfresco.repo.domain.audit.AuditQueryParameters();
|
||||
|
||||
return auditDAO.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
|
||||
}
|
||||
}
|
||||
|
@@ -186,4 +186,12 @@ public class AuditServiceImpl implements AuditService
|
||||
{
|
||||
return auditComponent.getAuditEntriesCountByApp(applicationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
|
||||
{
|
||||
return auditComponent.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
|
||||
}
|
||||
}
|
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.domain.audit;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -452,37 +452,86 @@ public abstract class AbstractAuditDAOImpl implements AuditDAO
|
||||
org.alfresco.service.cmr.audit.AuditQueryParameters parameters,
|
||||
int maxResults)
|
||||
{
|
||||
String searchKey = null;
|
||||
Serializable searchValue = null;
|
||||
if (parameters.getSearchKeyValues().size() > 0)
|
||||
{
|
||||
// Only handle one pair for now
|
||||
Pair<String, Serializable> searchKeyValue = parameters.getSearchKeyValues().get(0);
|
||||
searchKey = searchKeyValue.getFirst();
|
||||
searchValue = searchKeyValue.getSecond();
|
||||
}
|
||||
|
||||
AuditQueryRowHandler rowHandler = new AuditQueryRowHandler(callback);
|
||||
findAuditEntries(
|
||||
rowHandler,
|
||||
parameters.isForward(),
|
||||
parameters.getApplicationName(),
|
||||
parameters.getUser(),
|
||||
parameters.getFromId(),
|
||||
parameters.getToId(),
|
||||
parameters.getFromTime(),
|
||||
parameters.getToTime(),
|
||||
maxResults,
|
||||
searchKey,
|
||||
searchValue);
|
||||
parameters);
|
||||
}
|
||||
|
||||
protected abstract void findAuditEntries(
|
||||
AuditQueryRowHandler rowHandler,
|
||||
boolean forward,
|
||||
String applicationName, String user,
|
||||
Long fromId, Long toId,
|
||||
Long fromTime, Long toTime,
|
||||
int maxResults,
|
||||
String searchKey, Serializable searchValue);
|
||||
org.alfresco.service.cmr.audit.AuditQueryParameters restParameters);
|
||||
|
||||
protected AuditQueryParameters convertFromRestAuditQueryParameters(org.alfresco.service.cmr.audit.AuditQueryParameters restParameters)
|
||||
{
|
||||
AuditQueryParameters dbParameters = new AuditQueryParameters();
|
||||
|
||||
String appName = restParameters.getApplicationName();
|
||||
if (appName != null)
|
||||
{
|
||||
// Look up the application's ID (this is unique)
|
||||
Pair<Long, Serializable> appNamePair = propertyValueDAO.getPropertyValue(appName);
|
||||
if (appNamePair == null)
|
||||
{
|
||||
// No such value
|
||||
return null;
|
||||
}
|
||||
dbParameters.setAuditAppNameId(appNamePair.getFirst());
|
||||
}
|
||||
|
||||
String user = restParameters.getUser();
|
||||
if (user != null)
|
||||
{
|
||||
// Look up the application's ID (this is unique)
|
||||
Pair<Long, Serializable> userPair = propertyValueDAO.getPropertyValue(user);
|
||||
if (userPair == null)
|
||||
{
|
||||
// No such value
|
||||
return null;
|
||||
}
|
||||
dbParameters.setAuditUserId(userPair.getFirst());
|
||||
}
|
||||
|
||||
dbParameters.setAuditFromId(restParameters.getFromId());
|
||||
dbParameters.setAuditToId(restParameters.getToId());
|
||||
dbParameters.setAuditFromTime(restParameters.getFromTime());
|
||||
dbParameters.setAuditToTime(restParameters.getToTime());
|
||||
|
||||
String searchKey = null;
|
||||
Serializable searchValue = null;
|
||||
if (restParameters.getSearchKeyValues().size() > 0)
|
||||
{
|
||||
// Only handle one pair for now
|
||||
Pair<String, Serializable> searchKeyValue = restParameters.getSearchKeyValues().get(0);
|
||||
searchKey = searchKeyValue.getFirst();
|
||||
searchValue = searchKeyValue.getSecond();
|
||||
}
|
||||
if (searchKey != null)
|
||||
{
|
||||
// Look up the ID of the search key
|
||||
Pair<Long, Serializable> searchKeyPair = propertyValueDAO.getPropertyValue(searchKey);
|
||||
if (searchKeyPair == null)
|
||||
{
|
||||
// No such value
|
||||
return null;
|
||||
}
|
||||
dbParameters.setSearchKeyId(searchKeyPair.getFirst());
|
||||
}
|
||||
if (searchValue != null)
|
||||
{
|
||||
// Look up the ID of the search key
|
||||
Pair<Long, Serializable> searchValuePair = propertyValueDAO.getPropertyValue(searchValue);
|
||||
if (searchValuePair == null)
|
||||
{
|
||||
// No such value
|
||||
return null;
|
||||
}
|
||||
dbParameters.setSearchValueId(searchValuePair.getFirst());
|
||||
}
|
||||
dbParameters.setForward(restParameters.isForward());
|
||||
|
||||
return dbParameters;
|
||||
}
|
||||
}
|
||||
|
@@ -244,4 +244,16 @@ public interface AuditDAO
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an audit query to retrieve count of records for a given application and properties
|
||||
*
|
||||
* @param applicationName name of the application to be queried
|
||||
* @param parameters audit parameters provided by the <code>where</code> clause on the ReST API
|
||||
* @return a map containing min/max and the associated value
|
||||
*/
|
||||
default int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
@@ -66,6 +66,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
|
||||
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_COUNT_ENTRIES_FOR_APP = "alfresco.audit.select_CountAuditEntryId";
|
||||
private static final String SELECT_COUNT_ENTRIES_FOR_APP_WITH_PROPERTIES = "select_CountAuditEntryIdWithWhereClause";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String SELECT_ENTRIES_SIMPLE = "alfresco.audit.select_AuditEntriesSimple";
|
||||
@@ -235,68 +236,29 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
|
||||
{
|
||||
AuditQueryParameters dbParameters = convertFromRestAuditQueryParameters(parameters);
|
||||
|
||||
int result = template.selectOne(SELECT_COUNT_ENTRIES_FOR_APP_WITH_PROPERTIES, dbParameters);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void findAuditEntries(
|
||||
final AuditQueryRowHandler rowHandler,
|
||||
boolean forward,
|
||||
String appName, String user,
|
||||
Long fromId, Long toId,
|
||||
Long fromTime, Long toTime,
|
||||
int maxResults,
|
||||
String searchKey, Serializable searchValue)
|
||||
org.alfresco.service.cmr.audit.AuditQueryParameters restParameters)
|
||||
{
|
||||
AuditQueryParameters params = new AuditQueryParameters();
|
||||
if (appName != null)
|
||||
AuditQueryParameters params = convertFromRestAuditQueryParameters(restParameters);
|
||||
if (params==null)
|
||||
{
|
||||
// Look up the application's ID (this is unique)
|
||||
Pair<Long, Serializable> appNamePair = propertyValueDAO.getPropertyValue(appName);
|
||||
if (appNamePair == null)
|
||||
{
|
||||
// No such value
|
||||
return;
|
||||
}
|
||||
params.setAuditAppNameId(appNamePair.getFirst());
|
||||
return;
|
||||
}
|
||||
if (user != null)
|
||||
{
|
||||
// Look up the application's ID (this is unique)
|
||||
Pair<Long, Serializable> userPair = propertyValueDAO.getPropertyValue(user);
|
||||
if (userPair == null)
|
||||
{
|
||||
// No such value
|
||||
return;
|
||||
}
|
||||
params.setAuditUserId(userPair.getFirst());
|
||||
}
|
||||
params.setAuditFromId(fromId);
|
||||
params.setAuditToId(toId);
|
||||
params.setAuditFromTime(fromTime);
|
||||
params.setAuditToTime(toTime);
|
||||
if (searchKey != null)
|
||||
{
|
||||
// Look up the ID of the search key
|
||||
Pair<Long, Serializable> searchKeyPair = propertyValueDAO.getPropertyValue(searchKey);
|
||||
if (searchKeyPair == null)
|
||||
{
|
||||
// No such value
|
||||
return;
|
||||
}
|
||||
params.setSearchKeyId(searchKeyPair.getFirst());
|
||||
}
|
||||
if (searchValue != null)
|
||||
{
|
||||
// Look up the ID of the search key
|
||||
Pair<Long, Serializable> searchValuePair = propertyValueDAO.getPropertyValue(searchValue);
|
||||
if (searchValuePair == null)
|
||||
{
|
||||
// No such value
|
||||
return;
|
||||
}
|
||||
params.setSearchValueId(searchValuePair.getFirst());
|
||||
}
|
||||
params.setForward(forward);
|
||||
|
||||
|
||||
if (maxResults > 0)
|
||||
{
|
||||
// Query without getting the values. We gather all the results and batch-fetch the audited
|
||||
|
@@ -252,4 +252,16 @@ public interface AuditService
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an audit query to retrieve min / max audit record id for a given application and properties
|
||||
*
|
||||
* @param applicationName the name of the application
|
||||
* @param parameters audit parameters provided by the <code>where</code> clause on the ReST API
|
||||
* @return a map containing min/max and the associated value
|
||||
*/
|
||||
default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@@ -50,6 +50,15 @@
|
||||
<!-- Parameter Maps -->
|
||||
<!-- -->
|
||||
|
||||
<parameterMap id="parameter_AuditAppId_WhereClauseMap" type="map">
|
||||
<parameter property="auditAppNameId" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditUserId" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditFromTime" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditToTime" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditFromId" jdbcType="BIGINT" javaType="Long"/>
|
||||
<parameter property="auditToId" jdbcType="BIGINT" javaType="Long"/>
|
||||
</parameterMap>
|
||||
|
||||
<parameterMap id="parameter_IdMap" type="map">
|
||||
<parameter property="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
|
||||
</parameterMap>
|
||||
@@ -291,6 +300,14 @@
|
||||
alf_audit_entry.audit_app_id = #{auditAppId}
|
||||
</select>
|
||||
|
||||
<select id="select_CountAuditEntryIdWithWhereClause" parameterMap="parameter_AuditAppId_WhereClauseMap" resultType="int">
|
||||
select
|
||||
COUNT(id)
|
||||
from
|
||||
alf_audit_entry as entry
|
||||
<include refid="select_AuditEntriesWhereSnippet"/>
|
||||
</select>
|
||||
|
||||
<!-- Get the maximum/minimum audit entry id for application -->
|
||||
<select id="select_MinMaxAuditEntryId" parameterMap="parameter_IdMinMaxMap" resultMap="result_minMaxMap">
|
||||
select
|
||||
|
Reference in New Issue
Block a user