]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Import document action is fixed: uses relations are created now in the same transacti...
authorrkv <rkv@opencascade.com>
Wed, 5 Dec 2012 16:46:06 +0000 (16:46 +0000)
committerrkv <rkv@opencascade.com>
Wed, 5 Dec 2012 16:46:06 +0000 (16:46 +0000)
Workspace/Siman-Common/src/org/splat/service/PublicationService.java
Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java

index e30099e270186f67a14f9e5068abd6d62edd30d3..b3b4e4fbc1a156586dac7579a8f41809ca260ae8 100644 (file)
@@ -11,7 +11,9 @@ package org.splat.service;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.text.ParseException;
 import java.util.Date;
+import java.util.List;
 
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ConvertsRelation;
@@ -48,6 +50,14 @@ public interface PublicationService {
         */
        Publication copy(Publication aPublication, ProjectElement publisher);
 
+       public Publication createDoc(final long ownerId, final Step step,
+                       final long documentTypeId, final long userId, final String fname,
+                       final String doctitle, final ProgressState docstate,
+                       final String reference, final String version, final Date docDate,
+                       final List<Long> docuses) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException, IOException,
+                       NotApplicableException, InterruptedException, ParseException;
+       
        /**
         * Create a new version of the document.
         * 
index 50abe39f8d3e2229e14348e202a2a463423f25de..020cee9407e0f88698aa04bbba5b2c6539f942fe 100644 (file)
@@ -12,6 +12,7 @@ package org.splat.service;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
@@ -74,6 +75,14 @@ public class PublicationServiceImpl implements PublicationService {
         * Injected document service.
         */
        private DocumentService _documentService;
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
+       /**
+        * Injected user service.
+        */
+       private UserService _userService;
        /**
         * Injected project element service.
         */
@@ -117,6 +126,90 @@ public class PublicationServiceImpl implements PublicationService {
                return copy;
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.PublicationService#createDoc(long, org.splat.som.Step, long, long, java.lang.String, java.lang.String,
+        *      org.splat.dal.bo.som.ProgressState, java.lang.String, java.lang.String, java.util.Date, java.util.List)
+        */
+       @Transactional
+       public Publication createDoc(final long ownerId, final Step step,
+                       final long documentTypeId, final long userId, final String fname,
+                       final String doctitle, final ProgressState docstate,
+                       final String reference, final String version, final Date docDate,
+                       final List<Long> docuses) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException, IOException,
+                       NotApplicableException, InterruptedException, ParseException {
+               DocumentType type = getDocumentTypeService().selectType(
+                               (int) documentTypeId);
+               User user = getUserService().selectUser(userId);
+               File updir = getRepositoryService().getDownloadDirectory(user);
+               File upfile = new File(updir.getPath() + "/" + fname);
+               String[] table = fname.split("\\x2E");
+
+               // Creation of the document
+               Document.Properties dprop = new Document.Properties();
+               Publication addoc;
+
+               if (reference.length() == 0) { // Importation of a foreign document
+                       // TODO: Extract property of supported documents (DOCX, ODT...)
+                       addoc = getStepService().createDocument(
+                                       step,
+                                       dprop.setName(doctitle).setType(type).setFormat(
+                                                       table[table.length - 1]).setAuthor(user));
+                       updir = addoc.getSourceFile().asFile();
+                       if (LOG.isInfoEnabled()) {
+                               LOG.info("Moving \"" + upfile.getName() + "\" to \""
+                                               + updir.getPath() + "\".");
+                       }
+                       upfile.renameTo(updir);
+                       try {
+                               saveAs(addoc, docstate); // May throw FileNotFound if rename was not done
+                       } catch (FileNotFoundException saverror) {
+                               Thread.sleep(1000);
+                               LOG.info("Waiting for the file.");
+                               upfile.renameTo(updir);
+                               saveAs(addoc, docstate); // Forget it if throw again FileNotFound
+                       }
+               } else { // Importation of a previously created template-based document
+                       if (docDate != null) {
+                               dprop.setDate(docDate);
+                       }
+                       addoc = getStepService().assignDocument(step,
+                                       dprop.setReference(reference).setName(doctitle));
+                       updir = addoc.getSourceFile().asFile();
+                       if (LOG.isInfoEnabled()) {
+                               LOG.info("Moving \"" + upfile.getName() + "\" to \""
+                                               + updir.getPath() + "\".");
+                       }
+                       upfile.renameTo(updir);
+                       try {
+                               if (version.length() > 0) {
+                                       saveAs(addoc, new Revision(version));
+                               } else {
+                                       saveAs(addoc, docstate);
+                               }
+                       } catch (FileNotFoundException saverror) {
+                               Thread.sleep(1000);
+                               LOG.info("Waiting for the file.");
+                               upfile.renameTo(updir);
+                               if (version.length() > 0) {
+                                       saveAs(addoc, new Revision(version));
+                               } else {
+                                       saveAs(addoc, docstate);
+                               }
+                       }
+               }
+               // Creation of uses relations
+               if (docuses != null) {
+                       for (Long index : docuses) {
+                               Document used = getDocumentService().selectDocument(index);
+                               addoc.addDependency(used);
+                       }
+               }
+               return addoc;
+       }
+
        /**
         * {@inheritDoc}
         * 
@@ -807,4 +900,43 @@ public class PublicationServiceImpl implements PublicationService {
        public void setTimestampDAO(final TimestampDAO timestampDAO) {
                _timestampDAO = timestampDAO;
        }
+
+       /**
+        * Get the documentTypeService.
+        * 
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * 
+        * @param documentTypeService
+        *            the documentTypeService to set
+        */
+       public void setDocumentTypeService(
+                       final DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
+
+       /**
+        * Get the userService.
+        * 
+        * @return the userService
+        */
+       public UserService getUserService() {
+               return _userService;
+       }
+
+       /**
+        * Set the userService.
+        * 
+        * @param userService
+        *            the userService to set
+        */
+       public void setUserService(final UserService userService) {
+               _userService = userService;
+       }
 }
index 9ac10075bdf69755bd5eedda59a212c540fe6b04..201c9e57c973695ca1ba01b7dfd86d27c931c156 100644 (file)
@@ -61,6 +61,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
        <bean id="publicationService"
                class="org.splat.service.PublicationServiceImpl">
                <property name="documentService" ref="documentService" />
+        <property name="documentTypeService" ref="documentTypeService" />
+        <property name="userService" ref="userService" />
                <property name="projectElementService"
                        ref="projectElementService" />
                <property name="stepService" ref="stepService" />
index c86a7d54783b978081ab3429762353661bc2eb33..0a45e294ae61ddce30b4bc49459990f40478e309 100644 (file)
@@ -6,6 +6,7 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
@@ -305,81 +306,37 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                        mystudy = getOpenStudy();
                        User user = getConnectedUser();
                        Step step = mystudy.getSelectedStep();
-                       DocumentType type = getDocumentTypeService().selectType(
-                                       (int) _documentType);
-                       File updir = getRepositoryService().getDownloadDirectory(user);
-                       File upfile = new File(updir.getPath() + "/" + filename);
-                       String[] table = filename.split("\\x2E");
-
-                       // Creation of the document
-                       Document.Properties dprop = new Document.Properties();
-                       Publication addoc;
-
-                       if (_reference.length() == 0) { // Importation of a foreign document
-                               // TODO: Extract property of supported documents (DOCX, ODT...)
-                               addoc = getStepService().createDocument(
-                                               step,
-                                               dprop.setName(docname).setType(type).setFormat(
-                                                               table[table.length - 1]).setAuthor(user));
-                               updir = addoc.getSourceFile().asFile();
-                               if (LOG.isInfoEnabled()) {
-                                       LOG.info("Moving \"" + upfile.getName() + "\" to \""
-                                                       + updir.getPath() + "\".");
-                               }
-                               upfile.renameTo(updir);
-                               try {
-                                       getPublicationService().saveAs(addoc, state); // May throw FileNotFound if rename was not done
-                               } catch (FileNotFoundException saverror) {
-                                       Thread.sleep(1000);
-                                       LOG.info("Waiting for the file.");
-                                       upfile.renameTo(updir);
-                                       getPublicationService().saveAs(addoc, state); // Forget it if throw again FileNotFound
-                               }
-                       } else { // Importation of a previously created template-based document
-                               if (_documentDate.length() > 0) {
-                                       ResourceBundle locale = ResourceBundle.getBundle("som",
-                                                       getApplicationSettings().getCurrentLocale());
-                                       SimpleDateFormat get = new SimpleDateFormat(locale
-                                                       .getString("date.format"));
-                                       dprop.setDate(get.parse(_documentDate));
-                               }
-                               addoc = getStepService().assignDocument(step,
-                                               dprop.setReference(_reference).setName(docname));
-                               updir = addoc.getSourceFile().asFile();
-                               if (LOG.isInfoEnabled()) {
-                                       LOG.info("Moving \"" + upfile.getName() + "\" to \""
-                                                       + updir.getPath() + "\".");
-                               }
-                               upfile.renameTo(updir);
-                               try {
-                                       if (_version.length() > 0) {
-                                               getPublicationService().saveAs(addoc,
-                                                               new Revision(_version));
-                                       } else {
-                                               getPublicationService().saveAs(addoc, state);
-                                       }
-                               } catch (FileNotFoundException saverror) {
-                                       Thread.sleep(1000);
-                                       LOG.info("Waiting for the file.");
-                                       upfile.renameTo(updir);
-                                       if (_version.length() > 0) {
-                                               getPublicationService().saveAs(addoc,
-                                                               new Revision(_version));
-                                       } else {
-                                               getPublicationService().saveAs(addoc, state);
-                                       }
-                               }
-                               mystudy.updateSimulationContexts(); // In case of simulation contexts extracted from the imported document
+                       Date docdate = null;
+                       if (_documentDate.length() > 0) {
+                               ResourceBundle locale = ResourceBundle.getBundle("som",
+                                               getApplicationSettings().getCurrentLocale());
+                               SimpleDateFormat get = new SimpleDateFormat(locale
+                                               .getString("date.format"));
+                               docdate = get.parse(_documentDate);
                        }
                        // Creation of uses relations
+                       List<Long> uses = new ArrayList<Long>();
                        if (docuses != null) {
                                String[] list = docuses.split(",");
                                for (int i = 0; i < list.length; i++) {
-                                       Integer index = Integer.valueOf(list[i].trim());
-                                       Publication used = getPublication(index);
-                                       addoc.addDependency(used);
+                                       uses.add(Long.valueOf(list[i].trim()));
+                               }
+                       }
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug("Document to be imported uses documents with following ids:");
+                               for (Long usesId: uses) {
+                                       LOG.debug("#" + usesId);
                                }
                        }
+                       Publication addoc = getPublicationService().createDoc(
+                                       mystudy.getIndex(), step, _documentType, user.getIndex(),
+                                       filename, docname, state, _reference, _version, docdate,
+                                       uses);
+
+                       if (_reference.length() > 0) { // Importation of a not foreign document
+                               mystudy.updateSimulationContexts(); // In case of simulation contexts extracted from the imported document
+                       }
+
                        // Creation of derived the document formats
                        // Document ndoc = addoc.value();
                        // Converter send = getApplicationSettings().getConverter(ndoc.getType(), ndoc.getFormat());