// Remeber the new document
newDocs.add(newPub);
}
+ saveFile(newPub, step, file);
+ }
+ }
- // Attach the file to the created document
- java.io.File updir = newPub.getSourceFile().asFile();
- if (LOG.isDebugEnabled()) {
- LOG.debug("Moving \"" + upfile.getName() + "\" to \""
- + updir.getPath() + "\".");
- }
- if (updir.exists()) {
- if (updir.delete()) {
- LOG.info(MessageKeyEnum.SCN_000003.toString(), updir
- .getAbsoluteFile(), step.getOwner().getIndex());
- } else {
- throw new IOException(
- "Can't delete the existing destination file to move file from "
- + file.getPath() + " to "
- + updir.getAbsolutePath());
- }
- }
- if (upfile.renameTo(updir)) {
- // Save the new publication in the scenario.
- // The old publication is removed from the scenario here.
- getPublicationService().saveAs(newPub, ProgressState.inWORK); // May throw FileNotFound if rename was not done
+ /**
+ * Save the file in the vault and create its publication in the step.
+ * @param newPub
+ * the new publication to save
+ * @param step
+ * the study step to publish the document
+ * @param file
+ * the downloaded file DTO
+ * @throws IOException
+ * if a file can't be moved into the vault
+ * @throws NotApplicableException
+ * if failed saving of a new publication with a given state
+ */
+ private void saveFile(final Publication newPub, final Step step,
+ final FileDTO file) throws IOException, NotApplicableException {
+ // Attach the file to the created document
+ java.io.File updir = newPub.getSourceFile().asFile();
+ java.io.File upfile = new java.io.File(file.getPath());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Moving \"" + upfile.getName() + "\" to \""
+ + updir.getPath() + "\".");
+ }
+ if (updir.exists()) {
+ if (updir.delete()) {
+ LOG.info(MessageKeyEnum.SCN_000003.toString(), updir
+ .getAbsoluteFile(), step.getOwner().getIndex());
} else {
- throw new IOException("Can't move file from " + file.getPath()
- + " to " + updir.getAbsolutePath());
+ throw new IOException(
+ "Can't delete the existing destination file to move file from "
+ + file.getPath() + " to "
+ + updir.getAbsolutePath());
}
}
+ if (upfile.renameTo(updir)) {
+ // Save the new publication in the scenario.
+ // The old publication is removed from the scenario here.
+ getPublicationService().saveAs(newPub, ProgressState.inWORK); // May throw FileNotFound if rename was not done
+ } else {
+ throw new IOException("Can't move file from " + file.getPath()
+ + " to " + updir.getAbsolutePath());
+ }
}
/**