Skip to content

Commit

Permalink
Adding files due to package name refactoring, removing System.exit() …
Browse files Browse the repository at this point in the history
…from Updater.
  • Loading branch information
khituras committed May 20, 2019
1 parent 709cf19 commit 37cf9e8
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 6,017 deletions.
50 changes: 24 additions & 26 deletions src/main/java/de/julielab/costosys/medline/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,29 @@ public Updater(HierarchicalConfiguration<ImmutableNode> configuration) {
public void process(DataBaseConnector dbc) throws MedlineUpdateException, IOException {
log.info("Updating from {} into database at {}", medlineFile, dbc.getDbURL());
File[] updateFiles = getMedlineFiles(medlineFile);
List<File> unprocessedMedlineUpdates = getUnprocessedMedlineUpdates(updateFiles, dbc);
configureDocumentDeleters();
// Get the names of all deleters to be applied.
String[] configuredDeleters = configuration.getStringArray(ConfigurationConstants.DELETER_NAME);
for (File file : unprocessedMedlineUpdates) {
log.info("Processing file {}.", file.getAbsoluteFile());
dbc.updateFromXML(file.getAbsolutePath(), Constants.DEFAULT_DATA_TABLE_NAME);
List<String> pmidsToDelete = getPmidsToDelete(file);
for (Iterator<IDocumentDeleter> it = documentDeleterLoader.iterator(); it.hasNext();) {
IDocumentDeleter documentDeleter = it.next();
if (!documentDeleter.hasName(configuredDeleters))
continue;
// This is very hacky. Might work for now, does not scale, of course.
if (documentDeleter instanceof MedlineDataTableDocumentDeleter)
((MedlineDataTableDocumentDeleter)documentDeleter).setDbc(dbc);
documentDeleter.deleteDocuments(pmidsToDelete);
}
if (updateFiles != null && updateFiles.length > 0) {
List<File> unprocessedMedlineUpdates = getUnprocessedMedlineUpdates(updateFiles, dbc);
configureDocumentDeleters();
// Get the names of all deleters to be applied.
String[] configuredDeleters = configuration.getStringArray(ConfigurationConstants.DELETER_NAME);
for (File file : unprocessedMedlineUpdates) {
log.info("Processing file {}.", file.getAbsoluteFile());
dbc.updateFromXML(file.getAbsolutePath(), Constants.DEFAULT_DATA_TABLE_NAME);
List<String> pmidsToDelete = getPmidsToDelete(file);
for (Iterator<IDocumentDeleter> it = documentDeleterLoader.iterator(); it.hasNext(); ) {
IDocumentDeleter documentDeleter = it.next();
if (!documentDeleter.hasName(configuredDeleters))
continue;
// This is very hacky. Might work for now, does not scale, of course.
if (documentDeleter instanceof MedlineDataTableDocumentDeleter)
((MedlineDataTableDocumentDeleter) documentDeleter).setDbc(dbc);
documentDeleter.deleteDocuments(pmidsToDelete);
}

// As last thing, mark the current update file as finished.
markFileAsImported(file, dbc);
// As last thing, mark the current update file as finished.
markFileAsImported(file, dbc);
}
}

}

protected File[] getMedlineFiles(String medlinePathString) throws FileNotFoundException {
Expand All @@ -76,16 +77,13 @@ protected File[] getMedlineFiles(String medlinePathString) throws FileNotFoundEx
throw new FileNotFoundException("File \"" + medlinePathString + "\" was not found.");
if (!medlinePath.isDirectory())
return new File[] { medlinePath };
File[] medlineFiles = medlinePath.listFiles(new FileFilter() {
public boolean accept(File file) {
String filename = file.getName();
return filename.endsWith("gz") || filename.endsWith("gzip") || filename.endsWith("zip");
}
File[] medlineFiles = medlinePath.listFiles(file -> {
String filename = file.getName();
return filename.endsWith("gz") || filename.endsWith("gzip") || filename.endsWith("zip");
});
// Check whether anything has been read.
if (medlineFiles == null || medlineFiles.length == 0) {
log.info("No (g)zipped files found in directory {}. No update will be performed.", medlinePathString);
System.exit(0);
}
return medlineFiles;
}
Expand Down
116 changes: 0 additions & 116 deletions src/main/java/de/julielab/xmlData/Constants.java

This file was deleted.

Loading

0 comments on commit 37cf9e8

Please sign in to comment.