String fileFormat = upfile.getName().substring(
upfile.getName().lastIndexOf('.') + 1);
- // Create a new document or a new version of the document
+ // Attach the file via ConvertsRelation, create a new document or
+ // create a new version of the document
dprop.setAuthor(aUser).setDate(aDate).setFormat(fileFormat);
Publication pub, newPub;
if (doc.getId() > 0) {
- // If the document already exists then create a new version of it
+ // If the document already exists then
+ // Attach the file via ConvertsRelation if the extension of the
+ // new file differs from the old one.
+ // If file format (i.e. extension) is the same then create a new
+ // version of the document.
// Find the document publication
pub = step.getDocument(doc.getId());
if (pub == null) {
LOG.debug("Old format: " + pub.value().getFormat()
+ " => New format: " + fileFormat);
}
- newPub = getStepService().versionDocument(step, pub, dprop);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Created document type: "
- + newPub.value().getType().getName() + ", format: "
- + newPub.value().getFormat());
+ // If formats are same then create a new document version
+ if (pub.value().getFormat() != null
+ && pub.value().getFormat().equals(fileFormat)) {
+ newPub = getStepService().versionDocument(step, pub, dprop);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Created document type: "
+ + newPub.value().getType().getName()
+ + ", format: " + newPub.value().getFormat());
+ }
+ // Remeber the link from the old document to the new document version
+ newVersion.put(pub.value(), newPub.value());
+ // Remember the new version publication
+ newVers.add(newPub);
+
+ saveFile(newPub, step, file);
+
+ } else { // If formats are different then attach the new file via ConvertsRelation
+ ConvertsRelation export = getPublicationService().attach(
+ pub, fileFormat);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Moving " + upfile.getName() + " to "
+ + export.getTo().asFile().getPath());
+ }
+ upfile.renameTo(export.getTo().asFile());
}
- // Remeber the link from the old document to the new document version
- newVersion.put(pub.value(), newPub.value());
- // Remember the new version publication
- newVers.add(newPub);
} else {
// Otherwise create a new document of the result type
// Remeber the new document
newDocs.add(newPub);
+
+ saveFile(newPub, step, file);
}
- saveFile(newPub, step, file);
}
}
/**
* Save the file in the vault and create its publication in the step.
+ *
* @param newPub
* the new publication to save
* @param step
if ((docDTO.getId() != 0) && (docDTO.getId() != null)) {
boolean found = false;
Document prevDoc = null;
+ Document curDoc = null;
Publication newPub = null;
for (Publication pub : aScen.getDocums()) {
prevDoc = pub.value().getPreviousVersion();
break;
}
}
+ if (pub.value().getIndex() == docDTO.getId()) {
+ // Document version was not changed, old document is still published
+ curDoc = pub.value();
+ break;
+ }
}
- Assert.assertTrue(found,
- "New version of the existing checked in document \""
+ Assert.assertTrue(found || (curDoc != null),
+ "New version or new attached file of the existing checked in document \""
+ docDTO.getTitle() + "\" (id="
+ docDTO.getId()
+ ") is not found in the scenario.");
- // Check that presentation of the previous version is removed
- Assert.assertFalse(aScen.publishes(prevDoc));
- checkFiles(docDTO, newPub);
-
- // Formats of files are new if they are according to the document's type on the study step
- if ("py".equals(prevDoc.getFormat())
- && "geometry".equals(prevDoc.getType().getName())) {
- Assert.assertEquals(newPub.value().getFormat(), "brep");
- Assert.assertEquals(newPub.getSourceFile().getFormat(),
- "brep");
- Assert.assertEquals(newPub.getSourceFile()
- .getRelativePath().substring(
- newPub.getSourceFile()
- .getRelativePath().lastIndexOf(
- '.') + 1), "brep");
- }
+ // If previous version is found then the format must be the same
+ String newFormat = docDTO.getFiles().get(0).getPath()
+ .substring(
+ docDTO.getFiles().get(0).getPath()
+ .lastIndexOf('.') + 1);
+ if (found) {
+ Assert.assertEquals(prevDoc.getFormat(), newFormat,
+ "Formats of versions must be same");
+ Assert.assertFalse(aScen.publishes(prevDoc));
+ // Check that presentation of the previous version is removed
+ checkFiles(docDTO, newPub);
+
+ // Formats of files are new if they are according to the document's type on the study step
+ if ("py".equals(prevDoc.getFormat())
+ && "geometry".equals(prevDoc.getType().getName())) {
+ Assert.assertEquals(newPub.value().getFormat(), "brep");
+ Assert.assertEquals(newPub.getSourceFile().getFormat(),
+ "brep");
+ Assert.assertEquals(newPub.getSourceFile()
+ .getRelativePath().substring(
+ newPub.getSourceFile()
+ .getRelativePath().lastIndexOf(
+ '.') + 1), "brep");
+ }
- // Check that uses relations are copied correctly
-
- // 1. Get all uses relations of the previous document version
- for (Relation rel : prevDoc
- .getRelations(UsesRelation.class)) {
- Document used = ((UsesRelation) rel).getTo();
- // 2.1. Get the latest version of the document published in this scenario
- Publication toBeUsed = aScen.getPublication(used);
- if (toBeUsed == null) {
- // Find the latest published version
- for (Publication lastPub : aScen.getDocums()) {
- if ((lastPub.value().getPreviousVersion() != null)
- && (lastPub.value()
- .getPreviousVersion()
- .getIndex() == used.getIndex())) {
- toBeUsed = lastPub;
- break;
+ // Check that uses relations are copied correctly
+
+ // 1. Get all uses relations of the previous document version
+ for (Relation rel : prevDoc
+ .getRelations(UsesRelation.class)) {
+ Document used = ((UsesRelation) rel).getTo();
+ // 2.1. Get the latest version of the document published in this scenario
+ Publication toBeUsed = aScen.getPublication(used);
+ if (toBeUsed == null) {
+ // Find the latest published version
+ for (Publication lastPub : aScen.getDocums()) {
+ if ((lastPub.value().getPreviousVersion() != null)
+ && (lastPub.value()
+ .getPreviousVersion()
+ .getIndex() == used.getIndex())) {
+ toBeUsed = lastPub;
+ break;
+ }
}
}
+ if ((toBeUsed != null) && (!toBeUsed.isOutdated())) {
+ // 2.2. For each used document check that its latest not outdated version
+ // is used by the new checked in document version.
+ checkUsesRelation(newPub, toBeUsed);
+ }
}
- if ((toBeUsed != null) && (!toBeUsed.isOutdated())) {
- // 2.2. For each used document check that its latest not outdated version
- // is used by the new checked in document version.
- checkUsesRelation(newPub, toBeUsed);
- }
- }
- // 1. Get all usedBy relations of the previous document version
- for (Relation rel : prevDoc
- .getRelations(UsedByRelation.class)) {
- Document using = ((UsedByRelation) rel).getTo();
- // Check that not checked in dependent documents became outdated
- Publication usingPub = aScen.getPublication(using);
- if (usingPub != null) { // if the document using the old version is still published
- Assert.assertTrue(usingPub.isOutdated(),
- "Not checked in dependent document "
- + using.getTitle() + " ("
- + using.getType().getName()
- + ") must become outdated.");
- caseFound = true;
+ // 1. Get all usedBy relations of the previous document version
+ for (Relation rel : prevDoc
+ .getRelations(UsedByRelation.class)) {
+ Document using = ((UsedByRelation) rel).getTo();
+ // Check that not checked in dependent documents became outdated
+ Publication usingPub = aScen.getPublication(using);
+ if (usingPub != null) { // if the document using the old version is still published
+ Assert.assertTrue(usingPub.isOutdated(),
+ "Not checked in dependent document "
+ + using.getTitle() + " ("
+ + using.getType().getName()
+ + ") must become outdated.");
+ caseFound = true;
+ }
}
+ } else {
+ // Otherwise the new file format must differ from the previous one
+ // and the new file must be attached to the same document
+ org.splat.dal.bo.som.File attFile = curDoc
+ .getAttachedFile(newFormat);
+ Assert.assertNotNull(attFile, "File "
+ + docDTO.getFiles().get(0).getPath()
+ + " must be attached to the document "
+ + docDTO.getTitle() + "#" + docDTO.getId());
+ Assert.assertTrue(attFile.asFile().exists(), "File "
+ + docDTO.getFiles().get(0).getPath()
+ + " attached to the document "
+ + docDTO.getTitle() + "#" + docDTO.getId() + " doesn't exist");
}
+
} else {
// Check that new documents are created for new data
boolean found = false;