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;
*/
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.
*
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;
* Injected document service.
*/
private DocumentService _documentService;
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
+ /**
+ * Injected user service.
+ */
+ private UserService _userService;
/**
* Injected project element service.
*/
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}
*
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;
+ }
}
<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" />
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;
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());