@Override protected void setUp() throws Exception { mapper = new PathMapper(); mapper.addPathMap("/a/b/c", "/1/2/3"); mapper.addPathMap("/a/b/c", "/one/two/three"); mapper.addPathMap("/a/c/c", "/1/3/3"); mapper.addPathMap("/a/c/c", "/one/three/three"); mapper.addPathMap("/A/B/C", "/1/2/3"); mapper.addPathMap("/A/B/C", "/ONE/TWO/THREE"); mapper.addPathMap("/A/C/C", "/1/3/3"); mapper.addPathMap("/A/C/C", "/ONE/THREE/THREE"); }
public <V> Map<String, V> convertMap(Map<String, V> valueMap) { Map<String, V> resultMap = new HashMap<String, V>(valueMap.size() * 2 + 1); for (Map.Entry<String, V> entry : valueMap.entrySet()) { String path = entry.getKey(); V value = entry.getValue(); Set<String> mappedPaths = getMappedPaths(path); for (String mappedPath : mappedPaths) { resultMap.put(mappedPath, value); } } return resultMap; } }
/** * {@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; }
/** * Construct the reverse lookup maps for quick conversion of data to target maps. */ private void buildAuditPathMap(Audit audit) { PathMappings pathMappings = audit.getPathMappings(); if (pathMappings == null) { pathMappings = objectFactory.createPathMappings(); } for (PathMap pathMap : pathMappings.getPathMap()) { String sourcePath = pathMap.getSource(); String targetPath = pathMap.getTarget(); // Extract the application key from the root of the path int keyStart = targetPath.charAt(0) == '/' ? 1 : 0; int keyEnd = targetPath.indexOf('/', keyStart); String key = keyEnd == -1 ? targetPath.substring(keyStart) : targetPath.substring(keyStart, keyEnd); // Only add the path if the application is not disabled if (isApplicationEnabled(key)) { auditPathMapper.addPathMap(sourcePath, targetPath); } } } }
auditPathMapper = new PathMapper(); auditPathMapper.lock();
final Map<String, Serializable> mappedValues = pathMapper.convertMap(pathedValues); if (mappedValues.isEmpty())
/** * {@inheritDoc} * <p/> * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt> * will always be returned. * * @since 3.2 */ public boolean areAuditValuesRequired() { return (loggerInbound.isDebugEnabled()) || (isAuditEnabled() && !auditModelRegistry.getAuditPathMapper().isEmpty()); }
try return updateMappedPaths(sourcePath);
try return updateMappedPathsPartial(sourcePath);
/** * Construct the reverse lookup maps for quick conversion of data to target maps. */ private void buildAuditPathMap(Audit audit) { PathMappings pathMappings = audit.getPathMappings(); if (pathMappings == null) { pathMappings = objectFactory.createPathMappings(); } for (PathMap pathMap : pathMappings.getPathMap()) { String sourcePath = pathMap.getSource(); String targetPath = pathMap.getTarget(); // Extract the application key from the root of the path int keyStart = targetPath.charAt(0) == '/' ? 1 : 0; int keyEnd = targetPath.indexOf('/', keyStart); String key = keyEnd == -1 ? targetPath.substring(keyStart) : targetPath.substring(keyStart, keyEnd); // Only add the path if the application is not disabled if (isApplicationEnabled(key)) { auditPathMapper.addPathMap(sourcePath, targetPath); } } } }
auditPathMapper = new PathMapper(); auditPathMapper.lock();
final Map<String, Serializable> mappedValues = pathMapper.convertMap(pathedValues); if (mappedValues.isEmpty())
/** * {@inheritDoc} * <p/> * Note that if DEBUG is on for the the {@link #INBOUND_LOGGER}, then <tt>true</tt> * will always be returned. * * @since 3.2 */ public boolean areAuditValuesRequired() { return (loggerInbound.isDebugEnabled()) || (isAuditEnabled() && !auditModelRegistry.getAuditPathMapper().isEmpty()); }
try return updateMappedPaths(sourcePath);
try return updateMappedPathsPartial(sourcePath);
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 } }
/** * {@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; }
public <V> Map<String, V> convertMap(Map<String, V> valueMap) { Map<String, V> resultMap = new HashMap<String, V>(valueMap.size() * 2 + 1); for (Map.Entry<String, V> entry : valueMap.entrySet()) { String path = entry.getKey(); V value = entry.getValue(); Set<String> mappedPaths = getMappedPaths(path); for (String mappedPath : mappedPaths) { resultMap.put(mappedPath, value); } } return resultMap; } }
expectedOutputMap.put("/ONE/THREE/THREE/133", 133); Map<String, Integer> outputMap = mapper.convertMap(inputMap);
public void testPathMatchesPartial() { Set<String> mappedPaths = mapper.getMappedPathsWithPartialMatch("/a"); assertEquals("Partial matches expected", 4, mappedPaths.size()); } }