StroomFileNameUtil { static String constructFilename(long id, final String template, final MetaMap metaMap, String... fileExtensions) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Using" + " template " + template + " and fileExtensions " + Arrays.toString(fileExtensions)); } final String idStr = idToString(id); final String pathIdStr = idToPathId(idStr); String path = template; path = PathCreator.replaceAll(path, metaMap); path = PathCreator.replace(path, "pathId", pathIdStr); path = PathCreator.replace(path, "id", idStr); final String[] remainingVars = PathCreator.findVars(path); if (remainingVars.length > 0) { LOGGER.warn("Unused variables found: " + Arrays.toString(remainingVars)); for (final String remainingVar : remainingVars) { path = PathCreator.replace(path, remainingVar, MISSING_VALUE); } } path = clean(path); if (fileExtensions != null) { final StringBuilder sb = new StringBuilder(path); for (String extension : fileExtensions) { if (extension != null) { sb.append(extension); } } path = sb.toString(); } return path; } private  StroomFileNameUtil(); static String getIdPath(final long id);  }
@Test public void testConstructFilename() { MetaMap metaMap = new MetaMap(); metaMap.put("feed", "myFeed"); metaMap.put("var1", "myVar1"); final String standardTemplate = "${pathId}/${id}"; final String staticTemplate = "${pathId}/${id} someStaticText"; final String dynamicTemplate = "${id} ${var1} ${feed}"; final String extension1 = ".zip"; final String extension2 = ".bad"; Assert.assertEquals("001.zip.bad", StroomFileNameUtil.constructFilename(1, standardTemplate, metaMap, extension1, extension2)); Assert.assertEquals("003/003000.zip", StroomFileNameUtil.constructFilename(3000, standardTemplate, metaMap, extension1)); Assert.assertEquals("003000_myVar1_myFeed.zip", StroomFileNameUtil.constructFilename(3000, dynamicTemplate, metaMap, extension1)); Assert.assertEquals("003/003000_someStaticText.zip", StroomFileNameUtil.constructFilename(3000, staticTemplate, metaMap, extension1)); Assert.assertEquals("003/003000_someStaticText", StroomFileNameUtil.constructFilename(3000, staticTemplate, metaMap)); }