]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
DocumentServiceImpl doesn't use Database class anymore. Import document is working.
authorrkv <rkv@opencascade.com>
Wed, 17 Oct 2012 10:17:53 +0000 (10:17 +0000)
committerrkv <rkv@opencascade.com>
Wed, 17 Oct 2012 10:17:53 +0000 (10:17 +0000)
Workspace/Siman-Common/src/org/splat/service/DocumentService.java
Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml

index 952f52954354777c0bb9fdf0d95ceeae2c9f1987..967489c7642c37f173f64643bf8ae56cca6881a4 100644 (file)
@@ -19,7 +19,7 @@ import org.splat.som.Step;
 /**
  * Document service interface.
  * 
- * @author RKV
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a> 
  * 
  */
 public interface DocumentService {
index d922281e761e42f555d9645acd96a83b36d4a5b9..1d06100c05b1246a3fa52378dd7a1f13fae1c528 100644 (file)
@@ -13,24 +13,26 @@ import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.Document.Properties;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.dao.som.DocumentDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.NotApplicableException;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.service.technical.ProjectSettingsServiceImpl;
+import org.splat.service.technical.RepositoryService;
 import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
  * Document service implementation.
  * 
- * @author RKV
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  * 
  */
 public class DocumentServiceImpl implements DocumentService {
@@ -43,6 +45,10 @@ public class DocumentServiceImpl implements DocumentService {
         * Injected project settings service.
         */
        private ProjectSettingsService _projectSettingsService;
+       /**
+        * Injected repository service.
+        */
+       private RepositoryService _repositoryService;
        /**
         * Injected document service.
         */
@@ -55,7 +61,6 @@ public class DocumentServiceImpl implements DocumentService {
         */
        @Transactional(readOnly = true)
        public Document selectDocument(long index) {
-               // -------------------------------------------------
                return getDocumentDAO().get(index);
        }
 
@@ -64,13 +69,11 @@ public class DocumentServiceImpl implements DocumentService {
         * 
         * @see org.splat.service.DocumentService#selectDocument(java.lang.String, java.lang.String)
         */
+       @Transactional(readOnly = true)
        public Document selectDocument(String refid, String version) {
-               // --------------------------------------------------------------------
-               StringBuffer query = new StringBuffer("from Document where did='")
-                               .append(refid).append("' and version='").append(version)
-                               .append("'");
-               return (Document) Database.getSession().createQuery(query.toString())
-                               .uniqueResult();
+               Criterion aCondition = Restrictions.and(Restrictions.eq("did", refid),
+                               Restrictions.eq("version", version));
+               return getDocumentDAO().findByCriteria(aCondition);
        }
 
        /**
@@ -112,7 +115,6 @@ public class DocumentServiceImpl implements DocumentService {
         * @return document reference name
         */
        private String generateEncodedName(Document aDoc, Study scope) {
-               // ------------------------------------------------
                StringBuffer encoding = new StringBuffer();
                FileNaming scheme = getProjectSettings().getFileNamingScheme();
                DecimalFormat tostring = new DecimalFormat(Document.suformat);
@@ -139,7 +141,6 @@ public class DocumentServiceImpl implements DocumentService {
         * @return file name
         */
        private String getEncodedRootName(Document aDoc, Study scope) {
-               // -----------------------------------------------
                FileNaming scheme = getProjectSettings().getFileNamingScheme();
 
                if (scheme == FileNaming.encoded)
@@ -156,7 +157,6 @@ public class DocumentServiceImpl implements DocumentService {
        public void initialize(Document aDoc, Properties dprop)
                        throws MissedPropertyException, InvalidPropertyException,
                        NotApplicableException {
-               // --------------------------------------------
                if (!aDoc.isUndefined())
                        throw new NotApplicableException(
                                        "Cannot initialize an existing Document");
@@ -181,11 +181,16 @@ public class DocumentServiceImpl implements DocumentService {
                } else {
                        aDoc.setLastModificationDate(dprop.getDate());
                }
-               Database.getSession().update(aDoc);
+               getDocumentDAO().update(aDoc);
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.DocumentService#getSaveDirectory(org.splat.dal.bo.som.Document)
+        */
        public java.io.File getSaveDirectory(Document aDoc) {
-               String mypath = Database.getRepositoryVaultPath()
+               String mypath = getRepositoryService().getRepositoryVaultPath()
                                + aDoc.getSourceFile().getRelativePath();
                String[] table = mypath.split("/");
 
@@ -253,4 +258,23 @@ public class DocumentServiceImpl implements DocumentService {
                _documentDAO = documentDAO;
        }
 
+       /**
+        * Get the repositoryService.
+        * 
+        * @return the repositoryService
+        */
+       public RepositoryService getRepositoryService() {
+               return _repositoryService;
+       }
+
+       /**
+        * Set the repositoryService.
+        * 
+        * @param repositoryService
+        *            the repositoryService to set
+        */
+       public void setRepositoryService(RepositoryService repositoryService) {
+               _repositoryService = repositoryService;
+       }
+
 }
index 8752a5cbd8c741af01271de0e753cd0245bdbee2..9df836e407d486653ed191c8fb10ad4cbc4083ad 100644 (file)
@@ -26,6 +26,7 @@ import org.splat.dal.bo.som.UsedByRelation;
 import org.splat.dal.bo.som.UsesRelation;
 import org.splat.dal.bo.som.VersionsRelation;
 import org.splat.dal.dao.som.Database;
+import org.splat.dal.dao.som.DocumentDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
@@ -34,6 +35,7 @@ import org.splat.kernel.NotApplicableException;
 import org.splat.service.technical.IndexService;
 import org.splat.som.Revision;
 import org.splat.som.Step;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * Step service implementation.
@@ -49,6 +51,10 @@ public class StepServiceImpl implements StepService {
         * Injected document service.
         */
        private DocumentService _documentService;
+       /**
+        * Injected document DAO.
+        */
+       private DocumentDAO _documentDAO;
        /**
         * Injected simulation context service.
         */
@@ -132,8 +138,8 @@ public class StepServiceImpl implements StepService {
       return true;
     }
 
+    @Transactional
     public Publication createDocument (Step aStep, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException {
-    //  -------------------------------------------------------------
           Document  newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
           getDocumentService().generateDocumentId(newdoc, dprop);
 
@@ -143,13 +149,12 @@ public class StepServiceImpl implements StepService {
 
 //        Identification and save
           newdoc.buildReferenceFrom(aStep.getOwnerStudy());
-          Database.getSession().save(newdoc);
+          getDocumentDAO().create(newdoc);
 
           return  new Publication(newdoc, aStep.getOwner());
         }
 
         public Publication assignDocument (Step aStep, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, NotApplicableException {
-    //  -------------------------------------------------------------
           String refid = dprop.getReference();
           if    (refid == null)    return null;
 
@@ -171,6 +176,7 @@ public class StepServiceImpl implements StepService {
           return versionDocument(aStep, base, new Document.Properties().setDescription(reason));
         }
 
+        @Transactional
         public Publication versionDocument (Step aStep, Publication base, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
     //  --------------------------------------------------------------------------------
           Document previous = base.value();
@@ -185,7 +191,7 @@ public class StepServiceImpl implements StepService {
           Document  newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
           getDocumentService().generateDocumentId(newdoc, dprop);
           newdoc.buildReferenceFrom(aStep.getOwner(), previous);
-          Database.getSession().save(newdoc);
+          getDocumentDAO().create(newdoc);
 
 //        Versioning
           if (summary == null) newdoc.addRelation( new VersionsRelation(newdoc, previous) );
@@ -246,4 +252,20 @@ public class StepServiceImpl implements StepService {
                        SimulationContextService simulationContextService) {
                _simulationContextService = simulationContextService;
        }
+
+       /**
+        * Get the documentDAO.
+        * @return the documentDAO
+        */
+       public DocumentDAO getDocumentDAO() {
+               return _documentDAO;
+       }
+
+       /**
+        * Set the documentDAO.
+        * @param documentDAO the documentDAO to set
+        */
+       public void setDocumentDAO(DocumentDAO documentDAO) {
+               _documentDAO = documentDAO;
+       }
 }
index e2fa81d86644c2e6e85e2fdd4c1f38953c893ac1..5505908e969bd85a72515f668ac35b0fe49d3087 100644 (file)
@@ -25,7 +25,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                class="org.splat.service.DocumentServiceImpl">
                <property name="projectSettings" ref="projectSettings" />
                <property name="studyService" ref="studyService" />
-               <property name="documentDAO" ref="documentDAO" />
+        <property name="documentDAO" ref="documentDAO" />
+        <property name="repositoryService" ref="repositoryService" />
        </bean>
 
        <bean id="knowledgeElementService"
@@ -62,7 +63,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
        <bean id="stepService" class="org.splat.service.StepServiceImpl">
                <property name="indexService" ref="indexService" />
-               <property name="documentService" ref="documentService" />
+        <property name="documentDAO" ref="documentDAO" />
+        <property name="documentService" ref="documentService" />
                <property name="simulationContextService"
                        ref="simulationContextService" />
        </bean>