]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
The complex method has been decomposed.
authorrkv <rkv@opencascade.com>
Mon, 28 Jan 2013 11:58:46 +0000 (11:58 +0000)
committerrkv <rkv@opencascade.com>
Mon, 28 Jan 2013 11:58:46 +0000 (11:58 +0000)
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java

index 6365f7e57e70fd0cc7cf5164cfdf58b403c65cdc..d1b82f54e30d9b078a3d9c91752e9b07f57c60b9 100644 (file)
@@ -626,33 +626,51 @@ public class ScenarioServiceImpl implements ScenarioService {
                                // Remeber the new document
                                newDocs.add(newPub);
                        }
+                       saveFile(newPub, step, file);
+               }
+       }
 
-                       // Attach the file to the created document
-                       java.io.File updir = newPub.getSourceFile().asFile();
-                       if (LOG.isDebugEnabled()) {
-                               LOG.debug("Moving \"" + upfile.getName() + "\" to \""
-                                               + updir.getPath() + "\".");
-                       }
-                       if (updir.exists()) {
-                               if (updir.delete()) {
-                                       LOG.info(MessageKeyEnum.SCN_000003.toString(), updir
-                                                       .getAbsoluteFile(), step.getOwner().getIndex());
-                               } else {
-                                       throw new IOException(
-                                                       "Can't delete the existing destination file to move file from "
-                                                                       + file.getPath() + " to "
-                                                                       + updir.getAbsolutePath());
-                               }
-                       }
-                       if (upfile.renameTo(updir)) {
-                               // Save the new publication in the scenario.
-                               // The old publication is removed from the scenario here.
-                               getPublicationService().saveAs(newPub, ProgressState.inWORK); // May throw FileNotFound if rename was not done
+       /**
+        * Save the file in the vault and create its publication in the step.
+        * @param newPub
+        *            the new publication to save
+        * @param step
+        *            the study step to publish the document
+        * @param file
+        *            the downloaded file DTO
+        * @throws IOException
+        *             if a file can't be moved into the vault
+        * @throws NotApplicableException
+        *             if failed saving of a new publication with a given state
+        */
+       private void saveFile(final Publication newPub, final Step step,
+                       final FileDTO file) throws IOException, NotApplicableException {
+               // Attach the file to the created document
+               java.io.File updir = newPub.getSourceFile().asFile();
+               java.io.File upfile = new java.io.File(file.getPath());
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("Moving \"" + upfile.getName() + "\" to \""
+                                       + updir.getPath() + "\".");
+               }
+               if (updir.exists()) {
+                       if (updir.delete()) {
+                               LOG.info(MessageKeyEnum.SCN_000003.toString(), updir
+                                               .getAbsoluteFile(), step.getOwner().getIndex());
                        } else {
-                               throw new IOException("Can't move file from " + file.getPath()
-                                               + " to " + updir.getAbsolutePath());
+                               throw new IOException(
+                                               "Can't delete the existing destination file to move file from "
+                                                               + file.getPath() + " to "
+                                                               + updir.getAbsolutePath());
                        }
                }
+               if (upfile.renameTo(updir)) {
+                       // Save the new publication in the scenario.
+                       // The old publication is removed from the scenario here.
+                       getPublicationService().saveAs(newPub, ProgressState.inWORK); // May throw FileNotFound if rename was not done
+               } else {
+                       throw new IOException("Can't move file from " + file.getPath()
+                                       + " to " + updir.getAbsolutePath());
+               }
        }
 
        /**