]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java
Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / DocumentServiceImpl.java
index df410aa36a93ec9ad76d9e850cf3c87d00402e6d..508ebfc23dcae0edde0e8c0827e8b4de0b31dcf6 100644 (file)
@@ -15,7 +15,6 @@ import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
 
-import org.hibernate.Hibernate;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Restrictions;
 import org.splat.dal.bo.kernel.Relation;
@@ -37,7 +36,6 @@ import org.splat.dal.dao.som.DocumentTypeDAO;
 import org.splat.dal.dao.som.FileDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
-import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.NotApplicableException;
 import org.splat.manox.Reader;
 import org.splat.manox.Toolbox;
@@ -121,8 +119,8 @@ public class DocumentServiceImpl implements DocumentService {
                String path = owner.getReference();
                ProjectSettingsService.Step step = ProjectSettingsServiceImpl
                                .getStep(aDoc.getStep());
-               aDoc.setDid(new StringBuffer(path).append(".%").append(
-                               Document.suformat).toString()); // Document reference
+               aDoc.setDid(new StringBuffer(path).append(".%")
+                               .append(Document.suformat).toString()); // Document reference
                path = new StringBuffer(year).append("/").append(path).append("/")
                                .append(step.getPath())
                                // File path relative to the repository vault
@@ -149,11 +147,11 @@ public class DocumentServiceImpl implements DocumentService {
                int number = getStudyService().generateLocalIndex(scope);
 
                if (scheme == FileNaming.encoded) {
-                       encoding.append(scope.getReference()).append(".").append(
-                                       tostring.format(number));
+                       encoding.append(scope.getReference()).append(".")
+                                       .append(tostring.format(number));
                } else { // title and (temporarily) asis
-                       encoding.append(aDoc.getTitle()).append(".").append(
-                                       tostring.format(number));
+                       encoding.append(aDoc.getTitle()).append(".")
+                                       .append(tostring.format(number));
                }
                return encoding.toString();
        }
@@ -199,8 +197,12 @@ public class DocumentServiceImpl implements DocumentService {
                // }
                aDoc.setTitle(dprop.getName());
                aDoc.getFile().changePath(
-                               aDoc.getFile().getRelativePath().replace("%n",
-                                               getEncodedRootName(aDoc, (Study) dprop.getOwner())));
+                               aDoc.getFile()
+                                               .getRelativePath()
+                                               .replace(
+                                                               "%n",
+                                                               getEncodedRootName(aDoc,
+                                                                               (Study) dprop.getOwner())));
                if (aDoc.getHistory() == -1)
                        aDoc.setHistory(0);
                if (dprop.getDate() == null) {
@@ -568,6 +570,23 @@ public class DocumentServiceImpl implements DocumentService {
                return (aType.isResultOf(lastep));
        }
 
+       /**
+        * Get document by its path.
+        * @param path the document path
+        * @return the document if found or null
+        */
+       @Transactional(readOnly=true)
+       public Document getDocumentByPath(String path) {
+               String[] parse = path.split("'");
+
+               path = parse[0];
+               for (int i = 1; i < parse.length; i++) {
+                       path = path + "''" + parse[i];
+               }
+               Criterion aCondition = Restrictions.eq("path", path);
+               return getDocumentDAO().findByCriteria(aCondition);
+       }
+
        /**
         * Get the studyService.
         *