From: rkv Date: Wed, 5 Dec 2012 16:46:06 +0000 (+0000) Subject: Import document action is fixed: uses relations are created now in the same transacti... X-Git-Tag: Root_Delivery1_2012_12_06~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f58726d58df847144c71d10de8c6f1918c28c77a;p=tools%2Fsiman.git Import document action is fixed: uses relations are created now in the same transaction as the imported document. --- diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java index e30099e..b3b4e4f 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java @@ -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 docuses) throws MissedPropertyException, + InvalidPropertyException, MultiplyDefinedException, IOException, + NotApplicableException, InterruptedException, ParseException; + /** * Create a new version of the document. * diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index 50abe39..020cee9 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -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 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; + } } diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 9ac1007..201c9e5 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -61,6 +61,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> + + diff --git a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java index c86a7d5..0a45e29 100644 --- a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java @@ -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 uses = new ArrayList(); 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());