From d985aae8059749bc6c85f95c1461cad3cde20320 Mon Sep 17 00:00:00 2001 From: rkv Date: Tue, 11 Dec 2012 10:42:44 +0000 Subject: [PATCH] Fix: document format always has been taken from the previous version of the document even if the new version has another acceptable file format. --- .../splat/service/ScenarioServiceImpl.java | 11 +- .../org/splat/service/StepServiceImpl.java | 2 +- .../src/test/som-without-mappings.xml | 2 +- Workspace/Siman-Common/src/test/som.xml | 3 +- .../service/TestProjectSettingsService.java | 7 +- .../splat/service/TestScenarioService.java | 104 ++++++++++-------- Workspace/Siman/WebContent/conf/som.xml | 1 + 7 files changed, 81 insertions(+), 49 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index fa1f31e..55f7524 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -585,7 +585,16 @@ public class ScenarioServiceImpl implements ScenarioService { throw new MismatchException(MessageKeyEnum.SCN_000002 .toString(), doc.getId()); } + if (LOG.isDebugEnabled()) { + 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()); + } // Remeber the link from the old document to the new document version newVersion.put(pub.value(), newPub.value()); // Remember the new version publication @@ -892,7 +901,7 @@ public class ScenarioServiceImpl implements ScenarioService { KnowledgeElement torem = scenario.getKnowledgeElement(kelm.getIndex()); boolean isOk = (torem != null); if (isOk) { - isOk = scenario.getKnowledgeElements().remove(torem); + isOk = scenario.getKnowledgeElements().remove(torem); if (isOk) { getScenarioDAO().merge(scenario); // Update of my transient data diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 9c2458d..4aae91f 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -364,7 +364,7 @@ public class StepServiceImpl implements StepService { } if (newFormat != null - && previous.getTitle().equals( + && previous.getType().equals( getProjectSettings().getDefaultDocumentType( aStep.getStep(), newFormat))) { dprop.setFormat(newFormat); diff --git a/Workspace/Siman-Common/src/test/som-without-mappings.xml b/Workspace/Siman-Common/src/test/som-without-mappings.xml index 0aeae57..c3db0a4 100644 --- a/Workspace/Siman-Common/src/test/som-without-mappings.xml +++ b/Workspace/Siman-Common/src/test/som-without-mappings.xml @@ -6,7 +6,7 @@ - + diff --git a/Workspace/Siman-Common/src/test/som.xml b/Workspace/Siman-Common/src/test/som.xml index 64bcd7c..d6a34ef 100644 --- a/Workspace/Siman-Common/src/test/som.xml +++ b/Workspace/Siman-Common/src/test/som.xml @@ -6,7 +6,7 @@ - + @@ -232,6 +232,7 @@ + diff --git a/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java b/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java index c1fc9a5..a8aab56 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java @@ -301,7 +301,7 @@ public class TestProjectSettingsService extends BaseTest { "design"); break; case 3: - Assert.assertEquals(defTypes.size(), 7); + Assert.assertEquals(defTypes.size(), 8); Assert.assertNull(_projectSettings.getDefaultDocumentType( step, "pdf")); Assert.assertNotNull(_projectSettings @@ -324,6 +324,11 @@ public class TestProjectSettingsService extends BaseTest { Assert.assertEquals(_projectSettings .getDefaultDocumentType(step, "py").getName(), "geometry"); + Assert.assertNotNull(_projectSettings + .getDefaultDocumentType(step, "brep")); + Assert.assertEquals(_projectSettings + .getDefaultDocumentType(step, "brep").getName(), + "geometry"); Assert.assertNotNull(_projectSettings .getDefaultDocumentType(step, "doc")); Assert.assertEquals(_projectSettings diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index ef5fce1..d5e5b43 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -220,8 +220,9 @@ public class TestScenarioService extends BaseTest { Assert.assertEquals(doc.getTitle(), docName); Assert.assertNotNull(doc.getFiles(), "Document files list must not be null."); - Assert.assertTrue(doc.getFiles().size() > 1, - "Document must have more then 1 attached file."); + Assert + .assertTrue(doc.getFiles().size() > 1, + "Document must have more then 1 attached file."); for (FileDTO file : doc.getFiles()) { Assert.assertNotNull(file.getPath(), @@ -256,9 +257,10 @@ public class TestScenarioService extends BaseTest { } else { // Outdated Assert.assertEquals(file.getState(), 'O', "File state must be outdated ('O')."); - Assert.assertEquals(file.getProcessing(), - "file-download", - "Outdated document should not be imported but downloaded."); + Assert + .assertEquals(file.getProcessing(), + "file-download", + "Outdated document should not be imported but downloaded."); } } } @@ -271,7 +273,8 @@ public class TestScenarioService extends BaseTest { try { steps = _scenarioService.getScenarioInfo(-1L); // getHibernateTemplate().flush(); - Assert.fail("Getting an object with not existing id must be failed."); + Assert + .fail("Getting an object with not existing id must be failed."); } catch (Exception e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); @@ -291,6 +294,7 @@ public class TestScenarioService extends BaseTest { *
  • presentation of the previous version is removed
  • *
  • uses relations are copied correctly
  • *
  • files are moved correctly
  • + *
  • formats of files are new if they are according to the document's type on the study step
  • *
  • new documents are created for new data
  • *
  • new documents have correctly generated names
  • *
  • uses relations are created correctly
  • @@ -388,8 +392,7 @@ public class TestScenarioService extends BaseTest { } } } - Assert.assertTrue( - found, + Assert.assertTrue(found, "New version of the existing checked in document \"" + docDTO.getTitle() + "\" (id=" + docDTO.getId() @@ -397,6 +400,20 @@ public class TestScenarioService extends BaseTest { // 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"); + } + // Check that uses relations are copied correctly // 1. Get all uses relations of the previous document version @@ -452,8 +469,9 @@ public class TestScenarioService extends BaseTest { .getSourceFile().asFile()); found = fcontent.contains(docDTO.getTitle()); if (found) { - LOG.debug("Found new document with generated title: " - + pub.value().getTitle()); + LOG + .debug("Found new document with generated title: " + + pub.value().getTitle()); newPub = pub; break; } @@ -463,13 +481,10 @@ public class TestScenarioService extends BaseTest { Assert.assertTrue(found, "New document is not created for checked in document \"" + docDTO.getTitle() + "\"."); + // Check that uses relations are created correctly - Assert.assertTrue( - newPub.value() - .getTitle() - .startsWith( - newPub.value().getType().getName() - + "_"), + Assert.assertTrue(newPub.value().getTitle().startsWith( + newPub.value().getType().getName() + "_"), "Document title newPub.value().getTitle() must start with " + newPub.value().getType().getName() + "_"); @@ -499,7 +514,8 @@ public class TestScenarioService extends BaseTest { // Call checkin method for a not existing id. try { _scenarioService.checkin(-1, userId, stepsToCheckin); - Assert.fail("Check in for scenario with not existing id must be failed."); + Assert + .fail("Check in for scenario with not existing id must be failed."); } catch (Exception e) { LOG.debug("Expected exception is thrown: " + e.getClass().getSimpleName() + ": " + e.getMessage()); @@ -558,7 +574,7 @@ public class TestScenarioService extends BaseTest { String format = fileDTO.getPath().substring( fileDTO.getPath().lastIndexOf('.') + 1); } - // TODO:Check file by its internal content + // TODO: Check file by its internal content Assert.assertTrue(newPub.getSourceFile().exists(), "File " + newPub.getSourceFile().asFile().getAbsolutePath() + " for the document " + docDTO.getTitle() @@ -600,7 +616,9 @@ public class TestScenarioService extends BaseTest { DocumentDTO docToCheckin = stepToCheckin.addDoc( doc.getId(), doc.getTitle()); for (FileDTO file : doc.getFiles()) { - if (file.getPath().endsWith(format)) { + if (file.getPath().endsWith(format) + || (file.getPath().endsWith("py") && format + .equals("brep"))) { // Create a file in the download directory docToCheckin.addFile(createDownloadedFile(userId, doc.getTitle() + "_result", format)); @@ -610,8 +628,8 @@ public class TestScenarioService extends BaseTest { } // Prepare new data stepToCheckin.addDoc(0, "newdoc" + stepFrom.getNumber()).addFile( - createDownloadedFile(userId, - "newdoc" + stepFrom.getNumber(), "brep")); + createDownloadedFile(userId, "newdoc" + + stepFrom.getNumber(), "brep")); } return stepToCheckin; } @@ -651,8 +669,7 @@ public class TestScenarioService extends BaseTest { // Prepare download directory File tmpDir = _repositoryService.getDownloadDirectory(userId); if (!tmpDir.exists()) { - Assert.assertTrue( - tmpDir.mkdir(), + Assert.assertTrue(tmpDir.mkdir(), "Can't create temporary directory: " + tmpDir.getAbsolutePath()); } @@ -697,23 +714,21 @@ public class TestScenarioService extends BaseTest { User.Properties uprop = new User.Properties(); uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser") .setFirstName("TST_FirstName").setDisplayName("TST_test.user") - .addRole("TST_user") - .setMailAddress("noreply@salome-platform.org"); + .addRole("TST_user").setMailAddress( + "noreply@salome-platform.org"); uprop.disableCheck(); User anAuthor = new User(uprop); ht.saveOrUpdate(anAuthor); // Create a test study - Study.Properties stprops = new Study.Properties() - .setReference("TST_SID_01").setTitle("TST_Study") - .setManager(anAuthor); + Study.Properties stprops = new Study.Properties().setReference( + "TST_SID_01").setTitle("TST_Study").setManager(anAuthor); Study aStudy = new Study(stprops); ht.saveOrUpdate(aStudy); // Create a test scenario - Scenario.Properties sprops = new Scenario.Properties() - .setTitle("TST_Scenario").setManager(anAuthor) - .setOwnerStudy(aStudy); + Scenario.Properties sprops = new Scenario.Properties().setTitle( + "TST_Scenario").setManager(anAuthor).setOwnerStudy(aStudy); Scenario aScenario = new Scenario(sprops); aStudy.getScenariiList().add(aScenario); ht.saveOrUpdate(anAuthor); @@ -741,7 +756,7 @@ public class TestScenarioService extends BaseTest { if (step.getNumber() > 3) { dprop.setFormat("med"); } else { - dprop.setFormat("brep"); + dprop.setFormat("py"); } Publication pub = createDoc(aScenario, aScStep, dprop, "med", false); @@ -754,8 +769,7 @@ public class TestScenarioService extends BaseTest { usedPub = pub; // Create another document with outdated publication - dprop.setName("document" + i++).setType(dtype) - .setFormat("brep"); + dprop.setName("document" + i++).setType(dtype).setFormat("py"); createDoc(aScenario, aScStep, dprop, "med", true); } @@ -771,9 +785,8 @@ public class TestScenarioService extends BaseTest { Assert.assertTrue(ht.find("from Document").size() > 0, "No documents in the database."); - Assert.assertNotNull( - ht.find("from Publication where owner=" + aScenario.getIndex()), - "No publications in the database."); + Assert.assertNotNull(ht.find("from Publication where owner=" + + aScenario.getIndex()), "No publications in the database."); Assert.assertTrue( ht.find("from Publication where owner=" + aScenario.getIndex()) .size() > 0, "No publications in the database."); @@ -799,7 +812,9 @@ public class TestScenarioService extends BaseTest { "More then one document must be in the database"); // Check created uses relations - Assert.assertTrue(usedMap.size() > 0, "Uses relations must be created."); + Assert + .assertTrue(usedMap.size() > 0, + "Uses relations must be created."); boolean foundAny = false; for (Long usingId : usedMap.keySet()) { for (Publication pub : aScen.getDocums()) { @@ -940,8 +955,8 @@ public class TestScenarioService extends BaseTest { User.Properties uprop = new User.Properties(); uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser") .setFirstName("TST_FirstName").setDisplayName("TST_test.user") - .addRole("TST_user") - .setMailAddress("noreply@salome-platform.org"); + .addRole("TST_user").setMailAddress( + "noreply@salome-platform.org"); uprop.disableCheck(); User anAuthor = new User(uprop); @@ -952,14 +967,15 @@ public class TestScenarioService extends BaseTest { "Knowledge type 'usecase' must be created in the database."); SimulationContextType prodtype = _simulationContextService .selectType("product"); - Assert.assertNotNull(prodtype, - "Simulation context type 'product' must be created in the database."); + Assert + .assertNotNull(prodtype, + "Simulation context type 'product' must be created in the database."); // Create admin uprop.clear(); uprop.setUsername("TST_Admin").setName("TST_SimanUnitTestsAdmin") - .setFirstName("TST_AdminFirstName") - .setDisplayName("TST_test.admin").addRole("TST_user,sysadmin") + .setFirstName("TST_AdminFirstName").setDisplayName( + "TST_test.admin").addRole("TST_user,sysadmin") .setMailAddress("noreply@salome-platform.org"); uprop.disableCheck(); diff --git a/Workspace/Siman/WebContent/conf/som.xml b/Workspace/Siman/WebContent/conf/som.xml index af7c4a6..fb349b7 100644 --- a/Workspace/Siman/WebContent/conf/som.xml +++ b/Workspace/Siman/WebContent/conf/som.xml @@ -232,6 +232,7 @@ +
    -- 2.39.2