From 2a3b3718dc0b972b8fcdf3caba51e070f6a8a5d2 Mon Sep 17 00:00:00 2001 From: rkv Date: Tue, 27 Nov 2012 13:03:07 +0000 Subject: [PATCH] Dependent not checked in documents are marked as outdated during checkin. Unit test is improved. --- .../splat/service/ScenarioServiceImpl.java | 14 +++++++++++-- .../splat/service/TestScenarioService.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index 659d5bd..f32c3b4 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -33,6 +33,7 @@ import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Study; +import org.splat.dal.bo.som.UsedByRelation; import org.splat.dal.bo.som.UsesRelation; import org.splat.dal.dao.kernel.UserDAO; import org.splat.dal.dao.som.KnowledgeElementDAO; @@ -531,8 +532,17 @@ public class ScenarioServiceImpl implements ScenarioService { // Build the appropriate relation for the new version. newVer.addDependency(usedDoc); } - // TODO: Outdate documents which depend from the previous version and were not checked in during this operation. - + // Outdate documents which depend from the previous version and + // were not checked in during this operation. + // 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 = aScenario.getPublication(using); + if (usingPub != null) { // if the document using the old version is still published + usingPub.setIsnew('O'); + } + } } // For each new document create uses relation to the last versions of diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index f455c4e..005ddfb 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -27,6 +27,7 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.Study; +import org.splat.dal.bo.som.UsedByRelation; import org.splat.dal.bo.som.UsesRelation; import org.splat.dal.bo.som.Document.Properties; import org.splat.dal.dao.som.Database; @@ -346,6 +347,7 @@ public class TestScenarioService extends BaseTest { Assert.assertFalse(aScen.isCheckedout(), "Scenario is still marked as checked out after checkin."); // Check that new document versions are created for checked in documents + boolean caseFound = false; for (StepDTO step : stepsToCheckin) { for (DocumentDTO docDTO : step.getDocs()) { if ((docDTO.getId() != 0) && (docDTO.getId() != null)) { @@ -396,6 +398,22 @@ public class TestScenarioService extends BaseTest { 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; + } + } + } else { // Check that new documents are created for new data boolean found = false; @@ -434,6 +452,8 @@ public class TestScenarioService extends BaseTest { } } } + Assert.assertTrue(caseFound, + "Not checked in dependent documents must become outdated."); // /////////////////////////////////////////////////////////// // Call checkin method for a not existing id. -- 2.39.2