From e23858177d9bb7d92d52c7dd3bfb8205663831db Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 17 Oct 2012 10:17:53 +0000 Subject: [PATCH] DocumentServiceImpl doesn't use Database class anymore. Import document is working. --- .../org/splat/service/DocumentService.java | 2 +- .../splat/service/DocumentServiceImpl.java | 52 ++++++++++++++----- .../org/splat/service/StepServiceImpl.java | 30 +++++++++-- .../src/spring/businessServiceContext.xml | 6 ++- 4 files changed, 69 insertions(+), 21 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentService.java b/Workspace/Siman-Common/src/org/splat/service/DocumentService.java index 952f529..967489c 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentService.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentService.java @@ -19,7 +19,7 @@ import org.splat.som.Step; /** * Document service interface. * - * @author RKV + * @author Roman Kozlov (RKV) * */ public interface DocumentService { diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java index d922281..1d06100 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java @@ -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 Roman Kozlov (RKV) * */ 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; + } + } diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 8752a5c..9df836e 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -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; + } } diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index e2fa81d..5505908 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -25,7 +25,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> class="org.splat.service.DocumentServiceImpl"> - + + - + + -- 2.39.2