From 21e37b9ed61cff0cdbb11d15ad15d59b41777f34 Mon Sep 17 00:00:00 2001 From: Sathish Kumar Date: Thu, 12 Dec 2024 09:29:10 +0530 Subject: [PATCH] fix for apps-3129 --- ...Mv33HoldAuditEntryValuesPatchUnitTest.java | 9 +- .../org/alfresco/rest/api/impl/AuditImpl.java | 51 ++-- .../alfresco/repo/audit/AuditComponent.java | 212 +++++++++-------- .../repo/audit/AuditComponentImpl.java | 220 ++++++++++-------- .../alfresco/repo/audit/AuditServiceImpl.java | 17 +- .../org/alfresco/repo/domain/CrcHelper.java | 35 ++- .../alfresco/repo/domain/audit/AuditDAO.java | 161 +++++++------ .../domain/audit/ibatis/AuditDAOImpl.java | 42 ++-- .../propval/PropertyStringValueEntity.java | 28 +-- .../service/cmr/audit/AuditService.java | 164 +++++++------ 10 files changed, 511 insertions(+), 428 deletions(-) diff --git a/amps/ags/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java b/amps/ags/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java index af065295e4..0c9ff5980c 100644 --- a/amps/ags/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java +++ b/amps/ags/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v33/RMv33HoldAuditEntryValuesPatchUnitTest.java @@ -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() { @@ -89,6 +89,7 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(addToHoldPropertyStringValueEntity); verify(mockedRecordsManagementQueryDAO, times(1)).getPropertyStringValueEntity("removeFromHold"); verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(removeFromHoldPropertyStringValueEntity); + verify(mockedRecordsManagementQueryDAO, times(1)).getPropertyStringValueEntity("deleteHold"); verify(mockedRecordsManagementQueryDAO, times(1)).updatePropertyStringValueEntity(deleteHoldPropertyStringValueEntity); @@ -122,4 +123,4 @@ public class RMv33HoldAuditEntryValuesPatchUnitTest verify(mockedRecordsManagementQueryDAO, times(1)).getPropertyStringValueEntity("deleteHold"); verify(mockedRecordsManagementQueryDAO, times(0)).updatePropertyStringValueEntity(any()); } -} \ No newline at end of file +} diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java index c7c895b539..81149b8efc 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/AuditImpl.java @@ -85,7 +85,7 @@ public class AuditImpl implements Audit // list of equals filter's auditEntry (via where clause) private final static Set 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 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 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))); @@ -532,7 +537,7 @@ public class AuditImpl implements Audit params.setApplicationName(auditApplication.getName()); params.setFromId(auditEntryId); params.setToId(auditEntryId + 1); - + List includeParam = new ArrayList<>(); if (parameters != null) { @@ -545,8 +550,7 @@ public class AuditImpl implements Audit final List 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 listAuditEntriesByNodeId(String nodeId, Parameters parameters) { - AuthenticationUtil.runAs(new RunAsWork() - { + AuthenticationUtil.runAs(new RunAsWork() { public Void doWork() throws Exception { checkEnabled(); @@ -772,8 +775,7 @@ public class AuditImpl implements Audit final List results = new ArrayList<>(); String auditAppId = "alfresco-access"; - String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork() - { + String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork() { 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() - { + AuthenticationUtil.runAs(new RunAsWork() { 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 @@ -916,8 +916,9 @@ public class AuditImpl implements Audit parameters.setToTime(propertyWalker.getToTime()); parameters.setFromId(propertyWalker.getFromId()); parameters.setToId(propertyWalker.getToId()); + parameters.setUser(propertyWalker.getCreatedByUser()); return auditService.getAuditEntriesCountByAppAndProperties(applicationName, parameters); } -} \ No newline at end of file +} diff --git a/repository/src/main/java/org/alfresco/repo/audit/AuditComponent.java b/repository/src/main/java/org/alfresco/repo/audit/AuditComponent.java index 3193ea7e90..0279ff2845 100644 --- a/repository/src/main/java/org/alfresco/repo/audit/AuditComponent.java +++ b/repository/src/main/java/org/alfresco/repo/audit/AuditComponent.java @@ -46,73 +46,70 @@ public interface AuditComponent /** * Determines whether audit is globally enabled or disabled. * - * @return Returns true if audit is enabled + * @return Returns true if audit is enabled * * @since 3.3 */ public boolean isAuditEnabled(); - + /** * Switch auditing on or off * - * @param enable true to enable auditing or false to disable + * @param enable + * true to enable auditing or false to disable * * @since 3.4 */ public void setAuditEnabled(boolean enable); /** - * @param userAuditFilter UserAuditFilter + * @param userAuditFilter + * UserAuditFilter * * @since 4.2 */ public void setUserAuditFilter(UserAuditFilter userAuditFilter); - + /** * Get all registered audit applications, whether active or not. * - * @return Returns a map of registered audit applications keyed by name + * @return Returns a map of registered audit applications keyed by name * * @since 3.4 */ public Map 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 false are: auditing is disabled; no audit applications - * have been registered. Sometimes, depending on the log level, this method may always - * return true. + * 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 false are: auditing is disabled; no audit applications have been registered. Sometimes, depending on the log level, this method may always return true. * * - * @return Returns true if the calling code (data producers) - * should go ahead and generate the data for - * {@link #recordAuditValues(String, Map) recording}. + * @return Returns true 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 true if there is at least one audit application - * registered to handle the given path. + * @param path + * the audit path + * @return Returns true if there is at least one audit application registered to handle the given path. * - * @since 3.4 + * @since 3.4 */ public boolean areAuditValuesRequired(String path); - + /** * 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,121 +133,111 @@ 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 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 null to assume the - * application's root path - * @return Returns true 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 null to assume the application's root path + * @return Returns true 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. *

- * If the enabled + * If the enabled * - * @param applicationName the name of the application being logged to - * @param path the audit path to check or null 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 null 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. *

- * If the path is /x/y then any data paths that start with /x/y will be stripped - * out before 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 /x/y then any data paths that start with /x/y will be stripped out before 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 null 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 null 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. *

- * 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). *

- * 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. *

- * 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 null) - * @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 null) + * @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 */ Map recordAuditValues(String rootPath, Map values); - + /** * 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 null) - * @param useUserFilter if false 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 null) + * @param useUserFilter + * if false 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 recordAuditValuesWithUserFilter(String rootPath, Map 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 null) - * @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 null) + * @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 getAuditMinMaxByApp(String applicationName, List 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,12 +269,15 @@ public interface AuditComponent /** * Issue an audit query to retrieve count of records for a given application and properties * - * @param applicationName the name of the application - * @param parameters audit parameters provided by the where 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 where clause on the ReST API + * @return a map containing min/max and the associated value */ default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) { return -1; + } -} \ No newline at end of file +} diff --git a/repository/src/main/java/org/alfresco/repo/audit/AuditComponentImpl.java b/repository/src/main/java/org/alfresco/repo/audit/AuditComponentImpl.java index 784d96679e..9866081902 100644 --- a/repository/src/main/java/org/alfresco/repo/audit/AuditComponentImpl.java +++ b/repository/src/main/java/org/alfresco/repo/audit/AuditComponentImpl.java @@ -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. @@ -71,7 +72,7 @@ import org.springframework.extensions.surf.util.ParameterCheck; public class AuditComponentImpl implements AuditComponent { private static final String INBOUND_LOGGER = "org.alfresco.repo.audit.inbound"; - + private static Log logger = LogFactory.getLog(AuditComponentImpl.class); private static Log loggerInbound = LogFactory.getLog(INBOUND_LOGGER); @@ -81,16 +82,16 @@ public class AuditComponentImpl implements AuditComponent private TransactionService transactionService; private AuditFilter auditFilter; private UserAuditFilter userAuditFilter; - + /** * Default constructor */ public AuditComponentImpl() - { - } - + {} + /** * Set the registry holding the audit models + * * @since 3.2 */ public void setAuditModelRegistry(AuditModelRegistryImpl auditModelRegistry) @@ -100,15 +101,17 @@ public class AuditComponentImpl implements AuditComponent /** * Set the DAO for manipulating property values + * * @since 3.2 */ public void setPropertyValueDAO(PropertyValueDAO propertyValueDAO) { this.propertyValueDAO = propertyValueDAO; } - + /** * Set the DAO for accessing audit data + * * @since 3.2 */ public void setAuditDAO(AuditDAO auditDAO) @@ -123,7 +126,7 @@ public class AuditComponentImpl implements AuditComponent { this.transactionService = transactionService; } - + /** * Set the component used to filter which audit events to record */ @@ -139,6 +142,7 @@ public class AuditComponentImpl implements AuditComponent /** * {@inheritDoc} + * * @since 3.2 */ public int deleteAuditEntries(String applicationName, Long fromTime, Long toTime) @@ -154,14 +158,15 @@ public class AuditComponentImpl implements AuditComponent if (logger.isDebugEnabled()) { logger.debug( - "Delete audit " + deleted + " entries for " + applicationName + - " (" + fromTime + " to " + toTime); + "Delete audit " + deleted + " entries for " + applicationName + + " (" + 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 getDisabledPaths(AuditApplication application) @@ -239,15 +246,17 @@ public class AuditComponentImpl implements AuditComponent /** * {@inheritDoc} + * * @since 3.2 */ public boolean isAuditEnabled() { - return auditModelRegistry.isAuditEnabled(); + return auditModelRegistry.isAuditEnabled(); } /** * {@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 getAuditApplications() @@ -277,8 +287,7 @@ public class AuditComponentImpl implements AuditComponent /** * {@inheritDoc} *

- * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then true - * will always be returned. + * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then true will always be returned. * * @since 3.2 */ @@ -291,8 +300,7 @@ public class AuditComponentImpl implements AuditComponent /** * {@inheritDoc} *

- * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then true - * will always be returned. + * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then true will always be returned. * * @since 3.4 */ @@ -306,13 +314,14 @@ public class AuditComponentImpl implements AuditComponent /** * {@inheritDoc} + * * @since 3.2 */ public boolean isAuditPathEnabled(String applicationName, String path) { ParameterCheck.mandatory("applicationName", applicationName); AlfrescoTransactionSupport.checkTransactionReadState(false); - + AuditApplication application = auditModelRegistry.getAuditApplicationByName(applicationName); if (application == null) { @@ -334,9 +343,10 @@ public class AuditComponentImpl implements AuditComponent } Set 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,22 +360,23 @@ 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) { ParameterCheck.mandatory("applicationName", applicationName); AlfrescoTransactionSupport.checkTransactionReadState(true); - + AuditApplication application = auditModelRegistry.getAuditApplicationByName(applicationName); if (application == null) { @@ -388,7 +399,7 @@ public class AuditComponentImpl implements AuditComponent Long disabledPathsId = application.getDisabledPathsId(); Set disabledPaths = getDisabledPaths(application); - + // Remove any paths that start with the given path boolean changed = false; Iterator iterateDisabledPaths = disabledPaths.iterator(); @@ -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,13 +429,14 @@ public class AuditComponentImpl implements AuditComponent /** * {@inheritDoc} + * * @since 3.2 */ public void disableAudit(String applicationName, String path) { ParameterCheck.mandatory("applicationName", applicationName); AlfrescoTransactionSupport.checkTransactionReadState(true); - + AuditApplication application = auditModelRegistry.getAuditApplicationByName(applicationName); if (application == null) { @@ -444,10 +456,10 @@ public class AuditComponentImpl implements AuditComponent // Check the path against the application application.checkPath(path); } - + Long disabledPathsId = application.getDisabledPathsId(); Set disabledPaths = getDisabledPaths(application); - + // Shortcut if the disabled paths contain the exact path if (disabledPaths.contains(path)) { @@ -455,11 +467,11 @@ public class AuditComponentImpl implements AuditComponent { logger.debug( "Audit disable path already present: \n" + - " Path: " + path); + " Path: " + path); } return; } - + // Bring the set up to date by stripping out unwanted paths Iterator iterateDisabledPaths = disabledPaths.iterator(); while (iterateDisabledPaths.hasNext()) @@ -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,20 +504,21 @@ 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) { ParameterCheck.mandatory("applicationName", applicationName); AlfrescoTransactionSupport.checkTransactionReadState(true); - + AuditApplication application = auditModelRegistry.getAuditApplicationByName(applicationName); if (application == null) { @@ -535,20 +548,20 @@ public class AuditComponentImpl implements AuditComponent { ParameterCheck.mandatory("rootPath", rootPath); AuditApplication.checkPathFormat(rootPath); - + String username = AuthenticationUtil.getFullyAuthenticatedUser(); if (values == null || values.isEmpty() || !areAuditValuesRequired() || !(userAuditFilter.acceptUser(username) || !useUserFilter) || !auditFilter.accept(rootPath, values)) { return Collections.emptyMap(); } - + // 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 entry : values.entrySet()) { String pathElement = entry.getKey(); @@ -567,7 +580,7 @@ public class AuditComponentImpl implements AuditComponent String path = AuditApplication.buildPath(rootPath, pathElement); pathedValues.put(path, entry.getValue()); } - + // Translate the values map PathMapper pathMapper = auditModelRegistry.getAuditPathMapper(); final Map mappedValues = pathMapper.convertMap(pathedValues); @@ -575,17 +588,15 @@ 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> callback = - new RetryingTransactionCallback>() - { + RetryingTransactionCallback> callback = new RetryingTransactionCallback>() { public Map execute() throws Throwable { return recordAuditValuesImpl(mappedValues); @@ -600,14 +611,14 @@ public class AuditComponentImpl implements AuditComponent throw new IllegalStateException("Unknown txn state: " + txnState); } } - + /** * @since 3.2 */ public Map recordAuditValuesImpl(Map mappedValues) { // Group the values by root path - Map> mappedValuesByRootKey = new HashMap>(); + Map> mappedValuesByRootKey = new HashMap>(); for (Map.Entry entry : mappedValues.entrySet()) { String path = entry.getKey(); @@ -621,7 +632,7 @@ public class AuditComponentImpl implements AuditComponent rootKeyMappedValues.put(path, entry.getValue()); } - Map allAuditedValues = new HashMap(mappedValues.size()*2+1); + Map allAuditedValues = new HashMap(mappedValues.size() * 2 + 1); // Now audit for each of the root keys for (Map.Entry> 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 full paths. - * @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 full paths. + * @return Returns all values as audited */ private Map 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 generatorKeys = values.keySet(); // Eliminate any paths that have been disabled Iterator generatorKeysIterator = generatorKeys.iterator(); - while(generatorKeysIterator.hasNext()) + while (generatorKeysIterator.hasNext()) { String generatorKey = generatorKeysIterator.next(); for (String disabledPath : disabledPaths) @@ -707,14 +721,13 @@ public class AuditComponentImpl implements AuditComponent } } } - + // Generate data Map generators = application.getDataGenerators(generatorKeys); Map auditData = generateData(generators); // Now extract values - Map extractedData = AuthenticationUtil.runAs(new RunAsWork>() - { + Map extractedData = AuthenticationUtil.runAs(new RunAsWork>() { public Map doWork() throws Exception { return extractData(application, values); @@ -741,7 +754,7 @@ public class AuditComponentImpl implements AuditComponent // Time and username are intrinsic long time = System.currentTimeMillis(); String username = AuthenticationUtil.getFullyAuthenticatedUser(); - + Long entryId = null; if (!auditData.isEmpty()) { @@ -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 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 entry : values.entrySet()) { sb.append("\t\t").append(entry).append("\n"); @@ -790,16 +803,18 @@ public class AuditComponentImpl implements AuditComponent logger.debug(sb.toString()); } } - + return auditData; } - + /** * 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 */ @@ -808,7 +823,7 @@ public class AuditComponentImpl implements AuditComponent Map values) { Map newData = new HashMap(values.size()); - + List extractors = application.getDataExtractors(); for (DataExtractorDefinition extractorDef : extractors) { @@ -816,21 +831,21 @@ public class AuditComponentImpl implements AuditComponent String triggerPath = extractorDef.getDataTrigger(); String sourcePath = extractorDef.getDataSource(); String targetPath = extractorDef.getDataTarget(); - + // 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); - + // Check if the extraction is supported if (!extractor.isSupported(value)) { @@ -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 entry : values.entrySet()) { sb.append("\t\t").append(entry).append("\n"); @@ -875,10 +890,11 @@ public class AuditComponentImpl implements AuditComponent } return newData; } - + /** - * @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 @@ -916,13 +932,13 @@ public class AuditComponentImpl implements AuditComponent { ParameterCheck.mandatory("callback", callback); ParameterCheck.mandatory("parameters", parameters); - + // Shortcuts if (parameters.isZeroResultQuery()) { return; } - + auditDAO.findAuditEntries(callback, parameters, maxResults); } @@ -956,8 +972,10 @@ public class AuditComponentImpl implements AuditComponent return auditDAO.getAuditEntriesCountByApp(applicationId); } - @Override public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) + @Override + public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) { return auditDAO.getAuditEntriesCountByAppAndProperties(applicationName, parameters); + } -} \ No newline at end of file +} diff --git a/repository/src/main/java/org/alfresco/repo/audit/AuditServiceImpl.java b/repository/src/main/java/org/alfresco/repo/audit/AuditServiceImpl.java index 0e38a64b36..7c35819456 100644 --- a/repository/src/main/java/org/alfresco/repo/audit/AuditServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/audit/AuditServiceImpl.java @@ -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(String applicationName, AuditQueryParameters parameters) + @Override + public int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) { return auditComponent.getAuditEntriesCountByAppAndProperties(applicationName, parameters); + } -} \ No newline at end of file +} diff --git a/repository/src/main/java/org/alfresco/repo/domain/CrcHelper.java b/repository/src/main/java/org/alfresco/repo/domain/CrcHelper.java index 07be20c6a7..c26ea6e3fb 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/CrcHelper.java +++ b/repository/src/main/java/org/alfresco/repo/domain/CrcHelper.java @@ -40,29 +40,23 @@ import org.alfresco.util.Pair; 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. *

- * 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. *

- * 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 NULL. + * 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 NULL. * - * @param value the raw value that will be persisted - * @param dataLength the maximum number of characters that can be persisted - * @param useCharsFromStart true if the shortened string value must be made from - * the first characters of the string or false to use - * characters from the end of the string. - * @param caseSensitive true if the resulting pair must be case-sensitive or - * false if the pair must be case-insensitive. - * @return Return the persistable pair. The result will never be null, - * but the individual pair values will be null if the - * value given is null + * @param value + * the raw value that will be persisted + * @param dataLength + * the maximum number of characters that can be persisted + * @param useCharsFromStart + * true if the shortened string value must be made from the first characters of the string or false to use characters from the end of the string. + * @param caseSensitive + * true if the resulting pair must be case-sensitive or false if the pair must be case-insensitive. + * @return Return the persistable pair. The result will never be null, but the individual pair values will be null if the value given is null */ public static Pair getStringCrcPair( String value, @@ -118,5 +112,6 @@ public class CrcHelper valueShort = valueLowerCase.substring(valueLen - dataLength); } return new Pair(valueShort, valueCrc); + } -} \ No newline at end of file +} diff --git a/repository/src/main/java/org/alfresco/repo/domain/audit/AuditDAO.java b/repository/src/main/java/org/alfresco/repo/domain/audit/AuditDAO.java index 45739bbf9a..0ffc67ee43 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/audit/AuditDAO.java +++ b/repository/src/main/java/org/alfresco/repo/domain/audit/AuditDAO.java @@ -39,17 +39,14 @@ import org.alfresco.util.Pair; /** * DAO services for alf_audit_XXX tables. *

- * 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. @@ -63,113 +60,128 @@ public interface AuditDAO private String name; private Long modelId; private Long disabledPathsId; - + @Override public String toString() { 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(); } - + public Long getId() { 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; } } - + /** * 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 getOrCreateAuditModel(URL url); - + /** * Get the audit application details. * - * @param applicationName the name of the application - * @return Returns details of an existing application or null if it doesn't exist + * @param applicationName + * the name of the application + * @return Returns details of an existing application or null 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 */ void updateAuditApplicationDisabledPaths(Long id, Set disabledPaths); - + /** * 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,47 +190,56 @@ 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 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 (null 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 (null if not present) + * @param values + * the values to record + * @return Returns the unique entry ID * * @since 3.2 */ Long createAuditEntry(Long applicationId, long time, String username, Map values); - + /** * 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 null) - * @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 null) + * @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 getAuditMinMaxByApp(long appId, List 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,12 +272,15 @@ public interface AuditDAO /** * Issue an audit query to retrieve count of records for a given application and properties * - * @param applicationName name of the application to be queried - * @param parameters audit parameters provided by the where 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 where clause on the ReST API + * @return a map containing min/max and the associated value */ default int getAuditEntriesCountByAppAndProperties(String applicationName, org.alfresco.service.cmr.audit.AuditQueryParameters parameters) { return -1; + } -} \ No newline at end of file +} diff --git a/repository/src/main/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java b/repository/src/main/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java index c1d3bdc700..abcce46aeb 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java @@ -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 alf_audit_XXX tables. @@ -55,27 +56,27 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl { private static final String SELECT_MODEL_BY_CRC = "alfresco.audit.select_AuditModelByCrc"; private static final String INSERT_MODEL = "alfresco.audit.insert.insert_AuditModel"; - + private static final String SELECT_APPLICATION_BY_ID = "alfresco.audit.select_AuditApplicationById"; private static final String SELECT_APPLICATION_BY_NAME_ID = "alfresco.audit.select_AuditApplicationByNameId"; private static final String INSERT_APPLICATION = "alfresco.audit.insert.insert_AuditApplication"; private static final String UPDATE_APPLICATION = "alfresco.audit.update_AuditApplication"; - + private static final String DELETE_ENTRIES = "alfresco.audit.delete_AuditEntries"; private static final String DELETE_ENTRIES_BY_ID = "alfresco.audit.delete_AuditEntriesById"; private static final String INSERT_ENTRY = "alfresco.audit.insert.insert_AuditEntry"; private static final String SELECT_MINMAX_ENTRY_FOR_APP = "alfresco.audit.select_MinMaxAuditEntryId"; private static final String SELECT_COUNT_ENTRIES_FOR_APP = "alfresco.audit.select_CountAuditEntryId"; private static final String SELECT_COUNT_ENTRIES_FOR_APP_WITH_PROPERTIES = "select_CountAuditEntryIdWithWhereClause"; - + @SuppressWarnings("unused") private static final String SELECT_ENTRIES_SIMPLE = "alfresco.audit.select_AuditEntriesSimple"; private static final String SELECT_ENTRIES_WITH_VALUES = "alfresco.audit.select_AuditEntriesWithValues"; private static final String SELECT_ENTRIES_WITHOUT_VALUES = "alfresco.audit.select_AuditEntriesWithoutValues"; - + private SqlSessionTemplate template; - - public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) + + public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { this.template = sqlSessionTemplate; } @@ -128,7 +129,7 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl // There will be no results return null; } - + Map params = new HashMap(11); params.put("id", appNamePair.getFirst()); AuditApplicationEntity entity = template.selectOne( @@ -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); @@ -164,14 +165,14 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl updateEntity.setApplicationNameId(entity.getApplicationNameId()); updateEntity.setAuditModelId(entity.getAuditModelId()); updateEntity.setDisabledPathsId(entity.getDisabledPathsId()); - + int updated = template.update(UPDATE_APPLICATION, updateEntity); if (updated != 1) { // unexpected number of rows affected throw new ConcurrencyFailureException("Incorrect number of rows affected for updateAuditApplication: " + updateEntity + ": expected 1, actual " + updated); } - + // Done return updateEntity; } @@ -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 resultsByValueId = new HashMap(173); - PropertyFinderCallback propertyFinderCallback = new PropertyFinderCallback() - { + PropertyFinderCallback propertyFinderCallback = new PropertyFinderCallback() { public void handleProperty(Long id, Serializable value) { // get the row @@ -280,14 +280,14 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl } } }; - + List rows = template.selectList(SELECT_ENTRIES_WITHOUT_VALUES, params, new RowBounds(0, maxResults)); for (AuditQueryResult row : rows) { 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 valueIds = new ArrayList(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 valueIds = new ArrayList(resultsByValueId.keySet()); propertyValueDAO.getPropertiesByIds(valueIds, propertyFinderCallback); } @@ -312,4 +312,4 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl throw new IllegalArgumentException("maxResults must be greater than 0"); } } -} \ No newline at end of file +} diff --git a/repository/src/main/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java b/repository/src/main/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java index 6b405d1b6e..8b07cd465d 100644 --- a/repository/src/main/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java +++ b/repository/src/main/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java @@ -39,22 +39,21 @@ public class PropertyStringValueEntity { public static final String EMPTY_STRING = ""; public static final String EMPTY_STRING_REPLACEMENT = ".empty"; - + private Long id; private String stringValue; private String stringEndLower; private Long stringCrc; - + public PropertyStringValueEntity() - { - } - + {} + @Override public int hashCode() { return (stringValue == null ? 0 : stringValue.hashCode()); } - + @Override public boolean equals(Object obj) { @@ -72,18 +71,18 @@ public class PropertyStringValueEntity return false; } } - + @Override public String toString() { 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(); } - + public Pair getEntityPair() { if (stringValue != null && stringValue.equals(PropertyStringValueEntity.EMPTY_STRING_REPLACEMENT)) @@ -95,7 +94,7 @@ public class PropertyStringValueEntity return new Pair(id, stringValue); } } - + /** * Set the string and string-end values */ @@ -136,7 +135,7 @@ public class PropertyStringValueEntity { this.stringValue = stringValue; } - + public String getStringEndLower() { return stringEndLower; @@ -156,4 +155,5 @@ public class PropertyStringValueEntity { this.stringCrc = stringCrc; } -} \ No newline at end of file + +} diff --git a/repository/src/main/java/org/alfresco/service/cmr/audit/AuditService.java b/repository/src/main/java/org/alfresco/service/cmr/audit/AuditService.java index a67bca619e..79439ae284 100644 --- a/repository/src/main/java/org/alfresco/service/cmr/audit/AuditService.java +++ b/repository/src/main/java/org/alfresco/service/cmr/audit/AuditService.java @@ -38,16 +38,17 @@ import java.util.Map; public interface AuditService { /** - * @return Returns true if auditing is globally enabled + * @return Returns true if auditing is globally enabled * * @since 3.4 */ boolean isAuditEnabled(); - + /** * Enable or disable the global auditing state * - * @param enable true to enable auditing globally or false to disable + * @param enable + * true to enable auditing globally or false 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,79 +75,90 @@ public interface AuditService this.key = key; this.enabled = enabled; } + public String getName() { return name; } + public String getKey() { return key; } + public boolean isEnabled() { return enabled; } } - + /** * 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 getAuditApplications(); - + /** - * @param applicationName the name of the application to check - * @param path the path to check - * @return Returns true 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 true if auditing is enabled for the given path * * @since 3.2 */ boolean isAuditEnabled(String applicationName, String path); - + /** * 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 */ void enableAudit(String applicationName, String path); - + /** * 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 */ void disableAudit(String applicationName, String path); - + /** * 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,16 +182,16 @@ public interface AuditService /** * Delete a discrete list of audit entries. *

- * This method should not be called while processing - * {@link #auditQuery(AuditQueryCallback, AuditQueryParameters, int) query results}. + * This method should not be called while 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 */ int clearAudit(List auditEntryIds); - + /** * The interface that will be used to give query results to the calling code. * @@ -184,22 +200,26 @@ 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 true if this callback requires the values argument to be populated */ boolean valuesRequired(); - + /** * 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 true to continue processing rows or false 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 true to continue processing rows or false to stop */ boolean handleAuditEntry( Long entryId, @@ -207,27 +227,33 @@ public interface AuditService String user, long time, Map values); - + /** * Handle audit entry failures * - * @param entryId the entry ID - * @param errorMsg the error message - * @param error the exception causing the error (may be null) - * @return Return true to continue processing rows or false to stop + * @param entryId + * the entry ID + * @param errorMsg + * the error message + * @param error + * the exception causing the error (may be null) + * @return Return true to continue processing rows or false 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 null) - * @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 null) + * @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 getAuditMinMaxByApp(String applicationName, List 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,12 +285,15 @@ public interface AuditService /** * Issue an audit query to retrieve min / max audit record id for a given application and properties * - * @param applicationName the name of the application - * @param parameters audit parameters provided by the where 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 where clause on the ReST API + * @return a map containing min/max and the associated value */ default int getAuditEntriesCountByAppAndProperties(String applicationName, AuditQueryParameters parameters) { return -1; + } -} \ No newline at end of file +}