@Test(expected = ContentAddressableStorageNotFoundException.class) public void givenContainerNotExistWhenCheckListUriNotEmptyThenRaiseAnException() throws IOException, Exception { assertThat(storage.getListUriDigitalObjectFromFolder(SIP_CONTAINER, SIP_FOLDER)).isNotNull().isNotEmpty(); assertThat(storage.getListUriDigitalObjectFromFolder(SIP_CONTAINER, SIP_FOLDER)).hasSize(3); }
@Override public List<URI> getListUriDigitalObjectFromFolder(String containerName, String folderName) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_NAME_IS_A_MANDATORY_PARAMETER.getMessage(), containerName); ParametersChecker.checkParameter(ErrorMessage.FOLDER_NOT_FOUND.getMessage(), folderName); if (!isExistingContainer(containerName)) { throw new ContentAddressableStorageNotFoundException("Container " + containerName + " not found"); } if (!isExistingFolder(containerName, folderName)) { LOGGER.debug(ErrorMessage.FOLDER_NOT_FOUND.getMessage() + folderName); return new ArrayList<>(); } try { Path folderPath = getFolderPath(containerName, folderName); final List<URI> list = new ArrayList<>(); Files.walkFileTree(folderPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String pathFile = file.toString().replace(folderPath.toString() + "/", ""); list.add(URI.create(URLEncoder.encode(pathFile, CharsetUtils.UTF_8))); return FileVisitResult.CONTINUE; } }); return list; } catch (IOException ex) { throw new ContentAddressableStorageException(ex); } }
WorkspaceFileSystem implements WorkspaceContentAddressableStorage { @Override public List<URI> getListUriDigitalObjectFromFolder(String containerName, String folderName) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_NAME_IS_A_MANDATORY_PARAMETER.getMessage(), containerName); ParametersChecker.checkParameter(ErrorMessage.FOLDER_NOT_FOUND.getMessage(), folderName); if (!isExistingContainer(containerName)) { throw new ContentAddressableStorageNotFoundException("Container " + containerName + " not found"); } if (!isExistingFolder(containerName, folderName)) { LOGGER.debug(ErrorMessage.FOLDER_NOT_FOUND.getMessage() + folderName); return new ArrayList<>(); } try { Path folderPath = getFolderPath(containerName, folderName); final List<URI> list = new ArrayList<>(); Files.walkFileTree(folderPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String pathFile = file.toString().replace(folderPath.toString() + "/", ""); list.add(URI.create(URLEncoder.encode(pathFile, CharsetUtils.UTF_8))); return FileVisitResult.CONTINUE; } }); return list; } catch (IOException ex) { throw new ContentAddressableStorageException(ex); } } }
WorkspaceFileSystem implements WorkspaceContentAddressableStorage { @Override public List<URI> getListUriDigitalObjectFromFolder(String containerName, String folderName) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_NAME_IS_A_MANDATORY_PARAMETER.getMessage(), containerName); ParametersChecker.checkParameter(ErrorMessage.FOLDER_NOT_FOUND.getMessage(), folderName); if (!isExistingContainer(containerName)) { throw new ContentAddressableStorageNotFoundException("Container " + containerName + " not found"); } if (!isExistingFolder(containerName, folderName)) { LOGGER.debug(ErrorMessage.FOLDER_NOT_FOUND.getMessage() + folderName); return new ArrayList<>(); } try { Path folderPath = getFolderPath(containerName, folderName); final List<URI> list = new ArrayList<>(); Files.walkFileTree(folderPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String pathFile = file.toString().replace(folderPath.toString() + "/", ""); list.add(URI.create(URLEncoder.encode(pathFile, CharsetUtils.UTF_8))); return FileVisitResult.CONTINUE; } }); return list; } catch (IOException ex) { throw new ContentAddressableStorageException(ex); } } WorkspaceFileSystem(StorageConfiguration configuration); }
WorkspaceFileSystem implements WorkspaceContentAddressableStorage { @Override public List<URI> getListUriDigitalObjectFromFolder(String containerName, String folderName) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_NAME_IS_A_MANDATORY_PARAMETER.getMessage(), containerName); ParametersChecker.checkParameter(ErrorMessage.FOLDER_NOT_FOUND.getMessage(), folderName); if (!isExistingContainer(containerName)) { throw new ContentAddressableStorageNotFoundException("Container " + containerName + " not found"); } if (!isExistingFolder(containerName, folderName)) { LOGGER.debug(ErrorMessage.FOLDER_NOT_FOUND.getMessage() + folderName); return new ArrayList<>(); } try { Path folderPath = getFolderPath(containerName, folderName); final List<URI> list = new ArrayList<>(); Files.walkFileTree(folderPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String pathFile = file.toString().replace(folderPath.toString() + "/", ""); list.add(URI.create(URLEncoder.encode(pathFile, CharsetUtils.UTF_8))); return FileVisitResult.CONTINUE; } }); return list; } catch (IOException ex) { throw new ContentAddressableStorageException(ex); } } WorkspaceFileSystem(StorageConfiguration configuration); void checkWorkspaceFile(String... paths); @Override void createContainer(String containerName); @Override void purgeContainer(String containerName); @Override void purgeOldFilesInContainer(String containerName, TimeToLive timeToLive); @Override void deleteContainer(String containerName, boolean recursive); @Override boolean isExistingContainer(String containerName); @Override void createFolder(String containerName, String folderName); @Override void deleteFolder(String containerName, String folderName); @Override boolean isExistingFolder(String containerName, String folderName); @Override List<URI> getListUriDigitalObjectFromFolder(String containerName, String folderName); @Override void uncompressObject(String containerName, String folderName, String archiveMimeType,
        InputStream inputStreamObject); @Override void putObject(String containerName, String objectName, InputStream stream); @Override void putAtomicObject(String containerName, String objectName, InputStream stream, long size); @Override Response getObject(String containerName, String objectName, Long chunkOffset,
        Long maxChunkSize); @Override void deleteObject(String containerName, String objectName); @Override boolean isExistingObject(String containerName, String objectName); @Override String computeObjectDigest(String containerName, String objectName, DigestType algo); @Override ContainerInformation getContainerInformation(String containerName); @Override JsonNode getObjectInformation(String containerName, String objectName); @Override long countObjects(String containerName); void compress(String containerName, List<String> folderNames, String zipName,
        String outputContainer); }
WorkspaceFileSystem implements WorkspaceContentAddressableStorage { @Override public List<URI> getListUriDigitalObjectFromFolder(String containerName, String folderName) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_NAME_IS_A_MANDATORY_PARAMETER.getMessage(), containerName); ParametersChecker.checkParameter(ErrorMessage.FOLDER_NOT_FOUND.getMessage(), folderName); if (!isExistingContainer(containerName)) { throw new ContentAddressableStorageNotFoundException("Container " + containerName + " not found"); } if (!isExistingFolder(containerName, folderName)) { LOGGER.debug(ErrorMessage.FOLDER_NOT_FOUND.getMessage() + folderName); return new ArrayList<>(); } try { Path folderPath = getFolderPath(containerName, folderName); final List<URI> list = new ArrayList<>(); Files.walkFileTree(folderPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String pathFile = file.toString().replace(folderPath.toString() + "/", ""); list.add(URI.create(URLEncoder.encode(pathFile, CharsetUtils.UTF_8))); return FileVisitResult.CONTINUE; } }); return list; } catch (IOException ex) { throw new ContentAddressableStorageException(ex); } } WorkspaceFileSystem(StorageConfiguration configuration); void checkWorkspaceFile(String... paths); @Override void createContainer(String containerName); @Override void purgeContainer(String containerName); @Override void purgeOldFilesInContainer(String containerName, TimeToLive timeToLive); @Override void deleteContainer(String containerName, boolean recursive); @Override boolean isExistingContainer(String containerName); @Override void createFolder(String containerName, String folderName); @Override void deleteFolder(String containerName, String folderName); @Override boolean isExistingFolder(String containerName, String folderName); @Override List<URI> getListUriDigitalObjectFromFolder(String containerName, String folderName); @Override void uncompressObject(String containerName, String folderName, String archiveMimeType,
        InputStream inputStreamObject); @Override void putObject(String containerName, String objectName, InputStream stream); @Override void putAtomicObject(String containerName, String objectName, InputStream stream, long size); @Override Response getObject(String containerName, String objectName, Long chunkOffset,
        Long maxChunkSize); @Override void deleteObject(String containerName, String objectName); @Override boolean isExistingObject(String containerName, String objectName); @Override String computeObjectDigest(String containerName, String objectName, DigestType algo); @Override ContainerInformation getContainerInformation(String containerName); @Override JsonNode getObjectInformation(String containerName, String objectName); @Override long countObjects(String containerName); void compress(String containerName, List<String> folderNames, String zipName,
        String outputContainer);  }