From: rkv Date: Tue, 29 Jan 2013 08:52:01 +0000 (+0000) Subject: Fix for checkin: attach a new file to the same version if format differs from the... X-Git-Tag: Root_Delivery2_2013_04_22~158 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6e06da79bc83c7fa32aa5c2cb2ba07cc28bfa409;p=tools%2Fsiman.git Fix for checkin: attach a new file to the same version if format differs from the source file. --- diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index d1b82f5..75bcac1 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -570,12 +570,17 @@ public class ScenarioServiceImpl implements ScenarioService { 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) { @@ -590,16 +595,31 @@ public class ScenarioServiceImpl implements ScenarioService { 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 @@ -625,13 +645,15 @@ public class ScenarioServiceImpl implements ScenarioService { // 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 diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index 7c8dbbc..1c48612 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -382,6 +382,7 @@ public class TestScenarioService extends BaseTest { 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(); @@ -392,71 +393,99 @@ public class TestScenarioService extends BaseTest { 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;