From 4219c15be3b42f18424b12d1b52d97ece0ed70ef Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 10 Oct 2012 15:59:57 +0000 Subject: [PATCH] Beans initialization is fixed. Document can be added to study now. --- .../src/org/splat/dal/bo/som/Document.java | 194 ++--- .../src/org/splat/dal/bo/som/File.java | 2 +- .../org/splat/service/DocumentService.java | 26 +- .../splat/service/DocumentServiceImpl.java | 141 ++++ .../service/DocumentTypeServiceImpl.java | 6 +- .../splat/service/PublicationServiceImpl.java | 2 +- .../splat/service/ScenarioServiceImpl.java | 2 +- .../src/org/splat/service/StepService.java | 19 + .../org/splat/service/StepServiceImpl.java | 100 +++ .../org/splat/service/StudyServiceImpl.java | 27 +- .../Siman-Common/src/org/splat/som/Step.java | 70 +- .../src/spring/businessServiceContext.xml | 10 +- .../org/splat/module/SaveDocumentAction.java | 4 +- .../src/org/splat/simer/DocumentFacade.java | 663 ++++++++++-------- .../org/splat/simer/ImportDocumentAction.java | 22 +- .../src/org/splat/simer/OpenKnowledge.java | 17 - .../Siman/src/org/splat/simer/OpenObject.java | 42 +- .../Siman/src/org/splat/simer/OpenStudy.java | 43 +- .../splat/simer/VersionDocumentAction.java | 22 +- .../simer/admin/SimulationContextAction.java | 4 +- .../simer/admin/SimulationContextFacade.java | 20 +- .../Siman/src/spring/applicationContext.xml | 4 + 22 files changed, 888 insertions(+), 552 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java index 9669171..4f664c9 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java @@ -149,6 +149,14 @@ public class Document extends Entity { return this; } + /** + * Get the date. + * @return the date + */ + public Date getDate() { + return date; + } + public Properties setDescription(String summary) throws InvalidPropertyException { if (summary.length() == 0) @@ -200,12 +208,19 @@ public class Document extends Entity { this.name = name; return this; } + + public String getName() { + return this.name; + } public Properties setOwner(ProjectElement owner) { this.owner = owner; return this; } + public ProjectElement getOwner() { + return this.owner; + } // Required only for passing search arguments public Properties setReference(String did) throws InvalidPropertyException { @@ -289,30 +304,10 @@ public class Document extends Entity { state = ProgressState.inWORK; // Promoted when saving this document version = new Revision().toString(); } - Study owner = null; - if (dprop.owner instanceof Study) - owner = (Study) dprop.owner; - else - owner = ((Scenario) dprop.owner).getOwnerStudy(); - - ProjectSettingsService.Step step = ProjectSettingsServiceImpl - .getStep(this.step); - SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); - String year = tostring.format(owner.getDate()); if (name == null) { // Newed document this.name = "%n"; // Named later at publication this.history = -1; // Marks the document as undefined for future assignment } - String filename = generateEncodedName(owner); - String path; - - path = owner.getReference(); - did = new StringBuffer(path).append(".%").append(suformat).toString(); // Document reference - path = new StringBuffer(year).append("/").append(path).append("/") - .append(step.getPath()) // File path relative to the repository vault - .append(filename).append(".").append(myfile.getFormat()) // File name and extension - .toString(); - myfile.changePath(path); } // ============================================================================================================================== @@ -345,6 +340,10 @@ public class Document extends Entity { // -------------------------------------- return lasdate; } + + public void setLastModificationDate(Date aDate) { + lasdate = aDate; + } public String getFormat() { // -------------------------- @@ -446,6 +445,14 @@ public class Document extends Entity { else return name; } + + /** + * Set document title. + * @param aTitle document title to set + */ + public void setTitle(String aTitle) { + this.name = aTitle; + } public DocumentType getType() { // ------------------------------ @@ -454,9 +461,8 @@ public class Document extends Entity { /** * Returns the version number of this document. The version number, when exists, is either of the internal form (m.n.s) usable for - * building a Revision object, or any string in case of external document (document with EXTERN state).
- *
- * Note: document slots have a version number equal to "0.0.0". + * building a Revision object, or any string in case of external document (document with EXTERN state).

Note: document slots + * have a version number equal to "0.0.0". * * @return the version number of this document, or null if this is EXTERN. * @see #isUndefined() @@ -579,9 +585,8 @@ public class Document extends Entity { ProjectSettingsService.Step step) { // -------------------------------------------------------------------------- Integer number = step.getNumber(); - String query = new StringBuffer("from DocumentType") - .append(" where step like '%-").append(number).append("-%'") - .toString(); + String query = new StringBuffer("from DocumentType").append( + " where step like '%-").append(number).append("-%'").toString(); List types = Database.getSession().createQuery(query) .list(); @@ -642,8 +647,8 @@ public class Document extends Entity { return false; DecimalFormat tostring = new DecimalFormat(suformat); - did = did.replace("%" + suformat, - tostring.format(scope.getLastLocalIndex())); + did = did.replace("%" + suformat, tostring.format(scope + .getLastLocalIndex())); return true; } @@ -688,44 +693,6 @@ public class Document extends Entity { Database.getSession().update(this); } - /** - * Defines this document. - * - * @param dprop - * the properties of the document - * - * @see Step#createDocument(Properties) - * @see #isUndefined() - */ - public void initialize(Properties dprop) throws MissedPropertyException, - InvalidPropertyException, NotApplicableException { - // -------------------------------------------- - if (!this.isUndefined()) - throw new NotApplicableException( - "Cannot initialize an existing Document"); - if (dprop.name == null) - throw new MissedPropertyException("name"); - if (dprop.name.length() == 0) - throw new InvalidPropertyException("name"); - if (dprop.owner == null) - throw new MissedPropertyException("owner"); - // if (dprop.owner instanceof Study && !ProjectSettings.getStep(step).appliesTo(Study.class)) { - // throw new InvalidPropertyException("step"); - // } - name = dprop.name; - myfile.changePath(myfile.getRelativePath().replace("%n", - getEncodedRootName((Study) dprop.owner))); - if (history == -1) - history = 0; - if (dprop.date == null) { - Calendar current = Calendar.getInstance(); - lasdate = current.getTime(); // Today - } else { - lasdate = dprop.date; - } - Database.getSession().update(this); - } - public boolean promote(Timestamp stamp) { // ------------------------------------------- ProgressState newstate = null; @@ -837,37 +804,6 @@ public class Document extends Entity { // TODO: Promote documents using this one // } - // ============================================================================================================================== - // Private services - // ============================================================================================================================== - - private String generateEncodedName(Study scope) { - // ------------------------------------------------ - StringBuffer encoding = new StringBuffer(); - FileNaming scheme = getProjectSettingsService().getFileNamingScheme(); - DecimalFormat tostring = new DecimalFormat(suformat); - - int number = getStudyService().generateLocalIndex(scope); - - if (scheme == FileNaming.encoded) { - encoding.append(scope.getReference()).append(".") - .append(tostring.format(number)); - } else { // title and (temporarily) asis - encoding.append(name).append(".").append(tostring.format(number)); - } - return encoding.toString(); - } - - private String getEncodedRootName(Study scope) { - // ----------------------------------------------- - FileNaming scheme = getProjectSettingsService().getFileNamingScheme(); - - if (scheme == FileNaming.encoded) - return scope.getReference(); - else - return name; - } - /** * @return */ @@ -890,4 +826,68 @@ public class Document extends Entity { public void setStudyService(StudyService studyService) { _studyService = studyService; } + + /** + * Get the step. + * @return the step + */ + public int getStep() { + return step; + } + + /** + * Set the step. + * @param step the step to set + */ + public void setStep(int step) { + this.step = step; + } + + /** + * Get the did. + * @return the did + */ + public String getDid() { + return did; + } + + /** + * Set the did. + * @param did the did to set + */ + public void setDid(String did) { + this.did = did; + } + + /** + * Get the myfile. + * @return the myfile + */ + public File getFile() { + return myfile; + } + + /** + * Set the myfile. + * @param myfile the myfile to set + */ + public void setFile(File myfile) { + this.myfile = myfile; + } + + /** + * Get the history. + * @return the history + */ + public int getHistory() { + return history; + } + + /** + * Set the history. + * @param history the history to set + */ + public void setHistory(int history) { + this.history = history; + } } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/File.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/File.java index 9da39a7..64f2998 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/File.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/File.java @@ -102,7 +102,7 @@ public class File extends Persistent { // Protected service // ============================================================================================================================== - protected void changePath (String path) { + public void changePath (String path) { // --------------------------------------- this.path = path; this.myfile = null; diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentService.java b/Workspace/Siman-Common/src/org/splat/service/DocumentService.java index d2b2218..a956b69 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentService.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentService.java @@ -7,12 +7,34 @@ * @version $Revision$ *****************************************************************************/ -package org.splat.service; +package org.splat.service; + +import org.splat.dal.bo.som.Document; +import org.splat.dal.bo.som.Publication; +import org.splat.dal.bo.som.Document.Properties; +import org.splat.kernel.InvalidPropertyException; +import org.splat.kernel.MissedPropertyException; +import org.splat.kernel.NotApplicableException; +import org.splat.som.Step; /** * @author RKV - * + * */ public interface DocumentService { + /** + * Defines this document. + * + * @param dprop + * the properties of the document + * + * @see Step#createDocument(Properties) + * @see #isUndefined() + */ + public void initialize(Document aDoc, Properties dprop) + throws MissedPropertyException, InvalidPropertyException, + NotApplicableException; + + public void generateDocumentId(Document aDoc, Properties dprop); } diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java index cd86e08..fef0b99 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java @@ -9,10 +9,151 @@ package org.splat.service; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +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.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.ProjectSettingsServiceImpl.FileNaming; +import org.splat.som.Step; + /** * @author RKV * */ public class DocumentServiceImpl implements DocumentService { + private StudyService _studyService; + private ProjectSettingsService _projectSettingsService; + + public void generateDocumentId(Document aDoc, Properties dprop) { + Study owner = null; + if (dprop.getOwner() instanceof Study) + owner = (Study) dprop.getOwner(); + else + owner = ((Scenario) dprop.getOwner()).getOwnerStudy(); + + SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); + String year = tostring.format(owner.getDate()); + String filename = generateEncodedName(aDoc, owner); + String path = owner.getReference(); + ProjectSettingsService.Step step = ProjectSettingsServiceImpl + .getStep(aDoc.getStep()); + aDoc.setDid( new StringBuffer(path).append(".%").append(aDoc.suformat).toString()); // Document reference + path = new StringBuffer(year).append("/").append(path).append("/") + .append(step.getPath()) // File path relative to the repository vault + .append(filename).append(".").append(aDoc.getFile().getFormat()) // File name and extension + .toString(); + aDoc.getFile().changePath(path); + } + + private String generateEncodedName(Document aDoc, Study scope) { + // ------------------------------------------------ + StringBuffer encoding = new StringBuffer(); + FileNaming scheme = getProjectSettings().getFileNamingScheme(); + DecimalFormat tostring = new DecimalFormat(aDoc.suformat); + + int number = getStudyService().generateLocalIndex(scope); + + if (scheme == FileNaming.encoded) { + encoding.append(scope.getReference()).append(".").append( + tostring.format(number)); + } else { // title and (temporarily) asis + encoding.append(aDoc.getTitle()).append(".").append(tostring.format(number)); + } + return encoding.toString(); + } + + private String getEncodedRootName(Document aDoc, Study scope) { + // ----------------------------------------------- + FileNaming scheme = getProjectSettings().getFileNamingScheme(); + + if (scheme == FileNaming.encoded) + return scope.getReference(); + else + return aDoc.getTitle(); + } + + /** + * Defines this document. + * + * @param dprop + * the properties of the document + * + * @see Step#createDocument(Properties) + * @see #isUndefined() + */ + public void initialize(Document aDoc, Properties dprop) throws MissedPropertyException, + InvalidPropertyException, NotApplicableException { + // -------------------------------------------- + if (!aDoc.isUndefined()) + throw new NotApplicableException( + "Cannot initialize an existing Document"); + if (dprop.getName() == null) + throw new MissedPropertyException("name"); + if (dprop.getName().length() == 0) + throw new InvalidPropertyException("name"); + if (dprop.getOwner() == null) + throw new MissedPropertyException("owner"); + // if (dprop.owner instanceof Study && !ProjectSettings.getStep(step).appliesTo(Study.class)) { + // throw new InvalidPropertyException("step"); + // } + aDoc.setTitle(dprop.getName()); + aDoc.getFile().changePath(aDoc.getFile().getRelativePath().replace("%n", + getEncodedRootName(aDoc, (Study) dprop.getOwner()))); + if (aDoc.getHistory() == -1) + aDoc.setHistory( 0 ); + if (dprop.getDate() == null) { + Calendar current = Calendar.getInstance(); + aDoc.setLastModificationDate(current.getTime()); // Today + } else { + aDoc.setLastModificationDate(dprop.getDate()); + } + Database.getSession().update(aDoc); + } + + /** + * Get the studyService. + * @return the studyService + */ + public StudyService getStudyService() { + return _studyService; + } + + /** + * Set the studyService. + * @param studyService the studyService to set + */ + public void setStudyService(StudyService studyService) { + _studyService = studyService; + } + + /** + * Get project settings. + * + * @return Project settings service + */ + private ProjectSettingsService getProjectSettings() { + return _projectSettingsService; + } + + /** + * Set project settings service. + * + * @param projectSettingsService + * project settings service + */ + public void setProjectSettings(ProjectSettingsService projectSettingsService) { + _projectSettingsService = projectSettingsService; + } + } diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java index 5a717a1..c88ec88 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java @@ -32,7 +32,7 @@ public class DocumentTypeServiceImpl implements DocumentTypeService { */ public boolean isStudyResult (DocumentType aType) { // ------------------------------- - List step = getProjectSettingsService().getAllSteps(); + List step = getProjectSettings().getAllSteps(); ProjectSettingsService.Step lastep = step.get( step.size()-1 ); return (aType.isResultOf(lastep)); } @@ -40,11 +40,11 @@ public class DocumentTypeServiceImpl implements DocumentTypeService { /** * @return */ - public ProjectSettingsService getProjectSettingsService() { + public ProjectSettingsService getProjectSettings() { return _projectSettingsService; } - public void setProjectSettingsService( + public void setProjectSettings( ProjectSettingsService projectSettingsService) { _projectSettingsService = projectSettingsService; } diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index 8f64387..7fb730b 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -286,7 +286,7 @@ public class PublicationServiceImpl implements PublicationService { throw new FileNotFoundException(); if (state == ProgressState.inWORK || state == ProgressState.EXTERN) { - Database.getSession().save(this); // Must be done before updating the study in order to fix this final (rid-based) hascode + Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode aPublication.value().updateAs(state); } else { DocumentType mytype = aPublication.value().getType(); diff --git a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java index 003c4db..8cf54cd 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java @@ -176,7 +176,7 @@ public class ScenarioServiceImpl implements ScenarioService { aScenario.setUser(user); aScenario.setLastModificationDate(Calendar.getInstance().getTime()); - Database.getSession().update(this); + Database.getSession().update(aScenario); return true; } diff --git a/Workspace/Siman-Common/src/org/splat/service/StepService.java b/Workspace/Siman-Common/src/org/splat/service/StepService.java index 9a0457a..871a0b9 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepService.java @@ -9,10 +9,16 @@ package org.splat.service; +import java.io.IOException; + +import org.splat.dal.bo.som.Document; +import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.SimulationContext; 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.som.Step; /** @@ -21,6 +27,19 @@ import org.splat.som.Step; */ public interface StepService { + public Publication createDocument(Step aStep, Document.Properties dprop) + throws MissedPropertyException, InvalidPropertyException, + MultiplyDefinedException, IOException; + + public Publication assignDocument(Step aStep, Document.Properties dprop) + throws MissedPropertyException, InvalidPropertyException, + NotApplicableException; + + public Publication versionDocument(Step aStep, Publication base, + Document.Properties dprop) throws MissedPropertyException, + InvalidPropertyException, MultiplyDefinedException, IOException, + MismatchException; + public SimulationContext addSimulationContext(Step aStep, SimulationContext.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index dda84d6..353477e 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -9,19 +9,31 @@ package org.splat.service; +import java.io.File; +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; +import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; +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.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.service.technical.IndexService; import org.splat.service.technical.IndexServiceImpl; +import org.splat.som.Revision; import org.splat.som.Step; /** @@ -31,6 +43,7 @@ import org.splat.som.Step; public class StepServiceImpl implements StepService { private IndexService _indexService; + private DocumentService _documentService; public SimulationContext addSimulationContext(Step aStep, SimulationContext.Properties dprop) throws MissedPropertyException, @@ -112,6 +125,77 @@ public class StepServiceImpl implements StepService { return true; } + 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 = newdoc.getSaveDirectory(); + if (!wdir.exists()) if (!wdir.mkdirs()) throw new IOException("Cannot create the repository vault directory"); + +// Identification and save + newdoc.buildReferenceFrom(aStep.getOwnerStudy()); + Database.getSession().save(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 = Database.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)); + } + + 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); + Database.getSession().save(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()); + } + /** * @return */ @@ -122,4 +206,20 @@ public class StepServiceImpl implements StepService { public void setIndexService(IndexService indexService) { _indexService = indexService; } + + /** + * Get the documentService. + * @return the documentService + */ + public DocumentService getDocumentService() { + return _documentService; + } + + /** + * Set the documentService. + * @param documentService the documentService to set + */ + public void setDocumentService(DocumentService documentService) { + _documentService = documentService; + } } diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java index a9fe8b4..d0b9a56 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java @@ -122,17 +122,6 @@ public class StudyServiceImpl implements StudyService { return added; } - /** - * @return - */ - public StepService getStepService() { - return _stepService; - } - - public void setStepService(StepService stepService) { - _stepService = stepService; - } - public SimulationContext addProjectContext(Study aStudy, SimulationContext context) { // ---------------------------------------------------------------------- @@ -495,4 +484,20 @@ public class StudyServiceImpl implements StudyService { ProjectElementService projectElementService) { _projectElementService = projectElementService; } + + /** + * Get the stepService. + * @return the stepService + */ + public StepService getStepService() { + return _stepService; + } + + /** + * Set the stepService. + * @param stepService the stepService to set + */ + public void setStepService(StepService stepService) { + _stepService = stepService; + } } diff --git a/Workspace/Siman-Common/src/org/splat/som/Step.java b/Workspace/Siman-Common/src/org/splat/som/Step.java index d7a8dfb..ebac98c 100644 --- a/Workspace/Siman-Common/src/org/splat/som/Step.java +++ b/Workspace/Siman-Common/src/org/splat/som/Step.java @@ -30,6 +30,7 @@ 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.bo.som.Document.Properties; import org.splat.dal.dao.som.Database; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MismatchException; @@ -78,75 +79,6 @@ public class Step { // Public member functions // ============================================================================================================================== - public Publication createDocument (Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException { -// ------------------------------------------------------------- - Document newdoc = new Document(dprop.setOwner(owner).setStep(step)); - -// Creation of the save directory - File wdir = newdoc.getSaveDirectory(); - if (!wdir.exists()) if (!wdir.mkdirs()) throw new IOException("Cannot create the repository vault directory"); - -// Identification and save - newdoc.buildReferenceFrom(getOwnerStudy()); - Database.getSession().save(newdoc); - - return new Publication(newdoc, owner); - } - - public Publication assignDocument (Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, NotApplicableException { -// ------------------------------------------------------------- - String refid = dprop.getReference(); - if (refid == null) return null; - - Document slot = Database.selectDocument(refid, new Revision().toString()); - if ( slot == null ) return null; - if (!slot.isUndefined()) return null; // Should not happen - - slot.initialize(dprop.setOwner(getOwnerStudy())); - return new Publication(slot, owner); - } - - public Publication versionDocument (Publication base) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException { -// ----------------------------------------------------- - return versionDocument(base, new Document.Properties()); - } - - public Publication versionDocument (Publication base, String reason) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException { -// -------------------------------------------------------------------- - return versionDocument(base, new Document.Properties().setDescription(reason)); - } - - public Publication versionDocument (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() != this.step.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(owner).setStep(step)); - newdoc.buildReferenceFrom(getOwner(), previous); - Database.getSession().save(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 = 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, owner); - } - public User getActor () { // ----------------------- return actor; diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 01da7c5..337c839 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -18,8 +18,13 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> - + + + + + + + 0) dprop.setDescription(summary); - Publication next = step.versionDocument(current, dprop); + Publication next = getStepService().versionDocument(step, current, dprop); // Writing the uploaded file into the created document File target = next.getSourceFile().asFile(); diff --git a/Workspace/Siman/src/org/splat/simer/DocumentFacade.java b/Workspace/Siman/src/org/splat/simer/DocumentFacade.java index 9c113ca..a51a9d5 100644 --- a/Workspace/Siman/src/org/splat/simer/DocumentFacade.java +++ b/Workspace/Siman/src/org/splat/simer/DocumentFacade.java @@ -1,4 +1,5 @@ package org.splat.simer; + /** * * @author Daniel Brunier-Coulin @@ -30,306 +31,368 @@ import org.splat.dal.bo.som.UsesRelation; import org.splat.dal.bo.som.VersionsRelation; import org.splat.wapp.PopupMenu; - public class DocumentFacade implements HistoryFacade { - private OpenObject owner; - private Publication me; - private Document my; // Published document - private ProgressState state; // Document state - private String version; // My document version in customized format - private State display; // Presentation state - private String surl; // URL of the source file - private String format; // Extension of the source file - private String icon; // Corresponding icon - private String sharing; // Icon qualifying sharing between scenarios of a same study - private String updated; // Icon qualifying versioning from the previous study version - private String size; - private String date; - private String description; - private List uses; - private List exports; - private List history; - private PopupMenu popup; + private OpenObject owner; + private Publication me; + private Document my; // Published document + private ProgressState state; // Document state + private String version; // My document version in customized format + private State display; // Presentation state + private String surl; // URL of the source file + private String format; // Extension of the source file + private String icon; // Corresponding icon + private String sharing; // Icon qualifying sharing between scenarios of a same study + private String updated; // Icon qualifying versioning from the previous study version + private String size; + private String date; + private String description; + private List uses; + private List exports; + private List history; + private PopupMenu popup; private ProjectSettingsService _projectSettingsService; private PublicationService _publicationService; - - private enum State { closed, open, deepopen } - -// ============================================================================================================================== -// Constructors -// ============================================================================================================================== - - public DocumentFacade (OpenObject opened, Publication represented) { -// ------------------------------------------------------------------ - owner = opened; - me = represented; - my = me.value(); - state = my.getProgressState(); - display = State.closed; - description = null; - uses = null; - exports = null; - history = null; - popup = null; - - this.refresh(); // Initializes the presentation of my document - } -/** - * Constructs the facade of a document presented in the history folder. - * - * @param represented the represented history document - */ - private DocumentFacade (OpenObject opened, Document represented) { -// ---------------------------------------------------------------- - owner = opened; - me = null; // Marks the history context - my = represented; - state = my.getProgressState(); // In reality, HISTORY - display = State.open; // Because the given document is a history document - description = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale()).getString("history.creation") + " " + my.getAuthor().toString(); - uses = null; - exports = null; - history = null; - popup = null; - - this.refresh(); // Initializes the presentation of my document - } - -// ============================================================================================================================== -// Public member functions -// ============================================================================================================================== - - public void develop () { -// ------------------- - if (display != State.open) { // Opening the document - if (uses == null) { - List relist = me.getRelations(UsesRelation.class); - - uses = new ArrayList(relist.size()); - for (Iterator i=relist.iterator(); i.hasNext();) { - Publication used = i.next(); - Integer index = used.getIndex(); - DocumentFacade facade = OpenObject.docpres.get(index); - if (facade == null) { - facade = new DocumentFacade(owner, used); - OpenObject.docpres.put(index, facade); - } - uses.add(facade); - } - } - if (exports == null) { - List relation = my.getRelations(ConvertsRelation.class); - - exports = new ArrayList(relation.size()); - for (Iterator i=relation.iterator(); i.hasNext();) { - ConvertsRelation export = (ConvertsRelation)i.next(); - exports.add( new FileFacade(export) ); - } - } - if (history == null) { - if (my.getPreviousVersion() != null || state == ProgressState.inCHECK || state == ProgressState.APPROVED) history = new ArrayList(); - } - display = State.open; - } else { // Opening the history of document, if exist - if (history.isEmpty()) collectHistory(my); - display = State.deepopen; - } - } - - public void reduce () { -// --------------------- - if (display == State.deepopen) display = State.open; - } - - public void reduceAll () { -// ------------------------ - display = State.closed; - } - -// ============================================================================================================================== -// Getters -// ============================================================================================================================== - - public List getAttachments () { -// ------------------------------------------ - return exports; - } - public String getDate () { -// ------------------------ - return date; - } - public String getDescription () { -// ------------------------------- - return description; - } - public String getEditIcon () { -// ---------------------------- - return "icon.ed" + state + ".png"; - } - public String getFileIcon () { -// ---------------------------- - return icon; - } - public List getHistory () { -// ---------------------------------------- - return history; - } - public String getIndex () { -// ------------------------- - return String.valueOf(my.getIndex()); - } - public PopupMenu getPopup () { // Contextualizes the pop-up -// ---------------------------- - popup.setContext("document", new DocumentRights(owner.getUser(), me)); - return popup; // callers must "use" the returned pop-up before getting another pop-up - } - public String getPresentationState () { -// ------------------------------------- - return display.toString(); - } - public String getProgressState () { -// --------------------------------- - return state.toString(); - } - public String getSharingIcon () { -// ------------------------------- - return sharing; - } - public String getSize () { -// ------------------------ - return size; - } - public String getStateIcon () { -// ----------------------------- - return "icon." + state + ".png"; - } - public String getTitle () { -// ------------------------- - return my.getTitle(); - } - public String getURL () { -// ----------------------- - return surl; - } - public List getUses () { -// --------------------------------------- - return uses; - } - public String getVersion () { -// --------------------------- - return version; - } - public String getVersioningIcon () { -// ---------------------------------- - return updated; - } - public boolean isFacadeOf (Publication represented) { -// --------------------------------------------------- - return me.equals(represented); - } -// ============================================================================================================================== -// Protected services -// ============================================================================================================================== - - protected void refresh () { -// ------------------------- - ResourceBundle custom = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale()); - DecimalFormat sizstring = new DecimalFormat(custom.getString("size.format")); // Locale size display format - SimpleDateFormat datstring = new SimpleDateFormat(custom.getString("date.format")); // Locale date display format - Revision.Format verstring = new Revision.Format(getProjectSettings().getRevisionPattern()); - String path = my.getSourceFile().getRelativePath(); - String[] mapping = ApplicationSettings.getViewersMapping(); - - for (int i=0; i-1; i--) history.add( new StampFacade(stamp[i]) ); - history.add( new DocumentFacade(owner, given) ); - if (versions != null) collectHistory(versions.getTo()); - } - - /** - * Get project settings. + + private enum State { + closed, open, deepopen + } + + // ============================================================================================================================== + // Constructors + // ============================================================================================================================== + + public DocumentFacade(OpenObject opened, Publication represented, + ProjectSettingsService projectSettings, + PublicationService publicationService) { + // ------------------------------------------------------------------ + setProjectSettings(projectSettings); + setPublicationService(publicationService); + owner = opened; + me = represented; + my = me.value(); + state = my.getProgressState(); + display = State.closed; + description = null; + uses = null; + exports = null; + history = null; + popup = null; + + this.refresh(); // Initializes the presentation of my document + } + + /** + * Constructs the facade of a document presented in the history folder. + * + * @param represented + * the represented history document + */ + private DocumentFacade(OpenObject opened, Document represented, + ProjectSettingsService projectSettings, + PublicationService publicationService) { + // ---------------------------------------------------------------- + setProjectSettings(projectSettings); + setPublicationService(publicationService); + owner = opened; + me = null; // Marks the history context + my = represented; + state = my.getProgressState(); // In reality, HISTORY + display = State.open; // Because the given document is a history document + description = ResourceBundle.getBundle("som", + ApplicationSettings.getCurrentLocale()).getString( + "history.creation") + + " " + my.getAuthor().toString(); + uses = null; + exports = null; + history = null; + popup = null; + + this.refresh(); // Initializes the presentation of my document + } + + // ============================================================================================================================== + // Public member functions + // ============================================================================================================================== + + public void develop() { + // ------------------- + if (display != State.open) { // Opening the document + if (uses == null) { + List relist = me.getRelations(UsesRelation.class); + + uses = new ArrayList(relist.size()); + for (Iterator i = relist.iterator(); i.hasNext();) { + Publication used = i.next(); + Integer index = used.getIndex(); + DocumentFacade facade = OpenObject.docpres.get(index); + if (facade == null) { + facade = new DocumentFacade(owner, used, getProjectSettings(), getPublicationService()); + OpenObject.docpres.put(index, facade); + } + uses.add(facade); + } + } + if (exports == null) { + List relation = my + .getRelations(ConvertsRelation.class); + + exports = new ArrayList(relation.size()); + for (Iterator i = relation.iterator(); i.hasNext();) { + ConvertsRelation export = (ConvertsRelation) i.next(); + exports.add(new FileFacade(export)); + } + } + if (history == null) { + if (my.getPreviousVersion() != null + || state == ProgressState.inCHECK + || state == ProgressState.APPROVED) + history = new ArrayList(); + } + display = State.open; + } else { // Opening the history of document, if exist + if (history.isEmpty()) + collectHistory(my); + display = State.deepopen; + } + } + + public void reduce() { + // --------------------- + if (display == State.deepopen) + display = State.open; + } + + public void reduceAll() { + // ------------------------ + display = State.closed; + } + + // ============================================================================================================================== + // Getters + // ============================================================================================================================== + + public List getAttachments() { + // ------------------------------------------ + return exports; + } + + public String getDate() { + // ------------------------ + return date; + } + + public String getDescription() { + // ------------------------------- + return description; + } + + public String getEditIcon() { + // ---------------------------- + return "icon.ed" + state + ".png"; + } + + public String getFileIcon() { + // ---------------------------- + return icon; + } + + public List getHistory() { + // ---------------------------------------- + return history; + } + + public String getIndex() { + // ------------------------- + return String.valueOf(my.getIndex()); + } + + public PopupMenu getPopup() { // Contextualizes the pop-up + // ---------------------------- + popup.setContext("document", new DocumentRights(owner.getUser(), me)); + return popup; // callers must "use" the returned pop-up before getting another pop-up + } + + public String getPresentationState() { + // ------------------------------------- + return display.toString(); + } + + public String getProgressState() { + // --------------------------------- + return state.toString(); + } + + public String getSharingIcon() { + // ------------------------------- + return sharing; + } + + public String getSize() { + // ------------------------ + return size; + } + + public String getStateIcon() { + // ----------------------------- + return "icon." + state + ".png"; + } + + public String getTitle() { + // ------------------------- + return my.getTitle(); + } + + public String getURL() { + // ----------------------- + return surl; + } + + public List getUses() { + // --------------------------------------- + return uses; + } + + public String getVersion() { + // --------------------------- + return version; + } + + public String getVersioningIcon() { + // ---------------------------------- + return updated; + } + + public boolean isFacadeOf(Publication represented) { + // --------------------------------------------------- + return me.equals(represented); + } + + // ============================================================================================================================== + // Protected services + // ============================================================================================================================== + + protected void refresh() { + // ------------------------- + ResourceBundle custom = ResourceBundle.getBundle("som", + ApplicationSettings.getCurrentLocale()); + DecimalFormat sizstring = new DecimalFormat(custom + .getString("size.format")); // Locale size display format + SimpleDateFormat datstring = new SimpleDateFormat(custom + .getString("date.format")); // Locale date display format + Revision.Format verstring = new Revision.Format(getProjectSettings() + .getRevisionPattern()); + String path = my.getSourceFile().getRelativePath(); + String[] mapping = ApplicationSettings.getViewersMapping(); + + for (int i = 0; i < mapping.length; i++) { + org.splat.dal.bo.som.File export = my.getAttachedFile(mapping[i]); + if (export == null) + continue; + path = export.getRelativePath(); + break; + } + surl = ApplicationSettings.getRepositoryURL() + path; + surl = surl.replaceAll("'", "\\\\'"); + format = my.getFormat(); + if (format.equals("xml")) + format = XMLDocument.getActualFormat(my.getSourceFile().asFile()); + + // Document state (overridable by the publication - see below) + state = my.getProgressState(); + version = my.getVersion(); // May be null + + // Icons definition + icon = "icon." + format + ".png"; + sharing = "image.hold.gif"; + updated = "image.hold.gif"; + File image = new File(ApplicationSettings.getApplicationSkinPath() + + icon); + if (!image.exists()) + icon = "icon.any.png"; + + if (me != null) { + if (me.getOwnerStudy().shares(my)) { + sharing = "image.share.png"; + updated = "icon.hold.png"; + } + if (me.isOutdated()) + state = ProgressState.inWORK; // Overrides the document state + + } else { // Facade in the history folder + if (!my.isVersioned()) { // History of the last version + if (state != ProgressState.inWORK) + icon = "icon.inWORK.png"; + else + icon = "icon." + state.toString() + ".png"; + } else if (my.isPublished()) { + sharing = "image.share.png"; // Not correct if published in a previous version of the study + updated = "icon.hold.png"; + } + } + // Document description + VersionsRelation versions = (VersionsRelation) my + .getFirstRelation(VersionsRelation.class); + if (versions != null) { + description = versions.getDescription(); + } + // File details + if (state != ProgressState.EXTERN) + version = verstring.format(version); + size = sizstring.format(my.getSourceFile().asFile().length() / 1000); + date = datstring.format(my.getLastModificationDate()); + + // Refresh of the history in case of promotion + if (display == State.deepopen) { + history.clear(); + collectHistory(my); + } + // Popup menus + if (me == null) + return; // No pop-up (yet) in the history folder + if (state == ProgressState.EXTERN) + popup = ApplicationSettings.getPopupMenu("extern"); + else if (state == ProgressState.inWORK) + popup = ApplicationSettings.getPopupMenu("editable"); + else if (state == ProgressState.inDRAFT) + popup = ApplicationSettings.getPopupMenu("reviewable"); + else if (state == ProgressState.APPROVED) + popup = ApplicationSettings.getPopupMenu("approved"); + else { // (state == ProgressState.inCHECK) + DocumentType mytype = me.value().getType(); // Only result documents need to be approved + Step mystep = getPublicationService().getInvolvedStep(me); + if (mytype.isResultOf(mystep.getStep())) + popup = ApplicationSettings.getPopupMenu("approvable"); + else + popup = ApplicationSettings.getPopupMenu("notresult"); + } + } + + protected void setVersioned() { + // ------------------------------ + updated = "image.modified.png"; + } + + // ============================================================================================================================== + // Private services + // ============================================================================================================================== + + private void collectHistory(Document given) { + // -------------------------------------------- + VersionsRelation versions = (VersionsRelation) given + .getFirstRelation(VersionsRelation.class); + Timestamp[] stamp = given.getStamps(); // Stamps in ascending order of date + + for (int i = stamp.length - 1; i > -1; i--) + history.add(new StampFacade(stamp[i])); + history.add(new DocumentFacade(owner, given, getProjectSettings(), getPublicationService())); + if (versions != null) + collectHistory(versions.getTo()); + } + + /** + * Get project settings. + * * @return Project settings service */ private ProjectSettingsService getProjectSettings() { @@ -338,12 +401,14 @@ public class DocumentFacade implements HistoryFacade { /** * Set project settings service. - * @param projectSettingsService project settings service + * + * @param projectSettingsService + * project settings service */ - public void setProjectSettings( - ProjectSettingsService projectSettingsService) { + public void setProjectSettings(ProjectSettingsService projectSettingsService) { _projectSettingsService = projectSettingsService; } + /** * Get the publicationService. * diff --git a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java index 3de8369..b565afb 100644 --- a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java @@ -20,6 +20,7 @@ import org.splat.dal.dao.som.Database; import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.ProgressState; import org.splat.service.PublicationService; +import org.splat.service.StepService; import org.splat.service.technical.ProjectSettingsService; import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.DocumentType; @@ -35,6 +36,7 @@ public class ImportDocumentAction extends UploadBaseNextAction { private String date = ""; // Date extracted from the imported file, if exist private ProjectSettingsService _projectSettingsService; private PublicationService _publicationService; + private StepService _stepService; private static final long serialVersionUID = 2587822564883588556L; @@ -163,7 +165,7 @@ public class ImportDocumentAction extends UploadBaseNextAction { if (docref.length() == 0) { // Importation of a foreign document // TODO: Extract property of supported documents (DOCX, ODT...) - addoc = step.createDocument(dprop.setName(docname) + addoc = getStepService().createDocument(step, dprop.setName(docname) .setType(type).setFormat(table[table.length - 1]) .setAuthor(user)); updir = addoc.getSourceFile().asFile(); @@ -187,7 +189,7 @@ public class ImportDocumentAction extends UploadBaseNextAction { locale.getString("date.format")); dprop.setDate(get.parse(date)); } - addoc = step.assignDocument(dprop.setReference(docref).setName( + addoc = getStepService().assignDocument(step, dprop.setReference(docref).setName( docname)); updir = addoc.getSourceFile().asFile(); if (logger.isInfoEnabled()) @@ -357,4 +359,20 @@ public class ImportDocumentAction extends UploadBaseNextAction { public void setPublicationService(PublicationService publicationService) { _publicationService = publicationService; } + + /** + * Get the stepService. + * @return the stepService + */ + public StepService getStepService() { + return _stepService; + } + + /** + * Set the stepService. + * @param stepService the stepService to set + */ + public void setStepService(StepService stepService) { + _stepService = stepService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/OpenKnowledge.java b/Workspace/Siman/src/org/splat/simer/OpenKnowledge.java index 86dfc0c..402abfe 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenKnowledge.java +++ b/Workspace/Siman/src/org/splat/simer/OpenKnowledge.java @@ -21,7 +21,6 @@ public class OpenKnowledge extends OpenObject { private KnowledgeElement myknelm; private String credate; private ProjectElementService _projectElementService; - private ProjectSettingsService _projectSettingsService; public class Menu extends SimpleMenu { // ------------------------------------ @@ -202,20 +201,4 @@ public class OpenKnowledge extends OpenObject { _projectElementService = projectElementService; } - /** - * Get project settings. - * @return Project settings service - */ - private ProjectSettingsService getProjectSettings() { - return _projectSettingsService; - } - - /** - * Set project settings service. - * @param projectSettingsService project settings service - */ - public void setProjectSettings( - ProjectSettingsService projectSettingsService) { - _projectSettingsService = projectSettingsService; - } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/OpenObject.java b/Workspace/Siman/src/org/splat/simer/OpenObject.java index 92905fd..b00ad00 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenObject.java +++ b/Workspace/Siman/src/org/splat/simer/OpenObject.java @@ -11,7 +11,9 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.KnowledgeElementType; import org.splat.dal.bo.som.ProgressState; +import org.splat.service.PublicationService; import org.splat.service.dto.Proxy; +import org.splat.service.technical.ProjectSettingsService; import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Scenario; import org.splat.som.Step; @@ -32,6 +34,8 @@ public abstract class OpenObject implements Proxy { protected Menu menu = null; // Left pane menu of this object protected PopupMenu popup = null; // Pop-up menu of this object, if the user has write access + private ProjectSettingsService _projectSettingsService; + private PublicationService _publicationService; protected static HashMap docpres = null; protected static HashMap knowpres = null; @@ -253,7 +257,7 @@ public abstract class OpenObject implements Proxy { Integer index = present.getIndex(); DocumentFacade facade = docpres.get(index); if (facade == null) { - facade = new DocumentFacade(this, present); + facade = new DocumentFacade(this, present, getProjectSettings(), getPublicationService()); docpres.put(index, facade); } contents.add(facade); @@ -262,4 +266,40 @@ public abstract class OpenObject implements Proxy { contents = null; } } + + /** + * Get project settings. + * @return Project settings service + */ + public ProjectSettingsService getProjectSettings() { + return _projectSettingsService; + } + + /** + * Get the publicationService. + * + * @return the publicationService + */ + public PublicationService getPublicationService() { + return _publicationService; + } + + /** + * Set project settings service. + * @param projectSettingsService project settings service + */ + public void setProjectSettings( + ProjectSettingsService projectSettingsService) { + _projectSettingsService = projectSettingsService; + } + + /** + * Set the publicationService. + * + * @param publicationService + * the publicationService to set + */ + public void setPublicationService(PublicationService publicationService) { + _publicationService = publicationService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index 92673d2..8fdc286 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -27,7 +27,9 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.ProgressState; import org.splat.service.ProjectElementService; +import org.splat.service.PublicationService; import org.splat.service.ScenarioService; +import org.splat.service.StepService; import org.splat.service.technical.ProjectSettingsService; import org.splat.dal.bo.som.Publication; import org.splat.som.Revision; @@ -49,11 +51,10 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { private String credate; private String lasdate; private Publication selecdoc; - private ProjectSettingsService _projectSettingsService; private ProjectElementService _projectElementService; private ScenarioService _scenarioService; - - protected final static Logger logger = org.splat.simer.Action.logger; + private StepService _stepService; + protected final static Logger logger = org.splat.simer.Action.logger; // ============================================================================================================================== // Constructor @@ -190,7 +191,7 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { Step step = getSelectedStep(); // Should we check if the given document type is compatible ? DocumentType type = Document.selectType(typename); Document.Properties dprop = new Document.Properties(); - Document medoc = step.createDocument(dprop.setType(type).setFormat("xml").setAuthor(author)).value(); + Document medoc = getStepService().createDocument(step, dprop.setType(type).setFormat("xml").setAuthor(author)).value(); transax.commit(); // Instantiation of the template into the user download directory @@ -279,7 +280,7 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { protected void add (Publication doc) { // ------------------------------------ - DocumentFacade facade = new DocumentFacade(this, doc); + DocumentFacade facade = new DocumentFacade(this, doc, getProjectSettings(), getPublicationService()); boolean first = (contents.size() == 0); docpres.put(doc.getIndex(), facade); @@ -422,22 +423,6 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { } /** - * Get project settings. - * @return Project settings service - */ - private ProjectSettingsService getProjectSettings() { - return _projectSettingsService; - } - - /** - * Set project settings service. - * @param projectSettingsService project settings service - */ - public void setProjectSettings( - ProjectSettingsService projectSettingsService) { - _projectSettingsService = projectSettingsService; - } - /** * Get the projectElementService. * * @return the projectElementService @@ -475,4 +460,20 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { public void setScenarioService(ScenarioService scenarioService) { _scenarioService = scenarioService; } + + /** + * Get the stepService. + * @return the stepService + */ + public StepService getStepService() { + return _stepService; + } + + /** + * Set the stepService. + * @param stepService the stepService to set + */ + public void setStepService(StepService stepService) { + _stepService = stepService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java index c68b0ce..a5503b3 100644 --- a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java @@ -22,6 +22,7 @@ import org.splat.dal.dao.som.Database; import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.ProgressState; import org.splat.service.PublicationService; +import org.splat.service.StepService; import org.splat.service.technical.ProjectSettingsService; import org.splat.dal.bo.som.Publication; import org.splat.som.Revision; @@ -39,6 +40,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { private String date = ""; // Date extracted from the imported file, if exist private ProjectSettingsService _projectSettingsService; private PublicationService _publicationService; + private StepService _stepService; private static final long serialVersionUID = -5702264003232132168L; @@ -143,7 +145,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { Publication next; if (docver.length() == 0) { // Importation of a foreign document - next = step.versionDocument(current, dprop.setAuthor(user) + next = getStepService().versionDocument(step, current, dprop.setAuthor(user) .setDescription(summary)); updir = next.getSourceFile().asFile(); if (logger.isInfoEnabled()) @@ -166,7 +168,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { locale.getString("date.format")); dprop.setDate(get.parse(date)); } - next = step.versionDocument(current, dprop.setAuthor(user) + next = getStepService().versionDocument(step, current, dprop.setAuthor(user) .setDescription(summary)); updir = next.getSourceFile().asFile(); if (logger.isInfoEnabled()) @@ -328,4 +330,20 @@ public class VersionDocumentAction extends UploadBaseNextAction { public void setPublicationService(PublicationService publicationService) { _publicationService = publicationService; } + + /** + * Get the stepService. + * @return the stepService + */ + public StepService getStepService() { + return _stepService; + } + + /** + * Set the stepService. + * @param stepService the stepService to set + */ + public void setStepService(StepService stepService) { + _stepService = stepService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java index 693609c..9d65a2f 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java @@ -99,7 +99,7 @@ public class SimulationContextAction extends Action { tocheck = new Vector(context.size()); for (Iterator i=context.iterator(); i.hasNext(); ) { - tocheck.add( new SimulationContextFacade(i.next()) ); + tocheck.add( new SimulationContextFacade(i.next(), getProjectSettings().getAllSteps()) ); } selection = 0; edition = null; @@ -130,7 +130,7 @@ public class SimulationContextAction extends Action { edition = next; selected.add(edition); } - tocheck.add( new SimulationContextFacade(next) ); + tocheck.add( new SimulationContextFacade(next, getProjectSettings().getAllSteps()) ); } KnowledgeElement.Properties kprop = new KnowledgeElement.Properties(); List kelm = getSearchService().selectKnowledgeElementsWhere(kprop.setSimulationContexts(selected).setState(ProgressState.inWORK)); diff --git a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextFacade.java b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextFacade.java index 4904834..d27d373 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextFacade.java +++ b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextFacade.java @@ -17,15 +17,13 @@ public class SimulationContextFacade { private String name; private int at; private ProgressState state; - private ProjectSettingsService _projectSettingsService; // ============================================================================================================================== // Constructor // ============================================================================================================================== - public SimulationContextFacade (SimulationContext represented) { + public SimulationContextFacade (SimulationContext represented, List steps) { // -------------------------------------------------------------- - List steps = getProjectSettings().getAllSteps(); SimulationContextType mytype; my = represented; @@ -70,20 +68,4 @@ public class SimulationContextFacade { // ------------------------- return my.getValue(); } - /** - * Get project settings. - * @return Project settings service - */ - private ProjectSettingsService getProjectSettings() { - return _projectSettingsService; - } - - /** - * Set project settings service. - * @param projectSettingsService project settings service - */ - public void setProjectSettings( - ProjectSettingsService projectSettingsService) { - _projectSettingsService = projectSettingsService; - } } \ No newline at end of file diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index d915f68..f8cc9fd 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -17,7 +17,9 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> + + + @@ -127,6 +130,7 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> class="org.splat.simer.VersionDocumentAction" scope="prototype"> +