SpaceConfigStorageImpl implements SpaceConfigStorage { @Override public List<Long> getChangeRequestCommentIds(final String repositoryAlias, final Long changeRequestId) { List<Long> changeRequestCommentIds = new ArrayList<>(); final String changeRequestCommentsPathStr = buildChangeRequestCommentFolderPath(repositoryAlias, changeRequestId); if (objectStorage.exists(changeRequestCommentsPathStr)) { final Path changeRequestCommentsFolder = objectStorage.getPath(changeRequestCommentsPathStr); try (DirectoryStream<Path> directoryStream = ioService.newDirectoryStream(changeRequestCommentsFolder, Files::isRegularFile)) { directoryStream.forEach(commentFile -> { try { Long id = Long.valueOf(FilenameUtils.getBaseName(commentFile.getFileName().toString())); changeRequestCommentIds.add(id); } catch (NumberFormatException e) { logger.error("Cannot convert folder name to long: ", e); } catch (Exception e) { logger.error("An unexpected exception was thrown: ", e); } }); } } return changeRequestCommentIds; } SpaceConfigStorageImpl(); @Inject  SpaceConfigStorageImpl(final ObjectStorage objectStorage,
                                  final @Named("configIO") IOService ioService); void setup(final String spaceName); @Override BranchPermissions loadBranchPermissions(final String branchName,
                                                   final String projectIdentifier); @Override void saveBranchPermissions(final String branchName,
                                      final String projectIdentifier,
                                      final BranchPermissions branchPermissions); @Override void deleteBranchPermissions(final String branchName,
                                        final String projectIdentifier); @Override void deleteRepository(final String repositoryAlias); @Override List<ChangeRequest> loadChangeRequests(final String repositoryAlias); @Override ChangeRequest loadChangeRequest(final String repositoryAlias,
                                           final Long changeRequestId); @Override void saveChangeRequest(final String repositoryAlias,
                                  final ChangeRequest changeRequest); @Override void deleteAllChangeRequests(final String repositoryAlias); @Override void deleteChangeRequest(final String repositoryAlias,
                                    final Long changeRequestId); @Override List<Long> getChangeRequestIds(String repositoryAlias); @Override List<ChangeRequestComment> loadChangeRequestComments(final String repositoryAlias,
                                                                final Long changeRequestId); @Override ChangeRequestComment loadChangeRequestComment(final String repositoryAlias,
                                                         final Long changeRequestId,
                                                         final Long changeRequestCommentId); @Override void saveChangeRequestComment(final String repositoryAlias,
                                         final Long changeRequestId,
                                         final ChangeRequestComment changeRequestComment); @Override void deleteAllChangeRequestComments(final String repositoryAlias,
                                               final Long changeRequestId); @Override void deleteChangeRequestComment(final String repositoryAlias,
                                           final Long changeRequestId,
                                           final Long changeRequestCommentId); @Override List<Long> getChangeRequestCommentIds(final String repositoryAlias,
                                                 final Long changeRequestId); SpaceInfo loadSpaceInfo(); @Override void saveSpaceInfo(final SpaceInfo spaceInfo); @Override void startBatch(); @Override void endBatch(); @Override void close(); @Override boolean isInitialized(); Path getPath(); static final String FILE_FORMAT; static final String BRANCH_PERMISSIONS; static final String SPACE_INFO; }
@Test public void getChangeRequestCommentIdsTest() { final org.uberfire.java.nio.file.Path commentsPath = fileSystemTestingUtils.getIoService().get(URI.create(PATH_PREFIX + "MyProject/change_requests/1/comments")); fileSystemTestingUtils.getIoService().createFile(fileSystemTestingUtils.getIoService().get(URI.create(PATH_PREFIX + "MyProject/change_requests/1/comments/1.comment"))); fileSystemTestingUtils.getIoService().createFile(fileSystemTestingUtils.getIoService().get(URI.create(PATH_PREFIX + "MyProject/change_requests/1/comments/20.comment"))); fileSystemTestingUtils.getIoService().createFile(fileSystemTestingUtils.getIoService().get(URI.create(PATH_PREFIX + "MyProject/change_requests/1/comments/30.comment"))); doReturn(true).when(objectStorage).exists("/MyProject/change_requests/1/comments"); doReturn(commentsPath).when(objectStorage).getPath("/MyProject/change_requests/1/comments"); final List<Long> ids = spaceConfigStorage.getChangeRequestCommentIds("MyProject", 1L); assertSame(1L, ids.get(0)); assertSame(20L, ids.get(1)); assertSame(30L, ids.get(2)); }