StaticFileServiceImpl implements StaticFileService { @Override public void persistFile(final String uuid) throws NotFoundException, IOException { final String org = securityService.getOrganization().getId(); try (DirectoryStream<Path> folders = Files.newDirectoryStream(getTemporaryStorageDir(org), getDirsEqualsUuidFilter(uuid))) { for (Path folder : folders) { Files.move(folder, getDurableStorageDir(org).resolve(folder.getFileName())); } } }  void activate(ComponentContext cc); void deactivate(); void setSecurityService(SecurityService securityService); void setOrganizationDirectoryService(OrganizationDirectoryService directoryService); @Override String storeFile(String filename, InputStream inputStream); @Override InputStream getFile(final String uuid); @Override void persistFile(final String uuid); @Override void deleteFile(String uuid); @Override String getFileName(String uuid); @Override Long getContentLength(String uuid); static final String STATICFILES_ROOT_DIRECTORY_KEY; }
@Test public void testPersistFile() throws Exception { StaticFileServiceImpl staticFileServiceImpl = new StaticFileServiceImpl(); staticFileServiceImpl.setOrganizationDirectoryService(orgDir); staticFileServiceImpl.activate(getComponentContext(null)); staticFileServiceImpl.setSecurityService(getSecurityService()); String videoUUID = staticFileServiceImpl.storeFile(videoFilename, new FileInputStream(videoFile)); String imageUUID = staticFileServiceImpl.storeFile(imageFilename, new FileInputStream(imageFile)); staticFileServiceImpl.persistFile(videoUUID); staticFileServiceImpl.purgeTemporaryStorageSection(getSecurityService().getOrganization().getId(), 0); IOUtils.contentEquals(new FileInputStream(videoFile), staticFileServiceImpl.getFile(videoUUID)); try { staticFileServiceImpl.getFile(imageUUID); fail("File should no longer exist"); } catch (NotFoundException e) { } }