StroomFileNameUtil { public static String constructFilename(final String executionUuid, final long id, final String template, final AttributeMap attributeMap, final 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, attributeMap); path = PathCreator.replace(path, EXECUTION_UUID, executionUuid); path = PathCreator.replace(path, PATH_ID, 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); static String idToString(long id); static String idToPathId(final String id); static String constructFilename(final String executionUuid,
                                           final long id,
                                           final String template,
                                           final AttributeMap attributeMap,
                                           final String... fileExtensions); static final String EXECUTION_UUID; static final String PATH_ID; static final String ID; }
@Test void testConstructFilename() { AttributeMap attributeMap = new AttributeMap(); attributeMap.put("feed", "myFeed"); attributeMap.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"; assertThat(StroomFileNameUtil.constructFilename(null, 1, standardTemplate, attributeMap, extension1, extension2)).isEqualTo("001.zip.bad"); assertThat(StroomFileNameUtil.constructFilename(null, 3000, standardTemplate, attributeMap, extension1)).isEqualTo("003/003000.zip"); assertThat(StroomFileNameUtil.constructFilename(null, 3000, dynamicTemplate, attributeMap, extension1)).isEqualTo("003000_myVar1_myFeed.zip"); assertThat(StroomFileNameUtil.constructFilename(null, 3000, staticTemplate, attributeMap, extension1)).isEqualTo("003/003000_someStaticText.zip"); assertThat(StroomFileNameUtil.constructFilename(null, 3000, staticTemplate, attributeMap)).isEqualTo("003/003000_someStaticText"); }