diff --git a/source/java/org/alfresco/repo/audit/AuditBootstrapTest.java b/source/java/org/alfresco/repo/audit/AuditBootstrapTest.java index a370df60d1..4bf59b33c9 100644 --- a/source/java/org/alfresco/repo/audit/AuditBootstrapTest.java +++ b/source/java/org/alfresco/repo/audit/AuditBootstrapTest.java @@ -130,6 +130,12 @@ public class AuditBootstrapTest extends TestCase assertNotNull("No audit application ID for " + APPLICATION_TEST, appId); } + public void testGetApplications() + { + Map apps = auditModelRegistry.getAuditApplications(); + assertTrue("Application map not complete", apps.containsKey(APPLICATION_TEST)); + } + public void testGetApplicationByKey() { AuditApplication app = auditModelRegistry.getAuditApplicationByKey(KEY_TEST); diff --git a/source/java/org/alfresco/repo/audit/AuditComponent.java b/source/java/org/alfresco/repo/audit/AuditComponent.java index 631dc07249..4692c1aa31 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponent.java +++ b/source/java/org/alfresco/repo/audit/AuditComponent.java @@ -20,6 +20,7 @@ package org.alfresco.repo.audit; import java.io.Serializable; import java.util.Map; +import java.util.Set; import org.alfresco.repo.audit.model.AuditApplication; import org.alfresco.repo.audit.model.AuditModelRegistry; @@ -29,19 +30,26 @@ import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback; /** * The audit component. Used by the AuditService and AuditMethodInterceptor to insert audit entries. - *

- * The V3.2 audit functionality is contained within the same component. When the newer audit - * implementation has been tested and approved, then older ones will be deprecated as necessary. * - * @author Andy Hind * @author Derek Hulley */ public interface AuditComponent { + /** + * Get all registered audit applications, whether active or not. + * + * @return Returns a set of registered audit applications + * + * @since 3.4 + */ + public Set getAuditApplications(); + /** * Determines whether audit is globally enabled or disabled. * - * @return true, if audit is enabled + * @return Returns true if audit is enabled + * + * @since 3.3 */ public boolean isAuditEnabled(); @@ -49,7 +57,9 @@ public interface AuditComponent * Determines whether the given source path is mapped to any audit applications. Allows optimizations to be made in * calling components. * - * @return true if the given source path is mapped to one or more audit applications + * @return Returns true if the given source path is mapped to one or more + * audit applications + * * @since 3.3 */ public boolean isSourcePathMapped(String sourcePath); @@ -114,7 +124,7 @@ public interface AuditComponent * 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) disabling}. + * {@link #disableAudit(String, String) disabled}. * * @param applicationName the name of the application * @@ -125,7 +135,7 @@ public interface AuditComponent /** * 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 @@ -145,7 +155,7 @@ public interface AuditComponent * @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 there is not a writable transaction present + * @throws IllegalStateException if the transaction state could not be determined * * @since 3.2 */ diff --git a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java index ee4155a724..e981b43adb 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java +++ b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java @@ -157,6 +157,16 @@ public class AuditComponentImpl implements AuditComponent } } + /** + * {@inheritDoc} + * @since 3.4 + */ + public Set getAuditApplications() + { + Map auditApps = auditModelRegistry.getAuditApplications(); + return auditApps.keySet(); + } + /** * {@inheritDoc} * @since 3.2 @@ -199,7 +209,7 @@ public class AuditComponentImpl implements AuditComponent Set disabledPaths = getDisabledPaths(application); - // Check if there are any entries that match or superced the given path + // Check if there are any entries that match or supercede the given path String disablingPath = null;; for (String disabledPath : disabledPaths) { diff --git a/source/java/org/alfresco/repo/audit/AuditServiceImpl.java b/source/java/org/alfresco/repo/audit/AuditServiceImpl.java index 7e0b89acaa..34cf5c091c 100644 --- a/source/java/org/alfresco/repo/audit/AuditServiceImpl.java +++ b/source/java/org/alfresco/repo/audit/AuditServiceImpl.java @@ -18,6 +18,8 @@ */ package org.alfresco.repo.audit; +import java.util.Set; + import org.alfresco.service.cmr.audit.AuditQueryParameters; import org.alfresco.service.cmr.audit.AuditService; @@ -41,6 +43,16 @@ public class AuditServiceImpl implements AuditService this.auditComponent = auditComponent; } + /** + * {@inheritDoc} + * @since 3.4 + */ + @Override + public Set getAuditApplications() + { + return auditComponent.getAuditApplications(); + } + /** * {@inheritDoc} * @since 3.4 diff --git a/source/java/org/alfresco/repo/audit/model/AuditModelRegistry.java b/source/java/org/alfresco/repo/audit/model/AuditModelRegistry.java index 50db6a66ba..5ce04f8164 100644 --- a/source/java/org/alfresco/repo/audit/model/AuditModelRegistry.java +++ b/source/java/org/alfresco/repo/audit/model/AuditModelRegistry.java @@ -18,6 +18,8 @@ */ package org.alfresco.repo.audit.model; +import java.util.Map; + import org.alfresco.util.PathMapper; /** @@ -43,9 +45,18 @@ public interface AuditModelRegistry /** * Determines whether audit is globally enabled or disabled. * - * @return true, if audit is enabled + * @return true if audit is enabled */ public boolean isAuditEnabled(); + + /** + * Get a map of all audit applications key by name + * + * @return the audit applications + * + * @since 3.4 + */ + public Map getAuditApplications(); /** * Get the application model for the given root key (as defined on the application) @@ -65,7 +76,7 @@ public interface AuditModelRegistry /** * Get the path mapper. - * @return the path mapper + * @return the path mapper */ public PathMapper getAuditPathMapper(); } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/audit/model/AuditModelRegistryImpl.java b/source/java/org/alfresco/repo/audit/model/AuditModelRegistryImpl.java index 1d065da004..e0c3dccaca 100644 --- a/source/java/org/alfresco/repo/audit/model/AuditModelRegistryImpl.java +++ b/source/java/org/alfresco/repo/audit/model/AuditModelRegistryImpl.java @@ -90,6 +90,54 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement private NamedObjectRegistry dataGenerators; private final ObjectFactory objectFactory; + /** + * Default constructor. + */ + public AuditModelRegistryImpl() + { + objectFactory = new ObjectFactory(); + } + + /** + * Sets the search path for config files. + */ + public void setSearchPath(String[] searchPath) + { + this.searchPath = searchPath; + } + + /** + * Service to ensure DAO calls are transactionally wrapped. + */ + public void setTransactionService(TransactionService transactionService) + { + this.transactionService = transactionService; + } + + /** + * Set the DAO used to persisted the registered audit models. + */ + public void setAuditDAO(AuditDAO auditDAO) + { + this.auditDAO = auditDAO; + } + + /** + * Set the registry of {@link DataExtractor data extractors}. + */ + public void setDataExtractors(NamedObjectRegistry dataExtractors) + { + this.dataExtractors = dataExtractors; + } + + /** + * Set the registry of {@link DataGenerator data generators}. + */ + public void setDataGenerators(NamedObjectRegistry dataGenerators) + { + this.dataGenerators = dataGenerators; + } + /** * {@inheritDoc} */ @@ -116,6 +164,16 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * {@inheritDoc} */ + @Override + public Map getAuditApplications() + { + return getState(true).getAuditApplications(); + } + + /** + * {@inheritDoc} + */ + @Override public AuditApplication getAuditApplicationByKey(String key) { return getState(true).getAuditApplicationByKey(key); @@ -124,6 +182,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * {@inheritDoc} */ + @Override public AuditApplication getAuditApplicationByName(String applicationName) { return getState(true).getAuditApplicationByName(applicationName); @@ -132,6 +191,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * {@inheritDoc} */ + @Override public PathMapper getAuditPathMapper() { return getState(true).getAuditPathMapper(); @@ -140,6 +200,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * {@inheritDoc} */ + @Override public void loadAuditModels() { stop(); @@ -149,6 +210,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * {@inheritDoc} */ + @Override public boolean isAuditEnabled() { String value = getProperty(PROPERTY_AUDIT_ENABLED); @@ -159,8 +221,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement * Enables audit and registers an audit model at a given URL. Does not register across the cluster and should only * be used for unit test purposes. * - * @param auditModelUrl - * the source of the model + * @param auditModelUrl the source of the model */ public synchronized void registerModel(URL auditModelUrl) { @@ -176,20 +237,15 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement { /** The audit models. */ private final Map auditModels; - /** Used to lookup path translations. */ private PathMapper auditPathMapper; - /** Used to lookup the audit application java hierarchy. */ private Map auditApplicationsByKey; - /** Used to lookup the audit application java hierarchy. */ private Map auditApplicationsByName; - /** The exposed configuration properties. */ private final Map properties; - /** * Instantiates a new audit model registry state. */ @@ -220,8 +276,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * Register an audit model at a given URL. * - * @param auditModelUrl - * the source of the model + * @param auditModelUrl the source of the model */ public void registerModel(URL auditModelUrl) { @@ -250,11 +305,11 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement } /** - * Gets the name of an enablement property. + * Helper method to convert an application key into a enabled-disabled property. * - * @param key - * an application key - * @return the property name + * @param key an application key e.g. for "My App" the key might be "myapp", + * but is defined in the audit model config. + * @return the property name of the for "audit.myapp.enabled" */ private String getEnabledProperty(String key) { @@ -262,11 +317,12 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement } /** - * Checks if an application enabled. + * Checks if an application key is enabled. Each application has a name and a root key + * value. It is the key (which will be used as the root of all logged paths) that is + * used here. * - * @param key - * the application key - * @return true, if the application is enabled + * @param key the application key + * @return true if the application key is enabled */ private boolean isApplicationEnabled(String key) { @@ -311,7 +367,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement Boolean enabled = properties.get(PROPERTY_AUDIT_ENABLED); if (enabled != null && enabled) { - final RetryingTransactionCallback loadModelsCallback = new RetryingTransactionCallback() { public Void execute() throws Throwable @@ -366,13 +421,17 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement auditPathMapper = null; } - + /** + * Gets all audit applications keyed by name. + * @see org.alfresco.repo.audit.model.AuditModelRegistry#getAuditApplications() + */ + public Map getAuditApplications() + { + return auditApplicationsByName; + } + /** * Gets an audit application by key. - * - * @param key - * the application key - * @return the audit application * @see org.alfresco.repo.audit.model.AuditModelRegistry#getAuditApplicationByKey(java.lang.String) */ public AuditApplication getAuditApplicationByKey(String key) @@ -382,10 +441,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * Gets an audit application by name. - * - * @param applicationName - * the application name - * @return the audit application * @see org.alfresco.repo.audit.model.AuditModelRegistry#getAuditApplicationByName(java.lang.String) */ public AuditApplication getAuditApplicationByName(String applicationName) @@ -396,7 +451,7 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * Gets the audit path mapper. * - * @return the audit path mapper + * @return the audit path mapper * @see org.alfresco.repo.audit.model.AuditModelRegistry#getAuditPathMapper() */ public PathMapper getAuditPathMapper() @@ -406,11 +461,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * Caches audit elements from a model. - * - * @param auditModelId - * the audit model id - * @param audit - * the audit model */ private void cacheAuditElements(Long auditModelId, Audit audit) { @@ -576,9 +626,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement /** * Construct the reverse lookup maps for quick conversion of data to target maps. - * - * @param audit - * the audit model */ private void buildAuditPathMap(Audit audit) { @@ -615,55 +662,6 @@ public class AuditModelRegistryImpl extends AbstractPropertyBackedBean implement return new AuditModelRegistryState(); } - /** - * Default constructor. - */ - public AuditModelRegistryImpl() - { - objectFactory = new ObjectFactory(); - } - - - /** - * Sets the search path for config files. - */ - public void setSearchPath(String[] searchPath) - { - this.searchPath = searchPath; - } - - /** - * Service to ensure DAO calls are transactionally wrapped. - */ - public void setTransactionService(TransactionService transactionService) - { - this.transactionService = transactionService; - } - - /** - * Set the DAO used to persisted the registered audit models. - */ - public void setAuditDAO(AuditDAO auditDAO) - { - this.auditDAO = auditDAO; - } - - /** - * Set the registry of {@link DataExtractor data extractors}. - */ - public void setDataExtractors(NamedObjectRegistry dataExtractors) - { - this.dataExtractors = dataExtractors; - } - - /** - * Set the registry of {@link DataGenerator data generators}. - */ - public void setDataGenerators(NamedObjectRegistry dataGenerators) - { - this.dataGenerators = dataGenerators; - } - /** * Unmarshalls the Audit model from the URL. * diff --git a/source/java/org/alfresco/service/cmr/audit/AuditService.java b/source/java/org/alfresco/service/cmr/audit/AuditService.java index 8c4b6165f4..dd30947ce1 100644 --- a/source/java/org/alfresco/service/cmr/audit/AuditService.java +++ b/source/java/org/alfresco/service/cmr/audit/AuditService.java @@ -20,6 +20,7 @@ package org.alfresco.service.cmr.audit; import java.io.Serializable; import java.util.Map; +import java.util.Set; import org.alfresco.service.PublicService; @@ -31,6 +32,15 @@ import org.alfresco.service.PublicService; @PublicService public interface AuditService { + /** + * Get all registered audit applications + * + * @return Returns a set of all available audit applications + * + * @since 3.4 + */ + Set getAuditApplications(); + /** * @return Returns true if auditing is globally enabled *