@Test public void test_createSearchResult_extractedTextFile() { IDocument document = new Document(); document.setId(DOCUMENT_ID); document.setExtractedTextFileId(FILE_ID); Mockito.when(documentService.getDocument(DOCUMENT_ID)).thenReturn(document); FileSearchResult result = factoryToTest.createSearchResult(FILE_ID); Assert.assertEquals(access, result.getAccess()); Assert.assertEquals(FILE_ID, result.getId()); Assert.assertEquals(CONTENT_TYPE, result.getContentType()); Assert.assertEquals(DOCUMENT_ID, result.getDocumentId()); Assert.assertEquals(FILENAME, result.getFilename()); Assert.assertEquals(SIZE, result.getSize()); Assert.assertEquals(UPLOAD_DATE, result.getUploadDate()); Assert.assertEquals(UPLOAD_ID, result.getUploadId()); Assert.assertEquals( GILES_URL + FilesController.GET_DOCUMENT_PATH.replace( FilesController.DOCUMENT_ID_PLACEHOLDER, DOCUMENT_ID), result.getDocumentUrl()); Assert.assertEquals( GILES_URL + FilesController.DOWNLOAD_FILE_URL.replace( FilesController.FILE_ID_PLACEHOLDER, FILE_ID), result.getUrl()); }
@Override public FileSearchResult createSearchResult(String fileId) { IFile file = fileService.getFileById(fileId); if (file == null) { return null; } FileSearchResult result = new FileSearchResult(); result.setAccess(file.getAccess()); result.setContentType(file.getContentType()); result.setDocumentId(file.getDocumentId()); result.setFilename(file.getFilename()); result.setId(file.getId()); result.setSize(file.getSize()); result.setUploadDate(file.getUploadDate()); result.setUploadId(file.getUploadId()); result.setDocumentUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.GET_DOCUMENT_PATH.replace(FilesController.DOCUMENT_ID_PLACEHOLDER, file.getDocumentId())); result.setUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.DOWNLOAD_FILE_URL.replace(FilesController.FILE_ID_PLACEHOLDER, file.getId())); IDocument document = documentService.getDocument(file.getDocumentId()); if (document == null) { return result; } if (document.getExtractedTextFileId().equals(fileId)) { result.setPage(-1); } else { if (document.getPages() != null) { Optional<IPage> optional = document.getPages().stream().filter(p -> p != null && anyIdEqualsFileId(p, fileId)).findFirst(); if (optional.isPresent()) { IPage page = optional.get(); result.setPage(page.getPageNr()); } } } return result; }
FileSearchResultFactory implements IFileSearchResultFactory { @Override public FileSearchResult createSearchResult(String fileId) { IFile file = fileService.getFileById(fileId); if (file == null) { return null; } FileSearchResult result = new FileSearchResult(); result.setAccess(file.getAccess()); result.setContentType(file.getContentType()); result.setDocumentId(file.getDocumentId()); result.setFilename(file.getFilename()); result.setId(file.getId()); result.setSize(file.getSize()); result.setUploadDate(file.getUploadDate()); result.setUploadId(file.getUploadId()); result.setDocumentUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.GET_DOCUMENT_PATH.replace(FilesController.DOCUMENT_ID_PLACEHOLDER, file.getDocumentId())); result.setUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.DOWNLOAD_FILE_URL.replace(FilesController.FILE_ID_PLACEHOLDER, file.getId())); IDocument document = documentService.getDocument(file.getDocumentId()); if (document == null) { return result; } if (document.getExtractedTextFileId().equals(fileId)) { result.setPage(-1); } else { if (document.getPages() != null) { Optional<IPage> optional = document.getPages().stream().filter(p -> p != null && anyIdEqualsFileId(p, fileId)).findFirst(); if (optional.isPresent()) { IPage page = optional.get(); result.setPage(page.getPageNr()); } } } return result; } }
FileSearchResultFactory implements IFileSearchResultFactory { @Override public FileSearchResult createSearchResult(String fileId) { IFile file = fileService.getFileById(fileId); if (file == null) { return null; } FileSearchResult result = new FileSearchResult(); result.setAccess(file.getAccess()); result.setContentType(file.getContentType()); result.setDocumentId(file.getDocumentId()); result.setFilename(file.getFilename()); result.setId(file.getId()); result.setSize(file.getSize()); result.setUploadDate(file.getUploadDate()); result.setUploadId(file.getUploadId()); result.setDocumentUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.GET_DOCUMENT_PATH.replace(FilesController.DOCUMENT_ID_PLACEHOLDER, file.getDocumentId())); result.setUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.DOWNLOAD_FILE_URL.replace(FilesController.FILE_ID_PLACEHOLDER, file.getId())); IDocument document = documentService.getDocument(file.getDocumentId()); if (document == null) { return result; } if (document.getExtractedTextFileId().equals(fileId)) { result.setPage(-1); } else { if (document.getPages() != null) { Optional<IPage> optional = document.getPages().stream().filter(p -> p != null && anyIdEqualsFileId(p, fileId)).findFirst(); if (optional.isPresent()) { IPage page = optional.get(); result.setPage(page.getPageNr()); } } } return result; }  }
FileSearchResultFactory implements IFileSearchResultFactory { @Override public FileSearchResult createSearchResult(String fileId) { IFile file = fileService.getFileById(fileId); if (file == null) { return null; } FileSearchResult result = new FileSearchResult(); result.setAccess(file.getAccess()); result.setContentType(file.getContentType()); result.setDocumentId(file.getDocumentId()); result.setFilename(file.getFilename()); result.setId(file.getId()); result.setSize(file.getSize()); result.setUploadDate(file.getUploadDate()); result.setUploadId(file.getUploadId()); result.setDocumentUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.GET_DOCUMENT_PATH.replace(FilesController.DOCUMENT_ID_PLACEHOLDER, file.getDocumentId())); result.setUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.DOWNLOAD_FILE_URL.replace(FilesController.FILE_ID_PLACEHOLDER, file.getId())); IDocument document = documentService.getDocument(file.getDocumentId()); if (document == null) { return result; } if (document.getExtractedTextFileId().equals(fileId)) { result.setPage(-1); } else { if (document.getPages() != null) { Optional<IPage> optional = document.getPages().stream().filter(p -> p != null && anyIdEqualsFileId(p, fileId)).findFirst(); if (optional.isPresent()) { IPage page = optional.get(); result.setPage(page.getPageNr()); } } } return result; }  @Override FileSearchResult createSearchResult(String fileId); }
FileSearchResultFactory implements IFileSearchResultFactory { @Override public FileSearchResult createSearchResult(String fileId) { IFile file = fileService.getFileById(fileId); if (file == null) { return null; } FileSearchResult result = new FileSearchResult(); result.setAccess(file.getAccess()); result.setContentType(file.getContentType()); result.setDocumentId(file.getDocumentId()); result.setFilename(file.getFilename()); result.setId(file.getId()); result.setSize(file.getSize()); result.setUploadDate(file.getUploadDate()); result.setUploadId(file.getUploadId()); result.setDocumentUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.GET_DOCUMENT_PATH.replace(FilesController.DOCUMENT_ID_PLACEHOLDER, file.getDocumentId())); result.setUrl(propertiesManager.getProperty(Properties.GILES_URL) + FilesController.DOWNLOAD_FILE_URL.replace(FilesController.FILE_ID_PLACEHOLDER, file.getId())); IDocument document = documentService.getDocument(file.getDocumentId()); if (document == null) { return result; } if (document.getExtractedTextFileId().equals(fileId)) { result.setPage(-1); } else { if (document.getPages() != null) { Optional<IPage> optional = document.getPages().stream().filter(p -> p != null && anyIdEqualsFileId(p, fileId)).findFirst(); if (optional.isPresent()) { IPage page = optional.get(); result.setPage(page.getPageNr()); } } } return result; }  @Override FileSearchResult createSearchResult(String fileId);  }