use of org.alfresco.repo.audit.generator.DataGenerator in project alfresco-repository by Alfresco.
the class AuditBootstrapTest method testAuditApplication_GetDataGenerators.
public void testAuditApplication_GetDataGenerators() {
AuditApplication app = auditModelRegistry.getAuditApplicationByName(APPLICATION_TEST);
assertNotNull(app);
Map<String, DataGenerator> generators = app.getDataGenerators("/blah");
assertNotNull("Should never get a null map", generators);
assertTrue("Expected no generators", generators.isEmpty());
generators = app.getDataGenerators("/test/1.1/2.1/3.1/4.1");
assertEquals(1, generators.size());
assertTrue(generators.containsKey("/test/time"));
generators = app.getDataGenerators("/test/1.1/2.1/3.1/4.1");
assertEquals(1, generators.size());
assertTrue(generators.containsKey("/test/time"));
generators = app.getDataGenerators("/test/1.1/2.2/3.2/4.1");
assertEquals(2, generators.size());
assertTrue(generators.containsKey("/test/time"));
assertTrue(generators.containsKey("/test/1.1/2.2/3.2/4.1/time"));
}
use of org.alfresco.repo.audit.generator.DataGenerator in project alfresco-repository by Alfresco.
the class AuditComponentImpl method generateData.
/**
* @param generators the data generators
* @return Returns a map of generated data keyed by full path
*
* @since 3.2
*/
private Map<String, Serializable> generateData(Map<String, DataGenerator> generators) {
Map<String, Serializable> newData = new HashMap<String, Serializable>(generators.size() + 5);
for (Map.Entry<String, DataGenerator> entry : generators.entrySet()) {
String path = entry.getKey();
DataGenerator generator = entry.getValue();
final Serializable data;
try {
data = generator.getData();
} catch (Throwable e) {
throw new AlfrescoRuntimeException("Failed to generate audit data: \n" + " Path: " + path + "\n" + " Generator: " + generator, e);
}
// Add it to the map
newData.put(path, data);
}
// Done
return newData;
}
use of org.alfresco.repo.audit.generator.DataGenerator in project alfresco-repository by Alfresco.
the class AuditApplication method buildAuditPaths.
/**
* Recursive method to build generator and extractor mappings
*/
private void buildAuditPaths(AuditPath auditPath, String currentPath, Set<String> existingPaths, Map<String, DataGenerator> upperGeneratorsByPath) {
// Clone the upper maps to prevent pollution
upperGeneratorsByPath = new HashMap<String, DataGenerator>(upperGeneratorsByPath);
// Append the current audit path to the current path
if (currentPath == null) {
currentPath = AuditApplication.buildPath(auditPath.getKey());
} else {
currentPath = AuditApplication.buildPath(currentPath, auditPath.getKey());
}
// Make sure we have not processed it before
if (!existingPaths.add(currentPath)) {
generateException(currentPath, "The audit path already exists.");
}
// Get the data extractors declared for this key
for (RecordValue element : auditPath.getRecordValue()) {
String key = element.getKey();
String extractorPath = AuditApplication.buildPath(currentPath, key);
if (!existingPaths.add(extractorPath)) {
generateException(extractorPath, "The audit path already exists.");
}
String extractorName = element.getDataExtractor();
DataExtractor extractor = dataExtractorsByName.get(extractorName);
if (extractor == null) {
generateException(extractorPath, "No data extractor exists for name: " + extractorName);
}
// The extractor may pull data from somewhere else
String sourcePath = element.getDataSource();
if (sourcePath == null) {
sourcePath = currentPath;
}
// The extractor may be triggered by data from elsewhere
String dataTrigger = element.getDataTrigger();
if (dataTrigger == null) {
dataTrigger = currentPath;
}
// Store the extractor definition
DataExtractorDefinition extractorDef = new DataExtractorDefinition(dataTrigger, sourcePath, extractorPath, extractor);
dataExtractors.add(extractorDef);
}
// Get the data generators declared for this key
for (GenerateValue element : auditPath.getGenerateValue()) {
String key = element.getKey();
String generatorPath = AuditApplication.buildPath(currentPath, key);
if (!existingPaths.add(generatorPath)) {
generateException(generatorPath, "The audit path already exists.");
}
String generatorName = element.getDataGenerator();
DataGenerator generator = dataGeneratorsByName.get(generatorName);
if (generator == null) {
generateException(generatorPath, "No data generator exists for name: " + generatorName);
}
// All generators that occur earlier in the path will also be applicable here
upperGeneratorsByPath.put(generatorPath, generator);
}
// All the generators apply to the current path
dataGenerators.put(currentPath, upperGeneratorsByPath);
// Find all sub audit paths and recurse
for (AuditPath element : auditPath.getAuditPath()) {
buildAuditPaths(element, currentPath, existingPaths, upperGeneratorsByPath);
}
}
Aggregations