mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Audit changes and fixes
- Removed notion of audit session - Removed 'scope' attribute for DataGenerator elements - Removed alf_audit_session table and replaced with alf_audit_app (see script) - DataGenerators are working properly git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16053 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,18 +27,15 @@ package org.alfresco.repo.audit.model;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.audit.extractor.DataExtractor;
|
||||
import org.alfresco.repo.audit.generator.DataGenerator;
|
||||
import org.alfresco.repo.audit.generator.DataGenerator.DataGeneratorScope;
|
||||
import org.alfresco.repo.audit.model._3.Application;
|
||||
import org.alfresco.repo.audit.model._3.AuditPath;
|
||||
import org.alfresco.repo.audit.model._3.GenerateValue;
|
||||
import org.alfresco.repo.audit.model._3.RecordValue;
|
||||
import org.alfresco.repo.audit.model._3.ScopeAttribute;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -70,8 +67,6 @@ public class AuditApplication
|
||||
private Map<String, Map<String, DataExtractor>> dataExtractors = new HashMap<String, Map<String, DataExtractor>>(11);
|
||||
/** Derived expaned map for fast lookup */
|
||||
private Map<String, Map<String, DataGenerator>> dataGenerators = new HashMap<String, Map<String, DataGenerator>>(11);
|
||||
/** Derived expaned map for fast lookup */
|
||||
private Map<String, DataGeneratorScope> dataGeneratorScopes = new HashMap<String, DataGeneratorScope>(11);
|
||||
|
||||
/**
|
||||
* @param application the application that will be wrapped
|
||||
@@ -251,43 +246,29 @@ public class AuditApplication
|
||||
* Get all data generators applicable to a given path and scope.
|
||||
*
|
||||
* @param path the audit path
|
||||
* @param scope the audit scope (e.g. SESSION or AUDIT)
|
||||
* @return Returns all data generators mapped to their key-path
|
||||
*/
|
||||
public Map<String, DataGenerator> getDataGenerators(String path, DataGeneratorScope scope)
|
||||
public Map<String, DataGenerator> getDataGenerators(String path)
|
||||
{
|
||||
Map<String, DataGenerator> generators = dataGenerators.get(path);
|
||||
if (generators == null)
|
||||
return getDataGenerators(Collections.singleton(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all data generators applicable to a given path and scope.
|
||||
*
|
||||
* @param paths the audit paths
|
||||
* @return Returns all data generators mapped to their key-path
|
||||
*/
|
||||
public Map<String, DataGenerator> getDataGenerators(Set<String> paths)
|
||||
{
|
||||
Map<String, DataGenerator> amalgamatedGenerators = new HashMap<String, DataGenerator>(13);
|
||||
for (String path : paths)
|
||||
{
|
||||
// Don't give back a null
|
||||
generators = new HashMap<String, DataGenerator>(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy the map so that (a) we can modify it during iteration and (b) we return
|
||||
// something that the client can't mess up.
|
||||
generators = new HashMap<String, DataGenerator>(generators);
|
||||
}
|
||||
|
||||
if (scope != DataGeneratorScope.ALL)
|
||||
{
|
||||
// Go through them and eliminate the ones in the wrong scope
|
||||
Iterator<Map.Entry<String, DataGenerator>> iterator = generators.entrySet().iterator();
|
||||
while (iterator.hasNext())
|
||||
Map<String, DataGenerator> generators = dataGenerators.get(path);
|
||||
if (generators != null)
|
||||
{
|
||||
Map.Entry<String, DataGenerator> entry = iterator.next();
|
||||
String generatorPath = entry.getKey();
|
||||
DataGeneratorScope generatorScope = dataGeneratorScopes.get(generatorPath);
|
||||
if (generatorScope == DataGeneratorScope.ALL)
|
||||
{
|
||||
// This one always applies
|
||||
continue;
|
||||
}
|
||||
else if (generatorScope != scope)
|
||||
{
|
||||
// Wrong scope
|
||||
iterator.remove();
|
||||
}
|
||||
// Copy values to combined map
|
||||
amalgamatedGenerators.putAll(generators);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,11 +277,10 @@ public class AuditApplication
|
||||
{
|
||||
logger.debug(
|
||||
"Looked up data generators: \n" +
|
||||
" Path: " + path + "\n" +
|
||||
" Scope: " + scope + "\n" +
|
||||
" Found: " + generators);
|
||||
" Paths: " + paths + "\n" +
|
||||
" Found: " + amalgamatedGenerators);
|
||||
}
|
||||
return generators;
|
||||
return amalgamatedGenerators;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,11 +345,11 @@ public class AuditApplication
|
||||
}
|
||||
// All the extractors apply to the current path
|
||||
dataExtractors.put(currentPath, upperExtractorsByPath);
|
||||
// // Data extractors only apply directly to data in which they appear.
|
||||
// // TODO: Examine this assumption. If it is not true, i.e. data extractors apply to
|
||||
// // data anywhere down the hierarchy, then the followin line of code should be
|
||||
// // removed and the use-cases tested appropriately.
|
||||
// upperExtractorsByPath.clear();
|
||||
// Data extractors only apply directly to data in which they appear.
|
||||
// TODO: Examine this assumption. If it is not true, i.e. data extractors apply to
|
||||
// data anywhere down the hierarchy, then the followin line of code should be
|
||||
// removed and the use-cases tested appropriately.
|
||||
upperExtractorsByPath = new HashMap<String, DataExtractor>();
|
||||
|
||||
// Get the data generators declared for this key
|
||||
for (GenerateValue element : auditPath.getGenerateValue())
|
||||
@@ -387,26 +367,6 @@ public class AuditApplication
|
||||
{
|
||||
generateException(generatorPath, "No data generator exists for name: " + generatorName);
|
||||
}
|
||||
// Store the scope
|
||||
ScopeAttribute scopeAttribute = element.getScope();
|
||||
if (scopeAttribute == null)
|
||||
{
|
||||
generateException(generatorPath, "No scope defined for generator: " + generatorName);
|
||||
}
|
||||
String scopeStr = scopeAttribute.value();
|
||||
if (scopeStr == null)
|
||||
{
|
||||
scopeStr = DataGeneratorScope.AUDIT.toString();
|
||||
}
|
||||
try
|
||||
{
|
||||
DataGeneratorScope scope = DataGeneratorScope.valueOf(scopeStr);
|
||||
dataGeneratorScopes.put(generatorPath, scope);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
generateException(generatorPath, "Illegal generator scope value: " + scopeStr);
|
||||
}
|
||||
// All generators that occur earlier in the path will also be applicable here
|
||||
upperGeneratorsByPath.put(generatorPath, generator);
|
||||
}
|
||||
|
@@ -96,9 +96,9 @@ public class AuditModelRegistry
|
||||
*/
|
||||
private final Map<String, AuditApplication> auditApplicationsByName;
|
||||
/**
|
||||
* Used to lookup a reference to the persisted config binary for an application
|
||||
* Used to lookup a reference to the application
|
||||
*/
|
||||
private final Map<String, Long> auditModelIdsByApplicationsName;
|
||||
private final Map<String, Long> auditApplicationIdsByApplicationsName;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
@@ -114,7 +114,7 @@ public class AuditModelRegistry
|
||||
auditModelUrls = new HashSet<URL>(7);
|
||||
auditModels = new ArrayList<Audit>(7);
|
||||
auditApplicationsByName = new HashMap<String, AuditApplication>(7);
|
||||
auditModelIdsByApplicationsName = new HashMap<String, Long>(7);
|
||||
auditApplicationIdsByApplicationsName = new HashMap<String, Long>(7);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +209,7 @@ public class AuditModelRegistry
|
||||
{
|
||||
auditModels.clear();
|
||||
auditApplicationsByName.clear();
|
||||
auditModelIdsByApplicationsName.clear();
|
||||
auditApplicationIdsByApplicationsName.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,17 +271,17 @@ public class AuditModelRegistry
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the persisted audit model for the given application name
|
||||
* Get the ID of the persisted audit application for the given application name
|
||||
*
|
||||
* @param applicationName the name of the audited application
|
||||
* @return the unique ID of the persisted model (<tt>null</tt> if not found)
|
||||
* @return the unique ID of the persisted application (<tt>null</tt> if not found)
|
||||
*/
|
||||
public Long getAuditModelId(String applicationName)
|
||||
public Long getAuditApplicationId(String applicationName)
|
||||
{
|
||||
readLock.lock();
|
||||
try
|
||||
{
|
||||
return auditModelIdsByApplicationsName.get(applicationName);
|
||||
return auditApplicationIdsByApplicationsName.get(applicationName);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -514,9 +514,13 @@ public class AuditModelRegistry
|
||||
{
|
||||
throw new AuditModelException("Audit application '" + name + "' has already been defined.");
|
||||
}
|
||||
|
||||
// Get the ID of the application
|
||||
Long appId = auditDAO.getOrCreateAuditApplication(auditModelId, name);
|
||||
|
||||
AuditApplication wrapperApp = new AuditApplication(dataExtractorsByName, dataGeneratorsByName, application);
|
||||
auditApplicationsByName.put(name, wrapperApp);
|
||||
auditModelIdsByApplicationsName.put(name, auditModelId);
|
||||
auditApplicationIdsByApplicationsName.put(name, appId);
|
||||
}
|
||||
// Store the model itself
|
||||
auditModels.add(audit);
|
||||
|
@@ -17,7 +17,6 @@ import javax.xml.bind.annotation.XmlType;
|
||||
* <complexContent>
|
||||
* <extension base="{http://www.alfresco.org/repo/audit/model/3.2}KeyedAuditDefinition">
|
||||
* <attribute name="dataGenerator" use="required" type="{http://www.alfresco.org/repo/audit/model/3.2}NameAttribute" />
|
||||
* <attribute name="scope" use="required" type="{http://www.alfresco.org/repo/audit/model/3.2}ScopeAttribute" />
|
||||
* </extension>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
@@ -33,8 +32,6 @@ public class GenerateValue
|
||||
|
||||
@XmlAttribute(required = true)
|
||||
protected String dataGenerator;
|
||||
@XmlAttribute(required = true)
|
||||
protected ScopeAttribute scope;
|
||||
|
||||
/**
|
||||
* Gets the value of the dataGenerator property.
|
||||
@@ -60,28 +57,4 @@ public class GenerateValue
|
||||
this.dataGenerator = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the scope property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link ScopeAttribute }
|
||||
*
|
||||
*/
|
||||
public ScopeAttribute getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the scope property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link ScopeAttribute }
|
||||
*
|
||||
*/
|
||||
public void setScope(ScopeAttribute value) {
|
||||
this.scope = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,11 +34,11 @@ public class ObjectFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link KeyedAuditDefinition }
|
||||
* Create an instance of {@link RecordValue }
|
||||
*
|
||||
*/
|
||||
public KeyedAuditDefinition createKeyedAuditDefinition() {
|
||||
return new KeyedAuditDefinition();
|
||||
public RecordValue createRecordValue() {
|
||||
return new RecordValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,14 +57,6 @@ public class ObjectFactory {
|
||||
return new Audit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link DataExtractors }
|
||||
*
|
||||
*/
|
||||
public DataExtractors createDataExtractors() {
|
||||
return new DataExtractors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link AuditPath }
|
||||
*
|
||||
@@ -90,11 +82,11 @@ public class ObjectFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link RecordValue }
|
||||
* Create an instance of {@link KeyedAuditDefinition }
|
||||
*
|
||||
*/
|
||||
public RecordValue createRecordValue() {
|
||||
return new RecordValue();
|
||||
public KeyedAuditDefinition createKeyedAuditDefinition() {
|
||||
return new KeyedAuditDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,6 +105,14 @@ public class ObjectFactory {
|
||||
return new GenerateValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link DataExtractors }
|
||||
*
|
||||
*/
|
||||
public DataExtractors createDataExtractors() {
|
||||
return new DataExtractors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link JAXBElement }{@code <}{@link Audit }{@code >}}
|
||||
*
|
||||
|
@@ -1,40 +0,0 @@
|
||||
|
||||
package org.alfresco.repo.audit.model._3;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for ScopeAttribute.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
* <p>
|
||||
* <pre>
|
||||
* <simpleType name="ScopeAttribute">
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
|
||||
* <enumeration value="SESSION"/>
|
||||
* <enumeration value="AUDIT"/>
|
||||
* <enumeration value="ALL"/>
|
||||
* </restriction>
|
||||
* </simpleType>
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
@XmlType(name = "ScopeAttribute")
|
||||
@XmlEnum
|
||||
public enum ScopeAttribute {
|
||||
|
||||
SESSION,
|
||||
AUDIT,
|
||||
ALL;
|
||||
|
||||
public String value() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static ScopeAttribute fromValue(String v) {
|
||||
return valueOf(v);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user