Salome HOME
More business logic has been moved from BO to services. ServiceLocator is created...
authorrkv <rkv@opencascade.com>
Fri, 19 Oct 2012 12:27:16 +0000 (12:27 +0000)
committerrkv <rkv@opencascade.com>
Fri, 19 Oct 2012 12:27:16 +0000 (12:27 +0000)
140 files changed:
Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/ConvertsRelation.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/DocumentType.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/File.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElement.hbm.xml
Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElement.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Study.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Timestamp.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/ValidationCycle.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AnyDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AnyDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AttributeDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AttributeDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/EntityDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/EntityDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/PersistentDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/PersistentDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RelationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RelationDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ProjectElementDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ProjectElementDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAOImpl.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAO.java
Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAOImpl.java
Workspace/Siman-Common/src/org/splat/exception/AbstractException.java
Workspace/Siman-Common/src/org/splat/exception/LockAlreadyExistsException.java
Workspace/Siman-Common/src/org/splat/exception/LockNotExistsException.java
Workspace/Siman-Common/src/org/splat/exception/LockOutdatedException.java
Workspace/Siman-Common/src/org/splat/exception/LockProtectedException.java
Workspace/Siman-Common/src/org/splat/i18n/I18nUtils.java
Workspace/Siman-Common/src/org/splat/log/AppLogger.java
Workspace/Siman-Common/src/org/splat/service/DocumentService.java
Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/DocumentTypeService.java
Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/KnowledgeElementService.java
Workspace/Siman-Common/src/org/splat/service/KnowledgeElementServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/KnowledgeElementTypeService.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/KnowledgeElementTypeServiceImpl.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/LockService.java
Workspace/Siman-Common/src/org/splat/service/LockServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/ProjectElementService.java
Workspace/Siman-Common/src/org/splat/service/ProjectElementServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/PublicationService.java
Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/ScenarioService.java
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/SearchService.java
Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/ServiceLocator.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/ServiceLocatorImpl.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/SimulationContextService.java
Workspace/Siman-Common/src/org/splat/service/SimulationContextServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StepService.java
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StudyService.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/UtilService.java
Workspace/Siman-Common/src/org/splat/service/UtilServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/technical/DatabaseService.java
Workspace/Siman-Common/src/org/splat/service/technical/DatabaseServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/technical/IndexService.java
Workspace/Siman-Common/src/org/splat/service/technical/IndexServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsService.java
Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/technical/RepositoryService.java
Workspace/Siman-Common/src/org/splat/service/technical/RepositoryServiceImpl.java
Workspace/Siman-Common/src/org/splat/som/DocumentRights.java
Workspace/Siman-Common/src/org/splat/som/Step.java
Workspace/Siman-Common/src/org/splat/som/StepRights.java
Workspace/Siman-Common/src/org/splat/som/StudyRights.java
Workspace/Siman-Common/src/org/splat/util/BeanHelper.java
Workspace/Siman-Common/src/org/splat/util/TimestampTransformer.java
Workspace/Siman-Common/src/org/splat/util/TimestampTransformerFactory.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman-Common/src/spring/technicalServiceContext.xml
Workspace/Siman-Common/src/test/splat/common/BaseTest.java
Workspace/Siman-Common/src/test/splat/common/TestListingAndOrder.java
Workspace/Siman-Common/src/test/splat/dao/TestKnowledgeElementDAO.java
Workspace/Siman/src/org/splat/module/SaveDocumentAction.java
Workspace/Siman/src/org/splat/simer/ApplicationSettings.java
Workspace/Siman/src/org/splat/simer/EditDocumentAction.java
Workspace/Siman/src/org/splat/simer/EditKnowledgeElementAction.java
Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java
Workspace/Siman/src/org/splat/simer/NewScenarioAction.java
Workspace/Siman/src/org/splat/simer/NewStudyAction.java
Workspace/Siman/src/org/splat/simer/OpenKnowledge.java
Workspace/Siman/src/org/splat/simer/OpenObject.java
Workspace/Siman/src/org/splat/simer/OpenStudy.java
Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java
Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java
Workspace/Siman/src/spring/applicationContext.xml

index 6c1950b7625bd5acc202e4c0ebc43230e2d14a7b..b7c29211133d4beeb625f21a88f7776cf27877c6 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   03.10.2012
index ff2997af7b71c257734df215779ccc7c1bb640b1..1e79f757b27a7e715b739ab7992a85e412f098fc 100644 (file)
@@ -36,7 +36,7 @@ public class ConvertsRelation extends Relation {
       this.got         = true;
       this.description = null;          // Conversion not described
     }
-    protected ConvertsRelation (Document from, File to, String description) {
+    public ConvertsRelation (Document from, File to, String description) {
 //  -----------------------------------------------------------------------
       super(from);
       this.refer       = to;
index d998f3ec6e509e8f4dd4b017390fffa7d33c24ac..f084a223f300e4c64b41bfa13a62c021c5ac1ea4 100644 (file)
@@ -6,36 +6,27 @@ package org.splat.dal.bo.som;
  * @copyright OPEN CASCADE 2012
  */
 
-import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
 import java.util.Arrays;
-import java.util.Calendar;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 
-import org.hibernate.Hibernate;
-import org.hibernate.Session;
-
 import org.splat.dal.bo.kernel.Persistent;
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.Timestamp.ComparatorByDate;
-import org.splat.dal.dao.som.Database;
-import org.splat.kernel.NotApplicableException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
-import org.splat.manox.Reader;
-import org.splat.manox.Toolbox;
-import org.splat.service.StudyService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.service.technical.ProjectSettingsServiceImpl;
-import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming;
 import org.splat.som.Revision;
 import org.splat.som.Step;
 
+/**
+ * Document persistent class. 
+ */
 public class Document extends Entity {
 
        // Persistent fields
@@ -50,8 +41,6 @@ public class Document extends Entity {
        private int history;
        private User author;
        private Date lasdate;
-       private ProjectSettingsService _projectSettingsService;
-       private StudyService _studyService;
 
        // Transient fields
        public static String suformat = "00"; // Format of the suffix number of document did and file name
@@ -60,7 +49,9 @@ public class Document extends Entity {
        // Construction
        // ==============================================================================================================================
 
-       // Fields initialization class
+       /**
+        * Fields initialization class. 
+        */
        public static class Properties extends Persistent.Properties {
                // ------------------------------------------------------------
                private DocumentType type = null;
@@ -493,327 +484,6 @@ public class Document extends Entity {
                return (history > 0);
        }
 
-       // ==============================================================================================================================
-       // Public services
-       // ==============================================================================================================================
-
-       public static DocumentType createType(DocumentType.Properties tprop)
-                       throws MissedPropertyException, InvalidPropertyException,
-                       MultiplyDefinedException, RuntimeException {
-               // ---------------------------------------------------------------------
-               // TODO: Check for duplicate definition
-               DocumentType type = new DocumentType(tprop);
-               Session session = Database.getSession();
-               session.save(type);
-
-               return type;
-       }
-
-       public static Properties extractProperties(java.io.File file) {
-               // --------------------------------------------------------------
-               Properties fprop = new Properties();
-               Reader tool = Toolbox.getReader(file);
-               String value;
-               if (tool != null)
-                       try {
-                               value = tool.extractProperty("title");
-                               if (value != null)
-                                       fprop.setName(value);
-
-                               value = tool.extractProperty("reference");
-                               if (value != null)
-                                       fprop.setReference(value);
-                       } catch (Exception e) {
-                       }
-               return fprop;
-       }
-
-       @SuppressWarnings("unchecked")
-       public static List<DocumentType> selectAllTypes() {
-               // --------------------------------------------------
-               String query = "from DocumentType";
-
-               List<DocumentType> types = Database.getSession().createQuery(query)
-                               .list();
-               for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
-                       Hibernate.initialize(i.next()); // Supposed fetching document types
-               }
-               return types;
-       }
-
-       @SuppressWarnings("unchecked")
-       public static List<DocumentType> selectResultTypes() {
-               // -----------------------------------------------------
-               String query = "from DocumentType where result is not null order by result asc";
-
-               return Database.getSession().createQuery(query).list();
-       }
-
-       public static DocumentType selectType(String name) {
-               // ---------------------------------------------------
-               String query = new StringBuffer("from DocumentType where name='")
-                               .append(name).append("'").toString();
-
-               return (DocumentType) Database.getSession().createQuery(query)
-                               .uniqueResult();
-       }
-
-       public static DocumentType selectType(long index) {
-               // -------------------------------------------------
-               String query = new StringBuffer("from DocumentType where rid='")
-                               .append(index).append("'").toString();
-
-               return (DocumentType) Database.getSession().createQuery(query)
-                               .uniqueResult();
-       }
-
-       @SuppressWarnings("unchecked")
-       public static List<DocumentType> selectTypesOf(
-                       ProjectSettingsService.Step step) {
-               // --------------------------------------------------------------------------
-               Integer number = step.getNumber();
-               String query = new StringBuffer("from DocumentType").append(
-                               " where step like '%-").append(number).append("-%'").toString();
-
-               List<DocumentType> types = Database.getSession().createQuery(query)
-                               .list();
-               for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
-                       Hibernate.initialize(i.next()); // For fetching document types
-               }
-               return types;
-       }
-
-       // ==============================================================================================================================
-       // Protected services
-       // ==============================================================================================================================
-
-       protected ConvertsRelation attach(String format) {
-               // -------------------------------------------------
-               return attach(format, null);
-       }
-
-       protected ConvertsRelation attach(String format, String description) {
-               // ---------------------------------------------------------------------
-               String path = this.getRelativePath();
-               File export = new File(path + "." + format);
-               ConvertsRelation attach = new ConvertsRelation(this, export,
-                               description);
-               Session session = Database.getSession();
-
-               session.save(export);
-               session.save(attach);
-
-               this.addRelation(attach); // Updates this
-
-               return attach;
-       }
-
-       public boolean buildReferenceFrom(ProjectElement scope, Document lineage) {
-               // -----------------------------------------------------------------------------
-               if (state != ProgressState.inWORK)
-                       return false;
-               Study owner = null;
-               Scenario context = null;
-               if (scope instanceof Study)
-                       owner = (Study) scope;
-               else {
-                       context = ((Scenario) scope);
-                       owner = context.getOwnerStudy();
-               }
-               did = lineage.did;
-               if (context != null && (lineage.isVersioned() || owner.shares(lineage))) {
-                       version = new Revision(version).setBranch(context.getReference())
-                                       .toString();
-               }
-               return true;
-       }
-
-       public boolean buildReferenceFrom(Study scope) {
-               // --------------------------------------------------
-               if (state != ProgressState.inWORK && state != ProgressState.EXTERN)
-                       return false;
-               DecimalFormat tostring = new DecimalFormat(suformat);
-
-               did = did.replace("%" + suformat, tostring.format(scope
-                               .getLastLocalIndex()));
-               return true;
-       }
-
-       public boolean demote() {
-               // ---------------------------
-               ValidationStep torem;
-
-               if (state == ProgressState.inCHECK) {
-                       state = ProgressState.inDRAFT;
-                       torem = ValidationStep.REVIEW;
-                       // This operation must not change the version number of documents.
-                       // Consequently, inDRAFT documents may have a minor version number equal to zero.
-               } else if (state == ProgressState.inDRAFT) {
-                       state = ProgressState.inWORK;
-                       torem = ValidationStep.PROMOTION;
-               } else {
-                       return false;
-               }
-               for (Iterator<Relation> i = this.getAllRelations().iterator(); i
-                               .hasNext();) {
-                       Relation link = i.next();
-                       if (!(link instanceof StampRelation))
-                               continue;
-                       if (((StampRelation) link).getStampType() != torem)
-                               continue;
-                       i.remove();
-                       break;
-               }
-               Database.getSession().update(this);
-               return true;
-       }
-
-       /**
-        * Increments the reference count of this document following its publication into a Study step.
-        * 
-        * @see #release()
-        */
-       public void hold() {
-               // ----------------------
-               countag += 1;
-               if (this.isSaved())
-                       Database.getSession().update(this);
-       }
-
-       public boolean promote(Timestamp stamp) {
-               // -------------------------------------------
-               ProgressState newstate = null;
-
-               if (state == ProgressState.inWORK) {
-                       newstate = ProgressState.inDRAFT; // Promotion to being reviewed
-               } else if (state == ProgressState.inDRAFT) {
-                       newstate = ProgressState.inCHECK; // Promotion to approval
-                       Revision myvers = new Revision(version);
-                       if (myvers.isMinor()) {
-                               version = myvers.incrementAs(newstate).toString();
-                               // TODO: If my physical file is programatically editable, update its (property) version number
-                               // ISSUE: What about attached files such as PDF if exist, should we remove them ?
-                       }
-               } else if (state == ProgressState.inCHECK) {
-                       newstate = ProgressState.APPROVED;
-               }
-               this.state = newstate;
-               if (stamp != null)
-                       this.addRelation(stamp.getContext());
-               Database.getSession().update(this);
-               return true;
-       }
-
-       /**
-        * Decrements the reference count of this document following the removal of a Publication from a Study step.
-        * 
-        * @see #hold()
-        */
-       public void release() {
-               // -------------------------
-               countag -= 1;
-               if (this.isSaved())
-                       Database.getSession().update(this);
-       }
-
-       protected void rename(String title) throws InvalidPropertyException {
-               // ------------------------------------
-               if (title.length() == 0)
-                       throw new InvalidPropertyException("name");
-
-               Calendar current = Calendar.getInstance();
-               this.name = title;
-               this.lasdate = current.getTime(); // Today
-               Database.getSession().update(this);
-       }
-
-       public void updateAs(Revision newvers) {
-               // ------------------------------------------
-               version = newvers.setBranch(version).toString(); // Branch names are propagated by the versionning
-               ProgressState newstate = ProgressState.inCHECK;
-               if (newvers.isMinor())
-                       newstate = ProgressState.inWORK;
-               state = null; // Just to tell updateAs(sate) to not increment the version number
-               updateAs(newstate);
-       }
-
-       public void updateAs(ProgressState state) {
-               // ---------------------------------------------
-               Document previous = null;
-
-               // Set of version number
-               if (state == ProgressState.EXTERN) {
-                       if (this.state != ProgressState.EXTERN)
-                               this.version = null; // Strange use-case...
-               } else {
-                       Revision myvers = new Revision(version);
-                       if (!myvers.isNull()) { // Versionning context
-                               for (Iterator<Relation> i = getAllRelations().iterator(); i
-                                               .hasNext();) {
-                                       Relation link = i.next();
-                                       if (!link.getClass().equals(VersionsRelation.class))
-                                               continue;
-                                       previous = (Document) link.getTo(); // Versioned document
-                                       break;
-                               }
-                       }
-                       if (this.state != null)
-                               myvers.incrementAs(state); // Incrementation if the reversion number is not imposed
-                       this.version = myvers.toString();
-               }
-               // Update this document and the previous version, if exit
-               Session session = Database.getSession();
-               if (previous != null) {
-                       previous.history += 1;
-                       session.update(previous);
-               }
-               this.state = state;
-               session.update(this);
-       }
-
-       // protected void upgrade () {
-       // -------------------------
-       // if (this.state != ProgressState.inWORK) return;
-       //
-       // Calendar current = Calendar.getInstance();
-       // for (Iterator<Relation> i=getAllRelations().iterator(); i.hasNext();) {
-       // Relation link = i.next();
-       // if (!link.getClass().equals(UsesRelation.class)) continue;
-       //
-       // Document used = (Document)link.getTo();
-       // if (!used.isVersioned()) continue;
-       // TODO: Update the uses relation
-       // }
-       // this.promote();
-       // this.lasdate = current.getTime(); // Today
-       // Database.getSession().update(this);
-       //
-       // TODO: Promote documents using this one
-       // }
-
-       /**
-        * @return
-        */
-       private ProjectSettingsService getProjectSettingsService() {
-               return _projectSettingsService;
-       }
-
-       public void setProjectSettingsService(
-                       ProjectSettingsService projectSettingsService) {
-               _projectSettingsService = projectSettingsService;
-       }
-
-       /**
-        * @return
-        */
-       public StudyService getStudyService() {
-               return _studyService;
-       }
-
-       public void setStudyService(StudyService studyService) {
-               _studyService = studyService;
-       }
-
        /**
         * Get the step.
         * @return the step
@@ -877,4 +547,36 @@ public class Document extends Entity {
        public void setHistory(int history) {
                this.history = history;
        }
+
+       /**
+        * Set the version.
+        * @param version the version to set
+        */
+       public void setVersion(String version) {
+               this.version = version;
+       }
+
+       /**
+        * Set the state.
+        * @param state the state to set
+        */
+       public void setProgressState(ProgressState state) {
+               this.state = state;
+       }
+
+       /**
+        * Get the countag.
+        * @return the countag
+        */
+       public int getCountag() {
+               return countag;
+       }
+
+       /**
+        * Set the countag.
+        * @param countag the countag to set
+        */
+       public void setCountag(int countag) {
+               this.countag = countag;
+       }
 }
\ No newline at end of file
index 6b83936e84ea8b541941c1ee1dfedf40fe43dc4d..3f68472f5e40a4c46186ced2fb88c59955f9379b 100644 (file)
@@ -5,7 +5,6 @@ package org.splat.dal.bo.som;
  * @copyright OPEN CASCADE 2012
  */
 
-import java.util.List;
 import java.util.Set;
 import java.util.HashSet;
 
@@ -15,7 +14,6 @@ import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
 import org.splat.service.technical.ProjectSettingsService;
-import org.splat.service.technical.ProjectSettingsService.Step;
 
 
 public class DocumentType extends Persistent {
@@ -85,7 +83,7 @@ public class DocumentType extends Persistent {
 //  -------------------------
     }
 //  Initialization constructor
-    protected DocumentType (Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
+    public DocumentType (Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
 //  -----------------------------------------
       super(dprop);              // Throws one of the above exception if not valid
       name   = dprop.name;
index 64f2998d4d42e0712e887d1575780f7d49860bf9..56758848b4cd85e6efa5090b5492dd37e1fe51c7 100644 (file)
@@ -37,7 +37,7 @@ public class File extends Persistent {
       this.myfile = null;
     }
 //  Internal constructors
-    protected File (String path) {
+    public File (String path) {
 //  ----------------------------
       Calendar  current = Calendar.getInstance();
       String[]  table   = path.split("\\x2E");
index 15a2c12ca5145ea27ff9579feb58e170979a29d1..d471b0f79bbb2669df64da5885e005dca5821a5f 100644 (file)
@@ -28,7 +28,7 @@
     <property    name="value" type="text" column="value" access="field" not-null="true" />
     
     <!-- Scenario owner  -->    
-    <many-to-one name="owner"  column="owner" access="field" not-null="true" />
+    <many-to-one name="owner"  column="owner" access="field" not-null="true" cascade="save-update"/>
   
     <!-- ProgressState state -->
     <property    name="state"  column="state" type="ProgressState" access="field" not-null="true" />    
index 0923f9fcfdd10ef2b96f93d6fc769c31777c340b..0bfa2e56696899c25a7cff6a5783e52e6b5673e4 100644 (file)
@@ -275,63 +275,6 @@ public class KnowledgeElement extends Persistent {
       return getOwnerScenario().getOwnerStudy().getVisibility();
     }
 
-    public void update (String description) {
-//  ---------------------------------------
-      value = description.trim();
-      if (!value.startsWith("<p>")) {
-       StringBuffer  text  = new StringBuffer("<p>");
-       int           index = value.indexOf("<p>");
-       if (index > 0) {
-         value = text.append(value.substring(0, index)).append("</p>").append(value.substring(index)).toString();
-       } else {
-          value = text.append(value).append("</p>").toString();
-       }
-      }
-      Database.getSession().update(this);   // No need to update the Lucene index
-    }
-
-//  ==============================================================================================================================
-//  Public services
-//  ==============================================================================================================================
-
-    public static KnowledgeElementType createType (String name) throws RuntimeException {
-//  -----------------------------------------------------------
-//TODO: Check for duplicate definition
-      KnowledgeElementType kelt    = new KnowledgeElementType(name);
-      Session              session = Database.getSession();          
-      session.save(kelt);
-          
-      return kelt;
-    }
-
-    @SuppressWarnings("unchecked")
-       public static List<KnowledgeElementType> selectAllTypes () {
-//  ----------------------------------------------------------
-         StringBuffer  query = new StringBuffer("from KnowledgeElementType");
-                    query = query.append(" order by rid asc");
-      return  Database.getSession().createQuery(query.toString()).list();
-    }
-
-    @SuppressWarnings("unchecked")
-       public static List<KnowledgeElementType> selectTypesWhere (ProgressState state) {
-//  -------------------------------------------------------------------------------
-         StringBuffer  query = new StringBuffer("from KnowledgeElementType where state='").append(state).append("'");
-                    query = query.append(" order by rid asc");
-      return  Database.getSession().createQuery(query.toString()).list();
-       }
-
-    public static KnowledgeElementType selectType (String name) {
-//  -----------------------------------------------------------        
-         StringBuffer  query = new StringBuffer("from KnowledgeElementType where name='").append(name).append("'");
-         return (KnowledgeElementType)Database.getSession().createQuery(query.toString()).uniqueResult();
-    }
-
-    public static KnowledgeElementType selectType (int index) {
-//  ---------------------------------------------------------
-         StringBuffer  query = new StringBuffer("from KnowledgeElementType where rid='").append(index).append("'");
-         return (KnowledgeElementType)Database.getSession().createQuery(query.toString()).uniqueResult();
-    }
-    
        /**
         * @param aState knowledge element progress state to set
         */
@@ -344,4 +287,11 @@ public class KnowledgeElement extends Persistent {
        public void setTitle(String aTitle) {
                title = aTitle;
        }
+       /**
+        * Set the value.
+        * @param value the value to set
+        */
+       public void setValue(String value) {
+               this.value = value;
+       }
 }
\ No newline at end of file
index 0ce5c59706bd9b83ca18b9a92118228985d0ecdf..c869da1c22d36d54f8900a7350b99586a671ce79 100644 (file)
@@ -108,16 +108,6 @@ public class Publication extends Persistent {
       return true;
     }
 
-    public ConvertsRelation attach (String format) {
-//  ----------------------------------------------
-      return mydoc.attach(format);
-    }
-
-    public ConvertsRelation attach (String format, String description) {
-//  ------------------------------------------------------------------
-      return mydoc.attach(format, description);
-    }
-
 /**
  * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into
  * which the referenced document has been published.<br/>
@@ -209,11 +199,6 @@ public class Publication extends Persistent {
        public void setIsnew(char isnew) {
                this.isnew = isnew;
        }
-       public void rename (String title) throws InvalidPropertyException {
-//  ---------------------------------
-      mydoc.rename(title);
-    }
-
 /**
  * Out-dates this publication and recursively all publications using this one.
  * Typically, a publication is out-dated when modifying a document to which it depends.
index f4458be27273f8ded91f0b01a4f9200d54edb2a7..362e169074d8cec615a1f1f7454d83e9ea7839aa 100644 (file)
@@ -5,7 +5,6 @@ package org.splat.dal.bo.som;
  * @copyright OPEN CASCADE 2012
  */
 
-import java.io.IOException;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.Date;
@@ -16,17 +15,12 @@ import java.util.Set;
 import java.util.HashSet;
 import java.util.Vector;
 
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.splat.dal.bo.kernel.Persistent;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.dao.som.Database;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
-import org.splat.service.StepService;
-import org.splat.service.technical.IndexService;
 import org.splat.som.Step;
 
 
@@ -36,19 +30,34 @@ public class Scenario extends ProjectElement {
     private Study                 owner;
        private int                   sid;               // Identifier unique in the scope of owner study
        private User                  cuser;             // User having checked-out the scenario, if done
+    /**
+     * The persistent set of scenario knowledge elements.
+     */
     private Set<KnowledgeElement> kelms;
 
 //  Transient fields
-    private HashMap<Long, List<KnowledgeElement>> known;
-    private List<KnowledgeElement>                   knowl;  // Copy of kelms excluding the internal Knowledge Element (ucase below)
-       private KnowledgeElement                         ucase;  // Internal Knowledge Element for accessing to all used simulation contexts
+    /**
+     * The transient map of knowledge elements grouped by types.
+     */
+    transient private HashMap<Long, List<KnowledgeElement>> known;
+    /**
+     * The scenario transient list of knowledge elements.
+     */
+    transient private List<KnowledgeElement>                   knowl;  // Copy of kelms excluding the internal Knowledge Element (ucase below)
+       /**
+        * The scenario transient "use case" knowledge element.
+        */
+       transient private KnowledgeElement                         ucase;  // Internal Knowledge Element for accessing to all used simulation contexts
 
 
 //  ==============================================================================================================================
 //  Construction
 //  ==============================================================================================================================
 
-//  Fields initialization class
+
+    /**
+     *   Fields initialization class.
+     */
     public static class Properties extends Persistent.Properties {
 //  ------------------------------------------------------------
       private Study    owner    = null;
@@ -151,7 +160,7 @@ public class Scenario extends ProjectElement {
       kelms   = new HashSet<KnowledgeElement>();
 
       manager = sprop.manager;
-      if (!owner.isStaffedBy(manager)) throw new InvalidPropertyException("manager");
+//RKV: The business logic is moved to business services:      if (!owner.isStaffedBy(manager)) throw new InvalidPropertyException("manager");
 
       credate = sprop.date;        // Inherited attribute
       if (credate == null) {
@@ -258,26 +267,29 @@ public class Scenario extends ProjectElement {
 //  Private services
 //  ==============================================================================================================================
        /**
-        * @return
+        * Get the persistent set of knowledge elements.
+        * @return the persistent set of scenario knowledge elements
         */
        public Set<KnowledgeElement> getKnowledgeElements() {
                return kelms;
        }
-       /**
-        * @param kelm
+       /** 
+        * Get the transient list of knowledge elements.
+        * @return the transient list of knowledge elements
         */
-       public void setUcase(KnowledgeElement kelm) {
-               ucase = kelm;
+       public List<KnowledgeElement> getKnowledgeElementsList() {
+               return knowl;
        }
        /**
-        * @return
+        * Set the scenario transient "use case" knowledge element.
+        * @param kelm the scenario transient "use case" knowledge element
         */
-       public List<KnowledgeElement> getKnowledgeElementsList() {
-               return knowl;
+       public void setUcase(KnowledgeElement kelm) {
+               ucase = kelm;
        }
        /**
-        * Get the ucase.
-        * @return the ucase
+        * Get the scenario transient "use case" knowledge element.
+        * @return the scenario transient "use case" knowledge element
         */
        public KnowledgeElement getUcase() {
                return ucase;
index 7fdb682013fc1b1f7a4f457acf49080a989db60f..1fd88f4b560c76a4bd8c021330a0306cc273f649 100644 (file)
@@ -1,4 +1,5 @@
 package org.splat.dal.bo.som;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
@@ -6,443 +7,392 @@ package org.splat.dal.bo.som;
  */
 
 import java.util.Calendar;
-import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.LinkedList;
+import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
 
-import org.hibernate.Session;
 import org.splat.dal.bo.kernel.Persistent;
-import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
-import org.splat.dal.dao.som.Database;
 import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
-import org.splat.kernel.UserDirectory;
-import org.splat.service.StepService;
-import org.splat.service.technical.IndexServiceImpl;
-import org.splat.service.technical.ProjectSettingsServiceImpl;
-import org.splat.service.technical.ProjectSettingsServiceImpl.ProjectSettingsValidationCycle;
 import org.splat.som.Revision;
 
-
+/**
+ * Siman Study persistent object.
+ */
 public class Study extends ProjectElement {
 
-//  Persistent fields
-    private String         sid;                // External unique reference in a format conform to the configuration pattern
-    private int            docount;            // Total number of documents of this study, including versions
-    private ProgressState  state;
-    private Visibility     visibility;
-    private List<Scenario> scenarii;
-    private String         version;
-    private int            history;            // Number of studies versioning this one, if any
-
-//  Transient fields
-    private List<User>                      contributor;  // Shortcut to contributors
-    private HashMap<String,ValidationCycle> validactor;   // Shortcut to validation cycles
-    private Set<User>                       actor;        // Summary of above actors
-       private StepService _stepService;
-
-//  ==============================================================================================================================
-//  Construction
-//  ==============================================================================================================================
-
-//  Fields initialization class
-    public static class Properties extends Persistent.Properties {
-//  ------------------------------------------------------------
-      private String                  sid        = null;                             // Search criterion only
-      private String                  title      = null;
-      private String                  summary    = null;
-      private User                    manager    = null;
-      private User                    actor      = null;                             // Search criterion only
-      private Visibility              visibility = null;                             // Search criterion only
-      private ProgressState           state      = null;                             // Search criterion only
-      private Date                    date       = null;
-      private List<SimulationContext> context    = new Vector<SimulationContext>();  // Search criterion only
-
-//  - Public services
-
-      public void clear () {
-        super.clear();
-        sid        = null;
-        title      = null;
-        summary    = null;
-        manager    = null;
-        actor      = null;
-        visibility = null;
-        state      = null;
-        date       = null;
-        context    = new Vector<SimulationContext>();      // as clear() may generate side effects
-      }
-      public Properties copy () {
-        Properties copy = new Properties();
-        copy.sid        = this.sid;
-        copy.title      = this.title;
-        copy.summary    = this.summary;
-        copy.manager    = this.manager;
-        copy.actor      = this.actor;
-        copy.visibility = this.visibility;
-        copy.state      = this.state;
-        copy.date       = this.date;
-        copy.context    = this.context;
-        return copy;
-      }
-//  - Protected services
-
-      public User getActor () {
-       return actor;
-      }
-      public User getManager () {
-               return manager;
-         }
-      public ProgressState getProgressState () {
-        return state;
-         }
-      public String getReference () {
-        return sid;
-      }
-      public List<SimulationContext> getSimulationContexts () {
-           return context;
-         }
-      public String getTitle () {
-          return title;
-        }
-      public String getSummary () {
-          return summary;
-        }
-      public Visibility getVisibility () {
-       return visibility;
-      }
-//  - Property setters
-
-//    For building a search query
-      public Properties setActor (User actor)
-      {
-       this.actor = actor;
-       return this;
-      }
-      public Properties setDate (Date date)
-      {
-       this.date = date;
-        return this;
-      }
-      public Properties setDescription (String summary)
-      {
-       if (summary.length() > 0) this.summary = summary;
-       return this;
-      }
-      public Properties setManager (User user)
-      {
-       this.manager = user;
-        return this;
-      }
-//    For building a search query
-      public Properties setReference (String sid) throws InvalidPropertyException
-      {
-        if (sid.length() == 0) throw new InvalidPropertyException("reference");
-        this.sid = sid;
-        return this;
-      }
-//    For building a search query
-      public Properties setSimulationContexts (List<SimulationContext> context) {
-        this.context = context;
-        return this;
-      }
-//    For building a search query
-      public Properties setState (ProgressState state)
-      {
-        this.state = state;
-        return this;
-      }
-      public Properties setTitle (String title) throws InvalidPropertyException
-      {
-        if (title.length() == 0) throw new InvalidPropertyException("title");
-        this.title = title;
-        return this;
-      }
-//    For building a search query
-      public Properties setVisibility (Visibility area)
-      {
-        this.visibility = area;
-        return this;
-      }
-//  - Global validity check
-      
-      public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
-      {
-        if (title == null)   throw new MissedPropertyException("title");
-        if (manager == null) throw new MissedPropertyException("manager");
-      }
-    }
-//  Database fetch constructor
-    protected Study () {
-//  ------------------
-      contributor = null;
-      validactor  = null;
-      actor       = null;
-    }
-//  Internal constructor
-    public Study (Properties sprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
-//  ----------------------------------
-      super(sprop);                 // Throws one of the above exception if not valid
-      sid        = sprop.sid;   // Reset after save
-      title      = sprop.title;                             // Inherited attribute
-      manager    = sprop.manager;
-      docount    = 0;
-      history    = 0;
-      scenarii   = new LinkedList<Scenario>();
-      visibility = Visibility.PRIVATE;
-      state      = ProgressState.inWORK;
-
-      credate = sprop.date;                                 // Inherited attribute
-      if (credate == null) {
-        Calendar current = Calendar.getInstance();
-        credate = current.getTime();                        // Today
-      }
-      lasdate  = credate;                                   // Inherited attribute
-      version  = new Revision().incrementAs(state).toString();
-
-      if (sprop.summary != null) this.setAttribute( new DescriptionAttribute(this, sprop.summary) );
-
-      contributor = null;
-      validactor  = null;
-      actor       = null;
-    }
-
-    /**
-     * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
-     * 
-     * @return the actors of this study
-     * @see    #hasActor(User)
-     */
-        public Set<User> getActors () {
-    //  -----------------------------
-          if (actor == null) setShortCuts();
-          return Collections.unmodifiableSet(actor);
-        }
-
-        /**
-         * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
-         * 
-         * @return the actors of this study
-         * @see    #hasActor(User)
-         */
-            public Set<User> getModifiableActors () {
-        //  -----------------------------
-              if (actor == null) setShortCuts();
-              return actor;
-            }
-
-            public List<User> getContributors () {
-            //  ------------------------------------
-                  if (contributor == null) setShortCuts();
-                  return Collections.unmodifiableList(contributor);     // May be empty
-                }
-
-            public List<User> getModifiableContributors () {
-                  if (contributor == null) setShortCuts();
-                  return contributor;     // May be empty
-                }
-
-    public ProgressState getProgressState () {
-//  ----------------------------------------
-      return state;
-    }
+       // Persistent fields
+       /**
+        * Persistent sid property. It is an external unique reference in a format conform to the configuration pattern.
+        */
+       private String sid;
+       /**
+        * Persistent docount property. It is a total number of documents of this study, including versions.
+        */
+       private int docount;
+       /**
+        * Persistent state property. It is a study progress state.
+        * 
+        * @see org.splat.dal.bo.som.ProgressState enumeration
+        */
+       private ProgressState state;
+       /**
+        * Persistent visibility property.
+        * 
+        * @see org.splat.dal.bo.som.Visibility enumeration
+        */
+       private Visibility visibility;
+       /**
+        * Persistent list of study scenarii.
+        */
+       private List<Scenario> scenarii;
+       private String version;
+       /**
+        * Persistent history property. It is a number of studies versioning this one, if any.
+        */
+       private int history;
 
-/**
- * Returns the global unique reference of this study.
- * The study reference is common to all versions of the study (versioning a study does not change its reference).
- * The form of this study reference is defined in the configuration of the application server - see the SOM XML customization
- * file.
- */
-    public String getReference () {
-      return sid;
-    }
+       // Transient fields
+       /**
+        * Transient list of contributors.
+        */
+       private transient List<User> contributor = new Vector<User>(); // Shortcut to contributors
+       /**
+        * Transient map of document types to validation cycles.
+        */
+       private transient Map<String, ValidationCycle> validactor = new HashMap<String, ValidationCycle>(); // Shortcut to validation cycles
+       /**
+        * Transient set of all actors of the study, i.d. contributors and validation cycles participants.
+        */
+       private transient Set<User> actor = new HashSet<User>(); // Summary of above actors
 
-    public void setReference (String aReference) {
-      sid = aReference;
-    }
+       // ==============================================================================================================================
+       // Construction
+       // ==============================================================================================================================
 
-    public Scenario[] getScenarii () {
-//  --------------------------------
-      return  scenarii.toArray(new Scenario[scenarii.size()]);
-    }
+       /**
+        * Fields initialization class.
+        */
+       public static class Properties extends Persistent.Properties {
+               // ------------------------------------------------------------
+               private String sid = null; // Search criterion only
+               private String title = null;
+               private String summary = null;
+               private User manager = null;
+               private User actor = null; // Search criterion only
+               private Visibility visibility = null; // Search criterion only
+               private ProgressState state = null; // Search criterion only
+               private Date date = null;
+               private List<SimulationContext> context = new Vector<SimulationContext>(); // Search criterion only
+
+               // - Public services
+
+               public void clear() {
+                       super.clear();
+                       sid = null;
+                       title = null;
+                       summary = null;
+                       manager = null;
+                       actor = null;
+                       visibility = null;
+                       state = null;
+                       date = null;
+                       context = new Vector<SimulationContext>(); // as clear() may generate side effects
+               }
+
+               public Properties copy() {
+                       Properties copy = new Properties();
+                       copy.sid = this.sid;
+                       copy.title = this.title;
+                       copy.summary = this.summary;
+                       copy.manager = this.manager;
+                       copy.actor = this.actor;
+                       copy.visibility = this.visibility;
+                       copy.state = this.state;
+                       copy.date = this.date;
+                       copy.context = this.context;
+                       return copy;
+               }
+
+               // - Protected services
+
+               public User getActor() {
+                       return actor;
+               }
+
+               public User getManager() {
+                       return manager;
+               }
+
+               public ProgressState getProgressState() {
+                       return state;
+               }
+
+               public String getReference() {
+                       return sid;
+               }
+
+               public List<SimulationContext> getSimulationContexts() {
+                       return context;
+               }
+
+               public String getTitle() {
+                       return title;
+               }
+
+               public String getSummary() {
+                       return summary;
+               }
+
+               public Visibility getVisibility() {
+                       return visibility;
+               }
+
+               // - Property setters
+
+               // For building a search query
+               public Properties setActor(User actor) {
+                       this.actor = actor;
+                       return this;
+               }
+
+               public Properties setDate(Date date) {
+                       this.date = date;
+                       return this;
+               }
+
+               public Properties setDescription(String summary) {
+                       if (summary.length() > 0)
+                               this.summary = summary;
+                       return this;
+               }
+
+               public Properties setManager(User user) {
+                       this.manager = user;
+                       return this;
+               }
+
+               // For building a search query
+               public Properties setReference(String sid)
+                               throws InvalidPropertyException {
+                       if (sid.length() == 0)
+                               throw new InvalidPropertyException("reference");
+                       this.sid = sid;
+                       return this;
+               }
+
+               // For building a search query
+               public Properties setSimulationContexts(List<SimulationContext> context) {
+                       this.context = context;
+                       return this;
+               }
+
+               // For building a search query
+               public Properties setState(ProgressState state) {
+                       this.state = state;
+                       return this;
+               }
+
+               public Properties setTitle(String title)
+                               throws InvalidPropertyException {
+                       if (title.length() == 0)
+                               throw new InvalidPropertyException("title");
+                       this.title = title;
+                       return this;
+               }
+
+               // For building a search query
+               public Properties setVisibility(Visibility area) {
+                       this.visibility = area;
+                       return this;
+               }
+
+               // - Global validity check
+
+               public void checkValidity() throws MissedPropertyException,
+                               InvalidPropertyException, MultiplyDefinedException {
+                       if (title == null)
+                               throw new MissedPropertyException("title");
+                       if (manager == null)
+                               throw new MissedPropertyException("manager");
+               }
+       }
 
-    public List<Scenario> getScenariiList () {
-//  --------------------------------
-      return  scenarii;
-    }
+       // Database fetch constructor
+       protected Study() {
+               contributor.clear();
+               validactor.clear();
+               actor.clear();
+       }
 
-/**
- * Returns the validation cycle of the given document type.
- * 
- * @param doc the document type being subject of validation
- * @return     the validation cycle of the document, or null if not defined.
- */
-    public ValidationCycle getValidationCycleOf (DocumentType type) {
-//  ---------------------------------------------------------------
-      if (validactor == null)    setShortCuts();
-      ValidationCycle            result = validactor.get(type.getName());
-      if (result == null) {
-        if (type.isStepResult()) result = validactor.get("default");             // "default" validation cycle defined in the configuration, if exist
-        if (result == null)      result = validactor.get("built-in");
-      }
-      return result;
-    }
-
-    public String getVersion () {
-//  ---------------------------
-      return version;
-    }
-
-    public Visibility getVisibility () {
-//  ----------------------------------
-      return visibility;
-    }
+       // Internal constructor
+       public Study(Properties sprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException {
+               // ----------------------------------
+               super(sprop); // Throws one of the above exception if not valid
+               sid = sprop.sid; // Reset after save
+               title = sprop.title; // Inherited attribute
+               manager = sprop.manager;
+               docount = 0;
+               history = 0;
+               scenarii = new LinkedList<Scenario>();
+               visibility = Visibility.PRIVATE;
+               state = ProgressState.inWORK;
+
+               credate = sprop.date; // Inherited attribute
+               if (credate == null) {
+                       Calendar current = Calendar.getInstance();
+                       credate = current.getTime(); // Today
+               }
+               lasdate = credate; // Inherited attribute
+               version = new Revision().incrementAs(state).toString();
+
+               if (sprop.summary != null)
+                       this.setAttribute(new DescriptionAttribute(this, sprop.summary));
+
+               contributor.clear();
+               validactor.clear();
+               actor.clear();
+       }
 
-/**
- * Checks if the given user is actor of this study.
- * Actors include contributors, reviewers and approvers.
- * 
- * @return true if the given user is actor of this study.
- * @see    #getActors()
- */
-    public boolean hasActor (User user) {
-//  -----------------------------------
-      if (user == null) return false;
-      for (Iterator<User> i=this.getActors().iterator(); i.hasNext(); ) {
-        User involved = i.next();
-        if  (involved.equals(user))  return true;
-         }
-      return false;
-    }
+       public ProgressState getProgressState() {
+               return state;
+       }
+
+       /**
+        * Returns the global unique reference of this study. The study reference is common to all versions of the study (versioning a study
+        * does not change its reference). The form of this study reference is defined in the configuration of the application server - see the
+        * SOM XML customization file.
+        */
+       public String getReference() {
+               return sid;
+       }
+
+       public void setReference(String aReference) {
+               sid = aReference;
+       }
+
+       public Scenario[] getScenarii() {
+               // --------------------------------
+               return scenarii.toArray(new Scenario[scenarii.size()]);
+       }
+
+       public List<Scenario> getScenariiList() {
+               // --------------------------------
+               return scenarii;
+       }
+
+       public String getVersion() {
+               // ---------------------------
+               return version;
+       }
+
+       public Visibility getVisibility() {
+               // ----------------------------------
+               return visibility;
+       }
 
-/**
- * Checks whether this study is in the Public or the Reference area of the repository.
- * 
- * @return true if the study is public.
- * @see    #moveToPublic()
- * @see    #moveToReference()
- */
-    public boolean isPublic () {
-//  --------------------------
-      return (visibility != Visibility.PRIVATE);
-    }
-/**
- * Checks if the given user participates to this study.
- * The Study staff includes the author and contributors.
- * 
- * @return true if the given user is actor of this study.
- * @see    #getContributors()
- */
-    public boolean isStaffedBy (User user) {
-//  --------------------------------------
-      if (user == null)         return false;
-      if (manager.equals(user)) return true;
-      for (Iterator<User> i=getContributors().iterator(); i.hasNext();) {
-       if (i.next().equals(user)) return true;
-      }
-      return false;
-    }
-
-    public boolean isVersioned () {
-//  -----------------------------
-      return (history > 0);
-    }
-
-    public boolean shares (Document doc) {
-//  ------------------------------------
-      Scenario[] scene   = this.getScenarii();            // If shared from within the study, the document is shared by the scenarios
-      int        counter = 0;
-
-         for (int i=0; i<scene.length; i++) {
-        if (!scene[i].publishes(doc)) continue;
-        if (counter == 1)          return true;
-        counter += 1;
-         }
-      return false;
-    }
-
-    public int getLastLocalIndex () {
-//  ----------------------------------
-      return  docount;
-    }
-
-    public void loadWorkflow () {
-//  ------------------------------
-      setShortCuts();
-    }
-
-    public void setShortCuts () {
-//  ----------------------------
-      contributor = new Vector<User>();
-      validactor  = new HashMap<String,ValidationCycle>();
-      actor       = new HashSet<User>();
-
-//    Get the contributors
-      for (Iterator<Relation> i=getRelations(ContributorRelation.class).iterator(); i.hasNext(); ) {
-        ContributorRelation  link = (ContributorRelation)i.next();
-        contributor.add(link.getTo());
-      }
-//    Get the validation cycles specific to this study
-      for (Iterator<Relation> i=getRelations(ValidationCycleRelation.class).iterator(); i.hasNext(); ) {
-        ValidationCycleRelation  link = (ValidationCycleRelation)i.next();
-        validactor.put(link.getDocumentType().getName(), link.getTo());   // The associated document type is necessarily not null in this context
-      }
-//    Get the validation cycles coming from the configured workflow and not overridden in this study
-      for (Iterator<ProjectSettingsServiceImpl.ProjectSettingsValidationCycle> i=ProjectSettingsServiceImpl.getAllValidationCycles().iterator(); i.hasNext(); ) {
-        ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle = i.next();
-        String                          type  = cycle.getName();
-        if (!validactor.containsKey(type)) validactor.put(type, new ValidationCycle(this, cycle));
-      }
-//    Get all corresponding actors
-      for (Iterator<ValidationCycle> i=validactor.values().iterator(); i.hasNext(); ) {
-        ValidationCycle cycle = i.next();
-        User[]          user  = cycle.getAllActors();
-        for (int j=0; j<user.length; j++) actor.add(user[j]);
-      }
-//    Get all other actors
-      for (Iterator<Relation> i=this.getAllRelations().iterator(); i.hasNext(); ) {
-        Relation link   = i.next();
-        Class<?> kindof = link.getClass().getSuperclass();
-        if (!kindof.equals(ActorRelation.class)) continue;
-        actor.add( ((ActorRelation)link).getTo() );
-      }
-    }
        /**
-        * @param aVisibility a study visibility to set
+        * Checks whether this study is in the Public or the Reference area of the repository.
+        * 
+        * @return true if the study is public.
+        * @see #moveToPublic()
+        * @see #moveToReference()
+        */
+       public boolean isPublic() {
+               // --------------------------
+               return (visibility != Visibility.PRIVATE);
+       }
+
+       public boolean isVersioned() {
+               // -----------------------------
+               return (history > 0);
+       }
+
+       public boolean shares(Document doc) {
+               // ------------------------------------
+               Scenario[] scene = this.getScenarii(); // If shared from within the study, the document is shared by the scenarios
+               int counter = 0;
+
+               for (int i = 0; i < scene.length; i++) {
+                       if (!scene[i].publishes(doc))
+                               continue;
+                       if (counter == 1)
+                               return true;
+                       counter += 1;
+               }
+               return false;
+       }
+
+       public int getLastLocalIndex() {
+               // ----------------------------------
+               return docount;
+       }
+
+       /**
+        * @param aVisibility
+        *            a study visibility to set
         */
        public void setVisibility(Visibility aVisibility) {
                visibility = aVisibility;
        }
+
        /**
-        * @param aState a study progress state to set
+        * @param aState
+        *            a study progress state to set
         */
        public void setProgressState(ProgressState aState) {
                state = aState;
        }
+
        /**
-        * @param string
+        * @param aVersion
         */
        public void setVersion(String aVersion) {
                version = aVersion;
        }
+
        /**
-        * @param i
+        * Set total number of documents of this study, including versions. It is stored in the persistent property docount.
+        * 
+        * @param anIndex
+        *            a number of study documents
         */
        public void setLastLocalIndex(int anIndex) {
                docount = anIndex;
        }
+
        /**
-        * @return
+        * Get the transient map of document types to validation cycles.
+        * 
+        * @return map of validation cycles
         */
-       public HashMap<String, ValidationCycle> getValidationCycles() {
+       public Map<String, ValidationCycle> getValidationCycles() {
                return validactor;
        }
+
+       /**
+        * Get the transient list of study contributors.
+        * 
+        * @return the List of User objects
+        */
+       public List<User> getContributor() {
+               return contributor;
+       }
+
+       /**
+        * Get the transient set of all study actors (contributors and validation cycles participants).
+        * 
+        * @return the set of User objects
+        */
+       public Set<User> getActor() {
+               return actor;
+       }
 }
\ No newline at end of file
index 6593c54333e98976057cec2f2989e9b778dad674..ff87997bc90b54d2e535aa7610e3c664267321ae 100644 (file)
@@ -81,7 +81,7 @@ public class Timestamp extends Any {
 //  Protected services
 //  ==============================================================================================================================
 
-    protected StampRelation getContext () {
+    public StampRelation getContext () {
 //  -------------------------------------
       return context;
     }
index 8803d52e3799926583b07e4529ac16f471eaace4..989cd25befc67f1f08cbc9749647dbbf16e91d05 100644 (file)
@@ -100,44 +100,41 @@ public class ValidationCycle extends Persistent {
       { 
         if (doctype == null) throw new MissedPropertyException("type");
       }
+
+       /**
+        * Get the publisher.
+        * @return the publisher
+        */
+       public User getPublisher() {
+               return publisher;
+       }
+
+       /**
+        * Get the reviewer.
+        * @return the reviewer
+        */
+       public User getReviewer() {
+               return reviewer;
+       }
+
+       /**
+        * Get the approver.
+        * @return the approver
+        */
+       public User getApprover() {
+               return approver;
+       }
+
+       /**
+        * Get the signatory.
+        * @return the signatory
+        */
+       public User getSignatory() {
+               return signatory;
+       }
     }
 //  Database fetch constructor
-    protected ValidationCycle () {
-    }
-//  Internal constructors
-    protected ValidationCycle (Study from, ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle) {
-//  -----------------------------------------------------------------------------
-      Actor[]         actype = cycle.getActorTypes();
-      User.Properties uprop  = new User.Properties();
-
-      mytype  = Document.selectType(cycle.getName());     // Null in case of default validation cycle
-//    context = new ValidationCycleRelation(from, this);
-      context = null;                                     // Validation cycle defined in the workflow
-      for (int i=0; i<actype.length; i++) {
-        User actor = null;
-        if (actype[i] != null)
-        try {
-          if (actype[i] == Actor.manager) {
-            actor = from.getAuthor();
-          } else
-          if (actype[i] == Actor.Nx1) {
-            List<User> manager = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Nx1"));
-            if (manager.size() == 1) actor = manager.get(0);
-          } else
-          if (actype[i] == Actor.Nx2) {
-            List<User> manager = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Nx2"));
-            if (manager.size() == 1) actor = manager.get(0);
-          } else {      /* Actor.customer */
-            actor = from.getAuthor();
-//TODO: Get the customer of the study, if exists
-          }
-        } catch (Exception e) {      // Should not happen
-          actor = null;
-        }
-        if      (i == 0) reviewer  = actor;
-        else if (i == 1) approver  = actor;
-        else if (i == 2) signatory = actor;
-      }
+    public ValidationCycle () {
     }
     public ValidationCycle (Study from, Properties vprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
 //  --------------------------------------------------------
@@ -214,8 +211,16 @@ public class ValidationCycle extends Persistent {
  * @see    #isDefault()
  */
     public DocumentType getDocumentType () {
-//  --------------------------------------
-      return mytype;                    // May be null
+    //  --------------------------------------
+          return mytype;                    // May be null
+        }
+
+    /**
+     * Set a document type for the validation cycle.
+     * @param aType the document type
+     */
+    public void setDocumentType (DocumentType aType) {
+          mytype = aType;                    // May be null
     }
 
 /**
@@ -252,30 +257,32 @@ public class ValidationCycle extends Persistent {
 //  -----------------------------------------------
       return context;
     }
-
-    protected void remove (ValidationStep step) {
-//  ------------------------------------------
-      if      (step == ValidationStep.REVIEW)     reviewer  = null;
-      else if (step == ValidationStep.APPROVAL)   approver  = null;
-      else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = null;
-      if (this.isSaved()) Database.getSession().update(this);
-    }
-
-    public void resetActors (Properties vprop) {
-//  ---------------------------------------------
-      publisher = vprop.publisher;   // May be null
-      reviewer  = vprop.reviewer;    // May be null
-      approver  = vprop.approver;    // May be null
-      signatory = vprop.signatory;   // May be null
-      if (this.isSaved()) Database.getSession().update(this);
-    }
-
-    protected void setActor (ValidationStep step, User actor) {
-//  --------------------------------------------------------
-      if      (step == ValidationStep.PROMOTION) publisher = actor;
-      else if (step == ValidationStep.REVIEW)    reviewer  = actor;
-      else if (step == ValidationStep.APPROVAL)  approver  = actor;
-      else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = actor;
-      if (this.isSaved()) Database.getSession().update(this);
-    }
+       /**
+        * Set the publisher.
+        * @param publisher the publisher to set
+        */
+       public void setPublisher(User publisher) {
+               this.publisher = publisher;
+       }
+       /**
+        * Set the reviewer.
+        * @param reviewer the reviewer to set
+        */
+       public void setReviewer(User reviewer) {
+               this.reviewer = reviewer;
+       }
+       /**
+        * Set the approver.
+        * @param approver the approver to set
+        */
+       public void setApprover(User approver) {
+               this.approver = approver;
+       }
+       /**
+        * Set the signatory.
+        * @param signatory the signatory to set
+        */
+       public void setSignatory(User signatory) {
+               this.signatory = signatory;
+       }
 }
\ No newline at end of file
index d554554c3550d48a9ccd6bea424c89cbd63dd548..1afa838471eb3cf6e9a7d08494e26212d11f33f8 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 8059f70472e9db463888a29a3fabc7acfbfd1db0..2a8d6461af891e4f832f299a686023186b266696 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 85d23ed8d0c0791ef8a940761ab3f08b71b4ed89..22e7036b65d1ca048112c9347780d95e49ea334e 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index eb446ebfc4b7ec2388474f10e30f7709a6f237f2..fc639d1efdcddf72b96fb3847025d3fc4ebbc00d 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index e8e09dae189198d95e04594522fe61ef6120a26b..9b219dc4393cece7857096fc085c92308a2ab1bd 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 938d6f7fb8614d0578bae7c0adab8a13b0327aa1..62e383b12142d8d8817b8867d001aa581b12ef1c 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 9ae2887d9287711adfbb627eff7926d7adcbaa72..68f67d29912040d0f2b1fc039113a2d859dc5793 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   08.10.2012
@@ -70,6 +70,24 @@ public interface GenericDAO<T, PK extends Serializable> {
         */
        public T findByCriteria(Criterion aCondition);
 
+       /**
+        * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
+        * 
+        * @return a list of all objects of the considered type T
+        */
+       @SuppressWarnings("unchecked")
+       public List<T> getAll();
+
+       /**
+        * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
+        * 
+        * @param anOrder
+        *            a result list order. Null is ignored and in such case the result list is unordered.
+        * @return an ordered list of all objects of the considered type T
+        */
+       @SuppressWarnings("unchecked")
+       public List<T> getAll(Order anOrder);
+       
        /**
         * Retrieve a list of objects which were previously persisted to the database using the given criteria.
         * 
@@ -89,4 +107,20 @@ public interface GenericDAO<T, PK extends Serializable> {
         */
        @SuppressWarnings("unchecked")
        public List<T> getFilteredList(Criterion aCondition, Order anOrder);
+
+       /**
+        * Makes detached object persistent.
+        * @param transientObject
+        *            transient instance of the object to be made persistent
+        */
+       public void persist(T transientObject);
+
+       /**
+        * Merge detached object with persistent data.
+        * 
+        * @param transientObject
+        *            transient instance of the object to be merged with persistent data
+        * @return merged persistent object
+        */
+       public T merge(T transientObject);
 }
index d76653b7be14998d2cca2b9166f274fbcde0f171..64d3a6a4c598820d23f601a26fc7a9f491aa780c 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   08.10.2012
@@ -15,7 +15,6 @@ import java.util.List;
 import org.hibernate.Criteria;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Restrictions;
 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 
 /**
@@ -67,6 +66,32 @@ public abstract class GenericDAOImpl<T, PK extends Serializable> extends
                                .uniqueResult();
        }
 
+       /**
+        * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
+        * 
+        * @return a list of all objects of the considered type T
+        */
+       @SuppressWarnings("unchecked")
+       public List<T> getAll() {
+               return getSession().createCriteria(getType()).list();
+       }
+
+       /**
+        * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
+        * 
+        * @param anOrder
+        *            a result list order. Null is ignored and in such case the result list is unordered.
+        * @return an ordered list of all objects of the considered type T
+        */
+       @SuppressWarnings("unchecked")
+       public List<T> getAll(Order anOrder) {
+               Criteria aCriteria = getSession().createCriteria(getType());
+               if (anOrder != null) {
+                       aCriteria.addOrder(anOrder);
+               }
+               return aCriteria.list();
+       }
+
        /**
         * Retrieve a list of objects which were previously persisted to the database using the given criteria.
         * 
@@ -118,6 +143,28 @@ public abstract class GenericDAOImpl<T, PK extends Serializable> extends
                getSession().delete(persistentObject);
        }
 
+       /**
+        * Makes detached object persistent.
+        * 
+        * @param transientObject
+        *            transient instance of the object to be made persistent
+        */
+       public void persist(T transientObject) {
+               getSession().persist(transientObject);
+       }
+
+       /**
+        * Merge detached object with persistent data.
+        * 
+        * @param transientObject
+        *            transient instance of the object to be merged with persistent data
+        * @return merged persistent object
+        */
+       @SuppressWarnings("unchecked")
+       public T merge(T transientObject) {
+               return (T) getSession().merge(transientObject);
+       }
+
        /**
         * Get persistent object type.
         * 
index 651148ddf79d43dc0f6648873bcc7555d34a2971..a7ad02f6bcfe1297e5b11bc78466d04b7dd1799e 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 53ff63d5da73ee25e802cc4c5029ea1fcd7602ec..a95ea661658459435e969aaba90a4e8e7f4bab96 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index e8e09fcc99ac0e5153356ac8e084ed7ac266e247..10820f10b6afdd346050b337756994dd9e1da93f 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index e1247fd0f8bab292d8d7f01fdb48d5e89c1bacee..2e785228302243e031b844be86a539ecfb62d73f 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 5f32b668924aa2243da0894ce2c56c98d7875e6a..900f464aa12e46e35a75e6bb6ef3e441bca6ffb5 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 4c2fb01ced4416f1022208ab71f4f105cfc395cd..732abb28ea0fd3d10d4ad56b6bbf46c79458c8dd 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index c003804a937e8dbf5ce21835255444cfcec89aaa..6e463900ada28eb4b183cbdfa10f8f7782e44ecd 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 922414690eab1d98dff2a2faecd00b6ec84c1fcb..eef3992fa163fbc8f9ad51832628bf96ed666f49 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 01b386d0675ee45373147805d0d00eb6ab3ce8e3..3bb4f41d6e02f74bcaf05121fa0c517862c70d9f 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 7a721b69f0d69ac67eedff39451bbef78df0c79a..be184408e235df5e8d63b1817885561da0ed6958 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 84d9b5e39574b8dcddd788890b736e2ddd4fd4b7..4ca3260a6240443a294dcc3a5187b1ad818beddf 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 87b4125515fa6b6a8df3340cba65b67c92a15930..e908dfb90cecf7c2c0b52ae680cd2bc0be049ee5 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index df35aebfdd4ee93c312628f1f863dc64dd698d30..4cd4c873363c46caf51d75ea0d641b6808103772 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index c4b014d7a0a8f614559323017e2fb7eae84dfe6d..43c5e54d9ba6f6caf329c2adf5fbaa841df0f307 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 5f6eb473c0c2b201d2aed6d1e237de19b34c9a1b..c56c7301e6783f9f4a64f26c1a9f3b6e64b3e18e 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 59e48d812baccb7ab29930d2aa3944e4292a9b6c..74a3b1680dda4e606a2bb06dc5a01d516a2733a2 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 71b36338b646992b475e81e8798b45a5bf6d13c8..2f47380eead0320387d96b6cd76b890032a56442 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index dfb94f586c0cc00554051d0d05c169bd0c8b56d1..5004061ffc70e011f09996fc331ce3e712f496e7 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 439109af94d52e1dd5fae22ab2ca8adccb26989b..9677aaaa50c8bcffecb10b32202153b9d15d4c86 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 4527ce06f3626c1916ce875c959a37b711570319..3a0ed00c7aa089658ed2ab8ec74574f7e9c70436 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 896d48527622ae956bd17200435256c30c3f0b44..96163ef975c80a4519ffab3d6bea68bde2c14e72 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 13699317d434bd8cd7abb12f10598359e5dba06f..ca139e372f567afe5d157f0fa185cd5a6b40110d 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index e415f66c113c59a618fa878be14f091ad4e33fdd..dcdc8ba90dc4d0fa6234037b429ae66aa8a429b6 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 115cd38857807fb4b4858d2da2811f8df20fdf5a..d559ebc6e92ac48ecbe71c8bf0eaa012d3099144 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index ab15fdd2cb3194e2fdccadddce396f7c4a5399fb..1541a105faf0acf906c7fd23536058362f9fd75f 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 088adeffb9f5ea58866ad7baaee8d7535ac68fae..00590cc29b963f54810644d4c5ae8a83e197ec67 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 59e3ce5e1b9191f4d41b7c64cf0d3b083d5500b6..99218cd151cf97344f697f25f9ea948cb7286fe6 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 8ef22564ffd6cb76a82211bab7d08344a127a45f..7d660eac503bf0bc13af4c446ae2079ccc204d31 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index dd4fbc1adb9ba9cd49639a1b211910ea7e17931d..e25072a63efaf1a4155a1a424ea49083fe441fe7 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 9343f554d1994e1e8e0a57f5ff702085faf22611..a5a70ec301d8c60806f128bb4a97e7c454f6166a 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 414f8268f349fbb83a2295f81462e963edbc72d1..8391883297afdca805a6a55b1ed8abbe2e518d11 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 2423845ac38e8c28dbc24944f394bd534df6563d..920e530863c140328a81adb4673983c372a7b412 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index eb2ae9bea922df6952d7584d223e221b3392a39f..baef74ca7d1fc3ab8ea19aa6594481f81488a648 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 20531c23469c3e1f4a0eb142ef06edf509dc4a57..4c1a7ecc7183d5b9d85c4ccd53b174ab1f85d053 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 0bf5554352010501ff5779dfaaa6cceb2a52c5ed..bd1ad8cd5379e89305b817e8d212fc17b8585a97 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index ed85d859c119166243297c8cdb27efdfe2f9682e..3066bc43812d145bbf2234802055bfee1f908d1d 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index ddb279c385ead79b6433b0cce1e5a3bdafb021eb..78c50a750bf4eedd7426e35e4d3fe2a44bacc059 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 6cdcdd247063e9b8dc6e1569f2ec887d9414f732..9f66a7dae420b2459fc85b3dc9f864106b2e02ef 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 5ec1476c0515f03e15ac9d3ff747f0233c7d6f2e..5b3c5139b7cd72fd963ab09b1af801f2f5dfaac4 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 9ff5306d5a81227f2a0620b63c282b73e584500a..e6e3aa6871208f923adf736fd24dbf0c918d29cd 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 869cf59d0c417014e90342e2dd79707994be3259..2639da2ba676908d5c0188e019ae7ccd93a808f4 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index cd2d1d97109424275402f84b0180f2cbc0d147f8..dca4c40c977c94b5204b546aaea74b75fcc89f4b 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 0bd25f0feffc9f5ad32d9f22143b0dcb23c52aa1..dfb24870e7c651a0f2827078f5bb4ddb36657359 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index c7ce03e1335b8da142f7be3c95ed6634180ed6a6..1b4078ca727aa79dbb3fab81d5274892d2de4f35 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index d8fe1df4943ca47c8e571454f27a036073d550b9..0c5254b393b7ed15f247eb67a4c1b632fc3cf4ae 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 3f77cd57bb5f186fc0cd093b0e1ad242a0994d10..2d6a3a4e3deb4826256f8eaa241738b946a0d591 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 358f20f9966b928818aaf201933ed56a5665dc79..a89ce0939b1663f54c57cefc2d58fdfae933be65 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 3ba01cfcb63f51ea2cfc0cc671b856a3b1d0d07e..da0ad869859760180ff348457316cb3ce527970a 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 03666bae2145922cdd187be93cf74deb0b0f5571..fbae333c10ca9d7b4f4edc08c5f62a73c70fcf9b 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 05147aeb057ee3ddfd769ba4cb5840b33ad39c01..fae40cee36e587e07b04e1b65704966e6603727d 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 07c8cfcb6175b6df640af9e4e6b23e460e0d590f..468549a565be9a03e555e71682c7d0dd3dbea1d7 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index c03bce74044c98408d116a0bd3b816c8b3c9e0a1..247e0beb18593cca6a6a1da836617b9f845bea33 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 0f8ae1e0e64e9849b498a64ba4f3b18834f15224..da215484a3941b1fbb4e30f88cd4902804d2d948 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            Id: 
  * Creation date   02.10.2012
index b87884a3ec268c5fc7eaa4f27ab9056ab10bd55e..b174567aab58673728b0ca2f947481f803b8d9a1 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            Id: 
  * Creation date   02.10.2012
index 008488462ad79a49b2a29c046fdd9ac5946f9e86..8dc10e33c1cddc1d441540a030d38962aabf6947 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   03.10.2012
index 1d73311c43f659e665ba7d86eb33bcb518f3e031..44990da5dbfd9340d1fce52cdab0bc054573bffa 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   03.10.2012
index 54bf6633c654ecf8237c3804cd2fa36dda7d9126..08fe7803d103a801ef8c58503b06a1002b7e070a 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   03.10.2012
index 5f3b06ed8806a4c0304f300ebfdeadd9376f44df..679ddec128bb86afe700411a2b01da5276da7c98 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            Id: 
  * Creation date   02.10.2012
index 7463e6f9436e07e0a9ee9b8ef44cd397d8a530e1..9062fff8e68af27460bbaeb73fed9be0e678c478 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   02.10.2012
index 967489c7642c37f173f64643bf8ae56cca6881a4..84078b42f9ef03218e825e4ac655388fcbcb7959 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -9,17 +9,28 @@
 
 package org.splat.service;
 
+import java.util.List;
+
+import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.ProjectElement;
+import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.Timestamp;
 import org.splat.dal.bo.som.Document.Properties;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.NotApplicableException;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.som.Revision;
 import org.splat.som.Step;
 
 /**
  * Document service interface.
  * 
- * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a> 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  * 
  */
 public interface DocumentService {
@@ -73,11 +84,155 @@ public interface DocumentService {
         *            document properties (owner project element is used)
         */
        public void generateDocumentId(Document aDoc, Properties dprop);
-       
+
        /**
         * Get a directory where the document file is saved.
-        * @param aDoc the document
+        * 
+        * @param aDoc
+        *            the document
         * @return a directory
         */
        public java.io.File getSaveDirectory(Document aDoc);
+
+       /**
+        * Extract title and reference properties from the given file.
+        * 
+        * @param file
+        *            the file to parse
+        * @return the extracted properties
+        */
+       public Properties extractProperties(java.io.File file);
+
+       /**
+        * Create "Converts" relation for the given document and the given format.
+        * 
+        * @param aDoc
+        *            the document
+        * @param format
+        *            the format
+        * @return the created "Converts" relation
+        */
+       public ConvertsRelation attach(Document aDoc, String format);
+
+       /**
+        * Create "Converts" relation for the given document, format and description.
+        * 
+        * @param aDoc
+        *            the document
+        * @param format
+        *            the format
+        * @param description
+        *            the description of the relation
+        * @return the created "Converts" relation
+        */
+       public ConvertsRelation attach(Document aDoc, String format,
+                       String description);
+
+       /**
+        * Build a reference (document id) for the given document in the given study basing on the given original document.
+        * 
+        * @param aDoc
+        *            the document to set set the new reference to
+        * @param scope
+        *            the study
+        * @param lineage
+        *            the original document
+        * @return true if the new reference is set
+        */
+       public boolean buildReferenceFrom(Document aDoc, ProjectElement scope,
+                       Document lineage);
+
+       /**
+        * Build a reference (document id) for the given document in the given study.
+        * 
+        * @param aDoc
+        *            the document to set set the new reference to
+        * @param scope
+        *            the study
+        * @return true if the new reference is set
+        */
+       public boolean buildReferenceFrom(Document aDoc, Study scope);
+
+       /**
+        * Demote a document.
+        * 
+        * @param aDoc
+        *            the document to demote
+        * @return true if demoting succeeded
+        */
+       public boolean demote(Document aDoc);
+
+       /**
+        * Promote a document.
+        * 
+        * @param aDoc
+        *            the document to promote
+        * @param stamp
+        *            the timestamp of the promotion
+        * @return true if promotion succeeded
+        */
+       public boolean promote(Document aDoc, Timestamp stamp);
+
+       /**
+        * Increments the reference count of this document following its publication in a Study step.
+        * 
+        * @param aDoc
+        *            the document to hold
+        * @see #release()
+        */
+       public void hold(Document aDoc);
+
+       /**
+        * Decrements the reference count of this document following the removal of a Publication from a Study step.
+        * 
+        * @param aDoc
+        *            the document to release
+        * @see #hold()
+        */
+       public void release(Document aDoc);
+
+       /**
+        * Rename a document.
+        * 
+        * @param aDoc
+        *            the document to rename
+        * @param title
+        *            the new document title
+        * @throws InvalidPropertyException
+        *             if the new title is empty
+        */
+       public void rename(Document aDoc, String title)
+                       throws InvalidPropertyException;
+       
+       /**
+        * Update a version of the given document.
+        * 
+        * @param aDoc
+        *            the document
+        * @param newvers
+        *            the new version
+        */
+       public void updateAs(Document aDoc, Revision newvers);
+       
+       /**
+        * Update a state of the given document.
+        * 
+        * @param aDoc
+        *            the document
+        * @param state
+        *            the new state
+        */
+       public void updateAs(Document aDoc, ProgressState state);
+
+       /**
+        * Checks if documents of this type are result of a study. A document is the result of a study when it is the result of the last step of
+        * the study.
+        * 
+        * @param aType
+        *            the document type
+        * @return true if documents of this type are result of a study.
+        * @see #isStepResult()
+        * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+        */
+       public boolean isStudyResult(DocumentType aType);
 }
index 1d06100c05b1246a3fa52378dd7a1f13fae1c528..df410aa36a93ec9ad76d9e850cf3c87d00402e6d 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -12,21 +12,40 @@ package org.splat.service;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
 
+import org.hibernate.Hibernate;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Restrictions;
+import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.File;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.StampRelation;
 import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.Timestamp;
+import org.splat.dal.bo.som.ValidationStep;
+import org.splat.dal.bo.som.VersionsRelation;
 import org.splat.dal.bo.som.Document.Properties;
 import org.splat.dal.dao.som.DocumentDAO;
+import org.splat.dal.dao.som.DocumentTypeDAO;
+import org.splat.dal.dao.som.FileDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
 import org.splat.kernel.NotApplicableException;
+import org.splat.manox.Reader;
+import org.splat.manox.Toolbox;
 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.splat.som.Revision;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -50,9 +69,17 @@ public class DocumentServiceImpl implements DocumentService {
         */
        private RepositoryService _repositoryService;
        /**
-        * Injected document service.
+        * Injected document DAO.
         */
        private DocumentDAO _documentDAO;
+       /**
+        * Injected document type DAO.
+        */
+       private DocumentTypeDAO _documentTypeDAO;
+       /**
+        * Injected file DAO.
+        */
+       private FileDAO _fileDAO;
 
        /**
         * {@inheritDoc}
@@ -154,6 +181,7 @@ public class DocumentServiceImpl implements DocumentService {
         * 
         * @see org.splat.service.DocumentService#initialize(org.splat.dal.bo.som.Document, org.splat.dal.bo.som.Document.Properties)
         */
+       @Transactional
        public void initialize(Document aDoc, Properties dprop)
                        throws MissedPropertyException, InvalidPropertyException,
                        NotApplicableException {
@@ -201,6 +229,345 @@ public class DocumentServiceImpl implements DocumentService {
                return new java.io.File(path.append("/").toString());
        }
 
+       /**
+        * Extract title and reference properties from the given file.
+        * 
+        * @param file
+        *            the file to parse
+        * @return the extracted properties
+        */
+       public Properties extractProperties(java.io.File file) {
+               Properties fprop = new Properties();
+               Reader tool = Toolbox.getReader(file);
+               String value;
+               if (tool != null)
+                       try {
+                               value = tool.extractProperty("title");
+                               if (value != null)
+                                       fprop.setName(value);
+
+                               value = tool.extractProperty("reference");
+                               if (value != null)
+                                       fprop.setReference(value);
+                       } catch (Exception e) {
+                       }
+               return fprop;
+       }
+
+       /**
+        * Create "Converts" relation for the given document and the given format.
+        * 
+        * @param aDoc
+        *            the document
+        * @param format
+        *            the format
+        * @return the created "Converts" relation
+        */
+       public ConvertsRelation attach(Document aDoc, String format) {
+               return attach(aDoc, format, null);
+       }
+
+       /**
+        * Create "Converts" relation for the given document, format and description.
+        * 
+        * @param aDoc
+        *            the document
+        * @param format
+        *            the format
+        * @param description
+        *            the description of the relation
+        * @return the created "Converts" relation
+        */
+       @Transactional
+       public ConvertsRelation attach(Document aDoc, String format,
+                       String description) {
+               String path = aDoc.getRelativePath();
+               File export = new File(path + "." + format);
+               ConvertsRelation attach = new ConvertsRelation(aDoc, export,
+                               description);
+
+               // RKV Session session = Database.getSession();
+               // RKV session.save(export);
+               // RKV session.save(attach);
+
+               getFileDAO().create(export);
+
+               // RKV aDoc.addRelation(attach); // Updates this
+               aDoc.getAllRelations().add(attach); // Updates this //RKV
+
+               return attach;
+       }
+
+       /**
+        * Build a reference (document id) for the given document in the given study basing on the given original document.
+        * 
+        * @param aDoc
+        *            the document to set set the new reference to
+        * @param scope
+        *            the study
+        * @param lineage
+        *            the original document
+        * @return true if the new reference is set
+        */
+       public boolean buildReferenceFrom(Document aDoc, ProjectElement scope,
+                       Document lineage) {
+               if (aDoc.getProgressState() != ProgressState.inWORK)
+                       return false;
+               Study owner = null;
+               Scenario context = null;
+               if (scope instanceof Study)
+                       owner = (Study) scope;
+               else {
+                       context = ((Scenario) scope);
+                       owner = context.getOwnerStudy();
+               }
+               aDoc.setDid(lineage.getDid());
+               if (context != null && (lineage.isVersioned() || owner.shares(lineage))) {
+                       aDoc.setVersion(new Revision(aDoc.getVersion()).setBranch(
+                                       context.getReference()).toString());
+               }
+               return true;
+       }
+
+       /**
+        * Build a reference (document id) for the given document in the given study.
+        * 
+        * @param aDoc
+        *            the document to set set the new reference to
+        * @param scope
+        *            the study
+        * @return true if the new reference is set
+        */
+       public boolean buildReferenceFrom(Document aDoc, Study scope) {
+               if (aDoc.getProgressState() != ProgressState.inWORK
+                               && aDoc.getProgressState() != ProgressState.EXTERN)
+                       return false;
+               DecimalFormat tostring = new DecimalFormat(Document.suformat);
+
+               aDoc.setDid(aDoc.getDid().replace("%" + Document.suformat,
+                               tostring.format(scope.getLastLocalIndex())));
+               return true;
+       }
+
+       /**
+        * Demote a document.
+        * 
+        * @param aDoc
+        *            the document to demote
+        * @return true if demoting succeeded
+        */
+       @Transactional
+       public boolean demote(Document aDoc) {
+               ValidationStep torem;
+
+               if (aDoc.getProgressState() == ProgressState.inCHECK) {
+                       aDoc.setProgressState(ProgressState.inDRAFT);
+                       torem = ValidationStep.REVIEW;
+                       // This operation must not change the version number of documents.
+                       // Consequently, inDRAFT documents may have a minor version number equal to zero.
+               } else if (aDoc.getProgressState() == ProgressState.inDRAFT) {
+                       aDoc.setProgressState(ProgressState.inWORK);
+                       torem = ValidationStep.PROMOTION;
+               } else {
+                       return false;
+               }
+               for (Iterator<Relation> i = aDoc.getAllRelations().iterator(); i
+                               .hasNext();) {
+                       Relation link = i.next();
+                       if (!(link instanceof StampRelation))
+                               continue;
+                       if (((StampRelation) link).getStampType() != torem)
+                               continue;
+                       i.remove();
+                       break;
+               }
+               getDocumentDAO().update(aDoc);
+               return true;
+       }
+
+       /**
+        * Promote a document.
+        * 
+        * @param aDoc
+        *            the document to promote
+        * @param stamp
+        *            the timestamp of the promotion
+        * @return true if promotion succeeded
+        */
+       @Transactional
+       public boolean promote(Document aDoc, Timestamp stamp) {
+               ProgressState newstate = null;
+
+               if (aDoc.getProgressState() == ProgressState.inWORK) {
+                       newstate = ProgressState.inDRAFT; // Promotion to being reviewed
+               } else if (aDoc.getProgressState() == ProgressState.inDRAFT) {
+                       newstate = ProgressState.inCHECK; // Promotion to approval
+                       Revision myvers = new Revision(aDoc.getVersion());
+                       if (myvers.isMinor()) {
+                               aDoc.setVersion(myvers.incrementAs(newstate).toString());
+                               // TODO: If my physical file is programatically editable, update its (property) version number
+                               // ISSUE: What about attached files such as PDF if exist, should we remove them ?
+                       }
+               } else if (aDoc.getProgressState() == ProgressState.inCHECK) {
+                       newstate = ProgressState.APPROVED;
+               }
+               aDoc.setProgressState(newstate);
+               if (stamp != null) {
+                       // RKV: aDoc.addRelation(stamp.getContext());
+                       aDoc.getAllRelations().add(stamp.getContext());
+               }
+               getDocumentDAO().update(aDoc);
+               return true;
+       }
+
+       /**
+        * Increments the reference count of this document following its publication in a Study step.
+        * 
+        * @param aDoc
+        *            the document to hold
+        * @see #release()
+        */
+       @Transactional
+       public void hold(Document aDoc) {
+               aDoc.setCountag(aDoc.getCountag() + 1);
+               if (aDoc.isSaved()) {
+                       getDocumentDAO().update(aDoc);
+               }
+       }
+
+       /**
+        * Decrements the reference count of this document following the removal of a Publication from a Study step.
+        * 
+        * @param aDoc
+        *            the document to release
+        * @see #hold()
+        */
+       @Transactional
+       public void release(Document aDoc) {
+               aDoc.setCountag(aDoc.getCountag() - 1);
+               if (aDoc.isSaved()) {
+                       getDocumentDAO().update(aDoc);
+               }
+       }
+
+       /**
+        * Rename a document.
+        * 
+        * @param aDoc
+        *            the document to rename
+        * @param title
+        *            the new document title
+        * @throws InvalidPropertyException
+        *             if the new title is empty
+        */
+       @Transactional
+       public void rename(Document aDoc, String title)
+                       throws InvalidPropertyException {
+               if (title.length() == 0)
+                       throw new InvalidPropertyException("name");
+
+               Calendar current = Calendar.getInstance();
+               aDoc.setTitle(title);
+               aDoc.setLastModificationDate(current.getTime()); // Today
+               getDocumentDAO().update(aDoc);
+       }
+
+       /**
+        * Update a version of the given document.
+        * 
+        * @param aDoc
+        *            the document
+        * @param newvers
+        *            the new version
+        */
+       public void updateAs(Document aDoc, Revision newvers) {
+               aDoc.setVersion(newvers.setBranch(aDoc.getVersion()).toString()); // Branch names are propagated by the versionning
+               ProgressState newstate = ProgressState.inCHECK;
+               if (newvers.isMinor())
+                       newstate = ProgressState.inWORK;
+               aDoc.setProgressState(null); // Just to tell updateAs(state) to not increment the version number
+               updateAs(aDoc, newstate);
+       }
+
+       /**
+        * Update a state of the given document.
+        * 
+        * @param aDoc
+        *            the document
+        * @param state
+        *            the new state
+        */
+       @Transactional
+       public void updateAs(Document aDoc, ProgressState state) {
+               Document previous = null;
+
+               // Set of version number
+               if (state == ProgressState.EXTERN) {
+                       if (aDoc.getProgressState() != ProgressState.EXTERN)
+                               aDoc.setVersion(null); // Strange use-case...
+               } else {
+                       Revision myvers = new Revision(aDoc.getVersion());
+                       if (!myvers.isNull()) { // Versionning context
+                               for (Iterator<Relation> i = aDoc.getAllRelations().iterator(); i
+                                               .hasNext();) {
+                                       Relation link = i.next();
+                                       if (!link.getClass().equals(VersionsRelation.class))
+                                               continue;
+                                       previous = (Document) link.getTo(); // Versioned document
+                                       break;
+                               }
+                       }
+                       if (aDoc.getProgressState() != null)
+                               myvers.incrementAs(state); // Incrementation if the reversion number is not imposed
+                       aDoc.setVersion(myvers.toString());
+               }
+               // Update this document and the previous version, if exit
+               if (previous != null) {
+                       previous.setHistory(previous.getHistory() + 1);
+                       getDocumentDAO().update(previous);
+               }
+               aDoc.setProgressState(state);
+               getDocumentDAO().update(aDoc);
+       }
+
+       // protected void upgrade () {
+       // -------------------------
+       // if (this.state != ProgressState.inWORK) return;
+       //
+       // Calendar current = Calendar.getInstance();
+       // for (Iterator<Relation> i=getAllRelations().iterator(); i.hasNext();) {
+       // Relation link = i.next();
+       // if (!link.getClass().equals(UsesRelation.class)) continue;
+       //
+       // Document used = (Document)link.getTo();
+       // if (!used.isVersioned()) continue;
+       // TODO: Update the uses relation
+       // }
+       // this.promote();
+       // this.lasdate = current.getTime(); // Today
+       // Database.getSession().update(this);
+       //
+       // TODO: Promote documents using this one
+       // }
+
+       /**
+        * Checks if documents of this type are result of a study. A document is the result of a study when it is the result of the last step of
+        * the study.
+        * 
+        * @param aType
+        *            the document type
+        * @return true if documents of this type are result of a study.
+        * @see #isStepResult()
+        * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+        */
+       public boolean isStudyResult(DocumentType aType) {
+               // -------------------------------
+               List<ProjectSettingsService.Step> step = getProjectSettings()
+                               .getAllSteps();
+               ProjectSettingsService.Step lastep = step.get(step.size() - 1);
+               return (aType.isResultOf(lastep));
+       }
+
        /**
         * Get the studyService.
         * 
@@ -277,4 +644,42 @@ public class DocumentServiceImpl implements DocumentService {
                _repositoryService = repositoryService;
        }
 
+       /**
+        * Get the documentTypeDAO.
+        * 
+        * @return the documentTypeDAO
+        */
+       public DocumentTypeDAO getDocumentTypeDAO() {
+               return _documentTypeDAO;
+       }
+
+       /**
+        * Set the documentTypeDAO.
+        * 
+        * @param documentTypeDAO
+        *            the documentTypeDAO to set
+        */
+       public void setDocumentTypeDAO(DocumentTypeDAO documentTypeDAO) {
+               _documentTypeDAO = documentTypeDAO;
+       }
+
+       /**
+        * Get the fileDAO.
+        * 
+        * @return the fileDAO
+        */
+       public FileDAO getFileDAO() {
+               return _fileDAO;
+       }
+
+       /**
+        * Set the fileDAO.
+        * 
+        * @param fileDAO
+        *            the fileDAO to set
+        */
+       public void setFileDAO(FileDAO fileDAO) {
+               _fileDAO = fileDAO;
+       }
+
 }
index 84d82cc2a255308ea4f107fd658e528153230ccf..3875736ea141de8c1a9b0d5855e7e8f7b5be0339 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -7,23 +7,78 @@
  * @version        $Revision$
  *****************************************************************************/
 
-package org.splat.service; 
+package org.splat.service;
+
+import java.util.List;
 
 import org.splat.dal.bo.som.DocumentType;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
+import org.splat.service.technical.ProjectSettingsService;
 
 /**
- * @author RKV
+ * Document type service interface.
  *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
 public interface DocumentTypeService {
 
        /**
-        * Checks if documents of this type are result of a study.
-        * A document is the result of a study when it is the result of the last step of the study.
+        * Get all document types from the database.
+        * 
+        * @return the list of all document types
+        */
+       public List<DocumentType> selectAllTypes();
+
+       /**
+        * Find all result document types.
+        * 
+        * @return the list of found types
+        */
+       public List<DocumentType> selectResultTypes();
+
+       /**
+        * Get document type by the given type name.
+        * 
+        * @param name
+        *            the type name
+        * @return the found document type
+        */
+       public DocumentType selectType(String name);
+
+       /**
+        * Get document type by the given id.
+        * 
+        * @param index
+        *            the id
+        * @return the found document type
+        */
+       public DocumentType selectType(long index);
+
+       /**
+        * Create a new document type.
+        * 
+        * @param tprop
+        *            properties of the new document type
+        * @return the created document type
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property doesn't exist
+        * @throws MultiplyDefinedException
+        *             if some property is defined several times
+        */
+       public DocumentType createType(DocumentType.Properties tprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException;
+
+       /**
+        * Get document types applicable for the given study step.
         * 
-        * @return true if documents of this type are result of a study.
-        * @see    #isStepResult()
-        * @see    #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+        * @param step
+        *            the step (study activity)
+        * @return the list of found document types
         */
-           public boolean isStudyResult (DocumentType aType);
+       public List<DocumentType> selectTypesOf(ProjectSettingsService.Step step);
 }
index c88ec88d9a22a923dd06e3821e26c8ed0df9b46b..63fecb5b6236687d0585a6eabae003b7b2fa6dc0 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
  * @version        $Revision$
  *****************************************************************************/
 
-package org.splat.service; 
+package org.splat.service;
 
+import java.util.Iterator;
 import java.util.List;
 
+import org.hibernate.Hibernate;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
 import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.dao.som.DocumentTypeDAO;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
 import org.splat.service.technical.ProjectSettingsService;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
- * @author RKV
+ * Document type service implementation.
  *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
 public class DocumentTypeServiceImpl implements DocumentTypeService {
 
-       private ProjectSettingsService _projectSettingsService;
+       /**
+        * Injected document type DAO.
+        */
+       private DocumentTypeDAO _documentTypeDAO;
+
+       /**
+        * Get all document types from the database.
+        * 
+        * @return the list of all document types
+        */
+       @Transactional(readOnly = true)
+       public List<DocumentType> selectAllTypes() {
+               List<DocumentType> types = getDocumentTypeDAO().getAll();
+               for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
+                       Hibernate.initialize(i.next()); // Supposed fetching document types
+               }
+               return types;
+       }
 
        /**
-        * Checks if documents of this type are result of a study.
-        * A document is the result of a study when it is the result of the last step of the study.
+        * Find all result document types.
         * 
-        * @return true if documents of this type are result of a study.
-        * @see    #isStepResult()
-        * @see    #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+        * @return the list of found types
         */
-           public boolean isStudyResult (DocumentType aType) {
-       //  -------------------------------
-             List<ProjectSettingsService.Step> step   = getProjectSettings().getAllSteps();
-             ProjectSettingsService.Step       lastep = step.get( step.size()-1 );
-             return    (aType.isResultOf(lastep));
-           }
+       @Transactional(readOnly = true)
+       public List<DocumentType> selectResultTypes() {
+               return getDocumentTypeDAO().getFilteredList(
+                               Restrictions.isNotNull("result"), Order.asc("result"));
+       }
 
        /**
-        * @return
+        * Get document type by the given type name.
+        * 
+        * @param name
+        *            the type name
+        * @return the found document type
         */
-       public ProjectSettingsService getProjectSettings() {
-               return _projectSettingsService;
+       @Transactional(readOnly = true)
+       public DocumentType selectType(String name) {
+               return getDocumentTypeDAO().findByCriteria(
+                               Restrictions.eq("name", name));
        }
 
-       public void setProjectSettings(
-                       ProjectSettingsService projectSettingsService) {
-               _projectSettingsService = projectSettingsService;
+       /**
+        * Get document type by the given id.
+        * 
+        * @param index
+        *            the id
+        * @return the found document type
+        */
+       @Transactional(readOnly = true)
+       public DocumentType selectType(long index) {
+               return getDocumentTypeDAO().get(index);
        }
 
+       /**
+        * Create a new document type.
+        * 
+        * @param tprop
+        *            properties of the new document type
+        * @return the created document type
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property doesn't exist
+        * @throws MultiplyDefinedException
+        *             if some property is defined several times
+        */
+       @Transactional
+       public DocumentType createType(DocumentType.Properties tprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException {
+               // TODO: Check for duplicate definition
+               DocumentType type = new DocumentType(tprop);
+               getDocumentTypeDAO().create(type);
+               return type;
+       }
+
+       /**
+        * Get document types applicable for the given study step.
+        * 
+        * @param step
+        *            the step (study activity)
+        * @return the list of found document types
+        */
+       @Transactional(readOnly = true)
+       public List<DocumentType> selectTypesOf(ProjectSettingsService.Step step) {
+               Integer number = step.getNumber();
+               String sampleStr = new StringBuffer("%-").append(number).append("-%")
+                               .toString();
+               List<DocumentType> types = getDocumentTypeDAO().getFilteredList(
+                               Restrictions.like("step", sampleStr));
+               for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
+                       Hibernate.initialize(i.next()); // For fetching document types
+               }
+               return types;
+       }
+
+       /**
+        * Get the documentTypeDAO.
+        * 
+        * @return the documentTypeDAO
+        */
+       public DocumentTypeDAO getDocumentTypeDAO() {
+               return _documentTypeDAO;
+       }
+
+       /**
+        * Set the documentTypeDAO.
+        * 
+        * @param documentTypeDAO
+        *            the documentTypeDAO to set
+        */
+       public void setDocumentTypeDAO(DocumentTypeDAO documentTypeDAO) {
+               _documentTypeDAO = documentTypeDAO;
+       }
 }
index 62cec624baa806f0114df6f76ef47754cca96664..2ccef0cec1b943b9d5ada308c5df537eac52bc96 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -9,23 +9,76 @@
 
 package org.splat.service;
 
+import java.util.List;
+
 import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.ProgressState;
 import org.splat.kernel.InvalidPropertyException;
 
 /**
- * @author RKV
+ * Knowledge element service interface.
  * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
 public interface KnowledgeElementService {
 
+       /**
+        * Approve the knowledge element.
+        * 
+        * @param knowledgeElement
+        *            the knowledge element to approve
+        * @return true if approving succeeded
+        */
        public boolean approve(KnowledgeElement knowledgeElement);
 
+       /**
+        * Demote the knowledge element.
+        * 
+        * @param knowledgeElement
+        *            the knowledge element to demote
+        * @return true if demoting succeeded
+        */
        public boolean demote(KnowledgeElement knowledgeElement);
 
+       /**
+        * Promote the knowledge element.
+        * 
+        * @param knowledgeElement
+        *            the knowledge element to promote
+        * @return true if promotion succeeded
+        */
        public boolean promote(KnowledgeElement knowledgeElement);
 
+       /**
+        * Rename the knowledge element.
+        * 
+        * @param knowledgeElement
+        *            the knowledge element to rename
+        * @param title
+        *            the new title of the knowledge element
+        * @throws InvalidPropertyException
+        *             if renaming is failed
+        */
        public void rename(KnowledgeElement knowledgeElement, String title)
                        throws InvalidPropertyException;
 
+       /**
+        * Get a knowledge element by its id.
+        * 
+        * @param index
+        *            the knowledge element id
+        * @return the found knowledge element
+        */
        public KnowledgeElement selectKnowledgeElement(long index);
+
+       /**
+        * Update the description of the knowledge element.
+        * 
+        * @param kelm
+        *            the knoledge element to update
+        * @param description
+        *            the new description
+        */
+       public void update(KnowledgeElement kelm, String description);
 }
index 485ce628f36009d202a5a3c9cfed94933025046e..c6c23dd38161a4aa88609ad418ef6340e013dffb 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -7,35 +7,60 @@
  * @version        $Revision$
  *****************************************************************************/
 
-package org.splat.service; 
+package org.splat.service;
 
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.ProgressState;
-import org.splat.dal.dao.kernel.GenericDAO;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.dao.som.KnowledgeElementDAO;
 import org.splat.kernel.InvalidPropertyException;
+import org.splat.log.AppLogger;
 import org.splat.service.technical.IndexService;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
- * @author RKV
- *
+ * Knowledge element service implementation.
+ * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
 public class KnowledgeElementServiceImpl implements KnowledgeElementService {
 
+       /**
+        * The logger for the service.
+        */
+       public final static AppLogger logger = AppLogger
+                       .getLogger(KnowledgeElementServiceImpl.class);
+
+       /**
+        * Injected index service.
+        */
        private IndexService _indexService;
+       /**
+        * Injected knowledge element DAO.
+        */
        private KnowledgeElementDAO _knowledgeElementDAO;
+       /**
+        * Injected study service.
+        */
+       private StudyService _studyService;
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.KnowledgeElementService#approve(org.splat.dal.bo.som.KnowledgeElement)
+        */
        public boolean approve(KnowledgeElement knowledgeElement) {
-               // -------------------------
                if (knowledgeElement.getProgressState() != ProgressState.inCHECK)
                        return false;
                knowledgeElement.setProgressState(ProgressState.APPROVED);
                return update(knowledgeElement);
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.KnowledgeElementService#demote(org.splat.dal.bo.som.KnowledgeElement)
+        */
        public boolean demote(KnowledgeElement knowledgeElement) {
-               // ------------------------
                if (knowledgeElement.getProgressState() != ProgressState.APPROVED
                                && knowledgeElement.getProgressState() != ProgressState.inCHECK)
                        return false;
@@ -43,61 +68,137 @@ public class KnowledgeElementServiceImpl implements KnowledgeElementService {
                return update(knowledgeElement);
        }
 
+       /**
+        * Update knowledge element in the database and in the lucene index.
+        * @param knowledgeElement the knowledge element to update
+        * @return true if updating succeeded
+        */
        protected boolean update(KnowledgeElement knowledgeElement) {
-               // -----------------------------
                try {
                        getKnowledgeElementDAO().update(knowledgeElement);
                        getIndexService().update(knowledgeElement);
                        return true;
                } catch (Exception error) {
-                       // logger.error("Unable to re-index the knowledge '" + getIndex() + "', reason:", error);
+                       logger.error("Unable to re-index the knowledge '"
+                                       + knowledgeElement.getIndex() + "', reason:", error);
                        return false;
                }
        }
 
-       public boolean promote (KnowledgeElement knowledgeElement) {
-//  -------------------------
-      if  (knowledgeElement.getProgressState() != ProgressState.inDRAFT) return false;      
-      knowledgeElement.setProgressState(ProgressState.inCHECK);
-      return  update(knowledgeElement);
-    }
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.KnowledgeElementService#promote(org.splat.dal.bo.som.KnowledgeElement)
+        */
+       public boolean promote(KnowledgeElement knowledgeElement) {
+               // -------------------------
+               if (knowledgeElement.getProgressState() != ProgressState.inDRAFT)
+                       return false;
+               knowledgeElement.setProgressState(ProgressState.inCHECK);
+               return update(knowledgeElement);
+       }
 
-    public void rename (KnowledgeElement knowledgeElement, String title) throws InvalidPropertyException {
-      if (title.length() == 0) throw new InvalidPropertyException("name");
-      knowledgeElement.setTitle(title);
-      update(knowledgeElement);
-    }
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.KnowledgeElementService#rename(org.splat.dal.bo.som.KnowledgeElement, java.lang.String)
+        */
+       public void rename(KnowledgeElement knowledgeElement, String title)
+                       throws InvalidPropertyException {
+               if (title.length() == 0)
+                       throw new InvalidPropertyException("name");
+               knowledgeElement.setTitle(title);
+               update(knowledgeElement);
+       }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.KnowledgeElementService#selectKnowledgeElement(long)
+        */
        public KnowledgeElement selectKnowledgeElement(long index) {
-               // -----------------------------------------------------------------
-               StringBuffer query = new StringBuffer(
-                               "from KnowledgeElement where rid='").append(index).append("'");
-               KnowledgeElement result = (KnowledgeElement) Database.getSession()
-                               .createQuery(query.toString()).uniqueResult();
-
-               result.getOwnerScenario().getOwnerStudy().loadWorkflow();
+               KnowledgeElement result = getKnowledgeElementDAO().get(index);
+               getStudyService().loadWorkflow(result.getOwnerScenario().getOwnerStudy());
                return result;
        }
 
        /**
-        * @return
+        * Update the description of the knowledge element.
+        * 
+        * @param kelm
+        *            the knoledge element to update
+        * @param description
+        *            the new description
+        */
+       @Transactional
+       public void update(KnowledgeElement kelm, String description) {
+               kelm.setValue(description.trim());
+               if (!kelm.getValue().startsWith("<p>")) {
+                       StringBuffer text = new StringBuffer("<p>");
+                       int index = kelm.getValue().indexOf("<p>");
+                       if (index > 0) {
+                               kelm.setValue(text.append(kelm.getValue().substring(0, index))
+                                               .append("</p>")
+                                               .append(kelm.getValue().substring(index)).toString());
+                       } else {
+                               kelm.setValue(text.append(kelm.getValue()).append("</p>")
+                                               .toString());
+                       }
+               }
+               getKnowledgeElementDAO().update(kelm); // No need to update the Lucene index
+       }
+
+       /**
+        * 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;
        }
 
        /**
-        * @return
+        * Get the knowledgeElementDAO.
+        * 
+        * @return the knowledgeElementDAO
         */
        public KnowledgeElementDAO getKnowledgeElementDAO() {
                return _knowledgeElementDAO;
        }
-       
-    public void setKnowledgeElementDAO(KnowledgeElementDAO knowledgeElementDAO) {
+
+       /**
+        * Set the knowledgeElementDAO.
+        * 
+        * @param knowledgeElementDAO
+        *            the knowledgeElementDAO to set
+        */
+       public void setKnowledgeElementDAO(KnowledgeElementDAO knowledgeElementDAO) {
                _knowledgeElementDAO = knowledgeElementDAO;
        }
+
+       /**
+        * 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;
+       }
 }
diff --git a/Workspace/Siman-Common/src/org/splat/service/KnowledgeElementTypeService.java b/Workspace/Siman-Common/src/org/splat/service/KnowledgeElementTypeService.java
new file mode 100644 (file)
index 0000000..e17cb97
--- /dev/null
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   19.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ * @copyright      OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service;
+
+import java.util.List;
+
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.ProgressState;
+
+/**
+ * The service interface for working with knowledge element types.
+ * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public interface KnowledgeElementTypeService {
+
+       /**
+        * Find a knowledge type by its name.
+        * 
+        * @param name
+        *            the knowledge type name
+        * @return the found knowledge type
+        */
+       public KnowledgeElementType selectType(String name);
+
+       /**
+        * Create a knowledge element type with the given name.
+        * 
+        * @param name
+        *            the new type name
+        * @return the created knowledge type
+        */
+       public KnowledgeElementType createType(String name);
+
+       /**
+        * Get all knowledge types from the database.
+        * 
+        * @return the list of all knowledge types
+        */
+       public List<KnowledgeElementType> selectAllTypes();
+
+       /**
+        * Get knowledge types which have the given progress state.
+        * 
+        * @param state
+        *            the progress state
+        * @return the list of found knowledge types
+        */
+       public List<KnowledgeElementType> selectTypesWhere(ProgressState state);
+
+       /**
+        * Get a knowledge type by its id.
+        * 
+        * @param index
+        *            the id of a knowledge type
+        * @return the found knowledge type
+        */
+       public KnowledgeElementType selectType(long index);
+}
diff --git a/Workspace/Siman-Common/src/org/splat/service/KnowledgeElementTypeServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/KnowledgeElementTypeServiceImpl.java
new file mode 100644 (file)
index 0000000..a5dd084
--- /dev/null
@@ -0,0 +1,112 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   19.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ * @copyright      OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service; 
+
+import java.util.List;
+
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
+
+/**
+ * KnowledgeElementTypeService implementation for working with knowledge types.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class KnowledgeElementTypeServiceImpl implements
+               KnowledgeElementTypeService {
+
+       /**
+        * Injected knowledge element type DAO.
+        */
+       private KnowledgeElementTypeDAO _knowledgeElementTypeDAO;
+
+       /**
+        * Create a knowledge element type with the given name.
+        * 
+        * @param name
+        *            the new type name
+        * @return the created knowledge type
+        */
+       public KnowledgeElementType createType(String name) {
+               // TODO: Check for duplicate definition
+               KnowledgeElementType kelt = new KnowledgeElementType(name);
+               getKnowledgeElementTypeDAO().create(kelt);
+               return kelt;
+       }
+
+       /**
+        * Get all knowledge types from the database.
+        * 
+        * @return the list of all knowledge types
+        */
+       public List<KnowledgeElementType> selectAllTypes() {
+               return getKnowledgeElementTypeDAO().getAll(Order.asc("rid"));
+       }
+
+       /**
+        * Get knowledge types which have the given progress state.
+        * 
+        * @param state
+        *            the progress state
+        * @return the list of found knowledge types
+        */
+       public List<KnowledgeElementType> selectTypesWhere(ProgressState state) {
+               return getKnowledgeElementTypeDAO().getFilteredList(
+                               Restrictions.eq("state", state), Order.asc("rid"));
+       }
+
+       /**
+        * Find a knowledge type by its name.
+        * 
+        * @param name
+        *            the knowledge type name
+        * @return the found knowledge type
+        */
+       public KnowledgeElementType selectType(String name) {
+               return getKnowledgeElementTypeDAO().findByCriteria(
+                               Restrictions.eq("name", name));
+       }
+
+       /**
+        * Get a knowledge type by its id.
+        * 
+        * @param index
+        *            the id of a knowledge type
+        * @return the found knowledge type
+        */
+       public KnowledgeElementType selectType(long index) {
+               return getKnowledgeElementTypeDAO().get(index);
+       }
+
+       /**
+        * Get the knowledgeElementTypeDAO.
+        * 
+        * @return the knowledgeElementTypeDAO
+        */
+       public KnowledgeElementTypeDAO getKnowledgeElementTypeDAO() {
+               return _knowledgeElementTypeDAO;
+       }
+
+       /**
+        * Set the knowledgeElementTypeDAO.
+        * 
+        * @param knowledgeElementTypeDAO
+        *            the knowledgeElementTypeDAO to set
+        */
+       public void setKnowledgeElementTypeDAO(
+                       KnowledgeElementTypeDAO knowledgeElementTypeDAO) {
+               _knowledgeElementTypeDAO = knowledgeElementTypeDAO;
+       }
+
+}
index dc5f695cd643f14339db7d016b66756dc3f1ca00..6edf1f7ed5c1c6f6a9ba76138709403dc8bf6f2c 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            Id: 
  * Creation date   02.10.2012
index f4561a4fd213f57eef302583338e39a091b2f33d..9df0f087f961d2df9278b3436196b07e1f80033d 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   02.10.2012
index 7f9564d1fd2fd0e303500e92abe8c26b39d82ced..186a04847f6e5a73ecc6892bbd600a25d83d92bd 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   07.10.2012
index a8a5080d6b7c24767ca825cf089f8e88204f5c7a..84fc9df07753b7b7734a2f350cb868401403ccdb 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   07.10.2012
index a2eb497db5698c532ba1f01f097190aeb071ec9f..39d8b8eebd74aa227e5737ae7bd4d05f1c87f158 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -12,12 +12,14 @@ package org.splat.service;
 import java.io.FileNotFoundException;
 import java.util.Date;
 
+import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.Timestamp;
+import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.NotApplicableException;
 import org.splat.som.DocumentRights;
 import org.splat.som.Revision;
@@ -172,4 +174,42 @@ public interface PublicationService {
         */
        public void saveAs(Publication aPublication, Revision newvers)
                        throws FileNotFoundException, NotApplicableException;
+
+       /**
+        * Rename the published document.
+        * 
+        * @param aPublication
+        *            the publication of the document
+        * @param title
+        *            the new document title
+        * @throws InvalidPropertyException
+        *             if the new title is empty
+        */
+       public void rename(Publication aPublication, String title)
+                       throws InvalidPropertyException;
+
+       /**
+        * Create "Converts" relation for the given document publication and format.
+        * 
+        * @param aPublication
+        *            the document publication
+        * @param format
+        *            the format
+        * @return the created "Converts" relation
+        */
+       public ConvertsRelation attach(Publication aPublication, String format);
+
+       /**
+        * Create "Converts" relation for the given document publication, format and description.
+        * 
+        * @param aPublication
+        *            the document publication
+        * @param format
+        *            the format
+        * @param description
+        *            the description of the relation
+        * @return the created "Converts" relation
+        */
+       public ConvertsRelation attach(Publication aPublication, String format,
+                       String description);
 }
index e2e530214d12c71196bf1c657701e1edeff93e41..1516ba4305010b555607115c84c8c5c4006cf76c 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -15,8 +15,8 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 
-import org.hibernate.Session;
 import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.ProgressState;
@@ -28,12 +28,15 @@ import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.Timestamp;
 import org.splat.dal.bo.som.ValidationCycle;
 import org.splat.dal.bo.som.ValidationStep;
-import org.splat.dal.dao.som.Database;
+import org.splat.dal.dao.som.ProjectElementDAO;
+import org.splat.dal.dao.som.PublicationDAO;
+import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.NotApplicableException;
 import org.splat.manox.Reader;
 import org.splat.manox.Toolbox;
 import org.splat.som.Revision;
 import org.splat.som.Step;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * Publication service implementation.
@@ -47,21 +50,29 @@ public class PublicationServiceImpl implements PublicationService {
         */
        private StudyService _studyService;
        /**
-        * Injected study service.
+        * Injected step service.
         */
        private StepService _stepService;
        /**
-        * Injected study service.
+        * Injected document service.
         */
-       private DocumentTypeService _documentTypeService;
+       private DocumentService _documentService;
        /**
-        * Injected study service.
+        * Injected project element service.
         */
        private ProjectElementService _projectElementService;
        /**
         * Injected simulation context service.
         */
        private SimulationContextService _simulationContextService;
+       /**
+        * Injected publication DAO.
+        */
+       private PublicationDAO _publicationDAO;
+       /**
+        * Injected project element DAO.
+        */
+       private ProjectElementDAO _projectElementDAO;
 
        /**
         * {@inheritDoc}
@@ -86,7 +97,6 @@ public class PublicationServiceImpl implements PublicationService {
         * @see org.splat.service.PublicationService#approve(org.splat.dal.bo.som.Publication, java.util.Date)
         */
        public Timestamp approve(Publication aPublication, Date adate) {
-               // -------------------------------------
                if (aPublication.isOutdated())
                        return null;
                else if (aPublication.value().getProgressState() != ProgressState.inCHECK)
@@ -94,13 +104,14 @@ public class PublicationServiceImpl implements PublicationService {
 
                DocumentType type = aPublication.value().getType();
                Study owner = aPublication.getOwnerStudy();
-               ValidationCycle cycle = owner.getValidationCycleOf(type);
+               ValidationCycle cycle = getStudyService().getValidationCycleOf(owner,
+                               type);
                User approver = cycle.getActor(ValidationStep.APPROVAL);
                Timestamp stamp = new Timestamp(ValidationStep.APPROVAL, aPublication
                                .value(), approver, adate);
-               if (!aPublication.value().promote(stamp))
+               if (!getDocumentService().promote(aPublication.value(), stamp))
                        return null;
-               if (getDocumentTypeService().isStudyResult(type)
+               if (getDocumentService().isStudyResult(type)
                                && owner.getProgressState() == ProgressState.inCHECK)
                        getStudyService().promote(owner);
                return stamp; // Hoping that promotion of the study succeeded
@@ -112,27 +123,27 @@ public class PublicationServiceImpl implements PublicationService {
         * @see org.splat.service.PublicationService#demote(org.splat.dal.bo.som.Publication)
         */
        public boolean demote(Publication aPublication) {
-               // ------------------------
                DocumentType type = aPublication.value().getType();
                Study owner = aPublication.getOwnerStudy();
 
                if (aPublication.value().getProgressState() == ProgressState.inCHECK) {
-                       ValidationCycle cycle = owner.getValidationCycleOf(type);
+                       ValidationCycle cycle = getStudyService().getValidationCycleOf(
+                                       owner, type);
                        if (cycle.enables(ValidationStep.REVIEW)) {
-                               if (!aPublication.value().demote())
+                               if (!getDocumentService().demote(aPublication.value()))
                                        return false;
                        } else {
-                               if (!aPublication.value().demote())
+                               if (!getDocumentService().demote(aPublication.value()))
                                        return false;
-                               aPublication.value().demote();
+                               getDocumentService().demote(aPublication.value());
                        }
                } else if (aPublication.value().getProgressState() == ProgressState.inDRAFT) {
-                       if (!aPublication.value().demote())
+                       if (!getDocumentService().demote(aPublication.value()))
                                return false;
                } else {
                        return false;
                }
-               if (getDocumentTypeService().isStudyResult(type)
+               if (getDocumentService().isStudyResult(type)
                                && owner.getProgressState() != ProgressState.inWORK)
                        getStudyService().demote(owner);
                return true;
@@ -144,14 +155,13 @@ public class PublicationServiceImpl implements PublicationService {
         * @see org.splat.service.PublicationService#invalidate(org.splat.dal.bo.som.Publication)
         */
        public boolean invalidate(Publication aPublication) {
-               // ----------------------------
                if (aPublication.value().getProgressState() != ProgressState.inCHECK)
                        return false;
-               if (!aPublication.value().demote()) // Removes the reviewer if this document is In-Check
+               if (!getDocumentService().demote(aPublication.value())) // Removes the reviewer if this document is In-Check
                        return false;
                DocumentType type = aPublication.value().getType();
                Study owner = aPublication.getOwnerStudy();
-               if (getDocumentTypeService().isStudyResult(type)
+               if (getDocumentService().isStudyResult(type)
                                && owner.getProgressState() == ProgressState.inCHECK)
                        getStudyService().demote(owner);
                return true;
@@ -170,7 +180,8 @@ public class PublicationServiceImpl implements PublicationService {
                else {
                        DocumentType type = aPublication.value().getType();
                        Study owner = aPublication.getOwnerStudy();
-                       ValidationCycle cycle = owner.getValidationCycleOf(type);
+                       ValidationCycle cycle = getStudyService().getValidationCycleOf(
+                                       owner, type);
                        User promoter = cycle.getActor(ValidationStep.PROMOTION);
                        if (promoter == null)
                                promoter = getInvolvedStep(aPublication).getActor();
@@ -179,12 +190,12 @@ public class PublicationServiceImpl implements PublicationService {
                        Timestamp stamp = new Timestamp(ValidationStep.PROMOTION,
                                        aPublication.value(), promoter, pdate);
 
-                       if (!aPublication.value().promote(stamp)) // Promotion to being reviewed
+                       if (!getDocumentService().promote(aPublication.value(), stamp)) // Promotion to being reviewed
                                return null;
                        if (!cycle.enables(ValidationStep.REVIEW)) {
-                               aPublication.value().promote(null);
+                               getDocumentService().promote(aPublication.value(), null);
                        }
-                       if (getDocumentTypeService().isStudyResult(type)
+                       if (getDocumentService().isStudyResult(type)
                                        && owner.getProgressState() == ProgressState.inWORK)
                                getStudyService().promote(owner);
                        return stamp; // Hoping that promotion of the study succeeded
@@ -204,13 +215,14 @@ public class PublicationServiceImpl implements PublicationService {
 
                DocumentType type = aPublication.value().getType();
                Study owner = aPublication.getOwnerStudy();
-               ValidationCycle cycle = owner.getValidationCycleOf(type);
+               ValidationCycle cycle = getStudyService().getValidationCycleOf(owner,
+                               type);
                User reviewer = cycle.getActor(ValidationStep.REVIEW);
                Timestamp stamp = new Timestamp(ValidationStep.REVIEW, aPublication
                                .value(), reviewer, rdate);
-               if (!aPublication.value().promote(stamp))
+               if (!getDocumentService().promote(aPublication.value(), stamp))
                        return null;
-               if (getDocumentTypeService().isStudyResult(type)
+               if (getDocumentService().isStudyResult(type)
                                && owner.getProgressState() == ProgressState.inDRAFT)
                        getStudyService().promote(owner);
                return stamp; // Hoping that promotion of the study succeeded
@@ -222,17 +234,17 @@ public class PublicationServiceImpl implements PublicationService {
         * @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.som.Revision)
         * @deprecated
         */
+       @Transactional
        public void saveAs(Publication aPublication, Revision newvers)
                        throws FileNotFoundException, NotApplicableException {
-               // -------------------------------------
                if (aPublication.value().isUndefined())
                        throw new NotApplicableException(
                                        "Cannot save a Publication object refering an undefined Document");
                if (!aPublication.value().getSourceFile().exists())
                        throw new FileNotFoundException();
 
-               Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
-               aPublication.value().updateAs(newvers); // May change the branch name of given revision
+               getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
+               getDocumentService().updateAs(aPublication.value(), newvers); // May change the branch name of given revision
                updateOwner(aPublication);
        }
 
@@ -241,9 +253,9 @@ public class PublicationServiceImpl implements PublicationService {
         * 
         * @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProgressState)
         */
+       @Transactional
        public void saveAs(Publication aPublication, ProgressState state)
                        throws FileNotFoundException, NotApplicableException {
-               // ----------------------------------------
                if (aPublication.value().isUndefined())
                        throw new NotApplicableException(
                                        "Cannot save a Publication object refering an undefined Document");
@@ -251,13 +263,14 @@ public class PublicationServiceImpl implements PublicationService {
                        throw new FileNotFoundException();
 
                if (state == ProgressState.inWORK || state == ProgressState.EXTERN) {
-                       Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
+                       getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
                        // hascode
-                       aPublication.value().updateAs(state);
+                       getDocumentService().updateAs(aPublication.value(), state);
                } else {
                        DocumentType mytype = aPublication.value().getType();
                        Study owner = aPublication.getOwnerStudy();
-                       ValidationCycle cycle = owner.getValidationCycleOf(mytype);
+                       ValidationCycle cycle = getStudyService().getValidationCycleOf(
+                                       owner, mytype);
                        boolean review = cycle.enables(ValidationStep.REVIEW);
                        if (!(state == ProgressState.inDRAFT && review)
                                        && !(state == ProgressState.inCHECK && !review)) {
@@ -265,9 +278,10 @@ public class PublicationServiceImpl implements PublicationService {
                                                "Cannot save a result document in " + state.toString()
                                                                + " state");
                        }
-                       Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
+                       getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
                        // hascode
-                       aPublication.value().updateAs(ProgressState.inWORK);
+                       getDocumentService().updateAs(aPublication.value(),
+                                       ProgressState.inWORK);
 
                        promote(aPublication, aPublication.value()
                                        .getLastModificationDate()); // Promotes to the appropriate state in accordance to the validation cycle
@@ -281,24 +295,24 @@ public class PublicationServiceImpl implements PublicationService {
         * @param aPublication
         *            the document publication
         */
+       @Transactional
        private void updateOwner(Publication aPublication) {
-               Session session = Database.getSession();
                Step step = getInvolvedStep(aPublication);
 
                // Update of involved step
                Document previous = aPublication.value().getPreviousVersion();
                if (previous != null) {
                        Publication oldoc = step.getDocument(previous.getIndex());
-                       boolean done = step.remove(oldoc); // Decrements the configuration tag count of document
+                       boolean done = getStepService().remove(step, oldoc); // Decrements the configuration tag count of document
                        if (done)
-                               session.delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object
+                               getPublicationDAO().delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object
                }
-               step.add(aPublication); // Increments the configuration tag count of document
+               getStepService().add(step, aPublication); // Increments the configuration tag count of document
 
                // Import the document properties and update of the study
                forwardProperties(aPublication, aPublication.value().getSourceFile()
                                .asFile(), step);
-               session.update(aPublication.getOwner());
+               getProjectElementDAO().update(aPublication.getOwner());
        }
 
        /**
@@ -313,7 +327,6 @@ public class PublicationServiceImpl implements PublicationService {
         */
        private void forwardProperties(Publication aPublication, java.io.File from,
                        Step to) {
-               // -----------------------------------------------------------
                Reader tool = Toolbox.getReader(from);
                if (tool == null)
                        return; // No properties extractor available for this type of document
@@ -380,6 +393,51 @@ public class PublicationServiceImpl implements PublicationService {
                return aPublication.getStep();
        }
 
+       /**
+        * Create "Converts" relation for the given document publication and format.
+        * 
+        * @param aPublication
+        *            the document publication
+        * @param format
+        *            the format
+        * @return the created "Converts" relation
+        */
+       public ConvertsRelation attach(Publication aPublication, String format) {
+               return getDocumentService().attach(aPublication.value(), format);
+       }
+
+       /**
+        * Create "Converts" relation for the given document publication, format and description.
+        * 
+        * @param aPublication
+        *            the document publication
+        * @param format
+        *            the format
+        * @param description
+        *            the description of the relation
+        * @return the created "Converts" relation
+        */
+       public ConvertsRelation attach(Publication aPublication, String format,
+                       String description) {
+               return getDocumentService().attach(aPublication.value(), format,
+                               description);
+       }
+
+       /**
+        * Rename the published document.
+        * 
+        * @param aPublication
+        *            the publication of the document
+        * @param title
+        *            the new document title
+        * @throws InvalidPropertyException
+        *             if the new title is empty
+        */
+       public void rename(Publication aPublication, String title)
+                       throws InvalidPropertyException {
+               getDocumentService().rename(aPublication.value(), title);
+       }
+
        /**
         * Get the projectElementService.
         * 
@@ -422,6 +480,7 @@ public class PublicationServiceImpl implements PublicationService {
 
        /**
         * Get the studyService.
+        * 
         * @return the studyService
         */
        public StudyService getStudyService() {
@@ -430,7 +489,9 @@ public class PublicationServiceImpl implements PublicationService {
 
        /**
         * Set the studyService.
-        * @param studyService the studyService to set
+        * 
+        * @param studyService
+        *            the studyService to set
         */
        public void setStudyService(StudyService studyService) {
                _studyService = studyService;
@@ -438,6 +499,7 @@ public class PublicationServiceImpl implements PublicationService {
 
        /**
         * Get the stepService.
+        * 
         * @return the stepService
         */
        public StepService getStepService() {
@@ -446,25 +508,68 @@ public class PublicationServiceImpl implements PublicationService {
 
        /**
         * Set the stepService.
-        * @param stepService the stepService to set
+        * 
+        * @param stepService
+        *            the stepService to set
         */
        public void setStepService(StepService stepService) {
                _stepService = stepService;
        }
 
        /**
-        * Get the documentTypeService.
-        * @return the documentTypeService
+        * 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;
+       }
+
+       /**
+        * Get the publicationDAO.
+        * 
+        * @return the publicationDAO
+        */
+       public PublicationDAO getPublicationDAO() {
+               return _publicationDAO;
+       }
+
+       /**
+        * Set the publicationDAO.
+        * 
+        * @param publicationDAO
+        *            the publicationDAO to set
         */
-       public DocumentTypeService getDocumentTypeService() {
-               return _documentTypeService;
+       public void setPublicationDAO(PublicationDAO publicationDAO) {
+               _publicationDAO = publicationDAO;
        }
 
        /**
-        * Set the documentTypeService.
-        * @param documentTypeService the documentTypeService to set
+        * Get the projectElementDAO.
+        * 
+        * @return the projectElementDAO
+        */
+       public ProjectElementDAO getProjectElementDAO() {
+               return _projectElementDAO;
+       }
+
+       /**
+        * Set the projectElementDAO.
+        * 
+        * @param projectElementDAO
+        *            the projectElementDAO to set
         */
-       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
-               _documentTypeService = documentTypeService;
+       public void setProjectElementDAO(ProjectElementDAO projectElementDAO) {
+               _projectElementDAO = projectElementDAO;
        }
 }
index df872e765594a8e18aea37f1d18fe2aec81701a2..8c55cfbfcb0eecba95963dc7af2674c22eed69da 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -12,6 +12,7 @@ package org.splat.service;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
@@ -24,6 +25,25 @@ import org.splat.som.Step;
  */
 public interface ScenarioService {
 
+       /**
+        * Add a new scenario to the study.
+        * 
+        * @param aStudy
+        *            the study
+        * @param sprop
+        *            scenario properties
+        * @return the added scenario
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property doesn't exist
+        * @throws MultiplyDefinedException
+        *             if some property occurs several times
+        */
+       public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException;
+
        /**
         * Add a new knowledge element to the scenario.
         * 
index 01c9843c5d65742102c888644bc6010ced21cbdd..10b5ba93b72c8982120a6cb7570b46b7990e1840 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -17,14 +17,18 @@ import java.util.List;
 import org.apache.log4j.Logger;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.KnowledgeElementType;
 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.dao.som.KnowledgeElementDAO;
 import org.splat.dal.dao.som.ScenarioDAO;
+import org.splat.dal.dao.som.StudyDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
+import org.splat.kernel.UserDirectory;
 import org.splat.service.technical.IndexService;
 import org.splat.som.Step;
 import org.springframework.transaction.annotation.Transactional;
@@ -50,6 +54,10 @@ public class ScenarioServiceImpl implements ScenarioService {
         * Injected step service.
         */
        private StepService _stepService;
+       /**
+        * Injected study service.
+        */
+       private StudyService _studyService;
        /**
         * Injected publication service.
         */
@@ -67,6 +75,16 @@ public class ScenarioServiceImpl implements ScenarioService {
         */
        private ScenarioDAO _scenarioDAO;
 
+       /**
+        * Injected study DAO.
+        */
+       private StudyDAO _studyDAO;
+
+       /**
+        * Injected knowledge element service.
+        */
+       private KnowledgeElementTypeService _knowledgeElementTypeService;
+
        /**
         * Get the projectElementService.
         * 
@@ -135,18 +153,21 @@ public class ScenarioServiceImpl implements ScenarioService {
        public KnowledgeElement addKnowledgeElement(Scenario aScenario,
                        KnowledgeElement.Properties kprop) throws MissedPropertyException,
                        InvalidPropertyException, MultiplyDefinedException {
-               KnowledgeElement kelm = new KnowledgeElement(kprop
-                               .setOwnerScenario(aScenario));
+               KnowledgeElement kelm = null;
                try {
+                       // Attach the detached scenario to the new hibernate session.
+                       aScenario = getScenarioDAO().merge(aScenario); // RKV
+                       kelm = new KnowledgeElement(kprop.setOwnerScenario(aScenario));
                        getKnowledgeElementDAO().create(kelm);
                        // RKV: commented because of BatchUpdateException during creation of a new study: session.flush(); //RKV
                        // Update of my persistent data
-                       aScenario.getKnowledgeElements().add(kelm);
+                       // RKV aScenario.getKnowledgeElements().add(kelm);
+                       // RKV getKnowledgeElementDAO().flush();
                        // RKV: commented because of NullPointerException during creation of a new study: session.merge(aScenario); //RKV
                        // Update of my transient data
                        List<KnowledgeElement> known = aScenario
                                        .getKnowledgeElementsOf(kelm.getType()); // Initializes this.known, if not yet done
-                       known.add(kelm);
+                       // RKV: knowledge is already added into persistent set and "known" is constructed from it in the above call: known.add(kelm);
                        if (kelm.getType().equals("usecase")) {
                                aScenario.setUcase(kelm);
                        } else if (aScenario.getKnowledgeElementsList() != null) { // If null, knowl will be initialized when needed
@@ -202,7 +223,7 @@ public class ScenarioServiceImpl implements ScenarioService {
         * @see org.splat.service.ScenarioService#checkout(org.splat.dal.bo.som.Scenario, org.splat.dal.bo.kernel.User)
         */
        public boolean checkout(Scenario aScenario, User user) {
-               if (!aScenario.getOwnerStudy().isStaffedBy(user))
+               if (!getStudyService().isStaffedBy(aScenario.getOwnerStudy(), user))
                        return false;
 
                aScenario.setUser(user);
@@ -230,7 +251,7 @@ public class ScenarioServiceImpl implements ScenarioService {
                                Publication doc = getPublicationService().copy(j.next(),
                                                scenario); // Creation of a new reference to the document
                                // Database.getSession().save(doc); Publications MUST be saved later through cascading when saving the scenario
-                               to[i].add(doc);
+                               getStepService().add(to[i], doc);
                        }
                        List<SimulationContext> ctex = step.getAllSimulationContexts();
                        for (Iterator<SimulationContext> j = ctex.iterator(); j.hasNext();) {
@@ -273,6 +294,46 @@ public class ScenarioServiceImpl implements ScenarioService {
                return notempty;
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.StudyService#addScenario(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Scenario.Properties)
+        */
+       @Transactional
+       public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException {
+               if (sprop.getManager() == null)
+                       sprop.setManager(aStudy.getAuthor());
+
+               Scenario scenario = new Scenario(sprop.setOwnerStudy(aStudy));
+               if (sprop.getBaseStep() != null)
+                       copyContentsUpTo(scenario, sprop.getBaseStep());
+               Scenario previous = sprop.getInsertAfter();
+
+               if (previous == null) {
+                       aStudy.getScenariiList().add(scenario);
+               } else {
+                       aStudy.getScenariiList().add(
+                                       aStudy.getScenariiList().indexOf(previous) + 1, scenario);
+               }
+               getStudyDAO().update(aStudy); // No need to update the Lucene index
+               getScenarioDAO().create(scenario); // Must be done after updating this study because of the back reference to the study
+               if (sprop.getBaseStep() != null) {
+                       // No need to update the Knowledge Element index as Knowledge Elements are not copied
+                       scenario.refresh(); // Because saving the scenario changes the hashcode of copied Publications
+               }
+               KnowledgeElementType ucase = getKnowledgeElementTypeService().selectType(
+                               "usecase");
+               KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
+               User admin = UserDirectory.selectUser(1); // First user created when creating the database
+               kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue(
+                               scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of
+               // knowledges
+               addKnowledgeElement(scenario, kprop);
+               return scenario;
+       }
+
        /**
         * Get the knowledgeElementDAO.
         * 
@@ -330,4 +391,59 @@ public class ScenarioServiceImpl implements ScenarioService {
                _scenarioDAO = scenarioDAO;
        }
 
+       /**
+        * Get the studyDAO.
+        * 
+        * @return the studyDAO
+        */
+       public StudyDAO getStudyDAO() {
+               return _studyDAO;
+       }
+
+       /**
+        * Set the studyDAO.
+        * 
+        * @param studyDAO
+        *            the studyDAO to set
+        */
+       public void setStudyDAO(StudyDAO studyDAO) {
+               _studyDAO = studyDAO;
+       }
+
+       /**
+        * Get the knowledgeElementTypeService.
+        * 
+        * @return the knowledgeElementTypeService
+        */
+       public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+               return _knowledgeElementTypeService;
+       }
+
+       /**
+        * Set the knowledgeElementTypeService.
+        * 
+        * @param knowledgeElementTypeService
+        *            the knowledgeElementTypeService to set
+        */
+       public void setKnowledgeElementTypeService(
+                       KnowledgeElementTypeService knowledgeElementTypeService) {
+               _knowledgeElementTypeService = knowledgeElementTypeService;
+       }
+
+       /**
+        * 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;
+       }
+
 }
index 2482843501fdbc38b273f200fce0297281d328fd..08a8ab8ad4b53493a819bddef84fba4d1a8cf520 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
index 6ed816e7bff5e1cba554bfd5e48b179b9560e405..75f3d6a961f8ae6492fbb2fe01da66daa09ed484 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
diff --git a/Workspace/Siman-Common/src/org/splat/service/ServiceLocator.java b/Workspace/Siman-Common/src/org/splat/service/ServiceLocator.java
new file mode 100644 (file)
index 0000000..51c6214
--- /dev/null
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   19.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ * @copyright      OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service; 
+
+/**
+ * The service locator interface.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+@Deprecated
+public interface ServiceLocator {
+       /**
+        * Get study service.
+        * @return study service
+        */
+       StudyService getStudyService();
+}
diff --git a/Workspace/Siman-Common/src/org/splat/service/ServiceLocatorImpl.java b/Workspace/Siman-Common/src/org/splat/service/ServiceLocatorImpl.java
new file mode 100644 (file)
index 0000000..6f99f6a
--- /dev/null
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   19.10.2012
+ * @author         $Author$
+ * @version        $Revision$
+ * @copyright      OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service; 
+
+/**
+ * The service locator implementaion. This is a singleton class for providing access to business services.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+@Deprecated
+public class ServiceLocatorImpl implements ServiceLocator {
+
+       /**
+        * The Locator instance.
+        */
+       static ServiceLocator theInstance;
+
+       /**
+        * Get the locator instance.
+        * @return the locator instance
+        */
+       public static ServiceLocator getInstance() {
+               if (theInstance == null) {
+                       theInstance = new ServiceLocatorImpl();
+               }
+               return theInstance;
+       }
+       
+       /**
+        * Private constructor because this is a singleton class.
+        */
+       private ServiceLocatorImpl() {
+       }
+
+       /**
+        * Injected study service.
+        */
+       private StudyService _studyService;
+
+       /**
+        * 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;
+       }
+}
index 1cbf05c430dfbaa8a9a0948d39fbc47e6cd99372..dc9cc3425405eaa73b44d991ede287e0c8af0508 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   16.10.2012
index decbcdec79c9b96ee079c138dded480aab095a5e..81abc66eb2f1cfac6554bd8954bba5b5ef32aad0 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   16.10.2012
index 69c96fae708dc2f0b4481cb8e9be2cbb3e80f774..35a8ad057671d0da2f5cf1a04962e3c6f6cfd714 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
 package org.splat.service;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.kernel.InvalidPropertyException;
@@ -23,35 +25,158 @@ import org.splat.som.Step;
 
 /**
  * Step service interface.
+ * 
  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
 public interface StepService {
 
+       /**
+        * Create a new document published in the given study step.
+        * 
+        * @param aStep
+        *            the target study step
+        * @param dprop
+        *            properties of the new document
+        * @return the created publication of the new document
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property doesn't exist
+        * @throws MultiplyDefinedException
+        *             if some property is defined several times
+        * @throws IOException
+        *             if a file system error occurs
+        */
        public Publication createDocument(Step aStep, Document.Properties dprop)
                        throws MissedPropertyException, InvalidPropertyException,
                        MultiplyDefinedException, IOException;
 
+       /**
+        * Publish an existing document in the given study step.
+        * 
+        * @param aStep
+        *            the target study step
+        * @param dprop
+        *            new properties of the document
+        * @return the created publication of the document
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property doesn't exist
+        * @throws NotApplicableException
+        *             if the document is undefined
+        */
        public Publication assignDocument(Step aStep, Document.Properties dprop)
                        throws MissedPropertyException, InvalidPropertyException,
                        NotApplicableException;
 
+       /**
+        * Create a new version of a document in the given study step.
+        * 
+        * @param aStep
+        *            the study step
+        * @param base
+        *            the base document published version
+        * @param dprop
+        *            properties of the new version
+        * @return the new version publication
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property doesn't exist
+        * @throws MultiplyDefinedException
+        *             if some property is defined several times
+        * @throws IOException
+        *             if a file system error occurs
+        * @throws MismatchException
+        *             if the document is not applicable to the given study step
+        */
        public Publication versionDocument(Step aStep, Publication base,
                        Document.Properties dprop) throws MissedPropertyException,
                        InvalidPropertyException, MultiplyDefinedException, IOException,
                        MismatchException;
 
+       /**
+        * Add simulation context to the study step.
+        * 
+        * @param aStep
+        *            the study step
+        * @param dprop
+        *            properties of the simulation context to add
+        * @return the added simulation context
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property doesn't exist
+        * @throws MultiplyDefinedException
+        *             if some property is defined several times
+        */
        public SimulationContext addSimulationContext(Step aStep,
                        SimulationContext.Properties dprop) throws MissedPropertyException,
-                       InvalidPropertyException, MultiplyDefinedException,
-                       RuntimeException;
+                       InvalidPropertyException, MultiplyDefinedException;
 
        /**
+        * Add simulation context to the study step.
+        * 
         * @param firstStep
+        *            the study step
         * @param context
-        * @return
+        *            the simulation context to add
+        * @return the added simulation context
         */
        public SimulationContext addSimulationContext(Step firstStep,
                        SimulationContext context);
 
+       /**
+        * Remove a simulation context from the study step.
+        * 
+        * @param aStep
+        *            the study step
+        * @param context
+        *            the simulation context to remove
+        * @return true if removal succeeded
+        */
        public boolean removeSimulationContext(Step aStep, SimulationContext context);
+
+       /**
+        * Add a document publication to the given step.
+        * 
+        * @param aStep
+        *            the target study step
+        * @param newdoc
+        *            the document publication to add
+        * @return true if publication succeeded
+        */
+       public boolean add(Step aStep, Publication newdoc);
+
+       /**
+        * Remove a document publication from the given step.
+        * 
+        * @param aStep
+        *            the study step
+        * @param oldoc
+        *            the document publication to remove
+        * @return true if removing of the publication succeeded
+        */
+       public boolean remove(Step aStep, Publication oldoc);
+
+       /**
+        * Remove a document from the given step.
+        * 
+        * @param aStep
+        *            the study step
+        * @param doctag
+        *            the document publication
+        * @return true if removing of the document succeeded
+        */
+       public boolean removeDocument(Step aStep, Publication doctag);
+
+       /**
+        * Get document types which are applicable for the given study step (activity).
+        * 
+        * @param aStep
+        *            the study step
+        * @return the list of document types
+        */
+       public List<DocumentType> getValidDocumentTypes(Step aStep);
 }
index ccb0faca57e227217ef0ecfd7a7a1756fee87623..d40b87a50d22c329a76ec721b96721a337ea5b29 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
@@ -9,13 +9,17 @@
 
 package org.splat.service;
 
-import java.io.File;
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
+import java.util.Vector;
 
 import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.File;
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
@@ -25,6 +29,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.DocumentDAO;
+import org.splat.dal.dao.som.FileDAO;
 import org.splat.dal.dao.som.ProjectElementDAO;
 import org.splat.dal.dao.som.SimulationContextDAO;
 import org.splat.kernel.InvalidPropertyException;
@@ -58,10 +63,18 @@ public class StepServiceImpl implements StepService {
         * Injected document service.
         */
        private DocumentService _documentService;
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
        /**
         * Injected document DAO.
         */
        private DocumentDAO _documentDAO;
+       /**
+        * Injected file DAO.
+        */
+       private FileDAO _fileDAO;
        /**
         * Injected simulation context service.
         */
@@ -82,8 +95,7 @@ public class StepServiceImpl implements StepService {
         */
        public SimulationContext addSimulationContext(Step aStep,
                        SimulationContext.Properties dprop) throws MissedPropertyException,
-                       InvalidPropertyException, MultiplyDefinedException,
-                       RuntimeException {
+                       InvalidPropertyException, MultiplyDefinedException {
                SimulationContext context = new SimulationContext(dprop.setStep(aStep
                                .getStep()));
                return addSimulationContext(aStep, context);
@@ -143,7 +155,8 @@ public class StepServiceImpl implements StepService {
                                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);
                }
        }
 
@@ -209,14 +222,14 @@ public class StepServiceImpl implements StepService {
                getDocumentService().generateDocumentId(newdoc, dprop);
 
                // Creation of the save directory
-               File wdir = getDocumentService().getSaveDirectory(newdoc);
+               java.io.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());
+               getDocumentService().buildReferenceFrom(newdoc, aStep.getOwnerStudy());
                getDocumentDAO().create(newdoc);
 
                return new Publication(newdoc, aStep.getOwner());
@@ -247,14 +260,23 @@ public class StepServiceImpl implements StepService {
        }
 
        /**
+        * Create a new version of a document in the given study step.
+        * 
         * @param aStep
+        *            the study step
         * @param base
-        * @return
+        *            the base document published version
+        * @return the new version publication
         * @throws MissedPropertyException
+        *             if a mandatory property is missed
         * @throws InvalidPropertyException
+        *             if some property doesn't exist
         * @throws MultiplyDefinedException
+        *             if some property is defined several times
         * @throws IOException
+        *             if a file system error occurs
         * @throws MismatchException
+        *             if the document is not applicable to the given study step
         */
        public Publication versionDocument(Step aStep, Publication base)
                        throws MissedPropertyException, InvalidPropertyException,
@@ -263,15 +285,25 @@ public class StepServiceImpl implements StepService {
        }
 
        /**
+        * Create a new version of a document in the given study step.
+        * 
         * @param aStep
+        *            the study step
         * @param base
+        *            the base document published version
         * @param reason
-        * @return
+        *            the comment for the new version
+        * @return the new version publication
         * @throws MissedPropertyException
+        *             if a mandatory property is missed
         * @throws InvalidPropertyException
+        *             if some property doesn't exist
         * @throws MultiplyDefinedException
+        *             if some property is defined several times
         * @throws IOException
+        *             if a file system error occurs
         * @throws MismatchException
+        *             if the document is not applicable to the given study step
         */
        public Publication versionDocument(Step aStep, Publication base,
                        String reason) throws MissedPropertyException,
@@ -282,10 +314,25 @@ public class StepServiceImpl implements StepService {
        }
 
        /**
-        * {@inheritDoc}
+        * Create a new version of a document in the given study step.
         * 
-        * @see org.splat.service.StepService#versionDocument(org.splat.som.Step, org.splat.dal.bo.som.Publication,
-        *      org.splat.dal.bo.som.Document.Properties)
+        * @param aStep
+        *            the study step
+        * @param base
+        *            the base document published version
+        * @param dprop
+        *            properties of the new version
+        * @return the new version publication
+        * @throws MissedPropertyException
+        *             if a mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property doesn't exist
+        * @throws MultiplyDefinedException
+        *             if some property is defined several times
+        * @throws IOException
+        *             if a file system error occurs
+        * @throws MismatchException
+        *             if the document is not applicable to the given study step
         */
        @Transactional
        public Publication versionDocument(Step aStep, Publication base,
@@ -306,7 +353,8 @@ 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);
+               getDocumentService().buildReferenceFrom(newdoc, aStep.getOwner(),
+                               previous);
                getDocumentDAO().create(newdoc);
 
                // Versioning
@@ -329,6 +377,91 @@ public class StepServiceImpl implements StepService {
                return new Publication(newdoc, aStep.getOwner());
        }
 
+       /**
+        * Get document types which are applicable for the given study step (activity).
+        * 
+        * @param aStep
+        *            the study step
+        * @return the list of document types
+        */
+       public List<DocumentType> getValidDocumentTypes(Step aStep) {
+               return getDocumentTypeService().selectTypesOf(aStep.getStep());
+       }
+
+       /**
+        * Add a document publication to the given step.
+        * 
+        * @param aStep
+        *            the target study step
+        * @param newdoc
+        *            the document publication to add
+        * @return true if publication succeeded
+        */
+       public boolean add(Step aStep, Publication newdoc) {
+               if (!aStep.getOwner().add(newdoc))
+                       return false; // Updates the study in memory
+               aStep.getDocuments().add(0, newdoc); // Updates this step
+               getDocumentService().hold(newdoc.value()); // Increments the configuration tag count of document
+               // If not yet saved, the Publication MUST NOT be saved here, although this creates a temporary inconsistent state into the
+               // database (it will be saved later by cascading the update of owner scenario).
+               return true;
+       }
+
+       /**
+        * Remove a document publication from the given step.
+        * 
+        * @param aStep
+        *            the study step
+        * @param oldoc
+        *            the document publication to remove
+        * @return true if removing of the publication succeeded
+        */
+       public boolean remove(Step aStep, Publication oldoc) {
+               if (!aStep.getOwner().remove(oldoc))
+                       return false; // Updates the study in memory
+               aStep.getDocuments().remove(oldoc); // Updates this step
+               getDocumentService().release(oldoc.value()); // Decrements the configuration tag count of document
+               // The publication becoming orphan, it should automatically be removed from the database when updating of owner scenario.
+               return true;
+       }
+
+       /**
+        * Remove a document from the given step.
+        * 
+        * @param aStep
+        *            the study step
+        * @param doctag
+        *            the document publication
+        * @return true if removing of the document succeeded
+        */
+       public boolean removeDocument(Step aStep, Publication doctag) {
+               Document value = doctag.value();
+               Publication torem = aStep.getDocument(value.getIndex());
+
+               if (torem == null)
+                       return false;
+
+               remove(aStep, torem);
+               getProjectElementDAO().update(aStep.getOwner());
+               if (!value.isPublished() && !value.isVersioned()) { // The referenced document is no more used
+                       Set<Relation> links = value.getAllRelations(); // Get all relation of the document to remove them
+                       List<Document> using = new Vector<Document>();
+                       for (Iterator<Relation> i = links.iterator(); i.hasNext();) {
+                               Relation link = i.next();
+                               if (link.getClass().equals(ConvertsRelation.class)) { // File conversion
+                                       getFileDAO().delete((File) link.getTo()); // The corresponding physical file is not removed from the vault
+                               } else if (link.getClass().equals(UsesRelation.class)) { // Document dependency
+                                       using.add((Document) link.getTo());
+                               }
+                       }
+                       for (Iterator<Document> i = using.iterator(); i.hasNext();) {
+                               i.next().removeRelation(UsedByRelation.class, value); // TODO: RKV: don't use Database.getSession in removeRelation
+                       }
+                       getDocumentDAO().delete(value); // The corresponding physical file is not removed from the vault
+               }
+               return true;
+       }
+
        /**
         * Get the documentService.
         * 
@@ -444,4 +577,42 @@ public class StepServiceImpl implements StepService {
        public void setIndexService(IndexService indexService) {
                _indexService = indexService;
        }
+
+       /**
+        * Get the fileDAO.
+        * 
+        * @return the fileDAO
+        */
+       public FileDAO getFileDAO() {
+               return _fileDAO;
+       }
+
+       /**
+        * Set the fileDAO.
+        * 
+        * @param fileDAO
+        *            the fileDAO to set
+        */
+       public void setFileDAO(FileDAO fileDAO) {
+               _fileDAO = fileDAO;
+       }
+
+       /**
+        * Get the documentTypeService.
+        * 
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * 
+        * @param documentTypeService
+        *            the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
 }
index cfcdde044641640d68b025291b8357d0f2b5cb4c..50595523194a58b0341c0e1633b57632ccb131b2 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            Id: 
  * Creation date   02.10.2012
@@ -9,6 +9,8 @@
 
 package org.splat.service;
 
+import java.util.List;
+
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.Publication;
@@ -31,7 +33,9 @@ public interface StudyService {
 
        /**
         * Increment total number of study documents including versions (docount) and update it in the study.
-        * @param aStudy the study
+        * 
+        * @param aStudy
+        *            the study
         * @return incremented docount value
         */
        public int generateLocalIndex(Study aStudy);
@@ -94,28 +98,12 @@ public interface StudyService {
                        SimulationContext context);
 
        /**
-        * Add a new scenario to the study.
+        * Remove a simulation context from a study.
         * 
         * @param aStudy
         *            the study
-        * @param sprop
-        *            scenario properties
-        * @return the added scenario
-        * @throws MissedPropertyException
-        *             if a mandatory property is missed
-        * @throws InvalidPropertyException
-        *             if some property doesn't exist
-        * @throws MultiplyDefinedException
-        *             if some property occurs several times
-        */
-       public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
-                       throws MissedPropertyException, InvalidPropertyException,
-                       MultiplyDefinedException;
-
-       /**
-        * Remove a simulation context from a study.
-        * @param aStudy the study
-        * @param context the simulation context to remove
+        * @param context
+        *            the simulation context to remove
         * @return true if removing succeeded
         */
        public boolean removeProjectContext(Study aStudy, SimulationContext context);
@@ -211,4 +199,56 @@ public interface StudyService {
         */
        public boolean update(Study aStudy, Properties sprop)
                        throws InvalidPropertyException;
+
+       /**
+        * Initialize shortcuts of the study as its transient collections.
+        * 
+        * @param aStudy
+        *            the study
+        */
+       public void loadWorkflow(Study aStudy);
+
+       /**
+        * Returns the validation cycle of the given document type.
+        * 
+        * @param aStudy
+        *            the study
+        * @param type
+        *            the document type being subject of validation
+        * @return the validation cycle of the document, or null if not defined.
+        */
+       public ValidationCycle getValidationCycleOf(Study aStudy, DocumentType type);
+
+       /**
+        * Checks if the given user participates to this study. The Study staff includes the author and contributors.
+        * 
+        * @param aStudy
+        *            the study
+        * @param user
+        *            the user to look for
+        * @return true if the given user is actor of this study.
+        * @see #getContributors()
+        */
+       public boolean isStaffedBy(Study aStudy, User user);
+
+       /**
+        * Checks if the given user is actor of this study. Actors include contributors, reviewers and approvers.
+        * 
+        * @param aStudy
+        *            the study
+        * @param user
+        *            the user to look for
+        * @return true if the given user is actor of this study.
+        * @see #getActors()
+        */
+       public boolean hasActor(Study aStudy, User user);
+
+       /**
+        * Returns unmodifiable initialized transient list of contributors of this study.
+        * 
+        * @param aStudy
+        *            the study
+        * @return the unmodifiable not null transient list of contributors of this study
+        */
+       public List<User> getContributors(Study aStudy);
 }
index d120b69444d1675dd5fd47b31d17216fb495dfd8..5a0cbce2e6ae1031eab58576bd18e8347d8043dd 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            Id: 
  * Creation date   02.10.2012
 package org.splat.service;
 
 import java.io.IOException;
-import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import org.hibernate.criterion.Restrictions;
 import org.splat.dal.bo.kernel.Relation;
@@ -27,7 +28,6 @@ import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.IDBuilder;
 import org.splat.dal.bo.som.KnowledgeElement;
-import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
@@ -35,8 +35,10 @@ import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.ValidationCycle;
 import org.splat.dal.bo.som.ValidationCycleRelation;
+import org.splat.dal.bo.som.ValidationStep;
 import org.splat.dal.bo.som.Visibility;
 import org.splat.dal.bo.som.Study.Properties;
+import org.splat.dal.bo.som.ValidationCycle.Actor;
 import org.splat.dal.dao.som.IDBuilderDAO;
 import org.splat.dal.dao.som.ScenarioDAO;
 import org.splat.dal.dao.som.StudyDAO;
@@ -48,6 +50,7 @@ import org.splat.kernel.UserDirectory;
 import org.splat.log.AppLogger;
 import org.splat.service.technical.IndexService;
 import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.ProjectSettingsServiceImpl;
 import org.splat.som.Revision;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -75,11 +78,6 @@ public class StudyServiceImpl implements StudyService {
         */
        private StepService _stepService;
 
-       /**
-        * Injected scenario service.
-        */
-       private ScenarioService _scenarioService;
-
        /**
         * Injected project service.
         */
@@ -110,6 +108,11 @@ public class StudyServiceImpl implements StudyService {
         */
        private IDBuilderDAO _iDBuilderDAO;
 
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
+
        /**
         * {@inheritDoc}
         * 
@@ -118,7 +121,7 @@ public class StudyServiceImpl implements StudyService {
        @Transactional
        public Study selectStudy(long index) {
                Study result = getStudyDAO().get(index);
-               result.loadWorkflow();
+               loadWorkflow(result);
                return result;
        }
 
@@ -133,7 +136,7 @@ public class StudyServiceImpl implements StudyService {
        public Study selectStudy(String refid) {
                Study result = getStudyDAO().findByCriteria(
                                Restrictions.eq("sid", refid));
-               result.loadWorkflow();
+               loadWorkflow(result);
                return result;
        }
 
@@ -195,13 +198,13 @@ public class StudyServiceImpl implements StudyService {
         * @see org.splat.service.StudyService#addContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User)
         */
        public boolean addContributor(Study aStudy, User user) {
-               List<User> contributor = aStudy.getModifiableContributors(); // Initializes contributor
+               List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
                for (Iterator<User> i = contributor.iterator(); i.hasNext();) {
                        User present = i.next();
                        if (present.equals(user))
                                return false;
                }
-               boolean absent = aStudy.getModifiableActors().add(user); // User may already be a reviewer or an approver
+               boolean absent = getModifiableActors(aStudy).add(user); // User may already be a reviewer or an approver
 
                aStudy.addRelation(new ContributorRelation(aStudy, user));
                if (absent)
@@ -276,7 +279,7 @@ public class StudyServiceImpl implements StudyService {
         * @see org.splat.service.StudyService#removeContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User[])
         */
        public boolean removeContributor(Study aStudy, User... users) {
-               List<User> contributor = aStudy.getModifiableContributors(); // Initializes contributor
+               List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
                Boolean done = false;
                for (int i = 0; i < users.length; i++) {
                        User user = users[i];
@@ -317,26 +320,25 @@ public class StudyServiceImpl implements StudyService {
        @Transactional
        public void setValidationCycle(Study aStudy, DocumentType type,
                        ValidationCycle.Properties vprop) {
-               HashMap<String, ValidationCycle> validactor = aStudy
-                               .getValidationCycles();
+               Map<String, ValidationCycle> validactor = aStudy.getValidationCycles();
                if (validactor == null)
-                       aStudy.setShortCuts(); // Initializes validactor and actor
+                       setShortCuts(aStudy); // Initializes validactor and actor
 
                String cname = type.getName();
                ValidationCycle cycle = validactor.get(cname);
 
                if (cycle != null && cycle.isAssigned()) {
-                       cycle.resetActors(vprop);
+                       resetActors(cycle, vprop);
                } else
                        try {
                                cycle = new ValidationCycle(aStudy, vprop.setDocumentType(type));
 
-                               getValidationCycleDAO().create(cycle); //RKV
-                               
+                               getValidationCycleDAO().create(cycle); // RKV
+
                                ValidationCycleRelation link = cycle.getContext();
-//RKV:                         aStudy.addRelation(link);
-                               aStudy.getAllRelations().add(link); //RKV
-                               
+                               // RKV: aStudy.addRelation(link);
+                               aStudy.getAllRelations().add(link); // RKV
+
                                validactor.put(cname, link.getTo()); // Replaces the cycle if exists as default,
                        } catch (Exception error) {
                                logger.error("Unable to re-index Knowledge Elements, reason:",
@@ -377,46 +379,6 @@ public class StudyServiceImpl implements StudyService {
                return aStudy.getLastLocalIndex();
        }
 
-       /**
-        * {@inheritDoc}
-        * 
-        * @see org.splat.service.StudyService#addScenario(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Scenario.Properties)
-        */
-       @Transactional
-       public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
-                       throws MissedPropertyException, InvalidPropertyException,
-                       MultiplyDefinedException {
-               if (sprop.getManager() == null)
-                       sprop.setManager(aStudy.getAuthor());
-
-               Scenario scenario = new Scenario(sprop.setOwnerStudy(aStudy));
-               if (sprop.getBaseStep() != null)
-                       getScenarioService()
-                                       .copyContentsUpTo(scenario, sprop.getBaseStep());
-               Scenario previous = sprop.getInsertAfter();
-
-               if (previous == null) {
-                       aStudy.getScenariiList().add(scenario);
-               } else {
-                       aStudy.getScenariiList().add(
-                                       aStudy.getScenariiList().indexOf(previous) + 1, scenario);
-               }
-               getStudyDAO().update(aStudy); // No need to update the Lucene index
-               getScenarioDAO().create(scenario); // Must be done after updating this study because of the back reference to the study
-               if (sprop.getBaseStep() != null) {
-                       // No need to update the Knowledge Element index as Knowledge Elements are not copied
-                       scenario.refresh(); // Because saving the scenario changes the hashcode of copied Publications
-               }
-               KnowledgeElementType ucase = KnowledgeElement.selectType("usecase");
-               KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
-               User admin = UserDirectory.selectUser(1); // First user created when creating the database
-               kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue(
-                               scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of
-               // knowledges
-               getScenarioService().addKnowledgeElement(scenario, kprop);
-               return scenario;
-       }
-
        /**
         * Promotes this study from In-Work to In-Draft then In-Check and APPROVED states. This function is called internally when promoting the
         * final result document of the study.
@@ -474,6 +436,7 @@ public class StudyServiceImpl implements StudyService {
                boolean isOk = false;
                try {
                        getStudyDAO().update(aStudy); // Update of relational base
+                       setShortCuts(aStudy); //RKV: initialize transient actors set
                        getIndex().update(aStudy); // Update of Lucene index
                        isOk = true;
                } catch (Exception error) {
@@ -523,14 +486,14 @@ public class StudyServiceImpl implements StudyService {
         *            the study
         */
        private void resetActorsShortCut(Study aStudy) {
-               aStudy.getModifiableActors().clear();
+               getModifiableActors(aStudy).clear();
                // Get all actors involved in validation cycles
                for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
                                .values().iterator(); i.hasNext();) {
                        ValidationCycle cycle = i.next();
                        User[] user = cycle.getAllActors();
                        for (int j = 0; j < user.length; j++)
-                               aStudy.getModifiableActors().add(user[j]);
+                               getModifiableActors(aStudy).add(user[j]);
                }
                // Get all other actors
                for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
@@ -539,7 +502,7 @@ public class StudyServiceImpl implements StudyService {
                        Class<?> kindof = link.getClass().getSuperclass();
                        if (!kindof.equals(ActorRelation.class))
                                continue;
-                       aStudy.getModifiableActors().add(((ActorRelation) link).getTo());
+                       getModifiableActors(aStudy).add(((ActorRelation) link).getTo());
                }
        }
 
@@ -586,6 +549,316 @@ public class StudyServiceImpl implements StudyService {
                return lucin;
        }
 
+       /**
+        * Create a new validation cycle for documents of the given study.
+        * 
+        * @param from
+        *            the study
+        * @param cycle
+        *            the cycle description
+        * @return the new validation cycle
+        */
+       protected ValidationCycle createValidationCycle(Study from,
+                       ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle) {
+               // -----------------------------------------------------------------------------
+               Actor[] actype = cycle.getActorTypes();
+               User.Properties uprop = new User.Properties();
+
+               ValidationCycle aValidationCycle = new ValidationCycle();
+               aValidationCycle.setDocumentType(getDocumentTypeService().selectType(
+                               cycle.getName())); // Null in case of default validation cycle
+               // context = new ValidationCycleRelation(from, this);
+               // RKV aValidationCycle.context = null; // Validation cycle defined in the workflow
+               for (int i = 0; i < actype.length; i++) {
+                       User actor = null;
+                       if (actype[i] != null)
+                               try {
+                                       if (actype[i] == Actor.manager) {
+                                               actor = from.getAuthor();
+                                       } else if (actype[i] == Actor.Nx1) {
+                                               List<User> manager = UserDirectory
+                                                               .selectUsersWhere(uprop
+                                                                               .setOrganizationName("Nx1"));
+                                               if (manager.size() == 1)
+                                                       actor = manager.get(0);
+                                       } else if (actype[i] == Actor.Nx2) {
+                                               List<User> manager = UserDirectory
+                                                               .selectUsersWhere(uprop
+                                                                               .setOrganizationName("Nx2"));
+                                               if (manager.size() == 1)
+                                                       actor = manager.get(0);
+                                       } else { /* Actor.customer */
+                                               actor = from.getAuthor();
+                                               // TODO: Get the customer of the study, if exists
+                                       }
+                               } catch (Exception e) { // Should not happen
+                                       actor = null;
+                               }
+                       if (i == 0)
+                               aValidationCycle.setReviewer(actor);
+                       else if (i == 1)
+                               aValidationCycle.setApprover(actor);
+                       else if (i == 2)
+                               aValidationCycle.setSignatory(actor);
+               }
+               return aValidationCycle;
+       }
+
+       /**
+        * Remove a validation step from the validation cycle.
+        * 
+        * @param aValidationCycle
+        *            the validation cycle
+        * @param step
+        *            the validation step to remove
+        */
+       @Transactional
+       protected void remove(ValidationCycle aValidationCycle, ValidationStep step) {
+               // ------------------------------------------
+               if (step == ValidationStep.REVIEW)
+                       aValidationCycle.setReviewer(null);
+               else if (step == ValidationStep.APPROVAL)
+                       aValidationCycle.setApprover(null);
+               else if (step == ValidationStep.ACCEPTANCE
+                               || step == ValidationStep.REFUSAL)
+                       aValidationCycle.setSignatory(null);
+               if (aValidationCycle.isSaved()) {
+                       getValidationCycleDAO().update(aValidationCycle);
+               }
+       }
+
+       /**
+        * Reset actors for the validation cycle.
+        * 
+        * @param aValidationCycle
+        *            the validation cycle to update
+        * @param vprop
+        *            new validation cycle properties containing new actors
+        */
+       @Transactional
+       public void resetActors(ValidationCycle aValidationCycle,
+                       ValidationCycle.Properties vprop) {
+               aValidationCycle.setPublisher(vprop.getPublisher()); // May be null
+               aValidationCycle.setReviewer(vprop.getReviewer()); // May be null
+               aValidationCycle.setApprover(vprop.getApprover()); // May be null
+               aValidationCycle.setSignatory(vprop.getSignatory()); // May be null
+               if (aValidationCycle.isSaved()) {
+                       getValidationCycleDAO().update(aValidationCycle);
+               }
+       }
+
+       /**
+        * Set actor for the given validation cycle and validation step.
+        * 
+        * @param aValidationCycle
+        *            the validation cycle
+        * @param step
+        *            the validation step
+        * @param actor
+        *            the actor to set
+        */
+       @Transactional
+       protected void setActor(ValidationCycle aValidationCycle,
+                       ValidationStep step, User actor) {
+               if (step == ValidationStep.PROMOTION) {
+                       aValidationCycle.setPublisher(actor);
+               } else if (step == ValidationStep.REVIEW) {
+                       aValidationCycle.setReviewer(actor);
+               } else if (step == ValidationStep.APPROVAL) {
+                       aValidationCycle.setApprover(actor);
+               } else if (step == ValidationStep.ACCEPTANCE
+                               || step == ValidationStep.REFUSAL) {
+                       aValidationCycle.setSignatory(actor);
+               }
+               if (aValidationCycle.isSaved()) {
+                       getValidationCycleDAO().update(aValidationCycle);
+               }
+       }
+
+       /**
+        * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
+        * 
+        * @param aStudy
+        *            the study
+        * @return the actors of this study
+        * @see #hasActor(User)
+        */
+       public Set<User> getActors(Study aStudy) {
+               if (aStudy.getActor() == null)
+                       setShortCuts(aStudy);
+               return Collections.unmodifiableSet(aStudy.getActor());
+       }
+
+       /**
+        * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
+        * 
+        * @param aStudy
+        *            the study
+        * @return the modifiable set of actors of this study
+        * @see #hasActor(User)
+        */
+       public Set<User> getModifiableActors(Study aStudy) {
+               if (aStudy.getActor() == null)
+                       setShortCuts(aStudy);
+               return aStudy.getActor();
+       }
+
+       /**
+        * Returns unmodifiable initialized transient list of contributors of this study.
+        * 
+        * @param aStudy
+        *            the study
+        * @return the unmodifiable not null transient list of contributors of this study
+        */
+       public List<User> getContributors(Study aStudy) {
+               if (aStudy.getContributor() == null)
+                       setShortCuts(aStudy);
+               return Collections.unmodifiableList(aStudy.getContributor()); // May be empty
+       }
+
+       /**
+        * Returns modifiable initialized transient list of contributors of this study.
+        * 
+        * @param aStudy
+        *            the study
+        * @return the modifiable not null transient list of contributors of this study
+        */
+       public List<User> getModifiableContributors(Study aStudy) {
+               if (aStudy.getContributor() == null)
+                       setShortCuts(aStudy);
+               return aStudy.getContributor(); // May be empty
+       }
+
+       /**
+        * Returns the validation cycle of the given document type.
+        * 
+        * @param aStudy
+        *            the study
+        * @param type
+        *            the document type being subject of validation
+        * @return the validation cycle of the document, or null if not defined.
+        */
+       public ValidationCycle getValidationCycleOf(Study aStudy, DocumentType type) {
+               if (aStudy.getValidationCycles() == null)
+                       setShortCuts(aStudy);
+               ValidationCycle result = aStudy.getValidationCycles().get(
+                               type.getName());
+               if (result == null) {
+                       if (type.isStepResult())
+                               result = aStudy.getValidationCycles().get("default"); // "default" validation cycle defined in the configuration, if exist
+                       if (result == null)
+                               result = aStudy.getValidationCycles().get("built-in");
+               }
+               return result;
+       }
+
+       /**
+        * Checks if the given user is actor of this study. Actors include contributors, reviewers and approvers.
+        * 
+        * @param aStudy
+        *            the study
+        * @param user
+        *            the user to look for
+        * @return true if the given user is actor of this study.
+        * @see #getActors()
+        */
+       public boolean hasActor(Study aStudy, User user) {
+               if (user == null)
+                       return false;
+               for (Iterator<User> i = getActors(aStudy).iterator(); i.hasNext();) {
+                       User involved = i.next();
+                       if (involved.equals(user))
+                               return true;
+               }
+               return false;
+       }
+
+       /**
+        * Checks if the given user participates to this study. The Study staff includes the author and contributors.
+        * 
+        * @param aStudy
+        *            the study
+        * @param user
+        *            the user to look for
+        * @return true if the given user is actor of this study.
+        * @see #getContributors()
+        */
+       public boolean isStaffedBy(Study aStudy, User user) {
+               if (user == null)
+                       return false;
+               if (aStudy.getAuthor().equals(user))
+                       return true;
+               for (Iterator<User> i = getContributors(aStudy).iterator(); i.hasNext();) {
+                       if (i.next().equals(user))
+                               return true;
+               }
+               return false;
+       }
+
+       /**
+        * Initialize shortcuts of the study as its transient collections.
+        * 
+        * @param aStudy
+        *            the study
+        */
+       public void loadWorkflow(Study aStudy) {
+               setShortCuts(aStudy);
+       }
+
+       /**
+        * Initialize shortcuts of the study as its transient collections.
+        * 
+        * @param aStudy
+        *            the study
+        */
+       public void setShortCuts(Study aStudy) {
+               aStudy.getContributor().clear();
+               aStudy.getValidationCycles().clear();
+               aStudy.getActor().clear();
+
+               // Get the contributors
+               for (Iterator<Relation> i = aStudy.getRelations(
+                               ContributorRelation.class).iterator(); i.hasNext();) {
+                       ContributorRelation link = (ContributorRelation) i.next();
+                       aStudy.getContributor().add(link.getTo());
+               }
+               // Get the validation cycles specific to this study
+               for (Iterator<Relation> i = aStudy.getRelations(
+                               ValidationCycleRelation.class).iterator(); i.hasNext();) {
+                       ValidationCycleRelation link = (ValidationCycleRelation) i.next();
+                       aStudy.getValidationCycles().put(link.getDocumentType().getName(),
+                                       link.getTo()); // The associated document type is necessarily not null in this
+                       // context
+               }
+               // Get the validation cycles coming from the configured workflow and not overridden in this study
+               for (Iterator<ProjectSettingsServiceImpl.ProjectSettingsValidationCycle> i = ProjectSettingsServiceImpl
+                               .getAllValidationCycles().iterator(); i.hasNext();) {
+                       ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle = i
+                                       .next();
+                       String type = cycle.getName();
+                       if (!aStudy.getValidationCycles().containsKey(type))
+                               aStudy.getValidationCycles().put(type,
+                                               createValidationCycle(aStudy, cycle));
+               }
+               // Get all corresponding actors
+               for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
+                               .values().iterator(); i.hasNext();) {
+                       ValidationCycle cycle = i.next();
+                       User[] user = cycle.getAllActors();
+                       for (int j = 0; j < user.length; j++)
+                               aStudy.getActor().add(user[j]);
+               }
+               // Get all other actors
+               for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
+                               .hasNext();) {
+                       Relation link = i.next();
+                       Class<?> kindof = link.getClass().getSuperclass();
+                       if (!kindof.equals(ActorRelation.class))
+                               continue;
+                       aStudy.getActor().add(((ActorRelation) link).getTo());
+               }
+       }
+
        /**
         * Get project settings.
         * 
@@ -701,25 +974,6 @@ public class StudyServiceImpl implements StudyService {
                _iDBuilderDAO = builderDAO;
        }
 
-       /**
-        * Get the scenarioService.
-        * 
-        * @return the scenarioService
-        */
-       public ScenarioService getScenarioService() {
-               return _scenarioService;
-       }
-
-       /**
-        * Set the scenarioService.
-        * 
-        * @param scenarioService
-        *            the scenarioService to set
-        */
-       public void setScenarioService(ScenarioService scenarioService) {
-               _scenarioService = scenarioService;
-       }
-
        /**
         * Get the scenarioDAO.
         * 
@@ -741,6 +995,7 @@ public class StudyServiceImpl implements StudyService {
 
        /**
         * Get the validationCycleDAO.
+        * 
         * @return the validationCycleDAO
         */
        public ValidationCycleDAO getValidationCycleDAO() {
@@ -749,9 +1004,30 @@ public class StudyServiceImpl implements StudyService {
 
        /**
         * Set the validationCycleDAO.
-        * @param validationCycleDAO the validationCycleDAO to set
+        * 
+        * @param validationCycleDAO
+        *            the validationCycleDAO to set
         */
        public void setValidationCycleDAO(ValidationCycleDAO validationCycleDAO) {
                _validationCycleDAO = validationCycleDAO;
        }
+
+       /**
+        * Get the documentTypeService.
+        * 
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * 
+        * @param documentTypeService
+        *            the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
 }
index a00f13d8df501cf5c79317bf53e1b38ccd709f94..cb19c0b101305814b3571e0bfa3848dcaa1b3664 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   08.10.2012
index a4562d6a75a560fb6cfb5be6b4b56854a5d6bbf2..4bd90ae99c654189515b65aca24926d07b29a07a 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   08.10.2012
index 54d99dc7dfe2eddfb6a7a030e4c1793f18447329..420bc8af1ce5d536762c3bb5e3aeecc268b7460b 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
index a219f01db02b3904f79981be2df7ee56ea25c78c..122dc1c5ed55ca85bc4a3ae893503f992477218a 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
index 91c57c4e717e7fec75be6e3c424ff9212a170154..bdd96baee306fa3cba7e3d103da07aa32d96c24f 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
index be622eb304c4afd6a977e132ca58f8b782c99220..6f96dc9401d755e873d3b71d465f63c310d49c72 100644 (file)
@@ -161,7 +161,8 @@ public class IndexServiceImpl implements IndexService {
       }
       private void setActorsOf (Study study)
       {
-       Set<User> actors = study.getActors();
+//RKV: This set is always not null. Let's assume that it must be initialized before reindexing:        Set<User> actors = study.getActors();
+       Set<User> actors = study.getActor(); //RKV
        for (Iterator<User> i=actors.iterator(); i.hasNext(); ) {
          String value = i.next().toString();
           entry.add( new Field("actor", value, Field.Store.NO, Field.Index.NOT_ANALYZED) );
index 856126f0502b03959054bc68f1fb66481df3fd8b..c9919c6d56dec343e973d7b20db7c2af4f704ed7 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
index 3d0a6e0b245f4448715d4be5b0b91f5ddfbc66e5..687b8f5f48a7de456f3f66c5ff2ae2748498c8a9 100644 (file)
@@ -32,16 +32,23 @@ import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Scenario;
-import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.ValidationCycle.Actor;
 import org.splat.dal.dao.som.Database;
 import org.splat.manox.XDOM;
+import org.splat.service.DocumentTypeService;
+import org.splat.service.KnowledgeElementTypeService;
 import org.splat.service.SimulationContextService;
 
 public class ProjectSettingsServiceImpl implements ProjectSettingsService {
 
+       /**
+        * The logger for the service.
+        */
+       protected final static Logger logger = Logger
+                       .getLogger(ProjectSettingsServiceImpl.class);
+
        // Non persistent configuration information
        private Properties reprop; // Repository settings
        private String pattern; // Pattern of study references
@@ -64,8 +71,14 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * Injected simulation context service.
         */
        private SimulationContextService _simulationContextService;
-       protected final static Logger logger = Logger
-                       .getLogger(ProjectSettingsServiceImpl.class);
+       /**
+        * Injected knowledge element type service.
+        */
+       private KnowledgeElementTypeService _knowledgeElementTypeService;
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
 
        public enum FileNaming {
                title, encoded, asis
@@ -456,7 +469,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                        tprop.setResult(step);
 
                                tprop.disableCheck();
-                               tdoc = Document.createType(tprop); // Creation of Document Types
+                               tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types
                                tdoc.approve();
                                maptype.put(type, tdoc);
                        }
@@ -468,12 +481,13 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
        private void createKnowledgeElementTypes() {
                // -------------------------------------------
                try {
-                       KnowledgeElementType ktype = KnowledgeElement.createType("usecase"); // Internal reserved knowledge element type
+                       KnowledgeElementType ktype = getKnowledgeElementTypeService()
+                                       .createType("usecase"); // Internal reserved knowledge element type
                        ktype.reserve();
                        for (Iterator<String> i = kname.iterator(); i.hasNext();) {
                                String type = i.next();
 
-                               ktype = KnowledgeElement.createType(type); // Knowledge Elements Types defined in the configuration
+                               ktype = getKnowledgeElementTypeService().createType(type); // Knowledge Elements Types defined in the configuration
                                ktype.approve();
                        }
                } catch (Exception error) {
@@ -554,4 +568,40 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                        SimulationContextService simulationContextService) {
                _simulationContextService = simulationContextService;
        }
+
+       /**
+        * Get the knowledgeElementTypeService.
+        * 
+        * @return the knowledgeElementTypeService
+        */
+       public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+               return _knowledgeElementTypeService;
+       }
+
+       /**
+        * Set the knowledgeElementTypeService.
+        * 
+        * @param knowledgeElementTypeService
+        *            the knowledgeElementTypeService to set
+        */
+       public void setKnowledgeElementTypeService(
+                       KnowledgeElementTypeService knowledgeElementTypeService) {
+               _knowledgeElementTypeService = knowledgeElementTypeService;
+       }
+
+       /**
+        * Get the documentTypeService.
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * @param documentTypeService the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
 }
\ No newline at end of file
index 51e83f5e98c20d77cee87edb4aab693ab9d7f7d3..3965a1a0f08dffa242547773d73926e84b70ffaf 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index bc1dd1d3a44beca32110fe38b512394f4185b0ff..7ad6f13c97d56ccd678cc77c42b440cd921f97c2 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   06.10.2012
index 6934941d9705dd02b5a888c0cab30569c9ee451d..599a32c48a55283ec7c148b2e89b476101d63ca0 100644 (file)
@@ -24,6 +24,7 @@ import org.splat.dal.bo.som.UsesRelation;
 import org.splat.dal.bo.som.ValidationCycle;
 import org.splat.dal.bo.som.ValidationStep;
 import org.splat.dal.bo.som.VersionsRelation;
+import org.splat.service.ServiceLocatorImpl;
 
 
 public class DocumentRights {
@@ -41,7 +42,8 @@ public class DocumentRights {
 //  --------------------------------------------------
       this.user     = user;
       this.operand  = tag;
-      this.cycle    = operand.getOwnerStudy().getValidationCycleOf(operand.value().getType());
+//RKV      this.cycle    = operand.getOwnerStudy().getValidationCycleOf(operand.value().getType());
+      this.cycle    = ServiceLocatorImpl.getInstance().getStudyService().getValidationCycleOf(operand.getOwnerStudy(), operand.value().getType());
       this.isauthor = operand.value().getAuthor().equals(user);
 //TODO: all contributors of the given document (when supported) must also behave as author
     }
@@ -49,7 +51,7 @@ public class DocumentRights {
 //  ------------------------------------------
       this.user     = operand.value().getAuthor();
       this.operand  = tag;
-      this.cycle    = operand.getOwnerStudy().getValidationCycleOf(operand.value().getType());
+      this.cycle    = ServiceLocatorImpl.getInstance().getStudyService().getValidationCycleOf(operand.getOwnerStudy(), operand.value().getType());
       this.isauthor = true;           // In order to ignore the author state in the context of any user
 //TODO: all contributors of the given document (when supported) must also behave as author
     }
index 46e44661c895d7c27370071565c84ad450462127..385d738a7472a11148151d66452c0596aa3ffe5c 100644 (file)
@@ -1,4 +1,5 @@
 package org.splat.som;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
@@ -40,231 +41,202 @@ import org.splat.kernel.NotApplicableException;
 import org.splat.service.technical.IndexServiceImpl;
 import org.splat.service.technical.ProjectSettingsService;
 
-
 public class Step {
-       
-       private ProjectSettingsService.Step    step;
-    private ProjectElement          owner;
-    private List<SimulationContext> contex;
-       private List<Publication>       docums;
-    private User                    actor;     // Actor involved in operations on published documents and requiring a time-stamp
-
-//  ==============================================================================================================================
-//  Constructor
-//  ==============================================================================================================================
-
-    public Step (ProjectSettingsService.Step step, ProjectElement owner) {
-//  ----------------------------------------------------------------
-      this.step   = step;
-      this.owner  = owner;
-      this.contex = new Vector<SimulationContext>();
-      this.docums = new Vector<Publication>();
-      this.actor  = null;
-
-//  Filtering of Simulation contexts, if exist
-      for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
-       SimulationContext adoc = i.next();
-        if (!adoc.isInto(this)) continue;
-        this.contex.add(adoc);
-      }
-//  Filtering of Documents, if exist
-      for (Iterator<Publication> i=owner.PublicationIterator(); i.hasNext();) {
-       Publication mydoc = i.next();
-        if (!mydoc.value().isInto(this)) continue;
-        this.docums.add(mydoc);
-      }
-    }
-
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-
-    public User getActor () {
-//  -----------------------
-      return actor;
-    }
 
-    public List<Publication> getAllDocuments () {
-//  -------------------------------------------
-      return  Collections.unmodifiableList(docums);
-    }
-    
-    public List<SimulationContext> getAllSimulationContexts () {
-//  ----------------------------------------------------------
-      return  Collections.unmodifiableList(contex);
-    }
-
-    public Publication getDocument (long l) {
-//  ------------------------------------------
-      for (Iterator<Publication> i=docums.iterator(); i.hasNext();) {
-       Publication found = i.next();                          // In a given study step,
-       if (found.value().getIndex() == l) return found;   // there is only one publication of a given document
-      }
-      return null;
-    }
-    
-    public int getNumber () {
-//  -----------------------
-      return step.getNumber();
-    }
+       private ProjectSettingsService.Step step;
+       private ProjectElement owner;
+       private List<SimulationContext> contex;
+       private List<Publication> docums;
+       private User actor; // Actor involved in operations on published documents and requiring a time-stamp
+
+       // ==============================================================================================================================
+       // Constructor
+       // ==============================================================================================================================
+
+       public Step(ProjectSettingsService.Step step, ProjectElement owner) {
+               // ----------------------------------------------------------------
+               this.step = step;
+               this.owner = owner;
+               this.contex = new Vector<SimulationContext>();
+               this.docums = new Vector<Publication>();
+               this.actor = null;
+
+               // Filtering of Simulation contexts, if exist
+               for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+                               .hasNext();) {
+                       SimulationContext adoc = i.next();
+                       if (!adoc.isInto(this))
+                               continue;
+                       this.contex.add(adoc);
+               }
+               // Filtering of Documents, if exist
+               for (Iterator<Publication> i = owner.PublicationIterator(); i.hasNext();) {
+                       Publication mydoc = i.next();
+                       if (!mydoc.value().isInto(this))
+                               continue;
+                       this.docums.add(mydoc);
+               }
+       }
 
-    public ProjectElement getOwner () {
-//  ---------------------------------
-      return owner;   // May be a Study or a Scenario
-    }
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
 
-    public Study getOwnerStudy () {
-//  -----------------------------
-      if (owner instanceof Study) return  (Study)owner;
-      else                        return ((Scenario)owner).getOwnerStudy();
-    }
+       public User getActor() {
+               // -----------------------
+               return actor;
+       }
 
-    public String getPath () {
-//  ------------------------
-      return step.getPath();
-    }
+       public List<Publication> getAllDocuments() {
+               // -------------------------------------------
+               return Collections.unmodifiableList(docums);
+       }
 
-    public List<Publication> getResultDocuments () {
-//  ----------------------------------------------
-      List<Publication> result = new Vector<Publication>();
-      
-      if (!docums.isEmpty()) for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
-       Publication  content = i.next();
-        DocumentType type    = content.value().getType();
-        if (!type.isResultOf(this.getStep())) continue;
-        result.add(content);
-         }
-      return result;
-    }
+       /**
+        * Get the persistent collection of step documents.
+        * @return the list of documents
+        */
+       public List<Publication> getDocuments() {
+               return docums;
+       }
 
-    public ProjectSettingsService.Step getStep () {
-//  --------------------------------------
-      return step;
-    }
+       public List<SimulationContext> getAllSimulationContexts() {
+               // ----------------------------------------------------------
+               return Collections.unmodifiableList(contex);
+       }
 
-    public SimulationContext getSimulationContext (long l) {
-//  ---------------------------------------------------------
-      for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
-        SimulationContext myctex = i.next();
-        if (myctex.getIndex() == l) return myctex;
-      }
-      return null;
-    }
+       public Publication getDocument(long l) {
+               // ------------------------------------------
+               for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+                       Publication found = i.next(); // In a given study step,
+                       if (found.value().getIndex() == l)
+                               return found; // there is only one publication of a given document
+               }
+               return null;
+       }
 
-    public List<SimulationContext> getSimulationContext (SimulationContextType type) {
-//  --------------------------------------------------------------------------------
-      Vector<SimulationContext> result = new Vector<SimulationContext>();
+       public int getNumber() {
+               // -----------------------
+               return step.getNumber();
+       }
 
-      for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
-        SimulationContext myctex = i.next();
-        if (myctex.getType().equals(type)) result.add(myctex);
-      }
-      return result;
-    }
+       public ProjectElement getOwner() {
+               // ---------------------------------
+               return owner; // May be a Study or a Scenario
+       }
 
-    public List<DocumentType> getValidDocumentTypes () {
-//  --------------------------------------------------
-      return Document.selectTypesOf(step);
-    }
+       public Study getOwnerStudy() {
+               // -----------------------------
+               if (owner instanceof Study)
+                       return (Study) owner;
+               else
+                       return ((Scenario) owner).getOwnerStudy();
+       }
 
-    public boolean isStarted () {
-//  ---------------------------
-      if (!step.mayContain(KnowledgeElement.class)) return !docums.isEmpty();
+       public String getPath() {
+               // ------------------------
+               return step.getPath();
+       }
 
-      List<KnowledgeElement> kelm = ((Scenario)owner).getAllKnowledgeElements();
-      if (kelm.isEmpty() && docums.isEmpty()) return false;
-      return true;
-    }
+       public List<Publication> getResultDocuments() {
+               // ----------------------------------------------
+               List<Publication> result = new Vector<Publication>();
+
+               if (!docums.isEmpty())
+                       for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+                               Publication content = i.next();
+                               DocumentType type = content.value().getType();
+                               if (!type.isResultOf(this.getStep()))
+                                       continue;
+                               result.add(content);
+                       }
+               return result;
+       }
 
-    public boolean isFinished () {
-//  ----------------------------
-      if (!step.mayContain(KnowledgeElement.class)) {   // Check if all result documents are approved
-        if (docums.isEmpty()) return false;
-        boolean result = false;
-        for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
-          Document     content = i.next().value();
-          DocumentType type    = content.getType();
-          if (!type.isResultOf(this.getStep())) continue;
-          if (content.getProgressState() == ProgressState.EXTERN) continue;
-          result = true;          // There is at least 1 non external result document
-          if (content.getProgressState() != ProgressState.APPROVED) return false;
-       }
-       return result;
-      }
-      else {                                            // Check if all existing knowledges are approved
-        List<KnowledgeElement> kelm  = ((Scenario)owner).getAllKnowledgeElements();
-        if (kelm.isEmpty()) return false;
-        for (Iterator<KnowledgeElement> i=kelm.iterator(); i.hasNext(); ) {
-                 KnowledgeElement  content = i.next();
-          if (content.getProgressState() != ProgressState.APPROVED) return false;
-               }
-        return true;
-      }
-    }
+       public ProjectSettingsService.Step getStep() {
+               // --------------------------------------
+               return step;
+       }
 
-    public boolean mayContain (@SuppressWarnings("rawtypes") Class type) {
-//  --------------------------------------------------------------------
-      return step.mayContain(type);
-    }
+       public SimulationContext getSimulationContext(long l) {
+               // ---------------------------------------------------------
+               for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+                               .hasNext();) {
+                       SimulationContext myctex = i.next();
+                       if (myctex.getIndex() == l)
+                               return myctex;
+               }
+               return null;
+       }
 
-    public boolean removeDocument (Publication doctag) {
-//  --------------------------------------------------
-      Document     value   = doctag.value();
-      Publication  torem   = getDocument(value.getIndex());
-      Session      session = Database.getSession();
+       public List<SimulationContext> getSimulationContext(
+                       SimulationContextType type) {
+               // --------------------------------------------------------------------------------
+               Vector<SimulationContext> result = new Vector<SimulationContext>();
+
+               for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+                               .hasNext();) {
+                       SimulationContext myctex = i.next();
+                       if (myctex.getType().equals(type))
+                               result.add(myctex);
+               }
+               return result;
+       }
 
-      if (torem == null)        return false;
+       public boolean isStarted() {
+               // ---------------------------
+               if (!step.mayContain(KnowledgeElement.class))
+                       return !docums.isEmpty();
 
-      this.remove(torem);
-      session.update(owner);
-      if (!value.isPublished() && !value.isVersioned()) {         // The referenced document is no more used
-       Set<Relation>  links = value.getAllRelations();
-       List<Document> using = new Vector<Document>();
-        for (Iterator<Relation> i=links.iterator(); i.hasNext(); ) {
-          Relation link = i.next();
-          if (link.getClass().equals(ConvertsRelation.class)) {   // File conversion
-           session.delete(link.getTo());                         // The corresponding physical file is not removed from the vault
-          } else
-          if (link.getClass().equals(UsesRelation.class)) {       // Document dependency
-               using.add((Document)link.getTo());
-          }
-        }
-        for (Iterator<Document> i=using.iterator(); i.hasNext(); ) {
-          i.next().removeRelation(UsedByRelation.class, value);
-        }
-       session.delete(value);                              // The corresponding physical file is not removed from the vault
-      }
-      return true;
-    }
+               List<KnowledgeElement> kelm = ((Scenario) owner)
+                               .getAllKnowledgeElements();
+               if (kelm.isEmpty() && docums.isEmpty())
+                       return false;
+               return true;
+       }
 
-    public void setActor (User user) {
-//  --------------------------------
-      actor = user;
-    }
-//  ==============================================================================================================================
-//  Protected member functions
-//  ==============================================================================================================================
+       public boolean isFinished() {
+               // ----------------------------
+               if (!step.mayContain(KnowledgeElement.class)) { // Check if all result documents are approved
+                       if (docums.isEmpty())
+                               return false;
+                       boolean result = false;
+                       for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+                               Document content = i.next().value();
+                               DocumentType type = content.getType();
+                               if (!type.isResultOf(this.getStep()))
+                                       continue;
+                               if (content.getProgressState() == ProgressState.EXTERN)
+                                       continue;
+                               result = true; // There is at least 1 non external result document
+                               if (content.getProgressState() != ProgressState.APPROVED)
+                                       return false;
+                       }
+                       return result;
+               } else { // Check if all existing knowledges are approved
+                       List<KnowledgeElement> kelm = ((Scenario) owner)
+                                       .getAllKnowledgeElements();
+                       if (kelm.isEmpty())
+                               return false;
+                       for (Iterator<KnowledgeElement> i = kelm.iterator(); i.hasNext();) {
+                               KnowledgeElement content = i.next();
+                               if (content.getProgressState() != ProgressState.APPROVED)
+                                       return false;
+                       }
+                       return true;
+               }
+       }
 
-    public boolean add (Publication newdoc) {
-//  ------------------------------------------
-      if (!owner.add(newdoc)) return false;   // Updates the study in memory
-      docums.add(0, newdoc);                  // Updates this step
-      newdoc.value().hold();                  // Increments the configuration tag count of document
-//    If not yet saved, the Publication MUST NOT be saved here, although this creates a temporary inconsistent state into the
-//    database (it will be saved later by cascading the update of owner scenario).    
-      return true;
-    }
+       public boolean mayContain(@SuppressWarnings("rawtypes")
+       Class type) {
+               return step.mayContain(type);
+       }
 
-    public boolean remove (Publication oldoc) {
-//  --------------------------------------------
-      if (!owner.remove(oldoc)) return false; // Updates the study in memory
-      docums.remove(oldoc);                   // Updates this step
-      oldoc.value().release();                // Decrements the configuration tag count of document
-//    The publication becoming orphan, it should automatically be removed from the database when updating of owner scenario.
-      return true;
-    }
+       public void setActor(User user) {
+               actor = user;
+       }
 
-    public List<SimulationContext> getContex() {
+       public List<SimulationContext> getContex() {
                return contex;
        }
 
index 6a07bc88cd99b85254c12f209560a96f4130aca8..22f462b11621098d4d4007d52007aa5fd264af9a 100644 (file)
@@ -11,18 +11,14 @@ import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.Study;
+import org.splat.service.ServiceLocatorImpl;
 
 
 public class StepRights {
 
     private User     user;
     private Step     operand;
-
-//  ==============================================================================================================================
-//  Construction
-//  ==============================================================================================================================
-
-    public StepRights (User user, Step step) {
+       public StepRights (User user, Step step) {
 //  ----------------------------------------
       this.user    = user;
       this.operand = step;
@@ -46,7 +42,7 @@ public class StepRights {
     public boolean canAddComment () {
 //  -------------------------------
       Study   owner = operand.getOwnerStudy();
-      return (owner.getAuthor().equals(user) || owner.hasActor(user));
+      return (owner.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, user));
     }
 
 /**
@@ -58,7 +54,7 @@ public class StepRights {
     public boolean canCreateDocument () {
 //  -----------------------------------
       if (!isEnabled()) return false;
-      return operand.getOwnerStudy().isStaffedBy(user);
+      return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand.getOwnerStudy(), user);
     }
 
 /**
@@ -69,7 +65,7 @@ public class StepRights {
  */
     public boolean canCreateKnowledge () {
 //  ------------------------------------
-      return operand.getOwnerStudy().isStaffedBy(user);
+      return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand.getOwnerStudy(), user);
     }
 
 /**
@@ -81,7 +77,7 @@ public class StepRights {
     public boolean canEditSimulationContext () {
 //  ------------------------------------------
       Study   owner = operand.getOwnerStudy();
-      return (owner.getAuthor().equals(user) || owner.hasActor(user));
+      return (owner.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, user));
     }
 
 /**
index 2d98eca8209b7024d1eb1cd1b25fa5a8e31306de..f83bf9b67f63bfadc3df804f7de9925afc360dfe 100644 (file)
@@ -11,6 +11,7 @@ package org.splat.som;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.Study;
+import org.splat.service.ServiceLocatorImpl;
 
 
 public class StudyRights {
@@ -18,12 +19,7 @@ public class StudyRights {
     private User     user;
     private Study    operand;
     private boolean  author = false;                    // For optimizing 
-
-//  ==============================================================================================================================
-//  Construction
-//  ==============================================================================================================================
-
-    public StudyRights (User user, Study study) {
+       public StudyRights (User user, Study study) {
 //  -------------------------------------------
       this.user    = user;
       this.operand = study;
@@ -43,7 +39,7 @@ public class StudyRights {
     public boolean canAddScenario () {
 //  --------------------------------
       if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
-      return operand.isStaffedBy(user);
+      return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand, user);
     }
 
 /**
@@ -54,7 +50,7 @@ public class StudyRights {
  */
     public boolean canEditDescription () {
 //  ------------------------------------
-      return (operand.getAuthor().equals(user) || operand.hasActor(user));
+      return (operand.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(operand, user));
     }
 
     public boolean canEditProperties () {
@@ -89,7 +85,7 @@ public class StudyRights {
     public boolean canVersion () {
 //  ----------------------------
       if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
-      return operand.isStaffedBy(user);
+      return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand, user);
     }
 
 //  ==============================================================================================================================
index bc565a0970f635ae912cc89ef2d36809efb9f37a..167d41701ea497b8d1b2a3ecddce42a8dc5359d3 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
index 00cdf22e467fb9ee4f1996ffc9ef5afd4e0cd61f..0104fec0c76d7becf53e3b860fe42980488b6f78 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
index ef9f2c871c36b62e83177c6fa5c71159085b8671..0c19c45c4aa500ae9619c283631ab22a0cc5febd 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   05.10.2012
index 4592bf74c535b64e99c6da30dd1754f0ddb10c10..53680253214486f970ef9bd59f53d91761e6d23a 100644 (file)
@@ -11,6 +11,12 @@ http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
+       <bean id="serviceLocator"
+               class="org.splat.service.ServiceLocatorImpl"
+               factory-method="getInstance">
+               <property name="studyService" ref="studyService" />
+       </bean>
+
        <bean id="projectElementService"
                class="org.splat.service.ProjectElementServiceImpl">
                <property name="projectSettings" ref="projectSettings" />
@@ -18,30 +24,41 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
        <bean id="documentTypeService"
                class="org.splat.service.DocumentTypeServiceImpl">
-               <property name="projectSettings" ref="projectSettings" />
+               <property name="documentTypeDAO" ref="documentTypeDAO" />
        </bean>
 
        <bean id="documentService"
                class="org.splat.service.DocumentServiceImpl">
                <property name="projectSettings" ref="projectSettings" />
                <property name="studyService" ref="studyService" />
-        <property name="documentDAO" ref="documentDAO" />
-        <property name="repositoryService" ref="repositoryService" />
+               <property name="documentDAO" ref="documentDAO" />
+               <property name="documentTypeDAO" ref="documentTypeDAO" />
+               <property name="repositoryService" ref="repositoryService" />
+               <property name="fileDAO" ref="fileDAO" />
        </bean>
 
        <bean id="knowledgeElementService"
                class="org.splat.service.KnowledgeElementServiceImpl">
                <property name="indexService" ref="indexService" />
                <property name="knowledgeElementDAO" ref="knowledgeElementDAO" />
+               <property name="studyService" ref="studyService" />
+       </bean>
+
+       <bean id="knowledgeElementTypeService"
+               class="org.splat.service.KnowledgeElementTypeServiceImpl">
+               <property name="knowledgeElementTypeDAO"
+                       ref="knowledgeElementTypeDAO" />
        </bean>
 
        <bean id="publicationService"
                class="org.splat.service.PublicationServiceImpl">
-               <property name="documentTypeService" ref="documentTypeService" />
+               <property name="documentService" ref="documentService" />
                <property name="projectElementService"
                        ref="projectElementService" />
                <property name="stepService" ref="stepService" />
                <property name="studyService" ref="studyService" />
+               <property name="publicationDAO" ref="publicationDAO" />
+               <property name="projectElementDAO" ref="projectElementDAO" />
        </bean>
 
        <bean id="scenarioService"
@@ -51,8 +68,11 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                        ref="projectElementService" />
                <property name="publicationService" ref="publicationService" />
                <property name="stepService" ref="stepService" />
+               <property name="studyService" ref="studyService" />
                <property name="knowledgeElementDAO" ref="knowledgeElementDAO" />
-        <property name="scenarioDAO" ref="scenarioDAO" />
+               <property name="scenarioDAO" ref="scenarioDAO" />
+               <property name="knowledgeElementTypeService"
+                       ref="knowledgeElementTypeService" />
        </bean>
 
        <bean id="searchService"
@@ -63,14 +83,15 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
        <bean id="stepService" class="org.splat.service.StepServiceImpl">
                <property name="indexService" ref="indexService" />
-        <property name="documentDAO" ref="documentDAO" />
-        <property name="documentService" ref="documentService" />
-        <property name="simulationContextService"
-            ref="simulationContextService" />
-        <property name="simulationContextDAO"
-            ref="simulationContextDAO" />
-        <property name="projectElementDAO"
-            ref="projectElementDAO" />
+               <property name="documentDAO" ref="documentDAO" />
+               <property name="fileDAO" ref="fileDAO" />
+               <property name="documentService" ref="documentService" />
+               <property name="documentTypeService" ref="documentTypeService" />
+               <property name="simulationContextService"
+                       ref="simulationContextService" />
+               <property name="simulationContextDAO"
+                       ref="simulationContextDAO" />
+               <property name="projectElementDAO" ref="projectElementDAO" />
        </bean>
 
        <bean id="simulationContextService"
@@ -87,12 +108,15 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="projectElementService"
                        ref="projectElementService" />
                <property name="projectSettings" ref="projectSettings" />
-               <property name="scenarioService" ref="scenarioService" />
                <property name="stepService" ref="stepService" />
                <property name="studyDAO" ref="studyDAO" />
                <property name="scenarioDAO" ref="scenarioDAO" />
-        <property name="IDBuilderDAO" ref="iDBuilderDAO" />
-        <property name="validationCycleDAO" ref="validationCycleDAO" />
+               <property name="IDBuilderDAO" ref="iDBuilderDAO" />
+               <property name="validationCycleDAO" ref="validationCycleDAO" />
+               <property name="documentTypeService" ref="documentTypeService" />
        </bean>
 
+       <bean id="userRights" abstract="true" scope="session">
+               <property name="studyService" ref="studyService" />
+       </bean>
 </beans>
\ No newline at end of file
index 2e17609a083f0ff1964032efe14c9bb2fcfee354..2c368a54e59ada6f4faac38d8fc2be9aec647af4 100644 (file)
@@ -16,8 +16,12 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
        <bean id="projectSettings"
                class="org.splat.service.technical.ProjectSettingsServiceImpl">
-        <property name="database" ref="database" />
-        <property name="simulationContextService" ref="simulationContextService" />
+               <property name="database" ref="database" />
+               <property name="simulationContextService"
+                       ref="simulationContextService" />
+               <property name="documentTypeService" ref="documentTypeService" />
+               <property name="knowledgeElementTypeService"
+                       ref="knowledgeElementTypeService" />
        </bean>
 
        <bean id="indexService"
index 74dee2ee8d6e65de188b70427f080a651822fde8..2cdcff0fb7b2a678947aa6b2283ff9c7b4694eb7 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   12 Oct 2012
index c9fe7dd4b2e2b39def5bd92d569a25b902c7d5d3..6af2cde2479e6ee8dd4e2e95f67062134182caf7 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   12 Oct 2012
index d5dcbde2c20b3d9ea6ba5f5ccb9160aa2d0a093c..77ede0c2ed385391b3556115af9795ecce2c8262 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Company         EURIWARE
+ * Company         OPEN CASCADE
  * Application     SIMAN
  * File            $Id$ 
  * Creation date   12 Oct 2012
index a534902b1aefc45cb2979bb862d475de690cd774..f0920aa666620d6ba1fa6280b560feea8060832a 100644 (file)
@@ -11,6 +11,7 @@ import org.hibernate.Session;
 import org.hibernate.Transaction;
 import org.splat.kernel.Do;
 import org.splat.dal.bo.kernel.User;
+import org.splat.service.DocumentTypeService;
 import org.splat.service.PublicationService;
 import org.splat.service.ScenarioService;
 import org.splat.service.SimulationContextService;
@@ -58,6 +59,10 @@ public class SaveDocumentAction extends Action {
         * Injected step service.
         */
        private StepService _stepService;
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
        /**
         * Injected repository service.
         */
@@ -80,11 +85,11 @@ public class SaveDocumentAction extends Action {
                        mystudy = getOpenStudy();
                        User user = getConnectedUser();
                        Step step = mystudy.getSelectedStep();
-                       DocumentType type = Document.selectType(doctype);
+                       DocumentType type = getDocumentTypeService().selectType(doctype);
                        // File updir = Database.getDownloadDirectory(user);
                        // File upfile = new File(updir.getPath() + "/" + filename);
                        String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
-                                                                                                                                               // between users
+                       // between users
                        File upfile = new File(upath + filename);
                        String[] table = filename.split("\\x2E");
                        String format = table[table.length - 1];
@@ -120,7 +125,8 @@ public class SaveDocumentAction extends Action {
                        // 1. Conversion of the document to internal format, if required
                        // TODO: The following code is temporary, waiting for the support of converters
                        if (format.equals("part")) {
-                               ConvertsRelation export = credoc.attach("brep");
+                               ConvertsRelation export = getPublicationService().attach(
+                                               credoc, "brep");
 
                                target = export.getTo().asFile();
                                if (target.exists())
@@ -253,7 +259,7 @@ public class SaveDocumentAction extends Action {
                        // File updir = Database.getDownloadDirectory(user);
                        // File upfile = new File(updir.getPath() + "/" + filename);
                        String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
-                                                                                                                                               // between users
+                       // between users
                        File upfile = new File(upath + filename);
                        String[] table = filename.split("\\x2E");
                        String format = table[table.length - 1];
@@ -291,7 +297,8 @@ public class SaveDocumentAction extends Action {
                        // 1. Conversion of the document to internal format, if required
                        // TODO: The following code is temporary, waiting for the support of converters
                        if (format.equals("part")) {
-                               ConvertsRelation export = next.attach("brep");
+                               ConvertsRelation export = getPublicationService().attach(next,
+                                               "brep");
                                String fname = table[0];
 
                                for (int i = 1; i < table.length - 1; i++)
@@ -409,4 +416,23 @@ public class SaveDocumentAction extends Action {
                        SimulationContextService simulationContextService) {
                _simulationContextService = simulationContextService;
        }
+
+       /**
+        * Get the documentTypeService.
+        * 
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * 
+        * @param documentTypeService
+        *            the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
 }
\ No newline at end of file
index ebf3e06d37f7c1b69bbe53ba653c5d2fcfab8a08..0707ca507f6d00cf31b3ac49e3a68780bb90195f 100644 (file)
@@ -27,6 +27,7 @@ import org.splat.som.DocumentRights;
 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.DocumentTypeService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.som.Step;
@@ -37,710 +38,902 @@ import org.splat.wapp.PopupItem;
 import org.splat.wapp.SimpleMenu;
 import org.splat.wapp.ToolBar;
 
-
 public class ApplicationSettings {
 
-    private  String                            wappserver;
-    private  String                            wappname;
-       private  Properties                        wapprops;                 // General properties from the application properties files
-       private  Locale                            locale;                   // Current user locale
-    private  Map<String,SimpleMenu>            menus      = null;        // Application menus
-    private  Map<Integer,ToolBar>              bars       = null;        // Study module-bars structured by steps
-    private  Map<String,PopupMenu>             popups     = null;
-    private  Map<String,Map<String,Object>>    filter     = null;        // Named search filters
-       private  Map<String,DocumentType>          defdoctype = null;        // Default document types structured by step.formats
-    private  Map<String,String>                tempfile   = null;        // Available template files
-    private  String[]                          viewermap  = null;        // List of file extensions mapped to a viewer
-    private  Map<String,Converter>             convertmap = null;        // Available document format converters
-    private  Properties                        jndprops   = null;        // JNDI context for launching converters
-
-       private         static ApplicationSettings my         = null;        // Singleton instance
        /**
         * Application settings logger.
         */
-    protected final static Logger              logger     = Logger.getLogger(ApplicationSettings.class);
-
+       protected final static Logger logger = Logger
+                       .getLogger(ApplicationSettings.class);
+
+       private String wappserver;
+       private String wappname;
+       private Properties wapprops; // General properties from the application properties files
+       private Locale locale; // Current user locale
+       private Map<String, SimpleMenu> menus = null; // Application menus
+       private Map<Integer, ToolBar> bars = null; // Study module-bars structured by steps
+       private Map<String, PopupMenu> popups = null;
+       private Map<String, Map<String, Object>> filter = null; // Named search filters
+       private Map<String, DocumentType> defdoctype = null; // Default document types structured by step.formats
+       private Map<String, String> tempfile = null; // Available template files
+       private String[] viewermap = null; // List of file extensions mapped to a viewer
+       private Map<String, Converter> convertmap = null; // Available document format converters
+       private Properties jndprops = null; // JNDI context for launching converters
+
+       private static ApplicationSettings my = null; // Singleton instance
        /**
         * Injected project settings service.
         */
-    private ProjectSettingsService _projectSettingsService;
+       private ProjectSettingsService _projectSettingsService;
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
 
        /**
         * Get the projectSettingsService.
+        * 
         * @return the projectSettingsService
         */
        public ProjectSettingsService getProjectSettings() {
                return _projectSettingsService;
        }
+
        /**
         * Set the projectSettingsService.
-        * @param projectSettingsService the projectSettingsService to set
+        * 
+        * @param projectSettingsService
+        *            the projectSettingsService to set
         */
-       public void setProjectSettings(
-                       ProjectSettingsService projectSettingsService) {
+       public void setProjectSettings(ProjectSettingsService projectSettingsService) {
                _projectSettingsService = projectSettingsService;
        }
 
-       private   static class NewMenu                 extends SimpleMenu {
-//  -----------------------------------------------------------------
-      private NewMenu ()
-      {
-        super("create"); 
-        addItem("new-empty", "menu.new.empty", "image.empty.png", "select?menu=create&item=new-empty");
-        addItem("new-copy",     new MenuItem("menu.new.copy").icon("image.copy.png") );
-        addItem("new-instance", new MenuItem("menu.new.instance").icon("image.hold.gif") );
-        addItem("new-import",   new MenuItem("menu.new.import").icon("icon.upload.png") );
-        this.selects("new-empty");
-      }
-       }
-       private   static class SearchMenu              extends SimpleMenu {
-//  -----------------------------------------------------------------
-      private SearchMenu ()
-      {
-        super("search");
-        addItem("search-study",     "menu.search.study", "image.study.png", "select?menu=search&item=search-study");
-        addItem("search-knowledge", "menu.search.idea",  "image.idea.png",  "select?menu=search&item=search-knowledge");
-        addItem("search-document", new MenuItem("menu.search.document").icon("icon.any.png") );
-        this.selects("search-study");
-      }
-       }
-    private   static class PropertiesMenu          extends SimpleMenu {
-//  -----------------------------------------------------------------
-      private PropertiesMenu ()
-      {
-        super("configuration");
-        addItem("prop-general",  "menu.prop.general",  "image.hold.gif", "select?menu=properties&item=prop-general");
-        addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif", "select?menu=properties&item=prop-scenario");
-        addItem("prop-timestamp", new MenuItem("menu.prop.timestamp").icon("image.stamp.png") );
-        addItem("prop-comlog",    new MenuItem("menu.prop.comlog").icon("image.hold.gif") );
-        addItem("prop-version",   new MenuItem("menu.prop.version").icon("image.dirclosed.png") );
-      }
-    }
-       private   static class DatadminMenu            extends SimpleMenu {
-//  -----------------------------------------------------------------
-         private DatadminMenu ()
-         {
-               super("datadmin");
-        addItem("admin-scontext", "menu.admin.context",   "image.hold.gif", "select?menu=datadmin&item=admin-scontext");
-        addItem("admin-knowelm",  "menu.admin.knowledge", "image.idea.png", "select?menu=datadmin&item=admin-knowelm");
-        addItem("admin-study", new MenuItem("menu.admin.study").icon("image.study.png") );
-         }
-       }
-       private   static class SysadminMenu            extends SimpleMenu {
-//  -----------------------------------------------------------------
-      private SysadminMenu ()
-      {
-        super("sysadmin");
-        addItem("admin-indexing",   "menu.admin.indexing",   "image.index.png", "select?menu=sysadmin&item=admin-indexing");
-        addItem("admin-importuser", "menu.admin.importuser", "image.group.png", "select?menu=sysadmin&item=admin-importuser");
-      }
-       }
-       private          enum  Item { publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge };
-//  Resources relative to studies
-    private   static class EditableStudyPopup      extends PopupMenu {
-//  ----------------------------------------------------------------
-      private StudyRights  user = null;
-
-      private EditableStudyPopup ()
-      {
-        addItem("publish", new PopupItem("menu.publish").icon("image.publish.png").action("edit-study?action=publish").confirmation("message.publish.study"));
-        addItem("promote", new PopupItem("menu.archive"));
-        addSeparator();
-        addItem("edit",    new PopupItem("menu.properties").icon("icon.ed.png").action("../select?menu=properties"));
-        addSeparator();
-        addItem("script",  new PopupItem("menu.newscenario").action("add-scenario"));
-       addItem("version", new PopupItem("menu.version").icon("image.version.png").action("notyetimplemented"));
-        addSeparator();
-        addItem("purge",   new PopupItem("menu.purge").confirmation("message.purge.study"));
-        addItem("export",  new PopupItem("menu.export").icon("image.export.png"));   // For future needs
-        addItem("remove",  new PopupItem("menu.remove.version").icon("icon.delete.png").action("notyetimplemented").confirmation("message.delete.study"));
-      }
-      public boolean isEnabled (String name)
-      {
-        if (user == null) return false;      // Should not happen
-        Item item =  Item.valueOf(name);
-        if  (item == Item.publish) return user.canPublish();
-        if  (item == Item.edit)    return user.canEditProperties();
-        if  (item == Item.script)  return user.canAddScenario();
-        if  (item == Item.version) return user.canVersion();
-        if  (item == Item.remove)  return user.canRemove();
-        if  (item == Item.purge)   return user.canPurge();
-        return false;
-      }
-      public void setContext (String name, Object context)
-      {
-        if (context instanceof StudyRights) {
-          user = (StudyRights)context;          // Just for optimizing
-          boolean       history = user.getOperand().isVersioned();
-          PopupItem     item    = this.item("remove");
-          if (history) item.rename("menu.remove.version");
-          else         item.rename("menu.remove.study");
-        }
-      }
-    }
-//  Resources relative to documents
-       private   static class EditableDocumentPopup   extends PopupMenu {   // Popup of In-Work documents
-//  ----------------------------------------------------------------
-      private DocumentRights  user = null;
-
-      private EditableDocumentPopup ()
-      {
-        addItem("accept",  new PopupItem("menu.accept").icon("image.accept.png").action("setDocument?action=accept").confirmation("message.accept.document"));
-               addItem("promote", new PopupItem("menu.promote").icon("image.publish.png").action("setDocument?action=promote").confirmation("message.promote.document"));
-        addSeparator();
-        addItem("rename",  new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
-        addItem("attach",  new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
-        addSeparator();
-       addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
-        addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
-        addSeparator();
-        addItem("purge",   new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
-        addItem("remove",  new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
-      }
-      public boolean isEnabled (String name)
-      {
-        if (user == null) return false;      // Should not happen
-        Item item =  Item.valueOf(name);
-        if  (item == Item.accept)  return user.canAccept();
-        if  (item == Item.promote) return user.canPromote();
-        if  (item == Item.rename)  return user.canRename();
-        if  (item == Item.attach)  return user.canAttach();
-        if  (item == Item.version) return user.canVersion();
-        if  (item == Item.replace) return user.canReplace();
-        if  (item == Item.purge)   return user.canPurge();
-        if  (item == Item.remove)  return user.canRemove();
-        return false;
-      }
-      public void setContext (String name, Object context)
-      {
-        if (context instanceof DocumentRights) {
-          user = (DocumentRights)context;       // Just for optimizing
-          Document downer = user.getOperand();
-          PopupItem  item = this.item("remove");
-          if (downer.isVersioned()) item.rename("menu.remove.version");
-          else                      item.rename("menu.remove.document");
-        }
-      }
-       }
-       private   static class ReviewableDocumentPopup extends PopupMenu {   // Popup of In-Draft documents
-//  ----------------------------------------------------------------
-      private DocumentRights  user = null;
-
-      private ReviewableDocumentPopup ()
-      {
-        addItem("demote",  new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
-               addItem("promote", new PopupItem("menu.review").icon("image.review.png").action("setDocument?action=review").confirmation("message.review.document"));
-        addSeparator();
-        addItem("attach",  new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
-        addSeparator();
-       addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
-        addSeparator();
-        addItem("purge",   new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
-      }
-      public boolean isEnabled (String name)
-      {
-        if (user == null) return false;      // Should not happen
-        Item item =  Item.valueOf(name);
-        if  (item == Item.demote)  return user.canDemote();
-        if  (item == Item.promote) return user.canReview();
-        if  (item == Item.attach)  return user.canAttach();
-        if  (item == Item.version) return user.canVersion();
-        if  (item == Item.purge)   return user.canPurge();
-        return false;
-      }
-      public void setContext (String name, Object context)
-      {
-        if (context instanceof DocumentRights) {
-          user = (DocumentRights)context;       // Just for optimizing
-        }
-      }
-       }
-       private   static class NotResultDocumentPopup  extends PopupMenu {
-//  ----------------------------------------------------------------
-      private DocumentRights  user = null;
-
-      private NotResultDocumentPopup ()
-      {
-        addItem("demote",  new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
-        addSeparator();
-        addItem("attach",  new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
-        addSeparator();
-       addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
-        addSeparator();
-        addItem("purge",   new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
-        addItem("remove",  new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
-      }
-       }
-    private   static class ApprovableDocumentPopup extends PopupMenu {   // Popup of In-Check documents
-//  ----------------------------------------------------------------
-      private DocumentRights  user = null;
-
-      private ApprovableDocumentPopup ()
-      {
-        addItem("undo",    new PopupItem("menu.demote").icon("image.invalidate.png").action("setDocument?action=invalidate").confirmation("message.demote.document"));
-        addItem("demote",  new PopupItem("menu.disapprove").icon("image.demote.png").action("setDocument?action=disapprove").confirmation("message.disapprove.document"));
-        addItem("approve", new PopupItem("menu.approve").icon("icon.APPROVED.png").action("setDocument?action=approve").confirmation("message.approve.document"));
-      }
-      public boolean isEnabled (String name)
-      {
-        if (user == null) return false;      // Should not happen
-        Item item =  Item.valueOf(name);
-        if  (item == Item.undo)    return user.canInvalidate();
-        if  (item == Item.demote)  return user.canDemote(); 
-        if  (item == Item.approve) return user.canApprove();
-        return false;
-      }
-      public void setContext (String name, Object context)
-      {
-        if (context instanceof DocumentRights) {
-          user = (DocumentRights)context;       // Just for optimizing
-        }
-      }
-    }
-    private   static class ApprovedPopup           extends PopupMenu {   // Popup of Approved documents
-//  ----------------------------------------------------------------
-      private ApprovedPopup ()
-      {
-        addItem("attach",  new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
-        addSeparator();
-        addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
-      }
-    }
-    private   static class ExternPopup             extends PopupMenu {   // Popup of Extern documents
-//  ----------------------------------------------------------------
-      private DocumentRights  user = null;
-
-      private ExternPopup ()
-      {
-        addItem("rename",  new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
-        addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
-        addSeparator();
-        addItem("remove",  new PopupItem("menu.remove.document").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
-      }
-      public boolean isEnabled (String name)
-      {
-        if (user == null) return false;      // Should not happen
-        Item item =  Item.valueOf(name);
-        if  (item == Item.rename)  return user.canRename();
-        if  (item == Item.replace) return user.canReplace();
-        if  (item == Item.remove)  return user.canRemove();
-        return false;
-      }
-      public void setContext (String name, Object context)
-      {
-        if (context instanceof DocumentRights) {
-          user = (DocumentRights)context;          // Just for optimizing
-        }
-      }
-    }
-//  Resources relative to simulation contexts
-    private   static class ScontextPopup   extends PopupMenu {
-//  --------------------------------------------------------
-      private SimulationContextFacade owner = null;
-
-      private ScontextPopup ()
-      {
-        addItem("rename",  new PopupItem("menu.rename").action("edit-context?action=renameContext"));
-        addItem("edit",    new PopupItem("menu.edit").action("edit-context?action=editContext"));
-        addSeparator();
-        addItem("remove",  new PopupItem("menu.remove").icon("icon.delete.png").action("remove-context").confirmation("message.delete.context"));
-      }
-      public boolean isEnabled (String name)
-      {
-        Item  item = Item.valueOf(name);
-
-        if (item == Item.rename) {
-          return false;
-        } else
-        if (item == Item.edit) {
-//        if (!owner.isEditable())
-            return false;
-        }
-        return true;
-      }
-      public void setContext (String name, Object context)
-      {
-        if (context instanceof SimulationContextFacade) {
-          owner = (SimulationContextFacade)context;   // Just for optimizing
-        }
-        else {
-          super.setContext(name, context);
-        }
-      }
-    }
-//  Resources relative to knowledge
-       private   static class FeedbexPopup    extends PopupMenu {
-//  --------------------------------------------------------
-      private KnowledgeElement  owner = null;
-
-      private FeedbexPopup ()
-      {
-        addItem("promote", new PopupItem("menu.promote").icon("image.review.png").action("promote-knowledge").confirmation("message.promote.knowledge"));
-        addItem("demote",  new PopupItem("menu.demote").icon("image.invalidate.png").action("demote-knowledge").confirmation("message.demote.knowledge"));
-        addSeparator();
-        addItem("rename",  new PopupItem("menu.rename").action("edit-knowledge?action=renameKnowledge"));
-        addItem("edit",    new PopupItem("menu.edit").action("edit-knowledge?action=editKnowledge"));
-        addSeparator();
-        addItem("remove",  new PopupItem("menu.remove").icon("icon.delete.png").action("remove-knowledge").confirmation("message.delete.knowledge"));
-      }
-      public boolean isEnabled (String name)
-      {
-        Item  item = Item.valueOf(name);
-
-        if (item == Item.promote) {
-          if (owner.getProgressState() != ProgressState.inDRAFT) return false;
-        } else
-        if (item == Item.demote) {
-          if (owner.getProgressState() != ProgressState.inCHECK) return false;
-        }
-        return true;
-      }
-      public void setContext (String name, Object context)
-      {
-        if (context instanceof KnowledgeElement) owner = (KnowledgeElement)context;   // Just for optimizing
-        else {
-          super.setContext(name, context);
-        }
-      }
-       }
-
-//  ==============================================================================================================================
-//  Construction
-//  ==============================================================================================================================
-
-    public static ApplicationSettings getMe () {
-//  ------------------------------------------
-      return my;                                  // The application is supposed being previously created below
-    }
+       private static class NewMenu extends SimpleMenu {
+               // -----------------------------------------------------------------
+               private NewMenu() {
+                       super("create");
+                       addItem("new-empty", "menu.new.empty", "image.empty.png",
+                                       "select?menu=create&item=new-empty");
+                       addItem("new-copy", new MenuItem("menu.new.copy")
+                                       .icon("image.copy.png"));
+                       addItem("new-instance", new MenuItem("menu.new.instance")
+                                       .icon("image.hold.gif"));
+                       addItem("new-import", new MenuItem("menu.new.import")
+                                       .icon("icon.upload.png"));
+                       this.selects("new-empty");
+               }
+       }
+
+       private static class SearchMenu extends SimpleMenu {
+               // -----------------------------------------------------------------
+               private SearchMenu() {
+                       super("search");
+                       addItem("search-study", "menu.search.study", "image.study.png",
+                                       "select?menu=search&item=search-study");
+                       addItem("search-knowledge", "menu.search.idea", "image.idea.png",
+                                       "select?menu=search&item=search-knowledge");
+                       addItem("search-document", new MenuItem("menu.search.document")
+                                       .icon("icon.any.png"));
+                       this.selects("search-study");
+               }
+       }
+
+       private static class PropertiesMenu extends SimpleMenu {
+               // -----------------------------------------------------------------
+               private PropertiesMenu() {
+                       super("configuration");
+                       addItem("prop-general", "menu.prop.general", "image.hold.gif",
+                                       "select?menu=properties&item=prop-general");
+                       addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif",
+                                       "select?menu=properties&item=prop-scenario");
+                       addItem("prop-timestamp", new MenuItem("menu.prop.timestamp")
+                                       .icon("image.stamp.png"));
+                       addItem("prop-comlog", new MenuItem("menu.prop.comlog")
+                                       .icon("image.hold.gif"));
+                       addItem("prop-version", new MenuItem("menu.prop.version")
+                                       .icon("image.dirclosed.png"));
+               }
+       }
+
+       private static class DatadminMenu extends SimpleMenu {
+               // -----------------------------------------------------------------
+               private DatadminMenu() {
+                       super("datadmin");
+                       addItem("admin-scontext", "menu.admin.context", "image.hold.gif",
+                                       "select?menu=datadmin&item=admin-scontext");
+                       addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
+                                       "select?menu=datadmin&item=admin-knowelm");
+                       addItem("admin-study", new MenuItem("menu.admin.study")
+                                       .icon("image.study.png"));
+               }
+       }
+
+       private static class SysadminMenu extends SimpleMenu {
+               // -----------------------------------------------------------------
+               private SysadminMenu() {
+                       super("sysadmin");
+                       addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
+                                       "select?menu=sysadmin&item=admin-indexing");
+                       addItem("admin-importuser", "menu.admin.importuser",
+                                       "image.group.png",
+                                       "select?menu=sysadmin&item=admin-importuser");
+               }
+       }
+
+       private enum Item {
+               publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge
+       };
+
+       // Resources relative to studies
+       private static class EditableStudyPopup extends PopupMenu {
+               // ----------------------------------------------------------------
+               private StudyRights user = null;
+
+               private EditableStudyPopup() {
+                       addItem("publish", new PopupItem("menu.publish").icon(
+                                       "image.publish.png").action("edit-study?action=publish")
+                                       .confirmation("message.publish.study"));
+                       addItem("promote", new PopupItem("menu.archive"));
+                       addSeparator();
+                       addItem("edit", new PopupItem("menu.properties")
+                                       .icon("icon.ed.png").action("../select?menu=properties"));
+                       addSeparator();
+                       addItem("script", new PopupItem("menu.newscenario")
+                                       .action("add-scenario"));
+                       addItem("version", new PopupItem("menu.version").icon(
+                                       "image.version.png").action("notyetimplemented"));
+                       addSeparator();
+                       addItem("purge", new PopupItem("menu.purge")
+                                       .confirmation("message.purge.study"));
+                       addItem("export", new PopupItem("menu.export")
+                                       .icon("image.export.png")); // For future needs
+                       addItem("remove", new PopupItem("menu.remove.version").icon(
+                                       "icon.delete.png").action("notyetimplemented")
+                                       .confirmation("message.delete.study"));
+               }
+
+               public boolean isEnabled(String name) {
+                       if (user == null)
+                               return false; // Should not happen
+                       Item item = Item.valueOf(name);
+                       if (item == Item.publish)
+                               return user.canPublish();
+                       if (item == Item.edit)
+                               return user.canEditProperties();
+                       if (item == Item.script)
+                               return user.canAddScenario();
+                       if (item == Item.version)
+                               return user.canVersion();
+                       if (item == Item.remove)
+                               return user.canRemove();
+                       if (item == Item.purge)
+                               return user.canPurge();
+                       return false;
+               }
+
+               public void setContext(String name, Object context) {
+                       if (context instanceof StudyRights) {
+                               user = (StudyRights) context; // Just for optimizing
+                               boolean history = user.getOperand().isVersioned();
+                               PopupItem item = this.item("remove");
+                               if (history)
+                                       item.rename("menu.remove.version");
+                               else
+                                       item.rename("menu.remove.study");
+                       }
+               }
+       }
+
+       // Resources relative to documents
+       private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
+       // ----------------------------------------------------------------
+               private DocumentRights user = null;
+
+               private EditableDocumentPopup() {
+                       addItem("accept", new PopupItem("menu.accept").icon(
+                                       "image.accept.png").action("setDocument?action=accept")
+                                       .confirmation("message.accept.document"));
+                       addItem("promote", new PopupItem("menu.promote").icon(
+                                       "image.publish.png").action("setDocument?action=promote")
+                                       .confirmation("message.promote.document"));
+                       addSeparator();
+                       addItem("rename", new PopupItem("menu.rename")
+                                       .action("edit-document?action=renameDocument"));
+                       addItem("attach", new PopupItem("menu.attach").icon(
+                                       "image.attach.png").action("select-file?nextAction=attach"));
+                       addSeparator();
+                       addItem("version", new PopupItem("menu.version").icon(
+                                       "image.version.png").action(
+                                       "select-file?nextAction=version"));
+                       addItem("replace", new PopupItem("menu.replace").icon(
+                                       "image.replace.png").action(
+                                       "select-file?nextAction=replace"));
+                       addSeparator();
+                       addItem("purge", new PopupItem("menu.purge").action(
+                                       "notyetimplemented").confirmation("message.purge.document"));
+                       addItem("remove", new PopupItem("menu.remove.version").icon(
+                                       "icon.delete.png").action("remove-document").confirmation(
+                                       "message.delete.document"));
+               }
+
+               public boolean isEnabled(String name) {
+                       if (user == null)
+                               return false; // Should not happen
+                       Item item = Item.valueOf(name);
+                       if (item == Item.accept)
+                               return user.canAccept();
+                       if (item == Item.promote)
+                               return user.canPromote();
+                       if (item == Item.rename)
+                               return user.canRename();
+                       if (item == Item.attach)
+                               return user.canAttach();
+                       if (item == Item.version)
+                               return user.canVersion();
+                       if (item == Item.replace)
+                               return user.canReplace();
+                       if (item == Item.purge)
+                               return user.canPurge();
+                       if (item == Item.remove)
+                               return user.canRemove();
+                       return false;
+               }
+
+               public void setContext(String name, Object context) {
+                       if (context instanceof DocumentRights) {
+                               user = (DocumentRights) context; // Just for optimizing
+                               Document downer = user.getOperand();
+                               PopupItem item = this.item("remove");
+                               if (downer.isVersioned())
+                                       item.rename("menu.remove.version");
+                               else
+                                       item.rename("menu.remove.document");
+                       }
+               }
+       }
+
+       private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
+       // ----------------------------------------------------------------
+               private DocumentRights user = null;
+
+               private ReviewableDocumentPopup() {
+                       addItem("demote", new PopupItem("menu.demote").icon(
+                                       "image.demote.png").action("setDocument?action=demote")
+                                       .confirmation("message.demote.document"));
+                       addItem("promote", new PopupItem("menu.review").icon(
+                                       "image.review.png").action("setDocument?action=review")
+                                       .confirmation("message.review.document"));
+                       addSeparator();
+                       addItem("attach", new PopupItem("menu.attach").icon(
+                                       "image.attach.png").action("select-file?nextAction=attach"));
+                       addSeparator();
+                       addItem("version", new PopupItem("menu.version").icon(
+                                       "image.version.png").action(
+                                       "select-file?nextAction=version"));
+                       addSeparator();
+                       addItem("purge", new PopupItem("menu.purge").action(
+                                       "notyetimplemented").confirmation("message.purge.document"));
+               }
+
+               public boolean isEnabled(String name) {
+                       if (user == null)
+                               return false; // Should not happen
+                       Item item = Item.valueOf(name);
+                       if (item == Item.demote)
+                               return user.canDemote();
+                       if (item == Item.promote)
+                               return user.canReview();
+                       if (item == Item.attach)
+                               return user.canAttach();
+                       if (item == Item.version)
+                               return user.canVersion();
+                       if (item == Item.purge)
+                               return user.canPurge();
+                       return false;
+               }
+
+               public void setContext(String name, Object context) {
+                       if (context instanceof DocumentRights) {
+                               user = (DocumentRights) context; // Just for optimizing
+                       }
+               }
+       }
+
+       private static class NotResultDocumentPopup extends PopupMenu {
+               // ----------------------------------------------------------------
+               private DocumentRights user = null;
+
+               private NotResultDocumentPopup() {
+                       addItem("demote", new PopupItem("menu.demote").icon(
+                                       "image.demote.png").action("setDocument?action=demote")
+                                       .confirmation("message.demote.document"));
+                       addSeparator();
+                       addItem("attach", new PopupItem("menu.attach").icon(
+                                       "image.attach.png").action("select-file?nextAction=attach"));
+                       addSeparator();
+                       addItem("version", new PopupItem("menu.version").icon(
+                                       "image.version.png").action(
+                                       "select-file?nextAction=version"));
+                       addSeparator();
+                       addItem("purge", new PopupItem("menu.purge").action(
+                                       "notyetimplemented").confirmation("message.purge.document"));
+                       addItem("remove", new PopupItem("menu.remove.version").icon(
+                                       "icon.delete.png").action("remove-document").confirmation(
+                                       "message.delete.document"));
+               }
+       }
+
+       private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
+       // ----------------------------------------------------------------
+               private DocumentRights user = null;
+
+               private ApprovableDocumentPopup() {
+                       addItem("undo", new PopupItem("menu.demote").icon(
+                                       "image.invalidate.png").action(
+                                       "setDocument?action=invalidate").confirmation(
+                                       "message.demote.document"));
+                       addItem("demote", new PopupItem("menu.disapprove").icon(
+                                       "image.demote.png").action("setDocument?action=disapprove")
+                                       .confirmation("message.disapprove.document"));
+                       addItem("approve", new PopupItem("menu.approve").icon(
+                                       "icon.APPROVED.png").action("setDocument?action=approve")
+                                       .confirmation("message.approve.document"));
+               }
+
+               public boolean isEnabled(String name) {
+                       if (user == null)
+                               return false; // Should not happen
+                       Item item = Item.valueOf(name);
+                       if (item == Item.undo)
+                               return user.canInvalidate();
+                       if (item == Item.demote)
+                               return user.canDemote();
+                       if (item == Item.approve)
+                               return user.canApprove();
+                       return false;
+               }
+
+               public void setContext(String name, Object context) {
+                       if (context instanceof DocumentRights) {
+                               user = (DocumentRights) context; // Just for optimizing
+                       }
+               }
+       }
+
+       private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
+       // ----------------------------------------------------------------
+               private ApprovedPopup() {
+                       addItem("attach", new PopupItem("menu.attach").icon(
+                                       "image.attach.png").action("select-file?nextAction=attach"));
+                       addSeparator();
+                       addItem("version", new PopupItem("menu.version").icon(
+                                       "image.version.png").action(
+                                       "select-file?nextAction=version"));
+               }
+       }
+
+       private static class ExternPopup extends PopupMenu { // Popup of Extern documents
+       // ----------------------------------------------------------------
+               private DocumentRights user = null;
+
+               private ExternPopup() {
+                       addItem("rename", new PopupItem("menu.rename")
+                                       .action("edit-document?action=renameDocument"));
+                       addItem("replace", new PopupItem("menu.replace").icon(
+                                       "image.replace.png").action(
+                                       "select-file?nextAction=replace"));
+                       addSeparator();
+                       addItem("remove", new PopupItem("menu.remove.document").icon(
+                                       "icon.delete.png").action("remove-document").confirmation(
+                                       "message.delete.document"));
+               }
+
+               public boolean isEnabled(String name) {
+                       if (user == null)
+                               return false; // Should not happen
+                       Item item = Item.valueOf(name);
+                       if (item == Item.rename)
+                               return user.canRename();
+                       if (item == Item.replace)
+                               return user.canReplace();
+                       if (item == Item.remove)
+                               return user.canRemove();
+                       return false;
+               }
+
+               public void setContext(String name, Object context) {
+                       if (context instanceof DocumentRights) {
+                               user = (DocumentRights) context; // Just for optimizing
+                       }
+               }
+       }
+
+       // Resources relative to simulation contexts
+       private static class ScontextPopup extends PopupMenu {
+               // --------------------------------------------------------
+               private SimulationContextFacade owner = null;
+
+               private ScontextPopup() {
+                       addItem("rename", new PopupItem("menu.rename")
+                                       .action("edit-context?action=renameContext"));
+                       addItem("edit", new PopupItem("menu.edit")
+                                       .action("edit-context?action=editContext"));
+                       addSeparator();
+                       addItem("remove", new PopupItem("menu.remove").icon(
+                                       "icon.delete.png").action("remove-context").confirmation(
+                                       "message.delete.context"));
+               }
+
+               public boolean isEnabled(String name) {
+                       Item item = Item.valueOf(name);
+
+                       if (item == Item.rename) {
+                               return false;
+                       } else if (item == Item.edit) {
+                               // if (!owner.isEditable())
+                               return false;
+                       }
+                       return true;
+               }
+
+               public void setContext(String name, Object context) {
+                       if (context instanceof SimulationContextFacade) {
+                               owner = (SimulationContextFacade) context; // Just for optimizing
+                       } else {
+                               super.setContext(name, context);
+                       }
+               }
+       }
+
+       // Resources relative to knowledge
+       private static class FeedbexPopup extends PopupMenu {
+               // --------------------------------------------------------
+               private KnowledgeElement owner = null;
+
+               private FeedbexPopup() {
+                       addItem("promote", new PopupItem("menu.promote").icon(
+                                       "image.review.png").action("promote-knowledge")
+                                       .confirmation("message.promote.knowledge"));
+                       addItem("demote", new PopupItem("menu.demote").icon(
+                                       "image.invalidate.png").action("demote-knowledge")
+                                       .confirmation("message.demote.knowledge"));
+                       addSeparator();
+                       addItem("rename", new PopupItem("menu.rename")
+                                       .action("edit-knowledge?action=renameKnowledge"));
+                       addItem("edit", new PopupItem("menu.edit")
+                                       .action("edit-knowledge?action=editKnowledge"));
+                       addSeparator();
+                       addItem("remove", new PopupItem("menu.remove").icon(
+                                       "icon.delete.png").action("remove-knowledge").confirmation(
+                                       "message.delete.knowledge"));
+               }
+
+               public boolean isEnabled(String name) {
+                       Item item = Item.valueOf(name);
+
+                       if (item == Item.promote) {
+                               if (owner.getProgressState() != ProgressState.inDRAFT)
+                                       return false;
+                       } else if (item == Item.demote) {
+                               if (owner.getProgressState() != ProgressState.inCHECK)
+                                       return false;
+                       }
+                       return true;
+               }
+
+               public void setContext(String name, Object context) {
+                       if (context instanceof KnowledgeElement)
+                               owner = (KnowledgeElement) context; // Just for optimizing
+                       else {
+                               super.setContext(name, context);
+                       }
+               }
+       }
+
+       // ==============================================================================================================================
+       // Construction
+       // ==============================================================================================================================
+
+       public static ApplicationSettings getMe() {
+               // ------------------------------------------
+               return my; // The application is supposed being previously created below
+       }
+
        /**
         * @param wappurl
         * @param lang
         * @return
         */
-       public ApplicationSettings init(String wappurl, Locale lang) throws IOException {
-      ClassLoader cloader = getClass().getClassLoader();
-      String[]    wurl    = wappurl.split("/");   // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
-
-      locale     = lang;
-         wappserver = wurl[2];
-         wappname   = wurl[3];
-      wapprops   = new Properties();
-      jndprops   = new Properties();
-      wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
-      jndprops.load(cloader.getResourceAsStream("jndi.properties"));
-
-      logger.info("Application root set to " + wapprops.getProperty("wapp.root"));
-      my = this;
-      return this;
-    }
-    
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-
-       public void configure (String filename) {
-//  ---------------------------------------
-//    Non customizable settings
-      menus = new HashMap<String, SimpleMenu>();
-      SimpleMenu menu = new NewMenu();
-      menus.put( menu.getName(), menu );
-                 menu = new SearchMenu();
-      menus.put( menu.getName(), menu );
-                 menu = new DatadminMenu();
-      menus.put( menu.getName(), menu );
-                 menu = new SysadminMenu();
-      menus.put( menu.getName(), menu );
-                 menu = new PropertiesMenu();
-      menus.put( menu.getName(), menu );
-
-      popups = new HashMap<String, PopupMenu>();
-      popups.put("steditable", new EditableStudyPopup());
-      popups.put("editable",   new EditableDocumentPopup());
-      popups.put("notresult",  new NotResultDocumentPopup());
-      popups.put("reviewable", new ReviewableDocumentPopup());
-      popups.put("approvable", new ApprovableDocumentPopup());
-      popups.put("approved",   new ApprovedPopup());
-      popups.put("extern",     new ExternPopup());
-      popups.put("scontext",   new ScontextPopup());
-      popups.put("feedbex",    new FeedbexPopup());
-
-//    Default customizable mandatory settings
-      Map<String, Object> fprop = new HashMap<String, Object>();
-      fprop.put("visibility", "PRIVATE");
-      fprop.put("matchamong", "all");
-      fprop.put("matcontext", "all");
-      fprop.put("state",     "END");
-      fprop.put("author",    "0");
-      fprop.put("reference", "");
-      fprop.put("title",     "");
-      fprop.put("context", new Vector<SimulationContext>());
-             
-      Map<String, Object> gprop = new HashMap<String, Object>();
-      gprop.put("visibility", "PUBLIC");
-      gprop.put("matchamong", "all");
-      gprop.put("matcontext", "all");
-      gprop.put("type",      "2");                        //TODO: Get the index from the type name
-      gprop.put("author",    "0");
-      gprop.put("reference", "");
-      gprop.put("title",     "");
-      gprop.put("context", new Vector<SimulationContext>());
-
-      defdoctype = new LinkedHashMap<String, DocumentType>();
-      tempfile   = new HashMap<String, String>();
-      viewermap  = new String[0];
-      convertmap = new HashMap<String, Converter>();
-      filter     = new HashMap<String, Map<String, Object>>();
-      filter.put("study", fprop);
-      filter.put("knowledge", gprop);
-
-//       Customization (must be done after above default settings)
-      File config = new File(filename);
-      if  (config.exists()) {
-        loadCustomization(config);   // Sets default document types, installed modules and available templates
-      } else {
-        logger.info("Could not find the application configuration file \"" + config.getAbsolutePath() + "\", using default settings");
-      }
-//    Settings based on the customization
-         bars = new HashMap<Integer, ToolBar>();             // May be empty if no module installed
-         
-         List<ProjectSettingsService.Step> steps = getProjectSettings().getAllSteps();
-         for (Iterator<ProjectSettingsService.Step> i=steps.iterator(); i.hasNext();) {
-                 ProjectSettingsService.Step step    = i.next();
-               List<String>         formats = getDefaultFormats(step);
-               if (formats.size() == 0) continue;
-
-        ToolBar         bar    = new ToolBar(24);         // Height of the module-bar
-        HashSet<String> module = new HashSet<String>();   // For not duplicating modules
-               for (Iterator<String> j=formats.iterator(); j.hasNext();) {
-          String   format  = j.next();
-          String   command = getApplicationProperty("executable." + format);
-          if (command == null)          continue;         // Module not installed
-          if (module.contains(command)) continue;
-          module.add(command);
-          String[] parsed  = command.split("/");
-          String[] name    = parsed[parsed.length-1].split("\\x2E");
-          String   docname = my.defdoctype.get(step.getNumber() + "." + format).getName();
-          if (tempfile.get(docname) == null) {            // No available template
-            String tool = parsed[parsed.length-1];
-            String icon = name[0];
-            if    (icon.equals("index")) {
-                   tool = parsed[parsed.length-2];
-                   icon = "tool." + tool.toLowerCase() + ".png";
-            }
-            else {
-                  icon = "tool." + icon.toLowerCase() + ".png";
-            }
-            File   image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
-            if   (!image.exists()) icon = "tool.any.png";
-            bar.addTool(tool, icon, command);
-          } else {
-                     docname = "/jsp/newDocument.jsp?type=" + docname;
-            String   icon    = "tool." + name[0].toLowerCase() + ".png";
-            File    image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
-            if    (!image.exists()) icon = "tool.any.png";
-            bar.addTool(name[0], icon, command, docname);
-          }
-               }
-               if (!bar.isEmpty()) bars.put(step.getNumber(), bar);
-         }
-       }
-
-    public String getApplicationProperty (String name) {
-//  --------------------------------------------------
-      return wapprops.getProperty(name);                // May be null
-    }
-
-    public String getApplicationRootPath () {
-//  ---------------------------------------
-      return getApplicationProperty("wapp.root");       // The property is supposed including the Web application name
-    }
-
-    public String getApplicationURL () {
-//  ----------------------------------
-      StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/").append(wappname);
-      return       url.toString();
-    }
-
-    public Map<String, Object> getFilter (String name) {
-//  --------------------------------------------------
-      return filter.get(name);
-    }
-
-    public ToolBar getModuleBar (Step step) {
-//  -----------------------------------------
-      return bars.get(step.getNumber());
-    }
-
-    public Properties getNamingProperties () {
-//  ----------------------------------------
-      return jndprops;
-    }
-
-//  ==============================================================================================================================
-//  Public services
-//  ==============================================================================================================================    
-
-    public static String getApplicationPluginPath () {
-//  ------------------------------------------------
-      return my.getApplicationRootPath() + "plugin/";
-    }
-    public static String getApplicationResourcePath () {
-//  --------------------------------------------------
-      return my.getApplicationRootPath() + "WEB-INF/classes/";
-    }
-    public static String getApplicationSkinPath () {
-//  ----------------------------------------------
-      return my.getApplicationRootPath() + "skin/";
-    }
-    public static Converter getConverter (DocumentType type, String format) {
-//  -----------------------------------------------------------------------
-      return my.convertmap.get(format + type.getName());                           // May be null;
-    }
-    public static DocumentType getDefaultDocumentType (Step step, String format) {
-//  ----------------------------------------------------------------------------
-      String[] table = format.split("\\x2E");
-      return my.defdoctype.get(step.getNumber() + "." + table[table.length-1]);    // May be null
-    }
-    public static String getDownloadURL (User user) {
-//  --------------------------------------------------
-      StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/download/").append(user.getUsername()).append("/");
-      return       url.toString();     // The download Tomcat context is supposed being defined
-    }
-    public static Locale getCurrentLocale () {
-//  ----------------------------------------
-      return my.locale;
-    }
-    public static SimpleMenu getMenu (String name) {
-//  ----------------------------------------------
-      return my.menus.get(name);
-       }
-    public static PopupMenu getPopupMenu (String name) {
-//  --------------------------------------------------
-      return my.popups.get(name);
-    }
-    public static String getRepositoryURL () {
-//  ----------------------------------------
-      StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/repository/");
-      return       url.toString();     // The repository Tomcat context is supposed being defined
-    }
-    public static Locale[] getSupportedLocales () {
-//  ---------------------------------------------
-      String[] code   = my.wapprops.getProperty("locale.supported").split(",");
-      Locale[] result = new Locale[code.length];
-      for (int i=0; i<code.length; i++) result[i] = new Locale(code[i]);
-      return result;
-    }
-    public static String[] getViewersMapping () {
-//  -------------------------------------------
-      return my.viewermap;
-    }
-    public static String getWebSiteURL () {
-//  -------------------------------------
-      return my.getApplicationProperty("wapp.website");
-    }
-    public static String getHelpURL () {
-//  ----------------------------------
-      return my.getApplicationProperty("wapp.onlinehelp");
-    }
-//  ==============================================================================================================================
-//  Private services
-//  ==============================================================================================================================
-
-    private List<String> getDefaultFormats (ProjectSettingsService.Step step) {
-//  ------------------------------------------------------------------
-      Set<String>    keys   = defdoctype.keySet();
-      int            number = step.getNumber();
-      Vector<String> result = new Vector<String>();
-
-      for (Iterator<String> i=keys.iterator(); i.hasNext();) {
-       String[] key = i.next().split("\\x2E");
-       if (Integer.valueOf(key[0]) != number) continue;
-       if (key[1].equals("pdf"))              continue;           // PDF is not an authoring format
-       result.add(key[1]);                                        // Formats are unique
-      }
-      return result;
-    }
-
-    private void loadCustomization (File config) {
-//  --------------------------------------------
-      try {
-        DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
-        DocumentBuilder        dBuilder = dfactory.newDocumentBuilder();
-     
-        org.w3c.dom.Document   conf     = dBuilder.parse(config.getPath());
-        HashMap<String, Node>  children = XDOM.getNamedChildNodes(conf.getDocumentElement());
-
-//      Default document types tag
-        Node     child = children.get("default-doctypes");
-           NodeList nlist = child.getChildNodes();
-           
-        List<DocumentType>           listype = Document.selectAllTypes();
-        HashMap<String,DocumentType> maptype = new HashMap<String,DocumentType>();
-        for (Iterator<DocumentType> i=listype.iterator(); i.hasNext();) {
-         DocumentType  type = i.next();
-         maptype.put(type.getName(), type);
-        }          
-        for (int i=0; i<nlist.getLength(); i++) {
-          child = nlist.item(i);
-          if (!child.getNodeName().equals("step")) continue;
-
-          String   nstep = child.getAttributes().getNamedItem("number").getNodeValue();
-          NodeList map   = child.getChildNodes();
-          for (int j=0; j<map.getLength(); j++) {
-            child = map.item(j);
-            if (!child.getNodeName().equals("mapping")) continue;
-            NamedNodeMap natr = child.getAttributes();
-            String       dext = natr.getNamedItem("extension").getNodeValue();
-            String       type = natr.getNamedItem("type").getNodeValue();
-            defdoctype.put(nstep + "." + dext, maptype.get(type));
-          }
-        }
-//      Modules tag
-        child = children.get("modules");
-        nlist = child.getChildNodes();
-        for (int i=0; i<nlist.getLength(); i++) {
-          child = nlist.item(i);
-          if (!child.getNodeName().equals("mapping")) continue;
-          
-          NamedNodeMap natr = child.getAttributes();
-          String       dext = natr.getNamedItem("extension").getNodeValue();
-          String       exec = natr.getNamedItem("executable").getNodeValue();
-          wapprops.put("executable." + dext,  exec);
-        }
-//      Viewer mappings tag
-        child     = children.get("viewers");
-        viewermap = child.getAttributes().getNamedItem("extension").getNodeValue().split(",");
-
-//      Converters tag
-        child = children.get("converters");
-        nlist = child.getChildNodes();
-        for (int i=0; i<nlist.getLength(); i++) {
-          child = nlist.item(i);
-
-          if (child.getNodeName().equals("geometry")) {
-            NamedNodeMap natr = child.getAttributes();
-            String       from = natr.getNamedItem("from").getNodeValue();
-            String       to   = natr.getNamedItem("to").getNodeValue();
-            String       exec = natr.getNamedItem("executable").getNodeValue();
-            convertmap.put(from + "geometry", new Converter("geometry", from, to, exec));
-          }
-        }
-
-//      Templates tag
-        child = children.get("templates");
-        nlist = child.getChildNodes();
-        for (int i=0; i<nlist.getLength(); i++) {
-          child = nlist.item(i);
-          if (!child.getNodeName().equals("document")) continue;
-
-          NamedNodeMap natr = child.getAttributes();
-          String       type = natr.getNamedItem("type").getNodeValue();
-          String       file = natr.getNamedItem("file").getNodeValue();
-          tempfile.put(type, file);
-        }
-      }
-      catch (Exception error) {
-               logger.info("Error in customization", error);
-      }
-    }
+       public ApplicationSettings init(String wappurl, Locale lang)
+                       throws IOException {
+               ClassLoader cloader = getClass().getClassLoader();
+               String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
+
+               locale = lang;
+               wappserver = wurl[2];
+               wappname = wurl[3];
+               wapprops = new Properties();
+               jndprops = new Properties();
+               wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
+               jndprops.load(cloader.getResourceAsStream("jndi.properties"));
+
+               logger.info("Application root set to "
+                               + wapprops.getProperty("wapp.root"));
+               my = this;
+               return this;
+       }
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       public void configure(String filename) {
+               // ---------------------------------------
+               // Non customizable settings
+               menus = new HashMap<String, SimpleMenu>();
+               SimpleMenu menu = new NewMenu();
+               menus.put(menu.getName(), menu);
+               menu = new SearchMenu();
+               menus.put(menu.getName(), menu);
+               menu = new DatadminMenu();
+               menus.put(menu.getName(), menu);
+               menu = new SysadminMenu();
+               menus.put(menu.getName(), menu);
+               menu = new PropertiesMenu();
+               menus.put(menu.getName(), menu);
+
+               popups = new HashMap<String, PopupMenu>();
+               popups.put("steditable", new EditableStudyPopup());
+               popups.put("editable", new EditableDocumentPopup());
+               popups.put("notresult", new NotResultDocumentPopup());
+               popups.put("reviewable", new ReviewableDocumentPopup());
+               popups.put("approvable", new ApprovableDocumentPopup());
+               popups.put("approved", new ApprovedPopup());
+               popups.put("extern", new ExternPopup());
+               popups.put("scontext", new ScontextPopup());
+               popups.put("feedbex", new FeedbexPopup());
+
+               // Default customizable mandatory settings
+               Map<String, Object> fprop = new HashMap<String, Object>();
+               fprop.put("visibility", "PRIVATE");
+               fprop.put("matchamong", "all");
+               fprop.put("matcontext", "all");
+               fprop.put("state", "END");
+               fprop.put("author", "0");
+               fprop.put("reference", "");
+               fprop.put("title", "");
+               fprop.put("context", new Vector<SimulationContext>());
+
+               Map<String, Object> gprop = new HashMap<String, Object>();
+               gprop.put("visibility", "PUBLIC");
+               gprop.put("matchamong", "all");
+               gprop.put("matcontext", "all");
+               gprop.put("type", "2"); // TODO: Get the index from the type name
+               gprop.put("author", "0");
+               gprop.put("reference", "");
+               gprop.put("title", "");
+               gprop.put("context", new Vector<SimulationContext>());
+
+               defdoctype = new LinkedHashMap<String, DocumentType>();
+               tempfile = new HashMap<String, String>();
+               viewermap = new String[0];
+               convertmap = new HashMap<String, Converter>();
+               filter = new HashMap<String, Map<String, Object>>();
+               filter.put("study", fprop);
+               filter.put("knowledge", gprop);
+
+               // Customization (must be done after above default settings)
+               File config = new File(filename);
+               if (config.exists()) {
+                       loadCustomization(config); // Sets default document types, installed modules and available templates
+               } else {
+                       logger.info("Could not find the application configuration file \""
+                                       + config.getAbsolutePath() + "\", using default settings");
+               }
+               // Settings based on the customization
+               bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
+
+               List<ProjectSettingsService.Step> steps = getProjectSettings()
+                               .getAllSteps();
+               for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
+                               .hasNext();) {
+                       ProjectSettingsService.Step step = i.next();
+                       List<String> formats = getDefaultFormats(step);
+                       if (formats.size() == 0)
+                               continue;
+
+                       ToolBar bar = new ToolBar(24); // Height of the module-bar
+                       HashSet<String> module = new HashSet<String>(); // For not duplicating modules
+                       for (Iterator<String> j = formats.iterator(); j.hasNext();) {
+                               String format = j.next();
+                               String command = getApplicationProperty("executable." + format);
+                               if (command == null)
+                                       continue; // Module not installed
+                               if (module.contains(command))
+                                       continue;
+                               module.add(command);
+                               String[] parsed = command.split("/");
+                               String[] name = parsed[parsed.length - 1].split("\\x2E");
+                               String docname = my.defdoctype.get(
+                                               step.getNumber() + "." + format).getName();
+                               if (tempfile.get(docname) == null) { // No available template
+                                       String tool = parsed[parsed.length - 1];
+                                       String icon = name[0];
+                                       if (icon.equals("index")) {
+                                               tool = parsed[parsed.length - 2];
+                                               icon = "tool." + tool.toLowerCase() + ".png";
+                                       } else {
+                                               icon = "tool." + icon.toLowerCase() + ".png";
+                                       }
+                                       File image = new File(ApplicationSettings
+                                                       .getApplicationSkinPath()
+                                                       + icon);
+                                       if (!image.exists())
+                                               icon = "tool.any.png";
+                                       bar.addTool(tool, icon, command);
+                               } else {
+                                       docname = "/jsp/newDocument.jsp?type=" + docname;
+                                       String icon = "tool." + name[0].toLowerCase() + ".png";
+                                       File image = new File(ApplicationSettings
+                                                       .getApplicationSkinPath()
+                                                       + icon);
+                                       if (!image.exists())
+                                               icon = "tool.any.png";
+                                       bar.addTool(name[0], icon, command, docname);
+                               }
+                       }
+                       if (!bar.isEmpty())
+                               bars.put(step.getNumber(), bar);
+               }
+       }
+
+       public String getApplicationProperty(String name) {
+               // --------------------------------------------------
+               return wapprops.getProperty(name); // May be null
+       }
+
+       public String getApplicationRootPath() {
+               // ---------------------------------------
+               return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
+       }
+
+       public String getApplicationURL() {
+               // ----------------------------------
+               StringBuffer url = new StringBuffer("http://").append(my.wappserver)
+                               .append("/").append(wappname);
+               return url.toString();
+       }
+
+       public Map<String, Object> getFilter(String name) {
+               // --------------------------------------------------
+               return filter.get(name);
+       }
+
+       public ToolBar getModuleBar(Step step) {
+               // -----------------------------------------
+               return bars.get(step.getNumber());
+       }
+
+       public Properties getNamingProperties() {
+               // ----------------------------------------
+               return jndprops;
+       }
+
+       // ==============================================================================================================================
+       // Public services
+       // ==============================================================================================================================
+
+       public static String getApplicationPluginPath() {
+               // ------------------------------------------------
+               return my.getApplicationRootPath() + "plugin/";
+       }
+
+       public static String getApplicationResourcePath() {
+               // --------------------------------------------------
+               return my.getApplicationRootPath() + "WEB-INF/classes/";
+       }
+
+       public static String getApplicationSkinPath() {
+               // ----------------------------------------------
+               return my.getApplicationRootPath() + "skin/";
+       }
+
+       public static Converter getConverter(DocumentType type, String format) {
+               // -----------------------------------------------------------------------
+               return my.convertmap.get(format + type.getName()); // May be null;
+       }
+
+       public static DocumentType getDefaultDocumentType(Step step, String format) {
+               // ----------------------------------------------------------------------------
+               String[] table = format.split("\\x2E");
+               return my.defdoctype.get(step.getNumber() + "."
+                               + table[table.length - 1]); // May be null
+       }
+
+       public static String getDownloadURL(User user) {
+               // --------------------------------------------------
+               StringBuffer url = new StringBuffer("http://").append(my.wappserver)
+                               .append("/download/").append(user.getUsername()).append("/");
+               return url.toString(); // The download Tomcat context is supposed being defined
+       }
+
+       public static Locale getCurrentLocale() {
+               // ----------------------------------------
+               return my.locale;
+       }
+
+       public static SimpleMenu getMenu(String name) {
+               // ----------------------------------------------
+               return my.menus.get(name);
+       }
+
+       public static PopupMenu getPopupMenu(String name) {
+               // --------------------------------------------------
+               return my.popups.get(name);
+       }
+
+       public static String getRepositoryURL() {
+               // ----------------------------------------
+               StringBuffer url = new StringBuffer("http://").append(my.wappserver)
+                               .append("/repository/");
+               return url.toString(); // The repository Tomcat context is supposed being defined
+       }
+
+       public static Locale[] getSupportedLocales() {
+               // ---------------------------------------------
+               String[] code = my.wapprops.getProperty("locale.supported").split(",");
+               Locale[] result = new Locale[code.length];
+               for (int i = 0; i < code.length; i++)
+                       result[i] = new Locale(code[i]);
+               return result;
+       }
+
+       public static String[] getViewersMapping() {
+               // -------------------------------------------
+               return my.viewermap;
+       }
+
+       public static String getWebSiteURL() {
+               // -------------------------------------
+               return my.getApplicationProperty("wapp.website");
+       }
+
+       public static String getHelpURL() {
+               // ----------------------------------
+               return my.getApplicationProperty("wapp.onlinehelp");
+       }
+
+       // ==============================================================================================================================
+       // Private services
+       // ==============================================================================================================================
+
+       private List<String> getDefaultFormats(ProjectSettingsService.Step step) {
+               // ------------------------------------------------------------------
+               Set<String> keys = defdoctype.keySet();
+               int number = step.getNumber();
+               Vector<String> result = new Vector<String>();
+
+               for (Iterator<String> i = keys.iterator(); i.hasNext();) {
+                       String[] key = i.next().split("\\x2E");
+                       if (Integer.valueOf(key[0]) != number)
+                               continue;
+                       if (key[1].equals("pdf"))
+                               continue; // PDF is not an authoring format
+                       result.add(key[1]); // Formats are unique
+               }
+               return result;
+       }
+
+       private void loadCustomization(File config) {
+               // --------------------------------------------
+               try {
+                       DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
+                                       .newInstance();
+                       DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
+
+                       org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
+                       HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
+                                       .getDocumentElement());
+
+                       // Default document types tag
+                       Node child = children.get("default-doctypes");
+                       NodeList nlist = child.getChildNodes();
+
+                       List<DocumentType> listype = getDocumentTypeService()
+                                       .selectAllTypes();
+                       HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
+                       for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
+                               DocumentType type = i.next();
+                               maptype.put(type.getName(), type);
+                       }
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               if (!child.getNodeName().equals("step"))
+                                       continue;
+
+                               String nstep = child.getAttributes().getNamedItem("number")
+                                               .getNodeValue();
+                               NodeList map = child.getChildNodes();
+                               for (int j = 0; j < map.getLength(); j++) {
+                                       child = map.item(j);
+                                       if (!child.getNodeName().equals("mapping"))
+                                               continue;
+                                       NamedNodeMap natr = child.getAttributes();
+                                       String dext = natr.getNamedItem("extension").getNodeValue();
+                                       String type = natr.getNamedItem("type").getNodeValue();
+                                       defdoctype.put(nstep + "." + dext, maptype.get(type));
+                               }
+                       }
+                       // Modules tag
+                       child = children.get("modules");
+                       nlist = child.getChildNodes();
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               if (!child.getNodeName().equals("mapping"))
+                                       continue;
+
+                               NamedNodeMap natr = child.getAttributes();
+                               String dext = natr.getNamedItem("extension").getNodeValue();
+                               String exec = natr.getNamedItem("executable").getNodeValue();
+                               wapprops.put("executable." + dext, exec);
+                       }
+                       // Viewer mappings tag
+                       child = children.get("viewers");
+                       viewermap = child.getAttributes().getNamedItem("extension")
+                                       .getNodeValue().split(",");
+
+                       // Converters tag
+                       child = children.get("converters");
+                       nlist = child.getChildNodes();
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+
+                               if (child.getNodeName().equals("geometry")) {
+                                       NamedNodeMap natr = child.getAttributes();
+                                       String from = natr.getNamedItem("from").getNodeValue();
+                                       String to = natr.getNamedItem("to").getNodeValue();
+                                       String exec = natr.getNamedItem("executable")
+                                                       .getNodeValue();
+                                       convertmap.put(from + "geometry", new Converter("geometry",
+                                                       from, to, exec));
+                               }
+                       }
+
+                       // Templates tag
+                       child = children.get("templates");
+                       nlist = child.getChildNodes();
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               if (!child.getNodeName().equals("document"))
+                                       continue;
+
+                               NamedNodeMap natr = child.getAttributes();
+                               String type = natr.getNamedItem("type").getNodeValue();
+                               String file = natr.getNamedItem("file").getNodeValue();
+                               tempfile.put(type, file);
+                       }
+               } catch (Exception error) {
+                       logger.info("Error in customization", error);
+               }
+       }
+
+       /**
+        * Get the documentTypeService.
+        * 
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * 
+        * @param documentTypeService
+        *            the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
 }
\ No newline at end of file
index 3738cf43cf432fdbcb1288a06d2ee26c9ecc250c..69edf20eb76effd0ec37d21ef2e534a47685a1fe 100644 (file)
@@ -12,6 +12,7 @@ import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.service.PublicationService;
+import org.splat.service.StepService;
 import org.splat.service.technical.RepositoryService;
 import org.splat.som.Step;
 
@@ -32,6 +33,10 @@ public class EditDocumentAction extends DisplayStudyStepAction {
         * Injected publication service.
         */
        private PublicationService _publicationService;
+       /**
+        * Injected step service.
+        */
+       private StepService _stepService;
        /**
         * Injected repository service.
         */
@@ -70,7 +75,7 @@ public class EditDocumentAction extends DisplayStudyStepAction {
                        Publication doc = step.getDocument(Integer.valueOf(index));
 
                        if (todo == Execute.renameDocument) {
-                               doc.rename(title);
+                               getPublicationService().rename(doc, title);
                                // Useless to update the document presentation
                        } else if (todo == Execute.accept) {
                                doc.actualize();
@@ -128,7 +133,7 @@ public class EditDocumentAction extends DisplayStudyStepAction {
                        String[] parse = filename.split("\\x2E");
 
                        Publication edited = step.getDocument(Integer.valueOf(index));
-                       ConvertsRelation export = edited.attach(parse[parse.length - 1]);
+                       ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
 
                        if (logger.isInfoEnabled())
                                logger.info("Moving \"" + upfile.getName() + "\" to \""
@@ -154,7 +159,7 @@ public class EditDocumentAction extends DisplayStudyStepAction {
                        Step step = mystudy.getSelectedStep();
                        Publication doctag = step.getDocument(Integer.valueOf(index));
 
-                       step.removeDocument(doctag); // Updates the data structure
+                       getStepService().removeDocument(step, doctag); // Updates the data structure
                        transax.commit();
 
                        mystudy.remove(doctag); // Updates the presentation
@@ -229,4 +234,20 @@ public class EditDocumentAction extends DisplayStudyStepAction {
        public void setRepositoryService(RepositoryService repositoryService) {
                _repositoryService = repositoryService;
        }
+
+       /**
+        * 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
index 38f2f1741a9967765fb941c996a94f19d0da7077..99ae151c2050a0f3b83d8c074f622ca322614218 100644 (file)
 package org.splat.simer;
 
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.splat.dal.bo.kernel.User;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.service.KnowledgeElementService;
+import org.splat.service.KnowledgeElementTypeService;
 import org.splat.service.ScenarioService;
 import org.splat.som.Step;
 
-
+/**
+ * Action for addition and modification of knowledge elements in the selected scenario.
+ */
 public class EditKnowledgeElementAction extends DisplayStudyStepAction {
 
-       private String                      type      = null;     // Edited knowledge type
-       private String                      title     = null;
-       private String                      value     = null;
+       /**
+        * Serial version ID.
+        */
+       private static final long serialVersionUID = 4636919137087687068L;
+
+       /**
+        * Edited knowledge element type.
+        */
+       private String type = null; // Edited knowledge type
+       /**
+        * Edited knowledge element title.
+        */
+       private String title = null;
+       /**
+        * Edited knowledge element value.
+        */
+       private String value = null;
+       /**
+        * Injected scenario service.
+        */
        private ScenarioService _scenarioService;
+       /**
+        * Injected knowledge element service.
+        */
        private KnowledgeElementService _knowledgeElementService;
+       /**
+        * Injected knowledge element type service.
+        */
+       private KnowledgeElementTypeService _knowledgeElementTypeService;
+
+       // ==============================================================================================================================
+       // Action methods
+       // ==============================================================================================================================
 
        /**
-        * Serial version ID.
+        * Initialize the action. Get selected study from the session.
+        * 
+        * @return SUCCESS if no exceptions
         */
-       private static final long    serialVersionUID = 4636919137087687068L;
-
-//  ==============================================================================================================================
-//  Action methods
-//  ==============================================================================================================================
-
-    public String doInitialize () {
-//  -----------------------------
-//    Session      connex  = Database.getSession();
-//       Transaction  transax = connex.beginTransaction();
-
-         mystudy = getOpenStudy();
-        
-//    transax.commit();
-      return SUCCESS;
-    }
-
-    public String doSetKnowledge () {
-//  -------------------------------
-      Session      connex  = Database.getSession();
-         Transaction  transax = connex.beginTransaction();
-         try {
-       User user = getConnectedUser();
-               mystudy   = getOpenStudy();
-
-               Step     step  = mystudy.getSelectedStep();
-        Scenario scene = (Scenario)step.getOwner();          // It is necessarily a Scenario
-
-               if (title != null && value != null) {                // Addition of a new Knowledge Element
-                 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
-         KnowledgeElementType        ktype = KnowledgeElement.selectType(Integer.valueOf(type));
-         kprop.setType(ktype)
-                  .setTitle(title)
-                  .setValue(value)
-                  .setAuthor(user);
-          mystudy.add( getScenarioService().addKnowledgeElement(scene, kprop) );
-          getMenu("study").selects(mystudy.getSelection());  // Updates the menu icon, in case of first added document
-               } else
-               if (title != null) {                                 // Renaming of an existing Knowledge Element
-          KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
-          getKnowledgeElementService().rename(kelm, title);
-//        Useless to update the open study
-               } else
-               if (value != null) {                                 // Edition of a knowledge
-          KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
-          kelm.update(value);
-          mystudy.update(kelm);                              // For updating the truncated value
-               }
-        transax.commit();
-        return SUCCESS;
-         }
-      catch (RuntimeException saverror) {
-        logger.error("Reason:", saverror);
-        if (transax != null && transax.isActive()) {
-//        Second try-catch as the rollback could fail as well
-          try {
-               transax.rollback();
-          } catch (HibernateException backerror) {
-            logger.debug("Error rolling back transaction", backerror);
-          }
-        }
-        return ERROR;
-         }
-      catch (Exception error) {
-        transax.commit();
-       return INPUT;
-      }
-    }
-
-    public String doDeleteKnowledge () {
-//  ----------------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-      try {
-               mystudy = getOpenStudy();
-               Step     step  = mystudy.getSelectedStep();
-        Scenario scene = (Scenario)step.getOwner();        // It is necessarily a Scenario
-        
-        KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(myindex));
-        scene.removeKnowledgeElement(kelm);                // The knowledge element necessarily exists
-
-        mystudy.remove(kelm);
-        getMenu("study").selects(mystudy.getSelection());  // Updates the menu icon, in case of last removed document
-        
-        transax.commit();
-        return SUCCESS;
-         }
-      catch (RuntimeException saverror) {
-        logger.error("Reason:", saverror);
-        if (transax != null && transax.isActive()) {
-//        Second try-catch as the rollback could fail as well
-          try {
-               transax.rollback();
-          } catch (HibernateException backerror) {
-            logger.debug("Error rolling back transaction", backerror);
-          }
-        }
-        return ERROR;
-         }
-    }
-
-//  ==============================================================================================================================
-//  Getters and setters
-//  ==============================================================================================================================
-
-    public String getKnowledgeType () {
-//  ---------------------------------
-      return type;
-    }
-    public String getSelectedKnowledge () {
-//  -------------------------------------
-      return myindex;
-    }
-    
-    public void setKnowledgeType (String type) {
-//  ------------------------------------------
-      this.type = type;
-    }
-    public void setKnowledgeTitle (String title) {
-//  --------------------------------------------
-      this.title = title;
-    }
-    public void setKnowledgeValue (String value) {
-//  --------------------------------------------
-      this.value = value;
-    }
+       public String doInitialize() {
+               mystudy = getOpenStudy();
+               return SUCCESS;
+       }
+
+       /**
+        * Add a new or update an existing knowledge element of the selected scenario in the open study.
+        * 
+        * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
+        */
+       public String doSetKnowledge() {
+               try {
+                       User user = getConnectedUser();
+                       mystudy = getOpenStudy();
+
+                       Step step = mystudy.getSelectedStep();
+                       Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
+
+                       if (title != null && value != null) { // Addition of a new Knowledge Element
+                               KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
+                               KnowledgeElementType ktype = getKnowledgeElementTypeService()
+                                               .selectType(Integer.valueOf(type));
+                               kprop.setType(ktype).setTitle(title).setValue(value).setAuthor(
+                                               user);
+                               mystudy.add(getScenarioService().addKnowledgeElement(scene,
+                                               kprop));
+                               getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
+                       } else if (title != null) { // Renaming of an existing Knowledge Element
+                               KnowledgeElement kelm = scene.getKnowledgeElement(Integer
+                                               .valueOf(type));
+                               getKnowledgeElementService().rename(kelm, title);
+                               // Useless to update the open study
+                       } else if (value != null) { // Edition of a knowledge
+                               KnowledgeElement kelm = scene.getKnowledgeElement(Integer
+                                               .valueOf(type));
+                               getKnowledgeElementService().update(kelm, value);
+                               mystudy.update(kelm); // For updating the truncated value
+                       }
+                       return SUCCESS;
+               } catch (RuntimeException saverror) {
+                       logger.error("Reason:", saverror);
+                       return ERROR;
+               } catch (Exception error) {
+                       return INPUT;
+               }
+       }
+
+       /**
+        * Delete a knowledge element from the current scenario.
+        * 
+        * @return SUCCESS if no exceptions
+        */
+       public String doDeleteKnowledge() {
+               mystudy = getOpenStudy();
+               Step step = mystudy.getSelectedStep();
+               Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
+
+               KnowledgeElement kelm = scene.getKnowledgeElement(Integer
+                               .valueOf(myindex));
+               scene.removeKnowledgeElement(kelm); // The knowledge element necessarily exists
+
+               mystudy.remove(kelm);
+               getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
+
+               return SUCCESS;
+       }
+
+       // ==============================================================================================================================
+       // Getters and setters
+       // ==============================================================================================================================
+
+       /**
+        * Get the type of the modified knowledge element.
+        * 
+        * @return the knowledge type name
+        */
+       public String getKnowledgeType() {
+               // ---------------------------------
+               return type;
+       }
+
+       /**
+        * Get the id of the modified knowledge element.
+        * 
+        * @return the knowledge element id
+        */
+       public String getSelectedKnowledge() {
+               // -------------------------------------
+               return myindex;
+       }
+
+       /**
+        * Set the type of the modified knowledge element.
+        * 
+        * @param type
+        *            the knowledge type name
+        */
+       public void setKnowledgeType(String type) {
+               // ------------------------------------------
+               this.type = type;
+       }
+
+       /**
+        * Set the title of the modified knowledge element.
+        * 
+        * @param title
+        *            the new knowledge title
+        */
+       public void setKnowledgeTitle(String title) {
+               // --------------------------------------------
+               this.title = title;
+       }
+
+       /**
+        * Set the value of the modified knowledge element.
+        * 
+        * @param value
+        *            the knowledge value
+        */
+       public void setKnowledgeValue(String value) {
+               // --------------------------------------------
+               this.value = value;
+       }
+
        /**
         * Get the scenarioService.
+        * 
         * @return the scenarioService
         */
        public ScenarioService getScenarioService() {
@@ -160,7 +188,9 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
 
        /**
         * Set the scenarioService.
-        * @param scenarioService the scenarioService to set
+        * 
+        * @param scenarioService
+        *            the scenarioService to set
         */
        public void setScenarioService(ScenarioService scenarioService) {
                _scenarioService = scenarioService;
@@ -168,6 +198,7 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
 
        /**
         * Get the knowledgeElementService.
+        * 
         * @return the knowledgeElementService
         */
        public KnowledgeElementService getKnowledgeElementService() {
@@ -176,10 +207,29 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction {
 
        /**
         * Set the knowledgeElementService.
-        * @param knowledgeElementService the knowledgeElementService to set
+        * 
+        * @param knowledgeElementService
+        *            the knowledgeElementService to set
         */
        public void setKnowledgeElementService(
                        KnowledgeElementService knowledgeElementService) {
                _knowledgeElementService = knowledgeElementService;
        }
+
+       /**
+        * Get the knowledgeElementTypeService.
+        * @return the knowledgeElementTypeService
+        */
+       public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+               return _knowledgeElementTypeService;
+       }
+
+       /**
+        * Set the knowledgeElementTypeService.
+        * @param knowledgeElementTypeService the knowledgeElementTypeService to set
+        */
+       public void setKnowledgeElementTypeService(
+                       KnowledgeElementTypeService knowledgeElementTypeService) {
+               _knowledgeElementTypeService = knowledgeElementTypeService;
+       }
 }
\ No newline at end of file
index 47957e5b3622163054cbe745801dada692ee2eb7..02d9070f37596f0b3e42b6d1e9de294fe97a2b1d 100644 (file)
@@ -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.DocumentService;
+import org.splat.service.DocumentTypeService;
 import org.splat.service.PublicationService;
 import org.splat.service.StepService;
 import org.splat.service.technical.ProjectSettingsService;
@@ -57,7 +58,10 @@ public class ImportDocumentAction extends UploadBaseNextAction {
         * Injected document service.
         */
        private DocumentService _documentService;
-
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
        /**
         * Injected repository service.
         */
@@ -83,7 +87,7 @@ public class ImportDocumentAction extends UploadBaseNextAction {
 
                mystudy = getOpenStudy();
                Step step = mystudy.getSelectedStep();
-               doctypes = step.getValidDocumentTypes();
+               doctypes = getStepService().getValidDocumentTypes(step);
                deftype = ApplicationSettings.getDefaultDocumentType(step, filext);
                defuses = new Vector<Document>();
                state = ProgressState.inWORK;
@@ -185,7 +189,7 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                        mystudy = getOpenStudy();
                        User user = getConnectedUser();
                        Step step = mystudy.getSelectedStep();
-                       DocumentType type = Document.selectType((int)doctype);
+                       DocumentType type = getDocumentTypeService().selectType((int)doctype);
                        File updir = getRepositoryService().getDownloadDirectory(user);
                        File upfile = new File(updir.getPath() + "/" + filename);
                        String[] table = filename.split("\\x2E");
@@ -438,4 +442,20 @@ public class ImportDocumentAction extends UploadBaseNextAction {
        public void setRepositoryService(RepositoryService repositoryService) {
                _repositoryService = repositoryService;
        }
+
+       /**
+        * Get the documentTypeService.
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * @param documentTypeService the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
 }
\ No newline at end of file
index 9ff3ed6c8708e70f177acf8962624893d31eef64..68f98e200b3e156f60dc588e11517c499a388a58 100644 (file)
@@ -12,7 +12,7 @@ import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.service.ProjectElementService;
-import org.splat.service.StudyService;
+import org.splat.service.ScenarioService;
 import org.splat.som.Step;
 import org.splat.dal.bo.som.Study;
 import org.splat.wapp.Menu;
@@ -27,7 +27,13 @@ public class NewScenarioAction extends Action {
     private  long              scindex;
     private  int              bastep;
     private  ToDo             action;
-       private StudyService _studyService;
+       /**
+        * Injected scenario service.
+        */
+       private ScenarioService _scenarioService;
+       /**
+        * Injected project element service.
+        */
        private ProjectElementService _projectElementService;
        private Menu _menu;
 
@@ -105,7 +111,7 @@ public class NewScenarioAction extends Action {
           step = getProjectElementService().getSteps(bascene);
           sprop.setBaseStep(step[number-bastep]);
         }
-        bascene = getStudyService().addScenario(study, sprop);
+        bascene = getScenarioService().addScenario(study, sprop);
         transax.commit();
 
 //      Update of the display
@@ -184,24 +190,6 @@ public class NewScenarioAction extends Action {
 //  ----------------------------
       return (Integer.valueOf(getSharedStep()) > bastep);
     }
-       /**
-        * 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 the projectElementService.
         * 
@@ -237,4 +225,20 @@ public class NewScenarioAction extends Action {
        public void setMenu(Menu menu) {
                _menu = menu;
        }
+
+       /**
+        * Get the scenarioService.
+        * @return the scenarioService
+        */
+       public ScenarioService getScenarioService() {
+               return _scenarioService;
+       }
+
+       /**
+        * Set the scenarioService.
+        * @param scenarioService the scenarioService to set
+        */
+       public void setScenarioService(ScenarioService scenarioService) {
+               _scenarioService = scenarioService;
+       }
 }
\ No newline at end of file
index 05da635e63b716178bdd23be896c30ae9086390b..82755c5d540a0f444b075835030f7165750c337c 100644 (file)
@@ -11,6 +11,7 @@ import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.bo.som.Study;
+import org.splat.service.ScenarioService;
 import org.splat.service.SimulationContextService;
 import org.splat.service.StudyService;
 
@@ -31,6 +32,10 @@ public class NewStudyAction extends Action {
         */
        private StudyService _studyService;
        private SimulationContextService _simulationContextService;
+       /**
+        * Injected scenario service.
+        */
+       private ScenarioService _scenarioService;
 
        // ==============================================================================================================================
        // Action methods
@@ -90,7 +95,7 @@ public class NewStudyAction extends Action {
                                        ApplicationSettings.getCurrentLocale());
                        Scenario.Properties oprop = new Scenario.Properties();
                        oprop.setTitle(locale.getString("label.scenario") + " 1");
-                       getStudyService().addScenario(study, oprop);
+                       getScenarioService().addScenario(study, oprop);
 
                        // Addition of the entered project context
                        if (valid == 0) { // Input of new project context
@@ -190,4 +195,20 @@ public class NewStudyAction extends Action {
                        SimulationContextService simulationContextService) {
                _simulationContextService = simulationContextService;
        }
+
+       /**
+        * Get the scenarioService.
+        * @return the scenarioService
+        */
+       public ScenarioService getScenarioService() {
+               return _scenarioService;
+       }
+
+       /**
+        * Set the scenarioService.
+        * @param scenarioService the scenarioService to set
+        */
+       public void setScenarioService(ScenarioService scenarioService) {
+               _scenarioService = scenarioService;
+       }
 }
\ No newline at end of file
index 81202a4256618bd548597eebff105f9279683f8a..702f62b8c26f1b8d6c8895bd9ba8aa97b0c625af 100644 (file)
@@ -20,8 +20,6 @@ public class OpenKnowledge extends OpenObject {
 
        private KnowledgeElement myknelm;
        private String credate;
-       private ProjectElementService _projectElementService;
-
        public class Menu extends SimpleMenu {
                // ------------------------------------
                public Menu(List<Step> context) {
@@ -181,24 +179,4 @@ public class OpenKnowledge extends OpenObject {
                return result;
        }
 
-       /**
-        * Get the projectElementService.
-        * 
-        * @return the projectElementService
-        */
-       public ProjectElementService getProjectElementService() {
-               return _projectElementService;
-       }
-
-       /**
-        * Set the projectElementService.
-        * 
-        * @param projectElementService
-        *            the projectElementService to set
-        */
-       public void setProjectElementService(
-                       ProjectElementService projectElementService) {
-               _projectElementService = projectElementService;
-       }
-
 }
\ No newline at end of file
index ce6bc8cadc50d12293e80e1c06a0828e9dc6cadc..05d92896e30e7f91b2e5e36bcf32ee88e393d27c 100644 (file)
@@ -11,6 +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.KnowledgeElementService;
+import org.splat.service.KnowledgeElementTypeService;
+import org.splat.service.ProjectElementService;
 import org.splat.service.PublicationService;
 import org.splat.service.dto.Proxy;
 import org.splat.service.technical.ProjectSettingsService;
@@ -20,258 +23,291 @@ import org.splat.som.Step;
 import org.splat.wapp.Menu;
 import org.splat.wapp.PopupMenu;
 
-
 public abstract class OpenObject implements Proxy {
 
-       protected  User                          cuser       = null;   // Connected user
-       protected  String                        selection   = null;   // Menu selected by the user
-       protected  Step                          ustep       = null;   // Corresponding selected step
-       protected  String                        description = null;   // Object description (rich text)
-       protected  List<Step>                    involving   = null;
-       protected  List<SimulationContextFacade> context     = null;   // Simulation Context display representations
-       protected  List<DocumentFacade>          contents    = null;   // Document display representations
-       protected  List<KnowledgeIterator>       knowledge   = null;   // Knowledge Element display representations structured by knowledge types
-       
-       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
+       protected static HashMap<Long, DocumentFacade> docpres = null;
+       protected static HashMap<Long, KnowledgeElementFacade> knowpres = null;
+
+       protected User cuser = null; // Connected user
+       protected String selection = null; // Menu selected by the user
+       protected Step ustep = null; // Corresponding selected step
+       protected String description = null; // Object description (rich text)
+       protected List<Step> involving = null;
+       protected List<SimulationContextFacade> context = null; // Simulation Context display representations
+       protected List<DocumentFacade> contents = null; // Document display representations
+       protected List<KnowledgeIterator> knowledge = null; // Knowledge Element display representations structured by knowledge types
+
+       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
+       /**
+        * Injected project settings service.
+        */
        private ProjectSettingsService _projectSettingsService;
+       /**
+        * Injected publication service.
+        */
        private PublicationService _publicationService;
-
-    protected static HashMap<Long, DocumentFacade>         docpres  = null;
-    protected static HashMap<Long, KnowledgeElementFacade> knowpres = null;
+       /**
+        * Injected knowledge element service.
+        */
+       private KnowledgeElementTypeService _knowledgeElementTypeService;
+       /**
+        * Injected project element service.
+        */
+       private ProjectElementService _projectElementService;
 
        public class KnowledgeIterator {
-//  ------------------------------
-      protected KnowledgeElementType         type;
-      protected List<KnowledgeElementFacade> list;
-
-      public KnowledgeIterator (KnowledgeElementType type, List<KnowledgeElementFacade> list)
-      {
-        this.type = type;
-        this.list = list;
-      }
-      public String getIndex ()
-      {
-       return String.valueOf(type.getIndex());
-      }
-      public String getType ()
-      {
-       return type.getName();
-      }
-      public List<KnowledgeElementFacade> getKnowledgeElements ()
-      {
-       return list;
-      }
+               protected KnowledgeElementType type;
+               protected List<KnowledgeElementFacade> list;
+
+               public KnowledgeIterator(KnowledgeElementType type,
+                               List<KnowledgeElementFacade> list) {
+                       this.type = type;
+                       this.list = list;
+               }
+
+               public String getIndex() {
+                       return String.valueOf(type.getIndex());
+               }
+
+               public String getType() {
+                       return type.getName();
+               }
+
+               public List<KnowledgeElementFacade> getKnowledgeElements() {
+                       return list;
+               }
+       }
+
+       // ==============================================================================================================================
+       // Constructor
+       // ==============================================================================================================================
+
+       protected OpenObject() {
+               // -----------------------
+               // All member fields are supposed initialized by subclasses
+               if (docpres == null)
+                       docpres = new HashMap<Long, DocumentFacade>();
+               if (knowpres == null)
+                       knowpres = new HashMap<Long, KnowledgeElementFacade>();
+       }
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       public void developDocument(String index) {
+               // ------------------------------------------
+               for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
+                       DocumentFacade doc = i.next();
+                       if (!doc.getIndex().equals(index))
+                               continue;
+                       doc.develop();
+                       return;
+               }
+       }
+
+       public void developKnowledge(String index) {
+               // -------------------------------------------
+               for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
+                       List<KnowledgeElementFacade> knowelms = i.next()
+                                       .getKnowledgeElements();
+                       for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
+                                       .hasNext();) {
+                               KnowledgeElementFacade kelm = j.next();
+                               if (!kelm.getIndex().equals(index))
+                                       continue;
+                               kelm.develop();
+                               return;
+                       }
+               }
+       }
+
+       public void clearFacades() {
+               // ---------------------------
+               docpres.clear(); // For eventually reopening the knowledge from a fresh context
+               knowpres.clear(); // For eventually reopening the knowledge from a fresh context
+       }
+
+       public List<Document> collectInvolvedDocuments(DocumentType type) {
+               // ------------------------------------------------------------------
+               List<Document> found = new Vector<Document>();
+               for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
+                       Step step = i.next();
+                       List<Publication> exist = step.getAllDocuments();
+                       for (Iterator<Publication> j = exist.iterator(); j.hasNext();) {
+                               Document doc = j.next().value();
+                               if (doc.getType().equals(type))
+                                       found.add(doc);
+                       }
+               }
+               return found;
+       }
+
+       public String getDisplayedDescription() {
+               // ----------------------------------------
+               return description;
+       }
+
+       public List<DocumentFacade> getDisplayedDocuments() {
+               // -----------------------------------------------------
+               return contents;
+       }
+
+       public List<SimulationContextFacade> getDisplayedSimulationContexts() {
+               // ----------------------------------------------------------------------
+               return context;
+       }
+
+       public List<KnowledgeIterator> getDisplayedKnowledges() {
+               // --------------------------------------------------------
+               return knowledge;
+       }
+
+       public List<Step> getInvolvedSteps() {
+               // -------------------------------------
+               return involving;
+       }
+
+       public Menu getMenu() {
+               // ----------------------
+               return menu;
+       }
+
+       public PopupMenu getPopup() {
+               // ----------------------------
+               return popup;
+       }
+
+       public Step getSelectedStep() {
+               // ------------------------------
+               return ustep;
+       }
+
+       public String getSelection() {
+               // -----------------------------
+               return selection;
+       }
+
+       public User getUser() {
+               // ----------------------
+               return cuser;
+       }
+
+       public boolean isOpenForWriting() {
+               // ----------------------------------
+               return (popup != null); // The pop-up is supposed existed when the user is staffed on the study
+       }
+
+       public void reduceDocument(String index) {
+               // -----------------------------------------
+               for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
+                       DocumentFacade doc = i.next();
+                       if (!doc.getIndex().equals(index))
+                               continue;
+                       doc.reduceAll();
+                       return;
+               }
+       }
+
+       public void reduceHistory(String index) {
+               // ----------------------------------------
+               for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
+                       DocumentFacade doc = i.next();
+                       if (!doc.getIndex().equals(index))
+                               continue;
+                       doc.reduce();
+                       return;
+               }
+       }
+
+       public void reduceKnowledge(String index) {
+               // ------------------------------------------
+               for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
+                       List<KnowledgeElementFacade> knowelms = i.next()
+                                       .getKnowledgeElements();
+                       for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
+                                       .hasNext();) {
+                               KnowledgeElementFacade kelm = j.next();
+                               if (!kelm.getIndex().equals(index))
+                                       continue;
+                               kelm.reduce();
+                               return;
+                       }
+               }
+       }
+
+       // ==============================================================================================================================
+       // Protected services
+       // ==============================================================================================================================
+
+       protected void setupContents() {
+               // -------------------------------
+               // Description
+               // Initialized in subclasses
+
+               // Knowledge elements supposed ordered by type
+               if (ustep.mayContain(KnowledgeElement.class)) {
+                       Scenario scene = (Scenario) ustep.getOwner();
+                       List<KnowledgeElementType> types = getKnowledgeElementTypeService()
+                                       .selectTypesWhere(ProgressState.APPROVED);
+                       List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
+                       Iterator<KnowledgeElement> more = kelms.iterator();
+                       KnowledgeElement current = null;
+                       if (more.hasNext())
+                               current = more.next();
+
+                       knowledge = new Vector<KnowledgeIterator>(types.size());
+                       for (Iterator<KnowledgeElementType> i = types.iterator(); i
+                                       .hasNext();) {
+                               KnowledgeElementType type = i.next();
+                               List<KnowledgeElementFacade> display = new Vector<KnowledgeElementFacade>(
+                                               kelms.size());
+                               while (current != null && current.getType().equals(type)) {
+                                       KnowledgeElementFacade facade = knowpres.get(current
+                                                       .getIndex());
+                                       if (facade == null) {
+                                               facade = new KnowledgeElementFacade(current);
+                                               knowpres.put(current.getIndex(), facade);
+                                       }
+                                       display.add(facade);
+                                       if (more.hasNext())
+                                               current = more.next();
+                                       else
+                                               current = null;
+                               }
+                               knowledge.add(new KnowledgeIterator(type, display));
+                       }
+               } else {
+                       knowledge = null;
+               }
+               // Documents
+               if (ustep.mayContain(Document.class)) {
+                       List<Publication> list = ustep.getAllDocuments();
+
+                       contents = new Vector<DocumentFacade>(list.size());
+                       for (Iterator<Publication> i = list.iterator(); i.hasNext();) {
+                               Publication present = i.next();
+                               Long index = present.getIndex();
+                               DocumentFacade facade = docpres.get(index);
+                               if (facade == null) {
+                                       facade = new DocumentFacade(this, present,
+                                                       getProjectSettings(), getPublicationService());
+                                       docpres.put(index, facade);
+                               }
+                               contents.add(facade);
+                       }
+               } else {
+                       contents = null;
+               }
        }
-    
-//  ==============================================================================================================================
-//  Constructor
-//  ==============================================================================================================================
-
-    protected OpenObject () {
-//  -----------------------
-//    All member fields are supposed initialized by subclasses 
-      if (docpres == null)  docpres  = new HashMap<Long, DocumentFacade>();
-      if (knowpres == null) knowpres = new HashMap<Long, KnowledgeElementFacade>();
-    }
-
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-
-    public void developDocument (String index) {
-//  ------------------------------------------
-      for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
-       DocumentFacade doc = i.next();
-       if (!doc.getIndex().equals(index)) continue;
-       doc.develop();
-       return;
-      }
-    }
-
-    public void developKnowledge (String index) {
-//  -------------------------------------------
-      for (Iterator<KnowledgeIterator> i=knowledge.iterator(); i.hasNext();) {
-       List<KnowledgeElementFacade> knowelms = i.next().getKnowledgeElements();
-       for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j.hasNext(); ) {
-         KnowledgeElementFacade kelm = j.next();
-         if (!kelm.getIndex().equals(index)) continue;
-         kelm.develop();
-         return;
-       }
-      }
-    }
-
-    public void clearFacades () {
-//  ---------------------------
-      docpres.clear();      // For eventually reopening the knowledge from a fresh context
-      knowpres.clear();     // For eventually reopening the knowledge from a fresh context
-    }
-
-    public List<Document> collectInvolvedDocuments (DocumentType type) {
-//  ------------------------------------------------------------------
-      List<Document> found = new Vector<Document>();
-      for (Iterator<Step> i=involving.iterator(); i.hasNext();) {
-       Step              step  = i.next();
-       List<Publication> exist = step.getAllDocuments();
-        for (Iterator<Publication> j=exist.iterator(); j.hasNext();) {
-          Document doc = j.next().value();
-          if (doc.getType().equals(type)) found.add(doc);
-        }
-      }
-      return found;
-    }
-
-    public String getDisplayedDescription () {
-//  ----------------------------------------
-      return description;
-    }
-
-    public List<DocumentFacade> getDisplayedDocuments () {
-//  -----------------------------------------------------
-      return contents;
-    }
-
-    public List<SimulationContextFacade> getDisplayedSimulationContexts () {
-//  ----------------------------------------------------------------------
-      return context;
-    }
-
-    public List<KnowledgeIterator> getDisplayedKnowledges () {
-//  --------------------------------------------------------
-      return knowledge;
-    }
-
-    public List<Step> getInvolvedSteps () {
-//  -------------------------------------
-      return involving;
-    }
-
-    public Menu getMenu () {
-//  ----------------------
-      return menu;
-    }
-
-    public PopupMenu getPopup () {
-//  ----------------------------
-      return popup;
-    }
-
-    public Step getSelectedStep () {
-//  ------------------------------
-      return ustep;
-    }
-
-    public String getSelection () {
-//  -----------------------------
-      return selection;
-    }
-
-    public User getUser () {
-//  ----------------------
-      return cuser;
-    }
-
-    public boolean isOpenForWriting () {
-//  ----------------------------------
-      return (popup != null);     // The pop-up is supposed existed when the user is staffed on the study
-    }
-
-    public void reduceDocument (String index) {
-//  -----------------------------------------
-      for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
-        DocumentFacade doc = i.next();
-        if (!doc.getIndex().equals(index)) continue;
-        doc.reduceAll();
-        return;
-      }
-    }
-
-    public void reduceHistory (String index) {
-//  ----------------------------------------
-      for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
-        DocumentFacade doc = i.next();
-        if (!doc.getIndex().equals(index)) continue;
-        doc.reduce();
-        return;
-      }
-    }
-
-    public void reduceKnowledge (String index) {
-//  ------------------------------------------
-      for (Iterator<KnowledgeIterator> i=knowledge.iterator(); i.hasNext();) {
-       List<KnowledgeElementFacade> knowelms = i.next().getKnowledgeElements();
-       for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j.hasNext(); ) {
-         KnowledgeElementFacade kelm = j.next();
-         if (!kelm.getIndex().equals(index)) continue;
-         kelm.reduce();
-         return;
-       }
-      }
-    }
-
-//  ==============================================================================================================================
-//  Protected services
-//  ==============================================================================================================================
-
-    protected void setupContents () {
-//  -------------------------------
-//  Description
-//    Initialized in subclasses
-
-//  Knowledge elements supposed ordered by type
-      if (ustep.mayContain(KnowledgeElement.class)) {
-        Scenario                   scene   = (Scenario)ustep.getOwner();
-           List<KnowledgeElementType> types   = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
-        List<KnowledgeElement>     kelms   = scene.getAllKnowledgeElements();
-        Iterator<KnowledgeElement> more    = kelms.iterator();
-        KnowledgeElement           current = null;
-        if (more.hasNext())        current = more.next();
-
-        knowledge = new Vector<KnowledgeIterator>(types.size());
-           for (Iterator<KnowledgeElementType> i=types.iterator(); i.hasNext();) {
-          KnowledgeElementType         type    = i.next();
-          List<KnowledgeElementFacade> display = new Vector<KnowledgeElementFacade>(kelms.size());
-          while (current != null && current.getType().equals(type)) {
-               KnowledgeElementFacade facade = knowpres.get(current.getIndex());
-               if (facade == null) {
-              facade = new KnowledgeElementFacade(current);
-              knowpres.put(current.getIndex(), facade);
-               }
-               display.add(facade);
-               if (more.hasNext()) current = more.next();
-               else                current = null;
-         }
-          knowledge.add( new KnowledgeIterator(type, display) );
-        }
-      } else {
-        knowledge = null;
-      }
-//  Documents
-         if (ustep.mayContain(Document.class)) {
-        List<Publication> list = ustep.getAllDocuments();
-          
-        contents = new Vector<DocumentFacade>(list.size());
-        for (Iterator<Publication> i=list.iterator(); i.hasNext();) {
-          Publication     present = i.next();
-          Long         index   = present.getIndex();
-          DocumentFacade  facade  = docpres.get(index);
-          if (facade == null) {
-            facade = new DocumentFacade(this, present, getProjectSettings(), getPublicationService());
-            docpres.put(index, facade);
-          }
-         contents.add(facade);
-        }
-         } else {
-        contents = null;
-         }
-    }
 
        /**
         * Get project settings.
+        * 
         * @return Project settings service
         */
-    public ProjectSettingsService getProjectSettings() {
+       public ProjectSettingsService getProjectSettings() {
                return _projectSettingsService;
        }
 
@@ -286,10 +322,11 @@ public abstract class OpenObject implements Proxy {
 
        /**
         * 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;
        }
 
@@ -305,9 +342,48 @@ public abstract class OpenObject implements Proxy {
 
        /**
         * Set the menu.
-        * @param menu the menu to set
+        * 
+        * @param menu
+        *            the menu to set
         */
        public void setMenu(Menu menu) {
                this.menu = menu;
        }
+
+       /**
+        * Get the projectElementService.
+        * 
+        * @return the projectElementService
+        */
+       public ProjectElementService getProjectElementService() {
+               return _projectElementService;
+       }
+
+       /**
+        * Set the projectElementService.
+        * 
+        * @param projectElementService
+        *            the projectElementService to set
+        */
+       public void setProjectElementService(
+                       ProjectElementService projectElementService) {
+               _projectElementService = projectElementService;
+       }
+
+       /**
+        * Get the knowledgeElementTypeService.
+        * @return the knowledgeElementTypeService
+        */
+       public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+               return _knowledgeElementTypeService;
+       }
+
+       /**
+        * Set the knowledgeElementTypeService.
+        * @param knowledgeElementTypeService the knowledgeElementTypeService to set
+        */
+       public void setKnowledgeElementTypeService(
+                       KnowledgeElementTypeService knowledgeElementTypeService) {
+               _knowledgeElementTypeService = knowledgeElementTypeService;
+       }
 }
\ No newline at end of file
index 42247c11943b68480b8165220e28c297279efd5c..dd9937e34ec299c5d64a047d9e67e8cc1c27632b 100644 (file)
@@ -1,4 +1,5 @@
 package org.splat.simer;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
@@ -26,9 +27,9 @@ import org.splat.dal.bo.som.Document;
 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.ScenarioService;
+import org.splat.service.DocumentTypeService;
 import org.splat.service.StepService;
+import org.splat.service.StudyService;
 import org.splat.service.technical.RepositoryService;
 import org.splat.dal.bo.som.Publication;
 import org.splat.som.Revision;
@@ -38,32 +39,22 @@ import org.splat.som.Step;
 import org.splat.som.StepRights;
 import org.splat.dal.bo.som.Study;
 import org.splat.som.StudyRights;
-import org.splat.wapp.Menu;
 import org.splat.wapp.ToolBar;
 
-
 public class OpenStudy extends OpenObject implements OpenStudyServices {
 
        /**
         * Serial version ID.
         */
-       protected final static Logger   logger = org.splat.simer.Action.logger;
-    
-    private  Study       mystudy;
-    private  StudyRights urightstudy;              // User rights on the open study
-       private  StepRights  urightstep;               // User rights on the selected step
-    private  String      version;
-    private  String      credate;
-    private  String      lasdate;
-    private  Publication selecdoc;
-       /**
-        * Injected project element service.
-        */
-       private ProjectElementService _projectElementService;
-       /**
-        * Injected scenario service.
-        */
-       private ScenarioService _scenarioService;
+       protected final static Logger logger = org.splat.simer.Action.logger;
+
+       private Study mystudy;
+       private StudyRights urightstudy; // User rights on the open study
+       private StepRights urightstep; // User rights on the selected step
+       private String version;
+       private String credate;
+       private String lasdate;
+       private Publication selecdoc;
        /**
         * Injected step service.
         */
@@ -72,418 +63,450 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
         * Injected repository service.
         */
        private RepositoryService _repositoryService;
-//  ==============================================================================================================================
-//  Constructor
-//  ==============================================================================================================================
-
-    /**
-     * Open the given study in the current http session.
-     * @param user the current user
-     * @param study the study to open
-     * @return this open study object
-     */
-    public OpenStudy open (User user, Study study) {
-//  -----------------------------------------
-      ResourceBundle    custom    = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
-      SimpleDateFormat  datstring = new SimpleDateFormat(custom.getString("date.format"));
-      Revision.Format   verstring = new Revision.Format(getProjectSettings().getRevisionPattern());
-        
-      cuser       = user;                           // May be null if nobody connected
-      mystudy     = study;
-      selection   = "0.1";                          // Default selection
-      selecdoc    = null;
-
-//    Preparation of the display
-      version     = verstring.format(mystudy.getVersion());
-      credate     = datstring.format(mystudy.getDate());
-      lasdate     = "";                             // Not yet supported
-      description = mystudy.getDescription();
-      involving   = new ArrayList<Step>(1);
-      context     = new ArrayList<SimulationContextFacade>();
-      ustep       = getProjectElementService().getFirstStep(mystudy);
-      ustep.setActor(cuser);
-      involving.add(ustep);
-      for (Iterator<SimulationContext> i=ustep.getAllSimulationContexts().iterator(); i.hasNext(); ) {
-        context.add( new SimulationContextFacade(i.next(), getProjectSettings().getAllSteps()) );
-      }
-      if (mystudy.isStaffedBy(cuser) || mystudy.hasActor(cuser)) {
-//     ProgressState state = mystudy.getProgressState();
-//         if           (state == ProgressState.inCHECK)  popup = ApplicationSettings.getPopupMenu("stapprovable");
-//         else if      (state == ProgressState.APPROVED) popup = ApplicationSettings.getPopupMenu("stapproved");
-/*      else         */                                popup = ApplicationSettings.getPopupMenu("steditable");
-           popup.setContext("study", new StudyRights(cuser, mystudy));
-      }
-      urightstudy = new StudyRights(cuser, mystudy);
-      urightstep  = new StepRights(cuser, ustep);
-
-//RKV      menu = new StudyMenu(mystudy);
-      menu = ((StudyMenu)getMenu()).init(mystudy); //RKV
-      menu.selects(selection);                      // Initializes menu items to be displayed
-      setupContents();                              // Initializes documents and knowledge at ustep
-      return this;
-    }
-
-//  ==============================================================================================================================
-//  Getters
-//  ==============================================================================================================================
-
-       public String getAuthorName() {
-//  -----------------------------
-      return mystudy.getAuthor().toString();
-    }
-    public Long getIndex() {
-//  -------------------------
-      return mystudy.getIndex();
-    }
-    public String getDate () {
-//  ------------------------
-      return credate;
-    }
-    public StudyMenu getMenu () {
-//  ---------------------------
-      return (StudyMenu)menu;
-    }
-    public ProgressState getProgressState() {
-//  ----------------------------------------
-      return mystudy.getProgressState();
-    }
-    public String getLastModificationDate () {
-//  ----------------------------------------
-      return lasdate;
-    }
-    public ToolBar getModuleBar () {
-//  ------------------------------
-      return ApplicationSettings.getMe().getModuleBar(getSelectedStep());
-    }
-    public String getReference() {
-//  ----------------------------
-      return mystudy.getReference();
-    }
-    public Publication getSelectedDocument () {
-//  -----------------------------------------
-      return selecdoc;
-    }
-    public StepRights getSelectedStepRights () {
-//  ------------------------------------------
-      return urightstep;
-    }
-    public StudyRights getStudyRights () {
-//  ------------------------------------
-      return urightstudy;
-    }
-    public Study getStudyObject () {
-//  ------------------------------
-      return mystudy;
-    }
-    public String getTitle() {
-//  ------------------------
-      return mystudy.getTitle();
-    }
-    public String getType () {
-//  ------------------------
-      return ResourceBundle.getBundle("labels", ApplicationSettings.getCurrentLocale()).getString("label.study");
-    }
-    public String getVersion () {
-//  ---------------------------
-      return version;
-    }
-    public boolean isStepEnabled () {
-//  -------------------------------
-      return urightstep.isEnabled();
-    }
-
-//  ==============================================================================================================================
-//  Public services
-//  ==============================================================================================================================
-
-    public URL newTemplateBasedDocument (String typename, User author) {
-//  ------------------------------------------------------------------
-      String filename = typename + ".xml";     // Only XML templates are writeable
-      File   template = new File(getRepositoryService().getTemplatePath() + filename);      
-      if   (!template.exists()) return null;
-      
-      Session      connex  = Database.getSession();
-         Transaction  transax = connex.beginTransaction();
-      try {
-        File  udir   = getRepositoryService().getDownloadDirectory(author);
-        File  credoc = new File(udir.getPath() + "/" + filename);
-
-//      Creation of the meta-document
-        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 = getStepService().createDocument(step, dprop.setType(type).setFormat("xml").setAuthor(author)).value();
-        transax.commit();
-
-//      Instantiation of the template into the user download directory
-       if (!udir.exists())  udir.mkdir();
-       if (credoc.exists()) credoc.delete();
-        Do.copy(template, credoc);
-
-//      Transfer to the document of all known properties
-        ResourceBundle   locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
-        SimpleDateFormat get    = new SimpleDateFormat(locale.getString("date.format"));
-        Writer           tool   = Toolbox.getWriter(credoc);
-        List<Step>       slist  = getInvolvedSteps();
-        for (Iterator<Step> i=slist.iterator(); i.hasNext(); ) {
-          List<SimulationContext>            clist = i.next().getAllSimulationContexts();
-          for (Iterator<SimulationContext> j=clist.iterator(); j.hasNext(); ) {
-            SimulationContext   context = j.next();
-            tool.updateProperty(context.getType().getName(), context.getValue());
-          }
-        }
-        tool.updateProperty("reference", medoc.getReference());
-        tool.updateProperty("study",     mystudy.getTitle());
-        tool.updateProperty("step",      locale.getString("folder.step." + step.getNumber()).replaceAll("''", "'"));
-        tool.updateProperty("author",    author.getUsername().toUpperCase());
-        tool.updateProperty("date",      get.format(medoc.getCreationDate()));
-        tool.updateProperty("history",   locale.getString("label.creation").replaceAll("''", "'"));
-        tool.save();
-
-        return new URL(ApplicationSettings.getDownloadURL(author) + filename);
-      }
-      catch (Exception saverror) {
-        logger.error("Reason:", saverror);
-        if (transax != null && transax.isActive()) {
-//        Second try-catch as the rollback could fail as well
-          try {
-               transax.rollback();
-          } catch (HibernateException backerror) {
-            logger.debug("Error rolling back transaction", backerror);
-          }
-        }
-        return null;
-      }
-    }
-
-    public void selectDocument (String docurl) {
-//  ------------------------------------------
-      String  prefix = ApplicationSettings.getRepositoryURL();
-      
-      if (docurl.startsWith(prefix)) try {
-        Session      connex  = Database.getSession();
-        Transaction  transax = connex.beginTransaction();
-        String       path    = docurl.substring(prefix.length());
-        String[]     parse   = path.split("'");
-      
-        path = parse[0];
-        for (int i=1; i<parse.length; i++) path = path + "''" + parse[i];
-//      Better call Database.selectDocument(path), but this service does not exist (overloading issue)
-        String       query   = "from Document where path='" + path + "'";
-        Document     value   = (Document)Database.getSession().createQuery(query).uniqueResult();
-
-        selecdoc = ustep.getDocument(value.getIndex());
-        transax.commit();
-      }
-      catch (Exception error) {
-        logger.error("Reason:", error);
-      }
-    }
-
-    public void setSelection (String step) {
-//  --------------------------------------
-      if (!step.equals(selection)) {
-        selection = step;
-        selecdoc  = null;
-        setupPreviousToSelectedSteps();
-        updateSimulationContexts();                 // Initializes contexts according to the selected steps
-      }
-      ustep      = involving.get(involving.size()-1);
-      urightstep = new StepRights(cuser, ustep);
-      ustep.setActor(cuser);
-      menu.selects(selection);                      // Updates menu items to be displayed
-      setupContents();                              // The contents may have changed even if the selection is the same
-    }    
-
-//  ==============================================================================================================================
-//  Protected services
-//  ==============================================================================================================================
-
-    protected void add (Publication doc) {
-//  ------------------------------------
-         DocumentFacade  facade = new DocumentFacade(this, doc, getProjectSettings(), getPublicationService());
-         boolean         first  = (contents.size() == 0);
-
-      docpres.put(doc.getIndex(), facade);
-      contents.add(0, facade);                          // Prepend the new publication
-      if (first) this.getMenu().refreshSelectedItem();
-
-    }
-
-    protected void add (SimulationContext contex) {
-//  ---------------------------------------------
-      SimulationContextFacade  facade = new SimulationContextFacade(contex, getProjectSettings().getAllSteps());
-
-      context.add(facade);
-    }
-
-    protected void add (KnowledgeElement kelm) {
-//  ------------------------------------------
-      KnowledgeElementFacade  facade = new KnowledgeElementFacade(kelm);
-//RKV      KnowledgeIterator       known  = knowledge.get(kelm.getType().getIndex() - 2);
-                                   // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
-      //RKV:Begin: Find a knowledge iterator for appropriate knowledge type
-      KnowledgeIterator       known  = null;
-      for (KnowledgeIterator aKnowledgeSection : knowledge) {
-         if (aKnowledgeSection.getIndex().equals(String.valueOf(kelm.getType().getIndex()))) {
-                 known = aKnowledgeSection;
-                 break;
-         }
-      }
-      if (known != null) { //RKV:End
-             knowpres.put(kelm.getIndex(), facade);
-             known.list.add(facade);       // Insert the new knowledge at the end of the corresponding knowledge type
-      }
-    }
-
-    protected void remove (Publication doctag) {
-//  ------------------------------------------
-      for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext(); ) {
-        DocumentFacade  facade = i.next();
-        if (!facade.isFacadeOf(doctag)) continue;
-        i.remove();
-        break;
-      }
-      if (contents.size() == 0) this.getMenu().refreshSelectedItem();
-    }
-
-    protected void changeUser (User user) {
-//  -------------------------------------
-      cuser = user;
-      popup = null;
-      if (mystudy.isStaffedBy(cuser)) {
-        popup = ApplicationSettings.getPopupMenu("steditable");
-           popup.setContext("study", new StudyRights(cuser, mystudy));
-      }
-      ustep.setActor(cuser);
-      urightstudy = new StudyRights(cuser, mystudy);
-      urightstep  = new StepRights(cuser, ustep);
-    }
-
-    protected void remove (SimulationContext contex) {
-//  ------------------------------------------------
-      for (Iterator<SimulationContextFacade> i=context.iterator(); i.hasNext(); ) {
-        SimulationContextFacade  facade = i.next();
-        if (!facade.isFacadeOf(contex)) continue;
-        i.remove();
-        break;
-      }
-    }
-
-    protected void remove (KnowledgeElement kelm) {
-//  ---------------------------------------------
-      KnowledgeIterator       known  = knowledge.get((int)(kelm.getType().getIndex() - 2));
-                                   // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
-      knowpres.remove(kelm.getIndex());
-      for (Iterator<KnowledgeElementFacade> i=known.list.iterator(); i.hasNext(); ) {
-        KnowledgeElementFacade facade = i.next();
-        if (!facade.isFacadeOf(kelm)) continue;
-        i.remove();
-        break;
-      }
-    }
-
-    protected void update (Publication doc) {
-//  ---------------------------------------
-      DocumentFacade facade = docpres.get(doc.getIndex());
-         if (facade != null) {
-               facade.refresh();
-         }
-    }
-
-    protected void update (KnowledgeElement kelm) {
-//  ---------------------------------------------
-         KnowledgeElementFacade facade = knowpres.get(kelm.getIndex());
-         if (facade != null) {
-               facade.refresh();
-         }
-    }
-
-    protected void updateSimulationContexts () {
-//  ------------------------------------------
-      context.clear();
-      for (Iterator<Step> i=involving.iterator(); i.hasNext(); ) {
-        for (Iterator<SimulationContext> j=i.next().getAllSimulationContexts().iterator(); j.hasNext(); ) {
-          context.add( new SimulationContextFacade(j.next(), getProjectSettings().getAllSteps()) );
-        }
-      }
-    }
-
-//  ==============================================================================================================================
-//  Private services
-//  ==============================================================================================================================
-
-    private void setupPreviousToSelectedSteps () {
-//  --------------------------------------------
-      String[] item   = selection.split("\\x2E");
-      int      major  = Integer.valueOf(item[0]);
-      int      minor  = Integer.valueOf(item[1]);
-      int      base   = minor;
-      Step[]   step;
-
-      involving.clear();
-      if (major > 0) {
-       Scenario[] branch = mystudy.getScenarii();
-       Scenario   scenar = branch[0];
-       for (int i=0; i<branch.length; i++) {
-          scenar = branch[i];
-          if (scenar.getIndex() == major) break;      // Supposed exist
-       }
-       step = getProjectElementService().getSteps(scenar);
-       base = step[0].getNumber() - 1;
-       for (int i=0; i+base<minor; i++) {
-               involving.add(step[i]);
-       }
-      }
-      step = getProjectElementService().getSteps(mystudy);
-      for (int i=step.length-1; i>-1; i--) {
-         Step firstep = step[i];
-         if(firstep.getNumber() > base) continue;
-         involving.add(0, firstep);
-      }
-    }
-    
-    /**
-        * Get the projectElementService.
-        * 
-        * @return the projectElementService
+       /**
+        * Injected document type service.
         */
-       public ProjectElementService getProjectElementService() {
-               return _projectElementService;
-       }
+       private DocumentTypeService _documentTypeService;
 
        /**
-        * Set the projectElementService.
-        * 
-        * @param projectElementService
-        *            the projectElementService to set
+        * The injected Study service.
         */
-       public void setProjectElementService(
-                       ProjectElementService projectElementService) {
-               _projectElementService = projectElementService;
-       }
+       private StudyService _studyService;
+
+       // ==============================================================================================================================
+       // Constructor
+       // ==============================================================================================================================
 
        /**
-        * Get the scenarioService.
+        * Open the given study in the current http session.
         * 
-        * @return the scenarioService
+        * @param user
+        *            the current user
+        * @param study
+        *            the study to open
+        * @return this open study object
         */
-       public ScenarioService getScenarioService() {
-               return _scenarioService;
+       public OpenStudy open(User user, Study study) {
+               // -----------------------------------------
+               ResourceBundle custom = ResourceBundle.getBundle("som",
+                               ApplicationSettings.getCurrentLocale());
+               SimpleDateFormat datstring = new SimpleDateFormat(custom
+                               .getString("date.format"));
+               Revision.Format verstring = new Revision.Format(getProjectSettings()
+                               .getRevisionPattern());
+
+               cuser = user; // May be null if nobody connected
+               mystudy = study;
+               selection = "0.1"; // Default selection
+               selecdoc = null;
+
+               // Preparation of the display
+               version = verstring.format(mystudy.getVersion());
+               credate = datstring.format(mystudy.getDate());
+               lasdate = ""; // Not yet supported
+               description = mystudy.getDescription();
+               involving = new ArrayList<Step>(1);
+               context = new ArrayList<SimulationContextFacade>();
+               ustep = getProjectElementService().getFirstStep(mystudy);
+               ustep.setActor(cuser);
+               involving.add(ustep);
+               for (Iterator<SimulationContext> i = ustep.getAllSimulationContexts()
+                               .iterator(); i.hasNext();) {
+                       context.add(new SimulationContextFacade(i.next(),
+                                       getProjectSettings().getAllSteps()));
+               }
+               if (getStudyService().isStaffedBy(mystudy, cuser) || getStudyService().hasActor(mystudy, cuser)) {
+                       // ProgressState state = mystudy.getProgressState();
+                       // if (state == ProgressState.inCHECK) popup = ApplicationSettings.getPopupMenu("stapprovable");
+                       // else if (state == ProgressState.APPROVED) popup = ApplicationSettings.getPopupMenu("stapproved");
+                       /* else */popup = ApplicationSettings
+                                       .getPopupMenu("steditable");
+                       popup.setContext("study", new StudyRights(cuser, mystudy));
+               }
+               urightstudy = new StudyRights(cuser, mystudy);
+               urightstep = new StepRights(cuser, ustep);
+
+               // RKV menu = new StudyMenu(mystudy);
+               menu = ((StudyMenu) getMenu()).init(mystudy); // RKV
+               menu.selects(selection); // Initializes menu items to be displayed
+               setupContents(); // Initializes documents and knowledge at ustep
+               return this;
        }
 
-       /**
-        * Set the scenarioService.
-        * 
-        * @param scenarioService
-        *            the scenarioService to set
-        */
-       public void setScenarioService(ScenarioService scenarioService) {
-               _scenarioService = scenarioService;
+       // ==============================================================================================================================
+       // Getters
+       // ==============================================================================================================================
+
+       public String getAuthorName() {
+               // -----------------------------
+               return mystudy.getAuthor().toString();
+       }
+
+       public Long getIndex() {
+               // -------------------------
+               return mystudy.getIndex();
+       }
+
+       public String getDate() {
+               // ------------------------
+               return credate;
+       }
+
+       public StudyMenu getMenu() {
+               // ---------------------------
+               return (StudyMenu) menu;
+       }
+
+       public void setMenu(StudyMenu aMenu) {
+               menu = aMenu;
+       }
+
+       public ProgressState getProgressState() {
+               // ----------------------------------------
+               return mystudy.getProgressState();
+       }
+
+       public String getLastModificationDate() {
+               // ----------------------------------------
+               return lasdate;
+       }
+
+       public ToolBar getModuleBar() {
+               // ------------------------------
+               return ApplicationSettings.getMe().getModuleBar(getSelectedStep());
+       }
+
+       public String getReference() {
+               // ----------------------------
+               return mystudy.getReference();
+       }
+
+       public Publication getSelectedDocument() {
+               // -----------------------------------------
+               return selecdoc;
+       }
+
+       public StepRights getSelectedStepRights() {
+               // ------------------------------------------
+               return urightstep;
+       }
+
+       public StudyRights getStudyRights() {
+               // ------------------------------------
+               return urightstudy;
+       }
+
+       public Study getStudyObject() {
+               // ------------------------------
+               return mystudy;
+       }
+
+       public String getTitle() {
+               // ------------------------
+               return mystudy.getTitle();
+       }
+
+       public String getType() {
+               // ------------------------
+               return ResourceBundle.getBundle("labels",
+                               ApplicationSettings.getCurrentLocale())
+                               .getString("label.study");
+       }
+
+       public String getVersion() {
+               // ---------------------------
+               return version;
+       }
+
+       public boolean isStepEnabled() {
+               // -------------------------------
+               return urightstep.isEnabled();
+       }
+
+       // ==============================================================================================================================
+       // Public services
+       // ==============================================================================================================================
+
+       public URL newTemplateBasedDocument(String typename, User author) {
+               // ------------------------------------------------------------------
+               String filename = typename + ".xml"; // Only XML templates are writeable
+               File template = new File(getRepositoryService().getTemplatePath()
+                               + filename);
+               if (!template.exists())
+                       return null;
+
+               Session connex = Database.getSession();
+               Transaction transax = connex.beginTransaction();
+               try {
+                       File udir = getRepositoryService().getDownloadDirectory(author);
+                       File credoc = new File(udir.getPath() + "/" + filename);
+
+                       // Creation of the meta-document
+                       Step step = getSelectedStep(); // Should we check if the given document type is compatible ?
+                       DocumentType type = getDocumentTypeService().selectType(typename);
+                       Document.Properties dprop = new Document.Properties();
+                       Document medoc = getStepService().createDocument(step,
+                                       dprop.setType(type).setFormat("xml").setAuthor(author))
+                                       .value();
+                       transax.commit();
+
+                       // Instantiation of the template into the user download directory
+                       if (!udir.exists())
+                               udir.mkdir();
+                       if (credoc.exists())
+                               credoc.delete();
+                       Do.copy(template, credoc);
+
+                       // Transfer to the document of all known properties
+                       ResourceBundle locale = ResourceBundle.getBundle("som",
+                                       ApplicationSettings.getCurrentLocale());
+                       SimpleDateFormat get = new SimpleDateFormat(locale
+                                       .getString("date.format"));
+                       Writer tool = Toolbox.getWriter(credoc);
+                       List<Step> slist = getInvolvedSteps();
+                       for (Iterator<Step> i = slist.iterator(); i.hasNext();) {
+                               List<SimulationContext> clist = i.next()
+                                               .getAllSimulationContexts();
+                               for (Iterator<SimulationContext> j = clist.iterator(); j
+                                               .hasNext();) {
+                                       SimulationContext context = j.next();
+                                       tool.updateProperty(context.getType().getName(), context
+                                                       .getValue());
+                               }
+                       }
+                       tool.updateProperty("reference", medoc.getReference());
+                       tool.updateProperty("study", mystudy.getTitle());
+                       tool.updateProperty("step", locale.getString(
+                                       "folder.step." + step.getNumber()).replaceAll("''", "'"));
+                       tool.updateProperty("author", author.getUsername().toUpperCase());
+                       tool.updateProperty("date", get.format(medoc.getCreationDate()));
+                       tool.updateProperty("history", locale.getString("label.creation")
+                                       .replaceAll("''", "'"));
+                       tool.save();
+
+                       return new URL(ApplicationSettings.getDownloadURL(author)
+                                       + filename);
+               } catch (Exception saverror) {
+                       logger.error("Reason:", saverror);
+                       if (transax != null && transax.isActive()) {
+                               // Second try-catch as the rollback could fail as well
+                               try {
+                                       transax.rollback();
+                               } catch (HibernateException backerror) {
+                                       logger.debug("Error rolling back transaction", backerror);
+                               }
+                       }
+                       return null;
+               }
+       }
+
+       public void selectDocument(String docurl) {
+               // ------------------------------------------
+               String prefix = ApplicationSettings.getRepositoryURL();
+
+               if (docurl.startsWith(prefix))
+                       try {
+                               Session connex = Database.getSession();
+                               Transaction transax = connex.beginTransaction();
+                               String path = docurl.substring(prefix.length());
+                               String[] parse = path.split("'");
+
+                               path = parse[0];
+                               for (int i = 1; i < parse.length; i++)
+                                       path = path + "''" + parse[i];
+                               // Better call Database.selectDocument(path), but this service does not exist (overloading issue)
+                               String query = "from Document where path='" + path + "'";
+                               Document value = (Document) Database.getSession().createQuery(
+                                               query).uniqueResult();
+
+                               selecdoc = ustep.getDocument(value.getIndex());
+                               transax.commit();
+                       } catch (Exception error) {
+                               logger.error("Reason:", error);
+                       }
+       }
+
+       public void setSelection(String step) {
+               // --------------------------------------
+               if (!step.equals(selection)) {
+                       selection = step;
+                       selecdoc = null;
+                       setupPreviousToSelectedSteps();
+                       updateSimulationContexts(); // Initializes contexts according to the selected steps
+               }
+               ustep = involving.get(involving.size() - 1);
+               urightstep = new StepRights(cuser, ustep);
+               ustep.setActor(cuser);
+               menu.selects(selection); // Updates menu items to be displayed
+               setupContents(); // The contents may have changed even if the selection is the same
+       }
+
+       // ==============================================================================================================================
+       // Protected services
+       // ==============================================================================================================================
+
+       protected void add(Publication doc) {
+               // ------------------------------------
+               DocumentFacade facade = new DocumentFacade(this, doc,
+                               getProjectSettings(), getPublicationService());
+               boolean first = (contents.size() == 0);
+
+               docpres.put(doc.getIndex(), facade);
+               contents.add(0, facade); // Prepend the new publication
+               if (first)
+                       this.getMenu().refreshSelectedItem();
+
+       }
+
+       protected void add(SimulationContext contex) {
+               // ---------------------------------------------
+               SimulationContextFacade facade = new SimulationContextFacade(contex,
+                               getProjectSettings().getAllSteps());
+
+               context.add(facade);
+       }
+
+       protected void add(KnowledgeElement kelm) {
+               // ------------------------------------------
+               KnowledgeElementFacade facade = new KnowledgeElementFacade(kelm);
+               // RKV KnowledgeIterator known = knowledge.get(kelm.getType().getIndex() - 2);
+               // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
+               // RKV:Begin: Find a knowledge iterator for appropriate knowledge type
+               KnowledgeIterator known = null;
+               for (KnowledgeIterator aKnowledgeSection : knowledge) {
+                       if (aKnowledgeSection.getIndex().equals(
+                                       String.valueOf(kelm.getType().getIndex()))) {
+                               known = aKnowledgeSection;
+                               break;
+                       }
+               }
+               if (known != null) { // RKV:End
+                       knowpres.put(kelm.getIndex(), facade);
+                       known.list.add(facade); // Insert the new knowledge at the end of the corresponding knowledge type
+               }
+       }
+
+       protected void remove(Publication doctag) {
+               // ------------------------------------------
+               for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
+                       DocumentFacade facade = i.next();
+                       if (!facade.isFacadeOf(doctag))
+                               continue;
+                       i.remove();
+                       break;
+               }
+               if (contents.size() == 0)
+                       this.getMenu().refreshSelectedItem();
+       }
+
+       protected void changeUser(User user) {
+               // -------------------------------------
+               cuser = user;
+               popup = null;
+               if (getStudyService().isStaffedBy(mystudy, cuser)) {
+                       popup = ApplicationSettings.getPopupMenu("steditable");
+                       popup.setContext("study", new StudyRights(cuser, mystudy));
+               }
+               ustep.setActor(cuser);
+               urightstudy = new StudyRights(cuser, mystudy);
+               urightstep = new StepRights(cuser, ustep);
+       }
+
+       protected void remove(SimulationContext contex) {
+               // ------------------------------------------------
+               for (Iterator<SimulationContextFacade> i = context.iterator(); i
+                               .hasNext();) {
+                       SimulationContextFacade facade = i.next();
+                       if (!facade.isFacadeOf(contex))
+                               continue;
+                       i.remove();
+                       break;
+               }
+       }
+
+       protected void remove(KnowledgeElement kelm) {
+               // ---------------------------------------------
+               KnowledgeIterator known = knowledge.get((int) (kelm.getType()
+                               .getIndex() - 2));
+               // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
+               knowpres.remove(kelm.getIndex());
+               for (Iterator<KnowledgeElementFacade> i = known.list.iterator(); i
+                               .hasNext();) {
+                       KnowledgeElementFacade facade = i.next();
+                       if (!facade.isFacadeOf(kelm))
+                               continue;
+                       i.remove();
+                       break;
+               }
+       }
+
+       protected void update(Publication doc) {
+               // ---------------------------------------
+               DocumentFacade facade = docpres.get(doc.getIndex());
+               if (facade != null) {
+                       facade.refresh();
+               }
+       }
+
+       protected void update(KnowledgeElement kelm) {
+               // ---------------------------------------------
+               KnowledgeElementFacade facade = knowpres.get(kelm.getIndex());
+               if (facade != null) {
+                       facade.refresh();
+               }
+       }
+
+       protected void updateSimulationContexts() {
+               // ------------------------------------------
+               context.clear();
+               for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
+                       for (Iterator<SimulationContext> j = i.next()
+                                       .getAllSimulationContexts().iterator(); j.hasNext();) {
+                               context.add(new SimulationContextFacade(j.next(),
+                                               getProjectSettings().getAllSteps()));
+                       }
+               }
+       }
+
+       // ==============================================================================================================================
+       // Private services
+       // ==============================================================================================================================
+
+       private void setupPreviousToSelectedSteps() {
+               // --------------------------------------------
+               String[] item = selection.split("\\x2E");
+               int major = Integer.valueOf(item[0]);
+               int minor = Integer.valueOf(item[1]);
+               int base = minor;
+               Step[] step;
+
+               involving.clear();
+               if (major > 0) {
+                       Scenario[] branch = mystudy.getScenarii();
+                       Scenario scenar = branch[0];
+                       for (int i = 0; i < branch.length; i++) {
+                               scenar = branch[i];
+                               if (scenar.getIndex() == major)
+                                       break; // Supposed exist
+                       }
+                       step = getProjectElementService().getSteps(scenar);
+                       base = step[0].getNumber() - 1;
+                       for (int i = 0; i + base < minor; i++) {
+                               involving.add(step[i]);
+                       }
+               }
+               step = getProjectElementService().getSteps(mystudy);
+               for (int i = step.length - 1; i > -1; i--) {
+                       Step firstep = step[i];
+                       if (firstep.getNumber() > base)
+                               continue;
+                       involving.add(0, firstep);
+               }
        }
 
        /**
         * Get the stepService.
+        * 
         * @return the stepService
         */
        public StepService getStepService() {
@@ -492,7 +515,9 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
 
        /**
         * Set the stepService.
-        * @param stepService the stepService to set
+        * 
+        * @param stepService
+        *            the stepService to set
         */
        public void setStepService(StepService stepService) {
                _stepService = stepService;
@@ -500,6 +525,7 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
 
        /**
         * Get the repositoryService.
+        * 
         * @return the repositoryService
         */
        public RepositoryService getRepositoryService() {
@@ -508,9 +534,46 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
 
        /**
         * Set the repositoryService.
-        * @param repositoryService the repositoryService to set
+        * 
+        * @param repositoryService
+        *            the repositoryService to set
         */
        public void setRepositoryService(RepositoryService repositoryService) {
                _repositoryService = repositoryService;
        }
+
+       /**
+        * Get the documentTypeService.
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * @param documentTypeService the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
+
+       /**
+        * 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;
+       }
 }
\ No newline at end of file
index 096b5ed4d07a23a42abe57bdfb4cb95f4a35be53..33f39b2391484eb7bd01234bb9998add5316c56f 100644 (file)
@@ -3,14 +3,12 @@ package org.splat.simer;
 import java.util.List;
 import java.util.Map;
 
-import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.dal.bo.kernel.User;
 import org.splat.kernel.UserDirectory;
+import org.splat.service.KnowledgeElementTypeService;
 import org.splat.service.SearchService;
 import org.splat.service.SimulationContextService;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.ProgressState;
@@ -18,207 +16,236 @@ import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.bo.som.Visibility;
 
-
+/**
+ * Action for searching a knowledge in the database.
+ */
 public class SearchKnowledgeAction extends SearchBaseAction {
 
-    private String                       visibility = null;   // "Private", "Public", "All"
-    private String                       typid      = null;   // Knowledge type index when among all
-    private String                       matchamong = null;   // "all" or "any"
-    private String                       matcontext = null;   // "all" or "any"
-    private String                       refid      = null;   // Knowledge reference  when among ref
-    private String                       words      = null;   // Full text search words
-    private List<KnowledgeElementType>   types;            // Available knowledge types filter (initialized below)
-    private SearchService                _searchService;
+       /**
+        * Serial version ID.
+        */
+       private static final long serialVersionUID = -3104321907432838476L;
+
+       private String visibility = null; // "Private", "Public", "All"
+       private String typid = null; // Knowledge type index when among all
+       private String matchamong = null; // "all" or "any"
+       private String matcontext = null; // "all" or "any"
+       private String refid = null; // Knowledge reference when among ref
+       private String words = null; // Full text search words
+       private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
+       private SearchService _searchService;
        /**
         * Injected simulation context service.
         */
        private SimulationContextService _simulationContextService;
+       /**
+        * Injected knowledge element service.
+        */
+       private KnowledgeElementTypeService _knowledgeElementTypeService;
+
+       // ==============================================================================================================================
+       // Action methods
+       // ==============================================================================================================================
 
        /**
-        * Serial version ID.
+        * The action initialization.
+        * 
+        * @return SUCCESS if succeeded, ERROR if doSearch() is failed
         */
-       private static final long serialVersionUID = -3104321907432838476L;
+       public String doInitialize() {
+               try {
+                       loadFilter();
+                       doSearch();
+
+                       // Final initialization of the form
+                       types = getKnowledgeElementTypeService().selectTypesWhere(
+                                       ProgressState.APPROVED);
+                       setCandidates();
+                       setContextTypeOptions(getInvolvedContexts());
+
+                       return SUCCESS;
+               } catch (Exception error) {
+                       // No need to roll back the transaction as it is read only
+                       logger.error("Reason: ", error);
+                       return ERROR;
+               }
+       }
 
-//  ==============================================================================================================================
-//  Action methods
-//  ==============================================================================================================================
-
-       public String doInitialize () {
-//  -----------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();      
-      try {
-        loadFilter();          
-        doSearch();
-
-//      Final initialization of the form
-        types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
-        setCandidates();
-        setContextTypeOptions(getInvolvedContexts());
-
-        transax.commit();
-        return SUCCESS;
-      }
-      catch (Exception error) {
-//         No need to roll back the transaction as it is read only
-       logger.error("Reason: ", error);
-        return ERROR;
-      }
-       }
-
-       protected String doSearch () throws InvalidPropertyException {
-//  ----------------------------
-      Map<String, Object> session = getSession();
-      User                user    = getConnectedUser();
-
-      KnowledgeElement.Properties  sprop = new KnowledgeElement.Properties();
-
-//    Search matching all criteria
-        sprop.setType( KnowledgeElement.selectType(Integer.valueOf(typid)) );
-        if (words.length() > 0)          sprop.setTitle(words);
-        if (refid.length() > 0)          sprop.setReference(refid);
-        if (context.size() > 0)          sprop.setSimulationContexts(context);
-        int index = Integer.valueOf(author);
-        if (index > 0) {
-          User him = UserDirectory.selectUser(index);
-          sprop.setAuthor(him);
-        }
-//      Set of the visibility
-        if (visibility.equals("all")) {
-          KnowledgeElement.Properties  other = sprop.copy();
-
-          other.setVisibility(Visibility.PUBLIC);
-          sprop.setVisibility(Visibility.PRIVATE);
-          sprop.setActor(user);
-
-          result = getSearchService().selectKnowledgeElementsWhere(sprop, other);
-        }
-        else {
-          Visibility reparea = null;
-          if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
-          else                                 reparea = Visibility.valueOf(visibility);
-          sprop.setVisibility(reparea);
-          if (reparea == Visibility.PRIVATE) sprop.setActor(user);
-
-          result = getSearchService().selectKnowledgeElementsWhere(sprop);
-      }
-      session.put("search.result", result);     // For redisplaying the page without re-executing the search
-      return "refresh";
-       }
-
-//  ==============================================================================================================================
-//  Getters
-//  ==============================================================================================================================
-
-    public String getContextMatch () {
-//  --------------------------------
-      return matcontext;
-    }
-    public String getCriteriaMatch () {
-//  ---------------------------------
-      return matchamong;
-    }
-    public List<KnowledgeElementType> getKnowledgeTypes () {
-//  ------------------------------------------------------
-      return types;
-    }
-    public String getReference () {
-//  -----------------------------
-      return refid;
-    }
-    public String getState () {
-//  ------------------------
-      return typid;
-    }
-    public String getVisibility () {
-//  ------------------------------
-      return visibility;
-    }
-    public String getWords () {
-//  -------------------------
-      return words;
-    }
-
-//  ==============================================================================================================================
-//  Setters
-//  ==============================================================================================================================
-
-    public void setContextMatch (String value) {
-//  ------------------------------------------
-      this.matcontext = value;
-    }
-    public void setCriteriaMatch (String value) {
-//  -------------------------------------------
-      this.matchamong = value;
-    }
-    public void setReference (String value) {
-//  ---------------------------------------
-      this.refid = value;
-    }
-    public void setState (String value) {
-//  ----------------------------------
-      this.typid = value;
-    }
-    public void setVisibility (String value) {
-//  ----------------------------------------
-      this.visibility = value;
-    }
-    public void setWords (String value) {
-//  -----------------------------------
-      this.words = value;
-    }
-
-//  ==============================================================================================================================
-//  Implementation of abstract services
-//  ==============================================================================================================================
-
-       protected List<SimulationContextType> getInvolvedContexts () {
-//  ------------------------------------------------------------
-      return getSimulationContextService().selectAllTypes();
-       }
-
-    @SuppressWarnings("unchecked")
-       protected void loadFilter () {
-//  ----------------------------
-      Map<String,Object> session = getSession();
-      User               user    = getConnectedUser();
-      Map<String,Object> filter  = (Map<String, Object>)session.get("knowledge.filter");   // A default filter is supposed being set at start
-
-      visibility = (String)filter.get("visibility");
-      matchamong = (String)filter.get("matchamong");
-      matcontext = (String)filter.get("matcontext");
-      typid      = (String)filter.get("type");
-      author     = (String)filter.get("author");
-      refid      = (String)filter.get("reference");
-      words      = (String)filter.get("title");
-      context    = (List<SimulationContext>)filter.get("context");
-
-      if (user == null) {
-       visibility = "onlypublic";
-      }
-    }
+       protected String doSearch() throws InvalidPropertyException {
+               // ----------------------------
+               Map<String, Object> session = getSession();
+               User user = getConnectedUser();
+
+               KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
+
+               // Search matching all criteria
+               sprop.setType(getKnowledgeElementTypeService().selectType(
+                               Integer.valueOf(typid)));
+               if (words.length() > 0)
+                       sprop.setTitle(words);
+               if (refid.length() > 0)
+                       sprop.setReference(refid);
+               if (context.size() > 0)
+                       sprop.setSimulationContexts(context);
+               int index = Integer.valueOf(author);
+               if (index > 0) {
+                       User him = UserDirectory.selectUser(index);
+                       sprop.setAuthor(him);
+               }
+               // Set of the visibility
+               if (visibility.equals("all")) {
+                       KnowledgeElement.Properties other = sprop.copy();
+
+                       other.setVisibility(Visibility.PUBLIC);
+                       sprop.setVisibility(Visibility.PRIVATE);
+                       sprop.setActor(user);
+
+                       result = getSearchService().selectKnowledgeElementsWhere(sprop,
+                                       other);
+               } else {
+                       Visibility reparea = null;
+                       if (visibility.equals("onlypublic"))
+                               reparea = Visibility.PUBLIC;
+                       else
+                               reparea = Visibility.valueOf(visibility);
+                       sprop.setVisibility(reparea);
+                       if (reparea == Visibility.PRIVATE)
+                               sprop.setActor(user);
+
+                       result = getSearchService().selectKnowledgeElementsWhere(sprop);
+               }
+               session.put("search.result", result); // For redisplaying the page without re-executing the search
+               return "refresh";
+       }
 
-       @SuppressWarnings("unchecked")
-       protected void saveFilter () {
-//  ----------------------------
-      Map<String,Object> session = getSession();
-      Map<String,Object> filter  = (Map<String, Object>)session.get("knowledge.filter");   // A default filter is supposed being set at start
+       // ==============================================================================================================================
+       // Getters
+       // ==============================================================================================================================
 
-      filter.put("visibility", this.visibility);
-      filter.put("matchamong", this.matchamong);
-      filter.put("matcontext", this.matcontext);
-      filter.put("type",   this.typid);
-      filter.put("author", this.author);
-      filter.put("reference", "");
-      filter.put("title", this.words);
+       public String getContextMatch() {
+               // --------------------------------
+               return matcontext;
+       }
 
-      context = (List<SimulationContext>)filter.get("context");  // Only criteria not part of the form
+       public String getCriteriaMatch() {
+               // ---------------------------------
+               return matchamong;
+       }
+
+       public List<KnowledgeElementType> getKnowledgeTypes() {
+               // ------------------------------------------------------
+               return types;
+       }
+
+       public String getReference() {
+               // -----------------------------
+               return refid;
+       }
+
+       public String getState() {
+               // ------------------------
+               return typid;
+       }
 
-//    Initialization required by all do functions
-      types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
+       public String getVisibility() {
+               // ------------------------------
+               return visibility;
        }
-    /**
+
+       public String getWords() {
+               // -------------------------
+               return words;
+       }
+
+       // ==============================================================================================================================
+       // Setters
+       // ==============================================================================================================================
+
+       public void setContextMatch(String value) {
+               // ------------------------------------------
+               this.matcontext = value;
+       }
+
+       public void setCriteriaMatch(String value) {
+               // -------------------------------------------
+               this.matchamong = value;
+       }
+
+       public void setReference(String value) {
+               // ---------------------------------------
+               this.refid = value;
+       }
+
+       public void setState(String value) {
+               // ----------------------------------
+               this.typid = value;
+       }
+
+       public void setVisibility(String value) {
+               // ----------------------------------------
+               this.visibility = value;
+       }
+
+       public void setWords(String value) {
+               // -----------------------------------
+               this.words = value;
+       }
+
+       // ==============================================================================================================================
+       // Implementation of abstract services
+       // ==============================================================================================================================
+
+       protected List<SimulationContextType> getInvolvedContexts() {
+               // ------------------------------------------------------------
+               return getSimulationContextService().selectAllTypes();
+       }
+
+       @SuppressWarnings("unchecked")
+       protected void loadFilter() {
+               // ----------------------------
+               Map<String, Object> session = getSession();
+               User user = getConnectedUser();
+               Map<String, Object> filter = (Map<String, Object>) session
+                               .get("knowledge.filter"); // A default filter is supposed being set at start
+
+               visibility = (String) filter.get("visibility");
+               matchamong = (String) filter.get("matchamong");
+               matcontext = (String) filter.get("matcontext");
+               typid = (String) filter.get("type");
+               author = (String) filter.get("author");
+               refid = (String) filter.get("reference");
+               words = (String) filter.get("title");
+               context = (List<SimulationContext>) filter.get("context");
+
+               if (user == null) {
+                       visibility = "onlypublic";
+               }
+       }
+
+       @SuppressWarnings("unchecked")
+       protected void saveFilter() {
+               // ----------------------------
+               Map<String, Object> session = getSession();
+               Map<String, Object> filter = (Map<String, Object>) session
+                               .get("knowledge.filter"); // A default filter is supposed being set at start
+
+               filter.put("visibility", this.visibility);
+               filter.put("matchamong", this.matchamong);
+               filter.put("matcontext", this.matcontext);
+               filter.put("type", this.typid);
+               filter.put("author", this.author);
+               filter.put("reference", "");
+               filter.put("title", this.words);
+
+               context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
+
+               // Initialization required by all do functions
+               types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
+       }
+
+       /**
         * Get the searchService.
+        * 
         * @return the searchService
         */
        public SearchService getSearchService() {
@@ -227,7 +254,9 @@ public class SearchKnowledgeAction extends SearchBaseAction {
 
        /**
         * Set the searchService.
-        * @param searchService the searchService to set
+        * 
+        * @param searchService
+        *            the searchService to set
         */
        public void setSearchService(SearchService searchService) {
                _searchService = searchService;
@@ -252,4 +281,24 @@ public class SearchKnowledgeAction extends SearchBaseAction {
                        SimulationContextService simulationContextService) {
                _simulationContextService = simulationContextService;
        }
+
+       /**
+        * Get the knowledgeElementTypeService.
+        * 
+        * @return the knowledgeElementTypeService
+        */
+       public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+               return _knowledgeElementTypeService;
+       }
+
+       /**
+        * Set the knowledgeElementTypeService.
+        * 
+        * @param knowledgeElementTypeService
+        *            the knowledgeElementTypeService to set
+        */
+       public void setKnowledgeElementTypeService(
+                       KnowledgeElementTypeService knowledgeElementTypeService) {
+               _knowledgeElementTypeService = knowledgeElementTypeService;
+       }
 }
\ No newline at end of file
index c946aefbc45c9509510ac007df6c08a336fb9d74..5cb967c80f654e86d2c5409bc3a7227b666839c1 100644 (file)
@@ -10,354 +10,415 @@ import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.Name;
 import org.splat.dal.bo.kernel.User;
 import org.splat.kernel.UserDirectory;
+import org.splat.service.DocumentTypeService;
 import org.splat.service.StudyService;
 import org.splat.som.ApplicationRights;
 import org.splat.dal.dao.som.Database;
-import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.Study;
 import org.splat.som.StudyRights;
 import org.splat.dal.bo.som.ValidationCycle;
 import org.splat.dal.bo.som.ValidationStep;
 
-
+/**
+ * Edit/display study properties (study configuration) screen action.
+ */
 public class StudyPropertiesAction extends DisplayStudyStepAction {
 
-//  Presentation fields
-    private List<User>             staff;
-    private List<User>             member;
-    private List<Name>             validor;
-    private List<ValidationFacade> validation;
-    private ValidationFacade       validefault;
-    private List<DocumentType>     other;
-
-//  User input fields
-    private Save                   tosave;         // Edition action (title, contributors or cycle)
-    private String                 edicycle;
-    private String                 stitle;         // Title of the study
-    private String                 contributors;   // List of existing contributors, some of them may have been removed
-    private String                 candidates;     // List of added contributors
-    private long                    type;           // Type of document to be included in the validation process
-    private int                    publisher;
-    private int                    reviewer;
-    private int                    approver;
-       private StudyService _studyService;
-
        /**
         * Serial version ID.
         */
        private static final long serialVersionUID = 4210696018741092900L;
 
-    private enum Save { title, contributor, cycle }
-
-//  ==============================================================================================================================
-//  Action methods
-//  ==============================================================================================================================
-
-       public String doInitialize () {
-//  -----------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-
-      mystudy     = getOpenStudy();
-      validation  = new Vector<ValidationFacade>();
-      validefault = null;
-         other       = Document.selectResultTypes();
-
-         Study        study = mystudy.getStudyObject();
-         StudyRights  user  = mystudy.getStudyRights();
-      for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
-       DocumentType    type  = i.next();
-       ValidationCycle cycle = study.getValidationCycleOf(type);
-       if (cycle.isDefault()) {
-         validefault = new ValidationFacade(cycle);
-         continue;
-       }
-        validation.add( new ValidationFacade(cycle) );
-        i.remove();
-      }
-         if (validefault != null) validation.add(validefault);   // In order to be at the end
-      member  = study.getContributors();
-      staff   = null;
-      validor = null;
-
-      transax.commit();
-      if (mystudy.isOpenForWriting() && user.canEditProperties()) return "edit";
-      else return "display";
-    }
-
-       public String doEditTitle () {
-//  ----------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-
-      mystudy     = getOpenStudy();
-      validation  = new Vector<ValidationFacade>();
-      validefault = null;
-         other       = Document.selectResultTypes();
-
-         Study study = mystudy.getStudyObject();
-      for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
-       DocumentType    type  = i.next();
-       ValidationCycle cycle = study.getValidationCycleOf(type);
-       if (cycle.isDefault()) {
-         validefault = new ValidationFacade(cycle);
-         continue;
-       }
-        validation.add( new ValidationFacade(cycle) );
-      }
-         if (validefault != null) validation.add(validefault);   // In order to be at the end
-      member  = study.getContributors();
-      staff   = null;
-      validor = null;
-      other   = null;
-
-      transax.commit();
-      return SUCCESS;
-    }
-
-       public String doEditContributors () {
-//  -----------------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-
-      mystudy     = getOpenStudy();
-      validation  = new Vector<ValidationFacade>();
-      validefault = null;
-         other       = Document.selectAllTypes();
-
-         Study study = mystudy.getStudyObject();
-      for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
-       DocumentType    type  = i.next();
-       ValidationCycle cycle = study.getValidationCycleOf(type);
-       if (cycle.isDefault()) {
-         validefault = new ValidationFacade(cycle);
-         continue;
-       }
-        validation.add( new ValidationFacade(cycle) );
-      }
-         if (validefault != null) validation.add(validefault);   // In order to be at the end
-      member  = study.getContributors();
-      staff   = UserDirectory.selectAllUsers();
-      validor = null;
-      other   = null;
-      User me = this.getConnectedUser();
-      for (Iterator<User> i=staff.iterator(); i.hasNext(); ) {
-        User              next = i.next();
-        ApplicationRights he   = new ApplicationRights(next);
-        if (next.equals(me) || member.contains(next) || !he.canContributeToStudy()) i.remove();
-      }
-      transax.commit();
-      return SUCCESS;
-    }
-
-       public String doEditCycle () {
-//  ----------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-
-      mystudy     = getOpenStudy();
-      validation  = new Vector<ValidationFacade>();
-      validefault = null;
-         other       = Document.selectResultTypes();
-
-         Study study = mystudy.getStudyObject();
-      for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
-       DocumentType    type  = i.next();
-       ValidationCycle cycle = study.getValidationCycleOf(type);
-       if (cycle.isDefault()) {
-         validefault = new ValidationFacade(cycle);
-         continue;
-       }
-       if (type.getName().equals(edicycle)) {
-          this.type = type.getIndex();
-       }
-        validation.add( new ValidationFacade(cycle) );
-        i.remove();
-      }
-         if (validefault != null) validation.add(validefault);   // In order to be at the end
-      member  = study.getContributors();
-      validor = new Vector<Name>();
-      staff   = null;
-      List<User>            user = UserDirectory.selectAllUsers();
-      for (Iterator<User> i=user.iterator(); i.hasNext(); ) {
-        User              next = i.next();
-        ApplicationRights he   = new ApplicationRights(next);
-        if (he.canValidate()) {
-          if (next.equals(study.getAuthor())) validor.add( new ValidationFacade.ByManager(next) );
-          else                                validor.add(next);
-        }
-      }
-      transax.commit();
-      return SUCCESS;
-    }
-
-    public String doEdition () {
-//  --------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-      Study        study   = getOpenStudy().getStudyObject();
-
-      if (tosave == Save.title) {
-
-//      Edition of the title
-        Study.Properties sprop = new Study.Properties();
-        try {
-               getStudyService().update(study, sprop.setTitle(stitle));
-        }
-        catch (InvalidPropertyException e) {
-//TODO
-        }
-      } else
-      if (tosave == Save.contributor) {
-
-//      Edition of contributors
-        if (contributors == null) contributors = "";
-        if (candidates   == null) candidates   = "";
-
-        String[]     parsekept = contributors.split(",");
-        String[]     parsenew  = candidates.split(",");
-        Vector<User> toremove  = new Vector<User>(study.getContributors());
-
-        for (int i=0; i<parsekept.length; i++) {
-          if (parsekept[i].length() == 0) continue;   // Yet no contributor
-          int  index = Integer.valueOf(parsekept[i].trim());
-          for (Iterator<User> j=toremove.iterator(); j.hasNext(); ){
-            long present = j.next().getIndex();
-            if (present != index) continue;
-            j.remove();
-            break;
-          }
-        }
-        int size = toremove.size();
-        if (size > 0) getStudyService().removeContributor(study, toremove.toArray(new User[size]));
-
-        for (int i=0; i<parsenew.length; i++) {
-          if (parsenew[i].length() == 0) continue;    // No any new contributor
-          int  index  = Integer.valueOf(parsenew[i].trim());
-          User newser = UserDirectory.selectUser(index);
-
-          getStudyService().addContributor(study, newser);
-        }
-      } else
-      if (tosave == Save.cycle) {
-
-//      Addition of a document validation cycle
-       DocumentType               apply = Document.selectType(type);
-        ValidationCycle.Properties vprop = new ValidationCycle.Properties();
-       if (publisher > 0) {
-         User actor = UserDirectory.selectUser(publisher);
-          vprop.setActor(ValidationStep.PROMOTION, actor);
-       }
-       if (reviewer > 0) {
-         User actor = UserDirectory.selectUser(reviewer);
-          vprop.setActor(ValidationStep.REVIEW, actor);
-       }
-       if (approver > 0) {
-         User actor = UserDirectory.selectUser(approver);
-          vprop.setActor(ValidationStep.APPROVAL, actor);
-       }
-       getStudyService().setValidationCycle(study, apply, vprop);
-      }
-      transax.commit();
-
-      doInitialize();     // Re-initialization following the above edition
-      return SUCCESS;
+       // Presentation fields
+       private List<User> staff;
+       private List<User> member;
+       private List<Name> validor;
+       private List<ValidationFacade> validation;
+       private ValidationFacade validefault;
+       private List<DocumentType> other;
+
+       // User input fields
+       private Save tosave; // Edition action (title, contributors or cycle)
+       private String edicycle;
+       private String stitle; // Title of the study
+       private String contributors; // List of existing contributors, some of them may have been removed
+       private String candidates; // List of added contributors
+       private long type; // Type of document to be included in the validation process
+       private int publisher;
+       private int reviewer;
+       private int approver;
+
+       /**
+        * Injected study service.
+        */
+       private StudyService _studyService;
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
+
+       /**
+        * Save operation type enumeration pointing which section of properties has been edited.
+        */
+       private enum Save {
+               /**
+                * Save study title.
+                */
+               title,
+               /**
+                * Save contributors.
+                */
+               contributor,
+               /**
+                * Save validation cycle.
+                */
+               cycle
+       }
+
+       // ==============================================================================================================================
+       // Action methods
+       // ==============================================================================================================================
+
+       /**
+        * Initialize study properties action.
+        * 
+        * @return "edit" if user can edit study properties, otherwise return "display"
+        */
+       public String doInitialize() {
+
+               mystudy = getOpenStudy();
+               validation = new Vector<ValidationFacade>();
+               validefault = null;
+               other = getDocumentTypeService().selectResultTypes();
+
+               Study study = mystudy.getStudyObject();
+               StudyRights user = mystudy.getStudyRights();
+               for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
+                       DocumentType type = i.next();
+                       ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
+                       if (cycle.isDefault()) {
+                               validefault = new ValidationFacade(cycle);
+                               continue;
+                       }
+                       validation.add(new ValidationFacade(cycle));
+                       i.remove();
+               }
+               if (validefault != null)
+                       validation.add(validefault); // In order to be at the end
+               member = getStudyService().getContributors(study);
+               staff = null;
+               validor = null;
+
+               if (mystudy.isOpenForWriting() && user.canEditProperties())
+                       return "edit";
+               else
+                       return "display";
+       }
+
+       public String doEditTitle() {
+               // ----------------------------
+               Session connex = Database.getSession();
+               Transaction transax = connex.beginTransaction();
+
+               mystudy = getOpenStudy();
+               validation = new Vector<ValidationFacade>();
+               validefault = null;
+               other = getDocumentTypeService().selectResultTypes();
+
+               Study study = mystudy.getStudyObject();
+               for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
+                       DocumentType type = i.next();
+                       ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
+                       if (cycle.isDefault()) {
+                               validefault = new ValidationFacade(cycle);
+                               continue;
+                       }
+                       validation.add(new ValidationFacade(cycle));
+               }
+               if (validefault != null)
+                       validation.add(validefault); // In order to be at the end
+               member = getStudyService().getContributors(study);
+               staff = null;
+               validor = null;
+               other = null;
+
+               transax.commit();
+               return SUCCESS;
+       }
+
+       public String doEditContributors() {
+               // -----------------------------------
+               Session connex = Database.getSession();
+               Transaction transax = connex.beginTransaction();
+
+               mystudy = getOpenStudy();
+               validation = new Vector<ValidationFacade>();
+               validefault = null;
+               other = getDocumentTypeService().selectAllTypes();
+
+               Study study = mystudy.getStudyObject();
+               for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
+                       DocumentType type = i.next();
+                       ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
+                       if (cycle.isDefault()) {
+                               validefault = new ValidationFacade(cycle);
+                               continue;
+                       }
+                       validation.add(new ValidationFacade(cycle));
+               }
+               if (validefault != null)
+                       validation.add(validefault); // In order to be at the end
+               member = getStudyService().getContributors(study);
+               staff = UserDirectory.selectAllUsers();
+               validor = null;
+               other = null;
+               User me = this.getConnectedUser();
+               for (Iterator<User> i = staff.iterator(); i.hasNext();) {
+                       User next = i.next();
+                       ApplicationRights he = new ApplicationRights(next);
+                       if (next.equals(me) || member.contains(next)
+                                       || !he.canContributeToStudy())
+                               i.remove();
+               }
+               transax.commit();
+               return SUCCESS;
+       }
+
+       public String doEditCycle() {
+               // ----------------------------
+               Session connex = Database.getSession();
+               Transaction transax = connex.beginTransaction();
+
+               mystudy = getOpenStudy();
+               validation = new Vector<ValidationFacade>();
+               validefault = null;
+               other = getDocumentTypeService().selectResultTypes();
+
+               Study study = mystudy.getStudyObject();
+               for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
+                       DocumentType type = i.next();
+                       ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
+                       if (cycle.isDefault()) {
+                               validefault = new ValidationFacade(cycle);
+                               continue;
+                       }
+                       if (type.getName().equals(edicycle)) {
+                               this.type = type.getIndex();
+                       }
+                       validation.add(new ValidationFacade(cycle));
+                       i.remove();
+               }
+               if (validefault != null)
+                       validation.add(validefault); // In order to be at the end
+               member = getStudyService().getContributors(study);
+               validor = new Vector<Name>();
+               staff = null;
+               List<User> user = UserDirectory.selectAllUsers();
+               for (Iterator<User> i = user.iterator(); i.hasNext();) {
+                       User next = i.next();
+                       ApplicationRights he = new ApplicationRights(next);
+                       if (he.canValidate()) {
+                               if (next.equals(study.getAuthor()))
+                                       validor.add(new ValidationFacade.ByManager(next));
+                               else
+                                       validor.add(next);
+                       }
+               }
+               transax.commit();
+               return SUCCESS;
+       }
+
+       public String doEdition() {
+               // --------------------------
+               Session connex = Database.getSession();
+               Transaction transax = connex.beginTransaction();
+               Study study = getOpenStudy().getStudyObject();
+
+               if (tosave == Save.title) {
+
+                       // Edition of the title
+                       Study.Properties sprop = new Study.Properties();
+                       try {
+                               getStudyService().update(study, sprop.setTitle(stitle));
+                       } catch (InvalidPropertyException e) {
+                               // TODO
+                       }
+               } else if (tosave == Save.contributor) {
+
+                       // Edition of contributors
+                       if (contributors == null)
+                               contributors = "";
+                       if (candidates == null)
+                               candidates = "";
+
+                       String[] parsekept = contributors.split(",");
+                       String[] parsenew = candidates.split(",");
+                       Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
+
+                       for (int i = 0; i < parsekept.length; i++) {
+                               if (parsekept[i].length() == 0)
+                                       continue; // Yet no contributor
+                               int index = Integer.valueOf(parsekept[i].trim());
+                               for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
+                                       long present = j.next().getIndex();
+                                       if (present != index)
+                                               continue;
+                                       j.remove();
+                                       break;
+                               }
+                       }
+                       int size = toremove.size();
+                       if (size > 0)
+                               getStudyService().removeContributor(study,
+                                               toremove.toArray(new User[size]));
+
+                       for (int i = 0; i < parsenew.length; i++) {
+                               if (parsenew[i].length() == 0)
+                                       continue; // No any new contributor
+                               int index = Integer.valueOf(parsenew[i].trim());
+                               User newser = UserDirectory.selectUser(index);
+
+                               getStudyService().addContributor(study, newser);
+                       }
+               } else if (tosave == Save.cycle) {
+
+                       // Addition of a document validation cycle
+                       DocumentType apply = getDocumentTypeService().selectType(type);
+                       ValidationCycle.Properties vprop = new ValidationCycle.Properties();
+                       if (publisher > 0) {
+                               User actor = UserDirectory.selectUser(publisher);
+                               vprop.setActor(ValidationStep.PROMOTION, actor);
+                       }
+                       if (reviewer > 0) {
+                               User actor = UserDirectory.selectUser(reviewer);
+                               vprop.setActor(ValidationStep.REVIEW, actor);
+                       }
+                       if (approver > 0) {
+                               User actor = UserDirectory.selectUser(approver);
+                               vprop.setActor(ValidationStep.APPROVAL, actor);
+                       }
+                       getStudyService().setValidationCycle(study, apply, vprop);
+               }
+               transax.commit();
+
+               doInitialize(); // Re-initialization following the above edition
+               return SUCCESS;
+       }
+
+       // ==============================================================================================================================
+       // Getters
+       // ==============================================================================================================================
+
+       public User getAuthor() {
+               // ------------------------
+               return mystudy.getStudyObject().getAuthor();
+       }
+
+       public List<User> getCandidates() {
+               // ----------------------------------
+               return staff;
+       }
+
+       public String getCycle() {
+               // -------------------------
+               return edicycle;
+       }
+
+       public List<User> getContributors() {
+               // ------------------------------------
+               return member;
+       }
+
+       public ValidationFacade getDefaultValidation() {
+               // -----------------------------------------------
+               return validefault;
+       }
+
+       public long getDocumentTypeIndex() {
+               // ----------------------------------
+               return type;
+       }
+
+       public List<DocumentType> getOtherDocumentTypes() {
+               // --------------------------------------------------
+               return other;
+       }
+
+       public String getStudyTitle() {
+               // ------------------------------
+               return mystudy.getTitle();
+       }
+
+       public List<ValidationFacade> getValidations() {
+               // -----------------------------------------------
+               return validation;
+       }
+
+       public List<Name> getValidationActors() {
+               // ----------------------------------------
+               return validor;
+       }
+
+       // ==============================================================================================================================
+       // Setters
+       // ==============================================================================================================================
+
+       public void setCandidates(String indices) {
+               // ------------------------------------------
+               candidates = indices;
+       }
+
+       public void setCycle(String type) {
+               // ----------------------------------
+               edicycle = type;
+       }
+
+       public void setMembers(String indices) {
+               // ---------------------------------------
+               contributors = indices;
+       }
+
+       public void setDocumentType(String index) {
+               // ------------------------------------------
+               type = Integer.valueOf(index);
+       }
+
+       public void setApprover(String index) {
+               // --------------------------------------
+               approver = Integer.valueOf(index);
+       }
+
+       public void setPublisher(String index) {
+               // ---------------------------------------
+               publisher = Integer.valueOf(index);
+       }
+
+       public void setReviewer(String index) {
+               // --------------------------------------
+               reviewer = Integer.valueOf(index);
+       }
+
+       public void setTitle(String title) {
+               // -----------------------------------
+               stitle = title;
+       }
+
+       public void setSaveTitle(String save) {
+               // --------------------------------------
+               tosave = Save.title;
+       }
+
+       public void setSaveContributors(String save) {
+               // ---------------------------------------------
+               tosave = Save.contributor;
+       }
+
+       public void setSaveCycle(String save) {
+               // --------------------------------------
+               tosave = Save.cycle;
        }
 
-//  ==============================================================================================================================
-//  Getters
-//  ==============================================================================================================================
-
-    public User getAuthor () {
-//  ------------------------
-      return mystudy.getStudyObject().getAuthor();
-    }
-    public List<User> getCandidates () {
-//  ----------------------------------
-      return staff;
-    }
-    public String getCycle () {
-//  -------------------------
-      return edicycle;
-    }
-    public List<User> getContributors () {
-//  ------------------------------------
-      return member;
-    }
-    public ValidationFacade getDefaultValidation () {
-//  -----------------------------------------------
-      return validefault;
-    }
-    public long getDocumentTypeIndex () {
-//  ----------------------------------
-      return type;
-    }
-    public List<DocumentType> getOtherDocumentTypes () {
-//  --------------------------------------------------
-      return other;
-    }
-    public String getStudyTitle () {
-//  ------------------------------
-      return mystudy.getTitle();
-    }
-    public List<ValidationFacade> getValidations () {
-//  -----------------------------------------------
-      return validation;
-    }
-    public List<Name> getValidationActors () {
-//  ----------------------------------------
-      return validor;
-    }
-
-//  ==============================================================================================================================
-//  Setters
-//  ==============================================================================================================================
-
-    public void setCandidates (String indices) {
-//  ------------------------------------------
-      candidates = indices;
-    }
-    public void setCycle (String type) {
-//  ----------------------------------
-      edicycle = type;
-    }
-    public void setMembers (String indices) {
-//  ---------------------------------------
-      contributors = indices;
-    }
-    public void setDocumentType (String index) {
-//  ------------------------------------------
-      type = Integer.valueOf(index);
-    }
-    public void setApprover (String index) {
-//  --------------------------------------
-      approver = Integer.valueOf(index);
-    }
-    public void setPublisher (String index) {
-//  ---------------------------------------
-      publisher = Integer.valueOf(index);
-    }
-    public void setReviewer (String index) {
-//  --------------------------------------
-      reviewer = Integer.valueOf(index);
-    }
-    public void setTitle (String title) {
-//  -----------------------------------
-      stitle = title;
-    }
-    public void setSaveTitle (String save) {
-//  --------------------------------------
-      tosave = Save.title;
-    }
-    public void setSaveContributors (String save) {
-//  ---------------------------------------------
-      tosave = Save.contributor;
-    }
-    public void setSaveCycle (String save) {
-//  --------------------------------------
-      tosave = Save.cycle;
-    }
        /**
         * Get the studyService.
         * 
@@ -376,4 +437,23 @@ public class StudyPropertiesAction extends DisplayStudyStepAction {
        public void setStudyService(StudyService studyService) {
                _studyService = studyService;
        }
+
+       /**
+        * Get the documentTypeService.
+        * 
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * 
+        * @param documentTypeService
+        *            the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
 }
\ No newline at end of file
index bd1b83a952e0d2d7db2170ba83eb3138e39fd987..62240ae9b2b0d7c6650e626dd66408fd269c8c83 100644 (file)
@@ -36,6 +36,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
        <bean id="applicationSettings"
                class="org.splat.simer.ApplicationSettings">
                <property name="projectSettings" ref="projectSettings" />
+               <property name="documentTypeService" ref="documentTypeService" />
        </bean>
 
        <bean id="importedStudy" class="org.splat.simer.admin.ImportedStudy"
@@ -47,29 +48,35 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                <property name="scenarioService" ref="scenarioService" />
        </bean>
 
-    <bean id="studyMenu" class="org.splat.simer.StudyMenu"
-        scope="session" parent="slidMenu"/>
+       <bean id="studyMenu" class="org.splat.simer.StudyMenu"
+               scope="session" parent="slidMenu" />
 
-    <bean id="newScenarioMenu" class="org.splat.simer.NewScenarioMenu"
-        scope="session" parent="slidMenu"/>
+       <bean id="newScenarioMenu" class="org.splat.simer.NewScenarioMenu"
+               scope="session" parent="slidMenu" />
 
-       <bean id="openStudy" class="org.splat.simer.OpenStudy"
-               scope="session">
+       <bean id="openObject" abstract="true"
+               class="org.splat.simer.OpenObject" scope="session">
                <property name="projectElementService"
                        ref="projectElementService" />
                <property name="projectSettings" ref="projectSettings" />
+               <property name="knowledgeElementTypeService"
+                       ref="knowledgeElementTypeService" />
+       </bean>
+
+       <bean id="openStudy" class="org.splat.simer.OpenStudy"
+               parent="openObject" scope="session">
+               <property name="projectElementService"
+                       ref="projectElementService" />
                <property name="publicationService" ref="publicationService" />
-               <property name="scenarioService" ref="scenarioService" />
+               <property name="studyService" ref="studyService" />
                <property name="stepService" ref="stepService" />
-        <property name="repositoryService" ref="repositoryService" />
-        <property name="menu" ref="studyMenu" />
+               <property name="repositoryService" ref="repositoryService" />
+               <property name="menu" ref="studyMenu" />
+               <property name="documentTypeService" ref="documentTypeService" />
        </bean>
 
        <bean id="openKnowledge" class="org.splat.simer.OpenKnowledge"
-               scope="session">
-               <property name="projectElementService"
-                       ref="projectElementService" />
-               <property name="projectSettings" ref="projectSettings" />
+               parent="openObject" scope="session">
        </bean>
 
        <bean id="baseAction" class="org.splat.simer.Action"
@@ -92,8 +99,8 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                scope="prototype">
                <property name="projectElementService"
                        ref="projectElementService" />
-               <property name="studyService" ref="studyService" />
-        <property name="menu" ref="newScenarioMenu" />
+               <property name="scenarioService" ref="scenarioService" />
+               <property name="menu" ref="newScenarioMenu" />
        </bean>
 
        <bean id="importDocumentAction"
@@ -103,6 +110,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                <property name="projectSettings" ref="projectSettings" />
                <property name="publicationService" ref="publicationService" />
                <property name="repositoryService" ref="repositoryService" />
+               <property name="documentTypeService" ref="documentTypeService" />
        </bean>
 
        <bean id="displayStudyStepAction"
@@ -116,6 +124,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
        <bean id="studyPropertiesAction"
                class="org.splat.simer.StudyPropertiesAction" scope="prototype"
                parent="displayStudyStepAction">
+               <property name="documentTypeService" ref="documentTypeService" />
        </bean>
 
        <bean id="editStudyAction" class="org.splat.simer.EditStudyAction"
@@ -141,6 +150,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
        <bean id="editDocumentAction"
                class="org.splat.simer.EditDocumentAction" scope="prototype"
                parent="displayStudyStepAction">
+               <property name="stepService" ref="stepService" />
                <property name="publicationService" ref="publicationService" />
                <property name="repositoryService" ref="repositoryService" />
        </bean>
@@ -150,6 +160,8 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                parent="displayStudyStepAction">
                <property name="knowledgeElementService"
                        ref="knowledgeElementService" />
+               <property name="knowledgeElementTypeService"
+                       ref="knowledgeElementTypeService" />
                <property name="scenarioService" ref="scenarioService" />
        </bean>
 
@@ -185,6 +197,8 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                <property name="searchService" ref="searchService" />
                <property name="simulationContextService"
                        ref="simulationContextService" />
+               <property name="knowledgeElementTypeService"
+                       ref="knowledgeElementTypeService" />
        </bean>
 
        <bean id="searchDocumentAction"
@@ -241,6 +255,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
        <bean id="saveDocumentAction"
                class="org.splat.module.SaveDocumentAction" scope="prototype">
+               <property name="documentTypeService" ref="documentTypeService" />
                <property name="publicationService" ref="publicationService" />
                <property name="repositoryService" ref="repositoryService" />
                <property name="scenarioService" ref="scenarioService" />