import org.splat.service.dto.StepDTO;
import org.splat.service.technical.IndexService;
import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.RepositoryService;
import org.splat.service.technical.StepsConfigService;
import org.splat.som.Step;
import org.splat.util.BeanHelper;
*/
private StepsConfigService _stepsConfigService;
+ /**
+ * Injected repository service.
+ */
+ private RepositoryService _repositoryService;
+
/**
* Get the projectElementService.
*
for (Scenario scen : fromStudy.getScenariiList()) {
if (scen.getIndex() == fromScenId) {
fromScen = scen;
+ break;
}
}
}
// Copy validation cycles
- for (ValidationCycle fromCycle : fromStudy.getValidationCycles()
- .values()) {
- ValidationCycle cycle = new ValidationCycle(toStudy, fromCycle);
- getValidationCycleDAO().create(cycle);
- toStudy.addRelation(cycle.getContext());
- toStudy.getValidationCycles().put(
- cycle.getDocumentType().getName(), cycle); // Replaces the cycle if exists as default,
- }
+ copyValidationCycles(fromStudy, toStudy);
// Copy content of the study up to the given step
Map<Publication, Publication> oldToNewPub = new HashMap<Publication, Publication>();
}
}
+ /**
+ * Copy validation cycles from study to study.
+ *
+ * @param fromStudy
+ * the source study
+ * @param toStudy
+ * the destination study
+ */
+ private void copyValidationCycles(final Study fromStudy, final Study toStudy) {
+ for (ValidationCycle fromCycle : fromStudy.getValidationCycles()
+ .values()) {
+ if (fromCycle.isAssigned()) {
+ ValidationCycle cycle = fromCycle.clone(toStudy);
+ getValidationCycleDAO().create(cycle);
+ toStudy.addRelation(cycle.getContext());
+ toStudy.getValidationCycles().put(
+ cycle.getDocumentType().getName(), cycle); // Replaces the cycle if exists as default,
+ }
+ }
+ }
+
/**
* Copy dependencies between documents from the given project element up to <BR>
* the given step according to the given map of old publications to new publications.
throws MissedPropertyException, InvalidPropertyException,
MultiplyDefinedException, IOException, NotApplicableException {
- java.io.File upfile = fromDoc.getSourceFile().asFile();
+ java.io.File srcFile = fromDoc.getSourceFile().asFile();
// Creation of the document
Document.Properties dprop = new Document.Properties().setName(
fromDoc.getTitle()).setType(fromDoc.getType()).setFormat(
fromDoc.getFormat()).setAuthor(fromDoc.getAuthor());
+
+ java.io.File tmpDir = getRepositoryService().getDownloadDirectory(
+ step.getOwnerStudy().getAuthor());
+
+ // Remove local file index prefix to get original filename.
+ java.io.File upfile = new java.io.File(tmpDir.getPath()
+ + "/"
+ + srcFile.getName().substring(
+ srcFile.getName().indexOf('_') + 1));
+ // Copy the source file into the temporary folder with original filename.
+ copyFile(srcFile, upfile);
+
dprop.setLocalPath(upfile.getPath());
Publication addoc = getStepService().createDocument(step, dprop);
- copyFile(upfile, addoc.getSourceFile());
+
+ // Move the temporary file into the repository
+ moveFile(upfile, addoc.getSourceFile().asFile());
+
getPublicationService().saveAs(addoc, fromDoc.getProgressState());
// Copy attached files
- for (Relation rel : addoc.value().getRelations(ConvertsRelation.class)) {
+ for (Relation rel : fromDoc.getRelations(ConvertsRelation.class)) {
File attach = ((ConvertsRelation) rel).getTo();
ConvertsRelation export = getPublicationService().attach(addoc,
attach.getFormat());
- copyFile(attach.asFile(), export.getTo());
+ // Copy the source document attachment file to the new study vault
+ copyFile(attach.asFile(), export.getTo().asFile());
}
return addoc;
}
*
* @param upfile
* the source file.
- * @param targetFile
+ * @param file
* the target file
* @throws IOException
* if failed
*/
- private void copyFile(final java.io.File upfile, final File targetFile)
+ private void copyFile(final java.io.File upfile, final java.io.File file)
throws IOException {
if (LOG.isInfoEnabled()) {
- LOG.info("Copy " + upfile.getAbsolutePath() + TO
- + targetFile.asFile().getPath());
+ LOG.info("Copy " + upfile.getAbsolutePath() + TO + file.getPath());
}
- IOUtils.copy(upfile, targetFile.asFile());
+ IOUtils.copy(upfile, file);
+ }
+
+ /**
+ * Copy a file. Print info message.
+ *
+ * @param upfile
+ * the source file.
+ * @param file
+ * the target file
+ * @return true if renamed otherwise return false
+ */
+ private boolean moveFile(final java.io.File upfile, final java.io.File file) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Move " + upfile.getAbsolutePath() + TO + file.getPath());
+ }
+ return upfile.renameTo(file);
}
/**
// Attach the file via ConvertsRelation, create a new document or
// create a new version of the document
dprop.setAuthor(aUser).setDate(aDate).setFormat(fileFormat);
+ String authorName = I18nUtils.getMessageLocaleDefault(aUser
+ .getDisplayName());
+ String summary = I18nUtils.getMessageLocaleDefault(
+ MessageKeyEnum.DCT_000005.toString(), authorName);
+ dprop.setDescription(summary);
if (doc.getId() > 0) {
checkinExistingDoc(step, doc, dprop, fileFormat, upfile,
}
docname += "_" + i; // The generated new document title
- dprop.setDescription("Checked in").setName(docname);
+ dprop.setName(docname);
Publication newPub = getStepService().createDocument(step,
dprop);
// If there is no attachment with this extension then attach the new one
ConvertsRelation export = getPublicationService().attach(pub,
fileFormat);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Moving " + upfile.getName() + TO
- + export.getTo().asFile().getPath());
- }
- upfile.renameTo(export.getTo().asFile());
+ moveFile(upfile, export.getTo().asFile());
} else {
// If an attachment with this extension already exists then
// replace it by the new one
- upfile.renameTo(attach.asFile());
+ moveFile(upfile, attach.asFile());
// Update attached file modification date
attach.setDate(new Date());
}
NotApplicableException {
// 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
+ updir.getAbsolutePath());
}
}
- if (upfile.renameTo(updir)) {
+ if (moveFile(upfile, 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
_stepsConfigService = stepsConfigService;
}
+ /**
+ * Get the repositoryService.
+ *
+ * @return the repositoryService
+ */
+ public RepositoryService getRepositoryService() {
+ return _repositoryService;
+ }
+
+ /**
+ * Set the repositoryService.
+ *
+ * @param repositoryService
+ * the repositoryService to set
+ */
+ public void setRepositoryService(final RepositoryService repositoryService) {
+ _repositoryService = repositoryService;
+ }
+
}