[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.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.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
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
*
@@ -55,7 +56,6 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest
@InjectMocks
private RMv33HoldAuditEntryValuesPatch patch;
@Before
public void setUp()
{
@@ -93,15 +93,15 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest
verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(deleteHoldPropertyStringValueEntity);
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("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("Delete Hold", deleteHoldPropertyStringValueEntity.getStringValue());
assertEquals("delete hold", deleteHoldPropertyStringValueEntity.getStringLower());
assertEquals("delete hold", deleteHoldPropertyStringValueEntity.getStringEndLower());
assertEquals(Long.valueOf(132_640_810L), deleteHoldPropertyStringValueEntity.getStringCrc());
}
@@ -123,5 +123,3 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest
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)
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
private final static Map<String, String> SORT_PARAMS_TO_NAMES;
@@ -295,23 +295,29 @@ public class AuditImpl implements Audit
}
else
{
if (hasMoreItems) {
if (q != null) {
if (hasMoreItems)
{
if (q != null)
{
// filtering via "where" clause
AuditEntryQueryWalker propertyWalker = new AuditEntryQueryWalker();
QueryHelper.walk(q, propertyWalker);
totalItems = getAuditEntriesCountByAppAndProperties(auditApplication, propertyWalker);
} else {
}
else
{
totalItems = getAuditEntriesCountByApp(auditApplication);
}
} else {
}
else
{
totalItems = totalRetrievedItems;
}
}
entriesAudit = (skipCount >= totalRetrievedItems)
? Collections.emptyList()
: entriesAudit.subList(skipCount, end);
? Collections.emptyList()
: entriesAudit.subList(skipCount, end);
return CollectionWithPagingInfo.asPaged(paging, entriesAudit, hasMoreItems, totalItems);
}
@@ -475,8 +481,7 @@ public class AuditImpl implements Audit
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback()
{
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired()
{
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
@@ -545,8 +550,7 @@ public class AuditImpl implements Audit
final List<AuditEntry> results = new ArrayList<>();
// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback()
{
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired()
{
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
@@ -710,8 +714,7 @@ public class AuditImpl implements Audit
@Override
public CollectionWithPagingInfo<AuditEntry> listAuditEntriesByNodeId(String nodeId, Parameters parameters)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
AuthenticationUtil.runAs(new RunAsWork<Void>() {
public Void doWork() throws Exception
{
checkEnabled();
@@ -772,8 +775,7 @@ public class AuditImpl implements Audit
final List<AuditEntry> results = new ArrayList<>();
String auditAppId = "alfresco-access";
String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork<String>()
{
String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork<String>() {
public String doWork() throws Exception
{
return findAuditAppByIdOr404(auditAppId).getName();
@@ -781,8 +783,7 @@ public class AuditImpl implements Audit
}, AuthenticationUtil.getSystemUserName());
// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback()
{
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired()
{
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
@@ -808,8 +809,7 @@ public class AuditImpl implements Audit
Long toTime = propertyWalker.getToTime();
validateWhereBetween(nodeRef.getId(), fromTime, toTime);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() throws Exception
{
// QueryParameters
@@ -820,7 +820,7 @@ public class AuditImpl implements Audit
pathParams.setFromTime(fromTime);
pathParams.setToTime(toTime);
pathParams.setApplicationName(auditApplicationName);
pathParams.addSearchKey("/"+auditAppId+"/transaction/path", nodePath);
pathParams.addSearchKey("/" + auditAppId + "/transaction/path", nodePath);
auditService.auditQuery(callback, pathParams, limit);
AuditQueryParameters copyFromPathParams = new AuditQueryParameters();
@@ -830,7 +830,7 @@ public class AuditImpl implements Audit
copyFromPathParams.setFromTime(fromTime);
copyFromPathParams.setToTime(toTime);
copyFromPathParams.setApplicationName(auditApplicationName);
copyFromPathParams.addSearchKey("/"+auditAppId+"/transaction/copy/from/path", nodePath);
copyFromPathParams.addSearchKey("/" + auditAppId + "/transaction/copy/from/path", nodePath);
auditService.auditQuery(callback, copyFromPathParams, limit);
AuditQueryParameters moveFromPathParams = new AuditQueryParameters();
@@ -840,7 +840,7 @@ public class AuditImpl implements Audit
moveFromPathParams.setFromTime(fromTime);
moveFromPathParams.setToTime(toTime);
moveFromPathParams.setApplicationName(auditApplicationName);
moveFromPathParams.addSearchKey("/"+auditAppId+"/transaction/move/from/path", nodePath);
moveFromPathParams.addSearchKey("/" + auditAppId + "/transaction/move/from/path", nodePath);
auditService.auditQuery(callback, moveFromPathParams, limit);
return null;
@@ -857,7 +857,7 @@ public class AuditImpl implements Audit
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
@@ -904,19 +904,22 @@ public class AuditImpl implements Audit
public int getAuditEntriesCountByApp(AuditService.AuditApplication auditApplication)
{
final String applicationName = auditApplication.getKey().substring(1);
return auditService.getAuditEntriesCountByApp(applicationName);
}
public int getAuditEntriesCountByAppAndProperties(AuditService.AuditApplication auditApplication, AuditEntryQueryWalker propertyWalker)
{
final String applicationName = auditApplication.getKey().substring(1);
AuditQueryParameters parameters = new AuditQueryParameters();
parameters.setApplicationName(auditApplication.getName());
parameters.setApplicationName(applicationName);
parameters.setFromTime(propertyWalker.getFromTime());
parameters.setToTime(propertyWalker.getToTime());
parameters.setFromId(propertyWalker.getFromId());
parameters.setToId(propertyWalker.getToId());
parameters.setUser(propertyWalker.getCreatedByUser());
return auditService.getAuditEntriesCountByAppAndProperties(parameters);
return auditService.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
}
}

View File

@@ -46,7 +46,7 @@ public interface AuditComponent
/**
* 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
*/
@@ -55,14 +55,16 @@ public interface AuditComponent
/**
* 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
*/
public void setAuditEnabled(boolean enable);
/**
* @param userAuditFilter UserAuditFilter
* @param userAuditFilter
* UserAuditFilter
*
* @since 4.2
*/
@@ -71,36 +73,28 @@ public interface AuditComponent
/**
* Get all registered audit applications, whether active or not.
*
* @return Returns a map of registered audit applications keyed by name
* @return Returns a map of registered audit applications keyed by name
*
* @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
* have been registered. Sometimes, depending on the log level, this method may always
* return <tt>true</tt>.
* 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>.
*
*
* @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) should go ahead and generate the data for {@link #recordAuditValues(String, Map) recording}.
*
* @since 3.3
*/
public boolean areAuditValuesRequired();
/**
* 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.
* 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.
*
* @param path the audit path
* @return Returns <tt>true</tt> if there is at least one audit application
* registered to handle the given path.
* @param path
* the audit path
* @return Returns <tt>true</tt> if there is at least one audit application registered to handle the given path.
*
* @since 3.4
*/
@@ -109,10 +103,13 @@ public interface AuditComponent
/**
* Delete audit entries for the given application and time range
*
* @param applicationName the name of the application
* @param fromTime the start time of entries to remove (inclusive and optional)
* @param toTime the end time of entries to remove (exclusive and optional)
* @return Returns the number of entries deleted
* @param applicationName
* the name of the application
* @param fromTime
* the start time of entries to remove (inclusive and optional)
* @param toTime
* the end time of entries to remove (exclusive and optional)
* @return Returns the number of entries deleted
*
* @since 3.2
*/
@@ -121,10 +118,13 @@ public interface AuditComponent
/**
* Delete audit entries for the given application and id range
*
* @param applicationName the name of the application
* @param fromId the start time of entries to remove (inclusive and optional)
* @param toId the end time of entries to remove (exclusive and optional)
* @return Returns the number of entries deleted
* @param applicationName
* the name of the application
* @param fromId
* the start time of entries to remove (inclusive and optional)
* @param toId
* the end time of entries to remove (exclusive and optional)
* @return Returns the number of entries deleted
*
* @since 5.2.2
*/
@@ -133,95 +133,79 @@ public interface AuditComponent
/**
* Delete a discrete list of audit entries based on ID
*
* @param auditEntryIds the audit entry IDs to delete
* @return Returns the number of entries deleted
* @param auditEntryIds
* the audit entry IDs to delete
* @return Returns the number of entries deleted
*/
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
* data is audited.
* 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.
*
* @param applicationName the name of the application being logged to
* @param 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
* @param applicationName
* the name of the application being logged to
* @param 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
*
* @since 3.2
*/
boolean isAuditPathEnabled(String applicationName, String 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.
* 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.
* <p>
* If the enabled
*
* @param applicationName the name of the application being logged to
* @param path the audit path to check or <tt>null</tt> to assume the
* application's root path
* @param applicationName
* the name of the application being logged to
* @param path
* the audit path to check or <tt>null</tt> to assume the application's root path
*
* @since 3.2
*/
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.
* 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>
* 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.
* 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.
*
* @param applicationName the name of the application being logged to
* @param path the audit path to check or <tt>null</tt> to assume the
* application's root path
* @param applicationName
* the name of the application being logged to
* @param path
* the audit path to check or <tt>null</tt> to assume the application's root path
*
* @since 3.2
*/
void disableAudit(String applicationName, String 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}.
* 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}.
*
* @param applicationName the name of the application
* @param applicationName
* the name of the application
*
* @since 3.2
*/
void resetDisabledPaths(String applicationName);
/**
* 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.
* 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.
* <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).
* 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).
* <p/>
* The return values reflect what was actually persisted and is controlled by the data extractors
* defined in the audit configuration.
* The return values reflect what was actually persisted and is controlled by the data extractors defined in the audit configuration.
* <p/>
* A new read-write transaction is started if there are values to write that there is not a viable
* transaction present.
* 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 values the values to audit mapped by {@link AuditPath} key relative to root path
* (may be <tt>null</tt>)
* @return Returns the values that were actually persisted, keyed by their full path.
* @throws IllegalStateException if the transaction state could not be determined
* @param rootPath
* a base path of {@link AuditPath} key entries concatenated with the path separator '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR})
* @param values
* the values to audit mapped by {@link AuditPath} key relative to root path (may be <tt>null</tt>)
* @return Returns the values that were actually persisted, keyed by their full path.
* @throws IllegalStateException
* if the transaction state could not be determined
*
* @since 3.2
*/
@@ -230,24 +214,30 @@ public interface AuditComponent
/**
* The same as {@link AuditComponent#recordAuditValues(String, Map)}, but with controlled usage of userFilter
*
* @param rootPath a base path of {@link AuditPath} key entries concatenated with the path separator
* '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR})
* @param values the values to audit mapped by {@link AuditPath} key relative to root path
* (may be <tt>null</tt>)
* @param useUserFilter if <tt>false</tt> the user filter is disabled.
* @return Returns the values that were actually persisted, keyed by their full path.
* @throws IllegalStateException if the transaction state could not be determined
* @param rootPath
* a base path of {@link AuditPath} key entries concatenated with the path separator '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR})
* @param values
* the values to audit mapped by {@link AuditPath} key relative to root path (may be <tt>null</tt>)
* @param useUserFilter
* if <tt>false</tt> the user filter is disabled.
* @return Returns the values that were actually persisted, keyed by their full path.
* @throws IllegalStateException
* if the transaction state could not be determined
*/
Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter);
/**
* Find audit entries using the given parameters
*
* @param callback the data callback per entry
* @param parameters the parameters for the query (may not be <tt>null</tt>)
* @param maxResults the maximum number of results to retrieve (must be greater than 0)
* @param callback
* the data callback per entry
* @param parameters
* the parameters for the query (may not be <tt>null</tt>)
* @param maxResults
* the maximum number of results to retrieve (must be greater than 0)
*
* @throws IllegalArgumentException if maxResults less or equal to zero
* @throws IllegalArgumentException
* if maxResults less or equal to zero
*
* @since 3.2
*/
@@ -256,17 +246,20 @@ public interface AuditComponent
/**
* Issue an audit query to retrieve min / max audit record id for a given application.
*
* @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
* @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 count of records for a given application.
*
* @param applicationName the name of the application
* @return a map containing min/max and the associated value
* @param applicationName
* the name of the application
* @return a map containing min/max and the associated value
*/
default int getAuditEntriesCountByApp(String applicationName)
{
@@ -276,10 +269,13 @@ public interface AuditComponent
/**
* Issue an audit query to retrieve count of records for a given application and properties
*
* @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 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(AuditQueryParameters parameters)
default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
{
return -1;
}

View File

@@ -34,13 +34,17 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.audit.extractor.DataExtractor;
import org.alfresco.repo.audit.generator.DataGenerator;
import org.alfresco.repo.audit.model.AuditApplication;
import org.alfresco.repo.audit.model.AuditApplication.DataExtractorDefinition;
import org.alfresco.repo.audit.model.AuditModelRegistry;
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
import org.alfresco.repo.audit.model.AuditApplication.DataExtractorDefinition;
import org.alfresco.repo.domain.audit.AuditDAO;
import org.alfresco.repo.domain.propval.PropertyValueDAO;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
@@ -53,9 +57,6 @@ import org.alfresco.service.cmr.audit.AuditQueryParameters;
import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.PathMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* Component that records audit values as well as providing the query implementation.
@@ -86,11 +87,11 @@ public class AuditComponentImpl implements AuditComponent
* Default constructor
*/
public AuditComponentImpl()
{
}
{}
/**
* Set the registry holding the audit models
*
* @since 3.2
*/
public void setAuditModelRegistry(AuditModelRegistryImpl auditModelRegistry)
@@ -100,6 +101,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* Set the DAO for manipulating property values
*
* @since 3.2
*/
public void setPropertyValueDAO(PropertyValueDAO propertyValueDAO)
@@ -109,6 +111,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* Set the DAO for accessing audit data
*
* @since 3.2
*/
public void setAuditDAO(AuditDAO auditDAO)
@@ -139,6 +142,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
*
* @since 3.2
*/
public int deleteAuditEntries(String applicationName, Long fromTime, Long toTime)
@@ -155,13 +159,14 @@ public class AuditComponentImpl implements AuditComponent
{
logger.debug(
"Delete audit " + deleted + " entries for " + applicationName +
" (" + fromTime + " to " + toTime);
" (" + fromTime + " to " + toTime);
}
return deleted;
}
/**
* {@inheritDoc}
*
* @since 5.2.2
*/
public int deleteAuditEntriesByIdRange(String applicationName, Long fromId, Long toId)
@@ -203,6 +208,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
*
* @since 3.2
*/
@Override
@@ -217,8 +223,9 @@ public class AuditComponentImpl implements AuditComponent
}
/**
* @param application the audit application object
* @return Returns a copy of the set of disabled paths associated with the application
* @param application
* the audit application object
* @return Returns a copy of the set of disabled paths associated with the application
*/
@SuppressWarnings("unchecked")
private Set<String> getDisabledPaths(AuditApplication application)
@@ -239,6 +246,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
*
* @since 3.2
*/
public boolean isAuditEnabled()
@@ -248,6 +256,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
*
* @since 3.4
*/
@Override
@@ -259,14 +268,15 @@ public class AuditComponentImpl implements AuditComponent
// It is changing
auditModelRegistry.stop();
auditModelRegistry.setProperty(
AuditModelRegistry.AUDIT_PROPERTY_AUDIT_ENABLED,
Boolean.toString(enable).toLowerCase());
AuditModelRegistry.AUDIT_PROPERTY_AUDIT_ENABLED,
Boolean.toString(enable).toLowerCase());
auditModelRegistry.start();
}
}
/**
* {@inheritDoc}
*
* @since 3.4
*/
public Map<String, AuditApplication> getAuditApplications()
@@ -277,8 +287,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
* <p/>
* Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt>
* will always be returned.
* Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt> will always be returned.
*
* @since 3.2
*/
@@ -291,8 +300,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
* <p/>
* Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt>
* will always be returned.
* Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt> will always be returned.
*
* @since 3.4
*/
@@ -306,6 +314,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
*
* @since 3.2
*/
public boolean isAuditPathEnabled(String applicationName, String path)
@@ -336,7 +345,8 @@ public class AuditComponentImpl implements AuditComponent
Set<String> disabledPaths = getDisabledPaths(application);
// Check if there are any entries that match or supercede the given path
String disablingPath = null;;
String disablingPath = null;
;
for (String disabledPath : disabledPaths)
{
if (path.startsWith(disabledPath))
@@ -350,15 +360,16 @@ public class AuditComponentImpl implements AuditComponent
{
logger.debug(
"Audit path enabled check: \n" +
" Application: " + applicationName + "\n" +
" Path: " + path + "\n" +
" Disabling Path: " + disablingPath);
" Application: " + applicationName + "\n" +
" Path: " + path + "\n" +
" Disabling Path: " + disablingPath);
}
return disablingPath == null;
}
/**
* {@inheritDoc}
*
* @since 3.2
*/
public void enableAudit(String applicationName, String path)
@@ -409,8 +420,8 @@ public class AuditComponentImpl implements AuditComponent
{
logger.debug(
"Audit disabled paths updated: \n" +
" Application: " + applicationName + "\n" +
" Disabled: " + disabledPaths);
" Application: " + applicationName + "\n" +
" Disabled: " + disabledPaths);
}
}
// Done
@@ -418,6 +429,7 @@ public class AuditComponentImpl implements AuditComponent
/**
* {@inheritDoc}
*
* @since 3.2
*/
public void disableAudit(String applicationName, String path)
@@ -455,7 +467,7 @@ public class AuditComponentImpl implements AuditComponent
{
logger.debug(
"Audit disable path already present: \n" +
" Path: " + path);
" Path: " + path);
}
return;
}
@@ -477,8 +489,8 @@ public class AuditComponentImpl implements AuditComponent
{
logger.debug(
"Audit disable path superceded: \n" +
" Path: " + path + "\n" +
" Superceded by: " + disabledPath);
" Path: " + path + "\n" +
" Superceded by: " + disabledPath);
}
return;
}
@@ -492,13 +504,14 @@ public class AuditComponentImpl implements AuditComponent
{
logger.debug(
"Audit disabled paths updated: \n" +
" Application: " + applicationName + "\n" +
" Disabled: " + disabledPaths);
" Application: " + applicationName + "\n" +
" Disabled: " + disabledPaths);
}
}
/**
* {@inheritDoc}
*
* @since 3.2
*/
public void resetDisabledPaths(String applicationName)
@@ -546,9 +559,9 @@ public class AuditComponentImpl implements AuditComponent
// Log inbound values
if (loggerInbound.isDebugEnabled())
{
StringBuilder sb = new StringBuilder(values.size()*64);
StringBuilder sb = new StringBuilder(values.size() * 64);
sb.append("\n")
.append("Inbound audit values:");
.append("Inbound audit values:");
for (Map.Entry<String, Serializable> entry : values.entrySet())
{
String pathElement = entry.getKey();
@@ -576,16 +589,14 @@ public class AuditComponentImpl implements AuditComponent
return mappedValues;
}
// We have something to record. Start a transaction, if necessary
// We have something to record. Start a transaction, if necessary
TxnReadState txnState = AlfrescoTransactionSupport.getTransactionReadState();
switch (txnState)
{
case TXN_NONE:
case TXN_READ_ONLY:
// New transaction
RetryingTransactionCallback<Map<String, Serializable>> callback =
new RetryingTransactionCallback<Map<String,Serializable>>()
{
RetryingTransactionCallback<Map<String, Serializable>> callback = new RetryingTransactionCallback<Map<String, Serializable>>() {
public Map<String, Serializable> execute() throws Throwable
{
return recordAuditValuesImpl(mappedValues);
@@ -607,7 +618,7 @@ public class AuditComponentImpl implements AuditComponent
public Map<String, Serializable> recordAuditValuesImpl(Map<String, Serializable> mappedValues)
{
// Group the values by root path
Map<String, Map<String, Serializable>> mappedValuesByRootKey = new HashMap<String, Map<String,Serializable>>();
Map<String, Map<String, Serializable>> mappedValuesByRootKey = new HashMap<String, Map<String, Serializable>>();
for (Map.Entry<String, Serializable> entry : mappedValues.entrySet())
{
String path = entry.getKey();
@@ -621,7 +632,7 @@ public class AuditComponentImpl implements AuditComponent
rootKeyMappedValues.put(path, entry.getValue());
}
Map<String, Serializable> allAuditedValues = new HashMap<String, Serializable>(mappedValues.size()*2+1);
Map<String, Serializable> allAuditedValues = new HashMap<String, Serializable>(mappedValues.size() * 2 + 1);
// Now audit for each of the root keys
for (Map.Entry<String, Map<String, Serializable>> entry : mappedValuesByRootKey.entrySet())
{
@@ -646,8 +657,8 @@ public class AuditComponentImpl implements AuditComponent
{
logger.debug(
"Audit values root path has been excluded by disabled paths: \n" +
" Application: " + application + "\n" +
" Root Path: " + AuditApplication.buildPath(rootKey));
" Application: " + application + "\n" +
" Root Path: " + AuditApplication.buildPath(rootKey));
}
continue;
}
@@ -660,12 +671,15 @@ public class AuditComponentImpl implements AuditComponent
}
/**
* Audit values for a given application. No path checking is done.
* Audit values for a given application. No path checking is done.
*
* @param application the audit application to audit to
* @param disabledPaths the application's disabled paths
* @param values the values to store keyed by <b>full paths</b>.
* @return Returns all values as audited
* @param application
* the audit application to audit to
* @param disabledPaths
* the application's disabled paths
* @param values
* the values to store keyed by <b>full paths</b>.
* @return Returns all values as audited
*/
private Map<String, Serializable> audit(
final AuditApplication application,
@@ -686,8 +700,8 @@ public class AuditComponentImpl implements AuditComponent
{
logger.debug(
"Audit values have all been excluded by disabled paths: \n" +
" Application: " + application + "\n" +
" Values: " + values);
" Application: " + application + "\n" +
" Values: " + values);
}
return Collections.emptyMap();
}
@@ -695,7 +709,7 @@ public class AuditComponentImpl implements AuditComponent
Set<String> generatorKeys = values.keySet();
// Eliminate any paths that have been disabled
Iterator<String> generatorKeysIterator = generatorKeys.iterator();
while(generatorKeysIterator.hasNext())
while (generatorKeysIterator.hasNext())
{
String generatorKey = generatorKeysIterator.next();
for (String disabledPath : disabledPaths)
@@ -713,8 +727,7 @@ public class AuditComponentImpl implements AuditComponent
Map<String, Serializable> auditData = generateData(generators);
// Now extract values
Map<String, Serializable> extractedData = AuthenticationUtil.runAs(new RunAsWork<Map<String, Serializable>>()
{
Map<String, Serializable> extractedData = AuthenticationUtil.runAs(new RunAsWork<Map<String, Serializable>>() {
public Map<String, Serializable> doWork() throws Exception
{
return extractData(application, values);
@@ -757,9 +770,9 @@ public class AuditComponentImpl implements AuditComponent
StringBuilder sb = new StringBuilder();
sb.append(
((justGatherPreCallData) ? "\nPreCallData: \n" : "\nNew audit entry: \n") +
"\tApplication ID: " + applicationId + "\n" +
((justGatherPreCallData) ? "" : "\tEntry ID: " + entryId + "\n") +
"\tValues: " + "\n");
"\tApplication ID: " + applicationId + "\n" +
((justGatherPreCallData) ? "" : "\tEntry ID: " + entryId + "\n") +
"\tValues: " + "\n");
for (Map.Entry<String, Serializable> entry : values.entrySet())
{
sb.append("\t\t").append(entry).append("\n");
@@ -780,9 +793,9 @@ public class AuditComponentImpl implements AuditComponent
StringBuilder sb = new StringBuilder();
sb.append(
"\nNothing audited: \n" +
"\tApplication ID: " + applicationId + "\n" +
"\tEntry ID: " + entryId + "\n" +
"\tValues: " + "\n");
"\tApplication ID: " + applicationId + "\n" +
"\tEntry ID: " + entryId + "\n" +
"\tValues: " + "\n");
for (Map.Entry<String, Serializable> entry : values.entrySet())
{
sb.append("\t\t").append(entry).append("\n");
@@ -797,9 +810,11 @@ public class AuditComponentImpl implements AuditComponent
/**
* Extracts data from a given map using data extractors from the given application.
*
* @param application the application providing the data extractors
* @param values the data values from which to generate data
* @return Returns a map of derived data keyed by full path
* @param application
* the application providing the data extractors
* @param values
* the data values from which to generate data
* @return Returns a map of derived data keyed by full path
*
* @since 3.2
*/
@@ -820,13 +835,13 @@ public class AuditComponentImpl implements AuditComponent
// Check if it is triggered
if (!values.containsKey(triggerPath))
{
continue; // It is not triggered
continue; // It is not triggered
}
// We observe the key, not the actual value
if (!values.containsKey(sourcePath))
{
continue; // There is no data to extract
continue; // There is no data to extract
}
Serializable value = values.get(sourcePath);
@@ -846,9 +861,9 @@ public class AuditComponentImpl implements AuditComponent
{
throw new AlfrescoRuntimeException(
"Failed to extract audit data: \n" +
" Path: " + sourcePath + "\n" +
" Raw value: " + value + "\n" +
" Extractor: " + extractor,
" Path: " + sourcePath + "\n" +
" Raw value: " + value + "\n" +
" Extractor: " + extractor,
e);
}
// Add it to the map
@@ -860,8 +875,8 @@ public class AuditComponentImpl implements AuditComponent
StringBuilder sb = new StringBuilder();
sb.append(
"\nExtracted audit data: \n" +
"\tApplication: " + application + "\n" +
"\tValues: " + "\n");
"\tApplication: " + application + "\n" +
"\tValues: " + "\n");
for (Map.Entry<String, Serializable> entry : values.entrySet())
{
sb.append("\t\t").append(entry).append("\n");
@@ -877,8 +892,9 @@ public class AuditComponentImpl implements AuditComponent
}
/**
* @param generators the data generators
* @return Returns a map of generated data keyed by full path
* @param generators
* the data generators
* @return Returns a map of generated data keyed by full path
*
* @since 3.2
*/
@@ -898,8 +914,8 @@ public class AuditComponentImpl implements AuditComponent
{
throw new AlfrescoRuntimeException(
"Failed to generate audit data: \n" +
" Path: " + path + "\n" +
" Generator: " + generator,
" Path: " + path + "\n" +
" Generator: " + generator,
e);
}
// Add it to the map
@@ -947,6 +963,7 @@ public class AuditComponentImpl implements AuditComponent
{
// Get the id for the application
AuditApplication app = auditModelRegistry.getAuditApplicationByName(applicationName);
Long applicationId = app.getApplicationId();
if (applicationId == null)
{
@@ -956,8 +973,9 @@ public class AuditComponentImpl implements AuditComponent
return auditDAO.getAuditEntriesCountByApp(applicationId);
}
@Override public int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters)
@Override
public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
{
return auditDAO.getAuditEntriesCountByAppAndProperties(parameters);
return auditDAO.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
}
}

View File

@@ -55,6 +55,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.4
*/
public boolean isAuditEnabled()
@@ -64,6 +65,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.4
*/
@Override
@@ -74,6 +76,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.4
*/
@Override
@@ -95,6 +98,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.2
*/
public boolean isAuditEnabled(String applicationName, String path)
@@ -104,6 +108,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.2
*/
public void enableAudit(String applicationName, String path)
@@ -113,6 +118,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.2
*/
public void disableAudit(String applicationName, String path)
@@ -122,6 +128,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.2
*/
public int clearAudit(String applicationName)
@@ -132,6 +139,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.4
*/
@Override
@@ -143,6 +151,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 5.2.2
*/
@Override
@@ -153,6 +162,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.4
*/
@Override
@@ -163,6 +173,7 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*
* @since 3.3
*/
public void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults)
@@ -190,8 +201,10 @@ public class AuditServiceImpl implements AuditService
/**
* {@inheritDoc}
*/
@Override public int getAuditEntriesCountByAppAndProperties(AuditQueryParameters parameters)
@Override
public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
{
return auditComponent.getAuditEntriesCountByAppAndProperties(parameters);
return auditComponent.getAuditEntriesCountByAppAndProperties(applicationName, parameters);
}
}

View File

@@ -42,27 +42,21 @@ public class CrcHelper
public static final String EMPTY_STRING = ".empty";
/**
* Calculate a persistable, unique pair of values that can be persisted in a database unique
* key and guarantee correct case-sensitivity.
* Calculate a persistable, unique pair of values that can be persisted in a database unique key and guarantee correct case-sensitivity.
* <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 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.
* <p>
* 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>.
* 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>.
*
* @param value the raw value that will be persisted
* @param dataLength the maximum number of characters that can be persisted
* @param useCharsFromStart <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 caseSensitive <tt>true</tt> if the resulting pair must be case-sensitive or
* <tt>false</tt> if the pair must be case-insensitive.
* @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>
* @param value
* the raw value that will be persisted
* @param dataLength
* the maximum number of characters that can be persisted
* @param useCharsFromStart
* <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 caseSensitive
* <tt>true</tt> if the resulting pair must be case-sensitive or <tt>false</tt> if the pair must be case-insensitive.
* @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>
*/
public static Pair<String, Long> getStringCrcPair(
String value,
@@ -101,22 +95,22 @@ public class CrcHelper
catch (UnsupportedEncodingException e)
{
throw new RuntimeException("UTF-8 encoding is not supported");
}
// Crc Value will change based on the case-sensitive, So we need to get the short value based on case-sensitive
// Get the short value (case-sensitive or not)
String valueShort = null;
String currentValue = caseSensitive ? value : valueLowerCase;
int valueLen = currentValue.length();
int valueLen = valueLowerCase.length();
if (valueLen < dataLength)
{
valueShort = currentValue;
valueShort = valueLowerCase;
}
else if (useCharsFromStart)
{
valueShort = currentValue.substring(0, dataLength - 1);
valueShort = valueLowerCase.substring(0, dataLength - 1);
}
else
{
valueShort = currentValue.substring(valueLen - dataLength);
valueShort = valueLowerCase.substring(valueLen - dataLength);
}
return new Pair<String, Long>(valueShort, valueCrc);
}

View File

@@ -39,17 +39,14 @@ import org.alfresco.util.Pair;
/**
* DAO services for <b>alf_audit_XXX</b> tables.
* <p>
* The older methods are supported by a different implementation and will eventually
* be deprecated and phased out.
* The older methods are supported by a different implementation and will eventually be deprecated and phased out.
*
* @author Derek Hulley
* @since 3.2
*/
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.
@@ -69,11 +66,11 @@ public interface AuditDAO
{
StringBuilder sb = new StringBuilder();
sb.append("AuditApplicationInfo ")
.append("[ id=").append(id)
.append(", name=").append(name)
.append(", modelId=").append(modelId)
.append(", disabledPathsId=").append(disabledPathsId)
.append("]");
.append("[ id=").append(id)
.append(", name=").append(name)
.append(", modelId=").append(modelId)
.append(", disabledPathsId=").append(disabledPathsId)
.append("]");
return sb.toString();
}
@@ -81,30 +78,37 @@ public interface AuditDAO
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setname(String name)
{
this.name = name;
}
public Long getModelId()
{
return modelId;
}
public void setModelId(Long modelId)
{
this.modelId = modelId;
}
public Long getDisabledPathsId()
{
return disabledPathsId;
}
public void setDisabledPathsId(Long disabledPathsId)
{
this.disabledPathsId = disabledPathsId;
@@ -114,9 +118,9 @@ public interface AuditDAO
/**
* 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
* @param 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
*/
Pair<Long, ContentData> getOrCreateAuditModel(URL url);
@@ -124,40 +128,45 @@ public interface AuditDAO
/**
* Get the audit application details.
*
* @param applicationName the name of the application
* @return Returns details of an existing application or <tt>null</tt> if it doesn't exist
* @param applicationName
* the name of the application
* @return Returns details of an existing application or <tt>null</tt> if it doesn't exist
*
* @since 3.2
*/
AuditApplicationInfo getAuditApplication(String applicationName);
/**
* Creates a new audit application. The application name must be unique.
* Creates a new audit application. The application name must be unique.
*
* @param application the name of the application
* @param modelId the ID of the model configuration
* @param application
* the name of the application
* @param modelId
* the ID of the model configuration
*
* @since 3.2
*/
AuditApplicationInfo createAuditApplication(String application, Long modelId);
/**
* Update the audit application to refer to a new model.
* If the model did not change, then nothing will be done.
* Update the audit application to refer to a new model. If the model did not change, then nothing will be done.
*
* @param id the ID of the audit application
* @param modelId the ID of the new model
* @param id
* the ID of the audit application
* @param modelId
* the ID of the new model
*
* @since 3.2
*/
void updateAuditApplicationModel(Long id, Long modelId);
/**
* Update the audit application to hold a new set of disabled paths.
* If the value did not change, then nothing will be done.
* 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 the ID of the audit application
* @param disabledPaths the new disabled paths
* @param id
* the ID of the audit application
* @param disabledPaths
* the new disabled paths
*
* @since 3.2
*/
@@ -166,10 +175,13 @@ public interface AuditDAO
/**
* Delete audit entries for the application, possibly limiting the time range.
*
* @param applicationId an existing audit application ID
* @param fromTime the minimum entry time (inclusive, optional)
* @param toTime the maximum entry time (exclusive, optional)
* @return Returns the number of entries deleted
* @param applicationId
* an existing audit application ID
* @param fromTime
* the minimum entry time (inclusive, optional)
* @param toTime
* the maximum entry time (exclusive, optional)
* @return Returns the number of entries deleted
*
* @since 3.2
*/
@@ -178,34 +190,39 @@ public interface AuditDAO
/**
* Delete audit entries for the application for given id range.
*
* @param applicationId an existing audit application ID
* @param fromId the minimum fromId (inclusive, optional)
* @param toId the maximum toId (exclusive, optional)
* @return Returns the number of entries deleted
* @param applicationId
* an existing audit application ID
* @param fromId
* the minimum fromId (inclusive, optional)
* @param toId
* the maximum toId (exclusive, optional)
* @return Returns the number of entries deleted
*
* @since 5.2.2
*/
int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId);
/**
* 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.
* 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 auditEntryIds the IDs of all audit entries to delete
* @return Returns the number of entries deleted
* @param auditEntryIds
* the IDs of all audit entries to delete
* @return Returns the number of entries deleted
*/
int deleteAuditEntries(List<Long> auditEntryIds);
/**
* Create a new audit entry with the given map of values.
*
* @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)
* @param values the values to record
* @return Returns the unique entry ID
* @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)
* @param values
* the values to record
* @return Returns the unique entry ID
*
* @since 3.2
*/
@@ -214,11 +231,15 @@ public interface AuditDAO
/**
* Find audit entries using the given parameters, any of which may be null
*
* @param callback the data callback per entry
* @param parameters the parameters for the query (may not be <tt>null</tt>)
* @param maxResults the maximum number of results to retrieve (must be greater than 0)
* @param callback
* the data callback per entry
* @param parameters
* the parameters for the query (may not be <tt>null</tt>)
* @param maxResults
* the maximum number of results to retrieve (must be greater than 0)
*
* @throws IllegalArgumentException if maxResults less or equal to zero
* @throws IllegalArgumentException
* if maxResults less or equal to zero
*/
void findAuditEntries(
AuditQueryCallback callback,
@@ -228,17 +249,20 @@ public interface AuditDAO
/**
* Issue an audit query to retrieve min / max audit record id for a given application.
*
* @param appId the database id of the application
* @param extremes a list containing min/max or both
* @return a map containing min/max and the associated value
* @param appId
* the database id 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(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
* @param applicationId
* the database id of the application
* @return a map containing min/max and the associated value
*/
default int getAuditEntriesCountByApp(long applicationId)
{
@@ -248,10 +272,13 @@ public interface AuditDAO
/**
* Issue an audit query to retrieve count of records for a given application and properties
*
* @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 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(org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
default int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
{
return -1;
}

View File

@@ -32,6 +32,10 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.dao.ConcurrencyFailureException;
import org.alfresco.repo.domain.audit.AbstractAuditDAOImpl;
import org.alfresco.repo.domain.audit.AuditApplicationEntity;
import org.alfresco.repo.domain.audit.AuditDeleteParameters;
@@ -41,9 +45,6 @@ import org.alfresco.repo.domain.audit.AuditQueryParameters;
import org.alfresco.repo.domain.audit.AuditQueryResult;
import org.alfresco.repo.domain.propval.PropertyValueDAO.PropertyFinderCallback;
import org.alfresco.util.Pair;
import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.dao.ConcurrencyFailureException;
/**
* iBatis-specific implementation of the DAO for <b>alf_audit_XXX</b> tables.
@@ -146,7 +147,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
protected AuditApplicationEntity createAuditApplication(Long appNameId, Long modelId, Long disabledPathsId)
{
AuditApplicationEntity entity = new AuditApplicationEntity();
entity.setVersion((short)0);
entity.setVersion((short) 0);
entity.setApplicationNameId(appNameId);
entity.setAuditModelId(modelId);
entity.setDisabledPathsId(disabledPathsId);
@@ -237,7 +238,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
}
@Override
public int getAuditEntriesCountByAppAndProperties(org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
public int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters)
{
AuditQueryParameters dbParameters = convertFromRestAuditQueryParameters(parameters);
@@ -254,18 +255,17 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
org.alfresco.service.cmr.audit.AuditQueryParameters restParameters)
{
AuditQueryParameters params = convertFromRestAuditQueryParameters(restParameters);
if (params==null)
if (params == null)
{
return;
}
if (maxResults > 0)
{
// Query without getting the values. We gather all the results and batch-fetch the audited
// Query without getting the values. We gather all the results and batch-fetch the audited
// values afterwards.
final Map<Long, AuditQueryResult> resultsByValueId = new HashMap<Long, AuditQueryResult>(173);
PropertyFinderCallback propertyFinderCallback = new PropertyFinderCallback()
{
PropertyFinderCallback propertyFinderCallback = new PropertyFinderCallback() {
public void handleProperty(Long id, Serializable value)
{
// get the row
@@ -287,7 +287,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
resultsByValueId.put(row.getAuditValuesId(), row);
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());
propertyValueDAO.getPropertiesByIds(valueIds, propertyFinderCallback);
// Clear and continue
@@ -297,7 +297,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
// Process any remaining results
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());
propertyValueDAO.getPropertiesByIds(valueIds, propertyFinderCallback);
}
@@ -313,4 +313,3 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
}
}
}

View File

@@ -44,11 +44,9 @@ public class PropertyStringValueEntity
private String stringValue;
private String stringEndLower;
private Long stringCrc;
private String stringLower;
public PropertyStringValueEntity()
{
}
{}
@Override
public int hashCode()
@@ -79,9 +77,9 @@ public class PropertyStringValueEntity
{
StringBuilder sb = new StringBuilder(512);
sb.append("PropertyStringValueEntity")
.append("[ ID=").append(id)
.append(", stringValue=").append(stringValue)
.append("]");
.append("[ ID=").append(id)
.append(", stringValue=").append(stringValue)
.append("]");
return sb.toString();
}
@@ -116,9 +114,7 @@ public class PropertyStringValueEntity
Pair<String, Long> crcPair = CrcHelper.getStringCrcPair(value, 16, false, true);
stringEndLower = crcPair.getFirst();
stringCrc = crcPair.getSecond();
// Calculate the crc value with case-insensitive
Pair<String, Long> crcPairWithCaseInSensitive = CrcHelper.getStringCrcPair(value, 16, false, false);
stringLower = crcPairWithCaseInSensitive.getFirst();
}
public Long getId()
@@ -160,14 +156,4 @@ public class PropertyStringValueEntity
{
this.stringCrc = stringCrc;
}
public String getStringLower()
{
return stringLower;
}
public void setStringLower(String stringLower)
{
this.stringLower = stringLower;
}
}

View File

@@ -38,7 +38,7 @@ import java.util.Map;
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
*/
@@ -47,7 +47,8 @@ public interface AuditService
/**
* 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
*/
@@ -64,6 +65,7 @@ public interface AuditService
private final String name;
private final String key;
private final boolean enabled;
/**
* Constructor for final variables
*/
@@ -73,14 +75,17 @@ public interface AuditService
this.key = key;
this.enabled = enabled;
}
public String getName()
{
return name;
}
public String getKey()
{
return key;
}
public boolean isEnabled()
{
return enabled;
@@ -90,16 +95,18 @@ public interface AuditService
/**
* Get all registered audit applications
*
* @return Returns a map of audit applications keyed by their name
* @return Returns a map of audit applications keyed by their name
*
* @since 3.4
*/
Map<String, AuditApplication> getAuditApplications();
/**
* @param applicationName the name of the application to check
* @param path the path to check
* @return Returns <tt>true</tt> if auditing is enabled for the given path
* @param applicationName
* the name of the application to check
* @param path
* the path to check
* @return Returns <tt>true</tt> if auditing is enabled for the given path
*
* @since 3.2
*/
@@ -108,8 +115,10 @@ public interface AuditService
/**
* Enable auditing for an application path
*
* @param applicationName the name of the application to check
* @param path the path to enable
* @param applicationName
* the name of the application to check
* @param path
* the path to enable
*
* @since 3.2
*/
@@ -118,8 +127,10 @@ public interface AuditService
/**
* Disable auditing for an application path
*
* @param applicationName the name of the application to check
* @param path the path to disable
* @param applicationName
* the name of the application to check
* @param path
* the path to disable
*
* @since 3.2
*/
@@ -128,24 +139,26 @@ public interface AuditService
/**
* Remove all audit entries for the given application
*
* @param applicationName 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
* @return Returns the number of audit entries deleted
*
* @since 3.2
*
* @deprecated Use {@link #clearAudit(String, Long, Long)}
* @deprecated Use {@link #clearAudit(String, Long, Long)}
*/
int clearAudit(String applicationName);
/**
* 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 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.
*
* @param applicationName the name of the application for which to remove entries
* @param fromTime the start time of entries to remove (inclusive and optional)
* @param toTime the end time of entries to remove (exclusive and optional)
* @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)
* @param toTime
* the end time of entries to remove (exclusive and optional)
* @return Returns the number of audit entries deleted
*
* @since 3.4
*/
@@ -154,10 +167,13 @@ public interface AuditService
/**
* 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 fromId the start time of entries to remove (inclusive and optional)
* @param toId the end time of entries to remove (exclusive and optional)
* @return Returns the number of audit entries deleted
* @param applicationName
* the name of the application for which to remove entries
* @param fromId
* the start time of entries to remove (inclusive and optional)
* @param toId
* the end time of entries to remove (exclusive and optional)
* @return Returns the number of audit entries deleted
*
* @since 5.2.2
*/
@@ -166,11 +182,11 @@ public interface AuditService
/**
* Delete a discrete list of audit entries.
* <p/>
* This method should not be called <i>while</i> processing
* {@link #auditQuery(AuditQueryCallback, AuditQueryParameters, int) query results}.
* This method should not be called <i>while</i> processing {@link #auditQuery(AuditQueryCallback, AuditQueryParameters, int) query results}.
*
* @param auditEntryIds the IDs of all audit entries to delete
* @return Returns the number of audit entries deleted
* @param auditEntryIds
* the IDs of all audit entries to delete
* @return Returns the number of audit entries deleted
*
* @since 3.4
*/
@@ -184,8 +200,7 @@ public interface AuditService
public static interface AuditQueryCallback
{
/**
* Determines whether this callback requires the values argument to be populated when {@link #handleAuditEntry}
* is called.
* Determines whether this callback requires the values argument to be populated when {@link #handleAuditEntry} is called.
*
* @return <code>true</code> if this callback requires the values argument to be populated
*/
@@ -194,12 +209,17 @@ public interface AuditService
/**
* Handle a row of audit entry data.
*
* @param entryId the unique audit entry ID
* @param applicationName the name of the application
* @param user the user that logged the entry
* @param time 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
* @param entryId
* the unique audit entry ID
* @param applicationName
* the name of the application
* @param user
* the user that logged the entry
* @param time
* 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
*/
boolean handleAuditEntry(
Long entryId,
@@ -211,23 +231,29 @@ public interface AuditService
/**
* Handle audit entry failures
*
* @param entryId the entry ID
* @param errorMsg the error message
* @param error the exception causing the error (may be <tt>null</tt>)
* @return Return <tt>true</tt> to continue processing rows or <tt>false</tt> to stop
* @param entryId
* the entry ID
* @param errorMsg
* the error message
* @param error
* the exception causing the error (may be <tt>null</tt>)
* @return Return <tt>true</tt> to continue processing rows or <tt>false</tt> to stop
*/
boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error);
}
/**
* Issue an audit query using the given parameters and consuming results in the callback.
* Results are returned in entry order, corresponding to time order.
* 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 callback the callback that will handle results
* @param parameters the parameters for the query (may not be <tt>null</tt>)
* @param maxResults the maximum number of results to retrieve (must be greater than 0)
* @param callback
* the callback that will handle results
* @param parameters
* the parameters for the query (may not be <tt>null</tt>)
* @param maxResults
* the maximum number of results to retrieve (must be greater than 0)
*
* @throws IllegalArgumentException if maxResults less or equal to zero
* @throws IllegalArgumentException
* if maxResults less or equal to zero
*
* @since 3.3
*/
@@ -236,17 +262,20 @@ public interface AuditService
/**
* Issue an audit query to retrieve min / max audit record id for a given application.
*
* @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
* @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
* @param applicationName
* the name of the application
* @return a map containing min/max and the associated value
*/
default int getAuditEntriesCountByApp(String applicationName)
{
@@ -256,11 +285,15 @@ public interface AuditService
/**
* Issue an audit query to retrieve min / max audit record id for a given application and properties
*
* @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 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(AuditQueryParameters parameters)
default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters)
{
return -1;
}
}