From 7e0fe9305bd10b412474f37cec58c97c610158a4 Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 17 Oct 2012 12:48:40 +0000 Subject: [PATCH 1/1] StepServiceImpl doesn't use Database class anymore. --- .../src/org/splat/dal/bo/som/Scenario.java | 24 +- .../org/splat/service/StepServiceImpl.java | 394 +++++++++++++----- .../src/spring/businessServiceContext.xml | 8 +- .../Siman-Common/src/spring/daoContext.xml | 26 +- 4 files changed, 323 insertions(+), 129 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java index 54a119f..f4458be 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java @@ -254,23 +254,6 @@ public class Scenario extends ProjectElement { return (cuser != null); } - - -// ============================================================================================================================== -// Protected member function -// ============================================================================================================================== - - public void updateMyIndex (IndexService lucin) throws IOException { -// ------------------------------------------ - if (ucase == null) for (Iterator i=kelms.iterator(); i.hasNext(); ) { - KnowledgeElement kelm = i.next(); - if (!kelm.getType().equals("usecase")) continue; - ucase = kelm; - break; - } - lucin.update(ucase); - } - // ============================================================================================================================== // Private services // ============================================================================================================================== @@ -292,4 +275,11 @@ public class Scenario extends ProjectElement { public List getKnowledgeElementsList() { return knowl; } + /** + * Get the ucase. + * @return the ucase + */ + public KnowledgeElement getUcase() { + return ucase; + } } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 9df836e..ccb0fac 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -14,7 +14,6 @@ import java.io.IOException; import java.util.Iterator; import java.util.List; -import org.hibernate.Session; import org.splat.dal.bo.kernel.Relation; import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.KnowledgeElement; @@ -25,13 +24,15 @@ import org.splat.dal.bo.som.Study; 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.dal.dao.som.ProjectElementDAO; +import org.splat.dal.dao.som.SimulationContextDAO; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MismatchException; import org.splat.kernel.MissedPropertyException; import org.splat.kernel.MultiplyDefinedException; import org.splat.kernel.NotApplicableException; +import org.splat.log.AppLogger; import org.splat.service.technical.IndexService; import org.splat.som.Revision; import org.splat.som.Step; @@ -39,10 +40,16 @@ import org.springframework.transaction.annotation.Transactional; /** * Step service implementation. + * * @author Roman Kozlov (RKV) */ public class StepServiceImpl implements StepService { + /** + * logger for the service. + */ + public final static AppLogger logger = AppLogger + .getLogger(StepServiceImpl.class); /** * Injected index service. */ @@ -59,7 +66,20 @@ public class StepServiceImpl implements StepService { * Injected simulation context service. */ private SimulationContextService _simulationContextService; + /** + * Injected simulation context DAO. + */ + private SimulationContextDAO _simulationContextDAO; + /** + * Injected project element DAO. + */ + private ProjectElementDAO _projectElementDAO; + /** + * {@inheritDoc} + * + * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext.Properties) + */ public SimulationContext addSimulationContext(Step aStep, SimulationContext.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, @@ -69,20 +89,23 @@ public class StepServiceImpl implements StepService { return addSimulationContext(aStep, context); } + /** + * {@inheritDoc} + * + * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext) + */ + @Transactional public SimulationContext addSimulationContext(Step aStep, SimulationContext context) { getSimulationContextService().hold(context); // Increments the reference count of simulation context if (aStep.getOwner().isSaved()) try { - Session session = Database.getSession(); - IndexService lucin = getIndexService(); - if (!context.isSaved()) - session.save(context); + getSimulationContextDAO().create(context); aStep.getOwner().add(context); aStep.getContex().add(context); // The context is also referenced from this (transient) Step - session.update(aStep.getOwner()); - updateKnowledgeElementsIndex(aStep, lucin); + getProjectElementDAO().update(aStep.getOwner()); + updateKnowledgeElementsIndex(aStep); } catch (Exception error) { return null; } @@ -94,8 +117,13 @@ public class StepServiceImpl implements StepService { return context; } - private void updateKnowledgeElementsIndex(Step aStep, IndexService lucin) { - // ------------------------------------------------------ + /** + * Update lucene index of knowledge elements of a scenario or a study which the given step is related to. + * + * @param aStep + * the step (activity) + */ + private void updateKnowledgeElementsIndex(Step aStep) { Scenario[] scenarii; if (aStep.getOwner() instanceof Scenario) { scenarii = new Scenario[1]; @@ -110,118 +138,200 @@ public class StepServiceImpl implements StepService { for (Iterator j = knelm.iterator(); j .hasNext();) { KnowledgeElement kelm = j.next(); - lucin.update(kelm); + getIndexService().update(kelm); } - scene.updateMyIndex(lucin); + updateScenarioIndex(scene); } } catch (Exception error) { - // logger.error("Unable to re-index Knowledge Elements, reason:", error); + logger.error("Unable to re-index Knowledge Elements, reason:", error); + } + } + + /** + * Update lucene index for knowledge elements of the scenario. + * + * @param scene + * the scenario + * @throws IOException + * if can't update lucene index + */ + private void updateScenarioIndex(Scenario scene) throws IOException { + if (scene.getUcase() == null) { + for (Iterator i = scene.getKnowledgeElements() + .iterator(); i.hasNext();) { + KnowledgeElement kelm = i.next(); + if (!kelm.getType().equals("usecase")) + continue; + scene.setUcase(kelm); + break; + } } + getIndexService().update(scene.getUcase()); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext) + */ + @Transactional + public boolean removeSimulationContext(Step aStep, SimulationContext context) { + boolean isOk = false; + SimulationContext torem = aStep + .getSimulationContext(context.getIndex()); + + if ((torem != null) && (aStep.getOwner().remove(torem))) { + + aStep.getContex().remove(torem); + getProjectElementDAO().update(aStep.getOwner()); + if (torem.isShared()) { + getSimulationContextService().release(torem); + getSimulationContextDAO().update(torem); + } else { + getSimulationContextDAO().delete(torem); + } + isOk = true; + } + return isOk; + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties) + */ + @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); + + // Creation of the save directory + File wdir = getDocumentService().getSaveDirectory(newdoc); + if (!wdir.exists()) + if (!wdir.mkdirs()) + throw new IOException( + "Cannot create the repository vault directory"); + + // Identification and save + newdoc.buildReferenceFrom(aStep.getOwnerStudy()); + getDocumentDAO().create(newdoc); + + return new Publication(newdoc, aStep.getOwner()); } - public boolean removeSimulationContext (Step aStep, SimulationContext context) { -// ------------------------------------------------------------------ - SimulationContext torem = aStep.getSimulationContext(context.getIndex()); - Session session = Database.getSession(); - - if (torem == null) return false; - if (!aStep.getOwner().remove(torem)) return false; - - aStep.getContex().remove(torem); - session.update(aStep.getOwner()); - if (torem.isShared()) { - getSimulationContextService().release(torem); - session.update(torem); - } else { - session.delete(torem); - } - 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); - -// Creation of the save directory - File wdir = getDocumentService().getSaveDirectory(newdoc); - if (!wdir.exists()) if (!wdir.mkdirs()) throw new IOException("Cannot create the repository vault directory"); - -// Identification and save - newdoc.buildReferenceFrom(aStep.getOwnerStudy()); - 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; - - Document slot = getDocumentService().selectDocument(refid, new Revision().toString()); - if ( slot == null ) return null; - if (!slot.isUndefined()) return null; // Should not happen - - getDocumentService().initialize(slot, dprop.setOwner(aStep.getOwnerStudy())); - return new Publication(slot, aStep.getOwner()); - } - - public Publication versionDocument (Step aStep, Publication base) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException { - // ----------------------------------------------------- - return versionDocument(aStep, base, new Document.Properties()); - } - - public Publication versionDocument (Step aStep, Publication base, String reason) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException { - // -------------------------------------------------------------------- - 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(); - - dprop.setDocument(previous); // Initializes the Step property - if (dprop.getStep().getNumber() != aStep.getNumber()) throw new MismatchException(); - - if (dprop.getAuthor() == null) dprop.setAuthor(previous.getAuthor()); - String summary = dprop.getDescription(); - -// Creation of the document - Document newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep())); - getDocumentService().generateDocumentId(newdoc, dprop); - newdoc.buildReferenceFrom(aStep.getOwner(), previous); - getDocumentDAO().create(newdoc); - -// Versioning - if (summary == null) newdoc.addRelation( new VersionsRelation(newdoc, previous) ); - else newdoc.addRelation( new VersionsRelation(newdoc, previous, summary) ); - -// Update of usedby relations, if exist - List relist = previous.getRelations(UsedByRelation.class); - Study scope = aStep.getOwnerStudy(); - for (Iterator i=relist.iterator(); i.hasNext();) { - UsedByRelation relation = (UsedByRelation)i.next(); - Document relatedoc = relation.getTo(); - if (scope.shares(relatedoc)) relatedoc.addRelation( new UsesRelation(relatedoc, newdoc) ); - else relation.moveTo(newdoc); - } - return new Publication(newdoc, aStep.getOwner()); - } + /** + * {@inheritDoc} + * + * @see org.splat.service.StepService#assignDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties) + */ + public Publication assignDocument(Step aStep, Document.Properties dprop) + throws MissedPropertyException, InvalidPropertyException, + NotApplicableException { + String refid = dprop.getReference(); + if (refid == null) + return null; + + Document slot = getDocumentService().selectDocument(refid, + new Revision().toString()); + if (slot == null) + return null; + if (!slot.isUndefined()) + return null; // Should not happen + + getDocumentService().initialize(slot, + dprop.setOwner(aStep.getOwnerStudy())); + return new Publication(slot, aStep.getOwner()); + } /** + * @param aStep + * @param base * @return + * @throws MissedPropertyException + * @throws InvalidPropertyException + * @throws MultiplyDefinedException + * @throws IOException + * @throws MismatchException */ - public IndexService getIndexService() { - return _indexService; + public Publication versionDocument(Step aStep, Publication base) + throws MissedPropertyException, InvalidPropertyException, + MultiplyDefinedException, IOException, MismatchException { + return versionDocument(aStep, base, new Document.Properties()); } - public void setIndexService(IndexService indexService) { - _indexService = indexService; + /** + * @param aStep + * @param base + * @param reason + * @return + * @throws MissedPropertyException + * @throws InvalidPropertyException + * @throws MultiplyDefinedException + * @throws IOException + * @throws MismatchException + */ + public Publication versionDocument(Step aStep, Publication base, + String reason) throws MissedPropertyException, + InvalidPropertyException, MultiplyDefinedException, IOException, + MismatchException { + return versionDocument(aStep, base, new Document.Properties() + .setDescription(reason)); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.StepService#versionDocument(org.splat.som.Step, org.splat.dal.bo.som.Publication, + * org.splat.dal.bo.som.Document.Properties) + */ + @Transactional + public Publication versionDocument(Step aStep, Publication base, + Document.Properties dprop) throws MissedPropertyException, + InvalidPropertyException, MultiplyDefinedException, IOException, + MismatchException { + Document previous = base.value(); + + dprop.setDocument(previous); // Initializes the Step property + if (dprop.getStep().getNumber() != aStep.getNumber()) + throw new MismatchException(); + + if (dprop.getAuthor() == null) + dprop.setAuthor(previous.getAuthor()); + String summary = dprop.getDescription(); + + // Creation of the document + Document newdoc = new Document(dprop.setOwner(aStep.getOwner()) + .setStep(aStep.getStep())); + getDocumentService().generateDocumentId(newdoc, dprop); + newdoc.buildReferenceFrom(aStep.getOwner(), previous); + getDocumentDAO().create(newdoc); + + // Versioning + if (summary == null) + newdoc.addRelation(new VersionsRelation(newdoc, previous)); + else + newdoc.addRelation(new VersionsRelation(newdoc, previous, summary)); + + // Update of usedby relations, if exist + List relist = previous.getRelations(UsedByRelation.class); + Study scope = aStep.getOwnerStudy(); + for (Iterator i = relist.iterator(); i.hasNext();) { + UsedByRelation relation = (UsedByRelation) i.next(); + Document relatedoc = relation.getTo(); + if (scope.shares(relatedoc)) + relatedoc.addRelation(new UsesRelation(relatedoc, newdoc)); + else + relation.moveTo(newdoc); + } + return new Publication(newdoc, aStep.getOwner()); } /** * Get the documentService. + * * @return the documentService */ public DocumentService getDocumentService() { @@ -230,7 +340,9 @@ public class StepServiceImpl implements StepService { /** * Set the documentService. - * @param documentService the documentService to set + * + * @param documentService + * the documentService to set */ public void setDocumentService(DocumentService documentService) { _documentService = documentService; @@ -238,6 +350,7 @@ public class StepServiceImpl implements StepService { /** * Get the simulationContextService. + * * @return the simulationContextService */ public SimulationContextService getSimulationContextService() { @@ -246,7 +359,9 @@ public class StepServiceImpl implements StepService { /** * Set the simulationContextService. - * @param simulationContextService the simulationContextService to set + * + * @param simulationContextService + * the simulationContextService to set */ public void setSimulationContextService( SimulationContextService simulationContextService) { @@ -255,6 +370,7 @@ public class StepServiceImpl implements StepService { /** * Get the documentDAO. + * * @return the documentDAO */ public DocumentDAO getDocumentDAO() { @@ -263,9 +379,69 @@ public class StepServiceImpl implements StepService { /** * Set the documentDAO. - * @param documentDAO the documentDAO to set + * + * @param documentDAO + * the documentDAO to set */ public void setDocumentDAO(DocumentDAO documentDAO) { _documentDAO = documentDAO; } + + /** + * Get the simulationContextDAO. + * + * @return the simulationContextDAO + */ + public SimulationContextDAO getSimulationContextDAO() { + return _simulationContextDAO; + } + + /** + * Set the simulationContextDAO. + * + * @param simulationContextDAO + * the simulationContextDAO to set + */ + public void setSimulationContextDAO( + SimulationContextDAO simulationContextDAO) { + _simulationContextDAO = simulationContextDAO; + } + + /** + * Get the projectElementDAO. + * + * @return the projectElementDAO + */ + public ProjectElementDAO getProjectElementDAO() { + return _projectElementDAO; + } + + /** + * Set the projectElementDAO. + * + * @param projectElementDAO + * the projectElementDAO to set + */ + public void setProjectElementDAO(ProjectElementDAO projectElementDAO) { + _projectElementDAO = projectElementDAO; + } + + /** + * Get the indexService. + * + * @return the indexService + */ + public IndexService getIndexService() { + return _indexService; + } + + /** + * Set the indexService. + * + * @param indexService + * the indexService to set + */ + public void setIndexService(IndexService indexService) { + _indexService = indexService; + } } diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 5505908..4592bf7 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -65,8 +65,12 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> - + + + - + + + + + + + + + + + + + + + + @@ -18,6 +38,10 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> class="org.splat.dal.dao.kernel.UserDAOImpl"> + + + -- 2.39.2