Salome HOME
Don't attach format to the file name when adding a document.
authorrkv <rkv@opencascade.com>
Mon, 28 Jan 2013 08:25:51 +0000 (08:25 +0000)
committerrkv <rkv@opencascade.com>
Mon, 28 Jan 2013 08:25:51 +0000 (08:25 +0000)
Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java
Workspace/Siman-Common/src/test/splat/service/TestPublicationService.java
Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java

index 5b84fdfd7826ba2bff148fcd0d1f16795b785324..0cb8eaba4bb5351841557310d6cbd8f67e0ff0ae 100644 (file)
@@ -137,13 +137,15 @@ public class DocumentServiceImpl implements DocumentService {
                                aDoc.getStep());
                aDoc.setDid(new StringBuffer(path).append(".%").append(
                                Document.suformat).toString()); // Document reference
-               path = new StringBuffer(year).append("/").append(path).append("/")
-                               .append(step.getPath())
+               StringBuffer pathBuf = new StringBuffer(year).append("/").append(path)
+                               .append("/").append(step.getPath())
                                // File path relative to the repository vault
-                               .append(filename).append(".")
-                               .append(aDoc.getFile().getFormat()) // File name and extension
-                               .toString();
-               aDoc.getFile().changePath(path);
+                               .append(filename);
+               if (!FileNaming.asis.equals(getProjectSettings().getFileNamingScheme())) {
+                       // Use format as extension if file naming strategy is not "asis".
+                       pathBuf.append(".").append(aDoc.getFile().getFormat()); // File name and extension
+               }
+               aDoc.getFile().changePath(pathBuf.toString());
                owner = getStudyDAO().merge(owner);
        }
 
index 3d4f134855c7e247e8831294a282a4831967d576..47f98104a3ff14db6a9c7cea266b5a035bdf2fe3 100644 (file)
@@ -13,6 +13,7 @@ import java.io.FileNotFoundException;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.sql.SQLException;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -418,6 +419,7 @@ public class TestPublicationService extends BaseTest {
                steps.addAll(Arrays.asList(studySteps));
                steps.addAll(Arrays.asList(scSteps));
                steps.addAll(Arrays.asList(studySteps));
+               DecimalFormat tostring = new DecimalFormat(Document.suformat);
                for (org.splat.som.Step step : steps) {
                        LOG.debug("Create a document for the step " + step.getNumber());
 
@@ -461,6 +463,9 @@ public class TestPublicationService extends BaseTest {
                                                .get(0);
                                Assert.assertEquals(aStudy.getLastLocalIndex(), oldInd + 1,
                                                "Incremented index must be saved in the database.");
+                               Assert.assertEquals(addoc.getSourceFile().getName(), tostring
+                                               .format(aStudy.getLastLocalIndex())
+                                               + "_" + fname, "The generated file name is incorrect.");
                        }
                }
 
@@ -545,10 +550,11 @@ public class TestPublicationService extends BaseTest {
                                ht.evict(pub);
                                ht.evict(pub.value());
                                int nbConverts = ht.find("from ConvertsRelation").size();
-                               int nbDocConverts = ht.find("from ConvertsRelation where owner="
+                               int nbDocConverts = ht.find(
+                                               "from ConvertsRelation where owner="
                                                                + pub.value().getIndex()).size();
                                int nbFiles = ht.find("from File").size();
-                               
+
                                ConvertsRelation rel = _publicationService.attach(pub, "py");
 
                                _studyDAO.flush();
@@ -558,23 +564,25 @@ public class TestPublicationService extends BaseTest {
                                Assert
                                                .assertTrue(rel.isSaved(),
                                                                "Returned ConvertsRelation must be saved in the database.");
-                               Assert.assertEquals(ht
-                                               .find("from ConvertsRelation where owner="
-                                                               + pub.value().getIndex()).size(), nbDocConverts + 1,
+                               Assert.assertEquals(ht.find(
+                                               "from ConvertsRelation where owner="
+                                                               + pub.value().getIndex()).size(),
+                                               nbDocConverts + 1,
                                                "Number of created ConvertsRelations must be 1.");
-                               Assert.assertEquals(ht
-                                               .find("from ConvertsRelation").size(), nbConverts + 1,
+                               Assert.assertEquals(ht.find("from ConvertsRelation").size(),
+                                               nbConverts + 1,
                                                "Number of created ConvertsRelations must be 1.");
                                Assert.assertNotNull(rel.getTo(),
                                                "Attached File must not be null.");
                                Assert.assertTrue(rel.isSaved(),
                                                "Attached File must be saved in the database.");
-                               Assert.assertEquals(ht
-                                               .find("from File where rid="
-                                                               + rel.getTo().getIndex()).size(), 1,
-                                               "Number of created File must be 1.");
-                               Assert.assertEquals(ht
-                                               .find("from File").size(), nbFiles + 1,
+                               Assert
+                                               .assertEquals(ht
+                                                               .find(
+                                                                               "from File where rid="
+                                                                                               + rel.getTo().getIndex())
+                                                               .size(), 1, "Number of created File must be 1.");
+                               Assert.assertEquals(ht.find("from File").size(), nbFiles + 1,
                                                "Number of created Files must be 1.");
                        }
                }
index 4b9aa4727024d07c21a94429ff0588e69e379b4a..7c8dbbcbc900ae7df1332c9cbbe8644427d587ed 100644 (file)
@@ -370,6 +370,7 @@ public class TestScenarioService extends BaseTest {
                // Do test checkin
                _scenarioService.checkin(scenarioId, userId, stepsToCheckin);
 
+               _scenarioDAO.flush();
                // Check that scenario is no more marked as checked out
                aScen = _scenarioDAO.get(scenarioId);
                Assert.assertFalse(aScen.isCheckedout(),
@@ -650,10 +651,27 @@ public class TestScenarioService extends BaseTest {
        private FileDTO createDownloadedFile(final long userId, final String name,
                        final String format) throws IOException {
                // Create a file in the download directory
-               String filePath = getDownloadPath(userId) + name + "." + format;
+               return createDownloadedFile(userId, name + "." + format);
+       }
+
+       /**
+        * Create a file in the user's repository downloads directory.
+        * 
+        * @param userId
+        *            user id
+        * @param fname
+        *            file name
+        * @return created file DTO
+        * @throws IOException
+        *             if file creation failed
+        */
+       private FileDTO createDownloadedFile(final long userId, final String fname)
+                       throws IOException {
+               // Create a file in the download directory
+               String filePath = getDownloadPath(userId) + fname;
                FileWriter fw = new FileWriter(filePath);
-               fw.write("Simulation of " + name + "." + format
-                               + " file for checkin at " + new Date());
+               fw.write("Simulation of " + fname + " file for checkin at "
+                               + new Date());
                fw.close();
                return new FileDTO(filePath);
        }
@@ -758,6 +776,7 @@ public class TestScenarioService extends BaseTest {
                                } else {
                                        dprop.setFormat("py");
                                }
+                               dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
                                Publication pub = createDoc(aScenario, aScStep, dprop, "med",
                                                false);
                                if (usedPub != null) {
@@ -770,6 +789,7 @@ public class TestScenarioService extends BaseTest {
 
                                // Create another document with outdated publication
                                dprop.setName("document" + i++).setType(dtype).setFormat("py");
+                               dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
                                createDoc(aScenario, aScStep, dprop, "med", true);
 
                        }
@@ -870,6 +890,8 @@ public class TestScenarioService extends BaseTest {
                // document<i>: document type[0] - first type used on the step
                // <source-file>.brep
                // <attached-file>.med
+               createDownloadedFile(aScenario.getAuthor().getIndex(), dprop
+                               .getLocalPath());
                Publication pub = _stepService.createDocument(aScStep, dprop);
                Assert.assertNotNull(pub.getOwner(),
                                "The publication must be attached to the scenario.");
@@ -884,6 +906,10 @@ public class TestScenarioService extends BaseTest {
                ht.saveOrUpdate(pub);
 
                // Attach a file
+               createDownloadedFile(aScenario.getAuthor().getIndex(), dprop
+                               .getLocalPath().substring(0,
+                                               dprop.getLocalPath().lastIndexOf(".") - 1),
+                               attachedFileExt);
                ht.save(pub.value());
                ht.saveOrUpdate(_publicationService.attach(pub, attachedFileExt));