From a7653ca21334edc0d9bb5bfbf75c4a9959d1b52b Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 17 Oct 2012 04:44:30 +0000 Subject: [PATCH] Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria are added to base DAO. SimulationContextService is created. Some comments are added. --- .../org/splat/dal/bo/kernel/Persistent.java | 16 + .../src/org/splat/dal/bo/som/Document.java | 13 - .../splat/dal/bo/som/SimulationContext.java | 101 +- .../dal/bo/som/SimulationContextType.java | 6 +- .../org/splat/dal/dao/kernel/Database.java | 72 -- .../org/splat/dal/dao/kernel/GenericDAO.java | 47 +- .../splat/dal/dao/kernel/GenericDAOImpl.java | 68 +- .../src/org/splat/dal/dao/kernel/RoleDAO.java | 1 + .../org/splat/dal/dao/kernel/RoleDAOImpl.java | 1 + .../dal/dao/kernel/TextAttributeDAO.java | 1 + .../dal/dao/kernel/TextAttributeDAOImpl.java | 1 + .../src/org/splat/dal/dao/kernel/UserDAO.java | 1 + .../org/splat/dal/dao/kernel/UserDAOImpl.java | 1 + .../dal/dao/som/ContributorRelationDAO.java | 1 + .../dao/som/ContributorRelationDAOImpl.java | 1 + .../dal/dao/som/ConvertsRelationDAO.java | 1 + .../dal/dao/som/ConvertsRelationDAOImpl.java | 1 + .../src/org/splat/dal/dao/som/Database.java | 282 +----- .../org/splat/dal/dao/som/DocumentDAO.java | 1 + .../splat/dal/dao/som/DocumentDAOImpl.java | 1 + .../splat/dal/dao/som/DocumentTypeDAO.java | 1 + .../dal/dao/som/DocumentTypeDAOImpl.java | 1 + .../src/org/splat/dal/dao/som/FileDAO.java | 1 + .../org/splat/dal/dao/som/FileDAOImpl.java | 1 + .../org/splat/dal/dao/som/IDBuilderDAO.java | 1 + .../splat/dal/dao/som/IDBuilderDAOImpl.java | 1 + .../dal/dao/som/KnowledgeElementDAO.java | 1 + .../dal/dao/som/KnowledgeElementDAOImpl.java | 1 + .../dal/dao/som/KnowledgeElementTypeDAO.java | 1 + .../dao/som/KnowledgeElementTypeDAOImpl.java | 1 + .../org/splat/dal/dao/som/PublicationDAO.java | 1 + .../splat/dal/dao/som/PublicationDAOImpl.java | 1 + .../org/splat/dal/dao/som/ScenarioDAO.java | 1 + .../splat/dal/dao/som/ScenarioDAOImpl.java | 1 + .../dal/dao/som/SimulationContextDAO.java | 1 + .../dal/dao/som/SimulationContextDAOImpl.java | 1 + .../dal/dao/som/SimulationContextTypeDAO.java | 1 + .../dao/som/SimulationContextTypeDAOImpl.java | 1 + .../splat/dal/dao/som/StampRelationDAO.java | 1 + .../dal/dao/som/StampRelationDAOImpl.java | 1 + .../src/org/splat/dal/dao/som/StudyDAO.java | 1 + .../org/splat/dal/dao/som/StudyDAOImpl.java | 1 + .../org/splat/dal/dao/som/TimestampDAO.java | 1 + .../splat/dal/dao/som/TimestampDAOImpl.java | 1 + .../splat/dal/dao/som/UsedByRelationDAO.java | 1 + .../dal/dao/som/UsedByRelationDAOImpl.java | 1 + .../splat/dal/dao/som/UsesRelationDAO.java | 1 + .../dal/dao/som/UsesRelationDAOImpl.java | 1 + .../splat/dal/dao/som/ValidationCycleDAO.java | 1 + .../dal/dao/som/ValidationCycleDAOImpl.java | 1 + .../dao/som/ValidationCycleRelationDAO.java | 1 + .../som/ValidationCycleRelationDAOImpl.java | 1 + .../dal/dao/som/VersionsRelationDAO.java | 1 + .../dal/dao/som/VersionsRelationDAOImpl.java | 1 + .../src/org/splat/kernel/UserDirectory.java | 10 +- .../org/splat/service/DocumentService.java | 47 +- .../splat/service/DocumentServiceImpl.java | 137 ++- .../splat/service/ProjectElementService.java | 11 + .../service/ProjectElementServiceImpl.java | 16 +- .../org/splat/service/PublicationService.java | 66 +- .../splat/service/PublicationServiceImpl.java | 227 +++-- .../service/SimulationContextService.java | 136 +++ .../service/SimulationContextServiceImpl.java | 312 ++++++ .../src/org/splat/service/StepService.java | 4 +- .../org/splat/service/StepServiceImpl.java | 39 +- .../src/org/splat/service/StudyService.java | 8 - .../org/splat/service/StudyServiceImpl.java | 133 ++- .../technical/ProjectSettingsServiceImpl.java | 903 ++++++++++-------- .../src/spring/businessServiceContext.xml | 14 +- .../Siman-Common/src/spring/daoContext.xml | 1 + .../src/spring/technicalServiceContext.xml | 3 +- .../org/splat/module/SaveDocumentAction.java | 99 +- .../Siman/src/org/splat/simer/Action.java | 6 + .../org/splat/simer/ApplicationSettings.java | 6 + .../src/org/splat/simer/ConnectionAction.java | 3 + .../Siman/src/org/splat/simer/Converter.java | 7 +- .../org/splat/simer/DisplayBaseAction.java | 3 + .../org/splat/simer/EditDocumentAction.java | 350 ++++--- .../simer/EditKnowledgeElementAction.java | 3 + .../simer/EditScenarioPropertiesAction.java | 3 + .../simer/EditSimulationContextAction.java | 49 +- .../src/org/splat/simer/EditStudyAction.java | 3 + .../org/splat/simer/ImportDocumentAction.java | 71 +- .../Siman/src/org/splat/simer/MenuAction.java | 3 + .../org/splat/simer/NewScenarioAction.java | 3 + .../src/org/splat/simer/NewStudyAction.java | 65 +- .../splat/simer/NotYetImplementedAction.java | 3 + .../Siman/src/org/splat/simer/OpenStudy.java | 49 +- .../src/org/splat/simer/SearchBaseAction.java | 471 +++++---- .../org/splat/simer/SearchDocumentAction.java | 3 + .../splat/simer/SearchKnowledgeAction.java | 30 +- .../org/splat/simer/SearchStudyAction.java | 30 +- .../src/org/splat/simer/StartAction.java | 3 + .../splat/simer/StudyPropertiesAction.java | 3 + .../src/org/splat/simer/UploadAction.java | 23 +- .../org/splat/simer/UploadBaseNextAction.java | 3 + .../splat/simer/VersionDocumentAction.java | 28 +- .../simer/admin/DatabaseIndexingAction.java | 7 +- .../splat/simer/admin/ImportUserAction.java | 30 +- .../simer/admin/KnowledgeElementAction.java | 3 + .../simer/admin/SimulationContextAction.java | 473 +++++---- Workspace/Siman/src/org/splat/wapp/Item.java | 3 + .../Siman/src/org/splat/wapp/MenuItem.java | 6 + .../Siman/src/org/splat/wapp/TabBar.java | 3 + .../Siman/src/spring/applicationContext.xml | 60 +- 105 files changed, 2900 insertions(+), 1723 deletions(-) create mode 100644 Workspace/Siman-Common/src/org/splat/service/SimulationContextService.java create mode 100644 Workspace/Siman-Common/src/org/splat/service/SimulationContextServiceImpl.java diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java index 11aa5c4..42629f2 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java @@ -138,4 +138,20 @@ public abstract class Persistent { if (oid == 0) oid = super.hashCode(); //WARNING: Must not call super.toString() as it goes back here (this.toString()) return new StringBuffer("object ").append(getClass().getName()).append("@").append(oid).toString(); } + +/** + * Get the rid. + * @return the rid + */ +public long getRid() { + return rid; +} + +/** + * Set the rid. + * @param rid the rid to set + */ +public void setRid(long rid) { + this.rid = rid; +} } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java index ec7fcb3..d998f3e 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java @@ -391,19 +391,6 @@ public class Document extends Entity { return did; } - public java.io.File getSaveDirectory() { - // --------------------------------------- - String mypath = Database.getRepositoryVaultPath() - + myfile.getRelativePath(); - String[] table = mypath.split("/"); - - // Cutting the filename - StringBuffer path = new StringBuffer(table[0]); - for (int i = 1; i < table.length - 1; i++) - path = path.append("/").append(table[i]); - return new java.io.File(path.append("/").toString()); - } - public File getSourceFile() { // ---------------------------- return myfile; diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContext.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContext.java index a91d0af..828033b 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContext.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContext.java @@ -154,91 +154,18 @@ public class SimulationContext extends Persistent implements Serializable { // -------------------------- return (counter > 1); } - -// ============================================================================================================================== -// Public services -// ============================================================================================================================== - - public static SimulationContextType createType (String name, ProjectSettingsService.Step step) throws InvalidPropertyException, RuntimeException { -// --------------------------------------------------------------------------------------- -//TODO: Check for duplicate definition - SimulationContextType type = new SimulationContextType(name, step); - Session session = Database.getSession(); - session.save(type); - - return type; - } - - @SuppressWarnings("unchecked") - public static List selectAllTypes () { -// ----------------------------------------------------------- - StringBuffer query = new StringBuffer("from SimulationContextType"); // Useless to order by names as the result mixes localized and non localized types - query = query.append(" order by step asc"); - return Database.getSession().createQuery(query.toString()).list(); - } - - @SuppressWarnings("unchecked") - public static List selectTypesOf (ProjectSettingsService.Step... step) { -// -------------------------------------------------------------------------------------- - StringBuffer query = new StringBuffer("from SimulationContextType where step='").append(step[0].getNumber()).append("'"); - for (int i=1; i selectTypesWhere (SimulationContextType.Properties sprop) { -// --------------------------------------------------------------------------------------------------- - StringBuffer query = new StringBuffer("from SimulationContextType"); - String separator = " where"; - ProjectSettingsService.Step step = sprop.getStep(); - ProgressState state = sprop.getProgressState(); - String order = " order by step asc"; - - if (step != null) { - query = query.append(separator).append(" step='").append(step.getNumber()).append("'"); - separator = " and"; - order = " order by state desc"; // APPROVED (upper case A) is grater than inCHECK (lower case i) - } - if (state != null) { - query = query.append(separator).append(" state='").append(state.toString()).append("'"); -// separator = " and"; - if (step != null) { - if (state != ProgressState.APPROVED) order = " order by name asc"; - else order = ""; // Approved types are localized - } - } - query = query.append(order); - return Database.getSession().createQuery(query.toString()).list(); - } - - public static SimulationContextType selectType (String name) { -// ------------------------------------------------------------ - StringBuffer query = new StringBuffer("from SimulationContextType where name='").append(name).append("'"); - return (SimulationContextType)Database.getSession().createQuery(query.toString()).uniqueResult(); - } - - public static SimulationContextType selectType (int index) { -// ---------------------------------------------------------- - StringBuffer query = new StringBuffer("from SimulationContextType where rid='").append(index).append("'"); - return (SimulationContextType)Database.getSession().createQuery(query.toString()).uniqueResult(); - } - -// ============================================================================================================================== -// Protected services -// ============================================================================================================================== - - public void hold () { -// ---------------------- - counter += 1; - if (this.isSaved()) Database.getSession().update(this); - } - - public void release () { -// ------------------------- - counter -= 1; - if (this.isSaved()) Database.getSession().update(this); - } + /** + * Get counter. + * @return counter + */ + public int getCounter() { + return counter; + } + /** + * Set counter. + * @param aValue a counter value to set + */ + public void setCounter(int aValue) { + counter = aValue; + } } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContextType.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContextType.java index 881d086..c275cb8 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContextType.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/SimulationContextType.java @@ -35,10 +35,10 @@ public class SimulationContextType extends Persistent implements Serializable { private ProgressState state = null; private ProjectSettingsService.Step step = null; - protected ProgressState getProgressState () { + public ProgressState getProgressState () { return state; } - protected ProjectSettingsService.Step getStep () { + public ProjectSettingsService.Step getStep () { return step; } public Properties setState (ProgressState state) { @@ -54,7 +54,7 @@ public class SimulationContextType extends Persistent implements Serializable { protected SimulationContextType () { } // Initialization constructor - protected SimulationContextType (String name, ProjectSettingsService.Step step) throws InvalidPropertyException { + public SimulationContextType (String name, ProjectSettingsService.Step step) throws InvalidPropertyException { // ------------------------------------------------------------------------ super(); this.name = name; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/Database.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/Database.java index 9ebba99..0864202 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/Database.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/Database.java @@ -5,16 +5,11 @@ package org.splat.dal.dao.kernel; * @copyright OPEN CASCADE 2012 */ -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.hibernate.jdbc.Work; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.apache.log4j.Logger; @@ -45,73 +40,6 @@ public abstract class Database implements ApplicationContextAware { // private static String CONFIG_FILE = "/hibernate.cfg.xml"; private static SessionFactory mySessionFactory = null; - protected class CreateTables implements Work { -// ----------------------------------------------- - protected Statement request; - - public void execute(Connection connex) throws SQLException - { - request = connex.createStatement(); - -// Last identifier of Any objects - String create = "CREATE TABLE `any` (" + - "`rid` int(10) UNSIGNED NOT NULL," + - "`version` tinytext NOT NULL," + - "PRIMARY KEY (`rid`)" + - ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - -// Relation from entities - create = "CREATE TABLE `relation` (" + - "`rid` int(10) UNSIGNED NOT NULL," + - "`name` tinytext NOT NULL," + - "`owner` int(10) NOT NULL," + - "`refer` int(10) NOT NULL," + - "PRIMARY KEY (`rid`)" + - ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - -// Attribute objects - create = "CREATE TABLE `attribute` (" + - "`rid` int(10) UNSIGNED NOT NULL auto_increment," + - "`type` tinytext NOT NULL," + - "`owner` int(10) NOT NULL," + - "`value` int(10) NOT NULL," + - "PRIMARY KEY (`rid`)" + - ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - -// Java String objects - create = "CREATE TABLE `text` (" + - "`rid` int(10) UNSIGNED NOT NULL auto_increment," + - "`value` longtext NOT NULL," + - "PRIMARY KEY (`rid`)" + - ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - -// User and role objects - create = "CREATE TABLE `user` (" + - "`rid` int(10) UNSIGNED NOT NULL auto_increment," + - "`username` varchar(32) NOT NULL," + - "`password` varchar(32)," + - "`first` tinytext NOT NULL," + - "`last` tinytext NOT NULL," + - "`display` tinytext," + - "`email` tinytext," + - "`organid` tinytext," + - "PRIMARY KEY (`rid`)" + - ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - create = "CREATE TABLE `role` (" + - "`username` varchar(32) NOT NULL," + - "`role` varchar(32) NOT NULL," + - "PRIMARY KEY (`username`)" + - ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - } - } - protected final static Logger logger = Logger.getLogger(Database.class); // ============================================================================================================================== diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java index ee62feb..9ae2887 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java @@ -10,6 +10,10 @@ package org.splat.dal.dao.kernel; import java.io.Serializable; +import java.util.List; + +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Order; /** * Generic DAO interface. @@ -41,13 +45,48 @@ public interface GenericDAO { */ T get(PK id); - /** Save changes made to a persistent object. - * @param transientObject transient instance of the object to update + /** + * Save changes made to a persistent object. + * + * @param transientObject + * transient instance of the object to update */ void update(T transientObject); - /** Remove an object from persistent storage in the database. - * @param persistentObject a persistent object to delete from the database + /** + * Remove an object from persistent storage in the database. + * + * @param persistentObject + * a persistent object to delete from the database */ void delete(T persistentObject); + + /** + * Retrieve an object that was previously persisted to the database using the given criteria. + * + * @param aCondition + * a search condition + * @return an object found according to the given criteria + */ + public T findByCriteria(Criterion aCondition); + + /** + * Retrieve a list of objects which were previously persisted to the database using the given criteria. + * + * @param aCondition + * a search condition + * @return a list of objects filtered according to the given criteria + */ + public List getFilteredList(Criterion aCondition); + /** + * Retrieve a list of objects which were previously persisted to the database using the given criteria. + * + * @param aCondition + * a search condition + * @param anOrder + * a result list order. Null is ignored and in such case the result list is unordered. + * @return a list of objects filtered according to the given criteria + */ + @SuppressWarnings("unchecked") + public List getFilteredList(Criterion aCondition, Order anOrder); } diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java index bc94999..d76653b 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java @@ -10,7 +10,12 @@ package org.splat.dal.dao.kernel; import java.io.Serializable; +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; /** @@ -23,8 +28,8 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport; * @param * Primary key class */ -public abstract class GenericDAOImpl extends HibernateDaoSupport implements - GenericDAO { +public abstract class GenericDAOImpl extends + HibernateDaoSupport implements GenericDAO { /** * Persist the newInstance object into database. * @@ -49,15 +54,65 @@ public abstract class GenericDAOImpl extends Hiberna return (T) getSession().get(getType(), id); } - /** Save changes made to a persistent object. - * @param transientObject transient instance of the object to update + /** + * Retrieve an object that was previously persisted to the database using the given criteria. + * + * @param aCondition + * a search condition + * @return an object found according to the given criteria + */ + @SuppressWarnings("unchecked") + public T findByCriteria(Criterion aCondition) { + return (T) getSession().createCriteria(getType()).add(aCondition) + .uniqueResult(); + } + + /** + * Retrieve a list of objects which were previously persisted to the database using the given criteria. + * + * @param aCondition + * a search condition + * @return a list of objects filtered according to the given criteria + */ + @SuppressWarnings("unchecked") + public List getFilteredList(Criterion aCondition) { + return getSession().createCriteria(getType()).add(aCondition).list(); + } + + /** + * Retrieve a list of objects which were previously persisted to the database using the given criteria. + * + * @param aCondition + * a search condition + * @param anOrder + * a result list order. Null is ignored and in such case the result list is unordered. + * @return a list of objects filtered according to the given criteria + */ + @SuppressWarnings("unchecked") + public List getFilteredList(Criterion aCondition, Order anOrder) { + Criteria aCriteria = getSession().createCriteria(getType()).add( + aCondition); + if (anOrder != null) { + aCriteria.addOrder(anOrder); + } + return aCriteria.list(); + } + + /** + * Save changes made to a persistent object. + * + * @param transientObject + * transient instance of the object to update */ public void update(T transientObject) { getSession().update(transientObject); } - /** Remove an object from persistent storage in the database. - * @param persistentObject a persistent object to delete from the database + /** + * Remove an object from persistent storage in the database. + * + * @param persistentObject + * a persistent object to delete from the database */ public void delete(T persistentObject) { getSession().delete(persistentObject); @@ -65,6 +120,7 @@ public abstract class GenericDAOImpl extends Hiberna /** * Get persistent object type. + * * @return Persistent object class to be processed by this DAO */ abstract protected Class getType(); diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAO.java index 08d087b..c122d76 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.kernel; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAOImpl.java index 44a8b5f..9a860d9 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/RoleDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.kernel; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAO.java index 53a4b72..91ff888 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.kernel; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAOImpl.java index b81fd7f..8b1a68d 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/TextAttributeDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.kernel; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAO.java index 459bd52..27a0ec7 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.kernel; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAOImpl.java index 84a226b..702772a 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/UserDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.kernel; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAO.java index 3e5068b..da8cc46 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAOImpl.java index 2fc75b0..dfa4402 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ContributorRelationDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAO.java index 9812845..e655bca 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAOImpl.java index 70c1b62..dbc56cf 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ConvertsRelationDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java index 9daff68..3d5790a 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java @@ -24,13 +24,10 @@ import org.hibernate.jdbc.Work; import org.apache.log4j.Logger; import org.splat.dal.bo.kernel.User; -import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.IDBuilder; -import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.SimulationContextType; -import org.splat.dal.bo.som.Study; import org.splat.kernel.UserDirectory; import org.splat.kernel.InvalidPropertyException; import org.splat.service.technical.IndexService; @@ -39,169 +36,22 @@ import org.splat.service.technical.RepositoryService; public class Database extends org.splat.dal.dao.kernel.Database { private int uplevel = 0; // Level of database upgrade - private String basepath = null; // Path of the root directory of repository private RepositoryService _repositoryService; private IndexService _indexService; private SessionFactory _sessionFactory; private static Database my = null; // Singleton instance - protected class CreateTables extends - org.splat.dal.dao.kernel.Database.CreateTables { - // --------------------------------------------------------------------------- - public void execute(Connection connex) throws SQLException { - super.execute(connex); - - // Study Entity - String create = "CREATE TABLE `study` (" - + "`rid` int(10) UNSIGNED NOT NULL," - + "`sid` tinytext NOT NULL," - + "`title` tinytext NOT NULL," - + "`state` enum('inWORK','inDRAFT','inCHECK','APPROVED', 'TEMPLATE') NOT NULL default 'inWORK'," - + "`area` enum('PRIVATE','PUBLIC','REFERENCE') NOT NULL default 'PRIVATE'," - + "`manager` int(10) NOT NULL," - + "`version` tinytext NOT NULL," - + "`docount` int(10) UNSIGNED NOT NULL," - + "`history` int(10) UNSIGNED NOT NULL," - + "`credate` date NOT NULL," - + "`lasdate` date NOT NULL," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // Scenario Entity - create = "CREATE TABLE `scenario` (" - + "`rid` int(10) UNSIGNED NOT NULL," - + "`sid` int(10) UNSIGNED NOT NULL," - + "`owner` int(10) NOT NULL," - + "`scendex` int(3) NOT NULL," - + "`title` tinytext NOT NULL," - + "`manager` int(10) NOT NULL," + "`cuser` int(10)," - + "`credate` date NOT NULL," - + "`lasdate` date NOT NULL," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // Document Entity and document tag (Publication) - create = "CREATE TABLE `document` (" - + "`rid` int(10) UNSIGNED NOT NULL," - + "`did` tinytext NOT NULL," - + "`type` int(10) NOT NULL," - + "`step` int(10) NOT NULL," - + "`state` enum('inWORK','inDRAFT','inCHECK','APPROVED','EXTERN') NOT NULL default 'inWORK'," - + "`name` tinytext NOT NULL," - + "`author` int(10) NOT NULL," + "`version` tinytext," - + "`countag` int(10) UNSIGNED NOT NULL," - + "`history` int(10) NOT NULL," - + "`myfile` int(10) NOT NULL," - + "`lasdate` date NOT NULL," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - create = "CREATE TABLE `doctag` (" - + "`rid` int(10) UNSIGNED NOT NULL auto_increment," - + "`doc` int(10) NOT NULL," - + "`owner` int(10) NOT NULL," - + "`isnew` char(1) NOT NULL," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - // Document types - create = "CREATE TABLE `doctype` (" - + "`rid` int(10) UNSIGNED NOT NULL auto_increment," - + "`name` tinytext NOT NULL," - + "`state` enum('inCHECK','APPROVED') NOT NULL default 'inCHECK'," - + "`step` tinytext NOT NULL," + "`result` tinytext," - + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - // Document types dependencies - create = "CREATE TABLE `docuse` (" + "`owner` int(10) NOT NULL," - + "`rid` int(10) NOT NULL" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // ValidationCycle related object - create = "CREATE TABLE `cycle` (" - + "`rid` int(10) UNSIGNED NOT NULL auto_increment," - + "`type` int(10) NOT NULL," + "`publisher` int(10)," - + "`reviewer` int(10)," + "`approver` int(10)," - + "`signatory` int(10)," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // Timestamp related object - create = "CREATE TABLE `stamp` (" - + "`rid` int(10) UNSIGNED NOT NULL auto_increment," - + "`type` enum('PROMOTION','REVIEW','APPROVAL','ACCEPTANCE','DISTRIBUTION','REFUSAL') NOT NULL," - + "`author` int(10) NOT NULL," - + "`date` datetime NOT NULL," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // KnowledgeElements objects - create = "CREATE TABLE `knowelm` (" - + "`rid` int(10) UNSIGNED NOT NULL auto_increment," - + "`type` int(10) NOT NULL," - + "`owner` int(10) NOT NULL," - + "`state` enum('inWORK','inDRAFT','inCHECK','APPROVED') NOT NULL default 'inDRAFT'," - + "`title` tinytext NOT NULL," - + "`value` text NOT NULL," - + "`author` int(10) NOT NULL," - + "`date` date NOT NULL," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - // KnowledgeElement types - create = "CREATE TABLE `knowtype` (" - + "`rid` int(10) UNSIGNED NOT NULL auto_increment," - + "`name` tinytext NOT NULL," - + "`state` enum('inWORK','inCHECK','APPROVED') NOT NULL default 'inCHECK'," - + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // SimulationContext objects - create = "CREATE TABLE `contelm` (" - + "`rid` int(10) UNSIGNED NOT NULL auto_increment," - + "`type` int(10) NOT NULL," - + "`step` int(10) NOT NULL," - + "`state` enum('inCHECK','APPROVED') NOT NULL default 'inCHECK'," - + "`value` text NOT NULL," - + "`counter` int(10) UNSIGNED NOT NULL," - + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - // SimulationContext types - create = "CREATE TABLE `contype` (" - + "`rid` int(10) UNSIGNED NOT NULL auto_increment," - + "`name` tinytext NOT NULL," - + "`state` enum('inCHECK','APPROVED') NOT NULL default 'inCHECK'," - + "`step` int(10) NOT NULL," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // Many-to-many association between ProjectElement (Study and Scenario) and SimulationContext - create = "CREATE TABLE `projext` (" + "`owner` int(10) NOT NULL," - + "`ordex` int(10) NOT NULL," + "`rid` int(10) NOT NULL" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // File objects - create = "CREATE TABLE `file` (" - + "`rid` int(10) UNSIGNED NOT NULL," - + "`format` tinytext NOT NULL," - + "`path` tinytext NOT NULL," - + "`date` date NOT NULL," + "PRIMARY KEY (`rid`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - - // Reference objects - create = "CREATE TABLE `refid` (" + "`cycle` int(10) NOT NULL," - + "`base` int(10) NOT NULL," + "PRIMARY KEY (`cycle`)" - + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"; - request.execute(create); - } - } - + /** + * The job-class for database schema version ckeck. + * @author dbc + * + */ protected class CheckVersion implements Work { - // -------------------------------------------- + /** + * {@inheritDoc} + * @see org.hibernate.jdbc.Work#execute(java.sql.Connection) + */ public void execute(Connection connex) throws SQLException { DatabaseMetaData dbmdata = connex.getMetaData(); String dbname = connex.getCatalog(); @@ -235,6 +85,9 @@ public class Database extends org.splat.dal.dao.kernel.Database { private Database() { } + /** + * Check version of the database schema. + */ private void checkVersion() { getSessionFactory().getCurrentSession().doWork(new CheckVersion()); } @@ -257,8 +110,6 @@ public class Database extends org.splat.dal.dao.kernel.Database { // Creation of the SIMER SQL tables Session session = Database.getSession(); - session.doWork(new CreateTables()); // May throw SQLException if the SIMER database does not exist - session.flush(); // Population of the database with customized data this.populate(); @@ -273,7 +124,7 @@ public class Database extends org.splat.dal.dao.kernel.Database { public void configure(Properties reprop) throws IOException { // -------------------------------------------- - basepath = reprop.getProperty("repository"); + String basepath = reprop.getProperty("repository"); getRepositoryService().setBasepath(basepath); getIndexService().configure(); } @@ -302,117 +153,10 @@ public class Database extends org.splat.dal.dao.kernel.Database { // Public services // ============================================================================================================================== - public static File getDownloadDirectory(User user) { - return my.getRepositoryService().getDownloadDirectory(user); - } - - public static String getTemplatePath() { - return my.getRepositoryService().getTemplatePath(); - } - public static String getRepositoryVaultPath() { return my.getRepositoryService().getRepositoryVaultPath(); } - public static Document selectDocument(int index) { - // ------------------------------------------------- - StringBuffer query = new StringBuffer("from Document where rid='") - .append(index).append("'"); - return (Document) Database.getSession().createQuery(query.toString()) - .uniqueResult(); - } - - public static Document selectDocument(String refid, String version) { - // -------------------------------------------------------------------- - StringBuffer query = new StringBuffer("from Document where did='") - .append(refid).append("' and version='").append(version) - .append("'"); - return (Document) Database.getSession().createQuery(query.toString()) - .uniqueResult(); - } - - public static SimulationContext selectSimulationContext(int index) { - // ------------------------------------------------------------------- - StringBuffer query = new StringBuffer( - "from SimulationContext where rid='").append(index).append("'"); - return (SimulationContext) Database.getSession().createQuery( - query.toString()).uniqueResult(); - } - - public static SimulationContext selectSimulationContext( - SimulationContextType celt, String value) { - // -------------------------------------------------------------------------------------------------- - SimulationContext result = null; - try { - SimulationContext.Properties cprop = new SimulationContext.Properties(); - List clist = selectSimulationContextsWhere(cprop - .setType(celt).setValue(value)); - if (!clist.isEmpty()) - result = clist.get(0); // Supposed being the most used one if many exist - } catch (InvalidPropertyException error) { - logger.info("Attempt to select a simulation context \"" - + celt.getName() + "\" with an invalid value."); - } - return result; - } - - @SuppressWarnings("unchecked") - public static List selectSimulationContextsWhere( - SimulationContext.Properties cprop) { - // -------------------------------------------------------------------------------------------------------- - StringBuffer query = new StringBuffer("from SimulationContext"); - String separator = " where"; - SimulationContextType celt = cprop.getType(); - String value = cprop.getValue(); - ProgressState state = cprop.getProgressState(); - String order = ""; - - if (celt != null) { - query = query.append(separator).append(" type='").append( - celt.getIndex()).append("'"); - separator = " and"; - order = " order by value asc"; - } - if (value != null) { - query = query.append(separator).append(" value='").append(value) - .append("'"); - separator = " and"; - } - if (state != null) { - query = query.append(separator).append(" state='").append(state) - .append("'"); - if (celt == null) - order = " order by type asc"; - } - query.append(order); - return (List) Database.getSession().createQuery( - query.toString()).list(); - } - - protected static IDBuilder selectIDBuilder(int cycle) { - // ------------------------------------------------------ - StringBuffer buffer = new StringBuffer("from IDBuilder where cycle='") - .append(cycle).append("'"); - String qstring = buffer.toString(); - Query query = Database.getSession().createQuery(qstring); - IDBuilder result = (IDBuilder) query.uniqueResult(); - - return result; - } - - public static IDBuilder selectIDBuilder(Date date) { - // ------------------------------------------------------ - SimpleDateFormat year = new SimpleDateFormat("yyyy"); - String cycle = year.format(date); - StringBuffer buffer = new StringBuffer("from IDBuilder where cycle='") - .append(cycle).append("'"); - String qstring = buffer.toString(); - Query query = Database.getSession().createQuery(qstring); - IDBuilder result = (IDBuilder) query.uniqueResult(); - - return result; - } - /** * @return */ diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAO.java index 7fdc84a..61d6169 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAOImpl.java index 7726eee..65c5fb8 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAO.java index 5f7e795..7ee70a8 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAOImpl.java index dfc5e90..5f77434 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/DocumentTypeDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAO.java index 1bf937f..9f8eb48 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAOImpl.java index 420e9ba..52eac13 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/FileDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAO.java index 38e5ad6..a719d1e 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAOImpl.java index e59e606..08557ad 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/IDBuilderDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAO.java index ccf72ec..18db28d 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAOImpl.java index 6e3d918..2cd87ae 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAO.java index 264d5b4..960c226 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAOImpl.java index c7634f6..2e5a78c 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/KnowledgeElementTypeDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAO.java index 0122d21..e2cdd32 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAOImpl.java index 33bcd15..7342d72 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/PublicationDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAO.java index 404d80b..bcf1937 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAOImpl.java index a267181..f43e4bb 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ScenarioDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAO.java index 8305e68..2333ff2 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAOImpl.java index 7c97821..3abd7cf 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAO.java index 48d6e4c..268554d 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAOImpl.java index 10dfb52..68dc7f3 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/SimulationContextTypeDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAO.java index 6ae5c64..1399015 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAOImpl.java index 93aa81f..95ac8ff 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StampRelationDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAO.java index b3c530c..9a90f50 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAOImpl.java index 95c195f..d67e01a 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StudyDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAO.java index 99e1da5..f4d743f 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAOImpl.java index c2e51a4..a1d1654 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/TimestampDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAO.java index 6a82516..4090e07 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAOImpl.java index 5c8fe48..7d96c49 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsedByRelationDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAO.java index 47e13a3..c281679 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAOImpl.java index 35700be..2e84f01 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/UsesRelationDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAO.java index 34091d1..ab14a50 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAOImpl.java index a15006e..53f73d8 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAO.java index b4c0024..dc81173 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAOImpl.java index 7d59b81..ca27e8b 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/ValidationCycleRelationDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAO.java index f91231f..fd26e26 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAO.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAOImpl.java index 86bf5b6..3f73af8 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/VersionsRelationDAOImpl.java @@ -5,6 +5,7 @@ * Creation date 06.10.2012 * @author $Author$ * @version $Revision$ + * Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 *****************************************************************************/ package org.splat.dal.dao.som; diff --git a/Workspace/Siman-Common/src/org/splat/kernel/UserDirectory.java b/Workspace/Siman-Common/src/org/splat/kernel/UserDirectory.java index e9eefeb..e0fa88e 100644 --- a/Workspace/Siman-Common/src/org/splat/kernel/UserDirectory.java +++ b/Workspace/Siman-Common/src/org/splat/kernel/UserDirectory.java @@ -155,13 +155,13 @@ public class UserDirectory { @SuppressWarnings("unchecked") // For the casting List public static List selectAllUsers () { // ------------------------------------------ - String query = "FROM users order by last asc, first asc"; + String query = "FROM User order by last asc, first asc"; return (List)Database.getSession().createQuery(query).list(); } public static User selectUser (String username) { // ----------------------------------------------- - StringBuffer query = new StringBuffer("FROM users where username='").append(username).append("'"); + StringBuffer query = new StringBuffer("FROM User where username='").append(username).append("'"); return (User)Database.getSession().createQuery(query.toString()).uniqueResult(); } @@ -169,7 +169,7 @@ public class UserDirectory { // ---------------------------------------------------------------- //WARNING: For not encoding the password here, we better call a selectUsersWhere(User.Properties), // but this requires a getPassword in User.Properties nested class. - StringBuffer query = new StringBuffer("FROM users where username='").append(username).append("' and password"); + StringBuffer query = new StringBuffer("FROM User where username='").append(username).append("' and password"); if (password == null) query = query.append(" is null"); else query = query.append("='").append(String.valueOf(password.hashCode())).append("'"); @@ -178,14 +178,14 @@ public class UserDirectory { public static User selectUser (int index) { // ----------------------------------------- - StringBuffer query = new StringBuffer("FROM users where rid='").append(index).append("'"); + StringBuffer query = new StringBuffer("FROM User where rid='").append(index).append("'"); return (User)Database.getSession().createQuery(query.toString()).uniqueResult(); } @SuppressWarnings("unchecked") public static List selectUsersWhere (User.Properties... uprop) { // -------------------------------------------------------------------- - StringBuffer query = new StringBuffer("FROM users"); + StringBuffer query = new StringBuffer("FROM User"); String separator = " where ("; String value; diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentService.java b/Workspace/Siman-Common/src/org/splat/service/DocumentService.java index a956b69..952f529 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentService.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentService.java @@ -10,7 +10,6 @@ package org.splat.service; import org.splat.dal.bo.som.Document; -import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Document.Properties; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MissedPropertyException; @@ -18,6 +17,8 @@ import org.splat.kernel.NotApplicableException; import org.splat.som.Step; /** + * Document service interface. + * * @author RKV * */ @@ -26,9 +27,16 @@ public interface DocumentService { /** * Defines this document. * + * @param aDoc + * the document to define * @param dprop * the properties of the document - * + * @throws MissedPropertyException + * if a mandatory property is missed + * @throws InvalidPropertyException + * if a property doesn't exist + * @throws NotApplicableException + * if the document is undefined * @see Step#createDocument(Properties) * @see #isUndefined() */ @@ -36,5 +44,40 @@ public interface DocumentService { throws MissedPropertyException, InvalidPropertyException, NotApplicableException; + /** + * Find a document by its id. + * + * @param index + * document id + * @return found document + */ + public Document selectDocument(long index); + + /** + * Find a document by its reference and version. + * + * @param refid + * document reference + * @param version + * document version + * @return found document + */ + public Document selectDocument(String refid, String version); + + /** + * Generate document reference. + * + * @param aDoc + * the document + * @param dprop + * 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 + * @return a directory + */ + public java.io.File getSaveDirectory(Document aDoc); } diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java index fef0b99..d922281 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java @@ -7,7 +7,7 @@ * @version $Revision$ *****************************************************************************/ -package org.splat.service; +package org.splat.service; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -18,23 +18,66 @@ import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.Document.Properties; import org.splat.dal.dao.som.Database; +import org.splat.dal.dao.som.DocumentDAO; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MissedPropertyException; import org.splat.kernel.NotApplicableException; import org.splat.service.technical.ProjectSettingsService; import org.splat.service.technical.ProjectSettingsServiceImpl; import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming; -import org.splat.som.Step; +import org.springframework.transaction.annotation.Transactional; /** + * Document service implementation. + * * @author RKV - * + * */ public class DocumentServiceImpl implements DocumentService { + /** + * Injected study service. + */ private StudyService _studyService; + /** + * Injected project settings service. + */ private ProjectSettingsService _projectSettingsService; + /** + * Injected document service. + */ + private DocumentDAO _documentDAO; + + /** + * {@inheritDoc} + * + * @see org.splat.service.DocumentService#selectDocument(long) + */ + @Transactional(readOnly = true) + public Document selectDocument(long index) { + // ------------------------------------------------- + return getDocumentDAO().get(index); + } + /** + * {@inheritDoc} + * + * @see org.splat.service.DocumentService#selectDocument(java.lang.String, java.lang.String) + */ + public Document selectDocument(String refid, String version) { + // -------------------------------------------------------------------- + StringBuffer query = new StringBuffer("from Document where did='") + .append(refid).append("' and version='").append(version) + .append("'"); + return (Document) Database.getSession().createQuery(query.toString()) + .uniqueResult(); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.DocumentService#generateDocumentId(org.splat.dal.bo.som.Document, org.splat.dal.bo.som.Document.Properties) + */ public void generateDocumentId(Document aDoc, Properties dprop) { Study owner = null; if (dprop.getOwner() instanceof Study) @@ -48,19 +91,31 @@ public class DocumentServiceImpl implements DocumentService { String path = owner.getReference(); ProjectSettingsService.Step step = ProjectSettingsServiceImpl .getStep(aDoc.getStep()); - aDoc.setDid( new StringBuffer(path).append(".%").append(aDoc.suformat).toString()); // Document reference + aDoc.setDid(new StringBuffer(path).append(".%").append( + Document.suformat).toString()); // Document reference path = new StringBuffer(year).append("/").append(path).append("/") - .append(step.getPath()) // File path relative to the repository vault - .append(filename).append(".").append(aDoc.getFile().getFormat()) // File name and extension + .append(step.getPath()) + // File path relative to the repository vault + .append(filename).append(".") + .append(aDoc.getFile().getFormat()) // File name and extension .toString(); aDoc.getFile().changePath(path); } + /** + * Generate encoded document file name according to the naming scheme from project settings. + * + * @param aDoc + * the document + * @param scope + * the study + * @return document reference name + */ private String generateEncodedName(Document aDoc, Study scope) { // ------------------------------------------------ StringBuffer encoding = new StringBuffer(); FileNaming scheme = getProjectSettings().getFileNamingScheme(); - DecimalFormat tostring = new DecimalFormat(aDoc.suformat); + DecimalFormat tostring = new DecimalFormat(Document.suformat); int number = getStudyService().generateLocalIndex(scope); @@ -68,11 +123,21 @@ public class DocumentServiceImpl implements DocumentService { encoding.append(scope.getReference()).append(".").append( tostring.format(number)); } else { // title and (temporarily) asis - encoding.append(aDoc.getTitle()).append(".").append(tostring.format(number)); + encoding.append(aDoc.getTitle()).append(".").append( + tostring.format(number)); } return encoding.toString(); } + /** + * Get encoded root name for a document file. + * + * @param aDoc + * the document + * @param scope + * the study + * @return file name + */ private String getEncodedRootName(Document aDoc, Study scope) { // ----------------------------------------------- FileNaming scheme = getProjectSettings().getFileNamingScheme(); @@ -84,16 +149,13 @@ public class DocumentServiceImpl implements DocumentService { } /** - * Defines this document. - * - * @param dprop - * the properties of the document + * {@inheritDoc} * - * @see Step#createDocument(Properties) - * @see #isUndefined() + * @see org.splat.service.DocumentService#initialize(org.splat.dal.bo.som.Document, org.splat.dal.bo.som.Document.Properties) */ - public void initialize(Document aDoc, Properties dprop) throws MissedPropertyException, - InvalidPropertyException, NotApplicableException { + public void initialize(Document aDoc, Properties dprop) + throws MissedPropertyException, InvalidPropertyException, + NotApplicableException { // -------------------------------------------- if (!aDoc.isUndefined()) throw new NotApplicableException( @@ -108,10 +170,11 @@ public class DocumentServiceImpl implements DocumentService { // throw new InvalidPropertyException("step"); // } aDoc.setTitle(dprop.getName()); - aDoc.getFile().changePath(aDoc.getFile().getRelativePath().replace("%n", - getEncodedRootName(aDoc, (Study) dprop.getOwner()))); + aDoc.getFile().changePath( + aDoc.getFile().getRelativePath().replace("%n", + getEncodedRootName(aDoc, (Study) dprop.getOwner()))); if (aDoc.getHistory() == -1) - aDoc.setHistory( 0 ); + aDoc.setHistory(0); if (dprop.getDate() == null) { Calendar current = Calendar.getInstance(); aDoc.setLastModificationDate(current.getTime()); // Today @@ -121,8 +184,21 @@ public class DocumentServiceImpl implements DocumentService { Database.getSession().update(aDoc); } + public java.io.File getSaveDirectory(Document aDoc) { + String mypath = Database.getRepositoryVaultPath() + + aDoc.getSourceFile().getRelativePath(); + String[] table = mypath.split("/"); + + // Cutting the filename + StringBuffer path = new StringBuffer(table[0]); + for (int i = 1; i < table.length - 1; i++) + path = path.append("/").append(table[i]); + return new java.io.File(path.append("/").toString()); + } + /** * Get the studyService. + * * @return the studyService */ public StudyService getStudyService() { @@ -131,7 +207,9 @@ public class DocumentServiceImpl implements DocumentService { /** * Set the studyService. - * @param studyService the studyService to set + * + * @param studyService + * the studyService to set */ public void setStudyService(StudyService studyService) { _studyService = studyService; @@ -156,4 +234,23 @@ public class DocumentServiceImpl implements DocumentService { _projectSettingsService = projectSettingsService; } + /** + * Get the documentDAO. + * + * @return the documentDAO + */ + public DocumentDAO getDocumentDAO() { + return _documentDAO; + } + + /** + * Set the documentDAO. + * + * @param documentDAO + * the documentDAO to set + */ + public void setDocumentDAO(DocumentDAO documentDAO) { + _documentDAO = documentDAO; + } + } diff --git a/Workspace/Siman-Common/src/org/splat/service/ProjectElementService.java b/Workspace/Siman-Common/src/org/splat/service/ProjectElementService.java index b9fd9d5..7f9564d 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ProjectElementService.java +++ b/Workspace/Siman-Common/src/org/splat/service/ProjectElementService.java @@ -13,12 +13,23 @@ import org.splat.dal.bo.som.ProjectElement; import org.splat.som.Step; /** + * Project element service interface. * @author RKV * */ public interface ProjectElementService { + /** + * Get the first activity of the project element. + * @param elem a study or a scenario + * @return the first activity (step) of the project element + */ public Step getFirstStep(ProjectElement elem); + /** + * Get activities of the project element. + * @param elem a study or a scenario + * @return array of activities (steps). + */ public Step[] getSteps(ProjectElement elem); } diff --git a/Workspace/Siman-Common/src/org/splat/service/ProjectElementServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/ProjectElementServiceImpl.java index 031b2ee..a8a5080 100644 --- a/Workspace/Siman-Common/src/org/splat/service/ProjectElementServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/ProjectElementServiceImpl.java @@ -14,30 +14,38 @@ import java.util.List; import org.splat.dal.bo.som.ProjectElement; import org.splat.service.technical.ProjectSettingsService; -import org.splat.service.technical.ProjectSettingsServiceImpl; import org.splat.som.Step; /** + * Project element service implementation. * @author RKV * */ public class ProjectElementServiceImpl implements ProjectElementService { + /** + * Injected project settings service. + */ private ProjectSettingsService _projectSettingsService; + /** + * {@inheritDoc} + * @see org.splat.service.ProjectElementService#getFirstStep(org.splat.dal.bo.som.ProjectElement) + */ public Step getFirstStep(ProjectElement elem) { - // --------------------------- return getSteps(elem)[0]; } public Step getLastStep(ProjectElement elem) { - // -------------------------- Step[] mystep = getSteps(elem); // For getting the folders length, if null return mystep[mystep.length - 1]; } + /** + * {@inheritDoc} + * @see org.splat.service.ProjectElementService#getSteps(org.splat.dal.bo.som.ProjectElement) + */ public Step[] getSteps(ProjectElement elem) { - // ------------------------- if (elem.getFolders() == null) { List steps = getProjectSettings() .getStepsOf(elem.getClass()); diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java index 2b629c0..a2eb497 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java @@ -24,24 +24,40 @@ import org.splat.som.Revision; import org.splat.som.Step; /** - * @author RKV + * Publication service interface. * + * @author Roman Kozlov (RKV) */ public interface PublicationService { + /** + * Copy the publication to the given project element. + * + * @param aPublication + * the publication to copy + * @param publisher + * the target project element + * @return the created copy of the publication + */ public Publication copy(Publication aPublication, ProjectElement publisher); /** * Returns the study Step into which the document version referenced by this publication has been published. + * + * @param aPublication + * the document publication + * @return study step */ public Step getInvolvedStep(Publication aPublication); /** * Promotes the document referenced by this publication from In-Check to Approved state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
If the promoted document is the final result of the owner study, the study is itself - * is promoted as well.

Limitation: the way this promotion is propagated to the study supposes that the study has only ONE + * corresponding time-stamp to the document.
If the promoted document is the final result of the owner study, the study is itself + * is promoted as well.

Limitation: the way this promotion is propagated to the study supposes that the study has only ONE * final result document. * + * @param aPublication + * the document publication * @param adate * the date of approval * @return true if the approval succeeded @@ -53,11 +69,13 @@ public interface PublicationService { public Timestamp approve(Publication aPublication, Date adate); /** - * Demotes the document referenced by this publication to In-Work state, and removes the Promoter of the document, if exist.
The - * In-Draft state is skipped (direct demotion to In-Work) if the validation cycle of the document does not include the review step.
- * If the demoted document is the final result of the owner study, the study is itself is demoted as well.

Limitation: the + * Demotes the document referenced by this publication to In-Work state, and removes the Promoter of the document, if exist.
The + * In-Draft state is skipped (direct demotion to In-Work) if the validation cycle of the document does not include the review step.
+ * If the demoted document is the final result of the owner study, the study is itself is demoted as well.

Limitation: the * way this demotion is propagated to the study supposes that the study has only ONE final result document. * + * @param aPublication + * the document publication * @return true if the demotion succeeded * @see #getProgressState() * @see DocumentRights#canDemote() @@ -67,9 +85,11 @@ public interface PublicationService { /** * Undo the review operation by demoting the document referenced by this publication from In-Check to In-Draft state and removing the - * Reviewer.
If the demoted document is the final result of the owner study, the study is itself is demoted as well.

+ * Reviewer.
If the demoted document is the final result of the owner study, the study is itself is demoted as well.

* Limitation: the way this demotion is propagated to the study supposes that the study has only ONE final result document. * + * @param aPublication + * the document publication * @return true if the demotion succeeded * @see #getProgressState() * @see #review() @@ -80,11 +100,15 @@ public interface PublicationService { /** * Promotes the document referenced by this publication from In-Work to In-Draft or In-Check state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
The In-Draft state is skipped (direct promotion to In-Check) if the validation cycle - * of the document does not include the review step.
Also, if the promoted document is the final result of the owner study, the - * study is itself promoted as well.
This operation can be undo-ed by demote().

Limitation: the way this promotion is + * corresponding time-stamp to the document.
The In-Draft state is skipped (direct promotion to In-Check) if the validation cycle + * of the document does not include the review step.
Also, if the promoted document is the final result of the owner study, the + * study is itself promoted as well.
This operation can be undo-ed by demote().

Limitation: the way this promotion is * propagated to the study supposes that the study has only ONE final result document. * + * @param aPublication + * the document publication + * @param pdate + * the date of promotion * @return true if the promotion succeeded * @see #getProgressState() * @see #demote() @@ -95,10 +119,12 @@ public interface PublicationService { /** * Promotes the document referenced by this publication from In-Draft to In-Check state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
If the promoted document is the final result of the owner study, the study is itself - * is promoted as well.
This operation can be undo-ed by invalidate().

Limitation: the way this promotion is propagated - * to the study supposes that the study has only ONE final result document. + * corresponding time-stamp to the document.
If the promoted document is the final result of the owner study, the study is itself + * is promoted as well.
This operation can be undo-ed by invalidate().

Limitation: the way this promotion is + * propagated to the study supposes that the study has only ONE final result document. * + * @param aPublication + * the document publication * @param rdate * the date of review * @return true if the review succeeded @@ -115,6 +141,8 @@ public interface PublicationService { * the document being automatically set accordingly. If the given state is In-Draft and the document is final result of the owner study, * this automatically promotes the study to In-Draft. * + * @param aPublication + * the document publication * @param state * the required progress state * @throws FileNotFoundException @@ -126,12 +154,14 @@ public interface PublicationService { throws FileNotFoundException, NotApplicableException; /** - * Publishes the document referenced by this publication into the owner Project Element under the given revision number.
- * The state of the referenced document is supposed being automatically set according to the given revision number, but, due to the - * versioning scheme, as it is not possible to differentiate In-Work and In-Draft states, this function has been deprecated (it is - * currently used only for the need of integration of Microsoft Office which anyway has to be redesigned).
- * Note: in the context of branch versioning, the given revision may be modified by an update of the branch name. + * Publishes the document referenced by this publication into the owner Project Element under the given revision number.
The state + * of the referenced document is supposed being automatically set according to the given revision number, but, due to the versioning + * scheme, as it is not possible to differentiate In-Work and In-Draft states, this function has been deprecated (it is currently used + * only for the need of integration of Microsoft Office which anyway has to be redesigned).
Note: in the context of branch + * versioning, the given revision may be modified by an update of the branch name. * + * @param aPublication + * the document publication * @param newvers * the required revision number * @throws FileNotFoundException diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index 7fb730b..e2e5302 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -32,23 +32,43 @@ import org.splat.dal.dao.som.Database; import org.splat.kernel.NotApplicableException; import org.splat.manox.Reader; import org.splat.manox.Toolbox; -import org.splat.som.DocumentRights; import org.splat.som.Revision; import org.splat.som.Step; /** - * @author RKV + * Publication service implementation. * + * @author Roman Kozlov (RKV) */ public class PublicationServiceImpl implements PublicationService { + /** + * Injected study service. + */ private StudyService _studyService; + /** + * Injected study service. + */ private StepService _stepService; + /** + * Injected study service. + */ private DocumentTypeService _documentTypeService; + /** + * Injected study service. + */ private ProjectElementService _projectElementService; + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; + /** + * {@inheritDoc} + * + * @see org.splat.service.PublicationService#copy(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProjectElement) + */ public Publication copy(Publication aPublication, ProjectElement publisher) { - // ----------------------------------------------------- Publication copy = new Publication(); copy.setValue(aPublication.value()); copy.setStep(aPublication.getStep()); // May not be initialized yet @@ -61,18 +81,9 @@ public class PublicationServiceImpl implements PublicationService { } /** - * Promotes the document referenced by this publication from In-Check to Approved state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
If the promoted document is the final result of the owner study, the study is itself - * is promoted as well.

Limitation: the way this promotion is propagated to the study supposes that the study has only ONE - * final result document. + * {@inheritDoc} * - * @param adate - * the date of approval - * @return true if the approval succeeded - * @see #getProgressState() - * @see DocumentRights#canApprove() - * @see DocumentType#isStudyResult() - * @see Study#getApproverOf(Publication) + * @see org.splat.service.PublicationService#approve(org.splat.dal.bo.som.Publication, java.util.Date) */ public Timestamp approve(Publication aPublication, Date adate) { // ------------------------------------- @@ -85,8 +96,8 @@ public class PublicationServiceImpl implements PublicationService { Study owner = aPublication.getOwnerStudy(); ValidationCycle cycle = owner.getValidationCycleOf(type); User approver = cycle.getActor(ValidationStep.APPROVAL); - Timestamp stamp = new Timestamp(ValidationStep.APPROVAL, - aPublication.value(), approver, adate); + Timestamp stamp = new Timestamp(ValidationStep.APPROVAL, aPublication + .value(), approver, adate); if (!aPublication.value().promote(stamp)) return null; if (getDocumentTypeService().isStudyResult(type) @@ -96,15 +107,9 @@ public class PublicationServiceImpl implements PublicationService { } /** - * Demotes the document referenced by this publication to In-Work state, and removes the Promoter of the document, if exist.
The - * In-Draft state is skipped (direct demotion to In-Work) if the validation cycle of the document does not include the review step.
- * If the demoted document is the final result of the owner study, the study is itself is demoted as well.

Limitation: the - * way this demotion is propagated to the study supposes that the study has only ONE final result document. + * {@inheritDoc} * - * @return true if the demotion succeeded - * @see #getProgressState() - * @see DocumentRights#canDemote() - * @see DocumentType#isStudyResult() + * @see org.splat.service.PublicationService#demote(org.splat.dal.bo.som.Publication) */ public boolean demote(Publication aPublication) { // ------------------------ @@ -134,15 +139,9 @@ public class PublicationServiceImpl implements PublicationService { } /** - * Undo the review operation by demoting the document referenced by this publication from In-Check to In-Draft state and removing the - * Reviewer.
If the demoted document is the final result of the owner study, the study is itself is demoted as well.

- * Limitation: the way this demotion is propagated to the study supposes that the study has only ONE final result document. + * {@inheritDoc} * - * @return true if the demotion succeeded - * @see #getProgressState() - * @see #review() - * @see DocumentRights#canInvalidate() - * @see DocumentType#isStudyResult() + * @see org.splat.service.PublicationService#invalidate(org.splat.dal.bo.som.Publication) */ public boolean invalidate(Publication aPublication) { // ---------------------------- @@ -159,17 +158,9 @@ public class PublicationServiceImpl implements PublicationService { } /** - * Promotes the document referenced by this publication from In-Work to In-Draft or In-Check state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
The In-Draft state is skipped (direct promotion to In-Check) if the validation cycle - * of the document does not include the review step.
Also, if the promoted document is the final result of the owner study, the - * study is itself promoted as well.
This operation can be undo-ed by demote().

Limitation: the way this promotion is - * propagated to the study supposes that the study has only ONE final result document. + * {@inheritDoc} * - * @return true if the promotion succeeded - * @see #getProgressState() - * @see #demote() - * @see DocumentRights#canPromote() - * @see DocumentType#isStudyResult() + * @see org.splat.service.PublicationService#promote(org.splat.dal.bo.som.Publication, java.util.Date) */ public Timestamp promote(Publication aPublication, Date pdate) { if (aPublication.isOutdated()) @@ -201,19 +192,9 @@ public class PublicationServiceImpl implements PublicationService { } /** - * Promotes the document referenced by this publication from In-Draft to In-Check state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
If the promoted document is the final result of the owner study, the study is itself - * is promoted as well.
This operation can be undo-ed by invalidate().

Limitation: the way this promotion is propagated - * to the study supposes that the study has only ONE final result document. + * {@inheritDoc} * - * @param rdate - * the date of review - * @return true if the review succeeded - * @see #getProgressState() - * @see #invalidate() - * @see DocumentRights#canReview() - * @see DocumentType#isStudyResult() - * @see Study#getReviewerOf(Publication) + * @see org.splat.service.PublicationService#review(org.splat.dal.bo.som.Publication, java.util.Date) */ public Timestamp review(Publication aPublication, Date rdate) { if (aPublication.isOutdated()) @@ -225,8 +206,8 @@ public class PublicationServiceImpl implements PublicationService { Study owner = aPublication.getOwnerStudy(); ValidationCycle cycle = owner.getValidationCycleOf(type); User reviewer = cycle.getActor(ValidationStep.REVIEW); - Timestamp stamp = new Timestamp(ValidationStep.REVIEW, - aPublication.value(), reviewer, rdate); + Timestamp stamp = new Timestamp(ValidationStep.REVIEW, aPublication + .value(), reviewer, rdate); if (!aPublication.value().promote(stamp)) return null; if (getDocumentTypeService().isStudyResult(type) @@ -236,18 +217,9 @@ public class PublicationServiceImpl implements PublicationService { } /** - * Publishes the document referenced by this publication into the owner Project Element under the given revision number.
- * The state of the referenced document is supposed being automatically set according to the given revision number, but, due to the - * versioning scheme, as it is not possible to differentiate In-Work and In-Draft states, this function has been deprecated (it is - * currently used only for the need of integration of Microsoft Office which anyway has to be redesigned).
- * Note: in the context of branch versioning, the given revision may be modified by an update of the branch name. + * {@inheritDoc} * - * @param newvers - * the required revision number - * @throws FileNotFoundException - * If the referenced document is empty - * @throws NotApplicableException - * If the referenced document is undefined + * @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.som.Revision) * @deprecated */ public void saveAs(Publication aPublication, Revision newvers) @@ -265,16 +237,9 @@ public class PublicationServiceImpl implements PublicationService { } /** - * Publishes the document referenced by this publication into the owner Project Element under the given state, the revision number of - * the document being automatically set accordingly. If the given state is In-Draft and the document is final result of the owner study, - * this automatically promotes the study to In-Draft. + * {@inheritDoc} * - * @param state - * the required progress state - * @throws FileNotFoundException - * If the referenced document is empty - * @throws NotApplicableException - * If the referenced document is undefined + * @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProgressState) */ public void saveAs(Publication aPublication, ProgressState state) throws FileNotFoundException, NotApplicableException { @@ -286,7 +251,8 @@ 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) hascode + Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based) + // hascode aPublication.value().updateAs(state); } else { DocumentType mytype = aPublication.value().getType(); @@ -300,7 +266,7 @@ public class PublicationServiceImpl implements PublicationService { + " state"); } Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based) - // hascode + // hascode aPublication.value().updateAs(ProgressState.inWORK); promote(aPublication, aPublication.value() @@ -309,8 +275,13 @@ public class PublicationServiceImpl implements PublicationService { updateOwner(aPublication); } - public void updateOwner(Publication aPublication) { - // --------------------------- + /** + * Update an owner of the publication. + * + * @param aPublication + * the document publication + */ + private void updateOwner(Publication aPublication) { Session session = Database.getSession(); Step step = getInvolvedStep(aPublication); @@ -330,6 +301,16 @@ public class PublicationServiceImpl implements PublicationService { session.update(aPublication.getOwner()); } + /** + * Propagate simulation contexts from the given config file to the publication's owner (study or step). + * + * @param aPublication + * the document publication + * @param from + * the config file + * @param to + * the study step + */ private void forwardProperties(Publication aPublication, java.io.File from, Step to) { // ----------------------------------------------------------- @@ -339,7 +320,7 @@ public class PublicationServiceImpl implements PublicationService { SimulationContextType.Properties sprop = new SimulationContextType.Properties() .setStep(to.getStep()).setState(ProgressState.APPROVED); - List contype = SimulationContext + List contype = getSimulationContextService() .selectTypesWhere(sprop); if (contype.isEmpty()) return; // No approved property type configured at this step @@ -381,10 +362,15 @@ public class PublicationServiceImpl implements PublicationService { /** * Returns the study Step into which the document version referenced by this publication has been published. + * + * @param aPublication + * the document publication + * @return the study step where the document is published */ public Step getInvolvedStep(Publication aPublication) { if (aPublication.getStep() == null) { - Step[] step = getProjectElementService().getSteps(aPublication.getOwner()); + Step[] step = getProjectElementService().getSteps( + aPublication.getOwner()); for (int i = 0; i < step.length; i++) { aPublication.setStep(step[i]); // The involved step necessarily exists if (aPublication.value().isInto(aPublication.getStep())) @@ -395,51 +381,90 @@ public class PublicationServiceImpl implements PublicationService { } /** - * @return + * Get the projectElementService. + * + * @return the projectElementService */ - private StepService getStepService() { - return _stepService; + public ProjectElementService getProjectElementService() { + return _projectElementService; } - public void setStepService(StepService stepService) { - _stepService = stepService; + /** + * Set the projectElementService. + * + * @param projectElementService + * the projectElementService to set + */ + public void setProjectElementService( + ProjectElementService projectElementService) { + _projectElementService = projectElementService; + } + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; } /** - * @return + * 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; } /** - * @return + * Get the stepService. + * @return the stepService */ - public DocumentTypeService getDocumentTypeService() { - return _documentTypeService; + public StepService getStepService() { + return _stepService; } - public void setDocumentTypeService(DocumentTypeService documentTypeService) { - _documentTypeService = documentTypeService; + /** + * Set the stepService. + * @param stepService the stepService to set + */ + public void setStepService(StepService stepService) { + _stepService = stepService; } /** - * Get the projectElementService. - * @return the projectElementService + * Get the documentTypeService. + * @return the documentTypeService */ - public ProjectElementService getProjectElementService() { - return _projectElementService; + public DocumentTypeService getDocumentTypeService() { + return _documentTypeService; } /** - * Set the projectElementService. - * @param projectElementService the projectElementService to set + * Set the documentTypeService. + * @param documentTypeService the documentTypeService to set */ - public void setProjectElementService(ProjectElementService projectElementService) { - _projectElementService = projectElementService; + public void setDocumentTypeService(DocumentTypeService documentTypeService) { + _documentTypeService = documentTypeService; } } diff --git a/Workspace/Siman-Common/src/org/splat/service/SimulationContextService.java b/Workspace/Siman-Common/src/org/splat/service/SimulationContextService.java new file mode 100644 index 0000000..1cbf05c --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/service/SimulationContextService.java @@ -0,0 +1,136 @@ +/***************************************************************************** + * Company EURIWARE + * Application SIMAN + * File $Id$ + * Creation date 16.10.2012 + * @author $Author$ + * @version $Revision$ + *****************************************************************************/ + +package org.splat.service; + +import java.util.List; + +import org.splat.dal.bo.som.SimulationContext; +import org.splat.dal.bo.som.SimulationContextType; +import org.splat.kernel.InvalidPropertyException; +import org.splat.service.technical.ProjectSettingsService; + +/** + * Simulation context service interface. + * + * @author Roman Kozlov (RKV) + * + */ +public interface SimulationContextService { + + /** + * Get simulation context by its id. + * + * @param index + * simulation context id. + * @return found context + */ + public SimulationContext selectSimulationContext(long index); + + /** + * Find simulation context by its type and value. + * + * @param celt + * context type + * @param value + * context value + * @return found context + */ + public SimulationContext selectSimulationContext( + SimulationContextType celt, String value); + + /** + * Find simulation contexts by example. + * + * @param cprop + * example properties + * @return list of contexts + */ + public List selectSimulationContextsWhere( + SimulationContext.Properties cprop); + + /** + * Create a simulation context type. + * + * @param name + * context type name + * @param step + * activity related to this context type + * @return the created context type + * @throws InvalidPropertyException + * if some property of the type to be created is invalid + */ + public SimulationContextType createType(String name, + ProjectSettingsService.Step step) throws InvalidPropertyException; + + /** + * Get all simulation context types. + * + * @return list of context types + */ + public List selectAllTypes(); + + /** + * Get simulation context types related to given activities. + * + * @param step + * the activity + * @return list of found context types + */ + public List selectTypesOf( + ProjectSettingsService.Step... step); + + /** + * Get simulation context types by example. + * @param sprop the example + * @return list of found context types + */ + public List selectTypesWhere( + SimulationContextType.Properties sprop); + + /** + * Get a simulation context type by its name. + * @param name name of the context type + * @return found context type + */ + public SimulationContextType selectType(String name); + + /** + * Get simulation context type by its id. + * + * @param index + * simulation context type id. + * @return found context type + */ + public SimulationContextType selectType(long index); + + /** + * Hold the simulation context. + * + * @param simCtx + * the context to hold. + */ + public void hold(SimulationContext simCtx); + + /** + * Release the simulation context. + * + * @param simCtx + * the context to release + */ + public void release(SimulationContext simCtx); + + /** + * Get the simulation context list for displaying drop-down list values populating on the "Create new study" screen. + * + * @return List of the simulation contexts. + */ + List getSimulationContextList(); + +} diff --git a/Workspace/Siman-Common/src/org/splat/service/SimulationContextServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/SimulationContextServiceImpl.java new file mode 100644 index 0000000..729e7d4 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/service/SimulationContextServiceImpl.java @@ -0,0 +1,312 @@ +/***************************************************************************** + * Company EURIWARE + * Application SIMAN + * File $Id$ + * Creation date 16.10.2012 + * @author $Author$ + * @version $Revision$ + *****************************************************************************/ + +package org.splat.service; + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Example; +import org.hibernate.criterion.Order; +import org.hibernate.criterion.PropertyExpression; +import org.hibernate.criterion.Restrictions; +import org.splat.dal.bo.som.ProgressState; +import org.splat.dal.bo.som.SimulationContext; +import org.splat.dal.bo.som.SimulationContextType; +import org.splat.dal.dao.som.Database; +import org.splat.dal.dao.som.SimulationContextDAO; +import org.splat.dal.dao.som.SimulationContextTypeDAO; +import org.splat.kernel.InvalidPropertyException; +import org.splat.log.AppLogger; +import org.splat.service.technical.ProjectSettingsService; +import org.springframework.transaction.annotation.Transactional; + +/** + * Simulation context service implementation. + * + * @author rkv + * + */ +public class SimulationContextServiceImpl implements SimulationContextService { + + /** + * logger for the service. + */ + public final static AppLogger logger = AppLogger + .getLogger(SimulationContextServiceImpl.class); + /** + * Injected simulation context DAO. + */ + private SimulationContextDAO _simulationContextDAO; + + /** + * Injected simulation context type DAO. + */ + private SimulationContextTypeDAO _simulationContextTypeDAO; + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#selectSimulationContext(int) + */ + public SimulationContext selectSimulationContext(long index) { + return getSimulationContextDAO().get(index); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#selectSimulationContext(org.splat.dal.bo.som.SimulationContextType, java.lang.String) + */ + public SimulationContext selectSimulationContext( + SimulationContextType celt, String value) { + SimulationContext result = null; + try { + SimulationContext.Properties cprop = new SimulationContext.Properties(); + List clist = selectSimulationContextsWhere(cprop + .setType(celt).setValue(value)); + if (!clist.isEmpty()) + result = clist.get(0); // Supposed being the most used one if many exist + } catch (InvalidPropertyException error) { + logger.info("Attempt to select a simulation context \"" + + celt.getName() + "\" with an invalid value."); + } + return result; + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#selectSimulationContextsWhere(org.splat.dal.bo.som.SimulationContext.Properties) + */ + @Transactional(readOnly=true) + public List selectSimulationContextsWhere( + SimulationContext.Properties cprop) { +// StringBuffer query = new StringBuffer("from SimulationContext"); +// String separator = " where"; + SimulationContextType celt = cprop.getType(); + String value = cprop.getValue(); + ProgressState state = cprop.getProgressState(); +// String order = ""; + Criterion aCondition = null; + Order anOrder = null; + + if (celt != null) { +// query = query.append(separator).append(" type='").append( +// celt.getIndex()).append("'"); +// separator = " and"; +// order = " order by value asc"; + aCondition = Restrictions.eq("type", celt); + anOrder = Order.asc("value"); + } + if (value != null) { +// query = query.append(separator).append(" value='").append(value) +// .append("'"); +// separator = " and"; + + aCondition = Restrictions.and(aCondition, Restrictions.eq("value", value)); + } + if (state != null) { +// query = query.append(separator).append(" state='").append(state) +// .append("'"); + if (celt == null) { +// order = " order by type asc"; + anOrder = Order.asc("type"); + } + aCondition = Restrictions.and(aCondition, Restrictions.eq("state", state)); + } +// query.append(order); +// return (List) Database.getSession().createQuery( +// query.toString()).list(); + return getSimulationContextDAO().getFilteredList(aCondition, anOrder); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#getSimulationContextList() + */ + @Transactional(readOnly = true) + public List getSimulationContextList() { + SimulationContext.Properties cprop = new SimulationContext.Properties(); + SimulationContextType product = selectType("product"); + List resList = selectSimulationContextsWhere(cprop + .setType(product)); + return resList; + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#createType(java.lang.String, org.splat.service.technical.ProjectSettingsService.Step) + */ + @Transactional + public SimulationContextType createType(String name, + ProjectSettingsService.Step step) throws InvalidPropertyException { + // TODO: Check for duplicate definition + SimulationContextType type = new SimulationContextType(name, step); + getSimulationContextTypeDAO().create(type); + + return type; + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#selectAllTypes() + */ + @SuppressWarnings("unchecked") + public List selectAllTypes() { + // ----------------------------------------------------------- + StringBuffer query = new StringBuffer("from SimulationContextType"); // Useless to order by names as the result mixes localized + // and non localized types + query = query.append(" order by step asc"); + return Database.getSession().createQuery(query.toString()).list(); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#selectTypesOf(org.splat.service.technical.ProjectSettingsService.Step[]) + */ + @SuppressWarnings("unchecked") + public List selectTypesOf( + ProjectSettingsService.Step... step) { + // -------------------------------------------------------------------------------------- + StringBuffer query = new StringBuffer( + "from SimulationContextType where step='").append( + step[0].getNumber()).append("'"); + for (int i = 1; i < step.length; i++) { // Useless to order as the result mixes localized and non localized types + query = query.append(" or step='").append(step[i].getNumber()) + .append("'"); + } + query = query.append(" order by step asc"); + return Database.getSession().createQuery(query.toString()).list(); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#selectTypesWhere(org.splat.dal.bo.som.SimulationContextType.Properties) + */ + @SuppressWarnings("unchecked") + public List selectTypesWhere( + SimulationContextType.Properties sprop) { + StringBuffer query = new StringBuffer("from SimulationContextType"); + String separator = " where"; + ProjectSettingsService.Step step = sprop.getStep(); + ProgressState state = sprop.getProgressState(); + String order = " order by step asc"; + + if (step != null) { + query = query.append(separator).append(" step='").append( + step.getNumber()).append("'"); + separator = " and"; + order = " order by state desc"; // APPROVED (upper case A) is grater than inCHECK (lower case i) + } + if (state != null) { + query = query.append(separator).append(" state='").append( + state.toString()).append("'"); + // separator = " and"; + if (step != null) { + if (state != ProgressState.APPROVED) + order = " order by name asc"; + else + order = ""; // Approved types are localized + } + } + query = query.append(order); + return Database.getSession().createQuery(query.toString()).list(); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#selectType(java.lang.String) + */ + @Transactional(readOnly=true) + public SimulationContextType selectType(String name) { + return getSimulationContextTypeDAO().findByCriteria( + Restrictions.eq("name", name)); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#selectType(long) + */ + public SimulationContextType selectType(long index) { + return getSimulationContextTypeDAO().get(index); + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#hold(org.splat.dal.bo.som.SimulationContext) + */ + public void hold(SimulationContext simCtx) { + simCtx.setCounter(simCtx.getCounter() + 1); + if (simCtx.isSaved()) { + getSimulationContextDAO().update(simCtx); + } + } + + /** + * {@inheritDoc} + * + * @see org.splat.service.SimulationContextService#release(org.splat.dal.bo.som.SimulationContext) + */ + public void release(SimulationContext simCtx) { + simCtx.setCounter(simCtx.getCounter() - 1); + if (simCtx.isSaved()) { + getSimulationContextDAO().update(simCtx); + } + } + + /** + * Get the simulationContextDAO. + * + * @return the simulationContextDAO + */ + public SimulationContextDAO getSimulationContextDAO() { + return _simulationContextDAO; + } + + /** + * Set the simulationContextDAO. + * + * @param simulationContextDAO + * the simulationContextDAO to set + */ + public void setSimulationContextDAO( + SimulationContextDAO simulationContextDAO) { + _simulationContextDAO = simulationContextDAO; + } + + /** + * Get the simulationContextTypeDAO. + * + * @return the simulationContextTypeDAO + */ + public SimulationContextTypeDAO getSimulationContextTypeDAO() { + return _simulationContextTypeDAO; + } + + /** + * Set the simulationContextTypeDAO. + * + * @param simulationContextTypeDAO + * the simulationContextTypeDAO to set + */ + public void setSimulationContextTypeDAO( + SimulationContextTypeDAO simulationContextTypeDAO) { + _simulationContextTypeDAO = simulationContextTypeDAO; + } +} diff --git a/Workspace/Siman-Common/src/org/splat/service/StepService.java b/Workspace/Siman-Common/src/org/splat/service/StepService.java index 871a0b9..69c96fa 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepService.java @@ -22,8 +22,8 @@ import org.splat.kernel.NotApplicableException; import org.splat.som.Step; /** - * @author RKV - * + * Step service interface. + * @author Roman Kozlov (RKV) */ public interface StepService { diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 353477e..d437387 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -37,13 +37,23 @@ import org.splat.som.Revision; import org.splat.som.Step; /** - * @author RKV - * + * Step service implementation. + * @author Roman Kozlov (RKV) */ public class StepServiceImpl implements StepService { + /** + * Injected index service. + */ private IndexService _indexService; + /** + * Injected document service. + */ private DocumentService _documentService; + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; public SimulationContext addSimulationContext(Step aStep, SimulationContext.Properties dprop) throws MissedPropertyException, @@ -58,7 +68,7 @@ public class StepServiceImpl implements StepService { public SimulationContext addSimulationContext(Step aStep, SimulationContext context) { // ------------------------------------------------------------------------- - context.hold(); // Increments the reference count of simulation context + getSimulationContextService().hold(context); // Increments the reference count of simulation context if (aStep.getOwner().isSaved()) try { Session session = Database.getSession(); @@ -117,7 +127,7 @@ public class StepServiceImpl implements StepService { aStep.getContex().remove(torem); session.update(aStep.getOwner()); if (torem.isShared()) { - torem.release(); + getSimulationContextService().release(torem); session.update(torem); } else { session.delete(torem); @@ -131,7 +141,7 @@ public class StepServiceImpl implements StepService { getDocumentService().generateDocumentId(newdoc, dprop); // Creation of the save directory - File wdir = newdoc.getSaveDirectory(); + File wdir = getDocumentService().getSaveDirectory(newdoc); if (!wdir.exists()) if (!wdir.mkdirs()) throw new IOException("Cannot create the repository vault directory"); // Identification and save @@ -146,7 +156,7 @@ public class StepServiceImpl implements StepService { String refid = dprop.getReference(); if (refid == null) return null; - Document slot = Database.selectDocument(refid, new Revision().toString()); + Document slot = getDocumentService().selectDocument(refid, new Revision().toString()); if ( slot == null ) return null; if (!slot.isUndefined()) return null; // Should not happen @@ -222,4 +232,21 @@ public class StepServiceImpl implements StepService { public void setDocumentService(DocumentService documentService) { _documentService = documentService; } + + /** + * Get the simulationContextService. + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * @param simulationContextService the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } } diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyService.java b/Workspace/Siman-Common/src/org/splat/service/StudyService.java index 1c00bf7..bd249d7 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyService.java @@ -9,7 +9,6 @@ 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; @@ -29,13 +28,6 @@ import org.splat.kernel.MultiplyDefinedException; */ public interface StudyService { - /** - * Get the simulation context list for displaying drop-down list values populating - * on the "Create new study" screen. - * @return List of the simulation contexts. - */ - List getSimulationContextList(); - public int generateLocalIndex(Study aStudy); public Study selectStudy(long index); diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java index ef71552..99e22cd 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java @@ -10,14 +10,14 @@ package org.splat.service; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import org.apache.log4j.Logger; +import org.hibernate.Query; import org.hibernate.Session; -import org.hibernate.Transaction; import org.splat.dal.bo.kernel.Relation; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.ActorRelation; @@ -32,13 +32,13 @@ import org.splat.dal.bo.som.ProgressState; 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.SimulationContextType; 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.Visibility; import org.splat.dal.bo.som.Study.Properties; import org.splat.dal.dao.som.Database; +import org.splat.dal.dao.som.StudyDAO; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MissedPropertyException; import org.splat.kernel.MultiplyDefinedException; @@ -47,56 +47,59 @@ import org.splat.log.AppLogger; import org.splat.service.technical.IndexService; import org.splat.service.technical.ProjectSettingsService; import org.splat.som.Revision; +import org.springframework.transaction.annotation.Transactional; /** * This class defines all methods for creation, modification the study. + * * @author Maria KRUCHININA - * + * */ public class StudyServiceImpl implements StudyService { /** * logger for the service. */ - public final static AppLogger logger = AppLogger.getLogger(StudyServiceImpl.class); + public final static AppLogger logger = AppLogger + .getLogger(StudyServiceImpl.class); + /** + * Injected index service. + */ private IndexService _indexService; + /** + * Injected step service. + */ private StepService _stepService; + /** + * Injected scenario service. + */ private ScenarioService _scenarioService; + /** + * Injected project service. + */ private ProjectSettingsService _projectSettingsService; + /** + * Injected project element service. + */ private ProjectElementService _projectElementService; - + /** - * Get the simulation context list for displaying drop-down list values populating - * on the "Create new study" screen. + * Injected study DAO. + */ + private StudyDAO _studyDAO; + + /** * {@inheritDoc} - * @see org.splat.service.StudyService#getSimulationContextList() + * @see org.splat.service.StudyService#selectStudy(long) */ - public List getSimulationContextList() { - //TODO: remove the commit transaction ... - Session connex = Database.getSession(); - Transaction transax = connex.beginTransaction(); - - SimulationContext.Properties cprop = new SimulationContext.Properties(); - SimulationContextType product = SimulationContext.selectType("product"); - List resList = Database.selectSimulationContextsWhere(cprop.setType(product)); - - transax.commit(); - - return resList; - } - + @Transactional public Study selectStudy(long index) { - // ------------------------------------------- - StringBuffer query = new StringBuffer("from Study where rid='").append( - index).append("'"); - Study result = (Study) Database.getSession().createQuery( - query.toString()).uniqueResult(); - + Study result = getStudyDAO().get(index); result.loadWorkflow(); return result; } @@ -112,6 +115,7 @@ public class StudyServiceImpl implements StudyService { return result; } + @Transactional public Study createStudy(Study.Properties sprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, RuntimeException { @@ -119,7 +123,7 @@ public class StudyServiceImpl implements StudyService { Study study = new Study(sprop); buildReference(study); - Database.getSession().save(study); // TODO: use StudyDAO and throw out Database. + getStudyDAO().create(study); try { IndexService lucin = getIndex(); lucin.add(study); @@ -211,7 +215,7 @@ public class StudyServiceImpl implements StudyService { public boolean buildReference(Study aStudy) { String pattern = aStudy.getReference(); // The study being supposed just created, its reference is the reference pattern - IDBuilder tool = Database.selectIDBuilder(aStudy.getDate()); + IDBuilder tool = selectIDBuilder(aStudy.getDate()); if (tool == null) { tool = new IDBuilder(aStudy.getDate()); Database.getSession().save(tool); @@ -220,6 +224,19 @@ public class StudyServiceImpl implements StudyService { return true; } + public IDBuilder selectIDBuilder(Date date) { + // ------------------------------------------------------ + SimpleDateFormat year = new SimpleDateFormat("yyyy"); + String cycle = year.format(date); + StringBuffer buffer = new StringBuffer("from IDBuilder where cycle='") + .append(cycle).append("'"); + String qstring = buffer.toString(); + Query query = Database.getSession().createQuery(qstring); + IDBuilder result = (IDBuilder) query.uniqueResult(); + + return result; + } + public boolean publishes(Study aStudy, Document doc) { // --------------------------------------- if (!aStudy.publishes(doc)) { @@ -367,9 +384,9 @@ public class StudyServiceImpl implements StudyService { 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 + 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; } @@ -462,17 +479,6 @@ public class StudyServiceImpl implements StudyService { } } - /** - * @return - */ - public IndexService getIndexService() { - return _indexService; - } - - public void setIndexService(IndexService indexService) { - _indexService = indexService; - } - /** * Get project settings. * @@ -514,6 +520,7 @@ public class StudyServiceImpl implements StudyService { /** * Get the stepService. + * * @return the stepService */ public StepService getStepService() { @@ -522,9 +529,43 @@ public class StudyServiceImpl implements StudyService { /** * Set the stepService. - * @param stepService the stepService to set + * + * @param stepService + * the stepService to set */ public void setStepService(StepService stepService) { _stepService = stepService; } + + /** + * 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; + } + + /** + * 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; + } } diff --git a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java index 35b0665..3d0a6e0 100644 --- a/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java @@ -1,4 +1,5 @@ package org.splat.service.technical; + /** * * @author Daniel Brunier-Coulin @@ -37,434 +38,520 @@ 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.SimulationContextService; public class ProjectSettingsServiceImpl implements ProjectSettingsService { -// Non persistent configuration information - private Properties reprop; // Repository settings - private String pattern; // Pattern of study references - private FileNaming naming; // Scheme of file names stored into the repository - private String versioning; // Pattern of the presentation of version numbers - private Vector steps; // Ordered list of (transient) study steps - private Vector concycles; // Configuration document validation cycles - -// Temporary attributes initialized from the configuration file for populating the database with object types - private LinkedHashMap mapuse; // Document type names and uses mapping - private Vector context; // Simulation Context type names - private Vector kname; // Knowledge Element type names - private Vector flows; // Document flows - private Vector sclass; // Study classifications - -// Other resources - private static ProjectSettingsServiceImpl my = null; // Singleton instance + // Non persistent configuration information + private Properties reprop; // Repository settings + private String pattern; // Pattern of study references + private FileNaming naming; // Scheme of file names stored into the repository + private String versioning; // Pattern of the presentation of version numbers + private Vector steps; // Ordered list of (transient) study steps + private Vector concycles; // Configuration document validation cycles + + // Temporary attributes initialized from the configuration file for populating the database with object types + private LinkedHashMap mapuse; // Document type names and uses mapping + private Vector context; // Simulation Context type names + private Vector kname; // Knowledge Element type names + private Vector flows; // Document flows + private Vector sclass; // Study classifications + + // Other resources + private static ProjectSettingsServiceImpl my = null; // Singleton instance private Database _database; - protected final static Logger logger = Logger.getLogger(ProjectSettingsServiceImpl.class); + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; + protected final static Logger logger = Logger + .getLogger(ProjectSettingsServiceImpl.class); + + public enum FileNaming { + title, encoded, asis + } - public enum FileNaming { title, encoded, asis } public static class ProjectSettingsValidationCycle { -// ----------------------------------- - private String name; - private Actor[] actor; - - private ProjectSettingsValidationCycle () { - this.name = "built-in"; - this.actor = new Actor[] { null, null, null }; - } - private ProjectSettingsValidationCycle (String name, Actor[] actor) { - this.name = name; - this.actor = actor; - } - public String getName () { - return name; - } - public Actor[] getActorTypes () { - return actor; - } - } - -// ============================================================================================================================== -// Construction -// ============================================================================================================================== - protected ProjectSettingsServiceImpl () { -// ---------------------------- - reprop = new Properties(); - steps = new Vector(); - my = this; - } - -// ============================================================================================================================== -// Public functions -// ============================================================================================================================== - - public void configure (String filename) throws IOException, SQLException { -// --------------------------------------- - if (!steps.isEmpty()) return; // Project already configured - - Database base = getDatabase().getMe(); - File config = new File(filename); - if (config.exists()) { - loadCustomization(config); - } else { - logger.fatal("Could not find the database configuration file \"" + config.getAbsolutePath() + "\""); - throw new FileNotFoundException(); - } - base.configure(reprop); - if (!base.isInitialized()) { - base.initialize(); - initialize(); // Populates the database with all necessary stuff - } + // ----------------------------------- + private String name; + private Actor[] actor; + + private ProjectSettingsValidationCycle() { + this.name = "built-in"; + this.actor = new Actor[] { null, null, null }; + } + + private ProjectSettingsValidationCycle(String name, Actor[] actor) { + this.name = name; + this.actor = actor; + } + + public String getName() { + return name; + } + + public Actor[] getActorTypes() { + return actor; + } } - public List getAllSteps () { -// --------------------------------------- - return steps; - } + // ============================================================================================================================== + // Construction + // ============================================================================================================================== + protected ProjectSettingsServiceImpl() { + // ---------------------------- + reprop = new Properties(); + steps = new Vector(); + my = this; + } + + // ============================================================================================================================== + // Public functions + // ============================================================================================================================== + + public void configure(String filename) throws IOException, SQLException { + // --------------------------------------- + if (!steps.isEmpty()) + return; // Project already configured + + Database base = getDatabase().getMe(); + File config = new File(filename); + if (config.exists()) { + loadCustomization(config); + } else { + logger.fatal("Could not find the database configuration file \"" + + config.getAbsolutePath() + "\""); + throw new FileNotFoundException(); + } + base.configure(reprop); + if (!base.isInitialized()) { + base.initialize(); + initialize(); // Populates the database with all necessary stuff + } + } + + public List getAllSteps() { + // --------------------------------------- + return steps; + } + + /** + * Return the validation cycles of result documents defined in the workflow, ordered by study activities and ending by the default + * validation cycle, if defined. + * + * @return the validation cycles of the workflow + */ + public static List getAllValidationCycles() { + // ------------------------------------------------------------- + return my.concycles; + } + + public FileNaming getFileNamingScheme() { + // ----------------------------------------------- + return naming; + } + + public static ProjectSettingsValidationCycle getNewValidationCycle() { + // ------------------------------------------------------ + return new ProjectSettingsValidationCycle(); + } + + public String getReferencePattern() { + return pattern; + } + + public String getRevisionPattern() { + // ------------------------------------------ + return versioning; + } + + public static ProjectSettingsService.Step getStep(int number) { + // --------------------------------------- + for (int i = 0; i < my.steps.size(); i++) { + ProjectSettingsService.Step step = my.steps.get(i); + if (step.number == number) + return step; + } + return null; + } + + public List getStepsOf( + Class level) { + // --------------------------------------------------------------------------- + Vector result = new Vector(); + + for (int i = 0; i < steps.size(); i++) { + ProjectSettingsService.Step step = steps.get(i); + if (step.appliesTo(level)) + result.add(step); + } + return result; + } + + // ============================================================================================================================== + // Protected member function + // ============================================================================================================================== + + public void initialize() { + // ---------------------------- + createDocumentTypes(); + createSimulationContextTypes(); + createKnowledgeElementTypes(); + } + + // ============================================================================================================================== + // Private member function + // ============================================================================================================================== + + 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 children = XDOM.getNamedChildNodes(conf + .getDocumentElement()); + + // Repository tag initializing the reprop attribute + Node child = children.get("database"); + HashMap datag = XDOM.getNamedChildNodes(child); + + String disk = datag.get("repository").getAttributes().getNamedItem( + "disk").getNodeValue(); + if (!disk.endsWith("/")) + disk = disk + "/"; + logger.info("Database root set to " + disk); + reprop.setProperty("repository", disk); + + // Formats tag initializing the reference pattern and date attributes + child = children.get("formats"); + datag = XDOM.getNamedChildNodes(child); + + NamedNodeMap natr = datag.get("references").getAttributes(); + pattern = natr.getNamedItem("study").getNodeValue(); + + natr = datag.get("files").getAttributes(); + naming = FileNaming.valueOf(natr.getNamedItem("name") + .getNodeValue()); + + natr = datag.get("versions").getAttributes(); + versioning = natr.getNamedItem("pattern").getNodeValue(); + + // Activities tag initializing the steps and rex attributes + child = children.get("activities"); + NodeList nlist = child.getChildNodes(); + Vector flist = new Vector(); + Vector resultype = new Vector(); + Vector clist = new Vector(); + + int snum = 1; // Base number of steps + for (int i = 0; i < nlist.getLength(); i++) { + child = nlist.item(i); + if (child.getNodeName().equals("scenario")) { + NodeList slist = child.getChildNodes(); + for (int j = 0; j < slist.getLength(); j++) { + child = slist.item(j); + if (!child.getNodeName().equals("step")) + continue; + HashMap tags = XDOM + .getNamedChildNodes(child); + + natr = tags.get("storage").getAttributes(); + ProjectSettingsService.Step step = new ProjectSettingsService.Step( + snum, Scenario.class, natr.getNamedItem("path") + .getNodeValue()); + + // Keeping flow and classification information for eventual later use + natr = tags.get("flow").getAttributes(); + flist.add(natr); + child = natr.getNamedItem("result"); + if (child != null) + resultype.add(child.getNodeValue()); + + child = tags.get("classification"); + if (child != null) + clist.add(child.getAttributes()); + else + clist.add(null); + + if (natr.getNamedItem("contents").getNodeValue() + .equals("knowledge")) { + // TODO In a given scenario, only one step must contain knowledges + step.contents.add(KnowledgeElement.class); + } else { + step.contents.add(Document.class); + } + steps.add(step); + snum += 1; + } + } else { + if (!child.getNodeName().equals("step")) + continue; + HashMap tags = XDOM.getNamedChildNodes(child); + + natr = tags.get("storage").getAttributes(); // Mandatory information + ProjectSettingsService.Step step = new ProjectSettingsService.Step( + snum, Study.class, natr.getNamedItem("path") + .getNodeValue()); + + // Keeping flow and classification information for eventual later use + natr = tags.get("flow").getAttributes(); + flist.add(natr); + child = natr.getNamedItem("result"); + if (child != null) + resultype.add(child.getNodeValue()); + + child = tags.get("classification"); // Optional information + if (child != null) + clist.add(child.getAttributes()); + else + clist.add(null); + + if (natr.getNamedItem("contents").getNodeValue().equals( + "knowledge")) { + // TODO Error: knowledges must be attached to scenarios + } else { + step.contents.add(Document.class); + } + steps.add(step); + snum += 1; + } + } + // Validations tag + child = children.get("validations"); + concycles = new Vector(); + datag = XDOM.getNamedChildNodes(child); + + String[] step = { "review", "approval", "acceptance" }; + resultype.add("default"); + for (Iterator i = resultype.iterator(); i.hasNext();) { + Actor[] actor = { null, null, null }; + String name = i.next(); + child = datag.get(name); + if (child == null) + continue; // Document type not subject of any validation + natr = child.getAttributes(); + for (int j = 0; j < step.length; j++) { + child = natr.getNamedItem(step[j]); + if (child == null) + continue; // Validation step not required + actor[j] = Actor.valueOf(child.getNodeValue()); + } + concycles.add(new ProjectSettingsValidationCycle(name, actor)); + } + concycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle + + if (getDatabase().getMe().isInitialized()) + return; // No need to load object type definitions as they are already stored + + // Documents tag + child = children.get("documents"); + nlist = child.getChildNodes(); + + flows = flist; // Kept for later use in document type definition + sclass = clist; // Kept for later use in simulation context type definition + mapuse = new LinkedHashMap(); + for (int i = 0; i < nlist.getLength(); i++) { + child = nlist.item(i); + if (!child.getNodeName().equals("article")) + continue; + + natr = child.getAttributes(); + String type = natr.getNamedItem("type").getNodeValue(); + String uses = null; + child = natr.getNamedItem("uses"); + if (child != null) + uses = child.getNodeValue(); + mapuse.put(type, uses); // Must be added to the map even if no (null) uses + } + // Simulation Contexts tag + child = children.get("contexts"); + nlist = child.getChildNodes(); + + context = new Vector(); + for (int i = 0; i < nlist.getLength(); i++) { + child = nlist.item(i); + if (!child.getNodeName().equals("article")) + continue; + + context.add(child.getAttributes().getNamedItem("type") + .getNodeValue()); + } + // Knowledge Elements tag + child = children.get("knowledges"); + nlist = child.getChildNodes(); + + kname = new Vector(); + for (int i = 0; i < nlist.getLength(); i++) { + child = nlist.item(i); + if (!child.getNodeName().equals("article")) + continue; + + kname.add(child.getAttributes().getNamedItem("type") + .getNodeValue()); + } + } catch (Exception error) { + logger.info("Error in customization", error); + } + } + + private void createDocumentTypes() { + // ----------------------------------- + DocumentType.Properties tprop = new DocumentType.Properties(); + HashMap> mapsteps = new HashMap>(); + HashMap mapresult = new HashMap(); + HashMap maptype = new HashMap(); + + Vector slist = null; // List of Steps to which each document type is valid + int snum = 0; // Step number + String type = null; + String uses = null; + for (Iterator i = flows.iterator(); i.hasNext(); snum++) { + NamedNodeMap flow = i.next(); + ProjectSettingsService.Step step = steps.get(snum); + String[] contents = flow.getNamedItem("contents").getNodeValue() + .split(","); + for (int j = 0; j < contents.length; j++) { + type = contents[j]; + if (!mapuse.containsKey(type)) { + logger.warn("Undefined \"" + type + "\" document type."); + continue; + } + slist = mapsteps.get(type); + if (slist == null) + slist = new Vector(); + slist.add(step); + mapsteps.put(type, slist); + } + Node result = flow.getNamedItem("result"); + if (result != null) + mapresult.put(result.getNodeValue(), step); + } + try { + DocumentType tdoc = null; + Set tset = mapuse.keySet(); + ProjectSettingsService.Step step; + for (Iterator i = tset.iterator(); i.hasNext();) { + type = i.next(); + slist = mapsteps.get(type); + uses = mapuse.get(type); + step = mapresult.get(type); + + tprop.clear(); + tprop.setName(type).setStep( + slist.toArray(new ProjectSettingsService.Step[slist + .size()])); + if (uses != null) { + tdoc = maptype.get(uses); + if (tdoc == null) + logger + .warn("Undefined \"" + uses + + "\" document type."); + else + tprop.setUses(tdoc); + } + if (step != null) + tprop.setResult(step); + + tprop.disableCheck(); + tdoc = Document.createType(tprop); // Creation of Document Types + tdoc.approve(); + maptype.put(type, tdoc); + } + } catch (Exception error) { + logger.warn("Error creating document types, reason:", error); // Should not happen + } + } + + private void createKnowledgeElementTypes() { + // ------------------------------------------- + try { + KnowledgeElementType ktype = KnowledgeElement.createType("usecase"); // Internal reserved knowledge element type + ktype.reserve(); + for (Iterator i = kname.iterator(); i.hasNext();) { + String type = i.next(); + + ktype = KnowledgeElement.createType(type); // Knowledge Elements Types defined in the configuration + ktype.approve(); + } + } catch (Exception error) { + logger.warn("Error creating knowledge types, reason:", error); // Should not happen + } + } + + private void createSimulationContextTypes() { + // -------------------------------------------- + HashMap mapstep = new HashMap(); + int snum = 0; + for (Iterator i = sclass.iterator(); i.hasNext(); snum++) { + NamedNodeMap clatr = i.next(); + if (clatr == null) + continue; + + String[] clist = clatr.getNamedItem("context").getNodeValue() + .split(","); + for (int j = 0; j < clist.length; j++) { + mapstep.put(clist[j], steps.get(snum)); + } + } + try { + SimulationContextType tctex = null; + for (Iterator i = context.iterator(); i.hasNext();) { + String type = i.next(); + if (!mapstep.containsKey(type)) { + logger + .warn("Could not find \"" + + type + + "\" classification. Simulation Context type ignored."); + continue; + } + tctex = getSimulationContextService().createType(type, + mapstep.get(type)); // Creation of Simulation Context Types + tctex.approve(); + } + } catch (Exception error) { + logger.warn("Error creating context types, reason:", error); // Should not happen + } + } -/** - * Return the validation cycles of result documents defined in the workflow, ordered by study activities - * and ending by the default validation cycle, if defined. - * - * @return the validation cycles of the workflow - */ - public static List getAllValidationCycles () { -// ------------------------------------------------------------- - return my.concycles; - } - - public FileNaming getFileNamingScheme () { -// ----------------------------------------------- - return naming; - } - - public static ProjectSettingsValidationCycle getNewValidationCycle () { -// ------------------------------------------------------ - return new ProjectSettingsValidationCycle(); - } - - public String getReferencePattern () { - return pattern; - } - - public String getRevisionPattern () { -// ------------------------------------------ - return versioning; - } - - public static ProjectSettingsService.Step getStep (int number) { -// --------------------------------------- - for (int i=0; i getStepsOf (Class level) { -// --------------------------------------------------------------------------- - Vector result = new Vector(); - - for (int i=0; i children = XDOM.getNamedChildNodes(conf.getDocumentElement()); - -// Repository tag initializing the reprop attribute - Node child = children.get("database"); - HashMap datag = XDOM.getNamedChildNodes(child); - - String disk = datag.get("repository").getAttributes().getNamedItem("disk").getNodeValue(); - if (!disk.endsWith("/")) disk = disk + "/"; - logger.info("Database root set to " + disk); - reprop.setProperty("repository", disk); - -// Formats tag initializing the reference pattern and date attributes - child = children.get("formats"); - datag = XDOM.getNamedChildNodes(child); - - NamedNodeMap natr = datag.get("references").getAttributes(); - pattern = natr.getNamedItem("study").getNodeValue(); - - natr = datag.get("files").getAttributes(); - naming = FileNaming.valueOf(natr.getNamedItem("name").getNodeValue()); - - natr = datag.get("versions").getAttributes(); - versioning = natr.getNamedItem("pattern").getNodeValue(); - -// Activities tag initializing the steps and rex attributes - child = children.get("activities"); - NodeList nlist = child.getChildNodes(); - Vector flist = new Vector(); - Vector resultype = new Vector(); - Vector clist = new Vector(); - - int snum = 1; // Base number of steps - for (int i=0; i tags = XDOM.getNamedChildNodes(child); - - natr = tags.get("storage").getAttributes(); - ProjectSettingsService.Step step = new ProjectSettingsService.Step(snum, Scenario.class, natr.getNamedItem("path").getNodeValue()); - -// Keeping flow and classification information for eventual later use - natr = tags.get("flow").getAttributes(); - flist.add(natr); - child = natr.getNamedItem("result"); - if (child != null) resultype.add(child.getNodeValue()); - - child = tags.get("classification"); - if (child != null) clist.add( child.getAttributes() ); - else clist.add( null ); - - if (natr.getNamedItem("contents").getNodeValue().equals("knowledge")) { -//TODO In a given scenario, only one step must contain knowledges - step.contents.add(KnowledgeElement.class); - } else { - step.contents.add(Document.class); - } - steps.add(step); - snum += 1; - } - } else { - if (!child.getNodeName().equals("step")) continue; - HashMap tags = XDOM.getNamedChildNodes(child); - - natr = tags.get("storage").getAttributes(); // Mandatory information - ProjectSettingsService.Step step = new ProjectSettingsService.Step(snum, Study.class, natr.getNamedItem("path").getNodeValue()); - -// Keeping flow and classification information for eventual later use - natr = tags.get("flow").getAttributes(); - flist.add(natr); - child = natr.getNamedItem("result"); - if (child != null) resultype.add(child.getNodeValue()); - - child = tags.get("classification"); // Optional information - if (child != null) clist.add( child.getAttributes() ); - else clist.add( null ); - - if (natr.getNamedItem("contents").getNodeValue().equals("knowledge")) { -//TODO Error: knowledges must be attached to scenarios - } else { - step.contents.add(Document.class); - } - steps.add(step); - snum += 1; - } - } -// Validations tag - child = children.get("validations"); - concycles = new Vector(); - datag = XDOM.getNamedChildNodes(child); - - String[] step = { "review", "approval", "acceptance" }; - resultype.add("default"); - for (Iterator i=resultype.iterator(); i.hasNext(); ) { - Actor[] actor = { null, null, null }; - String name = i.next(); - child = datag.get(name); - if (child == null) continue; // Document type not subject of any validation - natr = child.getAttributes(); - for (int j=0; j(); - for (int i=0; i(); - for (int i=0; i(); - for (int i=0; i> mapsteps = new HashMap>(); - HashMap mapresult = new HashMap(); - HashMap maptype = new HashMap(); - - Vector slist = null; // List of Steps to which each document type is valid - int snum = 0; // Step number - String type = null; - String uses = null; - for (Iterator i=flows.iterator(); i.hasNext(); snum++) { - NamedNodeMap flow = i.next(); - ProjectSettingsService.Step step = steps.get(snum); - String[] contents = flow.getNamedItem("contents").getNodeValue().split(","); - for (int j=0; j(); - slist.add(step); - mapsteps.put(type, slist); - } - Node result = flow.getNamedItem("result"); - if (result != null) mapresult.put(result.getNodeValue(), step); - } - try { - DocumentType tdoc = null; - Set tset = mapuse.keySet(); - ProjectSettingsService.Step step; - for (Iterator i=tset.iterator(); i.hasNext(); ) { - type = i.next(); - slist = mapsteps.get(type); - uses = mapuse.get(type); - step = mapresult.get(type); - - tprop.clear(); - tprop.setName(type).setStep(slist.toArray(new ProjectSettingsService.Step[slist.size()])); - if (uses != null) { - tdoc = maptype.get(uses); - if (tdoc == null) logger.warn("Undefined \"" + uses + "\" document type."); - else tprop.setUses(tdoc); - } - if (step != null) tprop.setResult(step); - - tprop.disableCheck(); - tdoc = Document.createType(tprop); // Creation of Document Types - tdoc.approve(); - maptype.put(type, tdoc); - } - } catch (Exception error) { - logger.warn("Error creating document types, reason:", error); // Should not happen - } - } - - private void createKnowledgeElementTypes () { -// ------------------------------------------- - try { - KnowledgeElementType ktype = KnowledgeElement.createType("usecase"); // Internal reserved knowledge element type - ktype.reserve(); - for (Iterator i=kname.iterator(); i.hasNext(); ) { - String type = i.next(); - - ktype = KnowledgeElement.createType(type); // Knowledge Elements Types defined in the configuration - ktype.approve(); - } - } catch (Exception error) { - logger.warn("Error creating knowledge types, reason:", error); // Should not happen - } - } - - private void createSimulationContextTypes () { -// -------------------------------------------- - HashMap mapstep = new HashMap(); - int snum = 0; - for (Iterator i=sclass.iterator(); i.hasNext(); snum++) { - NamedNodeMap clatr = i.next(); - if (clatr == null) continue; - - String[] clist = clatr.getNamedItem("context").getNodeValue().split(","); - for (int j=0; j i=context.iterator(); i.hasNext(); ) { - String type = i.next(); - if (!mapstep.containsKey(type)) { - logger.warn("Could not find \"" + type + "\" classification. Simulation Context type ignored."); - continue; - } - tctex = SimulationContext.createType(type, mapstep.get(type)); // Creation of Simulation Context Types - tctex.approve(); - } - } catch (Exception error) { - logger.warn("Error creating context types, reason:", error); // Should not happen - } - } /** * Get the database. + * * @return the database */ public Database getDatabase() { return _database; } + /** * Set the database. - * @param database the database to set + * + * @param database + * the database to set */ public void setDatabase(Database database) { _database = database; } + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 337c839..0e2805f 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -25,6 +25,7 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> class="org.splat.service.DocumentServiceImpl"> + + + + + + + ref="projectElementService" /> - + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/spring/daoContext.xml b/Workspace/Siman-Common/src/spring/daoContext.xml index 0a54b95..fb558d8 100644 --- a/Workspace/Siman-Common/src/spring/daoContext.xml +++ b/Workspace/Siman-Common/src/spring/daoContext.xml @@ -4,6 +4,7 @@ xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> + diff --git a/Workspace/Siman-Common/src/spring/technicalServiceContext.xml b/Workspace/Siman-Common/src/spring/technicalServiceContext.xml index 2f8d9b5..2e17609 100644 --- a/Workspace/Siman-Common/src/spring/technicalServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/technicalServiceContext.xml @@ -16,7 +16,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> - + + defuses = null; private String summary = null; // Summary of changes in the new version + /** + * Injected scenario service. + */ private ScenarioService _scenarioService; + /** + * Injected publication service. + */ private PublicationService _publicationService; + /** + * Injected step service. + */ private StepService _stepService; - - private static final long serialVersionUID = -3364960833373200115L; + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; // ============================================================================================================================== // Action methods @@ -58,7 +83,8 @@ public class SaveDocumentAction extends Action { DocumentType type = Document.selectType(doctype); // File updir = Database.getDownloadDirectory(user); // File upfile = new File(updir.getPath() + "/" + filename); - String upath = Database.getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file between users + String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file + // between users File upfile = new File(upath + filename); String[] table = filename.split("\\x2E"); String format = table[table.length - 1]; @@ -68,8 +94,10 @@ public class SaveDocumentAction extends Action { connex.flush(); Document.Properties dprop = new Document.Properties(); - Publication credoc = getStepService().createDocument(step, dprop.setName(docname) - .setType(type).setFormat(format).setAuthor(user)); + Publication credoc = getStepService().createDocument( + step, + dprop.setName(docname).setType(type).setFormat(format) + .setAuthor(user)); // Writing the uploaded file into the created document File target = credoc.getSourceFile().asFile(); if (target.exists()) @@ -102,26 +130,28 @@ public class SaveDocumentAction extends Action { // 2. Addition of simulation contexts if (type.equals("model")) { // Set the characteristics of the mesh SimulationContext.Properties cprop = new SimulationContext.Properties(); - SimulationContextType ctype = SimulationContext + SimulationContextType ctype = getSimulationContextService() .selectType("model"); - SimulationContext context = Database.selectSimulationContext( - ctype, "Éléments finis"); + SimulationContext context = getSimulationContextService() + .selectSimulationContext(ctype, "Éléments finis"); if (context == null) { getStepService().addSimulationContext(step, cprop.setType(ctype).setValue("Éléments finis")); } else { getStepService().addSimulationContext(step, context); } - ctype = SimulationContext.selectType("element"); - context = Database.selectSimulationContext(ctype, "Surfacique"); + ctype = getSimulationContextService().selectType("element"); + context = getSimulationContextService() + .selectSimulationContext(ctype, "Surfacique"); if (context == null) { getStepService().addSimulationContext(step, cprop.setType(ctype).setValue("Surfacique")); } else { getStepService().addSimulationContext(step, context); } - ctype = SimulationContext.selectType("shape"); - context = Database.selectSimulationContext(ctype, "Triangles"); + ctype = getSimulationContextService().selectType("shape"); + context = getSimulationContextService() + .selectSimulationContext(ctype, "Triangles"); if (context == null) { getStepService().addSimulationContext(step, cprop.setType(ctype).setValue("Triangles")); @@ -222,7 +252,8 @@ public class SaveDocumentAction extends Action { Step step = mystudy.getSelectedStep(); // File updir = Database.getDownloadDirectory(user); // File upfile = new File(updir.getPath() + "/" + filename); - String upath = Database.getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file between users + String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file + // between users File upfile = new File(upath + filename); String[] table = filename.split("\\x2E"); String format = table[table.length - 1]; @@ -234,7 +265,8 @@ public class SaveDocumentAction extends Action { if (summary.length() > 0) dprop.setDescription(summary); - Publication next = getStepService().versionDocument(step, current, dprop); + Publication next = getStepService().versionDocument(step, current, + dprop); // Writing the uploaded file into the created document File target = next.getSourceFile().asFile(); @@ -338,4 +370,43 @@ public class SaveDocumentAction extends Action { defuses.addAll(usedoc); } } + + /** + * Get the repositoryService. + * + * @return the repositoryService + */ + public RepositoryService getRepositoryService() { + return _repositoryService; + } + + /** + * Set the repositoryService. + * + * @param repositoryService + * the repositoryService to set + */ + public void setRepositoryService(RepositoryService repositoryService) { + _repositoryService = repositoryService; + } + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/Action.java b/Workspace/Siman/src/org/splat/simer/Action.java index 1606a89..cf3137d 100644 --- a/Workspace/Siman/src/org/splat/simer/Action.java +++ b/Workspace/Siman/src/org/splat/simer/Action.java @@ -26,7 +26,13 @@ public class Action extends ActionSupport implements SessionAware { private OpenStudy _openStudy; private OpenKnowledge _openKnowledge; + /** + * Serial version ID. + */ private static final long serialVersionUID = -895295026709526501L; + /** + * Action logger. + */ protected static final Logger logger = Logger.getLogger(Action.class); public class DocumentTypeComparator implements Comparator { diff --git a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java index 27ec0ac..ebf3e06 100644 --- a/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java +++ b/Workspace/Siman/src/org/splat/simer/ApplicationSettings.java @@ -55,8 +55,14 @@ public class ApplicationSettings { 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); + /** + * Injected project settings service. + */ private ProjectSettingsService _projectSettingsService; /** diff --git a/Workspace/Siman/src/org/splat/simer/ConnectionAction.java b/Workspace/Siman/src/org/splat/simer/ConnectionAction.java index 1e90a55..dae99b3 100644 --- a/Workspace/Siman/src/org/splat/simer/ConnectionAction.java +++ b/Workspace/Siman/src/org/splat/simer/ConnectionAction.java @@ -23,6 +23,9 @@ public class ConnectionAction extends Action { private String password = null; private String backmenu = null; + /** + * Serial version ID. + */ private static final long serialVersionUID = 6095471616361606231L; private class Handler implements CallbackHandler { diff --git a/Workspace/Siman/src/org/splat/simer/Converter.java b/Workspace/Siman/src/org/splat/simer/Converter.java index 5721022..c687485 100644 --- a/Workspace/Siman/src/org/splat/simer/Converter.java +++ b/Workspace/Siman/src/org/splat/simer/Converter.java @@ -20,14 +20,17 @@ import org.apache.log4j.Logger; public class Converter implements MessageListener { + /** + * Converter logger. + */ + final static Logger logger = Logger.getLogger(Converter.class); + private String type; // Type of document to be converted (e.g. geometry, model) private String from; // Source format (e.g. py, sldprt) private String to; // Target format (e.g. brep) private String exec; // Command line launching the actual converter private String fname; // Absolute path of the source file to be converted - final static Logger logger = Logger.getLogger(Converter.class); - // ============================================================================================================================== // Constructor // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/DisplayBaseAction.java b/Workspace/Siman/src/org/splat/simer/DisplayBaseAction.java index 4985f7b..58b66ab 100644 --- a/Workspace/Siman/src/org/splat/simer/DisplayBaseAction.java +++ b/Workspace/Siman/src/org/splat/simer/DisplayBaseAction.java @@ -7,6 +7,9 @@ public abstract class DisplayBaseAction extends Action { protected String selection = null; // User activity selection protected String action = null; + /** + * Serial version ID. + */ private static final long serialVersionUID = 3003902258668626946L; protected enum Execute { popup, develop, reduce, reduceall } diff --git a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java index 80d1dc7..3738cf4 100644 --- a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java @@ -12,171 +12,186 @@ 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.technical.RepositoryService; import org.splat.som.Step; - +/** + * Document modification action. + */ public class EditDocumentAction extends DisplayStudyStepAction { - private String index = null; - private String title = null; - private String filename = null; + /** + * Serial version ID. + */ + private static final long serialVersionUID = 4573036736137033679L; + + private String index = null; + private String title = null; + private String filename = null; + /** + * Injected publication service. + */ private PublicationService _publicationService; + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; - private static final long serialVersionUID = 4573036736137033679L; + /** + * Operations enumeration. + */ + private enum Execute { + renameDocument, accept, promote, demote, review, invalidate, approve, disapprove + }; + + // ============================================================================================================================== + // Action methods + // ============================================================================================================================== + + /** + * Open a study. + * + * @return SUCCESS + */ + public String doInitialize() { + mystudy = getOpenStudy(); + return SUCCESS; + } + + public String doSetDocument() { + // ------------------------------ + Session connex = Database.getSession(); + Transaction transax = connex.beginTransaction(); + try { + mystudy = getOpenStudy(); + + Execute todo = Execute.valueOf(action); + Step step = mystudy.getSelectedStep(); + Publication doc = step.getDocument(Integer.valueOf(index)); + + if (todo == Execute.renameDocument) { + doc.rename(title); + // Useless to update the document presentation + } else if (todo == Execute.accept) { + doc.actualize(); + mystudy.update(doc); + } else if (todo == Execute.promote) { + getPublicationService().promote(doc, + Calendar.getInstance().getTime()); + mystudy.update(doc); + } else if (todo == Execute.demote) { + getPublicationService().demote(doc); + mystudy.update(doc); + } else if (todo == Execute.review) { + getPublicationService().review(doc, + Calendar.getInstance().getTime()); + mystudy.update(doc); + } else if (todo == Execute.invalidate) { + getPublicationService().invalidate(doc); + mystudy.update(doc); + } else if (todo == Execute.approve) { + getPublicationService().approve(doc, + Calendar.getInstance().getTime()); + mystudy.update(doc); + mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state + } + 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 (InvalidPropertyException error) { + transax.commit(); + return INPUT; + } + } + + public String doAttach() { + // ------------------------- + Session connex = Database.getSession(); + Transaction transax = connex.beginTransaction(); + try { + // Getting user inputs + mystudy = getOpenStudy(); + User user = getConnectedUser(); + Step step = mystudy.getSelectedStep(); + File updir = getRepositoryService().getDownloadDirectory(user); + File upfile = new File(updir.getPath() + "/" + filename); + String[] parse = filename.split("\\x2E"); + + Publication edited = step.getDocument(Integer.valueOf(index)); + ConvertsRelation export = edited.attach(parse[parse.length - 1]); + + if (logger.isInfoEnabled()) + logger.info("Moving \"" + upfile.getName() + "\" to \"" + + updir.getPath() + "\"."); + upfile.renameTo(export.getTo().asFile()); + + mystudy.update(edited); + transax.commit(); + return SUCCESS; + } catch (Exception error) { + logger.error("Reason:", error); + return ERROR; + } + } + + public String doDeleteDocument() { + // --------------------------------- + Session connex = Database.getSession(); + Transaction transax = connex.beginTransaction(); + try { + mystudy = getOpenStudy(); + + Step step = mystudy.getSelectedStep(); + Publication doctag = step.getDocument(Integer.valueOf(index)); + + step.removeDocument(doctag); // Updates the data structure + transax.commit(); + + mystudy.remove(doctag); // Updates the presentation + 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 void setDocumentTitle(String title) { + // ------------------------------------------- + this.title = title; + } + + public void setFileName(String filename) { + // ----------------------------------------- + this.filename = filename; + } + + public void setIndex(String index) { + // ----------------------------------- + this.index = index; + } - private enum Execute { renameDocument, accept, promote, demote, review, invalidate, approve, disapprove }; - -// ============================================================================================================================== -// Action methods -// ============================================================================================================================== - - public String doInitialize () { -// ----------------------------- -// Session connex = Database.getSession(); -// Transaction transax = connex.beginTransaction(); - - mystudy = getOpenStudy(); - -// transax.commit(); - return SUCCESS; - } - - public String doSetDocument () { -// ------------------------------ - Session connex = Database.getSession(); - Transaction transax = connex.beginTransaction(); - try { - mystudy = getOpenStudy(); - - Execute todo = Execute.valueOf(action); - Step step = mystudy.getSelectedStep(); - Publication doc = step.getDocument(Integer.valueOf(index)); - - if (todo == Execute.renameDocument) { - doc.rename(title); -// Useless to update the document presentation - } else - if (todo == Execute.accept) { - doc.actualize(); - mystudy.update(doc); - } else - if (todo == Execute.promote) { - getPublicationService().promote(doc, Calendar.getInstance().getTime()); - mystudy.update(doc); - } else - if (todo == Execute.demote) { - getPublicationService().demote(doc); - mystudy.update(doc); - } else - if (todo == Execute.review) { - getPublicationService().review(doc, Calendar.getInstance().getTime()); - mystudy.update(doc); - } else - if (todo == Execute.invalidate) { - getPublicationService().invalidate(doc); - mystudy.update(doc); - } else - if (todo == Execute.approve) { - getPublicationService().approve(doc, Calendar.getInstance().getTime()); - mystudy.update(doc); - mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state - } - 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 (InvalidPropertyException error) { - transax.commit(); - return INPUT; - } - } - - public String doAttach () { -// ------------------------- - Session connex = Database.getSession(); - Transaction transax = connex.beginTransaction(); - try { -// Getting user inputs - mystudy = getOpenStudy(); - User user = getConnectedUser(); - Step step = mystudy.getSelectedStep(); - File updir = Database.getDownloadDirectory(user); - File upfile = new File(updir.getPath() + "/" + filename); - String[] parse = filename.split("\\x2E"); - - Publication edited = step.getDocument(Integer.valueOf(index)); - ConvertsRelation export = edited.attach(parse[parse.length-1]); - - if (logger.isInfoEnabled()) logger.info("Moving \"" + upfile.getName() + "\" to \"" + updir.getPath() + "\"."); - upfile.renameTo(export.getTo().asFile()); - - mystudy.update(edited); - transax.commit(); - return SUCCESS; - } - catch (Exception error) { - logger.error("Reason:", error); - return ERROR; - } - } - - public String doDeleteDocument () { -// --------------------------------- - Session connex = Database.getSession(); - Transaction transax = connex.beginTransaction(); - try { - mystudy = getOpenStudy(); - - Step step = mystudy.getSelectedStep(); - Publication doctag = step.getDocument(Integer.valueOf(index)); - - step.removeDocument(doctag); // Updates the data structure - transax.commit(); - - mystudy.remove(doctag); // Updates the presentation - 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 void setDocumentTitle (String title) { -// ------------------------------------------- - this.title = title; - } - public void setFileName (String filename) { -// ----------------------------------------- - this.filename = filename; - } - public void setIndex (String index) { -// ----------------------------------- - this.index = index; - } /** * Get the publicationService. * @@ -195,4 +210,23 @@ public class EditDocumentAction extends DisplayStudyStepAction { public void setPublicationService(PublicationService publicationService) { _publicationService = publicationService; } + + /** + * Get the repositoryService. + * + * @return the repositoryService + */ + public RepositoryService getRepositoryService() { + return _repositoryService; + } + + /** + * Set the repositoryService. + * + * @param repositoryService + * the repositoryService to set + */ + public void setRepositoryService(RepositoryService repositoryService) { + _repositoryService = repositoryService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/EditKnowledgeElementAction.java b/Workspace/Siman/src/org/splat/simer/EditKnowledgeElementAction.java index 4b13620..38f2f17 100644 --- a/Workspace/Siman/src/org/splat/simer/EditKnowledgeElementAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditKnowledgeElementAction.java @@ -21,6 +21,9 @@ public class EditKnowledgeElementAction extends DisplayStudyStepAction { private ScenarioService _scenarioService; private KnowledgeElementService _knowledgeElementService; + /** + * Serial version ID. + */ private static final long serialVersionUID = 4636919137087687068L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java b/Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java index a3f3d25..cb27c9a 100644 --- a/Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java @@ -21,6 +21,9 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction { private ScenarioService _scenarioService; private ProjectElementService _projectElementService; + /** + * Serial version ID. + */ private static final long serialVersionUID = 4964740932426016171L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/EditSimulationContextAction.java b/Workspace/Siman/src/org/splat/simer/EditSimulationContextAction.java index 3dba784..d133314 100644 --- a/Workspace/Siman/src/org/splat/simer/EditSimulationContextAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditSimulationContextAction.java @@ -10,6 +10,7 @@ import org.splat.dal.dao.som.Database; import org.splat.dal.bo.som.ProjectElement; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.SimulationContextType; +import org.splat.service.SimulationContextService; import org.splat.service.StepService; import org.splat.service.StudyService; import org.splat.som.Step; @@ -23,8 +24,18 @@ public class EditSimulationContextAction extends DisplayStudyStepAction { private String newtype = null; // Context type, if newed private SimulationContextType type = null; // Corresponding context type object private String value = null; // Context value + /** + * Injected study service. + */ private StudyService _studyService; + /** + * Injected step service. + */ private StepService _stepService; + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; /** * Get the stepService. @@ -77,11 +88,11 @@ public class EditSimulationContextAction extends DisplayStudyStepAction { return "create"; SimulationContext.Properties cprop = new SimulationContext.Properties(); - type = SimulationContext.selectType(typid); + type = getSimulationContextService().selectType(typid); newtype = type.getName(); contype = getInvolvedContexts(); - contelm = Database.selectSimulationContextsWhere(cprop - .setType(type)); + contelm = getSimulationContextService() + .selectSimulationContextsWhere(cprop.setType(type)); return "set"; } finally { @@ -103,7 +114,8 @@ public class EditSimulationContextAction extends DisplayStudyStepAction { SimulationContext.Properties cprop = new SimulationContext.Properties(); SimulationContext contex = null; - type = SimulationContext.createType(newtype, step.getStep()); + type = getSimulationContextService().createType(newtype, + step.getStep()); cprop.setType(type).setValue(value); if (owner instanceof Study) contex = getStudyService().addProjectContext(((Study) owner), @@ -181,7 +193,8 @@ public class EditSimulationContextAction extends DisplayStudyStepAction { || (input.length == 2 && input[1].equals(" "))) { // Setting an existing simulation context identified by value (input = rid," ") int valid = Integer.valueOf(input[0]); - contex = Database.selectSimulationContext(valid); + contex = getSimulationContextService().selectSimulationContext( + valid); if (owner instanceof Study) getStudyService() .addProjectContext(((Study) owner), contex); @@ -191,8 +204,8 @@ public class EditSimulationContextAction extends DisplayStudyStepAction { // Setting a new simulation context value (input = 0,"new context value") int typid = Integer.valueOf(selectype); SimulationContext.Properties cprop = new SimulationContext.Properties(); - cprop.setType(SimulationContext.selectType(typid)).setValue( - input[1].trim()); + cprop.setType(getSimulationContextService().selectType(typid)) + .setValue(input[1].trim()); if (owner instanceof Study) contex = getStudyService().addProjectContext( ((Study) owner), cprop); // Re-indexes knowledges and the study @@ -273,7 +286,7 @@ public class EditSimulationContextAction extends DisplayStudyStepAction { // ---------------------------------------------------------- SimulationContextType.Properties sprop = new SimulationContextType.Properties() .setStep(mystudy.getSelectedStep().getStep()); - List contype = SimulationContext + List contype = getSimulationContextService() .selectTypesWhere(sprop); if (!contype.isEmpty()) { @@ -319,4 +332,24 @@ public class EditSimulationContextAction extends DisplayStudyStepAction { public void setStudyService(StudyService studyService) { _studyService = studyService; } + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/EditStudyAction.java b/Workspace/Siman/src/org/splat/simer/EditStudyAction.java index 79c4842..a494f1a 100644 --- a/Workspace/Siman/src/org/splat/simer/EditStudyAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditStudyAction.java @@ -10,6 +10,9 @@ import org.splat.service.StudyService; public class EditStudyAction extends DisplayStudyStepAction { + /** + * Serial version ID. + */ private static final long serialVersionUID = -4865668290514118396L; private enum Execute { publish, promote } diff --git a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java index 6508745..47957e5 100644 --- a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java @@ -19,9 +19,11 @@ import org.splat.manox.Toolbox; 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.PublicationService; import org.splat.service.StepService; import org.splat.service.technical.ProjectSettingsService; +import org.splat.service.technical.RepositoryService; import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.DocumentType; import org.splat.som.Revision; @@ -29,27 +31,52 @@ import org.splat.som.Step; public class ImportDocumentAction extends UploadBaseNextAction { + /** + * Serial version ID. + */ + private static final long serialVersionUID = 2587822564883588556L; + private List doctypes = null; private long doctype = 0; private String docref = null; // Reference extracted from the imported file, if exist private String docver = ""; // Version number extracted from the imported file, if exist private String date = ""; // Date extracted from the imported file, if exist + /** + * Injected project settings service. + */ private ProjectSettingsService _projectSettingsService; + /** + * Injected publication service. + */ private PublicationService _publicationService; + /** + * Injected step service. + */ private StepService _stepService; + /** + * Injected document service. + */ + private DocumentService _documentService; - private static final long serialVersionUID = 2587822564883588556L; + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; // ============================================================================================================================== // Action methods // ============================================================================================================================== + /** + * Initialize the operation. + * @return SUCCESS in success, otherwise - ERROR + */ public String doInitialize() { // ----------------------------- Session connex = Database.getSession(); Transaction transax = connex.beginTransaction(); User user = getConnectedUser(); - File updir = Database.getDownloadDirectory(user); + File updir = getRepositoryService().getDownloadDirectory(user); File upfile = new File(updir.getPath() + "/" + filename); String[] table = filename.split("\\x2E"); String filext = table[table.length - 1].toLowerCase(); @@ -75,7 +102,7 @@ public class ImportDocumentAction extends UploadBaseNextAction { break; } if (fileref != null) { - Document slot = Database.selectDocument(fileref, + Document slot = getDocumentService().selectDocument(fileref, new Revision().toString()); if (slot == null) { setErrorCode("reference.undefined"); @@ -139,6 +166,10 @@ public class ImportDocumentAction extends UploadBaseNextAction { return SUCCESS; } + /** + * Perform import of a document. + * @return SUCCESS if ok, "cancel" - if canceled, ERROR - if error + */ public String doImport() { // ------------------------- if (action == ToDo.cancel) @@ -155,7 +186,7 @@ public class ImportDocumentAction extends UploadBaseNextAction { User user = getConnectedUser(); Step step = mystudy.getSelectedStep(); DocumentType type = Document.selectType((int)doctype); - File updir = Database.getDownloadDirectory(user); + File updir = getRepositoryService().getDownloadDirectory(user); File upfile = new File(updir.getPath() + "/" + filename); String[] table = filename.split("\\x2E"); @@ -375,4 +406,36 @@ public class ImportDocumentAction extends UploadBaseNextAction { public void setStepService(StepService stepService) { _stepService = stepService; } + + /** + * 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 repositoryService. + * @return the repositoryService + */ + public RepositoryService getRepositoryService() { + return _repositoryService; + } + + /** + * Set the repositoryService. + * @param repositoryService the repositoryService to set + */ + public void setRepositoryService(RepositoryService repositoryService) { + _repositoryService = repositoryService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/MenuAction.java b/Workspace/Siman/src/org/splat/simer/MenuAction.java index 951a837..1c026e3 100644 --- a/Workspace/Siman/src/org/splat/simer/MenuAction.java +++ b/Workspace/Siman/src/org/splat/simer/MenuAction.java @@ -8,6 +8,9 @@ public class MenuAction extends Action { private String menuname; private String selection; + /** + * Serial version ID. + */ private static final long serialVersionUID = 5904292225286579036L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/NewScenarioAction.java b/Workspace/Siman/src/org/splat/simer/NewScenarioAction.java index bc9b0ba..85adabd 100644 --- a/Workspace/Siman/src/org/splat/simer/NewScenarioAction.java +++ b/Workspace/Siman/src/org/splat/simer/NewScenarioAction.java @@ -30,6 +30,9 @@ public class NewScenarioAction extends Action { private StudyService _studyService; private ProjectElementService _projectElementService; + /** + * Serial version ID. + */ private static final long serialVersionUID = -5586724442986956861L; protected enum ToDo { cancel, save }; diff --git a/Workspace/Siman/src/org/splat/simer/NewStudyAction.java b/Workspace/Siman/src/org/splat/simer/NewStudyAction.java index 7d81c00..05da635 100644 --- a/Workspace/Siman/src/org/splat/simer/NewStudyAction.java +++ b/Workspace/Siman/src/org/splat/simer/NewStudyAction.java @@ -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.SimulationContextService; import org.splat.service.StudyService; public class NewStudyAction extends Action { @@ -20,30 +21,35 @@ public class NewStudyAction extends Action { private String context = null; private static int number = 0; + /** + * Serial version ID. + */ private static final long serialVersionUID = 693943641800113782L; - /** - * The Study service. + * The injected Study service. */ private StudyService _studyService; + private SimulationContextService _simulationContextService; // ============================================================================================================================== // Action methods // ============================================================================================================================== - //Fill the values of the drop-down list. - public String doInitialize () { - - //get the list of the simulation contexts of the study - contelm = _studyService.getSimulationContextList(); - - //set the default name of the new study - ResourceBundle locale = ResourceBundle.getBundle("labels", ApplicationSettings.getCurrentLocale()); - title = locale.getString("label.study") + " " + String.valueOf(number + 1); - - return SUCCESS; - } + // Fill the values of the drop-down list. + public String doInitialize() { + + // get the list of the simulation contexts of the study + contelm = getSimulationContextService().getSimulationContextList(); + + // set the default name of the new study + ResourceBundle locale = ResourceBundle.getBundle("labels", + ApplicationSettings.getCurrentLocale()); + title = locale.getString("label.study") + " " + + String.valueOf(number + 1); + + return SUCCESS; + } public String doCreate() throws Exception { // ------------------------- @@ -69,10 +75,10 @@ public class NewStudyAction extends Action { sprop.disableCheck(); } catch (Exception error) { SimulationContext.Properties cprop = new SimulationContext.Properties(); - SimulationContextType product = SimulationContext + SimulationContextType product = getSimulationContextService() .selectType("product"); - contelm = Database.selectSimulationContextsWhere(cprop - .setType(product)); + contelm = getSimulationContextService() + .selectSimulationContextsWhere(cprop.setType(product)); transax.commit(); return INPUT; // Title empty, simply wait for input without error message } @@ -89,11 +95,12 @@ public class NewStudyAction extends Action { // Addition of the entered project context if (valid == 0) { // Input of new project context SimulationContext.Properties cprop = new SimulationContext.Properties(); - cprop.setType(SimulationContext.selectType("product")) + cprop.setType( + getSimulationContextService().selectType("product")) .setValue(value); getStudyService().addProjectContext(study, cprop); } else { // Selection of existing project context - SimulationContext context = Database + SimulationContext context = getSimulationContextService() .selectSimulationContext(valid); getStudyService().addProjectContext(study, context); } @@ -163,4 +170,24 @@ public class NewStudyAction extends Action { public void setStudyService(StudyService studyService) { _studyService = studyService; } + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/NotYetImplementedAction.java b/Workspace/Siman/src/org/splat/simer/NotYetImplementedAction.java index 091fb79..9f5666e 100644 --- a/Workspace/Siman/src/org/splat/simer/NotYetImplementedAction.java +++ b/Workspace/Siman/src/org/splat/simer/NotYetImplementedAction.java @@ -3,6 +3,9 @@ package org.splat.simer; public class NotYetImplementedAction extends Action { + /** + * Serial version ID. + */ private static final long serialVersionUID = 3131921588316476454L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/OpenStudy.java b/Workspace/Siman/src/org/splat/simer/OpenStudy.java index 9d1edc1..0e19bf0 100644 --- a/Workspace/Siman/src/org/splat/simer/OpenStudy.java +++ b/Workspace/Siman/src/org/splat/simer/OpenStudy.java @@ -27,10 +27,9 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.ProgressState; import org.splat.service.ProjectElementService; -import org.splat.service.PublicationService; import org.splat.service.ScenarioService; import org.splat.service.StepService; -import org.splat.service.technical.ProjectSettingsService; +import org.splat.service.technical.RepositoryService; import org.splat.dal.bo.som.Publication; import org.splat.som.Revision; import org.splat.dal.bo.som.Scenario; @@ -44,6 +43,11 @@ 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 @@ -51,15 +55,32 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { private String credate; private String lasdate; private Publication selecdoc; + /** + * Injected project element service. + */ private ProjectElementService _projectElementService; + /** + * Injected scenario service. + */ private ScenarioService _scenarioService; + /** + * Injected step service. + */ private StepService _stepService; - protected final static Logger logger = org.splat.simer.Action.logger; - + /** + * 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()); @@ -178,13 +199,13 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { public URL newTemplateBasedDocument (String typename, User author) { // ------------------------------------------------------------------ String filename = typename + ".xml"; // Only XML templates are writeable - File template = new File(Database.getTemplatePath() + filename); + File template = new File(getRepositoryService().getTemplatePath() + filename); if (!template.exists()) return null; Session connex = Database.getSession(); Transaction transax = connex.beginTransaction(); try { - File udir = Database.getDownloadDirectory(author); + File udir = getRepositoryService().getDownloadDirectory(author); File credoc = new File(udir.getPath() + "/" + filename); // Creation of the meta-document @@ -476,4 +497,20 @@ public class OpenStudy extends OpenObject implements OpenStudyServices { public void setStepService(StepService stepService) { _stepService = stepService; } + + /** + * Get the repositoryService. + * @return the repositoryService + */ + public RepositoryService getRepositoryService() { + return _repositoryService; + } + + /** + * Set the repositoryService. + * @param repositoryService the repositoryService to set + */ + public void setRepositoryService(RepositoryService repositoryService) { + _repositoryService = repositoryService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/SearchBaseAction.java b/Workspace/Siman/src/org/splat/simer/SearchBaseAction.java index 6258bbf..2c32117 100644 --- a/Workspace/Siman/src/org/splat/simer/SearchBaseAction.java +++ b/Workspace/Siman/src/org/splat/simer/SearchBaseAction.java @@ -13,222 +13,271 @@ import org.splat.dal.bo.kernel.User; import org.splat.kernel.UserDirectory; import org.splat.som.ApplicationRights; import org.splat.dal.dao.som.Database; +import org.splat.service.SimulationContextService; import org.splat.service.technical.ProjectSettingsService; import org.splat.service.dto.Proxy; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.SimulationContextType; - public abstract class SearchBaseAction extends Action { - protected String ctype = null; // Context type index, when selected - protected String cvalue = null; // Context value index, when selected - protected String cindex = ""; // Context index, when removed - protected String author = null; - protected List manager = null; - protected SimulationContextType newtype; // Context type to be valued - protected List newvalue; // Context value to be selected - protected List critext; // Addable context types - protected List context; // Current contexts search criteria - protected List result; - - private static final long serialVersionUID = 7863055790228544510L; - - enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext } - -// ============================================================================================================================== -// Action methods -// ============================================================================================================================== - - public String doSubmitForm () { -// ----------------------------- -// Identification of the user action - UserAction action = UserAction.refreshResult; - if (ctype != null && Integer.valueOf(ctype) > 0) action = UserAction.selectContextType; - else if (cvalue != null && Integer.valueOf(cvalue) > 0) action = UserAction.selectContextValue; - else if (cindex.length() > 0) { - int index = Integer.valueOf(cindex); - if (index > 0) action = UserAction.removeContext; - else if (index < 0) action = UserAction.cancelSelect; - } -// Execution of the user action - Session connex = Database.getSession(); - Transaction transax = connex.beginTransaction(); - String done; - try { - saveFilter(); // Also reinitializes the form, if needed - - if (action == UserAction.selectContextType) { - done = doSelectContextType(); - } else - if (action == UserAction.selectContextValue) { - done = doAddContext(); - } else - if (action == UserAction.removeContext) { - done = doRemoveContext(); - } else - if (action == UserAction.cancelSelect) { - done = doCancel(); - } - else { // UserAction.refreshResult - done = doSearch(); - setContextTypeOptions(getInvolvedContexts()); // Done in other do functions, when required - } - setCandidates(); - transax.commit(); - return done; - } - catch (Exception error) { -// No need to roll back the transaction as it is read only - logger.error("Reason: ", error); - return ERROR; - } - } - - @SuppressWarnings("unchecked") - protected String doSelectContextType () { -// --------------------------------------- - SimulationContext.Properties sprop = new SimulationContext.Properties(); - - newtype = SimulationContext.selectType(Integer.valueOf(ctype)); - newvalue = Database.selectSimulationContextsWhere(sprop.setType(newtype)); - if (cindex.length() > 0 && Integer.valueOf(cindex) == 0) - getSession().remove("search.result"); - else - result = (List)getSession().get("search.result"); // We keep the previous result search, if valid - return "selectype"; - } - - protected String doAddContext () { -// -------------------------------- - SimulationContext selected = Database.selectSimulationContext(Integer.valueOf(cvalue)); - - context.add(selected); - setContextTypeOptions(getInvolvedContexts()); // Sets critext - getSession().remove("search.result"); // The current result is obsolete - return "refresh"; - } - - protected String doRemoveContext () { -// ----------------------------------- - int index = Integer.valueOf(cindex); - for (Iterator selected=context.iterator(); selected.hasNext();) { - if (selected.next().getIndex() == index) { - selected.remove(); - break; - } - } - setContextTypeOptions(getInvolvedContexts()); // Sets critext - getSession().remove("search.result"); // The current result is obsolete - return "refresh"; - } - - @SuppressWarnings("unchecked") - protected String doCancel () { -// ---------------------------- - result = (List)getSession().get("search.result"); // Current result search - setContextTypeOptions(getInvolvedContexts()); // Sets critext - return "refresh"; - } - -// ============================================================================================================================== -// Getters -// ============================================================================================================================== - - public String getAuthor () { -// -------------------------- - return author; - } - public List getCandidates () { -// ---------------------------------- - return manager; - } - public List getContextTypeOptions () { -// ----------------------------------------------------------- - return critext; - } - public List getContextValueOptions () { -// -------------------------------------------------------- - return newvalue; - } - public SimulationContextType getSelectedContextType () { -// ------------------------------------------------------ - return newtype; - } - public List getSimulationContexts () { -// ------------------------------------------------------- - return context; - } - public List getResult () { -// ------------------------------- - return result; - } - -// ============================================================================================================================== -// Setters -// ============================================================================================================================== - - public void setAuthor (String index) { -// ------------------------------------ - this.author = index; - } - public void setContextType (String type) { -// ---------------------------------------- - this.ctype = type; - } - public void setContextValue (String value) { -// ------------------------------------------ - this.cvalue = value; - } - public void setContextIndex (String value) { -// ------------------------------------------ - this.cindex = value; - } - - protected void setCandidates () { -// ------------------------------- - manager = new Vector(); - List users = UserDirectory.selectAllUsers(); - User me = getConnectedUser(); // May be null - for (Iterator i=users.iterator(); i.hasNext(); ) { - User next = i.next(); - ApplicationRights he = new ApplicationRights(next); - if (he.canCreateStudy()) { - if (next.equals(me)) manager.add(0, new ValidationFacade.ByManager(me)); - else manager.add(next); - } - } - } - - protected void setContextTypeOptions (List critext) { -// -------------------------------------------------------------------------- - for (Iterator i=context.iterator(); i.hasNext();) { - critext.remove(i.next().getType()); // Already used context type - } -// Ordering by alphabetical order of localized context types - SimulationContextType[] types = critext.toArray( new SimulationContextType[critext.size()] ); - ContextTypeComparator compare = new ContextTypeComparator(); - ProjectSettingsService.Step step = types[0].getAttachedStep(); - int from = 0; - int to = 0; - while (to < types.length-1) { - to += 1; - if (types[to].isAttachedTo(step)) continue; - - if (to > from+1) Arrays.sort(types, from, to, compare); - from = to; - step = types[to].getAttachedStep(); - } - if (to > from) Arrays.sort(types, from, to+1, compare); - this.critext = Arrays.asList(types); - } - -// ============================================================================================================================== -// Abstract services -// ============================================================================================================================== - - protected abstract String doSearch () throws InvalidPropertyException; - protected abstract List getInvolvedContexts (); - protected abstract void loadFilter (); - protected abstract void saveFilter (); + /** + * Serial version ID. + */ + private static final long serialVersionUID = 7863055790228544510L; + + protected String ctype = null; // Context type index, when selected + protected String cvalue = null; // Context value index, when selected + protected String cindex = ""; // Context index, when removed + protected String author = null; + protected List manager = null; + protected SimulationContextType newtype; // Context type to be valued + protected List newvalue; // Context value to be selected + protected List critext; // Addable context types + protected List context; // Current contexts search criteria + protected List result; + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; + + enum UserAction { + refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext + } + + // ============================================================================================================================== + // Action methods + // ============================================================================================================================== + + public String doSubmitForm() { + // ----------------------------- + // Identification of the user action + UserAction action = UserAction.refreshResult; + if (ctype != null && Integer.valueOf(ctype) > 0) + action = UserAction.selectContextType; + else if (cvalue != null && Integer.valueOf(cvalue) > 0) + action = UserAction.selectContextValue; + else if (cindex.length() > 0) { + int index = Integer.valueOf(cindex); + if (index > 0) + action = UserAction.removeContext; + else if (index < 0) + action = UserAction.cancelSelect; + } + // Execution of the user action + Session connex = Database.getSession(); + Transaction transax = connex.beginTransaction(); + String done; + try { + saveFilter(); // Also reinitializes the form, if needed + + if (action == UserAction.selectContextType) { + done = doSelectContextType(); + } else if (action == UserAction.selectContextValue) { + done = doAddContext(); + } else if (action == UserAction.removeContext) { + done = doRemoveContext(); + } else if (action == UserAction.cancelSelect) { + done = doCancel(); + } else { // UserAction.refreshResult + done = doSearch(); + setContextTypeOptions(getInvolvedContexts()); // Done in other do functions, when required + } + setCandidates(); + transax.commit(); + return done; + } catch (Exception error) { + // No need to roll back the transaction as it is read only + logger.error("Reason: ", error); + return ERROR; + } + } + + @SuppressWarnings("unchecked") + protected String doSelectContextType() { + // --------------------------------------- + SimulationContext.Properties sprop = new SimulationContext.Properties(); + + newtype = getSimulationContextService().selectType(Integer.valueOf(ctype)); + newvalue = getSimulationContextService().selectSimulationContextsWhere( + sprop.setType(newtype)); + if (cindex.length() > 0 && Integer.valueOf(cindex) == 0) + getSession().remove("search.result"); + else + result = (List) getSession().get("search.result"); // We keep the previous result search, if valid + return "selectype"; + } + + protected String doAddContext() { + // -------------------------------- + SimulationContext selected = getSimulationContextService() + .selectSimulationContext(Integer.valueOf(cvalue)); + + context.add(selected); + setContextTypeOptions(getInvolvedContexts()); // Sets critext + getSession().remove("search.result"); // The current result is obsolete + return "refresh"; + } + + protected String doRemoveContext() { + // ----------------------------------- + int index = Integer.valueOf(cindex); + for (Iterator selected = context.iterator(); selected + .hasNext();) { + if (selected.next().getIndex() == index) { + selected.remove(); + break; + } + } + setContextTypeOptions(getInvolvedContexts()); // Sets critext + getSession().remove("search.result"); // The current result is obsolete + return "refresh"; + } + + @SuppressWarnings("unchecked") + protected String doCancel() { + // ---------------------------- + result = (List) getSession().get("search.result"); // Current result search + setContextTypeOptions(getInvolvedContexts()); // Sets critext + return "refresh"; + } + + // ============================================================================================================================== + // Getters + // ============================================================================================================================== + + public String getAuthor() { + // -------------------------- + return author; + } + + public List getCandidates() { + // ---------------------------------- + return manager; + } + + public List getContextTypeOptions() { + // ----------------------------------------------------------- + return critext; + } + + public List getContextValueOptions() { + // -------------------------------------------------------- + return newvalue; + } + + public SimulationContextType getSelectedContextType() { + // ------------------------------------------------------ + return newtype; + } + + public List getSimulationContexts() { + // ------------------------------------------------------- + return context; + } + + public List getResult() { + // ------------------------------- + return result; + } + + // ============================================================================================================================== + // Setters + // ============================================================================================================================== + + public void setAuthor(String index) { + // ------------------------------------ + this.author = index; + } + + public void setContextType(String type) { + // ---------------------------------------- + this.ctype = type; + } + + public void setContextValue(String value) { + // ------------------------------------------ + this.cvalue = value; + } + + public void setContextIndex(String value) { + // ------------------------------------------ + this.cindex = value; + } + + protected void setCandidates() { + // ------------------------------- + manager = new Vector(); + List users = UserDirectory.selectAllUsers(); + User me = getConnectedUser(); // May be null + for (Iterator i = users.iterator(); i.hasNext();) { + User next = i.next(); + ApplicationRights he = new ApplicationRights(next); + if (he.canCreateStudy()) { + if (next.equals(me)) + manager.add(0, new ValidationFacade.ByManager(me)); + else + manager.add(next); + } + } + } + + protected void setContextTypeOptions(List critext) { + // -------------------------------------------------------------------------- + for (Iterator i = context.iterator(); i.hasNext();) { + critext.remove(i.next().getType()); // Already used context type + } + // Ordering by alphabetical order of localized context types + SimulationContextType[] types = critext + .toArray(new SimulationContextType[critext.size()]); + ContextTypeComparator compare = new ContextTypeComparator(); + ProjectSettingsService.Step step = types[0].getAttachedStep(); + int from = 0; + int to = 0; + while (to < types.length - 1) { + to += 1; + if (types[to].isAttachedTo(step)) + continue; + + if (to > from + 1) + Arrays.sort(types, from, to, compare); + from = to; + step = types[to].getAttachedStep(); + } + if (to > from) + Arrays.sort(types, from, to + 1, compare); + this.critext = Arrays.asList(types); + } + + // ============================================================================================================================== + // Abstract services + // ============================================================================================================================== + + protected abstract String doSearch() throws InvalidPropertyException; + + protected abstract List getInvolvedContexts(); + + protected abstract void loadFilter(); + + protected abstract void saveFilter(); + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/SearchDocumentAction.java b/Workspace/Siman/src/org/splat/simer/SearchDocumentAction.java index df2cbda..a97e6ff 100644 --- a/Workspace/Siman/src/org/splat/simer/SearchDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/SearchDocumentAction.java @@ -3,6 +3,9 @@ package org.splat.simer; public class SearchDocumentAction extends Action { + /** + * Serial version ID. + */ private static final long serialVersionUID = 4347921635793712836L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java b/Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java index a442c3e..096b5ed 100644 --- a/Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java +++ b/Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java @@ -9,6 +9,7 @@ import org.splat.kernel.InvalidPropertyException; import org.splat.dal.bo.kernel.User; import org.splat.kernel.UserDirectory; 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; @@ -28,7 +29,14 @@ public class SearchKnowledgeAction extends SearchBaseAction { private String words = null; // Full text search words private List types; // Available knowledge types filter (initialized below) private SearchService _searchService; + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; + /** + * Serial version ID. + */ private static final long serialVersionUID = -3104321907432838476L; // ============================================================================================================================== @@ -166,7 +174,7 @@ public class SearchKnowledgeAction extends SearchBaseAction { protected List getInvolvedContexts () { // ------------------------------------------------------------ - return SimulationContext.selectAllTypes(); + return getSimulationContextService().selectAllTypes(); } @SuppressWarnings("unchecked") @@ -224,4 +232,24 @@ public class SearchKnowledgeAction extends SearchBaseAction { public void setSearchService(SearchService searchService) { _searchService = searchService; } + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java b/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java index 26bd2dd..58a7718 100644 --- a/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java +++ b/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java @@ -11,6 +11,7 @@ import org.splat.kernel.UserDirectory; import org.splat.dal.dao.som.Database; import org.splat.dal.bo.som.ProgressState; import org.splat.service.SearchService; +import org.splat.service.SimulationContextService; import org.splat.service.technical.ProjectSettingsService; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.SimulationContextType; @@ -28,7 +29,14 @@ public class SearchStudyAction extends SearchBaseAction { private String words = null; // Full text search words private SearchService _searchService; private ProjectSettingsService _projectSettingsService; + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; + /** + * Serial version ID. + */ private static final long serialVersionUID = -1910481357051393077L; enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext } @@ -166,7 +174,7 @@ public class SearchStudyAction extends SearchBaseAction { List steps = getProjectSettings().getStepsOf(Study.class); ProjectSettingsService.Step[] number = steps.toArray(new ProjectSettingsService.Step[steps.size()]); - return SimulationContext.selectTypesOf(number); + return getSimulationContextService().selectTypesOf(number); } @SuppressWarnings("unchecked") @@ -238,4 +246,24 @@ public class SearchStudyAction extends SearchBaseAction { ProjectSettingsService projectSettingsService) { _projectSettingsService = projectSettingsService; } + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/StartAction.java b/Workspace/Siman/src/org/splat/simer/StartAction.java index 9066571..e38e02d 100644 --- a/Workspace/Siman/src/org/splat/simer/StartAction.java +++ b/Workspace/Siman/src/org/splat/simer/StartAction.java @@ -20,6 +20,9 @@ public class StartAction extends Action implements ServletRequestAware { private ProjectSettingsService _projectSettingsService; private ApplicationSettings _ApplicationSettings; + /** + * Serial version ID. + */ private static final long serialVersionUID = 5875058140682652964L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java index 4f348c5..c946aef 100644 --- a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java +++ b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java @@ -43,6 +43,9 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { private int approver; private StudyService _studyService; + /** + * Serial version ID. + */ private static final long serialVersionUID = 4210696018741092900L; private enum Save { title, contributor, cycle } diff --git a/Workspace/Siman/src/org/splat/simer/UploadAction.java b/Workspace/Siman/src/org/splat/simer/UploadAction.java index 923a120..ad51319 100644 --- a/Workspace/Siman/src/org/splat/simer/UploadAction.java +++ b/Workspace/Siman/src/org/splat/simer/UploadAction.java @@ -3,6 +3,7 @@ package org.splat.simer; import java.io.File; import org.splat.kernel.Do; +import org.splat.service.technical.RepositoryService; import org.splat.dal.dao.som.Database; @@ -15,6 +16,10 @@ public class UploadAction extends Action { private ToDo action; // Action to do private String next = null; // Action to which the uploaded file is passed private String index = null; // Depending on the next action, document index to which the action applies + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; private static final long serialVersionUID = 6003880772275115923L; @@ -33,7 +38,7 @@ public class UploadAction extends Action { // ------------------------- if (action == ToDo.cancel) return "cancel"; try { - File udir = Database.getDownloadDirectory(getConnectedUser()); + File udir = getRepositoryService().getDownloadDirectory(getConnectedUser()); String path = udir.getPath() + "/" + uploadFileName; File file = new File(path); @@ -96,4 +101,20 @@ public class UploadAction extends Action { // ---------------------------------------------- this.uploadMimeType = mime; } + + /** + * Get the repositoryService. + * @return the repositoryService + */ + public RepositoryService getRepositoryService() { + return _repositoryService; + } + + /** + * Set the repositoryService. + * @param repositoryService the repositoryService to set + */ + public void setRepositoryService(RepositoryService repositoryService) { + _repositoryService = repositoryService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java b/Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java index 2aacb56..c47b322 100644 --- a/Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java +++ b/Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java @@ -22,6 +22,9 @@ public abstract class UploadBaseNextAction extends Action { protected String docuses = null; protected ToDo action = null; + /** + * Serial version ID. + */ private static final long serialVersionUID = -6925961099244461039L; protected enum ToDo { cancel, save }; diff --git a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java index a5503b3..e56c4db 100644 --- a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java @@ -24,6 +24,7 @@ import org.splat.dal.bo.som.ProgressState; import org.splat.service.PublicationService; import org.splat.service.StepService; import org.splat.service.technical.ProjectSettingsService; +import org.splat.service.technical.RepositoryService; import org.splat.dal.bo.som.Publication; import org.splat.som.Revision; import org.splat.som.Step; @@ -41,7 +42,14 @@ public class VersionDocumentAction extends UploadBaseNextAction { private ProjectSettingsService _projectSettingsService; private PublicationService _publicationService; private StepService _stepService; + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; + /** + * Serial version ID. + */ private static final long serialVersionUID = -5702264003232132168L; // ============================================================================================================================== @@ -53,7 +61,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { Session connex = Database.getSession(); Transaction transax = connex.beginTransaction(); User user = getConnectedUser(); - File updir = Database.getDownloadDirectory(user); + File updir = getRepositoryService().getDownloadDirectory(user); File upfile = new File(updir.getPath() + "/" + filename); mystudy = getOpenStudy(); @@ -136,7 +144,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { mystudy = getOpenStudy(); User user = getConnectedUser(); Step step = mystudy.getSelectedStep(); - File updir = Database.getDownloadDirectory(user); + File updir = getRepositoryService().getDownloadDirectory(user); File upfile = new File(updir.getPath() + "/" + filename); // Versioning of the document @@ -346,4 +354,20 @@ public class VersionDocumentAction extends UploadBaseNextAction { public void setStepService(StepService stepService) { _stepService = stepService; } + + /** + * Get the repositoryService. + * @return the repositoryService + */ + public RepositoryService getRepositoryService() { + return _repositoryService; + } + + /** + * Set the repositoryService. + * @param repositoryService the repositoryService to set + */ + public void setRepositoryService(RepositoryService repositoryService) { + _repositoryService = repositoryService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/admin/DatabaseIndexingAction.java b/Workspace/Siman/src/org/splat/simer/admin/DatabaseIndexingAction.java index b3b0041..931e0b8 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/DatabaseIndexingAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/DatabaseIndexingAction.java @@ -15,14 +15,17 @@ import org.splat.dal.bo.som.Study; public class DatabaseIndexingAction extends Action { + /** + * Serial version ID. + */ + private static final long serialVersionUID = 4194268823457749655L; + private List newstudies; private String indices; private SearchService _searchService; private ImportedStudy _importedStudy; private StudyService _studyService; - private static final long serialVersionUID = 4194268823457749655L; - // ============================================================================================================================== // Action methods // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java b/Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java index f4073e9..444cff8 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java @@ -9,16 +9,24 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.splat.dal.bo.kernel.User; import org.splat.kernel.UserDirectory; +import org.splat.service.technical.RepositoryService; import org.splat.simer.UploadBaseNextAction; import org.splat.dal.dao.som.Database; public class ImportUserAction extends UploadBaseNextAction { + /** + * Serial version ID. + */ + private static final long serialVersionUID = 1516715800624817965L; + private List users; private Set newsers; - - private static final long serialVersionUID = 1516715800624817965L; + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; // ============================================================================================================================== // Action methods @@ -30,7 +38,7 @@ public class ImportUserAction extends UploadBaseNextAction { Transaction transax = connex.beginTransaction(); try { User user = getConnectedUser(); // The database administrator - File updir = Database.getDownloadDirectory(user); + File updir = getRepositoryService().getDownloadDirectory(user); File upfile = new File(updir.getPath() + "/" + filename); newsers = UserDirectory.importUsers(upfile); @@ -62,4 +70,20 @@ public class ImportUserAction extends UploadBaseNextAction { // -------------------------------- return newsers.contains(user); } + + /** + * Get the repositoryService. + * @return the repositoryService + */ + public RepositoryService getRepositoryService() { + return _repositoryService; + } + + /** + * Set the repositoryService. + * @param repositoryService the repositoryService to set + */ + public void setRepositoryService(RepositoryService repositoryService) { + _repositoryService = repositoryService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/admin/KnowledgeElementAction.java b/Workspace/Siman/src/org/splat/simer/admin/KnowledgeElementAction.java index 01707dc..cc22a80 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/KnowledgeElementAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/KnowledgeElementAction.java @@ -5,6 +5,9 @@ import org.splat.simer.Action; public class KnowledgeElementAction extends Action { + /** + * Serial version ID. + */ private static final long serialVersionUID = 2416672950671183384L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java index 9d65a2f..232e52c 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java @@ -21,176 +21,214 @@ import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.ProgressState; import org.splat.service.KnowledgeElementService; import org.splat.service.SearchService; +import org.splat.service.SimulationContextService; import org.splat.service.technical.ProjectSettingsService; import org.splat.service.dto.Proxy; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.SimulationContextType; import org.splat.dal.bo.som.Study; - +/** + * Action for operations on simulation contexts. + */ public class SimulationContextAction extends Action { - private List tocheck; // Simulation contexts to be approved - private int selection; // Index of the selected simulation context presented in the approval form - private SimulationContext edition; // Corresponding simulation context object - private ProjectSettingsService.Step step; // Study step to which the selected simulation context is attached - private Set owner; // Study scenarios indexed by this simulation context - private List existype; // Existing approved simulation context types ordered by localized names - private List exisname; // Existing approved simulation context types ordered by internal codes - private List existing; // Existing simulation contexts of selected type + /** + * Serial version ID. + */ + private static final long serialVersionUID = 7083323229359094699L; + + private List tocheck; // Simulation contexts to be approved + private int selection; // Index of the selected simulation context presented in the approval form + private SimulationContext edition; // Corresponding simulation context object + private ProjectSettingsService.Step step; // Study step to which the selected simulation context is attached + private Set owner; // Study scenarios indexed by this simulation context + private List existype; // Existing approved simulation context types ordered by localized names + private List exisname; // Existing approved simulation context types ordered by internal codes + private List existing; // Existing simulation contexts of selected type + /** + * Injected search service. + */ private SearchService _searchService; + /** + * Injected project settings service. + */ private ProjectSettingsService _projectSettingsService; + /** + * Injected knowledge element service. + */ private KnowledgeElementService _knowledgeElementService; + /** + * Injected simulation context service. + */ + private SimulationContextService _simulationContextService; - private static final long serialVersionUID = 7083323229359094699L; - - private class ContextNameComparator implements Comparator { -// --------------------------------------------------------------------------------- - public int compare(SimulationContextType t1, SimulationContextType t2) - { - String name1 = t1.getName(); - String name2 = t2.getName(); - - return name1.compareToIgnoreCase(name2); - } - } - - public class LocalizedContextTypes { -// ---------------------------------- - private Locale locale; - private List sortype; // Existing approved simulation context types ordered by localized names - - public LocalizedContextTypes (List types, Locale lang) - { - ResourceBundle bundle = ResourceBundle.getBundle("som", lang); - SimulationContextType[] tosort = types.toArray( new SimulationContextType[types.size()] ); - String[] name = new String[types.size()]; - - for (int i=0; i getTypeNames () - { - return sortype; - } - public boolean isCurrent () - { - return (locale.equals(ApplicationSettings.getCurrentLocale())); - } - } - -// ============================================================================================================================== -// Action methods -// ============================================================================================================================== - - public String doInitialize () { -// ----------------------------- - Session connex = Database.getSession(); - Transaction transax = connex.beginTransaction(); - try { - SimulationContext.Properties cprop = new SimulationContext.Properties(); - List context = Database.selectSimulationContextsWhere(cprop.setState(ProgressState.inCHECK)); - - tocheck = new Vector(context.size()); - for (Iterator i=context.iterator(); i.hasNext(); ) { - tocheck.add( new SimulationContextFacade(i.next(), getProjectSettings().getAllSteps()) ); - } - selection = 0; - edition = null; - owner = null; - - transax.commit(); - return SUCCESS; - } - catch (Exception error) { - logger.error("Reason:", error); - return ERROR; // No need to roll-back the transaction as it is read-only - } - } - - public String doSelect () { -// ------------------------- - Session connex = Database.getSession(); - Transaction transax = connex.beginTransaction(); - try { - SimulationContext.Properties cprop = new SimulationContext.Properties(); - List context = Database.selectSimulationContextsWhere(cprop.setState(ProgressState.inCHECK)); - List selected = new ArrayList(1); - - tocheck = new Vector(context.size()); - for (Iterator i=context.iterator(); i.hasNext(); ) { - SimulationContext next = i.next(); - if (next.getIndex() == selection) { - edition = next; - selected.add(edition); - } - tocheck.add( new SimulationContextFacade(next, getProjectSettings().getAllSteps()) ); - } - KnowledgeElement.Properties kprop = new KnowledgeElement.Properties(); - List kelm = getSearchService().selectKnowledgeElementsWhere(kprop.setSimulationContexts(selected).setState(ProgressState.inWORK)); - - step = edition.getType().getAttachedStep(); - owner = new HashSet(); - for (Iterator i=kelm.iterator(); i.hasNext(); ) { - KnowledgeElement next = getKnowledgeElementService().selectKnowledgeElement(i.next().getIndex()); - ProjectElementFacade facade; - if (step.appliesTo(Study.class)) facade = new ProjectElementFacade(next.getOwnerScenario().getOwnerStudy(), step); - else facade = new ProjectElementFacade(next.getOwnerScenario(), step); - owner.add(facade); - } - SimulationContextType.Properties sprop = new SimulationContextType.Properties(); - List types = SimulationContext.selectTypesWhere(sprop.setState(ProgressState.APPROVED)); - Locale[] support = ApplicationSettings.getSupportedLocales(); - -// Sort localized type names - existype = new ArrayList(support.length); - for (int i=0; i { + /** + * {@inheritDoc} + * + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + public int compare(SimulationContextType t1, SimulationContextType t2) { + String name1 = t1.getName(); + String name2 = t2.getName(); + + return name1.compareToIgnoreCase(name2); + } } - public void setSearchService(SearchService searchService) { - _searchService = searchService; + public class LocalizedContextTypes { + // ---------------------------------- + private Locale locale; + private List sortype; // Existing approved simulation context types ordered by localized names + + public LocalizedContextTypes(List types, + Locale lang) { + ResourceBundle bundle = ResourceBundle.getBundle("som", lang); + SimulationContextType[] tosort = types + .toArray(new SimulationContextType[types.size()]); + String[] name = new String[types.size()]; + + for (int i = 0; i < name.length; i++) + name[i] = bundle.getString("type.context." + + tosort[i].getName()); + Arrays.sort(name); + sortype = Arrays.asList(name); + locale = lang; + } + + public String getLocale() { + return locale.toString(); + } + + public List getTypeNames() { + return sortype; + } + + public boolean isCurrent() { + return (locale.equals(ApplicationSettings.getCurrentLocale())); + } + } + + // ============================================================================================================================== + // Action methods + // ============================================================================================================================== + + public String doInitialize() { + // ----------------------------- + Session connex = Database.getSession(); + Transaction transax = connex.beginTransaction(); + try { + SimulationContext.Properties cprop = new SimulationContext.Properties(); + List context = getSimulationContextService() + .selectSimulationContextsWhere( + cprop.setState(ProgressState.inCHECK)); + + tocheck = new Vector(context.size()); + for (Iterator i = context.iterator(); i + .hasNext();) { + tocheck.add(new SimulationContextFacade(i.next(), + getProjectSettings().getAllSteps())); + } + selection = 0; + edition = null; + owner = null; + + transax.commit(); + return SUCCESS; + } catch (Exception error) { + logger.error("Reason:", error); + return ERROR; // No need to roll-back the transaction as it is read-only + } + } + + public String doSelect() { + // ------------------------- + Session connex = Database.getSession(); + Transaction transax = connex.beginTransaction(); + try { + SimulationContext.Properties cprop = new SimulationContext.Properties(); + List context = getSimulationContextService() + .selectSimulationContextsWhere( + cprop.setState(ProgressState.inCHECK)); + List selected = new ArrayList( + 1); + + tocheck = new Vector(context.size()); + for (Iterator i = context.iterator(); i + .hasNext();) { + SimulationContext next = i.next(); + if (next.getIndex() == selection) { + edition = next; + selected.add(edition); + } + tocheck.add(new SimulationContextFacade(next, + getProjectSettings().getAllSteps())); + } + KnowledgeElement.Properties kprop = new KnowledgeElement.Properties(); + List kelm = getSearchService().selectKnowledgeElementsWhere( + kprop.setSimulationContexts(selected).setState( + ProgressState.inWORK)); + + step = edition.getType().getAttachedStep(); + owner = new HashSet(); + for (Iterator i = kelm.iterator(); i.hasNext();) { + KnowledgeElement next = getKnowledgeElementService() + .selectKnowledgeElement(i.next().getIndex()); + ProjectElementFacade facade; + if (step.appliesTo(Study.class)) + facade = new ProjectElementFacade(next.getOwnerScenario() + .getOwnerStudy(), step); + else + facade = new ProjectElementFacade(next.getOwnerScenario(), + step); + owner.add(facade); + } + SimulationContextType.Properties sprop = new SimulationContextType.Properties(); + List types = getSimulationContextService() + .selectTypesWhere(sprop.setState(ProgressState.APPROVED)); + Locale[] support = ApplicationSettings.getSupportedLocales(); + + // Sort localized type names + existype = new ArrayList(support.length); + for (int i = 0; i < support.length; i++) { + existype.add(new LocalizedContextTypes(types, support[i])); + } + SimulationContextType[] names = types + .toArray(new SimulationContextType[types.size()]); + + Arrays.sort(names, new ContextNameComparator()); + exisname = Arrays.asList(names); + + existing = getSimulationContextService() + .selectSimulationContextsWhere( + cprop.setType(edition.getType()).setState( + ProgressState.APPROVED)); + + transax.commit(); + return SUCCESS; + } catch (Exception error) { + logger.error("Reason:", error); + return ERROR; // No need to roll-back the transaction as it is read-only + } + } + + // ============================================================================================================================== + // Getters and setters + // ============================================================================================================================== + + public List getAllStudySteps() { + // ----------------------------------------------------- + return getProjectSettings().getAllSteps(); } - public List getAllStudySteps () { -// ----------------------------------------------------- - return getProjectSettings().getAllSteps(); - } - /** - * Get project settings. + /** + * Get project settings. + * * @return Project settings service */ private ProjectSettingsService getProjectSettings() { @@ -199,53 +237,62 @@ public class SimulationContextAction extends Action { /** * 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; } - public ProjectSettingsService.Step getAttachedStep () { -// ---------------------------------------------- - return step; - } - public List getContextsToBeApproved () { -// --------------------------------------------------------------- - return tocheck; - } - public SimulationContext getEdited () { -// ------------------------------------- - return edition; - } - public List getExistingContexts () { -// ----------------------------------------------------- - return existing; - } - public List getExistingNames () { -// ------------------------------------------------------ - return exisname; - } - public List getSupportedLocales () { -// --------------------------------------------------------- - return existype; - } - public Set getIndexedElements () { -// ------------------------------------------------------ - return owner; - } - public int getSelection () { -// -------------------------- - return selection; - } - - public void setSelection (String index) { -// --------------------------------------- - selection = Integer.valueOf(index); - } + public ProjectSettingsService.Step getAttachedStep() { + // ---------------------------------------------- + return step; + } + + public List getContextsToBeApproved() { + // --------------------------------------------------------------- + return tocheck; + } + + public SimulationContext getEdited() { + // ------------------------------------- + return edition; + } + + public List getExistingContexts() { + // ----------------------------------------------------- + return existing; + } + + public List getExistingNames() { + // ------------------------------------------------------ + return exisname; + } + + public List getSupportedLocales() { + // --------------------------------------------------------- + return existype; + } + + public Set getIndexedElements() { + // ------------------------------------------------------ + return owner; + } + + public int getSelection() { + // -------------------------- + return selection; + } + + public void setSelection(String index) { + // --------------------------------------- + selection = Integer.valueOf(index); + } /** * Get the knowledgeElementService. + * * @return the knowledgeElementService */ public KnowledgeElementService getKnowledgeElementService() { @@ -254,10 +301,48 @@ public class SimulationContextAction extends Action { /** * Set the knowledgeElementService. - * @param knowledgeElementService the knowledgeElementService to set + * + * @param knowledgeElementService + * the knowledgeElementService to set */ public void setKnowledgeElementService( KnowledgeElementService knowledgeElementService) { _knowledgeElementService = knowledgeElementService; } + + /** + * Get the simulationContextService. + * + * @return the simulationContextService + */ + public SimulationContextService getSimulationContextService() { + return _simulationContextService; + } + + /** + * Set the simulationContextService. + * + * @param simulationContextService + * the simulationContextService to set + */ + public void setSimulationContextService( + SimulationContextService simulationContextService) { + _simulationContextService = simulationContextService; + } + + /** + * Get the searchService. + * @return the searchService + */ + public SearchService getSearchService() { + return _searchService; + } + + /** + * Set the searchService. + * @param searchService the searchService to set + */ + public void setSearchService(SearchService searchService) { + _searchService = searchService; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/wapp/Item.java b/Workspace/Siman/src/org/splat/wapp/Item.java index 929f399..e68dc43 100644 --- a/Workspace/Siman/src/org/splat/wapp/Item.java +++ b/Workspace/Siman/src/org/splat/wapp/Item.java @@ -10,6 +10,9 @@ public class Item implements Serializable { private String myurl; private boolean selected = false; + /** + * Serial version ID. + */ private static final long serialVersionUID = -3505572710372809913L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/org/splat/wapp/MenuItem.java b/Workspace/Siman/src/org/splat/wapp/MenuItem.java index 0a78e87..fafbac5 100644 --- a/Workspace/Siman/src/org/splat/wapp/MenuItem.java +++ b/Workspace/Siman/src/org/splat/wapp/MenuItem.java @@ -8,6 +8,9 @@ public class MenuItem extends Item { protected static class Group extends MenuItem { // --------------------------------------------- private boolean open = false; + /** + * Serial version ID. + */ private static final long serialVersionUID = 8319750643667219000L; protected Group (String label) { super(label); } @@ -18,6 +21,9 @@ public class MenuItem extends Item { } protected static class SubItem extends MenuItem { // ----------------------------------------------- + /** + * Serial version ID. + */ private static final long serialVersionUID = -4793172296421132566L; protected SubItem (String label) { super(label); } diff --git a/Workspace/Siman/src/org/splat/wapp/TabBar.java b/Workspace/Siman/src/org/splat/wapp/TabBar.java index b362d4e..0698691 100644 --- a/Workspace/Siman/src/org/splat/wapp/TabBar.java +++ b/Workspace/Siman/src/org/splat/wapp/TabBar.java @@ -13,6 +13,9 @@ public class TabBar implements Serializable { protected HashMap disabled; // Actions of disabled item protected String selection; + /** + * Serial version ID. + */ private static final long serialVersionUID = 1851786085512439549L; // ============================================================================================================================== diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 16e6b0a..ad3192f 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -2,7 +2,7 @@ - - - - + + + + @@ -31,10 +30,10 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> - + - - @@ -50,6 +49,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + - - - - - + + + + + + - - + + @@ -101,12 +103,15 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> class="org.splat.simer.EditSimulationContextAction" scope="prototype" parent="displayStudyStepAction"> + + - - + + @@ -140,11 +145,15 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> class="org.splat.simer.SearchStudyAction" scope="prototype"> + + + + + + ref="knowledgeElementService" /> + + + -- 2.39.2