Skip to content

Commit

Permalink
test fixes and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Jun 21, 2024
1 parent d3299cf commit e971462
Show file tree
Hide file tree
Showing 90 changed files with 482 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public void appendContent(CallContext context, String documentId, ContentStream
transaction.setSessionId(sid);
manager.replaceFile(doc.getId(), doc.getFileVersion(), mergeFile, transaction);
} finally {
FileUtil.strongDelete(chunksFolder);
FileUtil.delete(chunksFolder);
}
}
}
Expand All @@ -600,7 +600,7 @@ private File getMergedContent(File chunksDir) throws IOException {
for (Path path : chunks) {
File chunk = path.toFile();
Files.write(merge.toPath(), Files.readAllBytes(chunk.toPath()), StandardOpenOption.APPEND);
FileUtil.strongDelete(chunk);
FileUtil.delete(chunk);
}

return merge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setUp() throws IOException, SQLException, PluginException {
String storePath = Context.get().getProperties().getProperty("store.1.dir");
File store = new File(storePath);

FileUtil.strongDelete(store);
FileUtil.delete(store);

store.mkdir();
new File(store, "5/doc").mkdirs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ public void testAppendContent() throws PersistenceException, IOException {
"text/plain; fileNameCharset=UTF-8", fis);
testSubject.appendContent(null, "doc.5", contentStream, false);
} finally {
FileUtil.strongDelete(content);
FileUtil.delete(content);
}

// Upload a second chunk
Expand All @@ -706,7 +706,7 @@ public void testAppendContent() throws PersistenceException, IOException {
"text/plain; fileNameCharset=UTF-8", fis);
testSubject.appendContent(null, "doc.5", contentStream, true);
} finally {
FileUtil.strongDelete(content);
FileUtil.delete(content);
}

Storer storer = (Storer) context.getBean("Storer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public Document copyResource(Document doc, String fileVersion, String suffix, St
log.error(e.getMessage(), e);
return null;
} finally {
FileUtil.strongDelete(tmpFile);
FileUtil.delete(tmpFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public List<Document> extractAttachments(Document doc, String filterFileName, St
createdDocs.add(attDoc);
} finally {
if (tmpFile != null)
FileUtil.strongDelete(tmpFile);
FileUtil.delete(tmpFile);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ private void historycizeOutgoingEmail(EMail email, MimeMessage message, Internet
log.warn("Cannot historycize the email with subject '{}' sent to {}", email.getSubject(),
email.getAllRecipientsEmails(), t);
} finally {
FileUtil.strongDelete(emlFile);
FileUtil.delete(emlFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void convertMultipleEntries(String sid, Document document, File dest,
throw new IOException("Error in Zip conversion", e);
} finally {
if (tempFile != null)
FileUtil.strongDelete(tempFile);
FileUtil.delete(tempFile);
}
}

Expand All @@ -79,7 +79,7 @@ protected void convertSingleEntry(String sid, Document document, File src, File
converter.convert(sid, document, uncompressedEntryFile, dest);
} finally {
if (uncompressedEntryFile != null)
FileUtil.strongDelete(uncompressedEntryFile);
FileUtil.delete(uncompressedEntryFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public void convertToPdf(Document document, String fileVersion, String sid) thro
storer.store(dest, document.getId(), resource);
} finally {
// Delete temporary resources
FileUtil.strongDelete(src);
FileUtil.strongDelete(dest);
FileUtil.delete(src);
FileUtil.delete(dest);
}
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public Document convert(Document document, String fileVersion, String format, Do
throw new IOException("The conversion was not done");
} finally {
// Delete temporary resources
FileUtil.strongDelete(out);
FileUtil.delete(out);
}
}

Expand All @@ -251,7 +251,7 @@ public void convertToFile(Document document, String fileVersion, File out, Docum
if (converter == null)
return;

FileUtil.strongDelete(out);
FileUtil.delete(out);

// Prepare I/O files
File src = null;
Expand Down Expand Up @@ -279,7 +279,7 @@ public void convertToFile(Document document, String fileVersion, File out, Docum
}
} finally {
// Delete temporary resources
FileUtil.strongDelete(src);
FileUtil.delete(src);
}
}

Expand All @@ -304,7 +304,7 @@ public void convertFile(File in, String inFilename, File out, String outFormat,
if (!in.exists() || in.length() == 0)
throw new IOException(String.format("Unexisting source file %s", in));

FileUtil.strongDelete(out);
FileUtil.delete(out);

converter.convert(in, out);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void internalConvert(String sid, Document document, File src, File dest)
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
} finally {
FileUtil.strongDelete(tmp);
FileUtil.delete(tmp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void internalConvert(String sid, Document document, File src, File dest)
FileUtil.writeFile(listing, tempFile.getAbsolutePath());
converter.convert(sid, document, tempFile, dest);
} finally {
FileUtil.strongDelete(tempFile);
FileUtil.delete(tempFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public void internalConvert(String sid, Document document, File src, File dest)
}
} finally {
if (xslt != null)
FileUtil.strongDelete(xslt);
FileUtil.delete(xslt);
if (xml != null)
FileUtil.strongDelete(xml);
FileUtil.delete(xml);
}
}

Expand Down Expand Up @@ -152,7 +152,7 @@ private void convert(String sid, Document document, File dest, String destExt, F
converter.convert(sid, document, transformedFile, dest);
} finally {
if (transformedFile != null)
FileUtil.strongDelete(transformedFile);
FileUtil.delete(transformedFile);
}
}
} catch (FileNotFoundException | TransformerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void convertGZip(String sid, Document document, File src, File dest) thr
converter.convert(sid, document, ungzippedFile, dest);
} finally {
if (ungzippedFile != null)
FileUtil.strongDelete(ungzippedFile);
FileUtil.delete(ungzippedFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1708,8 +1708,8 @@ public Document merge(Collection<Document> documents, long targetFolderId, Strin
DocumentManager manager = (DocumentManager) Context.get().getBean(DocumentManager.class);
return manager.create(bigPdf, docVO, transaction);
} finally {
FileUtil.strongDelete(bigPdf);
FileUtil.strongDelete(tempDir);
FileUtil.delete(bigPdf);
FileUtil.delete(tempDir);
}
}

Expand Down Expand Up @@ -1813,26 +1813,26 @@ public Document mapRow(ResultSet rs, int arg1) throws SQLException {
log.info("Destroyed {} aliases of document {}", count, documentTag);

count = documentDAO.jdbcUpdate("delete from ld_tag where ld_docid = " + docId);
log.info("Destroyed {} tags of document {}", documentTag);
log.info("Destroyed {} tags of document {}", count, documentTag);

count = documentDAO.jdbcUpdate("delete from ld_link where ld_docid1 = " + docId + " or ld_docid2 = " + docId);
log.info("Destroyed {} links of document {}", documentTag);
log.info("Destroyed {} links of document {}", count, documentTag);

count = documentDAO.jdbcUpdate("delete from ld_bookmark where ld_type=0 and ld_docid = " + docId);
log.info("Destroyed {} bookmarks of document {}", documentTag);
log.info("Destroyed {} bookmarks of document {}", count, documentTag);

count = documentDAO.jdbcUpdate("delete from ld_ticket where ld_docid = " + docId);
log.info("Destroyed {} tickets of document {}", documentTag);
log.info("Destroyed {} tickets of document {}", count, documentTag);

count = documentDAO.jdbcUpdate("delete from ld_note where ld_docid = " + docId);
log.info("Destroyed {} notes of document {}", documentTag);
log.info("Destroyed {} notes of document {}", count, documentTag);

count = documentDAO.jdbcUpdate("delete from ld_history where ld_docid = " + docId);
log.info("Destroyed {} histories of document {}", documentTag);
log.info("Destroyed {} histories of document {}", count, documentTag);

try {
count = documentDAO.jdbcUpdate("delete from ld_readingrequest where ld_docid = " + docId);
log.info("Destroyed {} reading requests of document {}", documentTag);
log.info("Destroyed {} reading requests of document {}", documentTag, docId);
} catch (Exception e) {
// Ignore because the table may not exist
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public synchronized void buildThumbnail(String sid, Document document, String fi
if (pdfBuilder != null)
pdfBuilder.buildThumbnail(sid, document, fileVersion, pdf, dest, size, compression);
} finally {
FileUtil.strongDelete(pdf);
FileUtil.delete(pdf);
}
}
}
} catch (Exception e) {
throw new IOException("Thumbnail building " + e.getMessage(), e);
} finally {
FileUtil.strongDelete(tmp);
FileUtil.delete(tmp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public synchronized void buildThumbnail(String sid, Document document, String fi
} catch (Exception e) {
throw new IOException("Thumbnail building " + e.getMessage(), e);
} finally {
FileUtil.strongDelete(tmp);
FileUtil.delete(tmp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ protected void createImage(Document document, String fileVersion, int size, Inte
log.warn("Error rendering image for document: {} - {}", document.getId(), document.getFileName(), e);
} finally {
// Delete temporary resources
FileUtil.strongDelete(src);
FileUtil.strongDelete(dest);
FileUtil.delete(src);
FileUtil.delete(dest);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void cropImageToFile(String content, ImageZone zone, File file) th
saveImage(content, tmpFile);
cropImageToFile(tmpFile, zone, file);
} finally {
FileUtil.strongDelete(tmpFile);
FileUtil.delete(tmpFile);
}
}

Expand Down Expand Up @@ -288,7 +288,7 @@ public static void printFirstPage(File originalFile, String originalFileName, Fi
}
GhostUtil.print(pdfFile, out, 1);
} finally {
FileUtil.strongDelete(pdfFile);
FileUtil.delete(pdfFile);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ private void parse1(InputStream input, ParseParameters parameters, StringBuilder
log.error(t.getMessage(), t);
} finally {
if (inputFile != null && inputFile.exists())
FileUtil.strongDelete(inputFile);
FileUtil.delete(inputFile);
if (outputPdf != null && outputPdf.exists())
FileUtil.strongDelete(outputPdf);
FileUtil.delete(outputPdf);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void internalParse(InputStream input, ParseParameters parameters, StringB
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
} finally {
FileUtil.strongDelete(tmpFile);
FileUtil.delete(tmpFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void internalParse(InputStream input, ParseParameters parameters, StringB
else
log.warn("Failed to extract HTML text content");
} finally {
FileUtil.strongDelete(tempFile);
FileUtil.delete(tempFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void internalParse(InputStream input, ParseParameters parameters, StringB
}
}
} finally {
FileUtil.strongDelete(mainDocXml);
FileUtil.delete(mainDocXml);
}
} catch (Exception e) {
log.warn("Failed to extract KOffice text content", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void internalParse(InputStream input, ParseParameters parameters, StringB
}
}
} finally {
FileUtil.strongDelete(contentXml);
FileUtil.delete(contentXml);
}
} catch (Exception e) {
log.warn("Failed to extract OpenOffice text content", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public void internalParse(InputStream input, ParseParameters parameters, StringB
content.append(text);
} finally {
if (uncompressedEntryFile != null)
FileUtil.strongDelete(uncompressedEntryFile);
FileUtil.delete(uncompressedEntryFile);
}
}
} finally {
FileUtil.strongDelete(rarFile);
FileUtil.delete(rarFile);
}
}

Expand All @@ -81,7 +81,7 @@ public int countPages(InputStream input, String filename) {
log.error(t.getMessage(), t);
} finally {
if (rarFile != null)
FileUtil.strongDelete(rarFile);
FileUtil.delete(rarFile);
}
return 1;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public int countPages(File input, String filename) {
return entryParser.countPages(uncompressedEntryFile, uncompressedEntryFile.getName());
} finally {
if (uncompressedEntryFile != null)
FileUtil.strongDelete(uncompressedEntryFile);
FileUtil.delete(uncompressedEntryFile);
}
}
} catch (Exception e) {
Expand Down
Loading

0 comments on commit e971462

Please sign in to comment.