Search in sources :

Example 1 with PathMapper

use of org.alfresco.util.PathMapper in project alfresco-repository by Alfresco.

the class AuditBootstrapTest method testGetPathMappings.

public void testGetPathMappings() {
    PathMapper pathMapper = auditModelRegistry.getAuditPathMapper();
    assertNotNull(pathMapper);
    try {
        pathMapper.addPathMap("x", "y");
        fail("Should not be allowed to update the path mappings.");
    } catch (Throwable e) {
    // Expected
    }
}
Also used : PathMapper(org.alfresco.util.PathMapper)

Example 2 with PathMapper

use of org.alfresco.util.PathMapper in project alfresco-repository by Alfresco.

the class AuditComponentImpl method recordAuditValuesWithUserFilter.

@Override
public Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter) {
    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);
        sb.append("\n").append("Inbound audit values:");
        for (Map.Entry<String, Serializable> entry : values.entrySet()) {
            String pathElement = entry.getKey();
            String path = AuditApplication.buildPath(rootPath, pathElement);
            Serializable value = entry.getValue();
            sb.append("\n\t").append(path).append("=").append(value);
        }
        loggerInbound.debug(sb.toString());
    }
    // Build the key paths using the session root path
    Map<String, Serializable> pathedValues = new HashMap<String, Serializable>(values.size() * 2);
    for (Map.Entry<String, Serializable> entry : values.entrySet()) {
        String pathElement = entry.getKey();
        String path = AuditApplication.buildPath(rootPath, pathElement);
        pathedValues.put(path, entry.getValue());
    }
    // Translate the values map
    PathMapper pathMapper = auditModelRegistry.getAuditPathMapper();
    final Map<String, Serializable> mappedValues = pathMapper.convertMap(pathedValues);
    if (mappedValues.isEmpty()) {
        return mappedValues;
    }
    // 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<Map<String, Serializable>> callback = new RetryingTransactionCallback<Map<String, Serializable>>() {

                public Map<String, Serializable> execute() throws Throwable {
                    return recordAuditValuesImpl(mappedValues);
                }
            };
            RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
            txnHelper.setForceWritable(true);
            return txnHelper.doInTransaction(callback, false, true);
        case TXN_READ_WRITE:
            return recordAuditValuesImpl(mappedValues);
        default:
            throw new IllegalStateException("Unknown txn state: " + txnState);
    }
}
Also used : Serializable(java.io.Serializable) PathMapper(org.alfresco.util.PathMapper) HashMap(java.util.HashMap) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) TxnReadState(org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PathMapper

use of org.alfresco.util.PathMapper in project alfresco-repository by Alfresco.

the class AuditComponentImpl method areAuditValuesRequired.

/**
 * {@inheritDoc}
 * <p/>
 * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt>
 * will always be returned.
 *
 * @since 3.4
 */
@Override
public boolean areAuditValuesRequired(String path) {
    PathMapper pathMapper = auditModelRegistry.getAuditPathMapper();
    Set<String> mappedPaths = pathMapper.getMappedPathsWithPartialMatch(path);
    return loggerInbound.isDebugEnabled() || mappedPaths.size() > 0;
}
Also used : PathMapper(org.alfresco.util.PathMapper)

Aggregations

PathMapper (org.alfresco.util.PathMapper)3 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TxnReadState (org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1