[APPS-3130] reverting changes of MNT-24137 (#3076)

* [APPS-3130] reverting changes of MNT-24137

* reverting

* reverting the change of mnt-24137

* reverting the change of mnt-24137

* reverting the change of mnt-24137

* reverting the changes of mnt-24137

* reverting the changes of mnt-24137

* reverting the changes of mnt-24137

* [APPS-3130] reverting changes of MNT-24137

---------

Co-authored-by: Sathish Kumar <ST28@ford.com>
This commit is contained in:
SathishK-T
2024-12-06 16:40:38 +05:30
committed by GitHub
parent f7d1bbcec3
commit 853d1bdc1b
10 changed files with 2683 additions and 2616 deletions

View File

@@ -33,14 +33,15 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
import org.alfresco.repo.domain.propval.PropertyStringValueEntity;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
import org.alfresco.repo.domain.propval.PropertyStringValueEntity;
/** /**
* RM V3.3 Hold audit entries values patch unit test * RM V3.3 Hold audit entries values patch unit test
* *
@@ -55,7 +56,6 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest
@InjectMocks @InjectMocks
private RMv33HoldAuditEntryValuesPatch patch; private RMv33HoldAuditEntryValuesPatch patch;
@Before @Before
public void setUp() public void setUp()
{ {
@@ -93,15 +93,15 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest
verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(deleteHoldPropertyStringValueEntity); verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(deleteHoldPropertyStringValueEntity);
assertEquals("Add To Hold", addToHoldPropertyStringValueEntity.getStringValue()); assertEquals("Add To Hold", addToHoldPropertyStringValueEntity.getStringValue());
assertEquals("add to hold", addToHoldPropertyStringValueEntity.getStringLower()); assertEquals("add to hold", addToHoldPropertyStringValueEntity.getStringEndLower());
assertEquals(Long.valueOf(770_786_109L), addToHoldPropertyStringValueEntity.getStringCrc()); assertEquals(Long.valueOf(770_786_109L), addToHoldPropertyStringValueEntity.getStringCrc());
assertEquals("Remove From Hold", removeFromHoldPropertyStringValueEntity.getStringValue()); assertEquals("Remove From Hold", removeFromHoldPropertyStringValueEntity.getStringValue());
assertEquals("remove from hold", removeFromHoldPropertyStringValueEntity.getStringLower()); assertEquals("remove from hold", removeFromHoldPropertyStringValueEntity.getStringEndLower());
assertEquals(Long.valueOf(2_967_613_012L), removeFromHoldPropertyStringValueEntity.getStringCrc()); assertEquals(Long.valueOf(2_967_613_012L), removeFromHoldPropertyStringValueEntity.getStringCrc());
assertEquals("Delete Hold", deleteHoldPropertyStringValueEntity.getStringValue()); assertEquals("Delete Hold", deleteHoldPropertyStringValueEntity.getStringValue());
assertEquals("delete hold", deleteHoldPropertyStringValueEntity.getStringLower()); assertEquals("delete hold", deleteHoldPropertyStringValueEntity.getStringEndLower());
assertEquals(Long.valueOf(132_640_810L), deleteHoldPropertyStringValueEntity.getStringCrc()); assertEquals(Long.valueOf(132_640_810L), deleteHoldPropertyStringValueEntity.getStringCrc());
} }
@@ -123,5 +123,3 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest
verify(mockedRecordsManagementQueryDAO, times(0)).updatePropertyStringValueEntity(any()); verify(mockedRecordsManagementQueryDAO, times(0)).updatePropertyStringValueEntity(any());
} }
} }

View File

@@ -85,7 +85,7 @@ public class AuditImpl implements Audit
// list of equals filter's auditEntry (via where clause) // list of equals filter's auditEntry (via where clause)
private final static Set<String> LIST_AUDIT_ENTRY_EQUALS_QUERY_PROPERTIES = new HashSet<>( private final static Set<String> LIST_AUDIT_ENTRY_EQUALS_QUERY_PROPERTIES = new HashSet<>(
Arrays.asList(new String[] { CREATED_BY_USER, VALUES_KEY, VALUES_VALUE })); Arrays.asList(new String[]{CREATED_BY_USER, VALUES_KEY, VALUES_VALUE}));
// map of sort parameters for the moment one createdAt // map of sort parameters for the moment one createdAt
private final static Map<String, String> SORT_PARAMS_TO_NAMES; private final static Map<String, String> SORT_PARAMS_TO_NAMES;
@@ -295,23 +295,29 @@ public class AuditImpl implements Audit
} }
else else
{ {
if (hasMoreItems) { if (hasMoreItems)
if (q != null) { {
if (q != null)
{
// filtering via "where" clause // filtering via "where" clause
AuditEntryQueryWalker propertyWalker = new AuditEntryQueryWalker(); AuditEntryQueryWalker propertyWalker = new AuditEntryQueryWalker();
QueryHelper.walk(q, propertyWalker); QueryHelper.walk(q, propertyWalker);
totalItems = getAuditEntriesCountByAppAndProperties(auditApplication, propertyWalker); totalItems = getAuditEntriesCountByAppAndProperties(auditApplication, propertyWalker);
} else { }
else
{
totalItems = getAuditEntriesCountByApp(auditApplication); totalItems = getAuditEntriesCountByApp(auditApplication);
} }
} else { }
else
{
totalItems = totalRetrievedItems; totalItems = totalRetrievedItems;
} }
} }
entriesAudit = (skipCount >= totalRetrievedItems) entriesAudit = (skipCount >= totalRetrievedItems)
? Collections.emptyList() ? Collections.emptyList()
: entriesAudit.subList(skipCount, end); : entriesAudit.subList(skipCount, end);
return CollectionWithPagingInfo.asPaged(paging, entriesAudit, hasMoreItems, totalItems); return CollectionWithPagingInfo.asPaged(paging, entriesAudit, hasMoreItems, totalItems);
} }
@@ -475,8 +481,7 @@ public class AuditImpl implements Audit
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10); final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
// create the callback for auditQuery method // create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() final AuditQueryCallback callback = new AuditQueryCallback() {
{
public boolean valuesRequired() public boolean valuesRequired()
{ {
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES))); return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
@@ -532,7 +537,7 @@ public class AuditImpl implements Audit
params.setApplicationName(auditApplication.getName()); params.setApplicationName(auditApplication.getName());
params.setFromId(auditEntryId); params.setFromId(auditEntryId);
params.setToId(auditEntryId + 1); params.setToId(auditEntryId + 1);
List<String> includeParam = new ArrayList<>(); List<String> includeParam = new ArrayList<>();
if (parameters != null) if (parameters != null)
{ {
@@ -545,8 +550,7 @@ public class AuditImpl implements Audit
final List<AuditEntry> results = new ArrayList<>(); final List<AuditEntry> results = new ArrayList<>();
// create the callback for auditQuery method // create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() final AuditQueryCallback callback = new AuditQueryCallback() {
{
public boolean valuesRequired() public boolean valuesRequired()
{ {
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES))); return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
@@ -710,8 +714,7 @@ public class AuditImpl implements Audit
@Override @Override
public CollectionWithPagingInfo<AuditEntry> listAuditEntriesByNodeId(String nodeId, Parameters parameters) public CollectionWithPagingInfo<AuditEntry> listAuditEntriesByNodeId(String nodeId, Parameters parameters)
{ {
AuthenticationUtil.runAs(new RunAsWork<Void>() AuthenticationUtil.runAs(new RunAsWork<Void>() {
{
public Void doWork() throws Exception public Void doWork() throws Exception
{ {
checkEnabled(); checkEnabled();
@@ -772,8 +775,7 @@ public class AuditImpl implements Audit
final List<AuditEntry> results = new ArrayList<>(); final List<AuditEntry> results = new ArrayList<>();
String auditAppId = "alfresco-access"; String auditAppId = "alfresco-access";
String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork<String>() String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork<String>() {
{
public String doWork() throws Exception public String doWork() throws Exception
{ {
return findAuditAppByIdOr404(auditAppId).getName(); return findAuditAppByIdOr404(auditAppId).getName();
@@ -781,8 +783,7 @@ public class AuditImpl implements Audit
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
// create the callback for auditQuery method // create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() final AuditQueryCallback callback = new AuditQueryCallback() {
{
public boolean valuesRequired() public boolean valuesRequired()
{ {
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES))); return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
@@ -808,8 +809,7 @@ public class AuditImpl implements Audit
Long toTime = propertyWalker.getToTime(); Long toTime = propertyWalker.getToTime();
validateWhereBetween(nodeRef.getId(), fromTime, toTime); validateWhereBetween(nodeRef.getId(), fromTime, toTime);
AuthenticationUtil.runAs(new RunAsWork<Object>() AuthenticationUtil.runAs(new RunAsWork<Object>() {
{
public Object doWork() throws Exception public Object doWork() throws Exception
{ {
// QueryParameters // QueryParameters
@@ -820,7 +820,7 @@ public class AuditImpl implements Audit
pathParams.setFromTime(fromTime); pathParams.setFromTime(fromTime);
pathParams.setToTime(toTime); pathParams.setToTime(toTime);
pathParams.setApplicationName(auditApplicationName); pathParams.setApplicationName(auditApplicationName);
pathParams.addSearchKey("/"+auditAppId+"/transaction/path", nodePath); pathParams.addSearchKey("/" + auditAppId + "/transaction/path", nodePath);
auditService.auditQuery(callback, pathParams, limit); auditService.auditQuery(callback, pathParams, limit);
AuditQueryParameters copyFromPathParams = new AuditQueryParameters(); AuditQueryParameters copyFromPathParams = new AuditQueryParameters();
@@ -830,7 +830,7 @@ public class AuditImpl implements Audit
copyFromPathParams.setFromTime(fromTime); copyFromPathParams.setFromTime(fromTime);
copyFromPathParams.setToTime(toTime); copyFromPathParams.setToTime(toTime);
copyFromPathParams.setApplicationName(auditApplicationName); copyFromPathParams.setApplicationName(auditApplicationName);
copyFromPathParams.addSearchKey("/"+auditAppId+"/transaction/copy/from/path", nodePath); copyFromPathParams.addSearchKey("/" + auditAppId + "/transaction/copy/from/path", nodePath);
auditService.auditQuery(callback, copyFromPathParams, limit); auditService.auditQuery(callback, copyFromPathParams, limit);
AuditQueryParameters moveFromPathParams = new AuditQueryParameters(); AuditQueryParameters moveFromPathParams = new AuditQueryParameters();
@@ -840,7 +840,7 @@ public class AuditImpl implements Audit
moveFromPathParams.setFromTime(fromTime); moveFromPathParams.setFromTime(fromTime);
moveFromPathParams.setToTime(toTime); moveFromPathParams.setToTime(toTime);
moveFromPathParams.setApplicationName(auditApplicationName); moveFromPathParams.setApplicationName(auditApplicationName);
moveFromPathParams.addSearchKey("/"+auditAppId+"/transaction/move/from/path", nodePath); moveFromPathParams.addSearchKey("/" + auditAppId + "/transaction/move/from/path", nodePath);
auditService.auditQuery(callback, moveFromPathParams, limit); auditService.auditQuery(callback, moveFromPathParams, limit);
return null; return null;
@@ -857,7 +857,7 @@ public class AuditImpl implements Audit
public AuditEntriesByNodeIdQueryWalker() public AuditEntriesByNodeIdQueryWalker()
{ {
super(new HashSet<>(Arrays.asList(new String[] { CREATED_BY_USER })), null); super(new HashSet<>(Arrays.asList(new String[]{CREATED_BY_USER})), null);
} }
@Override @Override
@@ -904,19 +904,22 @@ public class AuditImpl implements Audit
public int getAuditEntriesCountByApp(AuditService.AuditApplication auditApplication) public int getAuditEntriesCountByApp(AuditService.AuditApplication auditApplication)
{ {
final String applicationName = auditApplication.getKey().substring(1); final String applicationName = auditApplication.getKey().substring(1);
return auditService.getAuditEntriesCountByApp(applicationName); return auditService.getAuditEntriesCountByApp(applicationName);
} }
public int getAuditEntriesCountByAppAndProperties(AuditService.AuditApplication auditApplication, AuditEntryQueryWalker propertyWalker) public int getAuditEntriesCountByAppAndProperties(AuditService.AuditApplication auditApplication, AuditEntryQueryWalker propertyWalker)
{ {
final String applicationName = auditApplication.getKey().substring(1);
AuditQueryParameters parameters = new AuditQueryParameters(); AuditQueryParameters parameters = new AuditQueryParameters();
parameters.setApplicationName(auditApplication.getName()); parameters.setApplicationName(applicationName);
parameters.setFromTime(propertyWalker.getFromTime()); parameters.setFromTime(propertyWalker.getFromTime());
parameters.setToTime(propertyWalker.getToTime()); parameters.setToTime(propertyWalker.getToTime());
parameters.setFromId(propertyWalker.getFromId()); parameters.setFromId(propertyWalker.getFromId());
parameters.setToId(propertyWalker.getToId()); parameters.setToId(propertyWalker.getToId());
parameters.setUser(propertyWalker.getCreatedByUser()); parameters.setUser(propertyWalker.getCreatedByUser());
return auditService.getAuditEntriesCountByAppAndProperties(parameters); return auditService.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
} }
} }

View File

@@ -1,286 +1,282 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2024 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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.audit; package org.alfresco.repo.audit;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.repo.audit.model.AuditApplication; import org.alfresco.repo.audit.model.AuditApplication;
import org.alfresco.repo.audit.model.AuditModelRegistry; import org.alfresco.repo.audit.model.AuditModelRegistry;
import org.alfresco.repo.audit.model._3.AuditPath; import org.alfresco.repo.audit.model._3.AuditPath;
import org.alfresco.service.cmr.audit.AuditQueryParameters; import org.alfresco.service.cmr.audit.AuditQueryParameters;
import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback; import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
/** /**
* The audit component. Used by the AuditService and AuditMethodInterceptor to insert audit entries. * The audit component. Used by the AuditService and AuditMethodInterceptor to insert audit entries.
* *
* @author Derek Hulley * @author Derek Hulley
*/ */
public interface AuditComponent public interface AuditComponent
{ {
/** /**
* Determines whether audit is globally enabled or disabled. * Determines whether audit is globally enabled or disabled.
* *
* @return Returns <code>true</code> if audit is enabled * @return Returns <code>true</code> if audit is enabled
* *
* @since 3.3 * @since 3.3
*/ */
public boolean isAuditEnabled(); public boolean isAuditEnabled();
/** /**
* Switch auditing on or off * Switch auditing on or off
* *
* @param enable <tt>true</tt> to enable auditing or <tt>false</tt> to disable * @param enable
* * <tt>true</tt> to enable auditing or <tt>false</tt> to disable
* @since 3.4 *
*/ * @since 3.4
public void setAuditEnabled(boolean enable); */
public void setAuditEnabled(boolean enable);
/**
* @param userAuditFilter UserAuditFilter /**
* * @param userAuditFilter
* @since 4.2 * UserAuditFilter
*/ *
public void setUserAuditFilter(UserAuditFilter userAuditFilter); * @since 4.2
*/
/** public void setUserAuditFilter(UserAuditFilter userAuditFilter);
* Get all registered audit applications, whether active or not.
* /**
* @return Returns a map of registered audit applications keyed by name * Get all registered audit applications, whether active or not.
* *
* @since 3.4 * @return Returns a map of registered audit applications keyed by name
*/ *
public Map<String, AuditApplication> getAuditApplications(); * @since 3.4
*/
/** public Map<String, AuditApplication> getAuditApplications();
* Determine whether the audit infrastructure expects audit values to be passed in.
* This is a helper method to allow optimizations in the client code. Reasons why /**
* this method might return <tt>false</tt> are: auditing is disabled; no audit applications * Determine whether the audit infrastructure expects audit values to be passed in. This is a helper method to allow optimizations in the client code. Reasons why this method might return <tt>false</tt> are: auditing is disabled; no audit applications have been registered. Sometimes, depending on the log level, this method may always return <tt>true</tt>.
* have been registered. Sometimes, depending on the log level, this method may always *
* return <tt>true</tt>. *
* * @return Returns <code>true</code> if the calling code (data producers) should go ahead and generate the data for {@link #recordAuditValues(String, Map) recording}.
* *
* @return Returns <code>true</code> if the calling code (data producers) * @since 3.3
* should go ahead and generate the data for */
* {@link #recordAuditValues(String, Map) recording}. public boolean areAuditValuesRequired();
*
* @since 3.3 /**
*/ * Determines if audit values are required based on whether there are any audit applications registered to record data for the given path. This helper method gives data producers a shortcut in the event that nothing would be recorded in any event.
public boolean areAuditValuesRequired(); *
* @param path
/** * the audit path
* Determines if audit values are required based on whether there are any audit applications * @return Returns <tt>true</tt> if there is at least one audit application registered to handle the given path.
* registered to record data for the given path. This helper method gives data producers a *
* shortcut in the event that nothing would be recorded in any event. * @since 3.4
* */
* @param path the audit path public boolean areAuditValuesRequired(String path);
* @return Returns <tt>true</tt> if there is at least one audit application
* registered to handle the given path. /**
* * Delete audit entries for the given application and time range
* @since 3.4 *
*/ * @param applicationName
public boolean areAuditValuesRequired(String path); * the name of the application
* @param fromTime
/** * the start time of entries to remove (inclusive and optional)
* Delete audit entries for the given application and time range * @param toTime
* * the end time of entries to remove (exclusive and optional)
* @param applicationName the name of the application * @return Returns the number of entries deleted
* @param fromTime the start time of entries to remove (inclusive and optional) *
* @param toTime the end time of entries to remove (exclusive and optional) * @since 3.2
* @return Returns the number of entries deleted */
* int deleteAuditEntries(String applicationName, Long fromTime, Long toTime);
* @since 3.2
*/ /**
int deleteAuditEntries(String applicationName, Long fromTime, Long toTime); * Delete audit entries for the given application and id range
*
/** * @param applicationName
* Delete audit entries for the given application and id range * the name of the application
* * @param fromId
* @param applicationName the name of the application * the start time of entries to remove (inclusive and optional)
* @param fromId the start time of entries to remove (inclusive and optional) * @param toId
* @param toId the end time of entries to remove (exclusive and optional) * the end time of entries to remove (exclusive and optional)
* @return Returns the number of entries deleted * @return Returns the number of entries deleted
* *
* @since 5.2.2 * @since 5.2.2
*/ */
int deleteAuditEntriesByIdRange(String applicationName, Long fromId, Long toId); int deleteAuditEntriesByIdRange(String applicationName, Long fromId, Long toId);
/** /**
* Delete a discrete list of audit entries based on ID * Delete a discrete list of audit entries based on ID
* *
* @param auditEntryIds the audit entry IDs to delete * @param auditEntryIds
* @return Returns the number of entries deleted * the audit entry IDs to delete
*/ * @return Returns the number of entries deleted
int deleteAuditEntries(List<Long> auditEntryIds); */
int deleteAuditEntries(List<Long> auditEntryIds);
/**
* Check if an audit path is enabled. The path will be disabled if it or any higher /**
* path has been explicitly disabled. Any disabled path will not be processed when * Check if an audit path is enabled. The path will be disabled if it or any higher path has been explicitly disabled. Any disabled path will not be processed when data is audited.
* data is audited. *
* * @param applicationName
* @param applicationName the name of the application being logged to * the name of the application being logged to
* @param path the audit path to check or <tt>null</tt> to assume the * @param path
* application's root path * the audit path to check or <tt>null</tt> to assume the application's root path
* @return Returns <tt>true</tt> if the audit path has been disabled * @return Returns <tt>true</tt> if the audit path has been disabled
* *
* @since 3.2 * @since 3.2
*/ */
boolean isAuditPathEnabled(String applicationName, String path); boolean isAuditPathEnabled(String applicationName, String path);
/** /**
* Enable auditing (if it is not already enabled) for all paths that contain the given path. * Enable auditing (if it is not already enabled) for all paths that contain the given path. The path is the path as originally logged and not the path that the generated data may contain - although this would be similarly enabled.
* The path is the path as originally logged and * <p>
* not the path that the generated data may contain - although this would be similarly * If the enabled
* enabled. *
* <p> * @param applicationName
* If the enabled * the name of the application being logged to
* * @param path
* @param applicationName the name of the application being logged to * the audit path to check or <tt>null</tt> to assume the application's root path
* @param path the audit path to check or <tt>null</tt> to assume the *
* application's root path * @since 3.2
* */
* @since 3.2 void enableAudit(String applicationName, String path);
*/
void enableAudit(String applicationName, String path); /**
* Disable auditing (if it is not already disabled) for all paths that contain the given path. The path is the path as originally logged and not the path that the generated data may contain - although this would be similarly disabled.
/** * <p>
* Disable auditing (if it is not already disabled) for all paths that contain the given path. * If the path is <b>/x/y</b> then any data paths that start with <b>/x/y</b> will be stripped out <u>before</u> data generators and data recorders are applied. If the path represents the root path of the application, then auditing for that application is effectively disabled.
* The path is the path as originally logged and *
* not the path that the generated data may contain - although this would be similarly * @param applicationName
* disabled. * the name of the application being logged to
* <p> * @param path
* If the path is <b>/x/y</b> then any data paths that start with <b>/x/y</b> will be stripped * the audit path to check or <tt>null</tt> to assume the application's root path
* out <u>before</u> data generators and data recorders are applied. If the path represents *
* the root path of the application, then auditing for that application is effectively disabled. * @since 3.2
* */
* @param applicationName the name of the application being logged to void disableAudit(String applicationName, String path);
* @param path the audit path to check or <tt>null</tt> to assume the
* application's root path /**
* * Remove all disabled paths i.e. enable all per-path based auditing. Auditing may still be disabled globally. This is primarily for test purposes; applications should know which paths need {@link #enableAudit(String, String) enabling} or {@link #disableAudit(String, String) disabled}.
* @since 3.2 *
*/ * @param applicationName
void disableAudit(String applicationName, String path); * the name of the application
*
/** * @since 3.2
* Remove all disabled paths i.e. enable all per-path based auditing. Auditing may still be */
* disabled globally. This is primarily for test purposes; applications should know which void resetDisabledPaths(String applicationName);
* paths need {@link #enableAudit(String, String) enabling} or
* {@link #disableAudit(String, String) disabled}. /**
* * Create an audit entry for the given map of values. The map key is a path - starting with '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) - relative to the root path provided.
* @param applicationName the name of the application * <p/>
* * The root path and value keys are combined to produce a map of data keyed by full path. This fully-pathed map is then passed through the {@link AuditModelRegistry#getAuditPathMapper() audit path mapper}. The result may yield data destined for several different {@link AuditModelRegistry#getAuditApplicationByKey(String) audit applications}. depending on the data extraction and generation defined in the applications, values (or derived values) may be recorded against several audit entries (one per application represented).
* @since 3.2 * <p/>
*/ * The return values reflect what was actually persisted and is controlled by the data extractors defined in the audit configuration.
void resetDisabledPaths(String applicationName); * <p/>
* A new read-write transaction is started if there are values to write that there is not a viable transaction present.
/** *
* Create an audit entry for the given map of values. The map key is a path - starting with '/' * @param rootPath
* ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) - relative to the root path provided. * a base path of {@link AuditPath} key entries concatenated with the path separator '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR})
* <p/> * @param values
* The root path and value keys are combined to produce a map of data keyed by full path. This * the values to audit mapped by {@link AuditPath} key relative to root path (may be <tt>null</tt>)
* fully-pathed map is then passed through the * @return Returns the values that were actually persisted, keyed by their full path.
* {@link AuditModelRegistry#getAuditPathMapper() audit path mapper}. The result may yield data * @throws IllegalStateException
* destined for several different * if the transaction state could not be determined
* {@link AuditModelRegistry#getAuditApplicationByKey(String) audit applications}. depending on *
* the data extraction and generation defined in the applications, values (or derived values) may * @since 3.2
* be recorded against several audit entries (one per application represented). */
* <p/> Map<String, Serializable> recordAuditValues(String rootPath, Map<String, Serializable> values);
* The return values reflect what was actually persisted and is controlled by the data extractors
* defined in the audit configuration. /**
* <p/> * The same as {@link AuditComponent#recordAuditValues(String, Map)}, but with controlled usage of userFilter
* A new read-write transaction is started if there are values to write that there is not a viable *
* transaction present. * @param rootPath
* * a base path of {@link AuditPath} key entries concatenated with the path separator '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR})
* @param rootPath a base path of {@link AuditPath} key entries concatenated with the path separator * @param values
* '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) * the values to audit mapped by {@link AuditPath} key relative to root path (may be <tt>null</tt>)
* @param values the values to audit mapped by {@link AuditPath} key relative to root path * @param useUserFilter
* (may be <tt>null</tt>) * if <tt>false</tt> the user filter is disabled.
* @return Returns the values that were actually persisted, keyed by their full path. * @return Returns the values that were actually persisted, keyed by their full path.
* @throws IllegalStateException if the transaction state could not be determined * @throws IllegalStateException
* * if the transaction state could not be determined
* @since 3.2 */
*/ Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter);
Map<String, Serializable> recordAuditValues(String rootPath, Map<String, Serializable> values);
/**
/** * Find audit entries using the given parameters
* The same as {@link AuditComponent#recordAuditValues(String, Map)}, but with controlled usage of userFilter *
* * @param callback
* @param rootPath a base path of {@link AuditPath} key entries concatenated with the path separator * the data callback per entry
* '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) * @param parameters
* @param values the values to audit mapped by {@link AuditPath} key relative to root path * the parameters for the query (may not be <tt>null</tt>)
* (may be <tt>null</tt>) * @param maxResults
* @param useUserFilter if <tt>false</tt> the user filter is disabled. * the maximum number of results to retrieve (must be greater than 0)
* @return Returns the values that were actually persisted, keyed by their full path. *
* @throws IllegalStateException if the transaction state could not be determined * @throws IllegalArgumentException
*/ * if maxResults less or equal to zero
Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter); *
* @since 3.2
/** */
* Find audit entries using the given parameters void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults);
*
* @param callback the data callback per entry /**
* @param parameters the parameters for the query (may not be <tt>null</tt>) * Issue an audit query to retrieve min / max audit record id for a given application.
* @param maxResults the maximum number of results to retrieve (must be greater than 0) *
* * @param applicationName
* @throws IllegalArgumentException if maxResults less or equal to zero * the name of the application
* * @param extremes
* @since 3.2 * a list containing min/max or both
*/ * @return a map containing min/max and the associated value
void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults); */
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes);
/**
* Issue an audit query to retrieve min / max audit record id for a given application. /**
* * Issue an audit query to retrieve count of records for a given application.
* @param applicationName the name of the application *
* @param extremes a list containing min/max or both * @param applicationName
* @return a map containing min/max and the associated value * the name of the application
*/ * @return a map containing min/max and the associated value
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes); */
default int getAuditEntriesCountByApp(String applicationName)
/** {
* Issue an audit query to retrieve count of records for a given application. return -1;
* }
* @param applicationName the name of the application
* @return a map containing min/max and the associated value /**
*/ * Issue an audit query to retrieve count of records for a given application and properties
default int getAuditEntriesCountByApp(String applicationName) *
{ * @param applicationName
return -1; * 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
* Issue an audit query to retrieve count of records for a given application and properties */
* default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
* @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 return -1;
*/ }
default int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters) }
{
return -1;
}
}

View File

@@ -1,197 +1,210 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2024 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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.audit; package org.alfresco.repo.audit;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.alfresco.service.cmr.audit.AuditQueryParameters; import org.alfresco.service.cmr.audit.AuditQueryParameters;
import org.alfresco.service.cmr.audit.AuditService; import org.alfresco.service.cmr.audit.AuditService;
/** /**
* The implementation of the AuditService for application auditing. * The implementation of the AuditService for application auditing.
* *
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
public class AuditServiceImpl implements AuditService public class AuditServiceImpl implements AuditService
{ {
private AuditComponent auditComponent; private AuditComponent auditComponent;
public AuditServiceImpl() public AuditServiceImpl()
{ {
super(); super();
} }
public void setAuditComponent(AuditComponent auditComponent) public void setAuditComponent(AuditComponent auditComponent)
{ {
this.auditComponent = auditComponent; this.auditComponent = auditComponent;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
* @since 3.4 *
*/ * @since 3.4
public boolean isAuditEnabled() */
{ public boolean isAuditEnabled()
return auditComponent.isAuditEnabled(); {
} return auditComponent.isAuditEnabled();
}
/**
* {@inheritDoc} /**
* @since 3.4 * {@inheritDoc}
*/ *
@Override * @since 3.4
public void setAuditEnabled(boolean enable) */
{ @Override
auditComponent.setAuditEnabled(enable); public void setAuditEnabled(boolean enable)
} {
auditComponent.setAuditEnabled(enable);
/** }
* {@inheritDoc}
* @since 3.4 /**
*/ * {@inheritDoc}
@Override *
public Map<String, AuditApplication> getAuditApplications() * @since 3.4
{ */
Map<String, org.alfresco.repo.audit.model.AuditApplication> apps = auditComponent.getAuditApplications(); @Override
public Map<String, AuditApplication> getAuditApplications()
Map<String, AuditApplication> ret = new TreeMap<String, AuditApplication>(); {
for (String app : apps.keySet()) Map<String, org.alfresco.repo.audit.model.AuditApplication> apps = auditComponent.getAuditApplications();
{
String name = app; Map<String, AuditApplication> ret = new TreeMap<String, AuditApplication>();
String key = org.alfresco.repo.audit.model.AuditApplication.AUDIT_PATH_SEPARATOR + apps.get(app).getApplicationKey(); for (String app : apps.keySet())
boolean enabled = auditComponent.isAuditPathEnabled(app, key); {
AuditApplication auditApplication = new AuditApplication(name, key, enabled); String name = app;
ret.put(name, auditApplication); String key = org.alfresco.repo.audit.model.AuditApplication.AUDIT_PATH_SEPARATOR + apps.get(app).getApplicationKey();
} boolean enabled = auditComponent.isAuditPathEnabled(app, key);
return ret; AuditApplication auditApplication = new AuditApplication(name, key, enabled);
} ret.put(name, auditApplication);
}
/** return ret;
* {@inheritDoc} }
* @since 3.2
*/ /**
public boolean isAuditEnabled(String applicationName, String path) * {@inheritDoc}
{ *
return auditComponent.isAuditPathEnabled(applicationName, path); * @since 3.2
} */
public boolean isAuditEnabled(String applicationName, String path)
/** {
* {@inheritDoc} return auditComponent.isAuditPathEnabled(applicationName, path);
* @since 3.2 }
*/
public void enableAudit(String applicationName, String path) /**
{ * {@inheritDoc}
auditComponent.enableAudit(applicationName, path); *
} * @since 3.2
*/
/** public void enableAudit(String applicationName, String path)
* {@inheritDoc} {
* @since 3.2 auditComponent.enableAudit(applicationName, path);
*/ }
public void disableAudit(String applicationName, String path)
{ /**
auditComponent.disableAudit(applicationName, path); * {@inheritDoc}
} *
* @since 3.2
/** */
* {@inheritDoc} public void disableAudit(String applicationName, String path)
* @since 3.2 {
*/ auditComponent.disableAudit(applicationName, path);
public int clearAudit(String applicationName) }
{
Long now = Long.valueOf(System.currentTimeMillis()); /**
return auditComponent.deleteAuditEntries(applicationName, null, now); * {@inheritDoc}
} *
* @since 3.2
/** */
* {@inheritDoc} public int clearAudit(String applicationName)
* @since 3.4 {
*/ Long now = Long.valueOf(System.currentTimeMillis());
@Override return auditComponent.deleteAuditEntries(applicationName, null, now);
public int clearAudit(String applicationName, Long fromTime, Long toTime) }
{
toTime = (toTime == null) ? Long.valueOf(System.currentTimeMillis()) : toTime; /**
return auditComponent.deleteAuditEntries(applicationName, fromTime, toTime); * {@inheritDoc}
} *
* @since 3.4
/** */
* {@inheritDoc} @Override
* @since 5.2.2 public int clearAudit(String applicationName, Long fromTime, Long toTime)
*/ {
@Override toTime = (toTime == null) ? Long.valueOf(System.currentTimeMillis()) : toTime;
public int clearAuditByIdRange(String applicationName, Long fromId, Long toId) return auditComponent.deleteAuditEntries(applicationName, fromTime, toTime);
{ }
return auditComponent.deleteAuditEntriesByIdRange(applicationName, fromId, toId);
} /**
* {@inheritDoc}
/** *
* {@inheritDoc} * @since 5.2.2
* @since 3.4 */
*/ @Override
@Override public int clearAuditByIdRange(String applicationName, Long fromId, Long toId)
public int clearAudit(List<Long> auditEntryIds) {
{ return auditComponent.deleteAuditEntriesByIdRange(applicationName, fromId, toId);
return auditComponent.deleteAuditEntries(auditEntryIds); }
}
/**
/** * {@inheritDoc}
* {@inheritDoc} *
* @since 3.3 * @since 3.4
*/ */
public void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults) @Override
{ public int clearAudit(List<Long> auditEntryIds)
auditComponent.auditQuery(callback, parameters, maxResults); {
} return auditComponent.deleteAuditEntries(auditEntryIds);
}
/**
* {@inheritDoc} /**
*/ * {@inheritDoc}
public HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes) *
{ * @since 3.3
return auditComponent.getAuditMinMaxByApp(applicationName, extremes); */
} public void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults)
{
/** auditComponent.auditQuery(callback, parameters, maxResults);
* {@inheritDoc} }
*/
@Override /**
public int getAuditEntriesCountByApp(String applicationName) * {@inheritDoc}
{ */
return auditComponent.getAuditEntriesCountByApp(applicationName); public HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes)
} {
return auditComponent.getAuditMinMaxByApp(applicationName, extremes);
/** }
* {@inheritDoc}
*/ /**
@Override public int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters) * {@inheritDoc}
{ */
return auditComponent.getAuditEntriesCountByAppAndProperties(parameters); @Override
} public int getAuditEntriesCountByApp(String applicationName)
} {
return auditComponent.getAuditEntriesCountByApp(applicationName);
}
/**
* {@inheritDoc}
*/
@Override
public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
{
return auditComponent.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
}
}

View File

@@ -1,123 +1,117 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2024 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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.domain; package org.alfresco.repo.domain;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
/** /**
* Helper class to calculate CRC values for string persistence. * Helper class to calculate CRC values for string persistence.
* *
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
public class CrcHelper public class CrcHelper
{ {
public static final String EMPTY_STRING = ".empty"; public static final String EMPTY_STRING = ".empty";
/** /**
* Calculate a persistable, unique pair of values that can be persisted in a database unique * Calculate a persistable, unique pair of values that can be persisted in a database unique key and guarantee correct case-sensitivity.
* key and guarantee correct case-sensitivity. * <p>
* <p> * While the short-string version of the value is always lowercase, the CRC is calculated from the virgin string if case-sensitivity is enforced; in the case-insensitive case, the CRC is calculated from a lowercase version of the string.
* While the short-string version of the value is always lowercase, the CRC is * <p>
* calculated from the virgin string if case-sensitivity is enforced; in the case-insensitive * If the value is an empty string, then {@link #EMPTY_STRING} is used instead. This ensures that persisted values don't fall foul of the Oracle empty string comparison "behaviour" i.e you should never persist an empty string in Oracle as it equates to a SQL <b>NULL</b>.
* case, the CRC is calculated from a lowercase version of the string. *
* <p> * @param value
* If the value is an empty string, then {@link #EMPTY_STRING} is used instead. This ensures * the raw value that will be persisted
* that persisted values don't fall foul of the Oracle empty string comparison "behaviour" i.e * @param dataLength
* you should never persist an empty string in Oracle as it equates to a SQL <b>NULL</b>. * the maximum number of characters that can be persisted
* * @param useCharsFromStart
* @param value the raw value that will be persisted * <tt>true</tt> if the shortened string value must be made from the first characters of the string or <tt>false</tt> to use characters from the end of the string.
* @param dataLength the maximum number of characters that can be persisted * @param caseSensitive
* @param useCharsFromStart <tt>true</tt> if the shortened string value must be made from * <tt>true</tt> if the resulting pair must be case-sensitive or <tt>false</tt> if the pair must be case-insensitive.
* the first characters of the string or <tt>false</tt> to use * @return Return the persistable pair. The result will never be <tt>null</tt>, but the individual pair values will be <tt>null</tt> if the value given is <tt>null</tt>
* characters from the end of the string. */
* @param caseSensitive <tt>true</tt> if the resulting pair must be case-sensitive or public static Pair<String, Long> getStringCrcPair(
* <tt>false</tt> if the pair must be case-insensitive. String value,
* @return Return the persistable pair. The result will never be <tt>null</tt>, int dataLength,
* but the individual pair values will be <tt>null</tt> if the boolean useCharsFromStart,
* value given is <tt>null</tt> boolean caseSensitive)
*/ {
public static Pair<String, Long> getStringCrcPair( String valueLowerCase;
String value, if (value == null)
int dataLength, {
boolean useCharsFromStart, return new Pair<String, Long>(null, null);
boolean caseSensitive) }
{ else if (value.length() == 0)
String valueLowerCase; {
if (value == null) value = CrcHelper.EMPTY_STRING;
{ valueLowerCase = value;
return new Pair<String, Long>(null, null); }
} else
else if (value.length() == 0) {
{ valueLowerCase = value.toLowerCase();
value = CrcHelper.EMPTY_STRING; }
valueLowerCase = value; Long valueCrc;
} try
else {
{ CRC32 crc = new CRC32();
valueLowerCase = value.toLowerCase(); if (caseSensitive)
} {
Long valueCrc; crc.update(value.getBytes("UTF-8"));
try }
{ else
CRC32 crc = new CRC32(); {
if (caseSensitive) crc.update(valueLowerCase.getBytes("UTF-8"));
{ }
crc.update(value.getBytes("UTF-8")); valueCrc = crc.getValue();
} }
else catch (UnsupportedEncodingException e)
{ {
crc.update(valueLowerCase.getBytes("UTF-8")); throw new RuntimeException("UTF-8 encoding is not supported");
}
valueCrc = crc.getValue(); }
} // Get the short value (case-sensitive or not)
catch (UnsupportedEncodingException e) String valueShort = null;
{ int valueLen = valueLowerCase.length();
throw new RuntimeException("UTF-8 encoding is not supported"); if (valueLen < dataLength)
} {
// Crc Value will change based on the case-sensitive, So we need to get the short value based on case-sensitive valueShort = valueLowerCase;
String valueShort = null; }
String currentValue = caseSensitive ? value : valueLowerCase; else if (useCharsFromStart)
int valueLen = currentValue.length(); {
if (valueLen < dataLength) valueShort = valueLowerCase.substring(0, dataLength - 1);
{ }
valueShort = currentValue; else
} {
else if (useCharsFromStart) valueShort = valueLowerCase.substring(valueLen - dataLength);
{ }
valueShort = currentValue.substring(0, dataLength - 1); return new Pair<String, Long>(valueShort, valueCrc);
} }
else }
{
valueShort = currentValue.substring(valueLen - dataLength);
}
return new Pair<String, Long>(valueShort, valueCrc);
}
}

View File

@@ -1,258 +1,285 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2024 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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.domain.audit; package org.alfresco.repo.domain.audit;
import java.io.Serializable; import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback; import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
/** /**
* DAO services for <b>alf_audit_XXX</b> tables. * DAO services for <b>alf_audit_XXX</b> tables.
* <p> * <p>
* The older methods are supported by a different implementation and will eventually * The older methods are supported by a different implementation and will eventually be deprecated and phased out.
* be deprecated and phased out. *
* * @author Derek Hulley
* @author Derek Hulley * @since 3.2
* @since 3.2 */
*/ public interface AuditDAO
public interface AuditDAO {
{ /* V3.2 methods after here only, please */
/*
* V3.2 methods after here only, please /**
*/ * Information about the audit application to be passed in an out of the interface.
*
/** * @author Derek Hulley
* Information about the audit application to be passed in an out of the interface. * @since 3.2
* */
* @author Derek Hulley public static class AuditApplicationInfo
* @since 3.2 {
*/ private Long id;
public static class AuditApplicationInfo private String name;
{ private Long modelId;
private Long id; private Long disabledPathsId;
private String name;
private Long modelId; @Override
private Long disabledPathsId; public String toString()
{
@Override StringBuilder sb = new StringBuilder();
public String toString() sb.append("AuditApplicationInfo ")
{ .append("[ id=").append(id)
StringBuilder sb = new StringBuilder(); .append(", name=").append(name)
sb.append("AuditApplicationInfo ") .append(", modelId=").append(modelId)
.append("[ id=").append(id) .append(", disabledPathsId=").append(disabledPathsId)
.append(", name=").append(name) .append("]");
.append(", modelId=").append(modelId) return sb.toString();
.append(", disabledPathsId=").append(disabledPathsId) }
.append("]");
return sb.toString(); public Long getId()
} {
return id;
public Long getId() }
{
return id; public void setId(Long id)
} {
public void setId(Long id) this.id = id;
{ }
this.id = id;
} public String getName()
public String getName() {
{ return name;
return name; }
}
public void setname(String name) public void setname(String name)
{ {
this.name = name; this.name = name;
} }
public Long getModelId()
{ public Long getModelId()
return modelId; {
} return modelId;
public void setModelId(Long modelId) }
{
this.modelId = modelId; public void setModelId(Long modelId)
} {
public Long getDisabledPathsId() this.modelId = modelId;
{ }
return disabledPathsId;
} public Long getDisabledPathsId()
public void setDisabledPathsId(Long disabledPathsId) {
{ return disabledPathsId;
this.disabledPathsId = disabledPathsId; }
}
} public void setDisabledPathsId(Long disabledPathsId)
{
/** this.disabledPathsId = disabledPathsId;
* Creates a new audit model entry or finds an existing one }
* }
* @param url the URL of the configuration
* @return Returns the ID of the config matching the input stream and the /**
* content storage details * Creates a new audit model entry or finds an existing one
* @since 3.2 *
*/ * @param url
Pair<Long, ContentData> getOrCreateAuditModel(URL url); * the URL of the configuration
* @return Returns the ID of the config matching the input stream and the content storage details
/** * @since 3.2
* Get the audit application details. */
* Pair<Long, ContentData> getOrCreateAuditModel(URL url);
* @param applicationName the name of the application
* @return Returns details of an existing application or <tt>null</tt> if it doesn't exist /**
* * Get the audit application details.
* @since 3.2 *
*/ * @param applicationName
AuditApplicationInfo getAuditApplication(String applicationName); * the name of the application
* @return Returns details of an existing application or <tt>null</tt> if it doesn't exist
/** *
* Creates a new audit application. The application name must be unique. * @since 3.2
* */
* @param application the name of the application AuditApplicationInfo getAuditApplication(String applicationName);
* @param modelId the ID of the model configuration
* /**
* @since 3.2 * Creates a new audit application. The application name must be unique.
*/ *
AuditApplicationInfo createAuditApplication(String application, Long modelId); * @param application
* the name of the application
/** * @param modelId
* Update the audit application to refer to a new model. * the ID of the model configuration
* If the model did not change, then nothing will be done. *
* * @since 3.2
* @param id the ID of the audit application */
* @param modelId the ID of the new model AuditApplicationInfo createAuditApplication(String application, Long modelId);
*
* @since 3.2 /**
*/ * Update the audit application to refer to a new model. If the model did not change, then nothing will be done.
void updateAuditApplicationModel(Long id, Long modelId); *
* @param id
/** * the ID of the audit application
* Update the audit application to hold a new set of disabled paths. * @param modelId
* If the value did not change, then nothing will be done. * the ID of the new model
* *
* @param id the ID of the audit application * @since 3.2
* @param disabledPaths the new disabled paths */
* void updateAuditApplicationModel(Long id, Long modelId);
* @since 3.2
*/ /**
void updateAuditApplicationDisabledPaths(Long id, Set<String> disabledPaths); * Update the audit application to hold a new set of disabled paths. If the value did not change, then nothing will be done.
*
/** * @param id
* Delete audit entries for the application, possibly limiting the time range. * the ID of the audit application
* * @param disabledPaths
* @param applicationId an existing audit application ID * the new disabled paths
* @param fromTime the minimum entry time (inclusive, optional) *
* @param toTime the maximum entry time (exclusive, optional) * @since 3.2
* @return Returns the number of entries deleted */
* void updateAuditApplicationDisabledPaths(Long id, Set<String> disabledPaths);
* @since 3.2
*/ /**
int deleteAuditEntries(Long applicationId, Long fromTime, Long toTime); * Delete audit entries for the application, possibly limiting the time range.
*
/** * @param applicationId
* Delete audit entries for the application for given id range. * an existing audit application ID
* * @param fromTime
* @param applicationId an existing audit application ID * the minimum entry time (inclusive, optional)
* @param fromId the minimum fromId (inclusive, optional) * @param toTime
* @param toId the maximum toId (exclusive, optional) * the maximum entry time (exclusive, optional)
* @return Returns the number of entries deleted * @return Returns the number of entries deleted
* *
* @since 5.2.2 * @since 3.2
*/ */
int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId); int deleteAuditEntries(Long applicationId, Long fromTime, Long toTime);
/** /**
* Delete a discrete list of audit entries. Duplicate entries are collapsed * Delete audit entries for the application for given id range.
* and the number of entries deleted will match the count of unique IDs in *
* the list; otherwise a concurrency condition has occured and an exception * @param applicationId
* will be generated. * an existing audit application ID
* * @param fromId
* @param auditEntryIds the IDs of all audit entries to delete * the minimum fromId (inclusive, optional)
* @return Returns the number of entries deleted * @param toId
*/ * the maximum toId (exclusive, optional)
int deleteAuditEntries(List<Long> auditEntryIds); * @return Returns the number of entries deleted
*
/** * @since 5.2.2
* Create a new audit entry with the given map of values. */
* int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId);
* @param applicationId an existing audit application ID
* @param time the time (ms since epoch) to log the entry against /**
* @param username the authenticated user (<tt>null</tt> if not present) * Delete a discrete list of audit entries. Duplicate entries are collapsed and the number of entries deleted will match the count of unique IDs in the list; otherwise a concurrency condition has occured and an exception will be generated.
* @param values the values to record *
* @return Returns the unique entry ID * @param auditEntryIds
* * the IDs of all audit entries to delete
* @since 3.2 * @return Returns the number of entries deleted
*/ */
Long createAuditEntry(Long applicationId, long time, String username, Map<String, Serializable> values); int deleteAuditEntries(List<Long> auditEntryIds);
/** /**
* Find audit entries using the given parameters, any of which may be null * Create a new audit entry with the given map of values.
* *
* @param callback the data callback per entry * @param applicationId
* @param parameters the parameters for the query (may not be <tt>null</tt>) * an existing audit application ID
* @param maxResults the maximum number of results to retrieve (must be greater than 0) * @param time
* * the time (ms since epoch) to log the entry against
* @throws IllegalArgumentException if maxResults less or equal to zero * @param username
*/ * the authenticated user (<tt>null</tt> if not present)
void findAuditEntries( * @param values
AuditQueryCallback callback, * the values to record
org.alfresco.service.cmr.audit.AuditQueryParameters parameters, * @return Returns the unique entry ID
int maxResults); *
* @since 3.2
/** */
* Issue an audit query to retrieve min / max audit record id for a given application. Long createAuditEntry(Long applicationId, long time, String username, Map<String, Serializable> values);
*
* @param appId the database id of the application /**
* @param extremes a list containing min/max or both * Find audit entries using the given parameters, any of which may be null
* @return a map containing min/max and the associated value *
*/ * @param callback
HashMap<String, Long> getAuditMinMaxByApp(long appId, List<String> extremes); * the data callback per entry
* @param parameters
/** * the parameters for the query (may not be <tt>null</tt>)
* Issue an audit query to retrieve count of records for a given application. * @param maxResults
* * the maximum number of results to retrieve (must be greater than 0)
* @param applicationId the database id of the application *
* @return a map containing min/max and the associated value * @throws IllegalArgumentException
*/ * if maxResults less or equal to zero
default int getAuditEntriesCountByApp(long applicationId) */
{ void findAuditEntries(
return -1; AuditQueryCallback callback,
} org.alfresco.service.cmr.audit.AuditQueryParameters parameters,
int maxResults);
/**
* Issue an audit query to retrieve count of records for a given application and properties /**
* * Issue an audit query to retrieve min / max audit record id for a given 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 * @param appId
*/ * the database id of the application
default int getAuditEntriesCountByAppAndProperties(org.alfresco.service.cmr.audit.AuditQueryParameters parameters) * @param extremes
{ * a list containing min/max or both
return -1; * @return a map containing min/max and the associated value
} */
} 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;
}
/**
* 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;
}
}

View File

@@ -1,316 +1,315 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2024 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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.domain.audit.ibatis; package org.alfresco.repo.domain.audit.ibatis;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.alfresco.repo.domain.audit.AbstractAuditDAOImpl; import org.apache.ibatis.session.RowBounds;
import org.alfresco.repo.domain.audit.AuditApplicationEntity; import org.mybatis.spring.SqlSessionTemplate;
import org.alfresco.repo.domain.audit.AuditDeleteParameters; import org.springframework.dao.ConcurrencyFailureException;
import org.alfresco.repo.domain.audit.AuditEntryEntity;
import org.alfresco.repo.domain.audit.AuditModelEntity; import org.alfresco.repo.domain.audit.AbstractAuditDAOImpl;
import org.alfresco.repo.domain.audit.AuditQueryParameters; import org.alfresco.repo.domain.audit.AuditApplicationEntity;
import org.alfresco.repo.domain.audit.AuditQueryResult; import org.alfresco.repo.domain.audit.AuditDeleteParameters;
import org.alfresco.repo.domain.propval.PropertyValueDAO.PropertyFinderCallback; import org.alfresco.repo.domain.audit.AuditEntryEntity;
import org.alfresco.util.Pair; import org.alfresco.repo.domain.audit.AuditModelEntity;
import org.apache.ibatis.session.RowBounds; import org.alfresco.repo.domain.audit.AuditQueryParameters;
import org.mybatis.spring.SqlSessionTemplate; import org.alfresco.repo.domain.audit.AuditQueryResult;
import org.springframework.dao.ConcurrencyFailureException; import org.alfresco.repo.domain.propval.PropertyValueDAO.PropertyFinderCallback;
import org.alfresco.util.Pair;
/**
* iBatis-specific implementation of the DAO for <b>alf_audit_XXX</b> tables. /**
* * iBatis-specific implementation of the DAO for <b>alf_audit_XXX</b> tables.
* @author Derek Hulley *
* @since 3.2 * @author Derek Hulley
*/ * @since 3.2
public class AuditDAOImpl extends AbstractAuditDAOImpl */
{ public class AuditDAOImpl extends AbstractAuditDAOImpl
private static final String SELECT_MODEL_BY_CRC = "alfresco.audit.select_AuditModelByCrc"; {
private static final String INSERT_MODEL = "alfresco.audit.insert.insert_AuditModel"; private static final String SELECT_MODEL_BY_CRC = "alfresco.audit.select_AuditModelByCrc";
private static final String INSERT_MODEL = "alfresco.audit.insert.insert_AuditModel";
private static final String SELECT_APPLICATION_BY_ID = "alfresco.audit.select_AuditApplicationById";
private static final String SELECT_APPLICATION_BY_NAME_ID = "alfresco.audit.select_AuditApplicationByNameId"; private static final String SELECT_APPLICATION_BY_ID = "alfresco.audit.select_AuditApplicationById";
private static final String INSERT_APPLICATION = "alfresco.audit.insert.insert_AuditApplication"; private static final String SELECT_APPLICATION_BY_NAME_ID = "alfresco.audit.select_AuditApplicationByNameId";
private static final String UPDATE_APPLICATION = "alfresco.audit.update_AuditApplication"; private static final String INSERT_APPLICATION = "alfresco.audit.insert.insert_AuditApplication";
private static final String UPDATE_APPLICATION = "alfresco.audit.update_AuditApplication";
private static final String DELETE_ENTRIES = "alfresco.audit.delete_AuditEntries";
private static final String DELETE_ENTRIES_BY_ID = "alfresco.audit.delete_AuditEntriesById"; private static final String DELETE_ENTRIES = "alfresco.audit.delete_AuditEntries";
private static final String INSERT_ENTRY = "alfresco.audit.insert.insert_AuditEntry"; private static final String DELETE_ENTRIES_BY_ID = "alfresco.audit.delete_AuditEntriesById";
private static final String SELECT_MINMAX_ENTRY_FOR_APP = "alfresco.audit.select_MinMaxAuditEntryId"; private static final String INSERT_ENTRY = "alfresco.audit.insert.insert_AuditEntry";
private static final String SELECT_COUNT_ENTRIES_FOR_APP = "alfresco.audit.select_CountAuditEntryId"; private static final String SELECT_MINMAX_ENTRY_FOR_APP = "alfresco.audit.select_MinMaxAuditEntryId";
private static final String SELECT_COUNT_ENTRIES_FOR_APP_WITH_PROPERTIES = "select_CountAuditEntryIdWithWhereClause"; 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"; @SuppressWarnings("unused")
private static final String SELECT_ENTRIES_WITH_VALUES = "alfresco.audit.select_AuditEntriesWithValues"; private static final String SELECT_ENTRIES_SIMPLE = "alfresco.audit.select_AuditEntriesSimple";
private static final String SELECT_ENTRIES_WITHOUT_VALUES = "alfresco.audit.select_AuditEntriesWithoutValues"; private static final String SELECT_ENTRIES_WITH_VALUES = "alfresco.audit.select_AuditEntriesWithValues";
private static final String SELECT_ENTRIES_WITHOUT_VALUES = "alfresco.audit.select_AuditEntriesWithoutValues";
private SqlSessionTemplate template;
private SqlSessionTemplate template;
public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
{ public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
this.template = sqlSessionTemplate; {
} this.template = sqlSessionTemplate;
}
@Override
protected AuditModelEntity getAuditModelByCrc(long crc) @Override
{ protected AuditModelEntity getAuditModelByCrc(long crc)
AuditModelEntity entity = new AuditModelEntity(); {
entity.setContentCrc(crc); AuditModelEntity entity = new AuditModelEntity();
entity = template.selectOne( entity.setContentCrc(crc);
SELECT_MODEL_BY_CRC, entity = template.selectOne(
entity); SELECT_MODEL_BY_CRC,
// Done entity);
return entity; // Done
} return entity;
}
@Override
protected AuditModelEntity createAuditModel(Long contentDataId, long crc) @Override
{ protected AuditModelEntity createAuditModel(Long contentDataId, long crc)
AuditModelEntity entity = new AuditModelEntity(); {
entity.setContentDataId(contentDataId); AuditModelEntity entity = new AuditModelEntity();
entity.setContentCrc(crc); entity.setContentDataId(contentDataId);
template.insert(INSERT_MODEL, entity); entity.setContentCrc(crc);
return entity; template.insert(INSERT_MODEL, entity);
} return entity;
}
@Override
protected AuditApplicationEntity getAuditApplicationById(Long id) @Override
{ protected AuditApplicationEntity getAuditApplicationById(Long id)
Map<String, Object> params = new HashMap<String, Object>(11); {
params.put("id", id); Map<String, Object> params = new HashMap<String, Object>(11);
AuditApplicationEntity entity = template.selectOne( params.put("id", id);
SELECT_APPLICATION_BY_ID, AuditApplicationEntity entity = template.selectOne(
params); SELECT_APPLICATION_BY_ID,
// Done params);
if (logger.isDebugEnabled()) // Done
{ if (logger.isDebugEnabled())
logger.debug("Searched for audit application ID " + id + " and found: " + entity); {
} logger.debug("Searched for audit application ID " + id + " and found: " + entity);
return entity; }
} return entity;
}
@Override
protected AuditApplicationEntity getAuditApplicationByName(String appName) @Override
{ protected AuditApplicationEntity getAuditApplicationByName(String appName)
// Resolve the name as a property ID {
Pair<Long, Serializable> appNamePair = propertyValueDAO.getPropertyValue(appName); // Resolve the name as a property ID
if (appNamePair == null) Pair<Long, Serializable> appNamePair = propertyValueDAO.getPropertyValue(appName);
{ if (appNamePair == null)
// There will be no results {
return null; // There will be no results
} return null;
}
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("id", appNamePair.getFirst()); Map<String, Object> params = new HashMap<String, Object>(11);
AuditApplicationEntity entity = template.selectOne( params.put("id", appNamePair.getFirst());
SELECT_APPLICATION_BY_NAME_ID, AuditApplicationEntity entity = template.selectOne(
params); SELECT_APPLICATION_BY_NAME_ID,
// Done params);
if (logger.isDebugEnabled()) // Done
{ if (logger.isDebugEnabled())
logger.debug("Searched for audit application '" + appName + "' and found: " + entity); {
} logger.debug("Searched for audit application '" + appName + "' and found: " + entity);
return entity; }
} return entity;
}
@Override
protected AuditApplicationEntity createAuditApplication(Long appNameId, Long modelId, Long disabledPathsId) @Override
{ protected AuditApplicationEntity createAuditApplication(Long appNameId, Long modelId, Long disabledPathsId)
AuditApplicationEntity entity = new AuditApplicationEntity(); {
entity.setVersion((short)0); AuditApplicationEntity entity = new AuditApplicationEntity();
entity.setApplicationNameId(appNameId); entity.setVersion((short) 0);
entity.setAuditModelId(modelId); entity.setApplicationNameId(appNameId);
entity.setDisabledPathsId(disabledPathsId); entity.setAuditModelId(modelId);
template.insert(INSERT_APPLICATION, entity); entity.setDisabledPathsId(disabledPathsId);
return entity; template.insert(INSERT_APPLICATION, entity);
} return entity;
}
@Override
protected AuditApplicationEntity updateAuditApplication(AuditApplicationEntity entity) @Override
{ protected AuditApplicationEntity updateAuditApplication(AuditApplicationEntity entity)
AuditApplicationEntity updateEntity = new AuditApplicationEntity(); {
updateEntity.setId(entity.getId()); AuditApplicationEntity updateEntity = new AuditApplicationEntity();
updateEntity.setVersion(entity.getVersion()); updateEntity.setId(entity.getId());
updateEntity.incrementVersion(); updateEntity.setVersion(entity.getVersion());
updateEntity.setApplicationNameId(entity.getApplicationNameId()); updateEntity.incrementVersion();
updateEntity.setAuditModelId(entity.getAuditModelId()); updateEntity.setApplicationNameId(entity.getApplicationNameId());
updateEntity.setDisabledPathsId(entity.getDisabledPathsId()); updateEntity.setAuditModelId(entity.getAuditModelId());
updateEntity.setDisabledPathsId(entity.getDisabledPathsId());
int updated = template.update(UPDATE_APPLICATION, updateEntity);
if (updated != 1) int updated = template.update(UPDATE_APPLICATION, updateEntity);
{ if (updated != 1)
// unexpected number of rows affected {
throw new ConcurrencyFailureException("Incorrect number of rows affected for updateAuditApplication: " + updateEntity + ": expected 1, actual " + updated); // unexpected number of rows affected
} throw new ConcurrencyFailureException("Incorrect number of rows affected for updateAuditApplication: " + updateEntity + ": expected 1, actual " + updated);
}
// Done
return updateEntity; // Done
} return updateEntity;
}
public int deleteAuditEntries(Long applicationId, Long from, Long to)
{ public int deleteAuditEntries(Long applicationId, Long from, Long to)
AuditDeleteParameters params = new AuditDeleteParameters(); {
params.setAuditApplicationId(applicationId); AuditDeleteParameters params = new AuditDeleteParameters();
params.setAuditFromTime(from); params.setAuditApplicationId(applicationId);
params.setAuditToTime(to); params.setAuditFromTime(from);
return template.delete(DELETE_ENTRIES, params); params.setAuditToTime(to);
} return template.delete(DELETE_ENTRIES, params);
}
public int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId)
{ public int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId)
AuditDeleteParameters params = new AuditDeleteParameters(); {
params.setAuditApplicationId(applicationId); AuditDeleteParameters params = new AuditDeleteParameters();
params.setAuditFromId(fromId); params.setAuditApplicationId(applicationId);
params.setAuditToId(toId); params.setAuditFromId(fromId);
return template.delete(DELETE_ENTRIES, params); params.setAuditToId(toId);
} return template.delete(DELETE_ENTRIES, params);
}
@Override
protected int deleteAuditEntriesImpl(List<Long> auditEntryIds) @Override
{ protected int deleteAuditEntriesImpl(List<Long> auditEntryIds)
AuditDeleteParameters params = new AuditDeleteParameters(); {
params.setAuditEntryIds(auditEntryIds); AuditDeleteParameters params = new AuditDeleteParameters();
return template.delete(DELETE_ENTRIES_BY_ID, params); params.setAuditEntryIds(auditEntryIds);
} return template.delete(DELETE_ENTRIES_BY_ID, params);
}
@Override
protected AuditEntryEntity createAuditEntry(Long applicationId, long time, Long usernameId, Long valuesId) @Override
{ protected AuditEntryEntity createAuditEntry(Long applicationId, long time, Long usernameId, Long valuesId)
AuditEntryEntity entity = new AuditEntryEntity(); {
entity.setAuditApplicationId(applicationId); AuditEntryEntity entity = new AuditEntryEntity();
entity.setAuditTime(time); entity.setAuditApplicationId(applicationId);
entity.setAuditUserId(usernameId); entity.setAuditTime(time);
entity.setAuditValuesId(valuesId); entity.setAuditUserId(usernameId);
template.insert(INSERT_ENTRY, entity); entity.setAuditValuesId(valuesId);
return entity; template.insert(INSERT_ENTRY, entity);
} return entity;
}
public HashMap<String, Long> getAuditMinMaxByApp(long appId, List<String> extremes)
{ public HashMap<String, Long> getAuditMinMaxByApp(long appId, List<String> extremes)
// Build parameters to be used in the query. Filter the duplicates when inserting into map {
Map<String, Object> params = extremes.stream().collect(Collectors.toMap(s -> s, s -> Boolean.TRUE, (s1, s2) -> s1)); // Build parameters to be used in the query. Filter the duplicates when inserting into map
params.put("auditAppId", appId); Map<String, Object> params = extremes.stream().collect(Collectors.toMap(s -> s, s -> Boolean.TRUE, (s1, s2) -> s1));
params.put("auditAppId", appId);
HashMap<String, Long> result = template.selectOne(SELECT_MINMAX_ENTRY_FOR_APP, params);
HashMap<String, Long> result = template.selectOne(SELECT_MINMAX_ENTRY_FOR_APP, params);
return result;
} return result;
}
@Override
public int getAuditEntriesCountByApp(long applicationId) @Override
{ public int getAuditEntriesCountByApp(long applicationId)
Map<String, Object> params = new HashMap<>(); {
params.put("auditAppId", applicationId); Map<String, Object> params = new HashMap<>();
params.put("auditAppId", applicationId);
int result = template.selectOne(SELECT_COUNT_ENTRIES_FOR_APP, params);
int result = template.selectOne(SELECT_COUNT_ENTRIES_FOR_APP, params);
return result;
} return result;
}
@Override
public int getAuditEntriesCountByAppAndProperties(org.alfresco.service.cmr.audit.AuditQueryParameters parameters) @Override
{ public int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
AuditQueryParameters dbParameters = convertFromRestAuditQueryParameters(parameters); {
AuditQueryParameters dbParameters = convertFromRestAuditQueryParameters(parameters);
int result = template.selectOne(SELECT_COUNT_ENTRIES_FOR_APP_WITH_PROPERTIES, dbParameters);
int result = template.selectOne(SELECT_COUNT_ENTRIES_FOR_APP_WITH_PROPERTIES, dbParameters);
return result;
} return result;
}
@SuppressWarnings("unchecked")
@Override @SuppressWarnings("unchecked")
protected void findAuditEntries( @Override
final AuditQueryRowHandler rowHandler, protected void findAuditEntries(
int maxResults, final AuditQueryRowHandler rowHandler,
org.alfresco.service.cmr.audit.AuditQueryParameters restParameters) int maxResults,
{ org.alfresco.service.cmr.audit.AuditQueryParameters restParameters)
AuditQueryParameters params = convertFromRestAuditQueryParameters(restParameters); {
if (params==null) AuditQueryParameters params = convertFromRestAuditQueryParameters(restParameters);
{ if (params == null)
return; {
} return;
}
if (maxResults > 0)
{ if (maxResults > 0)
// Query without getting the values. We gather all the results and batch-fetch the audited {
// values afterwards. // Query without getting the values. We gather all the results and batch-fetch the audited
final Map<Long, AuditQueryResult> resultsByValueId = new HashMap<Long, AuditQueryResult>(173); // values afterwards.
PropertyFinderCallback propertyFinderCallback = new PropertyFinderCallback() final Map<Long, AuditQueryResult> resultsByValueId = new HashMap<Long, AuditQueryResult>(173);
{ PropertyFinderCallback propertyFinderCallback = new PropertyFinderCallback() {
public void handleProperty(Long id, Serializable value) public void handleProperty(Long id, Serializable value)
{ {
// get the row // get the row
AuditQueryResult row = resultsByValueId.get(id); AuditQueryResult row = resultsByValueId.get(id);
try try
{ {
row.setAuditValue((Map<String, Serializable>) value); row.setAuditValue((Map<String, Serializable>) value);
} }
catch (ClassCastException e) catch (ClassCastException e)
{ {
// The handler will deal with the entry // The handler will deal with the entry
} }
} }
}; };
List<AuditQueryResult> rows = template.selectList(SELECT_ENTRIES_WITHOUT_VALUES, params, new RowBounds(0, maxResults)); List<AuditQueryResult> rows = template.selectList(SELECT_ENTRIES_WITHOUT_VALUES, params, new RowBounds(0, maxResults));
for (AuditQueryResult row : rows) for (AuditQueryResult row : rows)
{ {
resultsByValueId.put(row.getAuditValuesId(), row); resultsByValueId.put(row.getAuditValuesId(), row);
if (resultsByValueId.size() >= 100) if (resultsByValueId.size() >= 100)
{ {
// Fetch values for the results. The treemap is ordered. // Fetch values for the results. The treemap is ordered.
List<Long> valueIds = new ArrayList<Long>(resultsByValueId.keySet()); List<Long> valueIds = new ArrayList<Long>(resultsByValueId.keySet());
propertyValueDAO.getPropertiesByIds(valueIds, propertyFinderCallback); propertyValueDAO.getPropertiesByIds(valueIds, propertyFinderCallback);
// Clear and continue // Clear and continue
resultsByValueId.clear(); resultsByValueId.clear();
} }
} }
// Process any remaining results // Process any remaining results
if (resultsByValueId.size() > 0) if (resultsByValueId.size() > 0)
{ {
// Fetch values for the results. The treemap is ordered. // Fetch values for the results. The treemap is ordered.
List<Long> valueIds = new ArrayList<Long>(resultsByValueId.keySet()); List<Long> valueIds = new ArrayList<Long>(resultsByValueId.keySet());
propertyValueDAO.getPropertiesByIds(valueIds, propertyFinderCallback); propertyValueDAO.getPropertiesByIds(valueIds, propertyFinderCallback);
} }
// Now pass the filled-out results to the row handler (order-preserved) // Now pass the filled-out results to the row handler (order-preserved)
for (AuditQueryResult row : rows) for (AuditQueryResult row : rows)
{ {
rowHandler.processResult(row); rowHandler.processResult(row);
} }
} }
else else
{ {
throw new IllegalArgumentException("maxResults must be greater than 0"); throw new IllegalArgumentException("maxResults must be greater than 0");
} }
} }
} }

View File

@@ -1,173 +1,159 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2024 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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.domain.propval; package org.alfresco.repo.domain.propval;
import org.alfresco.repo.domain.CrcHelper; import org.alfresco.repo.domain.CrcHelper;
import org.alfresco.util.EqualsHelper; import org.alfresco.util.EqualsHelper;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
/** /**
* Entity bean for <b>alf_prop_string_value</b> table. * Entity bean for <b>alf_prop_string_value</b> table.
* *
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
public class PropertyStringValueEntity public class PropertyStringValueEntity
{ {
public static final String EMPTY_STRING = ""; public static final String EMPTY_STRING = "";
public static final String EMPTY_STRING_REPLACEMENT = ".empty"; public static final String EMPTY_STRING_REPLACEMENT = ".empty";
private Long id; private Long id;
private String stringValue; private String stringValue;
private String stringEndLower; private String stringEndLower;
private Long stringCrc; private Long stringCrc;
private String stringLower;
public PropertyStringValueEntity()
public PropertyStringValueEntity() {}
{
} @Override
public int hashCode()
@Override {
public int hashCode() return (stringValue == null ? 0 : stringValue.hashCode());
{ }
return (stringValue == null ? 0 : stringValue.hashCode());
} @Override
public boolean equals(Object obj)
@Override {
public boolean equals(Object obj) if (this == obj)
{ {
if (this == obj) return true;
{ }
return true; else if (obj != null && obj instanceof PropertyStringValueEntity)
} {
else if (obj != null && obj instanceof PropertyStringValueEntity) PropertyStringValueEntity that = (PropertyStringValueEntity) obj;
{ return EqualsHelper.nullSafeEquals(this.stringValue, that.stringValue);
PropertyStringValueEntity that = (PropertyStringValueEntity) obj; }
return EqualsHelper.nullSafeEquals(this.stringValue, that.stringValue); else
} {
else return false;
{ }
return false; }
}
} @Override
public String toString()
@Override {
public String toString() StringBuilder sb = new StringBuilder(512);
{ sb.append("PropertyStringValueEntity")
StringBuilder sb = new StringBuilder(512); .append("[ ID=").append(id)
sb.append("PropertyStringValueEntity") .append(", stringValue=").append(stringValue)
.append("[ ID=").append(id) .append("]");
.append(", stringValue=").append(stringValue) return sb.toString();
.append("]"); }
return sb.toString();
} public Pair<Long, String> getEntityPair()
{
public Pair<Long, String> getEntityPair() if (stringValue != null && stringValue.equals(PropertyStringValueEntity.EMPTY_STRING_REPLACEMENT))
{ {
if (stringValue != null && stringValue.equals(PropertyStringValueEntity.EMPTY_STRING_REPLACEMENT)) return new Pair<Long, String>(id, PropertyStringValueEntity.EMPTY_STRING);
{ }
return new Pair<Long, String>(id, PropertyStringValueEntity.EMPTY_STRING); else
} {
else return new Pair<Long, String>(id, stringValue);
{ }
return new Pair<Long, String>(id, stringValue); }
}
} /**
* Set the string and string-end values
/** */
* Set the string and string-end values public void setValue(String value)
*/ {
public void setValue(String value) if (value == null)
{ {
if (value == null) throw new IllegalArgumentException("Null strings cannot be persisted");
{ }
throw new IllegalArgumentException("Null strings cannot be persisted"); if (value != null && value.equals(PropertyStringValueEntity.EMPTY_STRING))
} {
if (value != null && value.equals(PropertyStringValueEntity.EMPTY_STRING)) // Oracle: We can't insert empty strings into the column.
{ value = PropertyStringValueEntity.EMPTY_STRING_REPLACEMENT;
// Oracle: We can't insert empty strings into the column. }
value = PropertyStringValueEntity.EMPTY_STRING_REPLACEMENT; stringValue = value;
} // Calculate the crc value from the original value
stringValue = value; Pair<String, Long> crcPair = CrcHelper.getStringCrcPair(value, 16, false, true);
// Calculate the crc value from the original value stringEndLower = crcPair.getFirst();
Pair<String, Long> crcPair = CrcHelper.getStringCrcPair(value, 16, false, true); stringCrc = crcPair.getSecond();
stringEndLower = crcPair.getFirst();
stringCrc = crcPair.getSecond(); }
// Calculate the crc value with case-insensitive
Pair<String, Long> crcPairWithCaseInSensitive = CrcHelper.getStringCrcPair(value, 16, false, false); public Long getId()
stringLower = crcPairWithCaseInSensitive.getFirst(); {
} return id;
}
public Long getId()
{ public void setId(Long id)
return id; {
} this.id = id;
}
public void setId(Long id)
{ public String getStringValue()
this.id = id; {
} return stringValue;
}
public String getStringValue()
{ public void setStringValue(String stringValue)
return stringValue; {
} this.stringValue = stringValue;
}
public void setStringValue(String stringValue)
{ public String getStringEndLower()
this.stringValue = stringValue; {
} return stringEndLower;
}
public String getStringEndLower()
{ public void setStringEndLower(String stringEndLower)
return stringEndLower; {
} this.stringEndLower = stringEndLower;
}
public void setStringEndLower(String stringEndLower)
{ public Long getStringCrc()
this.stringEndLower = stringEndLower; {
} return stringCrc;
}
public Long getStringCrc()
{ public void setStringCrc(Long stringCrc)
return stringCrc; {
} this.stringCrc = stringCrc;
}
public void setStringCrc(Long stringCrc) }
{
this.stringCrc = stringCrc;
}
public String getStringLower()
{
return stringLower;
}
public void setStringLower(String stringLower)
{
this.stringLower = stringLower;
}
}

View File

@@ -1,266 +1,299 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2024 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
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.service.cmr.audit; package org.alfresco.service.cmr.audit;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* The public API by which applications can query the audit logs and enable or disable auditing. * The public API by which applications can query the audit logs and enable or disable auditing.
* *
* @author Derek Hulley * @author Derek Hulley
*/ */
public interface AuditService public interface AuditService
{ {
/** /**
* @return Returns <tt>true</tt> if auditing is globally enabled * @return Returns <tt>true</tt> if auditing is globally enabled
* *
* @since 3.4 * @since 3.4
*/ */
boolean isAuditEnabled(); boolean isAuditEnabled();
/** /**
* Enable or disable the global auditing state * Enable or disable the global auditing state
* *
* @param enable <tt>true</tt> to enable auditing globally or <tt>false</tt> to disable * @param enable
* * <tt>true</tt> to enable auditing globally or <tt>false</tt> to disable
* @since 3.4 *
*/ * @since 3.4
void setAuditEnabled(boolean enable); */
void setAuditEnabled(boolean enable);
/**
* Helper bean to carry information about an audit application. /**
* * Helper bean to carry information about an audit application.
* @author Derek Hulley *
* @since 3.4 * @author Derek Hulley
*/ * @since 3.4
public static class AuditApplication */
{ public static class AuditApplication
private final String name; {
private final String key; private final String name;
private final boolean enabled; private final String key;
/** private final boolean enabled;
* Constructor for final variables
*/ /**
public AuditApplication(String name, String key, boolean enabled) * Constructor for final variables
{ */
this.name = name; public AuditApplication(String name, String key, boolean enabled)
this.key = key; {
this.enabled = enabled; this.name = name;
} this.key = key;
public String getName() this.enabled = enabled;
{ }
return name;
} public String getName()
public String getKey() {
{ return name;
return key; }
}
public boolean isEnabled() public String getKey()
{ {
return enabled; return key;
} }
}
public boolean isEnabled()
/** {
* Get all registered audit applications return enabled;
* }
* @return Returns a map of audit applications keyed by their name }
*
* @since 3.4 /**
*/ * Get all registered audit applications
Map<String, AuditApplication> getAuditApplications(); *
* @return Returns a map of audit applications keyed by their name
/** *
* @param applicationName the name of the application to check * @since 3.4
* @param path the path to check */
* @return Returns <tt>true</tt> if auditing is enabled for the given path Map<String, AuditApplication> getAuditApplications();
*
* @since 3.2 /**
*/ * @param applicationName
boolean isAuditEnabled(String applicationName, String path); * the name of the application to check
* @param path
/** * the path to check
* Enable auditing for an application path * @return Returns <tt>true</tt> if auditing is enabled for the given path
* *
* @param applicationName the name of the application to check * @since 3.2
* @param path the path to enable */
* boolean isAuditEnabled(String applicationName, String path);
* @since 3.2
*/ /**
void enableAudit(String applicationName, String path); * Enable auditing for an application path
*
/** * @param applicationName
* Disable auditing for an application path * the name of the application to check
* * @param path
* @param applicationName the name of the application to check * the path to enable
* @param path the path to disable *
* * @since 3.2
* @since 3.2 */
*/ void enableAudit(String applicationName, String path);
void disableAudit(String applicationName, String path);
/**
/** * Disable auditing for an application path
* Remove all audit entries for the given application *
* * @param applicationName
* @param applicationName the name of the application for which to remove entries * the name of the application to check
* @return Returns the number of audit entries deleted * @param path
* * the path to disable
* @since 3.2 *
* * @since 3.2
* @deprecated Use {@link #clearAudit(String, Long, Long)} */
*/ void disableAudit(String applicationName, String path);
int clearAudit(String applicationName);
/**
/** * Remove all audit entries for the given application
* Remove audit entries for the given application between the time ranges. If no start *
* time is given then entries are deleted as far back as they exist. If no end time is * @param applicationName
* given then entries are deleted up until the current time. * the name of the application for which to remove entries
* * @return Returns the number of audit entries deleted
* @param applicationName the name of the application for which to remove entries *
* @param fromTime the start time of entries to remove (inclusive and optional) * @since 3.2
* @param toTime the end time of entries to remove (exclusive and optional) *
* @return Returns the number of audit entries deleted * @deprecated Use {@link #clearAudit(String, Long, Long)}
* */
* @since 3.4 int clearAudit(String applicationName);
*/
int clearAudit(String applicationName, Long fromTime, Long toTime); /**
* Remove audit entries for the given application between the time ranges. If no start time is given then entries are deleted as far back as they exist. If no end time is given then entries are deleted up until the current time.
/** *
* Remove audit entries for the given application between the audit entry ids. * @param applicationName
* * the name of the application for which to remove entries
* @param applicationName the name of the application for which to remove entries * @param fromTime
* @param fromId the start time of entries to remove (inclusive and optional) * the start time of entries to remove (inclusive and optional)
* @param toId the end time of entries to remove (exclusive and optional) * @param toTime
* @return Returns the number of audit entries deleted * the end time of entries to remove (exclusive and optional)
* * @return Returns the number of audit entries deleted
* @since 5.2.2 *
*/ * @since 3.4
int clearAuditByIdRange(String applicationName, Long fromId, Long toId); */
int clearAudit(String applicationName, Long fromTime, Long toTime);
/**
* Delete a discrete list of audit entries. /**
* <p/> * Remove audit entries for the given application between the audit entry ids.
* This method should not be called <i>while</i> processing *
* {@link #auditQuery(AuditQueryCallback, AuditQueryParameters, int) query results}. * @param applicationName
* * the name of the application for which to remove entries
* @param auditEntryIds the IDs of all audit entries to delete * @param fromId
* @return Returns the number of audit entries deleted * the start time of entries to remove (inclusive and optional)
* * @param toId
* @since 3.4 * the end time of entries to remove (exclusive and optional)
*/ * @return Returns the number of audit entries deleted
int clearAudit(List<Long> auditEntryIds); *
* @since 5.2.2
/** */
* The interface that will be used to give query results to the calling code. int clearAuditByIdRange(String applicationName, Long fromId, Long toId);
*
* @since 3.2 /**
*/ * Delete a discrete list of audit entries.
public static interface AuditQueryCallback * <p/>
{ * This method should not be called <i>while</i> processing {@link #auditQuery(AuditQueryCallback, AuditQueryParameters, int) query results}.
/** *
* Determines whether this callback requires the values argument to be populated when {@link #handleAuditEntry} * @param auditEntryIds
* is called. * the IDs of all audit entries to delete
* * @return Returns the number of audit entries deleted
* @return <code>true</code> if this callback requires the values argument to be populated *
*/ * @since 3.4
boolean valuesRequired(); */
int clearAudit(List<Long> auditEntryIds);
/**
* Handle a row of audit entry data. /**
* * The interface that will be used to give query results to the calling code.
* @param entryId the unique audit entry ID *
* @param applicationName the name of the application * @since 3.2
* @param user the user that logged the entry */
* @param time the time of the entry public static interface AuditQueryCallback
* @param values the values map as created {
* @return Return <tt>true</tt> to continue processing rows or <tt>false</tt> to stop /**
*/ * Determines whether this callback requires the values argument to be populated when {@link #handleAuditEntry} is called.
boolean handleAuditEntry( *
Long entryId, * @return <code>true</code> if this callback requires the values argument to be populated
String applicationName, */
String user, boolean valuesRequired();
long time,
Map<String, Serializable> values); /**
* Handle a row of audit entry data.
/** *
* Handle audit entry failures * @param entryId
* * the unique audit entry ID
* @param entryId the entry ID * @param applicationName
* @param errorMsg the error message * the name of the application
* @param error the exception causing the error (may be <tt>null</tt>) * @param user
* @return Return <tt>true</tt> to continue processing rows or <tt>false</tt> to stop * the user that logged the entry
*/ * @param time
boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error); * the time of the entry
} * @param values
* the values map as created
/** * @return Return <tt>true</tt> to continue processing rows or <tt>false</tt> to stop
* Issue an audit query using the given parameters and consuming results in the callback. */
* Results are returned in entry order, corresponding to time order. boolean handleAuditEntry(
* Long entryId,
* @param callback the callback that will handle results String applicationName,
* @param parameters the parameters for the query (may not be <tt>null</tt>) String user,
* @param maxResults the maximum number of results to retrieve (must be greater than 0) long time,
* Map<String, Serializable> values);
* @throws IllegalArgumentException if maxResults less or equal to zero
* /**
* @since 3.3 * Handle audit entry failures
*/ *
void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults); * @param entryId
* the entry ID
/** * @param errorMsg
* Issue an audit query to retrieve min / max audit record id for a given application. * the error message
* * @param error
* @param applicationName the name of the application * the exception causing the error (may be <tt>null</tt>)
* @param extremes a list containing min/max or both * @return Return <tt>true</tt> to continue processing rows or <tt>false</tt> to stop
* @return a map containing min/max and the associated value */
*/ boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error);
HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes); }
/** /**
* Issue an audit query to retrieve min / max audit record id for a given application. * Issue an audit query using the given parameters and consuming results in the callback. Results are returned in entry order, corresponding to time order.
* *
* @param applicationName the name of the application * @param callback
* @return a map containing min/max and the associated value * the callback that will handle results
*/ * @param parameters
default int getAuditEntriesCountByApp(String applicationName) * the parameters for the query (may not be <tt>null</tt>)
{ * @param maxResults
return -1; * the maximum number of results to retrieve (must be greater than 0)
} *
* @throws IllegalArgumentException
/** * if maxResults less or equal to zero
* Issue an audit query to retrieve min / max audit record id for a given application and properties *
* * @since 3.3
* @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 void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults);
*/
default int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters) /**
{ * Issue an audit query to retrieve min / max audit record id for a given application.
return -1; *
} * @param applicationName
} * the name of the application
* @param extremes
* a list containing min/max or both
* @return a map containing min/max and the associated value
*/
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;
}
/**
* 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;
}
}