use of org.alfresco.repo.audit.model.AuditApplication.DataExtractorDefinition in project alfresco-repository by Alfresco.
the class AuditBootstrapTest method testAuditApplication_GetDataExtractors.
public void testAuditApplication_GetDataExtractors() {
AuditApplication app = auditModelRegistry.getAuditApplicationByName(APPLICATION_TEST);
assertNotNull(app);
List<DataExtractorDefinition> extractors = app.getDataExtractors();
assertNotNull("Should never get a null list", extractors);
assertEquals("Expected 13 extractors", 13, extractors.size());
}
use of org.alfresco.repo.audit.model.AuditApplication.DataExtractorDefinition in project alfresco-repository by Alfresco.
the class AuditComponentImpl method extractData.
/**
* 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
*
* @since 3.2
*/
private Map<String, Serializable> extractData(AuditApplication application, Map<String, Serializable> values) {
Map<String, Serializable> newData = new HashMap<String, Serializable>(values.size());
List<DataExtractorDefinition> extractors = application.getDataExtractors();
for (DataExtractorDefinition extractorDef : extractors) {
DataExtractor extractor = extractorDef.getDataExtractor();
String triggerPath = extractorDef.getDataTrigger();
String sourcePath = extractorDef.getDataSource();
String targetPath = extractorDef.getDataTarget();
// Check if it is triggered
if (!values.containsKey(triggerPath)) {
// It is not triggered
continue;
}
// We observe the key, not the actual value
if (!values.containsKey(sourcePath)) {
// There is no data to extract
continue;
}
Serializable value = values.get(sourcePath);
// Check if the extraction is supported
if (!extractor.isSupported(value)) {
continue;
}
// Use the extractor to pull the value out
final Serializable data;
try {
data = extractor.extractData(value);
} catch (Throwable e) {
throw new AlfrescoRuntimeException("Failed to extract audit data: \n" + " Path: " + sourcePath + "\n" + " Raw value: " + value + "\n" + " Extractor: " + extractor, e);
}
// Add it to the map
newData.put(targetPath, data);
}
// Done
if (logger.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("\nExtracted audit data: \n" + "\tApplication: " + application + "\n" + "\tValues: " + "\n");
for (Map.Entry<String, Serializable> entry : values.entrySet()) {
sb.append("\t\t").append(entry).append("\n");
}
sb.append("\n\tNew Data: \n");
for (Map.Entry<String, Serializable> entry : newData.entrySet()) {
sb.append("\t\t").append(entry).append("\n");
}
logger.debug(sb.toString());
}
return newData;
}
Aggregations