[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)));
@@ -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

@@ -46,7 +46,7 @@ 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
*/ */
@@ -55,14 +55,16 @@ public interface AuditComponent
/** /**
* 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
* UserAuditFilter
* *
* @since 4.2 * @since 4.2
*/ */
@@ -71,36 +73,28 @@ public interface AuditComponent
/** /**
* Get all registered audit applications, whether active or not. * 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 * @since 3.4
*/ */
public Map<String, AuditApplication> getAuditApplications(); public Map<String, AuditApplication> getAuditApplications();
/** /**
* Determine whether the audit infrastructure expects audit values to be passed in. * 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>.
* 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) * @return Returns <code>true</code> if the calling code (data producers) should go ahead and generate the data for {@link #recordAuditValues(String, Map) recording}.
* should go ahead and generate the data for
* {@link #recordAuditValues(String, Map) recording}.
* *
* @since 3.3 * @since 3.3
*/ */
public boolean areAuditValuesRequired(); public boolean areAuditValuesRequired();
/** /**
* Determines if audit values are required based on whether there are any audit applications * 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.
* 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 * @param path
* @return Returns <tt>true</tt> if there is at least one audit application * the audit path
* registered to handle the given path. * @return Returns <tt>true</tt> if there is at least one audit application registered to handle the given path.
* *
* @since 3.4 * @since 3.4
*/ */
@@ -109,10 +103,13 @@ public interface AuditComponent
/** /**
* Delete audit entries for the given application and time range * Delete audit entries for the given application and time range
* *
* @param applicationName the name of the application * @param applicationName
* @param fromTime the start time of entries to remove (inclusive and optional) * the name of the application
* @param toTime the end time of entries to remove (exclusive and optional) * @param fromTime
* @return Returns the number of entries deleted * 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 * @since 3.2
*/ */
@@ -121,10 +118,13 @@ public interface AuditComponent
/** /**
* Delete audit entries for the given application and id range * Delete audit entries for the given application and id range
* *
* @param applicationName the name of the application * @param applicationName
* @param fromId the start time of entries to remove (inclusive and optional) * the name of the application
* @param toId the end time of entries to remove (exclusive and optional) * @param fromId
* @return Returns the number of entries deleted * 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 * @since 5.2.2
*/ */
@@ -133,95 +133,79 @@ public interface AuditComponent
/** /**
* 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 * 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.
* 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 applicationName
* @param path the audit path to check or <tt>null</tt> to assume the * the name of the application being logged to
* application's root path * @param path
* @return Returns <tt>true</tt> if the audit path has been disabled * 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 * @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
* not the path that the generated data may contain - although this would be similarly
* enabled.
* <p> * <p>
* If the enabled * If the enabled
* *
* @param applicationName the name of the application being logged to * @param applicationName
* @param path the audit path to check or <tt>null</tt> to assume the * the name of the application being logged to
* 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. * 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.
* 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> * <p>
* If the path is <b>/x/y</b> then any data paths that start with <b>/x/y</b> will be stripped * 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.
* 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 applicationName
* @param path the audit path to check or <tt>null</tt> to assume the * the name of the application being logged to
* 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 disableAudit(String applicationName, String path); void disableAudit(String applicationName, String path);
/** /**
* Remove all disabled paths i.e. enable all per-path based auditing. Auditing may still be * 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}.
* 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 * @since 3.2
*/ */
void resetDisabledPaths(String applicationName); void resetDisabledPaths(String applicationName);
/** /**
* Create an audit entry for the given map of values. The map key is a path - starting with '/' * 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.
* ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) - relative to the root path provided.
* <p/> * <p/>
* The root path and value keys are combined to produce a map of data keyed by full path. This * 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).
* 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/> * <p/>
* The return values reflect what was actually persisted and is controlled by the data extractors * The return values reflect what was actually persisted and is controlled by the data extractors defined in the audit configuration.
* defined in the audit configuration.
* <p/> * <p/>
* A new read-write transaction is started if there are values to write that there is not a viable * A new read-write transaction is started if there are values to write that there is not a viable transaction present.
* transaction present.
* *
* @param rootPath a base path of {@link AuditPath} key entries concatenated with the path separator * @param rootPath
* '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) * 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 * @param values
* (may be <tt>null</tt>) * 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. * @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 * @since 3.2
*/ */
@@ -230,24 +214,30 @@ public interface AuditComponent
/** /**
* The same as {@link AuditComponent#recordAuditValues(String, Map)}, but with controlled usage of userFilter * 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 * @param rootPath
* '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) * 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 * @param values
* (may be <tt>null</tt>) * 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. * @param useUserFilter
* @return Returns the values that were actually persisted, keyed by their full path. * if <tt>false</tt> the user filter is disabled.
* @throws IllegalStateException if the transaction state could not be determined * @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); Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter);
/** /**
* Find audit entries using the given parameters * Find audit entries using the given parameters
* *
* @param callback the data callback per entry * @param callback
* @param parameters the parameters for the query (may not be <tt>null</tt>) * the data callback per entry
* @param maxResults the maximum number of results to retrieve (must be greater than 0) * @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 * @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. * Issue an audit query to retrieve min / max audit record id for a given application.
* *
* @param applicationName the name of the application * @param applicationName
* @param extremes a list containing min/max or both * the name of the application
* @return a map containing min/max and the associated value * @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); HashMap<String, Long> getAuditMinMaxByApp(String applicationName, List<String> extremes);
/** /**
* Issue an audit query to retrieve count of records 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 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
*/ */
default int getAuditEntriesCountByApp(String applicationName) 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 * 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 * @param applicationName
* @return a map containing min/max and the associated value * 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; return -1;
} }

View File

@@ -34,13 +34,17 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; 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.error.AlfrescoRuntimeException;
import org.alfresco.repo.audit.extractor.DataExtractor; import org.alfresco.repo.audit.extractor.DataExtractor;
import org.alfresco.repo.audit.generator.DataGenerator; import org.alfresco.repo.audit.generator.DataGenerator;
import org.alfresco.repo.audit.model.AuditApplication; 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.AuditModelRegistry;
import org.alfresco.repo.audit.model.AuditModelRegistryImpl; 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.audit.AuditDAO;
import org.alfresco.repo.domain.propval.PropertyValueDAO; import org.alfresco.repo.domain.propval.PropertyValueDAO;
import org.alfresco.repo.security.authentication.AuthenticationUtil; 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.cmr.audit.AuditService.AuditQueryCallback;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.PathMapper; 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. * Component that records audit values as well as providing the query implementation.
@@ -86,11 +87,11 @@ public class AuditComponentImpl implements AuditComponent
* Default constructor * Default constructor
*/ */
public AuditComponentImpl() public AuditComponentImpl()
{ {}
}
/** /**
* Set the registry holding the audit models * Set the registry holding the audit models
*
* @since 3.2 * @since 3.2
*/ */
public void setAuditModelRegistry(AuditModelRegistryImpl auditModelRegistry) public void setAuditModelRegistry(AuditModelRegistryImpl auditModelRegistry)
@@ -100,6 +101,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* Set the DAO for manipulating property values * Set the DAO for manipulating property values
*
* @since 3.2 * @since 3.2
*/ */
public void setPropertyValueDAO(PropertyValueDAO propertyValueDAO) public void setPropertyValueDAO(PropertyValueDAO propertyValueDAO)
@@ -109,6 +111,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* Set the DAO for accessing audit data * Set the DAO for accessing audit data
*
* @since 3.2 * @since 3.2
*/ */
public void setAuditDAO(AuditDAO auditDAO) public void setAuditDAO(AuditDAO auditDAO)
@@ -139,6 +142,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public int deleteAuditEntries(String applicationName, Long fromTime, Long toTime) public int deleteAuditEntries(String applicationName, Long fromTime, Long toTime)
@@ -155,13 +159,14 @@ public class AuditComponentImpl implements AuditComponent
{ {
logger.debug( logger.debug(
"Delete audit " + deleted + " entries for " + applicationName + "Delete audit " + deleted + " entries for " + applicationName +
" (" + fromTime + " to " + toTime); " (" + fromTime + " to " + toTime);
} }
return deleted; return deleted;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 5.2.2 * @since 5.2.2
*/ */
public int deleteAuditEntriesByIdRange(String applicationName, Long fromId, Long toId) public int deleteAuditEntriesByIdRange(String applicationName, Long fromId, Long toId)
@@ -203,6 +208,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
@Override @Override
@@ -217,8 +223,9 @@ public class AuditComponentImpl implements AuditComponent
} }
/** /**
* @param application the audit application object * @param application
* @return Returns a copy of the set of disabled paths associated with the application * the audit application object
* @return Returns a copy of the set of disabled paths associated with the application
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Set<String> getDisabledPaths(AuditApplication application) private Set<String> getDisabledPaths(AuditApplication application)
@@ -239,6 +246,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public boolean isAuditEnabled() public boolean isAuditEnabled()
@@ -248,6 +256,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.4 * @since 3.4
*/ */
@Override @Override
@@ -259,14 +268,15 @@ public class AuditComponentImpl implements AuditComponent
// It is changing // It is changing
auditModelRegistry.stop(); auditModelRegistry.stop();
auditModelRegistry.setProperty( auditModelRegistry.setProperty(
AuditModelRegistry.AUDIT_PROPERTY_AUDIT_ENABLED, AuditModelRegistry.AUDIT_PROPERTY_AUDIT_ENABLED,
Boolean.toString(enable).toLowerCase()); Boolean.toString(enable).toLowerCase());
auditModelRegistry.start(); auditModelRegistry.start();
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.4 * @since 3.4
*/ */
public Map<String, AuditApplication> getAuditApplications() public Map<String, AuditApplication> getAuditApplications()
@@ -277,8 +287,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* {@inheritDoc} * {@inheritDoc}
* <p/> * <p/>
* Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt> * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt> will always be returned.
* will always be returned.
* *
* @since 3.2 * @since 3.2
*/ */
@@ -291,8 +300,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* {@inheritDoc} * {@inheritDoc}
* <p/> * <p/>
* Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt> * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt> will always be returned.
* will always be returned.
* *
* @since 3.4 * @since 3.4
*/ */
@@ -306,6 +314,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public boolean isAuditPathEnabled(String applicationName, String path) public boolean isAuditPathEnabled(String applicationName, String path)
@@ -336,7 +345,8 @@ public class AuditComponentImpl implements AuditComponent
Set<String> disabledPaths = getDisabledPaths(application); Set<String> disabledPaths = getDisabledPaths(application);
// Check if there are any entries that match or supercede the given path // Check if there are any entries that match or supercede the given path
String disablingPath = null;; String disablingPath = null;
;
for (String disabledPath : disabledPaths) for (String disabledPath : disabledPaths)
{ {
if (path.startsWith(disabledPath)) if (path.startsWith(disabledPath))
@@ -350,15 +360,16 @@ public class AuditComponentImpl implements AuditComponent
{ {
logger.debug( logger.debug(
"Audit path enabled check: \n" + "Audit path enabled check: \n" +
" Application: " + applicationName + "\n" + " Application: " + applicationName + "\n" +
" Path: " + path + "\n" + " Path: " + path + "\n" +
" Disabling Path: " + disablingPath); " Disabling Path: " + disablingPath);
} }
return disablingPath == null; return disablingPath == null;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public void enableAudit(String applicationName, String path) public void enableAudit(String applicationName, String path)
@@ -409,8 +420,8 @@ public class AuditComponentImpl implements AuditComponent
{ {
logger.debug( logger.debug(
"Audit disabled paths updated: \n" + "Audit disabled paths updated: \n" +
" Application: " + applicationName + "\n" + " Application: " + applicationName + "\n" +
" Disabled: " + disabledPaths); " Disabled: " + disabledPaths);
} }
} }
// Done // Done
@@ -418,6 +429,7 @@ public class AuditComponentImpl implements AuditComponent
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public void disableAudit(String applicationName, String path) public void disableAudit(String applicationName, String path)
@@ -455,7 +467,7 @@ public class AuditComponentImpl implements AuditComponent
{ {
logger.debug( logger.debug(
"Audit disable path already present: \n" + "Audit disable path already present: \n" +
" Path: " + path); " Path: " + path);
} }
return; return;
} }
@@ -477,8 +489,8 @@ public class AuditComponentImpl implements AuditComponent
{ {
logger.debug( logger.debug(
"Audit disable path superceded: \n" + "Audit disable path superceded: \n" +
" Path: " + path + "\n" + " Path: " + path + "\n" +
" Superceded by: " + disabledPath); " Superceded by: " + disabledPath);
} }
return; return;
} }
@@ -492,13 +504,14 @@ public class AuditComponentImpl implements AuditComponent
{ {
logger.debug( logger.debug(
"Audit disabled paths updated: \n" + "Audit disabled paths updated: \n" +
" Application: " + applicationName + "\n" + " Application: " + applicationName + "\n" +
" Disabled: " + disabledPaths); " Disabled: " + disabledPaths);
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public void resetDisabledPaths(String applicationName) public void resetDisabledPaths(String applicationName)
@@ -546,9 +559,9 @@ public class AuditComponentImpl implements AuditComponent
// Log inbound values // Log inbound values
if (loggerInbound.isDebugEnabled()) if (loggerInbound.isDebugEnabled())
{ {
StringBuilder sb = new StringBuilder(values.size()*64); StringBuilder sb = new StringBuilder(values.size() * 64);
sb.append("\n") sb.append("\n")
.append("Inbound audit values:"); .append("Inbound audit values:");
for (Map.Entry<String, Serializable> entry : values.entrySet()) for (Map.Entry<String, Serializable> entry : values.entrySet())
{ {
String pathElement = entry.getKey(); String pathElement = entry.getKey();
@@ -576,16 +589,14 @@ public class AuditComponentImpl implements AuditComponent
return mappedValues; 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(); TxnReadState txnState = AlfrescoTransactionSupport.getTransactionReadState();
switch (txnState) switch (txnState)
{ {
case TXN_NONE: case TXN_NONE:
case TXN_READ_ONLY: case TXN_READ_ONLY:
// New transaction // New transaction
RetryingTransactionCallback<Map<String, Serializable>> callback = RetryingTransactionCallback<Map<String, Serializable>> callback = new RetryingTransactionCallback<Map<String, Serializable>>() {
new RetryingTransactionCallback<Map<String,Serializable>>()
{
public Map<String, Serializable> execute() throws Throwable public Map<String, Serializable> execute() throws Throwable
{ {
return recordAuditValuesImpl(mappedValues); return recordAuditValuesImpl(mappedValues);
@@ -607,7 +618,7 @@ public class AuditComponentImpl implements AuditComponent
public Map<String, Serializable> recordAuditValuesImpl(Map<String, Serializable> mappedValues) public Map<String, Serializable> recordAuditValuesImpl(Map<String, Serializable> mappedValues)
{ {
// Group the values by root path // 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()) for (Map.Entry<String, Serializable> entry : mappedValues.entrySet())
{ {
String path = entry.getKey(); String path = entry.getKey();
@@ -621,7 +632,7 @@ public class AuditComponentImpl implements AuditComponent
rootKeyMappedValues.put(path, entry.getValue()); 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 // Now audit for each of the root keys
for (Map.Entry<String, Map<String, Serializable>> entry : mappedValuesByRootKey.entrySet()) for (Map.Entry<String, Map<String, Serializable>> entry : mappedValuesByRootKey.entrySet())
{ {
@@ -646,8 +657,8 @@ public class AuditComponentImpl implements AuditComponent
{ {
logger.debug( logger.debug(
"Audit values root path has been excluded by disabled paths: \n" + "Audit values root path has been excluded by disabled paths: \n" +
" Application: " + application + "\n" + " Application: " + application + "\n" +
" Root Path: " + AuditApplication.buildPath(rootKey)); " Root Path: " + AuditApplication.buildPath(rootKey));
} }
continue; 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 application
* @param disabledPaths the application's disabled paths * the audit application to audit to
* @param values the values to store keyed by <b>full paths</b>. * @param disabledPaths
* @return Returns all values as audited * 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( private Map<String, Serializable> audit(
final AuditApplication application, final AuditApplication application,
@@ -686,8 +700,8 @@ public class AuditComponentImpl implements AuditComponent
{ {
logger.debug( logger.debug(
"Audit values have all been excluded by disabled paths: \n" + "Audit values have all been excluded by disabled paths: \n" +
" Application: " + application + "\n" + " Application: " + application + "\n" +
" Values: " + values); " Values: " + values);
} }
return Collections.emptyMap(); return Collections.emptyMap();
} }
@@ -695,7 +709,7 @@ public class AuditComponentImpl implements AuditComponent
Set<String> generatorKeys = values.keySet(); Set<String> generatorKeys = values.keySet();
// Eliminate any paths that have been disabled // Eliminate any paths that have been disabled
Iterator<String> generatorKeysIterator = generatorKeys.iterator(); Iterator<String> generatorKeysIterator = generatorKeys.iterator();
while(generatorKeysIterator.hasNext()) while (generatorKeysIterator.hasNext())
{ {
String generatorKey = generatorKeysIterator.next(); String generatorKey = generatorKeysIterator.next();
for (String disabledPath : disabledPaths) for (String disabledPath : disabledPaths)
@@ -713,8 +727,7 @@ public class AuditComponentImpl implements AuditComponent
Map<String, Serializable> auditData = generateData(generators); Map<String, Serializable> auditData = generateData(generators);
// Now extract values // 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 public Map<String, Serializable> doWork() throws Exception
{ {
return extractData(application, values); return extractData(application, values);
@@ -757,9 +770,9 @@ public class AuditComponentImpl implements AuditComponent
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append( sb.append(
((justGatherPreCallData) ? "\nPreCallData: \n" : "\nNew audit entry: \n") + ((justGatherPreCallData) ? "\nPreCallData: \n" : "\nNew audit entry: \n") +
"\tApplication ID: " + applicationId + "\n" + "\tApplication ID: " + applicationId + "\n" +
((justGatherPreCallData) ? "" : "\tEntry ID: " + entryId + "\n") + ((justGatherPreCallData) ? "" : "\tEntry ID: " + entryId + "\n") +
"\tValues: " + "\n"); "\tValues: " + "\n");
for (Map.Entry<String, Serializable> entry : values.entrySet()) for (Map.Entry<String, Serializable> entry : values.entrySet())
{ {
sb.append("\t\t").append(entry).append("\n"); sb.append("\t\t").append(entry).append("\n");
@@ -780,9 +793,9 @@ public class AuditComponentImpl implements AuditComponent
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append( sb.append(
"\nNothing audited: \n" + "\nNothing audited: \n" +
"\tApplication ID: " + applicationId + "\n" + "\tApplication ID: " + applicationId + "\n" +
"\tEntry ID: " + entryId + "\n" + "\tEntry ID: " + entryId + "\n" +
"\tValues: " + "\n"); "\tValues: " + "\n");
for (Map.Entry<String, Serializable> entry : values.entrySet()) for (Map.Entry<String, Serializable> entry : values.entrySet())
{ {
sb.append("\t\t").append(entry).append("\n"); 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. * Extracts data from a given map using data extractors from the given application.
* *
* @param application the application providing the data extractors * @param application
* @param values the data values from which to generate data * the application providing the data extractors
* @return Returns a map of derived data keyed by full path * @param values
* the data values from which to generate data
* @return Returns a map of derived data keyed by full path
* *
* @since 3.2 * @since 3.2
*/ */
@@ -820,13 +835,13 @@ public class AuditComponentImpl implements AuditComponent
// Check if it is triggered // Check if it is triggered
if (!values.containsKey(triggerPath)) if (!values.containsKey(triggerPath))
{ {
continue; // It is not triggered continue; // It is not triggered
} }
// We observe the key, not the actual value // We observe the key, not the actual value
if (!values.containsKey(sourcePath)) if (!values.containsKey(sourcePath))
{ {
continue; // There is no data to extract continue; // There is no data to extract
} }
Serializable value = values.get(sourcePath); Serializable value = values.get(sourcePath);
@@ -846,9 +861,9 @@ public class AuditComponentImpl implements AuditComponent
{ {
throw new AlfrescoRuntimeException( throw new AlfrescoRuntimeException(
"Failed to extract audit data: \n" + "Failed to extract audit data: \n" +
" Path: " + sourcePath + "\n" + " Path: " + sourcePath + "\n" +
" Raw value: " + value + "\n" + " Raw value: " + value + "\n" +
" Extractor: " + extractor, " Extractor: " + extractor,
e); e);
} }
// Add it to the map // Add it to the map
@@ -860,8 +875,8 @@ public class AuditComponentImpl implements AuditComponent
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append( sb.append(
"\nExtracted audit data: \n" + "\nExtracted audit data: \n" +
"\tApplication: " + application + "\n" + "\tApplication: " + application + "\n" +
"\tValues: " + "\n"); "\tValues: " + "\n");
for (Map.Entry<String, Serializable> entry : values.entrySet()) for (Map.Entry<String, Serializable> entry : values.entrySet())
{ {
sb.append("\t\t").append(entry).append("\n"); sb.append("\t\t").append(entry).append("\n");
@@ -877,8 +892,9 @@ public class AuditComponentImpl implements AuditComponent
} }
/** /**
* @param generators the data generators * @param generators
* @return Returns a map of generated data keyed by full path * the data generators
* @return Returns a map of generated data keyed by full path
* *
* @since 3.2 * @since 3.2
*/ */
@@ -898,8 +914,8 @@ public class AuditComponentImpl implements AuditComponent
{ {
throw new AlfrescoRuntimeException( throw new AlfrescoRuntimeException(
"Failed to generate audit data: \n" + "Failed to generate audit data: \n" +
" Path: " + path + "\n" + " Path: " + path + "\n" +
" Generator: " + generator, " Generator: " + generator,
e); e);
} }
// Add it to the map // Add it to the map
@@ -947,6 +963,7 @@ public class AuditComponentImpl implements AuditComponent
{ {
// Get the id for the application // Get the id for the application
AuditApplication app = auditModelRegistry.getAuditApplicationByName(applicationName); AuditApplication app = auditModelRegistry.getAuditApplicationByName(applicationName);
Long applicationId = app.getApplicationId(); Long applicationId = app.getApplicationId();
if (applicationId == null) if (applicationId == null)
{ {
@@ -956,8 +973,9 @@ public class AuditComponentImpl implements AuditComponent
return auditDAO.getAuditEntriesCountByApp(applicationId); 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} * {@inheritDoc}
*
* @since 3.4 * @since 3.4
*/ */
public boolean isAuditEnabled() public boolean isAuditEnabled()
@@ -64,6 +65,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.4 * @since 3.4
*/ */
@Override @Override
@@ -74,6 +76,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.4 * @since 3.4
*/ */
@Override @Override
@@ -95,6 +98,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public boolean isAuditEnabled(String applicationName, String path) public boolean isAuditEnabled(String applicationName, String path)
@@ -104,6 +108,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public void enableAudit(String applicationName, String path) public void enableAudit(String applicationName, String path)
@@ -113,6 +118,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public void disableAudit(String applicationName, String path) public void disableAudit(String applicationName, String path)
@@ -122,6 +128,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.2 * @since 3.2
*/ */
public int clearAudit(String applicationName) public int clearAudit(String applicationName)
@@ -132,6 +139,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.4 * @since 3.4
*/ */
@Override @Override
@@ -143,6 +151,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 5.2.2 * @since 5.2.2
*/ */
@Override @Override
@@ -153,6 +162,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.4 * @since 3.4
*/ */
@Override @Override
@@ -163,6 +173,7 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@inheritDoc}
*
* @since 3.3 * @since 3.3
*/ */
public void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults) public void auditQuery(AuditQueryCallback callback, AuditQueryParameters parameters, int maxResults)
@@ -190,8 +201,10 @@ public class AuditServiceImpl implements AuditService
/** /**
* {@inheritDoc} * {@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"; 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 * 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.
* 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> * <p>
* If the value is an empty string, then {@link #EMPTY_STRING} is used instead. This ensures * 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>.
* 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 value
* @param dataLength the maximum number of characters that can be persisted * the raw value that will be persisted
* @param useCharsFromStart <tt>true</tt> if the shortened string value must be made from * @param dataLength
* the first characters of the string or <tt>false</tt> to use * the maximum number of characters that can be persisted
* characters from the end of the string. * @param useCharsFromStart
* @param caseSensitive <tt>true</tt> if the resulting pair must be case-sensitive or * <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.
* <tt>false</tt> if the pair must be case-insensitive. * @param caseSensitive
* @return Return the persistable pair. The result will never be <tt>null</tt>, * <tt>true</tt> if the resulting pair must be case-sensitive or <tt>false</tt> if the pair must be case-insensitive.
* but the individual pair values will be <tt>null</tt> if the * @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>
* value given is <tt>null</tt>
*/ */
public static Pair<String, Long> getStringCrcPair( public static Pair<String, Long> getStringCrcPair(
String value, String value,
@@ -101,22 +95,22 @@ public class CrcHelper
catch (UnsupportedEncodingException e) catch (UnsupportedEncodingException e)
{ {
throw new RuntimeException("UTF-8 encoding is not supported"); 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 valueShort = null;
String currentValue = caseSensitive ? value : valueLowerCase; int valueLen = valueLowerCase.length();
int valueLen = currentValue.length();
if (valueLen < dataLength) if (valueLen < dataLength)
{ {
valueShort = currentValue; valueShort = valueLowerCase;
} }
else if (useCharsFromStart) else if (useCharsFromStart)
{ {
valueShort = currentValue.substring(0, dataLength - 1); valueShort = valueLowerCase.substring(0, dataLength - 1);
} }
else else
{ {
valueShort = currentValue.substring(valueLen - dataLength); valueShort = valueLowerCase.substring(valueLen - dataLength);
} }
return new Pair<String, Long>(valueShort, valueCrc); 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. * 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. * 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(); StringBuilder sb = new StringBuilder();
sb.append("AuditApplicationInfo ") sb.append("AuditApplicationInfo ")
.append("[ id=").append(id) .append("[ id=").append(id)
.append(", name=").append(name) .append(", name=").append(name)
.append(", modelId=").append(modelId) .append(", modelId=").append(modelId)
.append(", disabledPathsId=").append(disabledPathsId) .append(", disabledPathsId=").append(disabledPathsId)
.append("]"); .append("]");
return sb.toString(); return sb.toString();
} }
@@ -81,30 +78,37 @@ public interface AuditDAO
{ {
return id; 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) public void setModelId(Long modelId)
{ {
this.modelId = modelId; this.modelId = modelId;
} }
public Long getDisabledPathsId() public Long getDisabledPathsId()
{ {
return disabledPathsId; return disabledPathsId;
} }
public void setDisabledPathsId(Long disabledPathsId) public void setDisabledPathsId(Long disabledPathsId)
{ {
this.disabledPathsId = disabledPathsId; this.disabledPathsId = disabledPathsId;
@@ -114,9 +118,9 @@ public interface AuditDAO
/** /**
* Creates a new audit model entry or finds an existing one * Creates a new audit model entry or finds an existing one
* *
* @param url the URL of the configuration * @param url
* @return Returns the ID of the config matching the input stream and the * the URL of the configuration
* content storage details * @return Returns the ID of the config matching the input stream and the content storage details
* @since 3.2 * @since 3.2
*/ */
Pair<Long, ContentData> getOrCreateAuditModel(URL url); Pair<Long, ContentData> getOrCreateAuditModel(URL url);
@@ -124,40 +128,45 @@ public interface AuditDAO
/** /**
* Get the audit application details. * Get the audit application details.
* *
* @param applicationName the name of the application * @param applicationName
* @return Returns details of an existing application or <tt>null</tt> if it doesn't exist * the name of the application
* @return Returns details of an existing application or <tt>null</tt> if it doesn't exist
* *
* @since 3.2 * @since 3.2
*/ */
AuditApplicationInfo getAuditApplication(String applicationName); 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 application
* @param modelId the ID of the model configuration * the name of the application
* @param modelId
* the ID of the model configuration
* *
* @since 3.2 * @since 3.2
*/ */
AuditApplicationInfo createAuditApplication(String application, Long modelId); AuditApplicationInfo createAuditApplication(String application, Long modelId);
/** /**
* Update the audit application to refer to a new model. * Update the audit application to refer to a new model. If the model did not change, then nothing will be done.
* If the model did not change, then nothing will be done.
* *
* @param id the ID of the audit application * @param id
* @param modelId the ID of the new model * the ID of the audit application
* @param modelId
* the ID of the new model
* *
* @since 3.2 * @since 3.2
*/ */
void updateAuditApplicationModel(Long id, Long modelId); void updateAuditApplicationModel(Long id, Long modelId);
/** /**
* Update the audit application to hold a new set of disabled paths. * Update the audit application to hold a new set of disabled paths. If the value did not change, then nothing will be done.
* If the value did not change, then nothing will be done.
* *
* @param id the ID of the audit application * @param id
* @param disabledPaths the new disabled paths * the ID of the audit application
* @param disabledPaths
* the new disabled paths
* *
* @since 3.2 * @since 3.2
*/ */
@@ -166,10 +175,13 @@ public interface AuditDAO
/** /**
* Delete audit entries for the application, possibly limiting the time range. * Delete audit entries for the application, possibly limiting the time range.
* *
* @param applicationId an existing audit application ID * @param applicationId
* @param fromTime the minimum entry time (inclusive, optional) * an existing audit application ID
* @param toTime the maximum entry time (exclusive, optional) * @param fromTime
* @return Returns the number of entries deleted * the minimum entry time (inclusive, optional)
* @param toTime
* the maximum entry time (exclusive, optional)
* @return Returns the number of entries deleted
* *
* @since 3.2 * @since 3.2
*/ */
@@ -178,34 +190,39 @@ public interface AuditDAO
/** /**
* Delete audit entries for the application for given id range. * Delete audit entries for the application for given id range.
* *
* @param applicationId an existing audit application ID * @param applicationId
* @param fromId the minimum fromId (inclusive, optional) * an existing audit application ID
* @param toId the maximum toId (exclusive, optional) * @param fromId
* @return Returns the number of entries deleted * the minimum fromId (inclusive, optional)
* @param toId
* the maximum toId (exclusive, optional)
* @return Returns the number of entries deleted
* *
* @since 5.2.2 * @since 5.2.2
*/ */
int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId); int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId);
/** /**
* Delete a discrete list of audit entries. Duplicate entries are collapsed * 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.
* 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 * @param auditEntryIds
* @return Returns the number of entries deleted * the IDs of all audit entries to delete
* @return Returns the number of entries deleted
*/ */
int deleteAuditEntries(List<Long> auditEntryIds); int deleteAuditEntries(List<Long> auditEntryIds);
/** /**
* Create a new audit entry with the given map of values. * Create a new audit entry with the given map of values.
* *
* @param applicationId an existing audit application ID * @param applicationId
* @param time the time (ms since epoch) to log the entry against * an existing audit application ID
* @param username the authenticated user (<tt>null</tt> if not present) * @param time
* @param values the values to record * the time (ms since epoch) to log the entry against
* @return Returns the unique entry ID * @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 * @since 3.2
*/ */
@@ -214,11 +231,15 @@ public interface AuditDAO
/** /**
* Find audit entries using the given parameters, any of which may be null * Find audit entries using the given parameters, any of which may be null
* *
* @param callback the data callback per entry * @param callback
* @param parameters the parameters for the query (may not be <tt>null</tt>) * the data callback per entry
* @param maxResults the maximum number of results to retrieve (must be greater than 0) * @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( void findAuditEntries(
AuditQueryCallback callback, AuditQueryCallback callback,
@@ -228,17 +249,20 @@ public interface AuditDAO
/** /**
* Issue an audit query to retrieve min / max audit record id for a given application. * Issue an audit query to retrieve min / max audit record id for a given application.
* *
* @param appId the database id of the application * @param appId
* @param extremes a list containing min/max or both * the database id of the application
* @return a map containing min/max and the associated value * @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); HashMap<String, Long> getAuditMinMaxByApp(long appId, List<String> extremes);
/** /**
* Issue an audit query to retrieve count of records for a given application. * Issue an audit query to retrieve count of records for a given application.
* *
* @param applicationId the database id of the application * @param applicationId
* @return a map containing min/max and the associated value * the database id of the application
* @return a map containing min/max and the associated value
*/ */
default int getAuditEntriesCountByApp(long applicationId) 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 * 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 * @param applicationName
* @return a map containing min/max and the associated value * 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; return -1;
} }

View File

@@ -32,6 +32,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; 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.AbstractAuditDAOImpl;
import org.alfresco.repo.domain.audit.AuditApplicationEntity; import org.alfresco.repo.domain.audit.AuditApplicationEntity;
import org.alfresco.repo.domain.audit.AuditDeleteParameters; 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.audit.AuditQueryResult;
import org.alfresco.repo.domain.propval.PropertyValueDAO.PropertyFinderCallback; import org.alfresco.repo.domain.propval.PropertyValueDAO.PropertyFinderCallback;
import org.alfresco.util.Pair; 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. * 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) protected AuditApplicationEntity createAuditApplication(Long appNameId, Long modelId, Long disabledPathsId)
{ {
AuditApplicationEntity entity = new AuditApplicationEntity(); AuditApplicationEntity entity = new AuditApplicationEntity();
entity.setVersion((short)0); entity.setVersion((short) 0);
entity.setApplicationNameId(appNameId); entity.setApplicationNameId(appNameId);
entity.setAuditModelId(modelId); entity.setAuditModelId(modelId);
entity.setDisabledPathsId(disabledPathsId); entity.setDisabledPathsId(disabledPathsId);
@@ -237,7 +238,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
} }
@Override @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); AuditQueryParameters dbParameters = convertFromRestAuditQueryParameters(parameters);
@@ -254,18 +255,17 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
org.alfresco.service.cmr.audit.AuditQueryParameters restParameters) org.alfresco.service.cmr.audit.AuditQueryParameters restParameters)
{ {
AuditQueryParameters params = convertFromRestAuditQueryParameters(restParameters); AuditQueryParameters params = convertFromRestAuditQueryParameters(restParameters);
if (params==null) 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 // Query without getting the values. We gather all the results and batch-fetch the audited
// values afterwards. // values afterwards.
final Map<Long, AuditQueryResult> resultsByValueId = new HashMap<Long, AuditQueryResult>(173); 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) public void handleProperty(Long id, Serializable value)
{ {
// get the row // get the row
@@ -287,7 +287,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
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
@@ -297,7 +297,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
// 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);
} }
@@ -313,4 +313,3 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl
} }
} }
} }

View File

@@ -44,11 +44,9 @@ public class PropertyStringValueEntity
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 @Override
public int hashCode() public int hashCode()
@@ -79,9 +77,9 @@ public class PropertyStringValueEntity
{ {
StringBuilder sb = new StringBuilder(512); StringBuilder sb = new StringBuilder(512);
sb.append("PropertyStringValueEntity") sb.append("PropertyStringValueEntity")
.append("[ ID=").append(id) .append("[ ID=").append(id)
.append(", stringValue=").append(stringValue) .append(", stringValue=").append(stringValue)
.append("]"); .append("]");
return sb.toString(); return sb.toString();
} }
@@ -116,9 +114,7 @@ public class PropertyStringValueEntity
Pair<String, Long> crcPair = CrcHelper.getStringCrcPair(value, 16, false, true); Pair<String, Long> crcPair = CrcHelper.getStringCrcPair(value, 16, false, true);
stringEndLower = crcPair.getFirst(); stringEndLower = crcPair.getFirst();
stringCrc = crcPair.getSecond(); 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() public Long getId()
@@ -160,14 +156,4 @@ public class PropertyStringValueEntity
{ {
this.stringCrc = stringCrc; 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 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
*/ */
@@ -47,7 +47,8 @@ public interface AuditService
/** /**
* 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
*/ */
@@ -64,6 +65,7 @@ public interface AuditService
private final String name; private final String name;
private final String key; private final String key;
private final boolean enabled; private final boolean enabled;
/** /**
* Constructor for final variables * Constructor for final variables
*/ */
@@ -73,14 +75,17 @@ public interface AuditService
this.key = key; this.key = key;
this.enabled = enabled; this.enabled = enabled;
} }
public String getName() public String getName()
{ {
return name; return name;
} }
public String getKey() public String getKey()
{ {
return key; return key;
} }
public boolean isEnabled() public boolean isEnabled()
{ {
return enabled; return enabled;
@@ -90,16 +95,18 @@ public interface AuditService
/** /**
* Get all registered audit applications * 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 * @since 3.4
*/ */
Map<String, AuditApplication> getAuditApplications(); Map<String, AuditApplication> getAuditApplications();
/** /**
* @param applicationName the name of the application to check * @param applicationName
* @param path the path to check * the name of the application to check
* @return Returns <tt>true</tt> if auditing is enabled for the given path * @param path
* the path to check
* @return Returns <tt>true</tt> if auditing is enabled for the given path
* *
* @since 3.2 * @since 3.2
*/ */
@@ -108,8 +115,10 @@ public interface AuditService
/** /**
* Enable auditing for an application path * Enable auditing for an application path
* *
* @param applicationName the name of the application to check * @param applicationName
* @param path the path to enable * the name of the application to check
* @param path
* the path to enable
* *
* @since 3.2 * @since 3.2
*/ */
@@ -118,8 +127,10 @@ public interface AuditService
/** /**
* Disable auditing for an application path * Disable auditing for an application path
* *
* @param applicationName the name of the application to check * @param applicationName
* @param path the path to disable * the name of the application to check
* @param path
* the path to disable
* *
* @since 3.2 * @since 3.2
*/ */
@@ -128,24 +139,26 @@ public interface AuditService
/** /**
* Remove all audit entries for the given application * Remove all audit entries for the given application
* *
* @param applicationName the name of the application for which to remove entries * @param applicationName
* @return Returns the number of audit entries deleted * the name of the application for which to remove entries
* @return Returns the number of audit entries deleted
* *
* @since 3.2 * @since 3.2
* *
* @deprecated Use {@link #clearAudit(String, Long, Long)} * @deprecated Use {@link #clearAudit(String, Long, Long)}
*/ */
int clearAudit(String applicationName); int clearAudit(String applicationName);
/** /**
* Remove audit entries for the given application between the time ranges. If no start * 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.
* 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 applicationName
* @param fromTime the start time of entries to remove (inclusive and optional) * the name of the application for which to remove entries
* @param toTime the end time of entries to remove (exclusive and optional) * @param fromTime
* @return Returns the number of audit entries deleted * 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 * @since 3.4
*/ */
@@ -154,10 +167,13 @@ public interface AuditService
/** /**
* Remove audit entries for the given application between the audit entry ids. * 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
* @param fromId the start time of entries to remove (inclusive and optional) * the name of the application for which to remove entries
* @param toId the end time of entries to remove (exclusive and optional) * @param fromId
* @return Returns the number of audit entries deleted * 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 * @since 5.2.2
*/ */
@@ -166,11 +182,11 @@ public interface AuditService
/** /**
* Delete a discrete list of audit entries. * Delete a discrete list of audit entries.
* <p/> * <p/>
* This method should not be called <i>while</i> processing * This method should not be called <i>while</i> processing {@link #auditQuery(AuditQueryCallback, AuditQueryParameters, int) query results}.
* {@link #auditQuery(AuditQueryCallback, AuditQueryParameters, int) query results}.
* *
* @param auditEntryIds the IDs of all audit entries to delete * @param auditEntryIds
* @return Returns the number of audit entries deleted * the IDs of all audit entries to delete
* @return Returns the number of audit entries deleted
* *
* @since 3.4 * @since 3.4
*/ */
@@ -184,8 +200,7 @@ public interface AuditService
public static interface AuditQueryCallback public static interface AuditQueryCallback
{ {
/** /**
* Determines whether this callback requires the values argument to be populated when {@link #handleAuditEntry} * Determines whether this callback requires the values argument to be populated when {@link #handleAuditEntry} is called.
* is called.
* *
* @return <code>true</code> if this callback requires the values argument to be populated * @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. * Handle a row of audit entry data.
* *
* @param entryId the unique audit entry ID * @param entryId
* @param applicationName the name of the application * the unique audit entry ID
* @param user the user that logged the entry * @param applicationName
* @param time the time of the entry * the name of the application
* @param values the values map as created * @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
* 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( boolean handleAuditEntry(
Long entryId, Long entryId,
@@ -211,23 +231,29 @@ public interface AuditService
/** /**
* Handle audit entry failures * Handle audit entry failures
* *
* @param entryId the entry ID * @param entryId
* @param errorMsg the error message * the entry ID
* @param error the exception causing the error (may be <tt>null</tt>) * @param errorMsg
* @return Return <tt>true</tt> to continue processing rows or <tt>false</tt> to stop * 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); boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error);
} }
/** /**
* Issue an audit query using the given parameters and consuming results in the callback. * Issue an audit query using the given parameters and consuming results in the callback. Results are returned in entry order, corresponding to time order.
* Results are returned in entry order, corresponding to time order.
* *
* @param callback the callback that will handle results * @param callback
* @param parameters the parameters for the query (may not be <tt>null</tt>) * the callback that will handle results
* @param maxResults the maximum number of results to retrieve (must be greater than 0) * @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 * @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. * Issue an audit query to retrieve min / max audit record id for a given application.
* *
* @param applicationName the name of the application * @param applicationName
* @param extremes a list containing min/max or both * the name of the application
* @return a map containing min/max and the associated value * @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); 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 min / max audit record id for a given application.
* *
* @param applicationName the name of the application * @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
*/ */
default int getAuditEntriesCountByApp(String applicationName) 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 * 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 * @param applicationName
* @return a map containing min/max and the associated value * 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; return -1;
} }
} }