/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 03.10.2012
this.got = true;
this.description = null; // Conversion not described
}
- protected ConvertsRelation (Document from, File to, String description) {
+ public ConvertsRelation (Document from, File to, String description) {
// -----------------------------------------------------------------------
super(from);
this.refer = to;
* @copyright OPEN CASCADE 2012
*/
-import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
import java.util.Arrays;
-import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
-import org.hibernate.Hibernate;
-import org.hibernate.Session;
-
import org.splat.dal.bo.kernel.Persistent;
import org.splat.dal.bo.kernel.Relation;
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.Timestamp.ComparatorByDate;
-import org.splat.dal.dao.som.Database;
-import org.splat.kernel.NotApplicableException;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
-import org.splat.manox.Reader;
-import org.splat.manox.Toolbox;
-import org.splat.service.StudyService;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.service.technical.ProjectSettingsServiceImpl;
-import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming;
import org.splat.som.Revision;
import org.splat.som.Step;
+/**
+ * Document persistent class.
+ */
public class Document extends Entity {
// Persistent fields
private int history;
private User author;
private Date lasdate;
- private ProjectSettingsService _projectSettingsService;
- private StudyService _studyService;
// Transient fields
public static String suformat = "00"; // Format of the suffix number of document did and file name
// Construction
// ==============================================================================================================================
- // Fields initialization class
+ /**
+ * Fields initialization class.
+ */
public static class Properties extends Persistent.Properties {
// ------------------------------------------------------------
private DocumentType type = null;
return (history > 0);
}
- // ==============================================================================================================================
- // Public services
- // ==============================================================================================================================
-
- public static DocumentType createType(DocumentType.Properties tprop)
- throws MissedPropertyException, InvalidPropertyException,
- MultiplyDefinedException, RuntimeException {
- // ---------------------------------------------------------------------
- // TODO: Check for duplicate definition
- DocumentType type = new DocumentType(tprop);
- Session session = Database.getSession();
- session.save(type);
-
- return type;
- }
-
- public static Properties extractProperties(java.io.File file) {
- // --------------------------------------------------------------
- Properties fprop = new Properties();
- Reader tool = Toolbox.getReader(file);
- String value;
- if (tool != null)
- try {
- value = tool.extractProperty("title");
- if (value != null)
- fprop.setName(value);
-
- value = tool.extractProperty("reference");
- if (value != null)
- fprop.setReference(value);
- } catch (Exception e) {
- }
- return fprop;
- }
-
- @SuppressWarnings("unchecked")
- public static List<DocumentType> selectAllTypes() {
- // --------------------------------------------------
- String query = "from DocumentType";
-
- List<DocumentType> types = Database.getSession().createQuery(query)
- .list();
- for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
- Hibernate.initialize(i.next()); // Supposed fetching document types
- }
- return types;
- }
-
- @SuppressWarnings("unchecked")
- public static List<DocumentType> selectResultTypes() {
- // -----------------------------------------------------
- String query = "from DocumentType where result is not null order by result asc";
-
- return Database.getSession().createQuery(query).list();
- }
-
- public static DocumentType selectType(String name) {
- // ---------------------------------------------------
- String query = new StringBuffer("from DocumentType where name='")
- .append(name).append("'").toString();
-
- return (DocumentType) Database.getSession().createQuery(query)
- .uniqueResult();
- }
-
- public static DocumentType selectType(long index) {
- // -------------------------------------------------
- String query = new StringBuffer("from DocumentType where rid='")
- .append(index).append("'").toString();
-
- return (DocumentType) Database.getSession().createQuery(query)
- .uniqueResult();
- }
-
- @SuppressWarnings("unchecked")
- public static List<DocumentType> selectTypesOf(
- ProjectSettingsService.Step step) {
- // --------------------------------------------------------------------------
- Integer number = step.getNumber();
- String query = new StringBuffer("from DocumentType").append(
- " where step like '%-").append(number).append("-%'").toString();
-
- List<DocumentType> types = Database.getSession().createQuery(query)
- .list();
- for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
- Hibernate.initialize(i.next()); // For fetching document types
- }
- return types;
- }
-
- // ==============================================================================================================================
- // Protected services
- // ==============================================================================================================================
-
- protected ConvertsRelation attach(String format) {
- // -------------------------------------------------
- return attach(format, null);
- }
-
- protected ConvertsRelation attach(String format, String description) {
- // ---------------------------------------------------------------------
- String path = this.getRelativePath();
- File export = new File(path + "." + format);
- ConvertsRelation attach = new ConvertsRelation(this, export,
- description);
- Session session = Database.getSession();
-
- session.save(export);
- session.save(attach);
-
- this.addRelation(attach); // Updates this
-
- return attach;
- }
-
- public boolean buildReferenceFrom(ProjectElement scope, Document lineage) {
- // -----------------------------------------------------------------------------
- if (state != ProgressState.inWORK)
- return false;
- Study owner = null;
- Scenario context = null;
- if (scope instanceof Study)
- owner = (Study) scope;
- else {
- context = ((Scenario) scope);
- owner = context.getOwnerStudy();
- }
- did = lineage.did;
- if (context != null && (lineage.isVersioned() || owner.shares(lineage))) {
- version = new Revision(version).setBranch(context.getReference())
- .toString();
- }
- return true;
- }
-
- public boolean buildReferenceFrom(Study scope) {
- // --------------------------------------------------
- if (state != ProgressState.inWORK && state != ProgressState.EXTERN)
- return false;
- DecimalFormat tostring = new DecimalFormat(suformat);
-
- did = did.replace("%" + suformat, tostring.format(scope
- .getLastLocalIndex()));
- return true;
- }
-
- public boolean demote() {
- // ---------------------------
- ValidationStep torem;
-
- if (state == ProgressState.inCHECK) {
- state = ProgressState.inDRAFT;
- torem = ValidationStep.REVIEW;
- // This operation must not change the version number of documents.
- // Consequently, inDRAFT documents may have a minor version number equal to zero.
- } else if (state == ProgressState.inDRAFT) {
- state = ProgressState.inWORK;
- torem = ValidationStep.PROMOTION;
- } else {
- return false;
- }
- for (Iterator<Relation> i = this.getAllRelations().iterator(); i
- .hasNext();) {
- Relation link = i.next();
- if (!(link instanceof StampRelation))
- continue;
- if (((StampRelation) link).getStampType() != torem)
- continue;
- i.remove();
- break;
- }
- Database.getSession().update(this);
- return true;
- }
-
- /**
- * Increments the reference count of this document following its publication into a Study step.
- *
- * @see #release()
- */
- public void hold() {
- // ----------------------
- countag += 1;
- if (this.isSaved())
- Database.getSession().update(this);
- }
-
- public boolean promote(Timestamp stamp) {
- // -------------------------------------------
- ProgressState newstate = null;
-
- if (state == ProgressState.inWORK) {
- newstate = ProgressState.inDRAFT; // Promotion to being reviewed
- } else if (state == ProgressState.inDRAFT) {
- newstate = ProgressState.inCHECK; // Promotion to approval
- Revision myvers = new Revision(version);
- if (myvers.isMinor()) {
- version = myvers.incrementAs(newstate).toString();
- // TODO: If my physical file is programatically editable, update its (property) version number
- // ISSUE: What about attached files such as PDF if exist, should we remove them ?
- }
- } else if (state == ProgressState.inCHECK) {
- newstate = ProgressState.APPROVED;
- }
- this.state = newstate;
- if (stamp != null)
- this.addRelation(stamp.getContext());
- Database.getSession().update(this);
- return true;
- }
-
- /**
- * Decrements the reference count of this document following the removal of a Publication from a Study step.
- *
- * @see #hold()
- */
- public void release() {
- // -------------------------
- countag -= 1;
- if (this.isSaved())
- Database.getSession().update(this);
- }
-
- protected void rename(String title) throws InvalidPropertyException {
- // ------------------------------------
- if (title.length() == 0)
- throw new InvalidPropertyException("name");
-
- Calendar current = Calendar.getInstance();
- this.name = title;
- this.lasdate = current.getTime(); // Today
- Database.getSession().update(this);
- }
-
- public void updateAs(Revision newvers) {
- // ------------------------------------------
- version = newvers.setBranch(version).toString(); // Branch names are propagated by the versionning
- ProgressState newstate = ProgressState.inCHECK;
- if (newvers.isMinor())
- newstate = ProgressState.inWORK;
- state = null; // Just to tell updateAs(sate) to not increment the version number
- updateAs(newstate);
- }
-
- public void updateAs(ProgressState state) {
- // ---------------------------------------------
- Document previous = null;
-
- // Set of version number
- if (state == ProgressState.EXTERN) {
- if (this.state != ProgressState.EXTERN)
- this.version = null; // Strange use-case...
- } else {
- Revision myvers = new Revision(version);
- if (!myvers.isNull()) { // Versionning context
- for (Iterator<Relation> i = getAllRelations().iterator(); i
- .hasNext();) {
- Relation link = i.next();
- if (!link.getClass().equals(VersionsRelation.class))
- continue;
- previous = (Document) link.getTo(); // Versioned document
- break;
- }
- }
- if (this.state != null)
- myvers.incrementAs(state); // Incrementation if the reversion number is not imposed
- this.version = myvers.toString();
- }
- // Update this document and the previous version, if exit
- Session session = Database.getSession();
- if (previous != null) {
- previous.history += 1;
- session.update(previous);
- }
- this.state = state;
- session.update(this);
- }
-
- // protected void upgrade () {
- // -------------------------
- // if (this.state != ProgressState.inWORK) return;
- //
- // Calendar current = Calendar.getInstance();
- // for (Iterator<Relation> i=getAllRelations().iterator(); i.hasNext();) {
- // Relation link = i.next();
- // if (!link.getClass().equals(UsesRelation.class)) continue;
- //
- // Document used = (Document)link.getTo();
- // if (!used.isVersioned()) continue;
- // TODO: Update the uses relation
- // }
- // this.promote();
- // this.lasdate = current.getTime(); // Today
- // Database.getSession().update(this);
- //
- // TODO: Promote documents using this one
- // }
-
- /**
- * @return
- */
- private ProjectSettingsService getProjectSettingsService() {
- return _projectSettingsService;
- }
-
- public void setProjectSettingsService(
- ProjectSettingsService projectSettingsService) {
- _projectSettingsService = projectSettingsService;
- }
-
- /**
- * @return
- */
- public StudyService getStudyService() {
- return _studyService;
- }
-
- public void setStudyService(StudyService studyService) {
- _studyService = studyService;
- }
-
/**
* Get the step.
* @return the step
public void setHistory(int history) {
this.history = history;
}
+
+ /**
+ * Set the version.
+ * @param version the version to set
+ */
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ /**
+ * Set the state.
+ * @param state the state to set
+ */
+ public void setProgressState(ProgressState state) {
+ this.state = state;
+ }
+
+ /**
+ * Get the countag.
+ * @return the countag
+ */
+ public int getCountag() {
+ return countag;
+ }
+
+ /**
+ * Set the countag.
+ * @param countag the countag to set
+ */
+ public void setCountag(int countag) {
+ this.countag = countag;
+ }
}
\ No newline at end of file
* @copyright OPEN CASCADE 2012
*/
-import java.util.List;
import java.util.Set;
import java.util.HashSet;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
import org.splat.service.technical.ProjectSettingsService;
-import org.splat.service.technical.ProjectSettingsService.Step;
public class DocumentType extends Persistent {
// -------------------------
}
// Initialization constructor
- protected DocumentType (Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
+ public DocumentType (Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
// -----------------------------------------
super(dprop); // Throws one of the above exception if not valid
name = dprop.name;
this.myfile = null;
}
// Internal constructors
- protected File (String path) {
+ public File (String path) {
// ----------------------------
Calendar current = Calendar.getInstance();
String[] table = path.split("\\x2E");
<property name="value" type="text" column="value" access="field" not-null="true" />
<!-- Scenario owner -->
- <many-to-one name="owner" column="owner" access="field" not-null="true" />
+ <many-to-one name="owner" column="owner" access="field" not-null="true" cascade="save-update"/>
<!-- ProgressState state -->
<property name="state" column="state" type="ProgressState" access="field" not-null="true" />
return getOwnerScenario().getOwnerStudy().getVisibility();
}
- public void update (String description) {
-// ---------------------------------------
- value = description.trim();
- if (!value.startsWith("<p>")) {
- StringBuffer text = new StringBuffer("<p>");
- int index = value.indexOf("<p>");
- if (index > 0) {
- value = text.append(value.substring(0, index)).append("</p>").append(value.substring(index)).toString();
- } else {
- value = text.append(value).append("</p>").toString();
- }
- }
- Database.getSession().update(this); // No need to update the Lucene index
- }
-
-// ==============================================================================================================================
-// Public services
-// ==============================================================================================================================
-
- public static KnowledgeElementType createType (String name) throws RuntimeException {
-// -----------------------------------------------------------
-//TODO: Check for duplicate definition
- KnowledgeElementType kelt = new KnowledgeElementType(name);
- Session session = Database.getSession();
- session.save(kelt);
-
- return kelt;
- }
-
- @SuppressWarnings("unchecked")
- public static List<KnowledgeElementType> selectAllTypes () {
-// ----------------------------------------------------------
- StringBuffer query = new StringBuffer("from KnowledgeElementType");
- query = query.append(" order by rid asc");
- return Database.getSession().createQuery(query.toString()).list();
- }
-
- @SuppressWarnings("unchecked")
- public static List<KnowledgeElementType> selectTypesWhere (ProgressState state) {
-// -------------------------------------------------------------------------------
- StringBuffer query = new StringBuffer("from KnowledgeElementType where state='").append(state).append("'");
- query = query.append(" order by rid asc");
- return Database.getSession().createQuery(query.toString()).list();
- }
-
- public static KnowledgeElementType selectType (String name) {
-// -----------------------------------------------------------
- StringBuffer query = new StringBuffer("from KnowledgeElementType where name='").append(name).append("'");
- return (KnowledgeElementType)Database.getSession().createQuery(query.toString()).uniqueResult();
- }
-
- public static KnowledgeElementType selectType (int index) {
-// ---------------------------------------------------------
- StringBuffer query = new StringBuffer("from KnowledgeElementType where rid='").append(index).append("'");
- return (KnowledgeElementType)Database.getSession().createQuery(query.toString()).uniqueResult();
- }
-
/**
* @param aState knowledge element progress state to set
*/
public void setTitle(String aTitle) {
title = aTitle;
}
+ /**
+ * Set the value.
+ * @param value the value to set
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
}
\ No newline at end of file
return true;
}
- public ConvertsRelation attach (String format) {
-// ----------------------------------------------
- return mydoc.attach(format);
- }
-
- public ConvertsRelation attach (String format, String description) {
-// ------------------------------------------------------------------
- return mydoc.attach(format, description);
- }
-
/**
* Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into
* which the referenced document has been published.<br/>
public void setIsnew(char isnew) {
this.isnew = isnew;
}
- public void rename (String title) throws InvalidPropertyException {
-// ---------------------------------
- mydoc.rename(title);
- }
-
/**
* Out-dates this publication and recursively all publications using this one.
* Typically, a publication is out-dated when modifying a document to which it depends.
* @copyright OPEN CASCADE 2012
*/
-import java.io.IOException;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Vector;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.splat.dal.bo.kernel.Persistent;
import org.splat.dal.bo.kernel.User;
import org.splat.dal.dao.som.Database;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
-import org.splat.service.StepService;
-import org.splat.service.technical.IndexService;
import org.splat.som.Step;
private Study owner;
private int sid; // Identifier unique in the scope of owner study
private User cuser; // User having checked-out the scenario, if done
+ /**
+ * The persistent set of scenario knowledge elements.
+ */
private Set<KnowledgeElement> kelms;
// Transient fields
- private HashMap<Long, List<KnowledgeElement>> known;
- private List<KnowledgeElement> knowl; // Copy of kelms excluding the internal Knowledge Element (ucase below)
- private KnowledgeElement ucase; // Internal Knowledge Element for accessing to all used simulation contexts
+ /**
+ * The transient map of knowledge elements grouped by types.
+ */
+ transient private HashMap<Long, List<KnowledgeElement>> known;
+ /**
+ * The scenario transient list of knowledge elements.
+ */
+ transient private List<KnowledgeElement> knowl; // Copy of kelms excluding the internal Knowledge Element (ucase below)
+ /**
+ * The scenario transient "use case" knowledge element.
+ */
+ transient private KnowledgeElement ucase; // Internal Knowledge Element for accessing to all used simulation contexts
// ==============================================================================================================================
// Construction
// ==============================================================================================================================
-// Fields initialization class
+
+ /**
+ * Fields initialization class.
+ */
public static class Properties extends Persistent.Properties {
// ------------------------------------------------------------
private Study owner = null;
kelms = new HashSet<KnowledgeElement>();
manager = sprop.manager;
- if (!owner.isStaffedBy(manager)) throw new InvalidPropertyException("manager");
+//RKV: The business logic is moved to business services: if (!owner.isStaffedBy(manager)) throw new InvalidPropertyException("manager");
credate = sprop.date; // Inherited attribute
if (credate == null) {
// Private services
// ==============================================================================================================================
/**
- * @return
+ * Get the persistent set of knowledge elements.
+ * @return the persistent set of scenario knowledge elements
*/
public Set<KnowledgeElement> getKnowledgeElements() {
return kelms;
}
- /**
- * @param kelm
+ /**
+ * Get the transient list of knowledge elements.
+ * @return the transient list of knowledge elements
*/
- public void setUcase(KnowledgeElement kelm) {
- ucase = kelm;
+ public List<KnowledgeElement> getKnowledgeElementsList() {
+ return knowl;
}
/**
- * @return
+ * Set the scenario transient "use case" knowledge element.
+ * @param kelm the scenario transient "use case" knowledge element
*/
- public List<KnowledgeElement> getKnowledgeElementsList() {
- return knowl;
+ public void setUcase(KnowledgeElement kelm) {
+ ucase = kelm;
}
/**
- * Get the ucase.
- * @return the ucase
+ * Get the scenario transient "use case" knowledge element.
+ * @return the scenario transient "use case" knowledge element
*/
public KnowledgeElement getUcase() {
return ucase;
package org.splat.dal.bo.som;
+
/**
*
* @author Daniel Brunier-Coulin
*/
import java.util.Calendar;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
+import java.util.Map;
import java.util.Set;
import java.util.Vector;
-import org.hibernate.Session;
import org.splat.dal.bo.kernel.Persistent;
-import org.splat.dal.bo.kernel.Relation;
import org.splat.dal.bo.kernel.User;
-import org.splat.dal.dao.som.Database;
import org.splat.kernel.MultiplyDefinedException;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
-import org.splat.kernel.UserDirectory;
-import org.splat.service.StepService;
-import org.splat.service.technical.IndexServiceImpl;
-import org.splat.service.technical.ProjectSettingsServiceImpl;
-import org.splat.service.technical.ProjectSettingsServiceImpl.ProjectSettingsValidationCycle;
import org.splat.som.Revision;
-
+/**
+ * Siman Study persistent object.
+ */
public class Study extends ProjectElement {
-// Persistent fields
- private String sid; // External unique reference in a format conform to the configuration pattern
- private int docount; // Total number of documents of this study, including versions
- private ProgressState state;
- private Visibility visibility;
- private List<Scenario> scenarii;
- private String version;
- private int history; // Number of studies versioning this one, if any
-
-// Transient fields
- private List<User> contributor; // Shortcut to contributors
- private HashMap<String,ValidationCycle> validactor; // Shortcut to validation cycles
- private Set<User> actor; // Summary of above actors
- private StepService _stepService;
-
-// ==============================================================================================================================
-// Construction
-// ==============================================================================================================================
-
-// Fields initialization class
- public static class Properties extends Persistent.Properties {
-// ------------------------------------------------------------
- private String sid = null; // Search criterion only
- private String title = null;
- private String summary = null;
- private User manager = null;
- private User actor = null; // Search criterion only
- private Visibility visibility = null; // Search criterion only
- private ProgressState state = null; // Search criterion only
- private Date date = null;
- private List<SimulationContext> context = new Vector<SimulationContext>(); // Search criterion only
-
-// - Public services
-
- public void clear () {
- super.clear();
- sid = null;
- title = null;
- summary = null;
- manager = null;
- actor = null;
- visibility = null;
- state = null;
- date = null;
- context = new Vector<SimulationContext>(); // as clear() may generate side effects
- }
- public Properties copy () {
- Properties copy = new Properties();
- copy.sid = this.sid;
- copy.title = this.title;
- copy.summary = this.summary;
- copy.manager = this.manager;
- copy.actor = this.actor;
- copy.visibility = this.visibility;
- copy.state = this.state;
- copy.date = this.date;
- copy.context = this.context;
- return copy;
- }
-// - Protected services
-
- public User getActor () {
- return actor;
- }
- public User getManager () {
- return manager;
- }
- public ProgressState getProgressState () {
- return state;
- }
- public String getReference () {
- return sid;
- }
- public List<SimulationContext> getSimulationContexts () {
- return context;
- }
- public String getTitle () {
- return title;
- }
- public String getSummary () {
- return summary;
- }
- public Visibility getVisibility () {
- return visibility;
- }
-// - Property setters
-
-// For building a search query
- public Properties setActor (User actor)
- {
- this.actor = actor;
- return this;
- }
- public Properties setDate (Date date)
- {
- this.date = date;
- return this;
- }
- public Properties setDescription (String summary)
- {
- if (summary.length() > 0) this.summary = summary;
- return this;
- }
- public Properties setManager (User user)
- {
- this.manager = user;
- return this;
- }
-// For building a search query
- public Properties setReference (String sid) throws InvalidPropertyException
- {
- if (sid.length() == 0) throw new InvalidPropertyException("reference");
- this.sid = sid;
- return this;
- }
-// For building a search query
- public Properties setSimulationContexts (List<SimulationContext> context) {
- this.context = context;
- return this;
- }
-// For building a search query
- public Properties setState (ProgressState state)
- {
- this.state = state;
- return this;
- }
- public Properties setTitle (String title) throws InvalidPropertyException
- {
- if (title.length() == 0) throw new InvalidPropertyException("title");
- this.title = title;
- return this;
- }
-// For building a search query
- public Properties setVisibility (Visibility area)
- {
- this.visibility = area;
- return this;
- }
-// - Global validity check
-
- public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
- {
- if (title == null) throw new MissedPropertyException("title");
- if (manager == null) throw new MissedPropertyException("manager");
- }
- }
-// Database fetch constructor
- protected Study () {
-// ------------------
- contributor = null;
- validactor = null;
- actor = null;
- }
-// Internal constructor
- public Study (Properties sprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
-// ----------------------------------
- super(sprop); // Throws one of the above exception if not valid
- sid = sprop.sid; // Reset after save
- title = sprop.title; // Inherited attribute
- manager = sprop.manager;
- docount = 0;
- history = 0;
- scenarii = new LinkedList<Scenario>();
- visibility = Visibility.PRIVATE;
- state = ProgressState.inWORK;
-
- credate = sprop.date; // Inherited attribute
- if (credate == null) {
- Calendar current = Calendar.getInstance();
- credate = current.getTime(); // Today
- }
- lasdate = credate; // Inherited attribute
- version = new Revision().incrementAs(state).toString();
-
- if (sprop.summary != null) this.setAttribute( new DescriptionAttribute(this, sprop.summary) );
-
- contributor = null;
- validactor = null;
- actor = null;
- }
-
- /**
- * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
- *
- * @return the actors of this study
- * @see #hasActor(User)
- */
- public Set<User> getActors () {
- // -----------------------------
- if (actor == null) setShortCuts();
- return Collections.unmodifiableSet(actor);
- }
-
- /**
- * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
- *
- * @return the actors of this study
- * @see #hasActor(User)
- */
- public Set<User> getModifiableActors () {
- // -----------------------------
- if (actor == null) setShortCuts();
- return actor;
- }
-
- public List<User> getContributors () {
- // ------------------------------------
- if (contributor == null) setShortCuts();
- return Collections.unmodifiableList(contributor); // May be empty
- }
-
- public List<User> getModifiableContributors () {
- if (contributor == null) setShortCuts();
- return contributor; // May be empty
- }
-
- public ProgressState getProgressState () {
-// ----------------------------------------
- return state;
- }
+ // Persistent fields
+ /**
+ * Persistent sid property. It is an external unique reference in a format conform to the configuration pattern.
+ */
+ private String sid;
+ /**
+ * Persistent docount property. It is a total number of documents of this study, including versions.
+ */
+ private int docount;
+ /**
+ * Persistent state property. It is a study progress state.
+ *
+ * @see org.splat.dal.bo.som.ProgressState enumeration
+ */
+ private ProgressState state;
+ /**
+ * Persistent visibility property.
+ *
+ * @see org.splat.dal.bo.som.Visibility enumeration
+ */
+ private Visibility visibility;
+ /**
+ * Persistent list of study scenarii.
+ */
+ private List<Scenario> scenarii;
+ private String version;
+ /**
+ * Persistent history property. It is a number of studies versioning this one, if any.
+ */
+ private int history;
-/**
- * Returns the global unique reference of this study.
- * The study reference is common to all versions of the study (versioning a study does not change its reference).
- * The form of this study reference is defined in the configuration of the application server - see the SOM XML customization
- * file.
- */
- public String getReference () {
- return sid;
- }
+ // Transient fields
+ /**
+ * Transient list of contributors.
+ */
+ private transient List<User> contributor = new Vector<User>(); // Shortcut to contributors
+ /**
+ * Transient map of document types to validation cycles.
+ */
+ private transient Map<String, ValidationCycle> validactor = new HashMap<String, ValidationCycle>(); // Shortcut to validation cycles
+ /**
+ * Transient set of all actors of the study, i.d. contributors and validation cycles participants.
+ */
+ private transient Set<User> actor = new HashSet<User>(); // Summary of above actors
- public void setReference (String aReference) {
- sid = aReference;
- }
+ // ==============================================================================================================================
+ // Construction
+ // ==============================================================================================================================
- public Scenario[] getScenarii () {
-// --------------------------------
- return scenarii.toArray(new Scenario[scenarii.size()]);
- }
+ /**
+ * Fields initialization class.
+ */
+ public static class Properties extends Persistent.Properties {
+ // ------------------------------------------------------------
+ private String sid = null; // Search criterion only
+ private String title = null;
+ private String summary = null;
+ private User manager = null;
+ private User actor = null; // Search criterion only
+ private Visibility visibility = null; // Search criterion only
+ private ProgressState state = null; // Search criterion only
+ private Date date = null;
+ private List<SimulationContext> context = new Vector<SimulationContext>(); // Search criterion only
+
+ // - Public services
+
+ public void clear() {
+ super.clear();
+ sid = null;
+ title = null;
+ summary = null;
+ manager = null;
+ actor = null;
+ visibility = null;
+ state = null;
+ date = null;
+ context = new Vector<SimulationContext>(); // as clear() may generate side effects
+ }
+
+ public Properties copy() {
+ Properties copy = new Properties();
+ copy.sid = this.sid;
+ copy.title = this.title;
+ copy.summary = this.summary;
+ copy.manager = this.manager;
+ copy.actor = this.actor;
+ copy.visibility = this.visibility;
+ copy.state = this.state;
+ copy.date = this.date;
+ copy.context = this.context;
+ return copy;
+ }
+
+ // - Protected services
+
+ public User getActor() {
+ return actor;
+ }
+
+ public User getManager() {
+ return manager;
+ }
+
+ public ProgressState getProgressState() {
+ return state;
+ }
+
+ public String getReference() {
+ return sid;
+ }
+
+ public List<SimulationContext> getSimulationContexts() {
+ return context;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getSummary() {
+ return summary;
+ }
+
+ public Visibility getVisibility() {
+ return visibility;
+ }
+
+ // - Property setters
+
+ // For building a search query
+ public Properties setActor(User actor) {
+ this.actor = actor;
+ return this;
+ }
+
+ public Properties setDate(Date date) {
+ this.date = date;
+ return this;
+ }
+
+ public Properties setDescription(String summary) {
+ if (summary.length() > 0)
+ this.summary = summary;
+ return this;
+ }
+
+ public Properties setManager(User user) {
+ this.manager = user;
+ return this;
+ }
+
+ // For building a search query
+ public Properties setReference(String sid)
+ throws InvalidPropertyException {
+ if (sid.length() == 0)
+ throw new InvalidPropertyException("reference");
+ this.sid = sid;
+ return this;
+ }
+
+ // For building a search query
+ public Properties setSimulationContexts(List<SimulationContext> context) {
+ this.context = context;
+ return this;
+ }
+
+ // For building a search query
+ public Properties setState(ProgressState state) {
+ this.state = state;
+ return this;
+ }
+
+ public Properties setTitle(String title)
+ throws InvalidPropertyException {
+ if (title.length() == 0)
+ throw new InvalidPropertyException("title");
+ this.title = title;
+ return this;
+ }
+
+ // For building a search query
+ public Properties setVisibility(Visibility area) {
+ this.visibility = area;
+ return this;
+ }
+
+ // - Global validity check
+
+ public void checkValidity() throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException {
+ if (title == null)
+ throw new MissedPropertyException("title");
+ if (manager == null)
+ throw new MissedPropertyException("manager");
+ }
+ }
- public List<Scenario> getScenariiList () {
-// --------------------------------
- return scenarii;
- }
+ // Database fetch constructor
+ protected Study() {
+ contributor.clear();
+ validactor.clear();
+ actor.clear();
+ }
-/**
- * Returns the validation cycle of the given document type.
- *
- * @param doc the document type being subject of validation
- * @return the validation cycle of the document, or null if not defined.
- */
- public ValidationCycle getValidationCycleOf (DocumentType type) {
-// ---------------------------------------------------------------
- if (validactor == null) setShortCuts();
- ValidationCycle result = validactor.get(type.getName());
- if (result == null) {
- if (type.isStepResult()) result = validactor.get("default"); // "default" validation cycle defined in the configuration, if exist
- if (result == null) result = validactor.get("built-in");
- }
- return result;
- }
-
- public String getVersion () {
-// ---------------------------
- return version;
- }
-
- public Visibility getVisibility () {
-// ----------------------------------
- return visibility;
- }
+ // Internal constructor
+ public Study(Properties sprop) throws MissedPropertyException,
+ InvalidPropertyException, MultiplyDefinedException {
+ // ----------------------------------
+ super(sprop); // Throws one of the above exception if not valid
+ sid = sprop.sid; // Reset after save
+ title = sprop.title; // Inherited attribute
+ manager = sprop.manager;
+ docount = 0;
+ history = 0;
+ scenarii = new LinkedList<Scenario>();
+ visibility = Visibility.PRIVATE;
+ state = ProgressState.inWORK;
+
+ credate = sprop.date; // Inherited attribute
+ if (credate == null) {
+ Calendar current = Calendar.getInstance();
+ credate = current.getTime(); // Today
+ }
+ lasdate = credate; // Inherited attribute
+ version = new Revision().incrementAs(state).toString();
+
+ if (sprop.summary != null)
+ this.setAttribute(new DescriptionAttribute(this, sprop.summary));
+
+ contributor.clear();
+ validactor.clear();
+ actor.clear();
+ }
-/**
- * Checks if the given user is actor of this study.
- * Actors include contributors, reviewers and approvers.
- *
- * @return true if the given user is actor of this study.
- * @see #getActors()
- */
- public boolean hasActor (User user) {
-// -----------------------------------
- if (user == null) return false;
- for (Iterator<User> i=this.getActors().iterator(); i.hasNext(); ) {
- User involved = i.next();
- if (involved.equals(user)) return true;
- }
- return false;
- }
+ public ProgressState getProgressState() {
+ return state;
+ }
+
+ /**
+ * Returns the global unique reference of this study. The study reference is common to all versions of the study (versioning a study
+ * does not change its reference). The form of this study reference is defined in the configuration of the application server - see the
+ * SOM XML customization file.
+ */
+ public String getReference() {
+ return sid;
+ }
+
+ public void setReference(String aReference) {
+ sid = aReference;
+ }
+
+ public Scenario[] getScenarii() {
+ // --------------------------------
+ return scenarii.toArray(new Scenario[scenarii.size()]);
+ }
+
+ public List<Scenario> getScenariiList() {
+ // --------------------------------
+ return scenarii;
+ }
+
+ public String getVersion() {
+ // ---------------------------
+ return version;
+ }
+
+ public Visibility getVisibility() {
+ // ----------------------------------
+ return visibility;
+ }
-/**
- * Checks whether this study is in the Public or the Reference area of the repository.
- *
- * @return true if the study is public.
- * @see #moveToPublic()
- * @see #moveToReference()
- */
- public boolean isPublic () {
-// --------------------------
- return (visibility != Visibility.PRIVATE);
- }
-/**
- * Checks if the given user participates to this study.
- * The Study staff includes the author and contributors.
- *
- * @return true if the given user is actor of this study.
- * @see #getContributors()
- */
- public boolean isStaffedBy (User user) {
-// --------------------------------------
- if (user == null) return false;
- if (manager.equals(user)) return true;
- for (Iterator<User> i=getContributors().iterator(); i.hasNext();) {
- if (i.next().equals(user)) return true;
- }
- return false;
- }
-
- public boolean isVersioned () {
-// -----------------------------
- return (history > 0);
- }
-
- public boolean shares (Document doc) {
-// ------------------------------------
- Scenario[] scene = this.getScenarii(); // If shared from within the study, the document is shared by the scenarios
- int counter = 0;
-
- for (int i=0; i<scene.length; i++) {
- if (!scene[i].publishes(doc)) continue;
- if (counter == 1) return true;
- counter += 1;
- }
- return false;
- }
-
- public int getLastLocalIndex () {
-// ----------------------------------
- return docount;
- }
-
- public void loadWorkflow () {
-// ------------------------------
- setShortCuts();
- }
-
- public void setShortCuts () {
-// ----------------------------
- contributor = new Vector<User>();
- validactor = new HashMap<String,ValidationCycle>();
- actor = new HashSet<User>();
-
-// Get the contributors
- for (Iterator<Relation> i=getRelations(ContributorRelation.class).iterator(); i.hasNext(); ) {
- ContributorRelation link = (ContributorRelation)i.next();
- contributor.add(link.getTo());
- }
-// Get the validation cycles specific to this study
- for (Iterator<Relation> i=getRelations(ValidationCycleRelation.class).iterator(); i.hasNext(); ) {
- ValidationCycleRelation link = (ValidationCycleRelation)i.next();
- validactor.put(link.getDocumentType().getName(), link.getTo()); // The associated document type is necessarily not null in this context
- }
-// Get the validation cycles coming from the configured workflow and not overridden in this study
- for (Iterator<ProjectSettingsServiceImpl.ProjectSettingsValidationCycle> i=ProjectSettingsServiceImpl.getAllValidationCycles().iterator(); i.hasNext(); ) {
- ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle = i.next();
- String type = cycle.getName();
- if (!validactor.containsKey(type)) validactor.put(type, new ValidationCycle(this, cycle));
- }
-// Get all corresponding actors
- for (Iterator<ValidationCycle> i=validactor.values().iterator(); i.hasNext(); ) {
- ValidationCycle cycle = i.next();
- User[] user = cycle.getAllActors();
- for (int j=0; j<user.length; j++) actor.add(user[j]);
- }
-// Get all other actors
- for (Iterator<Relation> i=this.getAllRelations().iterator(); i.hasNext(); ) {
- Relation link = i.next();
- Class<?> kindof = link.getClass().getSuperclass();
- if (!kindof.equals(ActorRelation.class)) continue;
- actor.add( ((ActorRelation)link).getTo() );
- }
- }
/**
- * @param aVisibility a study visibility to set
+ * Checks whether this study is in the Public or the Reference area of the repository.
+ *
+ * @return true if the study is public.
+ * @see #moveToPublic()
+ * @see #moveToReference()
+ */
+ public boolean isPublic() {
+ // --------------------------
+ return (visibility != Visibility.PRIVATE);
+ }
+
+ public boolean isVersioned() {
+ // -----------------------------
+ return (history > 0);
+ }
+
+ public boolean shares(Document doc) {
+ // ------------------------------------
+ Scenario[] scene = this.getScenarii(); // If shared from within the study, the document is shared by the scenarios
+ int counter = 0;
+
+ for (int i = 0; i < scene.length; i++) {
+ if (!scene[i].publishes(doc))
+ continue;
+ if (counter == 1)
+ return true;
+ counter += 1;
+ }
+ return false;
+ }
+
+ public int getLastLocalIndex() {
+ // ----------------------------------
+ return docount;
+ }
+
+ /**
+ * @param aVisibility
+ * a study visibility to set
*/
public void setVisibility(Visibility aVisibility) {
visibility = aVisibility;
}
+
/**
- * @param aState a study progress state to set
+ * @param aState
+ * a study progress state to set
*/
public void setProgressState(ProgressState aState) {
state = aState;
}
+
/**
- * @param string
+ * @param aVersion
*/
public void setVersion(String aVersion) {
version = aVersion;
}
+
/**
- * @param i
+ * Set total number of documents of this study, including versions. It is stored in the persistent property docount.
+ *
+ * @param anIndex
+ * a number of study documents
*/
public void setLastLocalIndex(int anIndex) {
docount = anIndex;
}
+
/**
- * @return
+ * Get the transient map of document types to validation cycles.
+ *
+ * @return map of validation cycles
*/
- public HashMap<String, ValidationCycle> getValidationCycles() {
+ public Map<String, ValidationCycle> getValidationCycles() {
return validactor;
}
+
+ /**
+ * Get the transient list of study contributors.
+ *
+ * @return the List of User objects
+ */
+ public List<User> getContributor() {
+ return contributor;
+ }
+
+ /**
+ * Get the transient set of all study actors (contributors and validation cycles participants).
+ *
+ * @return the set of User objects
+ */
+ public Set<User> getActor() {
+ return actor;
+ }
}
\ No newline at end of file
// Protected services
// ==============================================================================================================================
- protected StampRelation getContext () {
+ public StampRelation getContext () {
// -------------------------------------
return context;
}
{
if (doctype == null) throw new MissedPropertyException("type");
}
+
+ /**
+ * Get the publisher.
+ * @return the publisher
+ */
+ public User getPublisher() {
+ return publisher;
+ }
+
+ /**
+ * Get the reviewer.
+ * @return the reviewer
+ */
+ public User getReviewer() {
+ return reviewer;
+ }
+
+ /**
+ * Get the approver.
+ * @return the approver
+ */
+ public User getApprover() {
+ return approver;
+ }
+
+ /**
+ * Get the signatory.
+ * @return the signatory
+ */
+ public User getSignatory() {
+ return signatory;
+ }
}
// Database fetch constructor
- protected ValidationCycle () {
- }
-// Internal constructors
- protected ValidationCycle (Study from, ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle) {
-// -----------------------------------------------------------------------------
- Actor[] actype = cycle.getActorTypes();
- User.Properties uprop = new User.Properties();
-
- mytype = Document.selectType(cycle.getName()); // Null in case of default validation cycle
-// context = new ValidationCycleRelation(from, this);
- context = null; // Validation cycle defined in the workflow
- for (int i=0; i<actype.length; i++) {
- User actor = null;
- if (actype[i] != null)
- try {
- if (actype[i] == Actor.manager) {
- actor = from.getAuthor();
- } else
- if (actype[i] == Actor.Nx1) {
- List<User> manager = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Nx1"));
- if (manager.size() == 1) actor = manager.get(0);
- } else
- if (actype[i] == Actor.Nx2) {
- List<User> manager = UserDirectory.selectUsersWhere(uprop.setOrganizationName("Nx2"));
- if (manager.size() == 1) actor = manager.get(0);
- } else { /* Actor.customer */
- actor = from.getAuthor();
-//TODO: Get the customer of the study, if exists
- }
- } catch (Exception e) { // Should not happen
- actor = null;
- }
- if (i == 0) reviewer = actor;
- else if (i == 1) approver = actor;
- else if (i == 2) signatory = actor;
- }
+ public ValidationCycle () {
}
public ValidationCycle (Study from, Properties vprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
// --------------------------------------------------------
* @see #isDefault()
*/
public DocumentType getDocumentType () {
-// --------------------------------------
- return mytype; // May be null
+ // --------------------------------------
+ return mytype; // May be null
+ }
+
+ /**
+ * Set a document type for the validation cycle.
+ * @param aType the document type
+ */
+ public void setDocumentType (DocumentType aType) {
+ mytype = aType; // May be null
}
/**
// -----------------------------------------------
return context;
}
-
- protected void remove (ValidationStep step) {
-// ------------------------------------------
- if (step == ValidationStep.REVIEW) reviewer = null;
- else if (step == ValidationStep.APPROVAL) approver = null;
- else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = null;
- if (this.isSaved()) Database.getSession().update(this);
- }
-
- public void resetActors (Properties vprop) {
-// ---------------------------------------------
- publisher = vprop.publisher; // May be null
- reviewer = vprop.reviewer; // May be null
- approver = vprop.approver; // May be null
- signatory = vprop.signatory; // May be null
- if (this.isSaved()) Database.getSession().update(this);
- }
-
- protected void setActor (ValidationStep step, User actor) {
-// --------------------------------------------------------
- if (step == ValidationStep.PROMOTION) publisher = actor;
- else if (step == ValidationStep.REVIEW) reviewer = actor;
- else if (step == ValidationStep.APPROVAL) approver = actor;
- else if (step == ValidationStep.ACCEPTANCE || step == ValidationStep.REFUSAL) signatory = actor;
- if (this.isSaved()) Database.getSession().update(this);
- }
+ /**
+ * Set the publisher.
+ * @param publisher the publisher to set
+ */
+ public void setPublisher(User publisher) {
+ this.publisher = publisher;
+ }
+ /**
+ * Set the reviewer.
+ * @param reviewer the reviewer to set
+ */
+ public void setReviewer(User reviewer) {
+ this.reviewer = reviewer;
+ }
+ /**
+ * Set the approver.
+ * @param approver the approver to set
+ */
+ public void setApprover(User approver) {
+ this.approver = approver;
+ }
+ /**
+ * Set the signatory.
+ * @param signatory the signatory to set
+ */
+ public void setSignatory(User signatory) {
+ this.signatory = signatory;
+ }
}
\ No newline at end of file
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 08.10.2012
*/
public T findByCriteria(Criterion aCondition);
+ /**
+ * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
+ *
+ * @return a list of all objects of the considered type T
+ */
+ @SuppressWarnings("unchecked")
+ public List<T> getAll();
+
+ /**
+ * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
+ *
+ * @param anOrder
+ * a result list order. Null is ignored and in such case the result list is unordered.
+ * @return an ordered list of all objects of the considered type T
+ */
+ @SuppressWarnings("unchecked")
+ public List<T> getAll(Order anOrder);
+
/**
* Retrieve a list of objects which were previously persisted to the database using the given criteria.
*
*/
@SuppressWarnings("unchecked")
public List<T> getFilteredList(Criterion aCondition, Order anOrder);
+
+ /**
+ * Makes detached object persistent.
+ * @param transientObject
+ * transient instance of the object to be made persistent
+ */
+ public void persist(T transientObject);
+
+ /**
+ * Merge detached object with persistent data.
+ *
+ * @param transientObject
+ * transient instance of the object to be merged with persistent data
+ * @return merged persistent object
+ */
+ public T merge(T transientObject);
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 08.10.2012
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;
/**
.uniqueResult();
}
+ /**
+ * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
+ *
+ * @return a list of all objects of the considered type T
+ */
+ @SuppressWarnings("unchecked")
+ public List<T> getAll() {
+ return getSession().createCriteria(getType()).list();
+ }
+
+ /**
+ * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
+ *
+ * @param anOrder
+ * a result list order. Null is ignored and in such case the result list is unordered.
+ * @return an ordered list of all objects of the considered type T
+ */
+ @SuppressWarnings("unchecked")
+ public List<T> getAll(Order anOrder) {
+ Criteria aCriteria = getSession().createCriteria(getType());
+ if (anOrder != null) {
+ aCriteria.addOrder(anOrder);
+ }
+ return aCriteria.list();
+ }
+
/**
* Retrieve a list of objects which were previously persisted to the database using the given criteria.
*
getSession().delete(persistentObject);
}
+ /**
+ * Makes detached object persistent.
+ *
+ * @param transientObject
+ * transient instance of the object to be made persistent
+ */
+ public void persist(T transientObject) {
+ getSession().persist(transientObject);
+ }
+
+ /**
+ * Merge detached object with persistent data.
+ *
+ * @param transientObject
+ * transient instance of the object to be merged with persistent data
+ * @return merged persistent object
+ */
+ @SuppressWarnings("unchecked")
+ public T merge(T transientObject) {
+ return (T) getSession().merge(transientObject);
+ }
+
/**
* Get persistent object type.
*
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File Id:
* Creation date 02.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File Id:
* Creation date 02.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 03.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 03.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 03.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File Id:
* Creation date 02.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 02.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
package org.splat.service;
+import java.util.List;
+
+import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.ProjectElement;
+import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.Timestamp;
import org.splat.dal.bo.som.Document.Properties;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
import org.splat.kernel.NotApplicableException;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.som.Revision;
import org.splat.som.Step;
/**
* Document service interface.
*
- * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*
*/
public interface DocumentService {
* document properties (owner project element is used)
*/
public void generateDocumentId(Document aDoc, Properties dprop);
-
+
/**
* Get a directory where the document file is saved.
- * @param aDoc the document
+ *
+ * @param aDoc
+ * the document
* @return a directory
*/
public java.io.File getSaveDirectory(Document aDoc);
+
+ /**
+ * Extract title and reference properties from the given file.
+ *
+ * @param file
+ * the file to parse
+ * @return the extracted properties
+ */
+ public Properties extractProperties(java.io.File file);
+
+ /**
+ * Create "Converts" relation for the given document and the given format.
+ *
+ * @param aDoc
+ * the document
+ * @param format
+ * the format
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Document aDoc, String format);
+
+ /**
+ * Create "Converts" relation for the given document, format and description.
+ *
+ * @param aDoc
+ * the document
+ * @param format
+ * the format
+ * @param description
+ * the description of the relation
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Document aDoc, String format,
+ String description);
+
+ /**
+ * Build a reference (document id) for the given document in the given study basing on the given original document.
+ *
+ * @param aDoc
+ * the document to set set the new reference to
+ * @param scope
+ * the study
+ * @param lineage
+ * the original document
+ * @return true if the new reference is set
+ */
+ public boolean buildReferenceFrom(Document aDoc, ProjectElement scope,
+ Document lineage);
+
+ /**
+ * Build a reference (document id) for the given document in the given study.
+ *
+ * @param aDoc
+ * the document to set set the new reference to
+ * @param scope
+ * the study
+ * @return true if the new reference is set
+ */
+ public boolean buildReferenceFrom(Document aDoc, Study scope);
+
+ /**
+ * Demote a document.
+ *
+ * @param aDoc
+ * the document to demote
+ * @return true if demoting succeeded
+ */
+ public boolean demote(Document aDoc);
+
+ /**
+ * Promote a document.
+ *
+ * @param aDoc
+ * the document to promote
+ * @param stamp
+ * the timestamp of the promotion
+ * @return true if promotion succeeded
+ */
+ public boolean promote(Document aDoc, Timestamp stamp);
+
+ /**
+ * Increments the reference count of this document following its publication in a Study step.
+ *
+ * @param aDoc
+ * the document to hold
+ * @see #release()
+ */
+ public void hold(Document aDoc);
+
+ /**
+ * Decrements the reference count of this document following the removal of a Publication from a Study step.
+ *
+ * @param aDoc
+ * the document to release
+ * @see #hold()
+ */
+ public void release(Document aDoc);
+
+ /**
+ * Rename a document.
+ *
+ * @param aDoc
+ * the document to rename
+ * @param title
+ * the new document title
+ * @throws InvalidPropertyException
+ * if the new title is empty
+ */
+ public void rename(Document aDoc, String title)
+ throws InvalidPropertyException;
+
+ /**
+ * Update a version of the given document.
+ *
+ * @param aDoc
+ * the document
+ * @param newvers
+ * the new version
+ */
+ public void updateAs(Document aDoc, Revision newvers);
+
+ /**
+ * Update a state of the given document.
+ *
+ * @param aDoc
+ * the document
+ * @param state
+ * the new state
+ */
+ public void updateAs(Document aDoc, ProgressState state);
+
+ /**
+ * Checks if documents of this type are result of a study. A document is the result of a study when it is the result of the last step of
+ * the study.
+ *
+ * @param aType
+ * the document type
+ * @return true if documents of this type are result of a study.
+ * @see #isStepResult()
+ * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+ */
+ public boolean isStudyResult(DocumentType aType);
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+import org.hibernate.Hibernate;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.File;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.ProjectElement;
import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.StampRelation;
import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.Timestamp;
+import org.splat.dal.bo.som.ValidationStep;
+import org.splat.dal.bo.som.VersionsRelation;
import org.splat.dal.bo.som.Document.Properties;
import org.splat.dal.dao.som.DocumentDAO;
+import org.splat.dal.dao.som.DocumentTypeDAO;
+import org.splat.dal.dao.som.FileDAO;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
import org.splat.kernel.NotApplicableException;
+import org.splat.manox.Reader;
+import org.splat.manox.Toolbox;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.service.technical.ProjectSettingsServiceImpl;
import org.splat.service.technical.RepositoryService;
import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming;
+import org.splat.som.Revision;
import org.springframework.transaction.annotation.Transactional;
/**
*/
private RepositoryService _repositoryService;
/**
- * Injected document service.
+ * Injected document DAO.
*/
private DocumentDAO _documentDAO;
+ /**
+ * Injected document type DAO.
+ */
+ private DocumentTypeDAO _documentTypeDAO;
+ /**
+ * Injected file DAO.
+ */
+ private FileDAO _fileDAO;
/**
* {@inheritDoc}
*
* @see org.splat.service.DocumentService#initialize(org.splat.dal.bo.som.Document, org.splat.dal.bo.som.Document.Properties)
*/
+ @Transactional
public void initialize(Document aDoc, Properties dprop)
throws MissedPropertyException, InvalidPropertyException,
NotApplicableException {
return new java.io.File(path.append("/").toString());
}
+ /**
+ * Extract title and reference properties from the given file.
+ *
+ * @param file
+ * the file to parse
+ * @return the extracted properties
+ */
+ public Properties extractProperties(java.io.File file) {
+ Properties fprop = new Properties();
+ Reader tool = Toolbox.getReader(file);
+ String value;
+ if (tool != null)
+ try {
+ value = tool.extractProperty("title");
+ if (value != null)
+ fprop.setName(value);
+
+ value = tool.extractProperty("reference");
+ if (value != null)
+ fprop.setReference(value);
+ } catch (Exception e) {
+ }
+ return fprop;
+ }
+
+ /**
+ * Create "Converts" relation for the given document and the given format.
+ *
+ * @param aDoc
+ * the document
+ * @param format
+ * the format
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Document aDoc, String format) {
+ return attach(aDoc, format, null);
+ }
+
+ /**
+ * Create "Converts" relation for the given document, format and description.
+ *
+ * @param aDoc
+ * the document
+ * @param format
+ * the format
+ * @param description
+ * the description of the relation
+ * @return the created "Converts" relation
+ */
+ @Transactional
+ public ConvertsRelation attach(Document aDoc, String format,
+ String description) {
+ String path = aDoc.getRelativePath();
+ File export = new File(path + "." + format);
+ ConvertsRelation attach = new ConvertsRelation(aDoc, export,
+ description);
+
+ // RKV Session session = Database.getSession();
+ // RKV session.save(export);
+ // RKV session.save(attach);
+
+ getFileDAO().create(export);
+
+ // RKV aDoc.addRelation(attach); // Updates this
+ aDoc.getAllRelations().add(attach); // Updates this //RKV
+
+ return attach;
+ }
+
+ /**
+ * Build a reference (document id) for the given document in the given study basing on the given original document.
+ *
+ * @param aDoc
+ * the document to set set the new reference to
+ * @param scope
+ * the study
+ * @param lineage
+ * the original document
+ * @return true if the new reference is set
+ */
+ public boolean buildReferenceFrom(Document aDoc, ProjectElement scope,
+ Document lineage) {
+ if (aDoc.getProgressState() != ProgressState.inWORK)
+ return false;
+ Study owner = null;
+ Scenario context = null;
+ if (scope instanceof Study)
+ owner = (Study) scope;
+ else {
+ context = ((Scenario) scope);
+ owner = context.getOwnerStudy();
+ }
+ aDoc.setDid(lineage.getDid());
+ if (context != null && (lineage.isVersioned() || owner.shares(lineage))) {
+ aDoc.setVersion(new Revision(aDoc.getVersion()).setBranch(
+ context.getReference()).toString());
+ }
+ return true;
+ }
+
+ /**
+ * Build a reference (document id) for the given document in the given study.
+ *
+ * @param aDoc
+ * the document to set set the new reference to
+ * @param scope
+ * the study
+ * @return true if the new reference is set
+ */
+ public boolean buildReferenceFrom(Document aDoc, Study scope) {
+ if (aDoc.getProgressState() != ProgressState.inWORK
+ && aDoc.getProgressState() != ProgressState.EXTERN)
+ return false;
+ DecimalFormat tostring = new DecimalFormat(Document.suformat);
+
+ aDoc.setDid(aDoc.getDid().replace("%" + Document.suformat,
+ tostring.format(scope.getLastLocalIndex())));
+ return true;
+ }
+
+ /**
+ * Demote a document.
+ *
+ * @param aDoc
+ * the document to demote
+ * @return true if demoting succeeded
+ */
+ @Transactional
+ public boolean demote(Document aDoc) {
+ ValidationStep torem;
+
+ if (aDoc.getProgressState() == ProgressState.inCHECK) {
+ aDoc.setProgressState(ProgressState.inDRAFT);
+ torem = ValidationStep.REVIEW;
+ // This operation must not change the version number of documents.
+ // Consequently, inDRAFT documents may have a minor version number equal to zero.
+ } else if (aDoc.getProgressState() == ProgressState.inDRAFT) {
+ aDoc.setProgressState(ProgressState.inWORK);
+ torem = ValidationStep.PROMOTION;
+ } else {
+ return false;
+ }
+ for (Iterator<Relation> i = aDoc.getAllRelations().iterator(); i
+ .hasNext();) {
+ Relation link = i.next();
+ if (!(link instanceof StampRelation))
+ continue;
+ if (((StampRelation) link).getStampType() != torem)
+ continue;
+ i.remove();
+ break;
+ }
+ getDocumentDAO().update(aDoc);
+ return true;
+ }
+
+ /**
+ * Promote a document.
+ *
+ * @param aDoc
+ * the document to promote
+ * @param stamp
+ * the timestamp of the promotion
+ * @return true if promotion succeeded
+ */
+ @Transactional
+ public boolean promote(Document aDoc, Timestamp stamp) {
+ ProgressState newstate = null;
+
+ if (aDoc.getProgressState() == ProgressState.inWORK) {
+ newstate = ProgressState.inDRAFT; // Promotion to being reviewed
+ } else if (aDoc.getProgressState() == ProgressState.inDRAFT) {
+ newstate = ProgressState.inCHECK; // Promotion to approval
+ Revision myvers = new Revision(aDoc.getVersion());
+ if (myvers.isMinor()) {
+ aDoc.setVersion(myvers.incrementAs(newstate).toString());
+ // TODO: If my physical file is programatically editable, update its (property) version number
+ // ISSUE: What about attached files such as PDF if exist, should we remove them ?
+ }
+ } else if (aDoc.getProgressState() == ProgressState.inCHECK) {
+ newstate = ProgressState.APPROVED;
+ }
+ aDoc.setProgressState(newstate);
+ if (stamp != null) {
+ // RKV: aDoc.addRelation(stamp.getContext());
+ aDoc.getAllRelations().add(stamp.getContext());
+ }
+ getDocumentDAO().update(aDoc);
+ return true;
+ }
+
+ /**
+ * Increments the reference count of this document following its publication in a Study step.
+ *
+ * @param aDoc
+ * the document to hold
+ * @see #release()
+ */
+ @Transactional
+ public void hold(Document aDoc) {
+ aDoc.setCountag(aDoc.getCountag() + 1);
+ if (aDoc.isSaved()) {
+ getDocumentDAO().update(aDoc);
+ }
+ }
+
+ /**
+ * Decrements the reference count of this document following the removal of a Publication from a Study step.
+ *
+ * @param aDoc
+ * the document to release
+ * @see #hold()
+ */
+ @Transactional
+ public void release(Document aDoc) {
+ aDoc.setCountag(aDoc.getCountag() - 1);
+ if (aDoc.isSaved()) {
+ getDocumentDAO().update(aDoc);
+ }
+ }
+
+ /**
+ * Rename a document.
+ *
+ * @param aDoc
+ * the document to rename
+ * @param title
+ * the new document title
+ * @throws InvalidPropertyException
+ * if the new title is empty
+ */
+ @Transactional
+ public void rename(Document aDoc, String title)
+ throws InvalidPropertyException {
+ if (title.length() == 0)
+ throw new InvalidPropertyException("name");
+
+ Calendar current = Calendar.getInstance();
+ aDoc.setTitle(title);
+ aDoc.setLastModificationDate(current.getTime()); // Today
+ getDocumentDAO().update(aDoc);
+ }
+
+ /**
+ * Update a version of the given document.
+ *
+ * @param aDoc
+ * the document
+ * @param newvers
+ * the new version
+ */
+ public void updateAs(Document aDoc, Revision newvers) {
+ aDoc.setVersion(newvers.setBranch(aDoc.getVersion()).toString()); // Branch names are propagated by the versionning
+ ProgressState newstate = ProgressState.inCHECK;
+ if (newvers.isMinor())
+ newstate = ProgressState.inWORK;
+ aDoc.setProgressState(null); // Just to tell updateAs(state) to not increment the version number
+ updateAs(aDoc, newstate);
+ }
+
+ /**
+ * Update a state of the given document.
+ *
+ * @param aDoc
+ * the document
+ * @param state
+ * the new state
+ */
+ @Transactional
+ public void updateAs(Document aDoc, ProgressState state) {
+ Document previous = null;
+
+ // Set of version number
+ if (state == ProgressState.EXTERN) {
+ if (aDoc.getProgressState() != ProgressState.EXTERN)
+ aDoc.setVersion(null); // Strange use-case...
+ } else {
+ Revision myvers = new Revision(aDoc.getVersion());
+ if (!myvers.isNull()) { // Versionning context
+ for (Iterator<Relation> i = aDoc.getAllRelations().iterator(); i
+ .hasNext();) {
+ Relation link = i.next();
+ if (!link.getClass().equals(VersionsRelation.class))
+ continue;
+ previous = (Document) link.getTo(); // Versioned document
+ break;
+ }
+ }
+ if (aDoc.getProgressState() != null)
+ myvers.incrementAs(state); // Incrementation if the reversion number is not imposed
+ aDoc.setVersion(myvers.toString());
+ }
+ // Update this document and the previous version, if exit
+ if (previous != null) {
+ previous.setHistory(previous.getHistory() + 1);
+ getDocumentDAO().update(previous);
+ }
+ aDoc.setProgressState(state);
+ getDocumentDAO().update(aDoc);
+ }
+
+ // protected void upgrade () {
+ // -------------------------
+ // if (this.state != ProgressState.inWORK) return;
+ //
+ // Calendar current = Calendar.getInstance();
+ // for (Iterator<Relation> i=getAllRelations().iterator(); i.hasNext();) {
+ // Relation link = i.next();
+ // if (!link.getClass().equals(UsesRelation.class)) continue;
+ //
+ // Document used = (Document)link.getTo();
+ // if (!used.isVersioned()) continue;
+ // TODO: Update the uses relation
+ // }
+ // this.promote();
+ // this.lasdate = current.getTime(); // Today
+ // Database.getSession().update(this);
+ //
+ // TODO: Promote documents using this one
+ // }
+
+ /**
+ * Checks if documents of this type are result of a study. A document is the result of a study when it is the result of the last step of
+ * the study.
+ *
+ * @param aType
+ * the document type
+ * @return true if documents of this type are result of a study.
+ * @see #isStepResult()
+ * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+ */
+ public boolean isStudyResult(DocumentType aType) {
+ // -------------------------------
+ List<ProjectSettingsService.Step> step = getProjectSettings()
+ .getAllSteps();
+ ProjectSettingsService.Step lastep = step.get(step.size() - 1);
+ return (aType.isResultOf(lastep));
+ }
+
/**
* Get the studyService.
*
_repositoryService = repositoryService;
}
+ /**
+ * Get the documentTypeDAO.
+ *
+ * @return the documentTypeDAO
+ */
+ public DocumentTypeDAO getDocumentTypeDAO() {
+ return _documentTypeDAO;
+ }
+
+ /**
+ * Set the documentTypeDAO.
+ *
+ * @param documentTypeDAO
+ * the documentTypeDAO to set
+ */
+ public void setDocumentTypeDAO(DocumentTypeDAO documentTypeDAO) {
+ _documentTypeDAO = documentTypeDAO;
+ }
+
+ /**
+ * Get the fileDAO.
+ *
+ * @return the fileDAO
+ */
+ public FileDAO getFileDAO() {
+ return _fileDAO;
+ }
+
+ /**
+ * Set the fileDAO.
+ *
+ * @param fileDAO
+ * the fileDAO to set
+ */
+ public void setFileDAO(FileDAO fileDAO) {
+ _fileDAO = fileDAO;
+ }
+
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
* @version $Revision$
*****************************************************************************/
-package org.splat.service;
+package org.splat.service;
+
+import java.util.List;
import org.splat.dal.bo.som.DocumentType;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
+import org.splat.service.technical.ProjectSettingsService;
/**
- * @author RKV
+ * Document type service interface.
*
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public interface DocumentTypeService {
/**
- * Checks if documents of this type are result of a study.
- * A document is the result of a study when it is the result of the last step of the study.
+ * Get all document types from the database.
+ *
+ * @return the list of all document types
+ */
+ public List<DocumentType> selectAllTypes();
+
+ /**
+ * Find all result document types.
+ *
+ * @return the list of found types
+ */
+ public List<DocumentType> selectResultTypes();
+
+ /**
+ * Get document type by the given type name.
+ *
+ * @param name
+ * the type name
+ * @return the found document type
+ */
+ public DocumentType selectType(String name);
+
+ /**
+ * Get document type by the given id.
+ *
+ * @param index
+ * the id
+ * @return the found document type
+ */
+ public DocumentType selectType(long index);
+
+ /**
+ * Create a new document type.
+ *
+ * @param tprop
+ * properties of the new document type
+ * @return the created document type
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ */
+ public DocumentType createType(DocumentType.Properties tprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException;
+
+ /**
+ * Get document types applicable for the given study step.
*
- * @return true if documents of this type are result of a study.
- * @see #isStepResult()
- * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+ * @param step
+ * the step (study activity)
+ * @return the list of found document types
*/
- public boolean isStudyResult (DocumentType aType);
+ public List<DocumentType> selectTypesOf(ProjectSettingsService.Step step);
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
* @version $Revision$
*****************************************************************************/
-package org.splat.service;
+package org.splat.service;
+import java.util.Iterator;
import java.util.List;
+import org.hibernate.Hibernate;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.dao.som.DocumentTypeDAO;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.MultiplyDefinedException;
import org.splat.service.technical.ProjectSettingsService;
+import org.springframework.transaction.annotation.Transactional;
/**
- * @author RKV
+ * Document type service implementation.
*
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public class DocumentTypeServiceImpl implements DocumentTypeService {
- private ProjectSettingsService _projectSettingsService;
+ /**
+ * Injected document type DAO.
+ */
+ private DocumentTypeDAO _documentTypeDAO;
+
+ /**
+ * Get all document types from the database.
+ *
+ * @return the list of all document types
+ */
+ @Transactional(readOnly = true)
+ public List<DocumentType> selectAllTypes() {
+ List<DocumentType> types = getDocumentTypeDAO().getAll();
+ for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
+ Hibernate.initialize(i.next()); // Supposed fetching document types
+ }
+ return types;
+ }
/**
- * Checks if documents of this type are result of a study.
- * A document is the result of a study when it is the result of the last step of the study.
+ * Find all result document types.
*
- * @return true if documents of this type are result of a study.
- * @see #isStepResult()
- * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+ * @return the list of found types
*/
- public boolean isStudyResult (DocumentType aType) {
- // -------------------------------
- List<ProjectSettingsService.Step> step = getProjectSettings().getAllSteps();
- ProjectSettingsService.Step lastep = step.get( step.size()-1 );
- return (aType.isResultOf(lastep));
- }
+ @Transactional(readOnly = true)
+ public List<DocumentType> selectResultTypes() {
+ return getDocumentTypeDAO().getFilteredList(
+ Restrictions.isNotNull("result"), Order.asc("result"));
+ }
/**
- * @return
+ * Get document type by the given type name.
+ *
+ * @param name
+ * the type name
+ * @return the found document type
*/
- public ProjectSettingsService getProjectSettings() {
- return _projectSettingsService;
+ @Transactional(readOnly = true)
+ public DocumentType selectType(String name) {
+ return getDocumentTypeDAO().findByCriteria(
+ Restrictions.eq("name", name));
}
- public void setProjectSettings(
- ProjectSettingsService projectSettingsService) {
- _projectSettingsService = projectSettingsService;
+ /**
+ * Get document type by the given id.
+ *
+ * @param index
+ * the id
+ * @return the found document type
+ */
+ @Transactional(readOnly = true)
+ public DocumentType selectType(long index) {
+ return getDocumentTypeDAO().get(index);
}
+ /**
+ * Create a new document type.
+ *
+ * @param tprop
+ * properties of the new document type
+ * @return the created document type
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ */
+ @Transactional
+ public DocumentType createType(DocumentType.Properties tprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException {
+ // TODO: Check for duplicate definition
+ DocumentType type = new DocumentType(tprop);
+ getDocumentTypeDAO().create(type);
+ return type;
+ }
+
+ /**
+ * Get document types applicable for the given study step.
+ *
+ * @param step
+ * the step (study activity)
+ * @return the list of found document types
+ */
+ @Transactional(readOnly = true)
+ public List<DocumentType> selectTypesOf(ProjectSettingsService.Step step) {
+ Integer number = step.getNumber();
+ String sampleStr = new StringBuffer("%-").append(number).append("-%")
+ .toString();
+ List<DocumentType> types = getDocumentTypeDAO().getFilteredList(
+ Restrictions.like("step", sampleStr));
+ for (Iterator<DocumentType> i = types.iterator(); i.hasNext();) {
+ Hibernate.initialize(i.next()); // For fetching document types
+ }
+ return types;
+ }
+
+ /**
+ * Get the documentTypeDAO.
+ *
+ * @return the documentTypeDAO
+ */
+ public DocumentTypeDAO getDocumentTypeDAO() {
+ return _documentTypeDAO;
+ }
+
+ /**
+ * Set the documentTypeDAO.
+ *
+ * @param documentTypeDAO
+ * the documentTypeDAO to set
+ */
+ public void setDocumentTypeDAO(DocumentTypeDAO documentTypeDAO) {
+ _documentTypeDAO = documentTypeDAO;
+ }
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
package org.splat.service;
+import java.util.List;
+
import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.ProgressState;
import org.splat.kernel.InvalidPropertyException;
/**
- * @author RKV
+ * Knowledge element service interface.
*
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public interface KnowledgeElementService {
+ /**
+ * Approve the knowledge element.
+ *
+ * @param knowledgeElement
+ * the knowledge element to approve
+ * @return true if approving succeeded
+ */
public boolean approve(KnowledgeElement knowledgeElement);
+ /**
+ * Demote the knowledge element.
+ *
+ * @param knowledgeElement
+ * the knowledge element to demote
+ * @return true if demoting succeeded
+ */
public boolean demote(KnowledgeElement knowledgeElement);
+ /**
+ * Promote the knowledge element.
+ *
+ * @param knowledgeElement
+ * the knowledge element to promote
+ * @return true if promotion succeeded
+ */
public boolean promote(KnowledgeElement knowledgeElement);
+ /**
+ * Rename the knowledge element.
+ *
+ * @param knowledgeElement
+ * the knowledge element to rename
+ * @param title
+ * the new title of the knowledge element
+ * @throws InvalidPropertyException
+ * if renaming is failed
+ */
public void rename(KnowledgeElement knowledgeElement, String title)
throws InvalidPropertyException;
+ /**
+ * Get a knowledge element by its id.
+ *
+ * @param index
+ * the knowledge element id
+ * @return the found knowledge element
+ */
public KnowledgeElement selectKnowledgeElement(long index);
+
+ /**
+ * Update the description of the knowledge element.
+ *
+ * @param kelm
+ * the knoledge element to update
+ * @param description
+ * the new description
+ */
+ public void update(KnowledgeElement kelm, String description);
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
* @version $Revision$
*****************************************************************************/
-package org.splat.service;
+package org.splat.service;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.ProgressState;
-import org.splat.dal.dao.kernel.GenericDAO;
-import org.splat.dal.dao.som.Database;
import org.splat.dal.dao.som.KnowledgeElementDAO;
import org.splat.kernel.InvalidPropertyException;
+import org.splat.log.AppLogger;
import org.splat.service.technical.IndexService;
+import org.springframework.transaction.annotation.Transactional;
/**
- * @author RKV
- *
+ * Knowledge element service implementation.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public class KnowledgeElementServiceImpl implements KnowledgeElementService {
+ /**
+ * The logger for the service.
+ */
+ public final static AppLogger logger = AppLogger
+ .getLogger(KnowledgeElementServiceImpl.class);
+
+ /**
+ * Injected index service.
+ */
private IndexService _indexService;
+ /**
+ * Injected knowledge element DAO.
+ */
private KnowledgeElementDAO _knowledgeElementDAO;
+ /**
+ * Injected study service.
+ */
+ private StudyService _studyService;
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#approve(org.splat.dal.bo.som.KnowledgeElement)
+ */
public boolean approve(KnowledgeElement knowledgeElement) {
- // -------------------------
if (knowledgeElement.getProgressState() != ProgressState.inCHECK)
return false;
knowledgeElement.setProgressState(ProgressState.APPROVED);
return update(knowledgeElement);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#demote(org.splat.dal.bo.som.KnowledgeElement)
+ */
public boolean demote(KnowledgeElement knowledgeElement) {
- // ------------------------
if (knowledgeElement.getProgressState() != ProgressState.APPROVED
&& knowledgeElement.getProgressState() != ProgressState.inCHECK)
return false;
return update(knowledgeElement);
}
+ /**
+ * Update knowledge element in the database and in the lucene index.
+ * @param knowledgeElement the knowledge element to update
+ * @return true if updating succeeded
+ */
protected boolean update(KnowledgeElement knowledgeElement) {
- // -----------------------------
try {
getKnowledgeElementDAO().update(knowledgeElement);
getIndexService().update(knowledgeElement);
return true;
} catch (Exception error) {
- // logger.error("Unable to re-index the knowledge '" + getIndex() + "', reason:", error);
+ logger.error("Unable to re-index the knowledge '"
+ + knowledgeElement.getIndex() + "', reason:", error);
return false;
}
}
- public boolean promote (KnowledgeElement knowledgeElement) {
-// -------------------------
- if (knowledgeElement.getProgressState() != ProgressState.inDRAFT) return false;
- knowledgeElement.setProgressState(ProgressState.inCHECK);
- return update(knowledgeElement);
- }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#promote(org.splat.dal.bo.som.KnowledgeElement)
+ */
+ public boolean promote(KnowledgeElement knowledgeElement) {
+ // -------------------------
+ if (knowledgeElement.getProgressState() != ProgressState.inDRAFT)
+ return false;
+ knowledgeElement.setProgressState(ProgressState.inCHECK);
+ return update(knowledgeElement);
+ }
- public void rename (KnowledgeElement knowledgeElement, String title) throws InvalidPropertyException {
- if (title.length() == 0) throw new InvalidPropertyException("name");
- knowledgeElement.setTitle(title);
- update(knowledgeElement);
- }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#rename(org.splat.dal.bo.som.KnowledgeElement, java.lang.String)
+ */
+ public void rename(KnowledgeElement knowledgeElement, String title)
+ throws InvalidPropertyException {
+ if (title.length() == 0)
+ throw new InvalidPropertyException("name");
+ knowledgeElement.setTitle(title);
+ update(knowledgeElement);
+ }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.KnowledgeElementService#selectKnowledgeElement(long)
+ */
public KnowledgeElement selectKnowledgeElement(long index) {
- // -----------------------------------------------------------------
- StringBuffer query = new StringBuffer(
- "from KnowledgeElement where rid='").append(index).append("'");
- KnowledgeElement result = (KnowledgeElement) Database.getSession()
- .createQuery(query.toString()).uniqueResult();
-
- result.getOwnerScenario().getOwnerStudy().loadWorkflow();
+ KnowledgeElement result = getKnowledgeElementDAO().get(index);
+ getStudyService().loadWorkflow(result.getOwnerScenario().getOwnerStudy());
return result;
}
/**
- * @return
+ * Update the description of the knowledge element.
+ *
+ * @param kelm
+ * the knoledge element to update
+ * @param description
+ * the new description
+ */
+ @Transactional
+ public void update(KnowledgeElement kelm, String description) {
+ kelm.setValue(description.trim());
+ if (!kelm.getValue().startsWith("<p>")) {
+ StringBuffer text = new StringBuffer("<p>");
+ int index = kelm.getValue().indexOf("<p>");
+ if (index > 0) {
+ kelm.setValue(text.append(kelm.getValue().substring(0, index))
+ .append("</p>")
+ .append(kelm.getValue().substring(index)).toString());
+ } else {
+ kelm.setValue(text.append(kelm.getValue()).append("</p>")
+ .toString());
+ }
+ }
+ getKnowledgeElementDAO().update(kelm); // No need to update the Lucene index
+ }
+
+ /**
+ * Get the indexService.
+ *
+ * @return the indexService
*/
public IndexService getIndexService() {
return _indexService;
}
+ /**
+ * Set the indexService.
+ *
+ * @param indexService
+ * the indexService to set
+ */
public void setIndexService(IndexService indexService) {
_indexService = indexService;
}
/**
- * @return
+ * Get the knowledgeElementDAO.
+ *
+ * @return the knowledgeElementDAO
*/
public KnowledgeElementDAO getKnowledgeElementDAO() {
return _knowledgeElementDAO;
}
-
- public void setKnowledgeElementDAO(KnowledgeElementDAO knowledgeElementDAO) {
+
+ /**
+ * Set the knowledgeElementDAO.
+ *
+ * @param knowledgeElementDAO
+ * the knowledgeElementDAO to set
+ */
+ public void setKnowledgeElementDAO(KnowledgeElementDAO knowledgeElementDAO) {
_knowledgeElementDAO = knowledgeElementDAO;
}
+
+ /**
+ * Get the studyService.
+ * @return the studyService
+ */
+ public StudyService getStudyService() {
+ return _studyService;
+ }
+
+ /**
+ * Set the studyService.
+ * @param studyService the studyService to set
+ */
+ public void setStudyService(StudyService studyService) {
+ _studyService = studyService;
+ }
}
--- /dev/null
+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 19.10.2012
+ * @author $Author$
+ * @version $Revision$
+ * @copyright OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service;
+
+import java.util.List;
+
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.ProgressState;
+
+/**
+ * The service interface for working with knowledge element types.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public interface KnowledgeElementTypeService {
+
+ /**
+ * Find a knowledge type by its name.
+ *
+ * @param name
+ * the knowledge type name
+ * @return the found knowledge type
+ */
+ public KnowledgeElementType selectType(String name);
+
+ /**
+ * Create a knowledge element type with the given name.
+ *
+ * @param name
+ * the new type name
+ * @return the created knowledge type
+ */
+ public KnowledgeElementType createType(String name);
+
+ /**
+ * Get all knowledge types from the database.
+ *
+ * @return the list of all knowledge types
+ */
+ public List<KnowledgeElementType> selectAllTypes();
+
+ /**
+ * Get knowledge types which have the given progress state.
+ *
+ * @param state
+ * the progress state
+ * @return the list of found knowledge types
+ */
+ public List<KnowledgeElementType> selectTypesWhere(ProgressState state);
+
+ /**
+ * Get a knowledge type by its id.
+ *
+ * @param index
+ * the id of a knowledge type
+ * @return the found knowledge type
+ */
+ public KnowledgeElementType selectType(long index);
+}
--- /dev/null
+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 19.10.2012
+ * @author $Author$
+ * @version $Revision$
+ * @copyright OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service;
+
+import java.util.List;
+
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.dao.som.KnowledgeElementTypeDAO;
+
+/**
+ * KnowledgeElementTypeService implementation for working with knowledge types.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class KnowledgeElementTypeServiceImpl implements
+ KnowledgeElementTypeService {
+
+ /**
+ * Injected knowledge element type DAO.
+ */
+ private KnowledgeElementTypeDAO _knowledgeElementTypeDAO;
+
+ /**
+ * Create a knowledge element type with the given name.
+ *
+ * @param name
+ * the new type name
+ * @return the created knowledge type
+ */
+ public KnowledgeElementType createType(String name) {
+ // TODO: Check for duplicate definition
+ KnowledgeElementType kelt = new KnowledgeElementType(name);
+ getKnowledgeElementTypeDAO().create(kelt);
+ return kelt;
+ }
+
+ /**
+ * Get all knowledge types from the database.
+ *
+ * @return the list of all knowledge types
+ */
+ public List<KnowledgeElementType> selectAllTypes() {
+ return getKnowledgeElementTypeDAO().getAll(Order.asc("rid"));
+ }
+
+ /**
+ * Get knowledge types which have the given progress state.
+ *
+ * @param state
+ * the progress state
+ * @return the list of found knowledge types
+ */
+ public List<KnowledgeElementType> selectTypesWhere(ProgressState state) {
+ return getKnowledgeElementTypeDAO().getFilteredList(
+ Restrictions.eq("state", state), Order.asc("rid"));
+ }
+
+ /**
+ * Find a knowledge type by its name.
+ *
+ * @param name
+ * the knowledge type name
+ * @return the found knowledge type
+ */
+ public KnowledgeElementType selectType(String name) {
+ return getKnowledgeElementTypeDAO().findByCriteria(
+ Restrictions.eq("name", name));
+ }
+
+ /**
+ * Get a knowledge type by its id.
+ *
+ * @param index
+ * the id of a knowledge type
+ * @return the found knowledge type
+ */
+ public KnowledgeElementType selectType(long index) {
+ return getKnowledgeElementTypeDAO().get(index);
+ }
+
+ /**
+ * Get the knowledgeElementTypeDAO.
+ *
+ * @return the knowledgeElementTypeDAO
+ */
+ public KnowledgeElementTypeDAO getKnowledgeElementTypeDAO() {
+ return _knowledgeElementTypeDAO;
+ }
+
+ /**
+ * Set the knowledgeElementTypeDAO.
+ *
+ * @param knowledgeElementTypeDAO
+ * the knowledgeElementTypeDAO to set
+ */
+ public void setKnowledgeElementTypeDAO(
+ KnowledgeElementTypeDAO knowledgeElementTypeDAO) {
+ _knowledgeElementTypeDAO = knowledgeElementTypeDAO;
+ }
+
+}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File Id:
* Creation date 02.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 02.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 07.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 07.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
import java.io.FileNotFoundException;
import java.util.Date;
+import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.bo.som.ProjectElement;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.Timestamp;
+import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.NotApplicableException;
import org.splat.som.DocumentRights;
import org.splat.som.Revision;
*/
public void saveAs(Publication aPublication, Revision newvers)
throws FileNotFoundException, NotApplicableException;
+
+ /**
+ * Rename the published document.
+ *
+ * @param aPublication
+ * the publication of the document
+ * @param title
+ * the new document title
+ * @throws InvalidPropertyException
+ * if the new title is empty
+ */
+ public void rename(Publication aPublication, String title)
+ throws InvalidPropertyException;
+
+ /**
+ * Create "Converts" relation for the given document publication and format.
+ *
+ * @param aPublication
+ * the document publication
+ * @param format
+ * the format
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Publication aPublication, String format);
+
+ /**
+ * Create "Converts" relation for the given document publication, format and description.
+ *
+ * @param aPublication
+ * the document publication
+ * @param format
+ * the format
+ * @param description
+ * the description of the relation
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Publication aPublication, String format,
+ String description);
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
import java.util.Iterator;
import java.util.List;
-import org.hibernate.Session;
import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.bo.som.Timestamp;
import org.splat.dal.bo.som.ValidationCycle;
import org.splat.dal.bo.som.ValidationStep;
-import org.splat.dal.dao.som.Database;
+import org.splat.dal.dao.som.ProjectElementDAO;
+import org.splat.dal.dao.som.PublicationDAO;
+import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.NotApplicableException;
import org.splat.manox.Reader;
import org.splat.manox.Toolbox;
import org.splat.som.Revision;
import org.splat.som.Step;
+import org.springframework.transaction.annotation.Transactional;
/**
* Publication service implementation.
*/
private StudyService _studyService;
/**
- * Injected study service.
+ * Injected step service.
*/
private StepService _stepService;
/**
- * Injected study service.
+ * Injected document service.
*/
- private DocumentTypeService _documentTypeService;
+ private DocumentService _documentService;
/**
- * Injected study service.
+ * Injected project element service.
*/
private ProjectElementService _projectElementService;
/**
* Injected simulation context service.
*/
private SimulationContextService _simulationContextService;
+ /**
+ * Injected publication DAO.
+ */
+ private PublicationDAO _publicationDAO;
+ /**
+ * Injected project element DAO.
+ */
+ private ProjectElementDAO _projectElementDAO;
/**
* {@inheritDoc}
* @see org.splat.service.PublicationService#approve(org.splat.dal.bo.som.Publication, java.util.Date)
*/
public Timestamp approve(Publication aPublication, Date adate) {
- // -------------------------------------
if (aPublication.isOutdated())
return null;
else if (aPublication.value().getProgressState() != ProgressState.inCHECK)
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- ValidationCycle cycle = owner.getValidationCycleOf(type);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(owner,
+ type);
User approver = cycle.getActor(ValidationStep.APPROVAL);
Timestamp stamp = new Timestamp(ValidationStep.APPROVAL, aPublication
.value(), approver, adate);
- if (!aPublication.value().promote(stamp))
+ if (!getDocumentService().promote(aPublication.value(), stamp))
return null;
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() == ProgressState.inCHECK)
getStudyService().promote(owner);
return stamp; // Hoping that promotion of the study succeeded
* @see org.splat.service.PublicationService#demote(org.splat.dal.bo.som.Publication)
*/
public boolean demote(Publication aPublication) {
- // ------------------------
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
if (aPublication.value().getProgressState() == ProgressState.inCHECK) {
- ValidationCycle cycle = owner.getValidationCycleOf(type);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ owner, type);
if (cycle.enables(ValidationStep.REVIEW)) {
- if (!aPublication.value().demote())
+ if (!getDocumentService().demote(aPublication.value()))
return false;
} else {
- if (!aPublication.value().demote())
+ if (!getDocumentService().demote(aPublication.value()))
return false;
- aPublication.value().demote();
+ getDocumentService().demote(aPublication.value());
}
} else if (aPublication.value().getProgressState() == ProgressState.inDRAFT) {
- if (!aPublication.value().demote())
+ if (!getDocumentService().demote(aPublication.value()))
return false;
} else {
return false;
}
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() != ProgressState.inWORK)
getStudyService().demote(owner);
return true;
* @see org.splat.service.PublicationService#invalidate(org.splat.dal.bo.som.Publication)
*/
public boolean invalidate(Publication aPublication) {
- // ----------------------------
if (aPublication.value().getProgressState() != ProgressState.inCHECK)
return false;
- if (!aPublication.value().demote()) // Removes the reviewer if this document is In-Check
+ if (!getDocumentService().demote(aPublication.value())) // Removes the reviewer if this document is In-Check
return false;
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() == ProgressState.inCHECK)
getStudyService().demote(owner);
return true;
else {
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- ValidationCycle cycle = owner.getValidationCycleOf(type);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ owner, type);
User promoter = cycle.getActor(ValidationStep.PROMOTION);
if (promoter == null)
promoter = getInvolvedStep(aPublication).getActor();
Timestamp stamp = new Timestamp(ValidationStep.PROMOTION,
aPublication.value(), promoter, pdate);
- if (!aPublication.value().promote(stamp)) // Promotion to being reviewed
+ if (!getDocumentService().promote(aPublication.value(), stamp)) // Promotion to being reviewed
return null;
if (!cycle.enables(ValidationStep.REVIEW)) {
- aPublication.value().promote(null);
+ getDocumentService().promote(aPublication.value(), null);
}
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() == ProgressState.inWORK)
getStudyService().promote(owner);
return stamp; // Hoping that promotion of the study succeeded
DocumentType type = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- ValidationCycle cycle = owner.getValidationCycleOf(type);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(owner,
+ type);
User reviewer = cycle.getActor(ValidationStep.REVIEW);
Timestamp stamp = new Timestamp(ValidationStep.REVIEW, aPublication
.value(), reviewer, rdate);
- if (!aPublication.value().promote(stamp))
+ if (!getDocumentService().promote(aPublication.value(), stamp))
return null;
- if (getDocumentTypeService().isStudyResult(type)
+ if (getDocumentService().isStudyResult(type)
&& owner.getProgressState() == ProgressState.inDRAFT)
getStudyService().promote(owner);
return stamp; // Hoping that promotion of the study succeeded
* @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.som.Revision)
* @deprecated
*/
+ @Transactional
public void saveAs(Publication aPublication, Revision newvers)
throws FileNotFoundException, NotApplicableException {
- // -------------------------------------
if (aPublication.value().isUndefined())
throw new NotApplicableException(
"Cannot save a Publication object refering an undefined Document");
if (!aPublication.value().getSourceFile().exists())
throw new FileNotFoundException();
- Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
- aPublication.value().updateAs(newvers); // May change the branch name of given revision
+ getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
+ getDocumentService().updateAs(aPublication.value(), newvers); // May change the branch name of given revision
updateOwner(aPublication);
}
*
* @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProgressState)
*/
+ @Transactional
public void saveAs(Publication aPublication, ProgressState state)
throws FileNotFoundException, NotApplicableException {
- // ----------------------------------------
if (aPublication.value().isUndefined())
throw new NotApplicableException(
"Cannot save a Publication object refering an undefined Document");
throw new FileNotFoundException();
if (state == ProgressState.inWORK || state == ProgressState.EXTERN) {
- Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
+ getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
// hascode
- aPublication.value().updateAs(state);
+ getDocumentService().updateAs(aPublication.value(), state);
} else {
DocumentType mytype = aPublication.value().getType();
Study owner = aPublication.getOwnerStudy();
- ValidationCycle cycle = owner.getValidationCycleOf(mytype);
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ owner, mytype);
boolean review = cycle.enables(ValidationStep.REVIEW);
if (!(state == ProgressState.inDRAFT && review)
&& !(state == ProgressState.inCHECK && !review)) {
"Cannot save a result document in " + state.toString()
+ " state");
}
- Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
+ getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
// hascode
- aPublication.value().updateAs(ProgressState.inWORK);
+ getDocumentService().updateAs(aPublication.value(),
+ ProgressState.inWORK);
promote(aPublication, aPublication.value()
.getLastModificationDate()); // Promotes to the appropriate state in accordance to the validation cycle
* @param aPublication
* the document publication
*/
+ @Transactional
private void updateOwner(Publication aPublication) {
- Session session = Database.getSession();
Step step = getInvolvedStep(aPublication);
// Update of involved step
Document previous = aPublication.value().getPreviousVersion();
if (previous != null) {
Publication oldoc = step.getDocument(previous.getIndex());
- boolean done = step.remove(oldoc); // Decrements the configuration tag count of document
+ boolean done = getStepService().remove(step, oldoc); // Decrements the configuration tag count of document
if (done)
- session.delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object
+ getPublicationDAO().delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object
}
- step.add(aPublication); // Increments the configuration tag count of document
+ getStepService().add(step, aPublication); // Increments the configuration tag count of document
// Import the document properties and update of the study
forwardProperties(aPublication, aPublication.value().getSourceFile()
.asFile(), step);
- session.update(aPublication.getOwner());
+ getProjectElementDAO().update(aPublication.getOwner());
}
/**
*/
private void forwardProperties(Publication aPublication, java.io.File from,
Step to) {
- // -----------------------------------------------------------
Reader tool = Toolbox.getReader(from);
if (tool == null)
return; // No properties extractor available for this type of document
return aPublication.getStep();
}
+ /**
+ * Create "Converts" relation for the given document publication and format.
+ *
+ * @param aPublication
+ * the document publication
+ * @param format
+ * the format
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Publication aPublication, String format) {
+ return getDocumentService().attach(aPublication.value(), format);
+ }
+
+ /**
+ * Create "Converts" relation for the given document publication, format and description.
+ *
+ * @param aPublication
+ * the document publication
+ * @param format
+ * the format
+ * @param description
+ * the description of the relation
+ * @return the created "Converts" relation
+ */
+ public ConvertsRelation attach(Publication aPublication, String format,
+ String description) {
+ return getDocumentService().attach(aPublication.value(), format,
+ description);
+ }
+
+ /**
+ * Rename the published document.
+ *
+ * @param aPublication
+ * the publication of the document
+ * @param title
+ * the new document title
+ * @throws InvalidPropertyException
+ * if the new title is empty
+ */
+ public void rename(Publication aPublication, String title)
+ throws InvalidPropertyException {
+ getDocumentService().rename(aPublication.value(), title);
+ }
+
/**
* Get the projectElementService.
*
/**
* Get the studyService.
+ *
* @return the studyService
*/
public StudyService getStudyService() {
/**
* Set the studyService.
- * @param studyService the studyService to set
+ *
+ * @param studyService
+ * the studyService to set
*/
public void setStudyService(StudyService studyService) {
_studyService = studyService;
/**
* Get the stepService.
+ *
* @return the stepService
*/
public StepService getStepService() {
/**
* Set the stepService.
- * @param stepService the stepService to set
+ *
+ * @param stepService
+ * the stepService to set
*/
public void setStepService(StepService stepService) {
_stepService = stepService;
}
/**
- * Get the documentTypeService.
- * @return the documentTypeService
+ * Get the documentService.
+ *
+ * @return the documentService
+ */
+ public DocumentService getDocumentService() {
+ return _documentService;
+ }
+
+ /**
+ * Set the documentService.
+ *
+ * @param documentService
+ * the documentService to set
+ */
+ public void setDocumentService(DocumentService documentService) {
+ _documentService = documentService;
+ }
+
+ /**
+ * Get the publicationDAO.
+ *
+ * @return the publicationDAO
+ */
+ public PublicationDAO getPublicationDAO() {
+ return _publicationDAO;
+ }
+
+ /**
+ * Set the publicationDAO.
+ *
+ * @param publicationDAO
+ * the publicationDAO to set
*/
- public DocumentTypeService getDocumentTypeService() {
- return _documentTypeService;
+ public void setPublicationDAO(PublicationDAO publicationDAO) {
+ _publicationDAO = publicationDAO;
}
/**
- * Set the documentTypeService.
- * @param documentTypeService the documentTypeService to set
+ * Get the projectElementDAO.
+ *
+ * @return the projectElementDAO
+ */
+ public ProjectElementDAO getProjectElementDAO() {
+ return _projectElementDAO;
+ }
+
+ /**
+ * Set the projectElementDAO.
+ *
+ * @param projectElementDAO
+ * the projectElementDAO to set
*/
- public void setDocumentTypeService(DocumentTypeService documentTypeService) {
- _documentTypeService = documentTypeService;
+ public void setProjectElementDAO(ProjectElementDAO projectElementDAO) {
+ _projectElementDAO = projectElementDAO;
}
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
*/
public interface ScenarioService {
+ /**
+ * Add a new scenario to the study.
+ *
+ * @param aStudy
+ * the study
+ * @param sprop
+ * scenario properties
+ * @return the added scenario
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws MultiplyDefinedException
+ * if some property occurs several times
+ */
+ public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException;
+
/**
* Add a new knowledge element to the scenario.
*
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
import org.apache.log4j.Logger;
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.Study;
import org.splat.dal.dao.som.KnowledgeElementDAO;
import org.splat.dal.dao.som.ScenarioDAO;
+import org.splat.dal.dao.som.StudyDAO;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
+import org.splat.kernel.UserDirectory;
import org.splat.service.technical.IndexService;
import org.splat.som.Step;
import org.springframework.transaction.annotation.Transactional;
* Injected step service.
*/
private StepService _stepService;
+ /**
+ * Injected study service.
+ */
+ private StudyService _studyService;
/**
* Injected publication service.
*/
*/
private ScenarioDAO _scenarioDAO;
+ /**
+ * Injected study DAO.
+ */
+ private StudyDAO _studyDAO;
+
+ /**
+ * Injected knowledge element service.
+ */
+ private KnowledgeElementTypeService _knowledgeElementTypeService;
+
/**
* Get the projectElementService.
*
public KnowledgeElement addKnowledgeElement(Scenario aScenario,
KnowledgeElement.Properties kprop) throws MissedPropertyException,
InvalidPropertyException, MultiplyDefinedException {
- KnowledgeElement kelm = new KnowledgeElement(kprop
- .setOwnerScenario(aScenario));
+ KnowledgeElement kelm = null;
try {
+ // Attach the detached scenario to the new hibernate session.
+ aScenario = getScenarioDAO().merge(aScenario); // RKV
+ kelm = new KnowledgeElement(kprop.setOwnerScenario(aScenario));
getKnowledgeElementDAO().create(kelm);
// RKV: commented because of BatchUpdateException during creation of a new study: session.flush(); //RKV
// Update of my persistent data
- aScenario.getKnowledgeElements().add(kelm);
+ // RKV aScenario.getKnowledgeElements().add(kelm);
+ // RKV getKnowledgeElementDAO().flush();
// RKV: commented because of NullPointerException during creation of a new study: session.merge(aScenario); //RKV
// Update of my transient data
List<KnowledgeElement> known = aScenario
.getKnowledgeElementsOf(kelm.getType()); // Initializes this.known, if not yet done
- known.add(kelm);
+ // RKV: knowledge is already added into persistent set and "known" is constructed from it in the above call: known.add(kelm);
if (kelm.getType().equals("usecase")) {
aScenario.setUcase(kelm);
} else if (aScenario.getKnowledgeElementsList() != null) { // If null, knowl will be initialized when needed
* @see org.splat.service.ScenarioService#checkout(org.splat.dal.bo.som.Scenario, org.splat.dal.bo.kernel.User)
*/
public boolean checkout(Scenario aScenario, User user) {
- if (!aScenario.getOwnerStudy().isStaffedBy(user))
+ if (!getStudyService().isStaffedBy(aScenario.getOwnerStudy(), user))
return false;
aScenario.setUser(user);
Publication doc = getPublicationService().copy(j.next(),
scenario); // Creation of a new reference to the document
// Database.getSession().save(doc); Publications MUST be saved later through cascading when saving the scenario
- to[i].add(doc);
+ getStepService().add(to[i], doc);
}
List<SimulationContext> ctex = step.getAllSimulationContexts();
for (Iterator<SimulationContext> j = ctex.iterator(); j.hasNext();) {
return notempty;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StudyService#addScenario(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Scenario.Properties)
+ */
+ @Transactional
+ public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
+ throws MissedPropertyException, InvalidPropertyException,
+ MultiplyDefinedException {
+ if (sprop.getManager() == null)
+ sprop.setManager(aStudy.getAuthor());
+
+ Scenario scenario = new Scenario(sprop.setOwnerStudy(aStudy));
+ if (sprop.getBaseStep() != null)
+ copyContentsUpTo(scenario, sprop.getBaseStep());
+ Scenario previous = sprop.getInsertAfter();
+
+ if (previous == null) {
+ aStudy.getScenariiList().add(scenario);
+ } else {
+ aStudy.getScenariiList().add(
+ aStudy.getScenariiList().indexOf(previous) + 1, scenario);
+ }
+ getStudyDAO().update(aStudy); // No need to update the Lucene index
+ getScenarioDAO().create(scenario); // Must be done after updating this study because of the back reference to the study
+ if (sprop.getBaseStep() != null) {
+ // No need to update the Knowledge Element index as Knowledge Elements are not copied
+ scenario.refresh(); // Because saving the scenario changes the hashcode of copied Publications
+ }
+ KnowledgeElementType ucase = getKnowledgeElementTypeService().selectType(
+ "usecase");
+ KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
+ User admin = UserDirectory.selectUser(1); // First user created when creating the database
+ kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue(
+ scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of
+ // knowledges
+ addKnowledgeElement(scenario, kprop);
+ return scenario;
+ }
+
/**
* Get the knowledgeElementDAO.
*
_scenarioDAO = scenarioDAO;
}
+ /**
+ * Get the studyDAO.
+ *
+ * @return the studyDAO
+ */
+ public StudyDAO getStudyDAO() {
+ return _studyDAO;
+ }
+
+ /**
+ * Set the studyDAO.
+ *
+ * @param studyDAO
+ * the studyDAO to set
+ */
+ public void setStudyDAO(StudyDAO studyDAO) {
+ _studyDAO = studyDAO;
+ }
+
+ /**
+ * Get the knowledgeElementTypeService.
+ *
+ * @return the knowledgeElementTypeService
+ */
+ public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+ return _knowledgeElementTypeService;
+ }
+
+ /**
+ * Set the knowledgeElementTypeService.
+ *
+ * @param knowledgeElementTypeService
+ * the knowledgeElementTypeService to set
+ */
+ public void setKnowledgeElementTypeService(
+ KnowledgeElementTypeService knowledgeElementTypeService) {
+ _knowledgeElementTypeService = knowledgeElementTypeService;
+ }
+
+ /**
+ * Get the studyService.
+ * @return the studyService
+ */
+ public StudyService getStudyService() {
+ return _studyService;
+ }
+
+ /**
+ * Set the studyService.
+ * @param studyService the studyService to set
+ */
+ public void setStudyService(StudyService studyService) {
+ _studyService = studyService;
+ }
+
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
--- /dev/null
+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 19.10.2012
+ * @author $Author$
+ * @version $Revision$
+ * @copyright OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service;
+
+/**
+ * The service locator interface.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+@Deprecated
+public interface ServiceLocator {
+ /**
+ * Get study service.
+ * @return study service
+ */
+ StudyService getStudyService();
+}
--- /dev/null
+/*****************************************************************************
+ * Company OPEN CASCADE
+ * Application SIMAN
+ * File $Id$
+ * Creation date 19.10.2012
+ * @author $Author$
+ * @version $Revision$
+ * @copyright OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.service;
+
+/**
+ * The service locator implementaion. This is a singleton class for providing access to business services.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+@Deprecated
+public class ServiceLocatorImpl implements ServiceLocator {
+
+ /**
+ * The Locator instance.
+ */
+ static ServiceLocator theInstance;
+
+ /**
+ * Get the locator instance.
+ * @return the locator instance
+ */
+ public static ServiceLocator getInstance() {
+ if (theInstance == null) {
+ theInstance = new ServiceLocatorImpl();
+ }
+ return theInstance;
+ }
+
+ /**
+ * Private constructor because this is a singleton class.
+ */
+ private ServiceLocatorImpl() {
+ }
+
+ /**
+ * Injected study service.
+ */
+ private StudyService _studyService;
+
+ /**
+ * Get the studyService.
+ * @return the studyService
+ */
+ public StudyService getStudyService() {
+ return _studyService;
+ }
+
+ /**
+ * Set the studyService.
+ * @param studyService the studyService to set
+ */
+ public void setStudyService(StudyService studyService) {
+ _studyService = studyService;
+ }
+}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 16.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 16.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
package org.splat.service;
import java.io.IOException;
+import java.util.List;
import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.kernel.InvalidPropertyException;
/**
* Step service interface.
+ *
* @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
public interface StepService {
+ /**
+ * Create a new document published in the given study step.
+ *
+ * @param aStep
+ * the target study step
+ * @param dprop
+ * properties of the new document
+ * @return the created publication of the new document
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ * @throws IOException
+ * if a file system error occurs
+ */
public Publication createDocument(Step aStep, Document.Properties dprop)
throws MissedPropertyException, InvalidPropertyException,
MultiplyDefinedException, IOException;
+ /**
+ * Publish an existing document in the given study step.
+ *
+ * @param aStep
+ * the target study step
+ * @param dprop
+ * new properties of the document
+ * @return the created publication of the document
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws NotApplicableException
+ * if the document is undefined
+ */
public Publication assignDocument(Step aStep, Document.Properties dprop)
throws MissedPropertyException, InvalidPropertyException,
NotApplicableException;
+ /**
+ * Create a new version of a document in the given study step.
+ *
+ * @param aStep
+ * the study step
+ * @param base
+ * the base document published version
+ * @param dprop
+ * properties of the new version
+ * @return the new version publication
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ * @throws IOException
+ * if a file system error occurs
+ * @throws MismatchException
+ * if the document is not applicable to the given study step
+ */
public Publication versionDocument(Step aStep, Publication base,
Document.Properties dprop) throws MissedPropertyException,
InvalidPropertyException, MultiplyDefinedException, IOException,
MismatchException;
+ /**
+ * Add simulation context to the study step.
+ *
+ * @param aStep
+ * the study step
+ * @param dprop
+ * properties of the simulation context to add
+ * @return the added simulation context
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ */
public SimulationContext addSimulationContext(Step aStep,
SimulationContext.Properties dprop) throws MissedPropertyException,
- InvalidPropertyException, MultiplyDefinedException,
- RuntimeException;
+ InvalidPropertyException, MultiplyDefinedException;
/**
+ * Add simulation context to the study step.
+ *
* @param firstStep
+ * the study step
* @param context
- * @return
+ * the simulation context to add
+ * @return the added simulation context
*/
public SimulationContext addSimulationContext(Step firstStep,
SimulationContext context);
+ /**
+ * Remove a simulation context from the study step.
+ *
+ * @param aStep
+ * the study step
+ * @param context
+ * the simulation context to remove
+ * @return true if removal succeeded
+ */
public boolean removeSimulationContext(Step aStep, SimulationContext context);
+
+ /**
+ * Add a document publication to the given step.
+ *
+ * @param aStep
+ * the target study step
+ * @param newdoc
+ * the document publication to add
+ * @return true if publication succeeded
+ */
+ public boolean add(Step aStep, Publication newdoc);
+
+ /**
+ * Remove a document publication from the given step.
+ *
+ * @param aStep
+ * the study step
+ * @param oldoc
+ * the document publication to remove
+ * @return true if removing of the publication succeeded
+ */
+ public boolean remove(Step aStep, Publication oldoc);
+
+ /**
+ * Remove a document from the given step.
+ *
+ * @param aStep
+ * the study step
+ * @param doctag
+ * the document publication
+ * @return true if removing of the document succeeded
+ */
+ public boolean removeDocument(Step aStep, Publication doctag);
+
+ /**
+ * Get document types which are applicable for the given study step (activity).
+ *
+ * @param aStep
+ * the study step
+ * @return the list of document types
+ */
+ public List<DocumentType> getValidDocumentTypes(Step aStep);
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
package org.splat.service;
-import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+import java.util.Vector;
import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.File;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.UsesRelation;
import org.splat.dal.bo.som.VersionsRelation;
import org.splat.dal.dao.som.DocumentDAO;
+import org.splat.dal.dao.som.FileDAO;
import org.splat.dal.dao.som.ProjectElementDAO;
import org.splat.dal.dao.som.SimulationContextDAO;
import org.splat.kernel.InvalidPropertyException;
* Injected document service.
*/
private DocumentService _documentService;
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
/**
* Injected document DAO.
*/
private DocumentDAO _documentDAO;
+ /**
+ * Injected file DAO.
+ */
+ private FileDAO _fileDAO;
/**
* Injected simulation context service.
*/
*/
public SimulationContext addSimulationContext(Step aStep,
SimulationContext.Properties dprop) throws MissedPropertyException,
- InvalidPropertyException, MultiplyDefinedException,
- RuntimeException {
+ InvalidPropertyException, MultiplyDefinedException {
SimulationContext context = new SimulationContext(dprop.setStep(aStep
.getStep()));
return addSimulationContext(aStep, context);
updateScenarioIndex(scene);
}
} catch (Exception error) {
- logger.error("Unable to re-index Knowledge Elements, reason:", error);
+ logger.error("Unable to re-index Knowledge Elements, reason:",
+ error);
}
}
getDocumentService().generateDocumentId(newdoc, dprop);
// Creation of the save directory
- File wdir = getDocumentService().getSaveDirectory(newdoc);
+ java.io.File wdir = getDocumentService().getSaveDirectory(newdoc);
if (!wdir.exists())
if (!wdir.mkdirs())
throw new IOException(
"Cannot create the repository vault directory");
// Identification and save
- newdoc.buildReferenceFrom(aStep.getOwnerStudy());
+ getDocumentService().buildReferenceFrom(newdoc, aStep.getOwnerStudy());
getDocumentDAO().create(newdoc);
return new Publication(newdoc, aStep.getOwner());
}
/**
+ * Create a new version of a document in the given study step.
+ *
* @param aStep
+ * the study step
* @param base
- * @return
+ * the base document published version
+ * @return the new version publication
* @throws MissedPropertyException
+ * if a mandatory property is missed
* @throws InvalidPropertyException
+ * if some property doesn't exist
* @throws MultiplyDefinedException
+ * if some property is defined several times
* @throws IOException
+ * if a file system error occurs
* @throws MismatchException
+ * if the document is not applicable to the given study step
*/
public Publication versionDocument(Step aStep, Publication base)
throws MissedPropertyException, InvalidPropertyException,
}
/**
+ * Create a new version of a document in the given study step.
+ *
* @param aStep
+ * the study step
* @param base
+ * the base document published version
* @param reason
- * @return
+ * the comment for the new version
+ * @return the new version publication
* @throws MissedPropertyException
+ * if a mandatory property is missed
* @throws InvalidPropertyException
+ * if some property doesn't exist
* @throws MultiplyDefinedException
+ * if some property is defined several times
* @throws IOException
+ * if a file system error occurs
* @throws MismatchException
+ * if the document is not applicable to the given study step
*/
public Publication versionDocument(Step aStep, Publication base,
String reason) throws MissedPropertyException,
}
/**
- * {@inheritDoc}
+ * Create a new version of a document in the given study step.
*
- * @see org.splat.service.StepService#versionDocument(org.splat.som.Step, org.splat.dal.bo.som.Publication,
- * org.splat.dal.bo.som.Document.Properties)
+ * @param aStep
+ * the study step
+ * @param base
+ * the base document published version
+ * @param dprop
+ * properties of the new version
+ * @return the new version publication
+ * @throws MissedPropertyException
+ * if a mandatory property is missed
+ * @throws InvalidPropertyException
+ * if some property doesn't exist
+ * @throws MultiplyDefinedException
+ * if some property is defined several times
+ * @throws IOException
+ * if a file system error occurs
+ * @throws MismatchException
+ * if the document is not applicable to the given study step
*/
@Transactional
public Publication versionDocument(Step aStep, Publication base,
Document newdoc = new Document(dprop.setOwner(aStep.getOwner())
.setStep(aStep.getStep()));
getDocumentService().generateDocumentId(newdoc, dprop);
- newdoc.buildReferenceFrom(aStep.getOwner(), previous);
+ getDocumentService().buildReferenceFrom(newdoc, aStep.getOwner(),
+ previous);
getDocumentDAO().create(newdoc);
// Versioning
return new Publication(newdoc, aStep.getOwner());
}
+ /**
+ * Get document types which are applicable for the given study step (activity).
+ *
+ * @param aStep
+ * the study step
+ * @return the list of document types
+ */
+ public List<DocumentType> getValidDocumentTypes(Step aStep) {
+ return getDocumentTypeService().selectTypesOf(aStep.getStep());
+ }
+
+ /**
+ * Add a document publication to the given step.
+ *
+ * @param aStep
+ * the target study step
+ * @param newdoc
+ * the document publication to add
+ * @return true if publication succeeded
+ */
+ public boolean add(Step aStep, Publication newdoc) {
+ if (!aStep.getOwner().add(newdoc))
+ return false; // Updates the study in memory
+ aStep.getDocuments().add(0, newdoc); // Updates this step
+ getDocumentService().hold(newdoc.value()); // Increments the configuration tag count of document
+ // If not yet saved, the Publication MUST NOT be saved here, although this creates a temporary inconsistent state into the
+ // database (it will be saved later by cascading the update of owner scenario).
+ return true;
+ }
+
+ /**
+ * Remove a document publication from the given step.
+ *
+ * @param aStep
+ * the study step
+ * @param oldoc
+ * the document publication to remove
+ * @return true if removing of the publication succeeded
+ */
+ public boolean remove(Step aStep, Publication oldoc) {
+ if (!aStep.getOwner().remove(oldoc))
+ return false; // Updates the study in memory
+ aStep.getDocuments().remove(oldoc); // Updates this step
+ getDocumentService().release(oldoc.value()); // Decrements the configuration tag count of document
+ // The publication becoming orphan, it should automatically be removed from the database when updating of owner scenario.
+ return true;
+ }
+
+ /**
+ * Remove a document from the given step.
+ *
+ * @param aStep
+ * the study step
+ * @param doctag
+ * the document publication
+ * @return true if removing of the document succeeded
+ */
+ public boolean removeDocument(Step aStep, Publication doctag) {
+ Document value = doctag.value();
+ Publication torem = aStep.getDocument(value.getIndex());
+
+ if (torem == null)
+ return false;
+
+ remove(aStep, torem);
+ getProjectElementDAO().update(aStep.getOwner());
+ if (!value.isPublished() && !value.isVersioned()) { // The referenced document is no more used
+ Set<Relation> links = value.getAllRelations(); // Get all relation of the document to remove them
+ List<Document> using = new Vector<Document>();
+ for (Iterator<Relation> i = links.iterator(); i.hasNext();) {
+ Relation link = i.next();
+ if (link.getClass().equals(ConvertsRelation.class)) { // File conversion
+ getFileDAO().delete((File) link.getTo()); // The corresponding physical file is not removed from the vault
+ } else if (link.getClass().equals(UsesRelation.class)) { // Document dependency
+ using.add((Document) link.getTo());
+ }
+ }
+ for (Iterator<Document> i = using.iterator(); i.hasNext();) {
+ i.next().removeRelation(UsedByRelation.class, value); // TODO: RKV: don't use Database.getSession in removeRelation
+ }
+ getDocumentDAO().delete(value); // The corresponding physical file is not removed from the vault
+ }
+ return true;
+ }
+
/**
* Get the documentService.
*
public void setIndexService(IndexService indexService) {
_indexService = indexService;
}
+
+ /**
+ * Get the fileDAO.
+ *
+ * @return the fileDAO
+ */
+ public FileDAO getFileDAO() {
+ return _fileDAO;
+ }
+
+ /**
+ * Set the fileDAO.
+ *
+ * @param fileDAO
+ * the fileDAO to set
+ */
+ public void setFileDAO(FileDAO fileDAO) {
+ _fileDAO = fileDAO;
+ }
+
+ /**
+ * Get the documentTypeService.
+ *
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File Id:
* Creation date 02.10.2012
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;
/**
* Increment total number of study documents including versions (docount) and update it in the study.
- * @param aStudy the study
+ *
+ * @param aStudy
+ * the study
* @return incremented docount value
*/
public int generateLocalIndex(Study aStudy);
SimulationContext context);
/**
- * Add a new scenario to the study.
+ * Remove a simulation context from a study.
*
* @param aStudy
* the study
- * @param sprop
- * scenario properties
- * @return the added scenario
- * @throws MissedPropertyException
- * if a mandatory property is missed
- * @throws InvalidPropertyException
- * if some property doesn't exist
- * @throws MultiplyDefinedException
- * if some property occurs several times
- */
- public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
- throws MissedPropertyException, InvalidPropertyException,
- MultiplyDefinedException;
-
- /**
- * Remove a simulation context from a study.
- * @param aStudy the study
- * @param context the simulation context to remove
+ * @param context
+ * the simulation context to remove
* @return true if removing succeeded
*/
public boolean removeProjectContext(Study aStudy, SimulationContext context);
*/
public boolean update(Study aStudy, Properties sprop)
throws InvalidPropertyException;
+
+ /**
+ * Initialize shortcuts of the study as its transient collections.
+ *
+ * @param aStudy
+ * the study
+ */
+ public void loadWorkflow(Study aStudy);
+
+ /**
+ * Returns the validation cycle of the given document type.
+ *
+ * @param aStudy
+ * the study
+ * @param type
+ * the document type being subject of validation
+ * @return the validation cycle of the document, or null if not defined.
+ */
+ public ValidationCycle getValidationCycleOf(Study aStudy, DocumentType type);
+
+ /**
+ * Checks if the given user participates to this study. The Study staff includes the author and contributors.
+ *
+ * @param aStudy
+ * the study
+ * @param user
+ * the user to look for
+ * @return true if the given user is actor of this study.
+ * @see #getContributors()
+ */
+ public boolean isStaffedBy(Study aStudy, User user);
+
+ /**
+ * Checks if the given user is actor of this study. Actors include contributors, reviewers and approvers.
+ *
+ * @param aStudy
+ * the study
+ * @param user
+ * the user to look for
+ * @return true if the given user is actor of this study.
+ * @see #getActors()
+ */
+ public boolean hasActor(Study aStudy, User user);
+
+ /**
+ * Returns unmodifiable initialized transient list of contributors of this study.
+ *
+ * @param aStudy
+ * the study
+ * @return the unmodifiable not null transient list of contributors of this study
+ */
+ public List<User> getContributors(Study aStudy);
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File Id:
* Creation date 02.10.2012
package org.splat.service;
import java.io.IOException;
-import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.hibernate.criterion.Restrictions;
import org.splat.dal.bo.kernel.Relation;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.IDBuilder;
import org.splat.dal.bo.som.KnowledgeElement;
-import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.ValidationCycle;
import org.splat.dal.bo.som.ValidationCycleRelation;
+import org.splat.dal.bo.som.ValidationStep;
import org.splat.dal.bo.som.Visibility;
import org.splat.dal.bo.som.Study.Properties;
+import org.splat.dal.bo.som.ValidationCycle.Actor;
import org.splat.dal.dao.som.IDBuilderDAO;
import org.splat.dal.dao.som.ScenarioDAO;
import org.splat.dal.dao.som.StudyDAO;
import org.splat.log.AppLogger;
import org.splat.service.technical.IndexService;
import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.ProjectSettingsServiceImpl;
import org.splat.som.Revision;
import org.springframework.transaction.annotation.Transactional;
*/
private StepService _stepService;
- /**
- * Injected scenario service.
- */
- private ScenarioService _scenarioService;
-
/**
* Injected project service.
*/
*/
private IDBuilderDAO _iDBuilderDAO;
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
+
/**
* {@inheritDoc}
*
@Transactional
public Study selectStudy(long index) {
Study result = getStudyDAO().get(index);
- result.loadWorkflow();
+ loadWorkflow(result);
return result;
}
public Study selectStudy(String refid) {
Study result = getStudyDAO().findByCriteria(
Restrictions.eq("sid", refid));
- result.loadWorkflow();
+ loadWorkflow(result);
return result;
}
* @see org.splat.service.StudyService#addContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User)
*/
public boolean addContributor(Study aStudy, User user) {
- List<User> contributor = aStudy.getModifiableContributors(); // Initializes contributor
+ List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
for (Iterator<User> i = contributor.iterator(); i.hasNext();) {
User present = i.next();
if (present.equals(user))
return false;
}
- boolean absent = aStudy.getModifiableActors().add(user); // User may already be a reviewer or an approver
+ boolean absent = getModifiableActors(aStudy).add(user); // User may already be a reviewer or an approver
aStudy.addRelation(new ContributorRelation(aStudy, user));
if (absent)
* @see org.splat.service.StudyService#removeContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User[])
*/
public boolean removeContributor(Study aStudy, User... users) {
- List<User> contributor = aStudy.getModifiableContributors(); // Initializes contributor
+ List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
Boolean done = false;
for (int i = 0; i < users.length; i++) {
User user = users[i];
@Transactional
public void setValidationCycle(Study aStudy, DocumentType type,
ValidationCycle.Properties vprop) {
- HashMap<String, ValidationCycle> validactor = aStudy
- .getValidationCycles();
+ Map<String, ValidationCycle> validactor = aStudy.getValidationCycles();
if (validactor == null)
- aStudy.setShortCuts(); // Initializes validactor and actor
+ setShortCuts(aStudy); // Initializes validactor and actor
String cname = type.getName();
ValidationCycle cycle = validactor.get(cname);
if (cycle != null && cycle.isAssigned()) {
- cycle.resetActors(vprop);
+ resetActors(cycle, vprop);
} else
try {
cycle = new ValidationCycle(aStudy, vprop.setDocumentType(type));
- getValidationCycleDAO().create(cycle); //RKV
-
+ getValidationCycleDAO().create(cycle); // RKV
+
ValidationCycleRelation link = cycle.getContext();
-//RKV: aStudy.addRelation(link);
- aStudy.getAllRelations().add(link); //RKV
-
+ // RKV: aStudy.addRelation(link);
+ aStudy.getAllRelations().add(link); // RKV
+
validactor.put(cname, link.getTo()); // Replaces the cycle if exists as default,
} catch (Exception error) {
logger.error("Unable to re-index Knowledge Elements, reason:",
return aStudy.getLastLocalIndex();
}
- /**
- * {@inheritDoc}
- *
- * @see org.splat.service.StudyService#addScenario(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Scenario.Properties)
- */
- @Transactional
- public Scenario addScenario(Study aStudy, Scenario.Properties sprop)
- throws MissedPropertyException, InvalidPropertyException,
- MultiplyDefinedException {
- if (sprop.getManager() == null)
- sprop.setManager(aStudy.getAuthor());
-
- Scenario scenario = new Scenario(sprop.setOwnerStudy(aStudy));
- if (sprop.getBaseStep() != null)
- getScenarioService()
- .copyContentsUpTo(scenario, sprop.getBaseStep());
- Scenario previous = sprop.getInsertAfter();
-
- if (previous == null) {
- aStudy.getScenariiList().add(scenario);
- } else {
- aStudy.getScenariiList().add(
- aStudy.getScenariiList().indexOf(previous) + 1, scenario);
- }
- getStudyDAO().update(aStudy); // No need to update the Lucene index
- getScenarioDAO().create(scenario); // Must be done after updating this study because of the back reference to the study
- if (sprop.getBaseStep() != null) {
- // No need to update the Knowledge Element index as Knowledge Elements are not copied
- scenario.refresh(); // Because saving the scenario changes the hashcode of copied Publications
- }
- KnowledgeElementType ucase = KnowledgeElement.selectType("usecase");
- KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
- User admin = UserDirectory.selectUser(1); // First user created when creating the database
- kprop.setType(ucase).setTitle(aStudy.getTitle()).setValue(
- scenario.getTitle()).setAuthor(admin); // Internal Knowledge Element required by the validation process of
- // knowledges
- getScenarioService().addKnowledgeElement(scenario, kprop);
- return scenario;
- }
-
/**
* Promotes this study from In-Work to In-Draft then In-Check and APPROVED states. This function is called internally when promoting the
* final result document of the study.
boolean isOk = false;
try {
getStudyDAO().update(aStudy); // Update of relational base
+ setShortCuts(aStudy); //RKV: initialize transient actors set
getIndex().update(aStudy); // Update of Lucene index
isOk = true;
} catch (Exception error) {
* the study
*/
private void resetActorsShortCut(Study aStudy) {
- aStudy.getModifiableActors().clear();
+ getModifiableActors(aStudy).clear();
// Get all actors involved in validation cycles
for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
.values().iterator(); i.hasNext();) {
ValidationCycle cycle = i.next();
User[] user = cycle.getAllActors();
for (int j = 0; j < user.length; j++)
- aStudy.getModifiableActors().add(user[j]);
+ getModifiableActors(aStudy).add(user[j]);
}
// Get all other actors
for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
Class<?> kindof = link.getClass().getSuperclass();
if (!kindof.equals(ActorRelation.class))
continue;
- aStudy.getModifiableActors().add(((ActorRelation) link).getTo());
+ getModifiableActors(aStudy).add(((ActorRelation) link).getTo());
}
}
return lucin;
}
+ /**
+ * Create a new validation cycle for documents of the given study.
+ *
+ * @param from
+ * the study
+ * @param cycle
+ * the cycle description
+ * @return the new validation cycle
+ */
+ protected ValidationCycle createValidationCycle(Study from,
+ ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle) {
+ // -----------------------------------------------------------------------------
+ Actor[] actype = cycle.getActorTypes();
+ User.Properties uprop = new User.Properties();
+
+ ValidationCycle aValidationCycle = new ValidationCycle();
+ aValidationCycle.setDocumentType(getDocumentTypeService().selectType(
+ cycle.getName())); // Null in case of default validation cycle
+ // context = new ValidationCycleRelation(from, this);
+ // RKV aValidationCycle.context = null; // Validation cycle defined in the workflow
+ for (int i = 0; i < actype.length; i++) {
+ User actor = null;
+ if (actype[i] != null)
+ try {
+ if (actype[i] == Actor.manager) {
+ actor = from.getAuthor();
+ } else if (actype[i] == Actor.Nx1) {
+ List<User> manager = UserDirectory
+ .selectUsersWhere(uprop
+ .setOrganizationName("Nx1"));
+ if (manager.size() == 1)
+ actor = manager.get(0);
+ } else if (actype[i] == Actor.Nx2) {
+ List<User> manager = UserDirectory
+ .selectUsersWhere(uprop
+ .setOrganizationName("Nx2"));
+ if (manager.size() == 1)
+ actor = manager.get(0);
+ } else { /* Actor.customer */
+ actor = from.getAuthor();
+ // TODO: Get the customer of the study, if exists
+ }
+ } catch (Exception e) { // Should not happen
+ actor = null;
+ }
+ if (i == 0)
+ aValidationCycle.setReviewer(actor);
+ else if (i == 1)
+ aValidationCycle.setApprover(actor);
+ else if (i == 2)
+ aValidationCycle.setSignatory(actor);
+ }
+ return aValidationCycle;
+ }
+
+ /**
+ * Remove a validation step from the validation cycle.
+ *
+ * @param aValidationCycle
+ * the validation cycle
+ * @param step
+ * the validation step to remove
+ */
+ @Transactional
+ protected void remove(ValidationCycle aValidationCycle, ValidationStep step) {
+ // ------------------------------------------
+ if (step == ValidationStep.REVIEW)
+ aValidationCycle.setReviewer(null);
+ else if (step == ValidationStep.APPROVAL)
+ aValidationCycle.setApprover(null);
+ else if (step == ValidationStep.ACCEPTANCE
+ || step == ValidationStep.REFUSAL)
+ aValidationCycle.setSignatory(null);
+ if (aValidationCycle.isSaved()) {
+ getValidationCycleDAO().update(aValidationCycle);
+ }
+ }
+
+ /**
+ * Reset actors for the validation cycle.
+ *
+ * @param aValidationCycle
+ * the validation cycle to update
+ * @param vprop
+ * new validation cycle properties containing new actors
+ */
+ @Transactional
+ public void resetActors(ValidationCycle aValidationCycle,
+ ValidationCycle.Properties vprop) {
+ aValidationCycle.setPublisher(vprop.getPublisher()); // May be null
+ aValidationCycle.setReviewer(vprop.getReviewer()); // May be null
+ aValidationCycle.setApprover(vprop.getApprover()); // May be null
+ aValidationCycle.setSignatory(vprop.getSignatory()); // May be null
+ if (aValidationCycle.isSaved()) {
+ getValidationCycleDAO().update(aValidationCycle);
+ }
+ }
+
+ /**
+ * Set actor for the given validation cycle and validation step.
+ *
+ * @param aValidationCycle
+ * the validation cycle
+ * @param step
+ * the validation step
+ * @param actor
+ * the actor to set
+ */
+ @Transactional
+ protected void setActor(ValidationCycle aValidationCycle,
+ ValidationStep step, User actor) {
+ if (step == ValidationStep.PROMOTION) {
+ aValidationCycle.setPublisher(actor);
+ } else if (step == ValidationStep.REVIEW) {
+ aValidationCycle.setReviewer(actor);
+ } else if (step == ValidationStep.APPROVAL) {
+ aValidationCycle.setApprover(actor);
+ } else if (step == ValidationStep.ACCEPTANCE
+ || step == ValidationStep.REFUSAL) {
+ aValidationCycle.setSignatory(actor);
+ }
+ if (aValidationCycle.isSaved()) {
+ getValidationCycleDAO().update(aValidationCycle);
+ }
+ }
+
+ /**
+ * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
+ *
+ * @param aStudy
+ * the study
+ * @return the actors of this study
+ * @see #hasActor(User)
+ */
+ public Set<User> getActors(Study aStudy) {
+ if (aStudy.getActor() == null)
+ setShortCuts(aStudy);
+ return Collections.unmodifiableSet(aStudy.getActor());
+ }
+
+ /**
+ * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
+ *
+ * @param aStudy
+ * the study
+ * @return the modifiable set of actors of this study
+ * @see #hasActor(User)
+ */
+ public Set<User> getModifiableActors(Study aStudy) {
+ if (aStudy.getActor() == null)
+ setShortCuts(aStudy);
+ return aStudy.getActor();
+ }
+
+ /**
+ * Returns unmodifiable initialized transient list of contributors of this study.
+ *
+ * @param aStudy
+ * the study
+ * @return the unmodifiable not null transient list of contributors of this study
+ */
+ public List<User> getContributors(Study aStudy) {
+ if (aStudy.getContributor() == null)
+ setShortCuts(aStudy);
+ return Collections.unmodifiableList(aStudy.getContributor()); // May be empty
+ }
+
+ /**
+ * Returns modifiable initialized transient list of contributors of this study.
+ *
+ * @param aStudy
+ * the study
+ * @return the modifiable not null transient list of contributors of this study
+ */
+ public List<User> getModifiableContributors(Study aStudy) {
+ if (aStudy.getContributor() == null)
+ setShortCuts(aStudy);
+ return aStudy.getContributor(); // May be empty
+ }
+
+ /**
+ * Returns the validation cycle of the given document type.
+ *
+ * @param aStudy
+ * the study
+ * @param type
+ * the document type being subject of validation
+ * @return the validation cycle of the document, or null if not defined.
+ */
+ public ValidationCycle getValidationCycleOf(Study aStudy, DocumentType type) {
+ if (aStudy.getValidationCycles() == null)
+ setShortCuts(aStudy);
+ ValidationCycle result = aStudy.getValidationCycles().get(
+ type.getName());
+ if (result == null) {
+ if (type.isStepResult())
+ result = aStudy.getValidationCycles().get("default"); // "default" validation cycle defined in the configuration, if exist
+ if (result == null)
+ result = aStudy.getValidationCycles().get("built-in");
+ }
+ return result;
+ }
+
+ /**
+ * Checks if the given user is actor of this study. Actors include contributors, reviewers and approvers.
+ *
+ * @param aStudy
+ * the study
+ * @param user
+ * the user to look for
+ * @return true if the given user is actor of this study.
+ * @see #getActors()
+ */
+ public boolean hasActor(Study aStudy, User user) {
+ if (user == null)
+ return false;
+ for (Iterator<User> i = getActors(aStudy).iterator(); i.hasNext();) {
+ User involved = i.next();
+ if (involved.equals(user))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the given user participates to this study. The Study staff includes the author and contributors.
+ *
+ * @param aStudy
+ * the study
+ * @param user
+ * the user to look for
+ * @return true if the given user is actor of this study.
+ * @see #getContributors()
+ */
+ public boolean isStaffedBy(Study aStudy, User user) {
+ if (user == null)
+ return false;
+ if (aStudy.getAuthor().equals(user))
+ return true;
+ for (Iterator<User> i = getContributors(aStudy).iterator(); i.hasNext();) {
+ if (i.next().equals(user))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Initialize shortcuts of the study as its transient collections.
+ *
+ * @param aStudy
+ * the study
+ */
+ public void loadWorkflow(Study aStudy) {
+ setShortCuts(aStudy);
+ }
+
+ /**
+ * Initialize shortcuts of the study as its transient collections.
+ *
+ * @param aStudy
+ * the study
+ */
+ public void setShortCuts(Study aStudy) {
+ aStudy.getContributor().clear();
+ aStudy.getValidationCycles().clear();
+ aStudy.getActor().clear();
+
+ // Get the contributors
+ for (Iterator<Relation> i = aStudy.getRelations(
+ ContributorRelation.class).iterator(); i.hasNext();) {
+ ContributorRelation link = (ContributorRelation) i.next();
+ aStudy.getContributor().add(link.getTo());
+ }
+ // Get the validation cycles specific to this study
+ for (Iterator<Relation> i = aStudy.getRelations(
+ ValidationCycleRelation.class).iterator(); i.hasNext();) {
+ ValidationCycleRelation link = (ValidationCycleRelation) i.next();
+ aStudy.getValidationCycles().put(link.getDocumentType().getName(),
+ link.getTo()); // The associated document type is necessarily not null in this
+ // context
+ }
+ // Get the validation cycles coming from the configured workflow and not overridden in this study
+ for (Iterator<ProjectSettingsServiceImpl.ProjectSettingsValidationCycle> i = ProjectSettingsServiceImpl
+ .getAllValidationCycles().iterator(); i.hasNext();) {
+ ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle = i
+ .next();
+ String type = cycle.getName();
+ if (!aStudy.getValidationCycles().containsKey(type))
+ aStudy.getValidationCycles().put(type,
+ createValidationCycle(aStudy, cycle));
+ }
+ // Get all corresponding actors
+ for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
+ .values().iterator(); i.hasNext();) {
+ ValidationCycle cycle = i.next();
+ User[] user = cycle.getAllActors();
+ for (int j = 0; j < user.length; j++)
+ aStudy.getActor().add(user[j]);
+ }
+ // Get all other actors
+ for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
+ .hasNext();) {
+ Relation link = i.next();
+ Class<?> kindof = link.getClass().getSuperclass();
+ if (!kindof.equals(ActorRelation.class))
+ continue;
+ aStudy.getActor().add(((ActorRelation) link).getTo());
+ }
+ }
+
/**
* Get project settings.
*
_iDBuilderDAO = builderDAO;
}
- /**
- * Get the scenarioService.
- *
- * @return the scenarioService
- */
- public ScenarioService getScenarioService() {
- return _scenarioService;
- }
-
- /**
- * Set the scenarioService.
- *
- * @param scenarioService
- * the scenarioService to set
- */
- public void setScenarioService(ScenarioService scenarioService) {
- _scenarioService = scenarioService;
- }
-
/**
* Get the scenarioDAO.
*
/**
* Get the validationCycleDAO.
+ *
* @return the validationCycleDAO
*/
public ValidationCycleDAO getValidationCycleDAO() {
/**
* Set the validationCycleDAO.
- * @param validationCycleDAO the validationCycleDAO to set
+ *
+ * @param validationCycleDAO
+ * the validationCycleDAO to set
*/
public void setValidationCycleDAO(ValidationCycleDAO validationCycleDAO) {
_validationCycleDAO = validationCycleDAO;
}
+
+ /**
+ * Get the documentTypeService.
+ *
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
}
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 08.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 08.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
}
private void setActorsOf (Study study)
{
- Set<User> actors = study.getActors();
+//RKV: This set is always not null. Let's assume that it must be initialized before reindexing: Set<User> actors = study.getActors();
+ Set<User> actors = study.getActor(); //RKV
for (Iterator<User> i=actors.iterator(); i.hasNext(); ) {
String value = i.next().toString();
entry.add( new Field("actor", value, Field.Store.NO, Field.Index.NOT_ANALYZED) );
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.ProjectElement;
import org.splat.dal.bo.som.Scenario;
-import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.SimulationContextType;
import org.splat.dal.bo.som.Study;
import org.splat.dal.bo.som.ValidationCycle.Actor;
import org.splat.dal.dao.som.Database;
import org.splat.manox.XDOM;
+import org.splat.service.DocumentTypeService;
+import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.SimulationContextService;
public class ProjectSettingsServiceImpl implements ProjectSettingsService {
+ /**
+ * The logger for the service.
+ */
+ protected final static Logger logger = Logger
+ .getLogger(ProjectSettingsServiceImpl.class);
+
// Non persistent configuration information
private Properties reprop; // Repository settings
private String pattern; // Pattern of study references
* Injected simulation context service.
*/
private SimulationContextService _simulationContextService;
- protected final static Logger logger = Logger
- .getLogger(ProjectSettingsServiceImpl.class);
+ /**
+ * Injected knowledge element type service.
+ */
+ private KnowledgeElementTypeService _knowledgeElementTypeService;
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
public enum FileNaming {
title, encoded, asis
tprop.setResult(step);
tprop.disableCheck();
- tdoc = Document.createType(tprop); // Creation of Document Types
+ tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types
tdoc.approve();
maptype.put(type, tdoc);
}
private void createKnowledgeElementTypes() {
// -------------------------------------------
try {
- KnowledgeElementType ktype = KnowledgeElement.createType("usecase"); // Internal reserved knowledge element type
+ KnowledgeElementType ktype = getKnowledgeElementTypeService()
+ .createType("usecase"); // Internal reserved knowledge element type
ktype.reserve();
for (Iterator<String> i = kname.iterator(); i.hasNext();) {
String type = i.next();
- ktype = KnowledgeElement.createType(type); // Knowledge Elements Types defined in the configuration
+ ktype = getKnowledgeElementTypeService().createType(type); // Knowledge Elements Types defined in the configuration
ktype.approve();
}
} catch (Exception error) {
SimulationContextService simulationContextService) {
_simulationContextService = simulationContextService;
}
+
+ /**
+ * Get the knowledgeElementTypeService.
+ *
+ * @return the knowledgeElementTypeService
+ */
+ public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+ return _knowledgeElementTypeService;
+ }
+
+ /**
+ * Set the knowledgeElementTypeService.
+ *
+ * @param knowledgeElementTypeService
+ * the knowledgeElementTypeService to set
+ */
+ public void setKnowledgeElementTypeService(
+ KnowledgeElementTypeService knowledgeElementTypeService) {
+ _knowledgeElementTypeService = knowledgeElementTypeService;
+ }
+
+ /**
+ * Get the documentTypeService.
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ * @param documentTypeService the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
}
\ No newline at end of file
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 06.10.2012
import org.splat.dal.bo.som.ValidationCycle;
import org.splat.dal.bo.som.ValidationStep;
import org.splat.dal.bo.som.VersionsRelation;
+import org.splat.service.ServiceLocatorImpl;
public class DocumentRights {
// --------------------------------------------------
this.user = user;
this.operand = tag;
- this.cycle = operand.getOwnerStudy().getValidationCycleOf(operand.value().getType());
+//RKV this.cycle = operand.getOwnerStudy().getValidationCycleOf(operand.value().getType());
+ this.cycle = ServiceLocatorImpl.getInstance().getStudyService().getValidationCycleOf(operand.getOwnerStudy(), operand.value().getType());
this.isauthor = operand.value().getAuthor().equals(user);
//TODO: all contributors of the given document (when supported) must also behave as author
}
// ------------------------------------------
this.user = operand.value().getAuthor();
this.operand = tag;
- this.cycle = operand.getOwnerStudy().getValidationCycleOf(operand.value().getType());
+ this.cycle = ServiceLocatorImpl.getInstance().getStudyService().getValidationCycleOf(operand.getOwnerStudy(), operand.value().getType());
this.isauthor = true; // In order to ignore the author state in the context of any user
//TODO: all contributors of the given document (when supported) must also behave as author
}
package org.splat.som;
+
/**
*
* @author Daniel Brunier-Coulin
import org.splat.service.technical.IndexServiceImpl;
import org.splat.service.technical.ProjectSettingsService;
-
public class Step {
-
- private ProjectSettingsService.Step step;
- private ProjectElement owner;
- private List<SimulationContext> contex;
- private List<Publication> docums;
- private User actor; // Actor involved in operations on published documents and requiring a time-stamp
-
-// ==============================================================================================================================
-// Constructor
-// ==============================================================================================================================
-
- public Step (ProjectSettingsService.Step step, ProjectElement owner) {
-// ----------------------------------------------------------------
- this.step = step;
- this.owner = owner;
- this.contex = new Vector<SimulationContext>();
- this.docums = new Vector<Publication>();
- this.actor = null;
-
-// Filtering of Simulation contexts, if exist
- for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
- SimulationContext adoc = i.next();
- if (!adoc.isInto(this)) continue;
- this.contex.add(adoc);
- }
-// Filtering of Documents, if exist
- for (Iterator<Publication> i=owner.PublicationIterator(); i.hasNext();) {
- Publication mydoc = i.next();
- if (!mydoc.value().isInto(this)) continue;
- this.docums.add(mydoc);
- }
- }
-
-// ==============================================================================================================================
-// Public member functions
-// ==============================================================================================================================
-
- public User getActor () {
-// -----------------------
- return actor;
- }
- public List<Publication> getAllDocuments () {
-// -------------------------------------------
- return Collections.unmodifiableList(docums);
- }
-
- public List<SimulationContext> getAllSimulationContexts () {
-// ----------------------------------------------------------
- return Collections.unmodifiableList(contex);
- }
-
- public Publication getDocument (long l) {
-// ------------------------------------------
- for (Iterator<Publication> i=docums.iterator(); i.hasNext();) {
- Publication found = i.next(); // In a given study step,
- if (found.value().getIndex() == l) return found; // there is only one publication of a given document
- }
- return null;
- }
-
- public int getNumber () {
-// -----------------------
- return step.getNumber();
- }
+ private ProjectSettingsService.Step step;
+ private ProjectElement owner;
+ private List<SimulationContext> contex;
+ private List<Publication> docums;
+ private User actor; // Actor involved in operations on published documents and requiring a time-stamp
+
+ // ==============================================================================================================================
+ // Constructor
+ // ==============================================================================================================================
+
+ public Step(ProjectSettingsService.Step step, ProjectElement owner) {
+ // ----------------------------------------------------------------
+ this.step = step;
+ this.owner = owner;
+ this.contex = new Vector<SimulationContext>();
+ this.docums = new Vector<Publication>();
+ this.actor = null;
+
+ // Filtering of Simulation contexts, if exist
+ for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+ .hasNext();) {
+ SimulationContext adoc = i.next();
+ if (!adoc.isInto(this))
+ continue;
+ this.contex.add(adoc);
+ }
+ // Filtering of Documents, if exist
+ for (Iterator<Publication> i = owner.PublicationIterator(); i.hasNext();) {
+ Publication mydoc = i.next();
+ if (!mydoc.value().isInto(this))
+ continue;
+ this.docums.add(mydoc);
+ }
+ }
- public ProjectElement getOwner () {
-// ---------------------------------
- return owner; // May be a Study or a Scenario
- }
+ // ==============================================================================================================================
+ // Public member functions
+ // ==============================================================================================================================
- public Study getOwnerStudy () {
-// -----------------------------
- if (owner instanceof Study) return (Study)owner;
- else return ((Scenario)owner).getOwnerStudy();
- }
+ public User getActor() {
+ // -----------------------
+ return actor;
+ }
- public String getPath () {
-// ------------------------
- return step.getPath();
- }
+ public List<Publication> getAllDocuments() {
+ // -------------------------------------------
+ return Collections.unmodifiableList(docums);
+ }
- public List<Publication> getResultDocuments () {
-// ----------------------------------------------
- List<Publication> result = new Vector<Publication>();
-
- if (!docums.isEmpty()) for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
- Publication content = i.next();
- DocumentType type = content.value().getType();
- if (!type.isResultOf(this.getStep())) continue;
- result.add(content);
- }
- return result;
- }
+ /**
+ * Get the persistent collection of step documents.
+ * @return the list of documents
+ */
+ public List<Publication> getDocuments() {
+ return docums;
+ }
- public ProjectSettingsService.Step getStep () {
-// --------------------------------------
- return step;
- }
+ public List<SimulationContext> getAllSimulationContexts() {
+ // ----------------------------------------------------------
+ return Collections.unmodifiableList(contex);
+ }
- public SimulationContext getSimulationContext (long l) {
-// ---------------------------------------------------------
- for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
- SimulationContext myctex = i.next();
- if (myctex.getIndex() == l) return myctex;
- }
- return null;
- }
+ public Publication getDocument(long l) {
+ // ------------------------------------------
+ for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+ Publication found = i.next(); // In a given study step,
+ if (found.value().getIndex() == l)
+ return found; // there is only one publication of a given document
+ }
+ return null;
+ }
- public List<SimulationContext> getSimulationContext (SimulationContextType type) {
-// --------------------------------------------------------------------------------
- Vector<SimulationContext> result = new Vector<SimulationContext>();
+ public int getNumber() {
+ // -----------------------
+ return step.getNumber();
+ }
- for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
- SimulationContext myctex = i.next();
- if (myctex.getType().equals(type)) result.add(myctex);
- }
- return result;
- }
+ public ProjectElement getOwner() {
+ // ---------------------------------
+ return owner; // May be a Study or a Scenario
+ }
- public List<DocumentType> getValidDocumentTypes () {
-// --------------------------------------------------
- return Document.selectTypesOf(step);
- }
+ public Study getOwnerStudy() {
+ // -----------------------------
+ if (owner instanceof Study)
+ return (Study) owner;
+ else
+ return ((Scenario) owner).getOwnerStudy();
+ }
- public boolean isStarted () {
-// ---------------------------
- if (!step.mayContain(KnowledgeElement.class)) return !docums.isEmpty();
+ public String getPath() {
+ // ------------------------
+ return step.getPath();
+ }
- List<KnowledgeElement> kelm = ((Scenario)owner).getAllKnowledgeElements();
- if (kelm.isEmpty() && docums.isEmpty()) return false;
- return true;
- }
+ public List<Publication> getResultDocuments() {
+ // ----------------------------------------------
+ List<Publication> result = new Vector<Publication>();
+
+ if (!docums.isEmpty())
+ for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+ Publication content = i.next();
+ DocumentType type = content.value().getType();
+ if (!type.isResultOf(this.getStep()))
+ continue;
+ result.add(content);
+ }
+ return result;
+ }
- public boolean isFinished () {
-// ----------------------------
- if (!step.mayContain(KnowledgeElement.class)) { // Check if all result documents are approved
- if (docums.isEmpty()) return false;
- boolean result = false;
- for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
- Document content = i.next().value();
- DocumentType type = content.getType();
- if (!type.isResultOf(this.getStep())) continue;
- if (content.getProgressState() == ProgressState.EXTERN) continue;
- result = true; // There is at least 1 non external result document
- if (content.getProgressState() != ProgressState.APPROVED) return false;
- }
- return result;
- }
- else { // Check if all existing knowledges are approved
- List<KnowledgeElement> kelm = ((Scenario)owner).getAllKnowledgeElements();
- if (kelm.isEmpty()) return false;
- for (Iterator<KnowledgeElement> i=kelm.iterator(); i.hasNext(); ) {
- KnowledgeElement content = i.next();
- if (content.getProgressState() != ProgressState.APPROVED) return false;
- }
- return true;
- }
- }
+ public ProjectSettingsService.Step getStep() {
+ // --------------------------------------
+ return step;
+ }
- public boolean mayContain (@SuppressWarnings("rawtypes") Class type) {
-// --------------------------------------------------------------------
- return step.mayContain(type);
- }
+ public SimulationContext getSimulationContext(long l) {
+ // ---------------------------------------------------------
+ for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+ .hasNext();) {
+ SimulationContext myctex = i.next();
+ if (myctex.getIndex() == l)
+ return myctex;
+ }
+ return null;
+ }
- public boolean removeDocument (Publication doctag) {
-// --------------------------------------------------
- Document value = doctag.value();
- Publication torem = getDocument(value.getIndex());
- Session session = Database.getSession();
+ public List<SimulationContext> getSimulationContext(
+ SimulationContextType type) {
+ // --------------------------------------------------------------------------------
+ Vector<SimulationContext> result = new Vector<SimulationContext>();
+
+ for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+ .hasNext();) {
+ SimulationContext myctex = i.next();
+ if (myctex.getType().equals(type))
+ result.add(myctex);
+ }
+ return result;
+ }
- if (torem == null) return false;
+ public boolean isStarted() {
+ // ---------------------------
+ if (!step.mayContain(KnowledgeElement.class))
+ return !docums.isEmpty();
- this.remove(torem);
- session.update(owner);
- if (!value.isPublished() && !value.isVersioned()) { // The referenced document is no more used
- Set<Relation> links = value.getAllRelations();
- List<Document> using = new Vector<Document>();
- for (Iterator<Relation> i=links.iterator(); i.hasNext(); ) {
- Relation link = i.next();
- if (link.getClass().equals(ConvertsRelation.class)) { // File conversion
- session.delete(link.getTo()); // The corresponding physical file is not removed from the vault
- } else
- if (link.getClass().equals(UsesRelation.class)) { // Document dependency
- using.add((Document)link.getTo());
- }
- }
- for (Iterator<Document> i=using.iterator(); i.hasNext(); ) {
- i.next().removeRelation(UsedByRelation.class, value);
- }
- session.delete(value); // The corresponding physical file is not removed from the vault
- }
- return true;
- }
+ List<KnowledgeElement> kelm = ((Scenario) owner)
+ .getAllKnowledgeElements();
+ if (kelm.isEmpty() && docums.isEmpty())
+ return false;
+ return true;
+ }
- public void setActor (User user) {
-// --------------------------------
- actor = user;
- }
-// ==============================================================================================================================
-// Protected member functions
-// ==============================================================================================================================
+ public boolean isFinished() {
+ // ----------------------------
+ if (!step.mayContain(KnowledgeElement.class)) { // Check if all result documents are approved
+ if (docums.isEmpty())
+ return false;
+ boolean result = false;
+ for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+ Document content = i.next().value();
+ DocumentType type = content.getType();
+ if (!type.isResultOf(this.getStep()))
+ continue;
+ if (content.getProgressState() == ProgressState.EXTERN)
+ continue;
+ result = true; // There is at least 1 non external result document
+ if (content.getProgressState() != ProgressState.APPROVED)
+ return false;
+ }
+ return result;
+ } else { // Check if all existing knowledges are approved
+ List<KnowledgeElement> kelm = ((Scenario) owner)
+ .getAllKnowledgeElements();
+ if (kelm.isEmpty())
+ return false;
+ for (Iterator<KnowledgeElement> i = kelm.iterator(); i.hasNext();) {
+ KnowledgeElement content = i.next();
+ if (content.getProgressState() != ProgressState.APPROVED)
+ return false;
+ }
+ return true;
+ }
+ }
- public boolean add (Publication newdoc) {
-// ------------------------------------------
- if (!owner.add(newdoc)) return false; // Updates the study in memory
- docums.add(0, newdoc); // Updates this step
- newdoc.value().hold(); // Increments the configuration tag count of document
-// If not yet saved, the Publication MUST NOT be saved here, although this creates a temporary inconsistent state into the
-// database (it will be saved later by cascading the update of owner scenario).
- return true;
- }
+ public boolean mayContain(@SuppressWarnings("rawtypes")
+ Class type) {
+ return step.mayContain(type);
+ }
- public boolean remove (Publication oldoc) {
-// --------------------------------------------
- if (!owner.remove(oldoc)) return false; // Updates the study in memory
- docums.remove(oldoc); // Updates this step
- oldoc.value().release(); // Decrements the configuration tag count of document
-// The publication becoming orphan, it should automatically be removed from the database when updating of owner scenario.
- return true;
- }
+ public void setActor(User user) {
+ actor = user;
+ }
- public List<SimulationContext> getContex() {
+ public List<SimulationContext> getContex() {
return contex;
}
import org.splat.dal.bo.som.ProjectElement;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.Study;
+import org.splat.service.ServiceLocatorImpl;
public class StepRights {
private User user;
private Step operand;
-
-// ==============================================================================================================================
-// Construction
-// ==============================================================================================================================
-
- public StepRights (User user, Step step) {
+ public StepRights (User user, Step step) {
// ----------------------------------------
this.user = user;
this.operand = step;
public boolean canAddComment () {
// -------------------------------
Study owner = operand.getOwnerStudy();
- return (owner.getAuthor().equals(user) || owner.hasActor(user));
+ return (owner.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, user));
}
/**
public boolean canCreateDocument () {
// -----------------------------------
if (!isEnabled()) return false;
- return operand.getOwnerStudy().isStaffedBy(user);
+ return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand.getOwnerStudy(), user);
}
/**
*/
public boolean canCreateKnowledge () {
// ------------------------------------
- return operand.getOwnerStudy().isStaffedBy(user);
+ return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand.getOwnerStudy(), user);
}
/**
public boolean canEditSimulationContext () {
// ------------------------------------------
Study owner = operand.getOwnerStudy();
- return (owner.getAuthor().equals(user) || owner.hasActor(user));
+ return (owner.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(owner, user));
}
/**
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.bo.som.Study;
+import org.splat.service.ServiceLocatorImpl;
public class StudyRights {
private User user;
private Study operand;
private boolean author = false; // For optimizing
-
-// ==============================================================================================================================
-// Construction
-// ==============================================================================================================================
-
- public StudyRights (User user, Study study) {
+ public StudyRights (User user, Study study) {
// -------------------------------------------
this.user = user;
this.operand = study;
public boolean canAddScenario () {
// --------------------------------
if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
- return operand.isStaffedBy(user);
+ return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand, user);
}
/**
*/
public boolean canEditDescription () {
// ------------------------------------
- return (operand.getAuthor().equals(user) || operand.hasActor(user));
+ return (operand.getAuthor().equals(user) || ServiceLocatorImpl.getInstance().getStudyService().hasActor(operand, user));
}
public boolean canEditProperties () {
public boolean canVersion () {
// ----------------------------
if (operand.getProgressState() != ProgressState.inWORK && operand.getProgressState() != ProgressState.inDRAFT) return false;
- return operand.isStaffedBy(user);
+ return ServiceLocatorImpl.getInstance().getStudyService().isStaffedBy(operand, user);
}
// ==============================================================================================================================
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 05.10.2012
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+ <bean id="serviceLocator"
+ class="org.splat.service.ServiceLocatorImpl"
+ factory-method="getInstance">
+ <property name="studyService" ref="studyService" />
+ </bean>
+
<bean id="projectElementService"
class="org.splat.service.ProjectElementServiceImpl">
<property name="projectSettings" ref="projectSettings" />
<bean id="documentTypeService"
class="org.splat.service.DocumentTypeServiceImpl">
- <property name="projectSettings" ref="projectSettings" />
+ <property name="documentTypeDAO" ref="documentTypeDAO" />
</bean>
<bean id="documentService"
class="org.splat.service.DocumentServiceImpl">
<property name="projectSettings" ref="projectSettings" />
<property name="studyService" ref="studyService" />
- <property name="documentDAO" ref="documentDAO" />
- <property name="repositoryService" ref="repositoryService" />
+ <property name="documentDAO" ref="documentDAO" />
+ <property name="documentTypeDAO" ref="documentTypeDAO" />
+ <property name="repositoryService" ref="repositoryService" />
+ <property name="fileDAO" ref="fileDAO" />
</bean>
<bean id="knowledgeElementService"
class="org.splat.service.KnowledgeElementServiceImpl">
<property name="indexService" ref="indexService" />
<property name="knowledgeElementDAO" ref="knowledgeElementDAO" />
+ <property name="studyService" ref="studyService" />
+ </bean>
+
+ <bean id="knowledgeElementTypeService"
+ class="org.splat.service.KnowledgeElementTypeServiceImpl">
+ <property name="knowledgeElementTypeDAO"
+ ref="knowledgeElementTypeDAO" />
</bean>
<bean id="publicationService"
class="org.splat.service.PublicationServiceImpl">
- <property name="documentTypeService" ref="documentTypeService" />
+ <property name="documentService" ref="documentService" />
<property name="projectElementService"
ref="projectElementService" />
<property name="stepService" ref="stepService" />
<property name="studyService" ref="studyService" />
+ <property name="publicationDAO" ref="publicationDAO" />
+ <property name="projectElementDAO" ref="projectElementDAO" />
</bean>
<bean id="scenarioService"
ref="projectElementService" />
<property name="publicationService" ref="publicationService" />
<property name="stepService" ref="stepService" />
+ <property name="studyService" ref="studyService" />
<property name="knowledgeElementDAO" ref="knowledgeElementDAO" />
- <property name="scenarioDAO" ref="scenarioDAO" />
+ <property name="scenarioDAO" ref="scenarioDAO" />
+ <property name="knowledgeElementTypeService"
+ ref="knowledgeElementTypeService" />
</bean>
<bean id="searchService"
<bean id="stepService" class="org.splat.service.StepServiceImpl">
<property name="indexService" ref="indexService" />
- <property name="documentDAO" ref="documentDAO" />
- <property name="documentService" ref="documentService" />
- <property name="simulationContextService"
- ref="simulationContextService" />
- <property name="simulationContextDAO"
- ref="simulationContextDAO" />
- <property name="projectElementDAO"
- ref="projectElementDAO" />
+ <property name="documentDAO" ref="documentDAO" />
+ <property name="fileDAO" ref="fileDAO" />
+ <property name="documentService" ref="documentService" />
+ <property name="documentTypeService" ref="documentTypeService" />
+ <property name="simulationContextService"
+ ref="simulationContextService" />
+ <property name="simulationContextDAO"
+ ref="simulationContextDAO" />
+ <property name="projectElementDAO" ref="projectElementDAO" />
</bean>
<bean id="simulationContextService"
<property name="projectElementService"
ref="projectElementService" />
<property name="projectSettings" ref="projectSettings" />
- <property name="scenarioService" ref="scenarioService" />
<property name="stepService" ref="stepService" />
<property name="studyDAO" ref="studyDAO" />
<property name="scenarioDAO" ref="scenarioDAO" />
- <property name="IDBuilderDAO" ref="iDBuilderDAO" />
- <property name="validationCycleDAO" ref="validationCycleDAO" />
+ <property name="IDBuilderDAO" ref="iDBuilderDAO" />
+ <property name="validationCycleDAO" ref="validationCycleDAO" />
+ <property name="documentTypeService" ref="documentTypeService" />
</bean>
+ <bean id="userRights" abstract="true" scope="session">
+ <property name="studyService" ref="studyService" />
+ </bean>
</beans>
\ No newline at end of file
<bean id="projectSettings"
class="org.splat.service.technical.ProjectSettingsServiceImpl">
- <property name="database" ref="database" />
- <property name="simulationContextService" ref="simulationContextService" />
+ <property name="database" ref="database" />
+ <property name="simulationContextService"
+ ref="simulationContextService" />
+ <property name="documentTypeService" ref="documentTypeService" />
+ <property name="knowledgeElementTypeService"
+ ref="knowledgeElementTypeService" />
</bean>
<bean id="indexService"
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 12 Oct 2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 12 Oct 2012
/*****************************************************************************
- * Company EURIWARE
+ * Company OPEN CASCADE
* Application SIMAN
* File $Id$
* Creation date 12 Oct 2012
import org.hibernate.Transaction;
import org.splat.kernel.Do;
import org.splat.dal.bo.kernel.User;
+import org.splat.service.DocumentTypeService;
import org.splat.service.PublicationService;
import org.splat.service.ScenarioService;
import org.splat.service.SimulationContextService;
* Injected step service.
*/
private StepService _stepService;
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
/**
* Injected repository service.
*/
mystudy = getOpenStudy();
User user = getConnectedUser();
Step step = mystudy.getSelectedStep();
- DocumentType type = Document.selectType(doctype);
+ DocumentType type = getDocumentTypeService().selectType(doctype);
// File updir = Database.getDownloadDirectory(user);
// File upfile = new File(updir.getPath() + "/" + filename);
String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
- // between users
+ // between users
File upfile = new File(upath + filename);
String[] table = filename.split("\\x2E");
String format = table[table.length - 1];
// 1. Conversion of the document to internal format, if required
// TODO: The following code is temporary, waiting for the support of converters
if (format.equals("part")) {
- ConvertsRelation export = credoc.attach("brep");
+ ConvertsRelation export = getPublicationService().attach(
+ credoc, "brep");
target = export.getTo().asFile();
if (target.exists())
// File updir = Database.getDownloadDirectory(user);
// File upfile = new File(updir.getPath() + "/" + filename);
String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
- // between users
+ // between users
File upfile = new File(upath + filename);
String[] table = filename.split("\\x2E");
String format = table[table.length - 1];
// 1. Conversion of the document to internal format, if required
// TODO: The following code is temporary, waiting for the support of converters
if (format.equals("part")) {
- ConvertsRelation export = next.attach("brep");
+ ConvertsRelation export = getPublicationService().attach(next,
+ "brep");
String fname = table[0];
for (int i = 1; i < table.length - 1; i++)
SimulationContextService simulationContextService) {
_simulationContextService = simulationContextService;
}
+
+ /**
+ * Get the documentTypeService.
+ *
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
}
\ No newline at end of file
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.ProgressState;
+import org.splat.service.DocumentTypeService;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.som.Step;
import org.splat.wapp.SimpleMenu;
import org.splat.wapp.ToolBar;
-
public class ApplicationSettings {
- private String wappserver;
- private String wappname;
- private Properties wapprops; // General properties from the application properties files
- private Locale locale; // Current user locale
- private Map<String,SimpleMenu> menus = null; // Application menus
- private Map<Integer,ToolBar> bars = null; // Study module-bars structured by steps
- private Map<String,PopupMenu> popups = null;
- private Map<String,Map<String,Object>> filter = null; // Named search filters
- private Map<String,DocumentType> defdoctype = null; // Default document types structured by step.formats
- private Map<String,String> tempfile = null; // Available template files
- private String[] viewermap = null; // List of file extensions mapped to a viewer
- private Map<String,Converter> convertmap = null; // Available document format converters
- private Properties jndprops = null; // JNDI context for launching converters
-
- private static ApplicationSettings my = null; // Singleton instance
/**
* Application settings logger.
*/
- protected final static Logger logger = Logger.getLogger(ApplicationSettings.class);
-
+ protected final static Logger logger = Logger
+ .getLogger(ApplicationSettings.class);
+
+ private String wappserver;
+ private String wappname;
+ private Properties wapprops; // General properties from the application properties files
+ private Locale locale; // Current user locale
+ private Map<String, SimpleMenu> menus = null; // Application menus
+ private Map<Integer, ToolBar> bars = null; // Study module-bars structured by steps
+ private Map<String, PopupMenu> popups = null;
+ private Map<String, Map<String, Object>> filter = null; // Named search filters
+ private Map<String, DocumentType> defdoctype = null; // Default document types structured by step.formats
+ private Map<String, String> tempfile = null; // Available template files
+ private String[] viewermap = null; // List of file extensions mapped to a viewer
+ private Map<String, Converter> convertmap = null; // Available document format converters
+ private Properties jndprops = null; // JNDI context for launching converters
+
+ private static ApplicationSettings my = null; // Singleton instance
/**
* Injected project settings service.
*/
- private ProjectSettingsService _projectSettingsService;
+ private ProjectSettingsService _projectSettingsService;
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
/**
* Get the projectSettingsService.
+ *
* @return the projectSettingsService
*/
public ProjectSettingsService getProjectSettings() {
return _projectSettingsService;
}
+
/**
* Set the projectSettingsService.
- * @param projectSettingsService the projectSettingsService to set
+ *
+ * @param projectSettingsService
+ * the projectSettingsService to set
*/
- public void setProjectSettings(
- ProjectSettingsService projectSettingsService) {
+ public void setProjectSettings(ProjectSettingsService projectSettingsService) {
_projectSettingsService = projectSettingsService;
}
- private static class NewMenu extends SimpleMenu {
-// -----------------------------------------------------------------
- private NewMenu ()
- {
- super("create");
- addItem("new-empty", "menu.new.empty", "image.empty.png", "select?menu=create&item=new-empty");
- addItem("new-copy", new MenuItem("menu.new.copy").icon("image.copy.png") );
- addItem("new-instance", new MenuItem("menu.new.instance").icon("image.hold.gif") );
- addItem("new-import", new MenuItem("menu.new.import").icon("icon.upload.png") );
- this.selects("new-empty");
- }
- }
- private static class SearchMenu extends SimpleMenu {
-// -----------------------------------------------------------------
- private SearchMenu ()
- {
- super("search");
- addItem("search-study", "menu.search.study", "image.study.png", "select?menu=search&item=search-study");
- addItem("search-knowledge", "menu.search.idea", "image.idea.png", "select?menu=search&item=search-knowledge");
- addItem("search-document", new MenuItem("menu.search.document").icon("icon.any.png") );
- this.selects("search-study");
- }
- }
- private static class PropertiesMenu extends SimpleMenu {
-// -----------------------------------------------------------------
- private PropertiesMenu ()
- {
- super("configuration");
- addItem("prop-general", "menu.prop.general", "image.hold.gif", "select?menu=properties&item=prop-general");
- addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif", "select?menu=properties&item=prop-scenario");
- addItem("prop-timestamp", new MenuItem("menu.prop.timestamp").icon("image.stamp.png") );
- addItem("prop-comlog", new MenuItem("menu.prop.comlog").icon("image.hold.gif") );
- addItem("prop-version", new MenuItem("menu.prop.version").icon("image.dirclosed.png") );
- }
- }
- private static class DatadminMenu extends SimpleMenu {
-// -----------------------------------------------------------------
- private DatadminMenu ()
- {
- super("datadmin");
- addItem("admin-scontext", "menu.admin.context", "image.hold.gif", "select?menu=datadmin&item=admin-scontext");
- addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png", "select?menu=datadmin&item=admin-knowelm");
- addItem("admin-study", new MenuItem("menu.admin.study").icon("image.study.png") );
- }
- }
- private static class SysadminMenu extends SimpleMenu {
-// -----------------------------------------------------------------
- private SysadminMenu ()
- {
- super("sysadmin");
- addItem("admin-indexing", "menu.admin.indexing", "image.index.png", "select?menu=sysadmin&item=admin-indexing");
- addItem("admin-importuser", "menu.admin.importuser", "image.group.png", "select?menu=sysadmin&item=admin-importuser");
- }
- }
- private enum Item { publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge };
-// Resources relative to studies
- private static class EditableStudyPopup extends PopupMenu {
-// ----------------------------------------------------------------
- private StudyRights user = null;
-
- private EditableStudyPopup ()
- {
- addItem("publish", new PopupItem("menu.publish").icon("image.publish.png").action("edit-study?action=publish").confirmation("message.publish.study"));
- addItem("promote", new PopupItem("menu.archive"));
- addSeparator();
- addItem("edit", new PopupItem("menu.properties").icon("icon.ed.png").action("../select?menu=properties"));
- addSeparator();
- addItem("script", new PopupItem("menu.newscenario").action("add-scenario"));
- addItem("version", new PopupItem("menu.version").icon("image.version.png").action("notyetimplemented"));
- addSeparator();
- addItem("purge", new PopupItem("menu.purge").confirmation("message.purge.study"));
- addItem("export", new PopupItem("menu.export").icon("image.export.png")); // For future needs
- addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("notyetimplemented").confirmation("message.delete.study"));
- }
- public boolean isEnabled (String name)
- {
- if (user == null) return false; // Should not happen
- Item item = Item.valueOf(name);
- if (item == Item.publish) return user.canPublish();
- if (item == Item.edit) return user.canEditProperties();
- if (item == Item.script) return user.canAddScenario();
- if (item == Item.version) return user.canVersion();
- if (item == Item.remove) return user.canRemove();
- if (item == Item.purge) return user.canPurge();
- return false;
- }
- public void setContext (String name, Object context)
- {
- if (context instanceof StudyRights) {
- user = (StudyRights)context; // Just for optimizing
- boolean history = user.getOperand().isVersioned();
- PopupItem item = this.item("remove");
- if (history) item.rename("menu.remove.version");
- else item.rename("menu.remove.study");
- }
- }
- }
-// Resources relative to documents
- private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
-// ----------------------------------------------------------------
- private DocumentRights user = null;
-
- private EditableDocumentPopup ()
- {
- addItem("accept", new PopupItem("menu.accept").icon("image.accept.png").action("setDocument?action=accept").confirmation("message.accept.document"));
- addItem("promote", new PopupItem("menu.promote").icon("image.publish.png").action("setDocument?action=promote").confirmation("message.promote.document"));
- addSeparator();
- addItem("rename", new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
- addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
- addSeparator();
- addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
- addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
- addSeparator();
- addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
- addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
- }
- public boolean isEnabled (String name)
- {
- if (user == null) return false; // Should not happen
- Item item = Item.valueOf(name);
- if (item == Item.accept) return user.canAccept();
- if (item == Item.promote) return user.canPromote();
- if (item == Item.rename) return user.canRename();
- if (item == Item.attach) return user.canAttach();
- if (item == Item.version) return user.canVersion();
- if (item == Item.replace) return user.canReplace();
- if (item == Item.purge) return user.canPurge();
- if (item == Item.remove) return user.canRemove();
- return false;
- }
- public void setContext (String name, Object context)
- {
- if (context instanceof DocumentRights) {
- user = (DocumentRights)context; // Just for optimizing
- Document downer = user.getOperand();
- PopupItem item = this.item("remove");
- if (downer.isVersioned()) item.rename("menu.remove.version");
- else item.rename("menu.remove.document");
- }
- }
- }
- private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
-// ----------------------------------------------------------------
- private DocumentRights user = null;
-
- private ReviewableDocumentPopup ()
- {
- addItem("demote", new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
- addItem("promote", new PopupItem("menu.review").icon("image.review.png").action("setDocument?action=review").confirmation("message.review.document"));
- addSeparator();
- addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
- addSeparator();
- addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
- addSeparator();
- addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
- }
- public boolean isEnabled (String name)
- {
- if (user == null) return false; // Should not happen
- Item item = Item.valueOf(name);
- if (item == Item.demote) return user.canDemote();
- if (item == Item.promote) return user.canReview();
- if (item == Item.attach) return user.canAttach();
- if (item == Item.version) return user.canVersion();
- if (item == Item.purge) return user.canPurge();
- return false;
- }
- public void setContext (String name, Object context)
- {
- if (context instanceof DocumentRights) {
- user = (DocumentRights)context; // Just for optimizing
- }
- }
- }
- private static class NotResultDocumentPopup extends PopupMenu {
-// ----------------------------------------------------------------
- private DocumentRights user = null;
-
- private NotResultDocumentPopup ()
- {
- addItem("demote", new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
- addSeparator();
- addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
- addSeparator();
- addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
- addSeparator();
- addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
- addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
- }
- }
- private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
-// ----------------------------------------------------------------
- private DocumentRights user = null;
-
- private ApprovableDocumentPopup ()
- {
- addItem("undo", new PopupItem("menu.demote").icon("image.invalidate.png").action("setDocument?action=invalidate").confirmation("message.demote.document"));
- addItem("demote", new PopupItem("menu.disapprove").icon("image.demote.png").action("setDocument?action=disapprove").confirmation("message.disapprove.document"));
- addItem("approve", new PopupItem("menu.approve").icon("icon.APPROVED.png").action("setDocument?action=approve").confirmation("message.approve.document"));
- }
- public boolean isEnabled (String name)
- {
- if (user == null) return false; // Should not happen
- Item item = Item.valueOf(name);
- if (item == Item.undo) return user.canInvalidate();
- if (item == Item.demote) return user.canDemote();
- if (item == Item.approve) return user.canApprove();
- return false;
- }
- public void setContext (String name, Object context)
- {
- if (context instanceof DocumentRights) {
- user = (DocumentRights)context; // Just for optimizing
- }
- }
- }
- private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
-// ----------------------------------------------------------------
- private ApprovedPopup ()
- {
- addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
- addSeparator();
- addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
- }
- }
- private static class ExternPopup extends PopupMenu { // Popup of Extern documents
-// ----------------------------------------------------------------
- private DocumentRights user = null;
-
- private ExternPopup ()
- {
- addItem("rename", new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
- addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
- addSeparator();
- addItem("remove", new PopupItem("menu.remove.document").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
- }
- public boolean isEnabled (String name)
- {
- if (user == null) return false; // Should not happen
- Item item = Item.valueOf(name);
- if (item == Item.rename) return user.canRename();
- if (item == Item.replace) return user.canReplace();
- if (item == Item.remove) return user.canRemove();
- return false;
- }
- public void setContext (String name, Object context)
- {
- if (context instanceof DocumentRights) {
- user = (DocumentRights)context; // Just for optimizing
- }
- }
- }
-// Resources relative to simulation contexts
- private static class ScontextPopup extends PopupMenu {
-// --------------------------------------------------------
- private SimulationContextFacade owner = null;
-
- private ScontextPopup ()
- {
- addItem("rename", new PopupItem("menu.rename").action("edit-context?action=renameContext"));
- addItem("edit", new PopupItem("menu.edit").action("edit-context?action=editContext"));
- addSeparator();
- addItem("remove", new PopupItem("menu.remove").icon("icon.delete.png").action("remove-context").confirmation("message.delete.context"));
- }
- public boolean isEnabled (String name)
- {
- Item item = Item.valueOf(name);
-
- if (item == Item.rename) {
- return false;
- } else
- if (item == Item.edit) {
-// if (!owner.isEditable())
- return false;
- }
- return true;
- }
- public void setContext (String name, Object context)
- {
- if (context instanceof SimulationContextFacade) {
- owner = (SimulationContextFacade)context; // Just for optimizing
- }
- else {
- super.setContext(name, context);
- }
- }
- }
-// Resources relative to knowledge
- private static class FeedbexPopup extends PopupMenu {
-// --------------------------------------------------------
- private KnowledgeElement owner = null;
-
- private FeedbexPopup ()
- {
- addItem("promote", new PopupItem("menu.promote").icon("image.review.png").action("promote-knowledge").confirmation("message.promote.knowledge"));
- addItem("demote", new PopupItem("menu.demote").icon("image.invalidate.png").action("demote-knowledge").confirmation("message.demote.knowledge"));
- addSeparator();
- addItem("rename", new PopupItem("menu.rename").action("edit-knowledge?action=renameKnowledge"));
- addItem("edit", new PopupItem("menu.edit").action("edit-knowledge?action=editKnowledge"));
- addSeparator();
- addItem("remove", new PopupItem("menu.remove").icon("icon.delete.png").action("remove-knowledge").confirmation("message.delete.knowledge"));
- }
- public boolean isEnabled (String name)
- {
- Item item = Item.valueOf(name);
-
- if (item == Item.promote) {
- if (owner.getProgressState() != ProgressState.inDRAFT) return false;
- } else
- if (item == Item.demote) {
- if (owner.getProgressState() != ProgressState.inCHECK) return false;
- }
- return true;
- }
- public void setContext (String name, Object context)
- {
- if (context instanceof KnowledgeElement) owner = (KnowledgeElement)context; // Just for optimizing
- else {
- super.setContext(name, context);
- }
- }
- }
-
-// ==============================================================================================================================
-// Construction
-// ==============================================================================================================================
-
- public static ApplicationSettings getMe () {
-// ------------------------------------------
- return my; // The application is supposed being previously created below
- }
+ private static class NewMenu extends SimpleMenu {
+ // -----------------------------------------------------------------
+ private NewMenu() {
+ super("create");
+ addItem("new-empty", "menu.new.empty", "image.empty.png",
+ "select?menu=create&item=new-empty");
+ addItem("new-copy", new MenuItem("menu.new.copy")
+ .icon("image.copy.png"));
+ addItem("new-instance", new MenuItem("menu.new.instance")
+ .icon("image.hold.gif"));
+ addItem("new-import", new MenuItem("menu.new.import")
+ .icon("icon.upload.png"));
+ this.selects("new-empty");
+ }
+ }
+
+ private static class SearchMenu extends SimpleMenu {
+ // -----------------------------------------------------------------
+ private SearchMenu() {
+ super("search");
+ addItem("search-study", "menu.search.study", "image.study.png",
+ "select?menu=search&item=search-study");
+ addItem("search-knowledge", "menu.search.idea", "image.idea.png",
+ "select?menu=search&item=search-knowledge");
+ addItem("search-document", new MenuItem("menu.search.document")
+ .icon("icon.any.png"));
+ this.selects("search-study");
+ }
+ }
+
+ private static class PropertiesMenu extends SimpleMenu {
+ // -----------------------------------------------------------------
+ private PropertiesMenu() {
+ super("configuration");
+ addItem("prop-general", "menu.prop.general", "image.hold.gif",
+ "select?menu=properties&item=prop-general");
+ addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif",
+ "select?menu=properties&item=prop-scenario");
+ addItem("prop-timestamp", new MenuItem("menu.prop.timestamp")
+ .icon("image.stamp.png"));
+ addItem("prop-comlog", new MenuItem("menu.prop.comlog")
+ .icon("image.hold.gif"));
+ addItem("prop-version", new MenuItem("menu.prop.version")
+ .icon("image.dirclosed.png"));
+ }
+ }
+
+ private static class DatadminMenu extends SimpleMenu {
+ // -----------------------------------------------------------------
+ private DatadminMenu() {
+ super("datadmin");
+ addItem("admin-scontext", "menu.admin.context", "image.hold.gif",
+ "select?menu=datadmin&item=admin-scontext");
+ addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
+ "select?menu=datadmin&item=admin-knowelm");
+ addItem("admin-study", new MenuItem("menu.admin.study")
+ .icon("image.study.png"));
+ }
+ }
+
+ private static class SysadminMenu extends SimpleMenu {
+ // -----------------------------------------------------------------
+ private SysadminMenu() {
+ super("sysadmin");
+ addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
+ "select?menu=sysadmin&item=admin-indexing");
+ addItem("admin-importuser", "menu.admin.importuser",
+ "image.group.png",
+ "select?menu=sysadmin&item=admin-importuser");
+ }
+ }
+
+ private enum Item {
+ publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge
+ };
+
+ // Resources relative to studies
+ private static class EditableStudyPopup extends PopupMenu {
+ // ----------------------------------------------------------------
+ private StudyRights user = null;
+
+ private EditableStudyPopup() {
+ addItem("publish", new PopupItem("menu.publish").icon(
+ "image.publish.png").action("edit-study?action=publish")
+ .confirmation("message.publish.study"));
+ addItem("promote", new PopupItem("menu.archive"));
+ addSeparator();
+ addItem("edit", new PopupItem("menu.properties")
+ .icon("icon.ed.png").action("../select?menu=properties"));
+ addSeparator();
+ addItem("script", new PopupItem("menu.newscenario")
+ .action("add-scenario"));
+ addItem("version", new PopupItem("menu.version").icon(
+ "image.version.png").action("notyetimplemented"));
+ addSeparator();
+ addItem("purge", new PopupItem("menu.purge")
+ .confirmation("message.purge.study"));
+ addItem("export", new PopupItem("menu.export")
+ .icon("image.export.png")); // For future needs
+ addItem("remove", new PopupItem("menu.remove.version").icon(
+ "icon.delete.png").action("notyetimplemented")
+ .confirmation("message.delete.study"));
+ }
+
+ public boolean isEnabled(String name) {
+ if (user == null)
+ return false; // Should not happen
+ Item item = Item.valueOf(name);
+ if (item == Item.publish)
+ return user.canPublish();
+ if (item == Item.edit)
+ return user.canEditProperties();
+ if (item == Item.script)
+ return user.canAddScenario();
+ if (item == Item.version)
+ return user.canVersion();
+ if (item == Item.remove)
+ return user.canRemove();
+ if (item == Item.purge)
+ return user.canPurge();
+ return false;
+ }
+
+ public void setContext(String name, Object context) {
+ if (context instanceof StudyRights) {
+ user = (StudyRights) context; // Just for optimizing
+ boolean history = user.getOperand().isVersioned();
+ PopupItem item = this.item("remove");
+ if (history)
+ item.rename("menu.remove.version");
+ else
+ item.rename("menu.remove.study");
+ }
+ }
+ }
+
+ // Resources relative to documents
+ private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
+ // ----------------------------------------------------------------
+ private DocumentRights user = null;
+
+ private EditableDocumentPopup() {
+ addItem("accept", new PopupItem("menu.accept").icon(
+ "image.accept.png").action("setDocument?action=accept")
+ .confirmation("message.accept.document"));
+ addItem("promote", new PopupItem("menu.promote").icon(
+ "image.publish.png").action("setDocument?action=promote")
+ .confirmation("message.promote.document"));
+ addSeparator();
+ addItem("rename", new PopupItem("menu.rename")
+ .action("edit-document?action=renameDocument"));
+ addItem("attach", new PopupItem("menu.attach").icon(
+ "image.attach.png").action("select-file?nextAction=attach"));
+ addSeparator();
+ addItem("version", new PopupItem("menu.version").icon(
+ "image.version.png").action(
+ "select-file?nextAction=version"));
+ addItem("replace", new PopupItem("menu.replace").icon(
+ "image.replace.png").action(
+ "select-file?nextAction=replace"));
+ addSeparator();
+ addItem("purge", new PopupItem("menu.purge").action(
+ "notyetimplemented").confirmation("message.purge.document"));
+ addItem("remove", new PopupItem("menu.remove.version").icon(
+ "icon.delete.png").action("remove-document").confirmation(
+ "message.delete.document"));
+ }
+
+ public boolean isEnabled(String name) {
+ if (user == null)
+ return false; // Should not happen
+ Item item = Item.valueOf(name);
+ if (item == Item.accept)
+ return user.canAccept();
+ if (item == Item.promote)
+ return user.canPromote();
+ if (item == Item.rename)
+ return user.canRename();
+ if (item == Item.attach)
+ return user.canAttach();
+ if (item == Item.version)
+ return user.canVersion();
+ if (item == Item.replace)
+ return user.canReplace();
+ if (item == Item.purge)
+ return user.canPurge();
+ if (item == Item.remove)
+ return user.canRemove();
+ return false;
+ }
+
+ public void setContext(String name, Object context) {
+ if (context instanceof DocumentRights) {
+ user = (DocumentRights) context; // Just for optimizing
+ Document downer = user.getOperand();
+ PopupItem item = this.item("remove");
+ if (downer.isVersioned())
+ item.rename("menu.remove.version");
+ else
+ item.rename("menu.remove.document");
+ }
+ }
+ }
+
+ private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
+ // ----------------------------------------------------------------
+ private DocumentRights user = null;
+
+ private ReviewableDocumentPopup() {
+ addItem("demote", new PopupItem("menu.demote").icon(
+ "image.demote.png").action("setDocument?action=demote")
+ .confirmation("message.demote.document"));
+ addItem("promote", new PopupItem("menu.review").icon(
+ "image.review.png").action("setDocument?action=review")
+ .confirmation("message.review.document"));
+ addSeparator();
+ addItem("attach", new PopupItem("menu.attach").icon(
+ "image.attach.png").action("select-file?nextAction=attach"));
+ addSeparator();
+ addItem("version", new PopupItem("menu.version").icon(
+ "image.version.png").action(
+ "select-file?nextAction=version"));
+ addSeparator();
+ addItem("purge", new PopupItem("menu.purge").action(
+ "notyetimplemented").confirmation("message.purge.document"));
+ }
+
+ public boolean isEnabled(String name) {
+ if (user == null)
+ return false; // Should not happen
+ Item item = Item.valueOf(name);
+ if (item == Item.demote)
+ return user.canDemote();
+ if (item == Item.promote)
+ return user.canReview();
+ if (item == Item.attach)
+ return user.canAttach();
+ if (item == Item.version)
+ return user.canVersion();
+ if (item == Item.purge)
+ return user.canPurge();
+ return false;
+ }
+
+ public void setContext(String name, Object context) {
+ if (context instanceof DocumentRights) {
+ user = (DocumentRights) context; // Just for optimizing
+ }
+ }
+ }
+
+ private static class NotResultDocumentPopup extends PopupMenu {
+ // ----------------------------------------------------------------
+ private DocumentRights user = null;
+
+ private NotResultDocumentPopup() {
+ addItem("demote", new PopupItem("menu.demote").icon(
+ "image.demote.png").action("setDocument?action=demote")
+ .confirmation("message.demote.document"));
+ addSeparator();
+ addItem("attach", new PopupItem("menu.attach").icon(
+ "image.attach.png").action("select-file?nextAction=attach"));
+ addSeparator();
+ addItem("version", new PopupItem("menu.version").icon(
+ "image.version.png").action(
+ "select-file?nextAction=version"));
+ addSeparator();
+ addItem("purge", new PopupItem("menu.purge").action(
+ "notyetimplemented").confirmation("message.purge.document"));
+ addItem("remove", new PopupItem("menu.remove.version").icon(
+ "icon.delete.png").action("remove-document").confirmation(
+ "message.delete.document"));
+ }
+ }
+
+ private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
+ // ----------------------------------------------------------------
+ private DocumentRights user = null;
+
+ private ApprovableDocumentPopup() {
+ addItem("undo", new PopupItem("menu.demote").icon(
+ "image.invalidate.png").action(
+ "setDocument?action=invalidate").confirmation(
+ "message.demote.document"));
+ addItem("demote", new PopupItem("menu.disapprove").icon(
+ "image.demote.png").action("setDocument?action=disapprove")
+ .confirmation("message.disapprove.document"));
+ addItem("approve", new PopupItem("menu.approve").icon(
+ "icon.APPROVED.png").action("setDocument?action=approve")
+ .confirmation("message.approve.document"));
+ }
+
+ public boolean isEnabled(String name) {
+ if (user == null)
+ return false; // Should not happen
+ Item item = Item.valueOf(name);
+ if (item == Item.undo)
+ return user.canInvalidate();
+ if (item == Item.demote)
+ return user.canDemote();
+ if (item == Item.approve)
+ return user.canApprove();
+ return false;
+ }
+
+ public void setContext(String name, Object context) {
+ if (context instanceof DocumentRights) {
+ user = (DocumentRights) context; // Just for optimizing
+ }
+ }
+ }
+
+ private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
+ // ----------------------------------------------------------------
+ private ApprovedPopup() {
+ addItem("attach", new PopupItem("menu.attach").icon(
+ "image.attach.png").action("select-file?nextAction=attach"));
+ addSeparator();
+ addItem("version", new PopupItem("menu.version").icon(
+ "image.version.png").action(
+ "select-file?nextAction=version"));
+ }
+ }
+
+ private static class ExternPopup extends PopupMenu { // Popup of Extern documents
+ // ----------------------------------------------------------------
+ private DocumentRights user = null;
+
+ private ExternPopup() {
+ addItem("rename", new PopupItem("menu.rename")
+ .action("edit-document?action=renameDocument"));
+ addItem("replace", new PopupItem("menu.replace").icon(
+ "image.replace.png").action(
+ "select-file?nextAction=replace"));
+ addSeparator();
+ addItem("remove", new PopupItem("menu.remove.document").icon(
+ "icon.delete.png").action("remove-document").confirmation(
+ "message.delete.document"));
+ }
+
+ public boolean isEnabled(String name) {
+ if (user == null)
+ return false; // Should not happen
+ Item item = Item.valueOf(name);
+ if (item == Item.rename)
+ return user.canRename();
+ if (item == Item.replace)
+ return user.canReplace();
+ if (item == Item.remove)
+ return user.canRemove();
+ return false;
+ }
+
+ public void setContext(String name, Object context) {
+ if (context instanceof DocumentRights) {
+ user = (DocumentRights) context; // Just for optimizing
+ }
+ }
+ }
+
+ // Resources relative to simulation contexts
+ private static class ScontextPopup extends PopupMenu {
+ // --------------------------------------------------------
+ private SimulationContextFacade owner = null;
+
+ private ScontextPopup() {
+ addItem("rename", new PopupItem("menu.rename")
+ .action("edit-context?action=renameContext"));
+ addItem("edit", new PopupItem("menu.edit")
+ .action("edit-context?action=editContext"));
+ addSeparator();
+ addItem("remove", new PopupItem("menu.remove").icon(
+ "icon.delete.png").action("remove-context").confirmation(
+ "message.delete.context"));
+ }
+
+ public boolean isEnabled(String name) {
+ Item item = Item.valueOf(name);
+
+ if (item == Item.rename) {
+ return false;
+ } else if (item == Item.edit) {
+ // if (!owner.isEditable())
+ return false;
+ }
+ return true;
+ }
+
+ public void setContext(String name, Object context) {
+ if (context instanceof SimulationContextFacade) {
+ owner = (SimulationContextFacade) context; // Just for optimizing
+ } else {
+ super.setContext(name, context);
+ }
+ }
+ }
+
+ // Resources relative to knowledge
+ private static class FeedbexPopup extends PopupMenu {
+ // --------------------------------------------------------
+ private KnowledgeElement owner = null;
+
+ private FeedbexPopup() {
+ addItem("promote", new PopupItem("menu.promote").icon(
+ "image.review.png").action("promote-knowledge")
+ .confirmation("message.promote.knowledge"));
+ addItem("demote", new PopupItem("menu.demote").icon(
+ "image.invalidate.png").action("demote-knowledge")
+ .confirmation("message.demote.knowledge"));
+ addSeparator();
+ addItem("rename", new PopupItem("menu.rename")
+ .action("edit-knowledge?action=renameKnowledge"));
+ addItem("edit", new PopupItem("menu.edit")
+ .action("edit-knowledge?action=editKnowledge"));
+ addSeparator();
+ addItem("remove", new PopupItem("menu.remove").icon(
+ "icon.delete.png").action("remove-knowledge").confirmation(
+ "message.delete.knowledge"));
+ }
+
+ public boolean isEnabled(String name) {
+ Item item = Item.valueOf(name);
+
+ if (item == Item.promote) {
+ if (owner.getProgressState() != ProgressState.inDRAFT)
+ return false;
+ } else if (item == Item.demote) {
+ if (owner.getProgressState() != ProgressState.inCHECK)
+ return false;
+ }
+ return true;
+ }
+
+ public void setContext(String name, Object context) {
+ if (context instanceof KnowledgeElement)
+ owner = (KnowledgeElement) context; // Just for optimizing
+ else {
+ super.setContext(name, context);
+ }
+ }
+ }
+
+ // ==============================================================================================================================
+ // Construction
+ // ==============================================================================================================================
+
+ public static ApplicationSettings getMe() {
+ // ------------------------------------------
+ return my; // The application is supposed being previously created below
+ }
+
/**
* @param wappurl
* @param lang
* @return
*/
- public ApplicationSettings init(String wappurl, Locale lang) throws IOException {
- ClassLoader cloader = getClass().getClassLoader();
- String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
-
- locale = lang;
- wappserver = wurl[2];
- wappname = wurl[3];
- wapprops = new Properties();
- jndprops = new Properties();
- wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
- jndprops.load(cloader.getResourceAsStream("jndi.properties"));
-
- logger.info("Application root set to " + wapprops.getProperty("wapp.root"));
- my = this;
- return this;
- }
-
-// ==============================================================================================================================
-// Public member functions
-// ==============================================================================================================================
-
- public void configure (String filename) {
-// ---------------------------------------
-// Non customizable settings
- menus = new HashMap<String, SimpleMenu>();
- SimpleMenu menu = new NewMenu();
- menus.put( menu.getName(), menu );
- menu = new SearchMenu();
- menus.put( menu.getName(), menu );
- menu = new DatadminMenu();
- menus.put( menu.getName(), menu );
- menu = new SysadminMenu();
- menus.put( menu.getName(), menu );
- menu = new PropertiesMenu();
- menus.put( menu.getName(), menu );
-
- popups = new HashMap<String, PopupMenu>();
- popups.put("steditable", new EditableStudyPopup());
- popups.put("editable", new EditableDocumentPopup());
- popups.put("notresult", new NotResultDocumentPopup());
- popups.put("reviewable", new ReviewableDocumentPopup());
- popups.put("approvable", new ApprovableDocumentPopup());
- popups.put("approved", new ApprovedPopup());
- popups.put("extern", new ExternPopup());
- popups.put("scontext", new ScontextPopup());
- popups.put("feedbex", new FeedbexPopup());
-
-// Default customizable mandatory settings
- Map<String, Object> fprop = new HashMap<String, Object>();
- fprop.put("visibility", "PRIVATE");
- fprop.put("matchamong", "all");
- fprop.put("matcontext", "all");
- fprop.put("state", "END");
- fprop.put("author", "0");
- fprop.put("reference", "");
- fprop.put("title", "");
- fprop.put("context", new Vector<SimulationContext>());
-
- Map<String, Object> gprop = new HashMap<String, Object>();
- gprop.put("visibility", "PUBLIC");
- gprop.put("matchamong", "all");
- gprop.put("matcontext", "all");
- gprop.put("type", "2"); //TODO: Get the index from the type name
- gprop.put("author", "0");
- gprop.put("reference", "");
- gprop.put("title", "");
- gprop.put("context", new Vector<SimulationContext>());
-
- defdoctype = new LinkedHashMap<String, DocumentType>();
- tempfile = new HashMap<String, String>();
- viewermap = new String[0];
- convertmap = new HashMap<String, Converter>();
- filter = new HashMap<String, Map<String, Object>>();
- filter.put("study", fprop);
- filter.put("knowledge", gprop);
-
-// Customization (must be done after above default settings)
- File config = new File(filename);
- if (config.exists()) {
- loadCustomization(config); // Sets default document types, installed modules and available templates
- } else {
- logger.info("Could not find the application configuration file \"" + config.getAbsolutePath() + "\", using default settings");
- }
-// Settings based on the customization
- bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
-
- List<ProjectSettingsService.Step> steps = getProjectSettings().getAllSteps();
- for (Iterator<ProjectSettingsService.Step> i=steps.iterator(); i.hasNext();) {
- ProjectSettingsService.Step step = i.next();
- List<String> formats = getDefaultFormats(step);
- if (formats.size() == 0) continue;
-
- ToolBar bar = new ToolBar(24); // Height of the module-bar
- HashSet<String> module = new HashSet<String>(); // For not duplicating modules
- for (Iterator<String> j=formats.iterator(); j.hasNext();) {
- String format = j.next();
- String command = getApplicationProperty("executable." + format);
- if (command == null) continue; // Module not installed
- if (module.contains(command)) continue;
- module.add(command);
- String[] parsed = command.split("/");
- String[] name = parsed[parsed.length-1].split("\\x2E");
- String docname = my.defdoctype.get(step.getNumber() + "." + format).getName();
- if (tempfile.get(docname) == null) { // No available template
- String tool = parsed[parsed.length-1];
- String icon = name[0];
- if (icon.equals("index")) {
- tool = parsed[parsed.length-2];
- icon = "tool." + tool.toLowerCase() + ".png";
- }
- else {
- icon = "tool." + icon.toLowerCase() + ".png";
- }
- File image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
- if (!image.exists()) icon = "tool.any.png";
- bar.addTool(tool, icon, command);
- } else {
- docname = "/jsp/newDocument.jsp?type=" + docname;
- String icon = "tool." + name[0].toLowerCase() + ".png";
- File image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
- if (!image.exists()) icon = "tool.any.png";
- bar.addTool(name[0], icon, command, docname);
- }
- }
- if (!bar.isEmpty()) bars.put(step.getNumber(), bar);
- }
- }
-
- public String getApplicationProperty (String name) {
-// --------------------------------------------------
- return wapprops.getProperty(name); // May be null
- }
-
- public String getApplicationRootPath () {
-// ---------------------------------------
- return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
- }
-
- public String getApplicationURL () {
-// ----------------------------------
- StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/").append(wappname);
- return url.toString();
- }
-
- public Map<String, Object> getFilter (String name) {
-// --------------------------------------------------
- return filter.get(name);
- }
-
- public ToolBar getModuleBar (Step step) {
-// -----------------------------------------
- return bars.get(step.getNumber());
- }
-
- public Properties getNamingProperties () {
-// ----------------------------------------
- return jndprops;
- }
-
-// ==============================================================================================================================
-// Public services
-// ==============================================================================================================================
-
- public static String getApplicationPluginPath () {
-// ------------------------------------------------
- return my.getApplicationRootPath() + "plugin/";
- }
- public static String getApplicationResourcePath () {
-// --------------------------------------------------
- return my.getApplicationRootPath() + "WEB-INF/classes/";
- }
- public static String getApplicationSkinPath () {
-// ----------------------------------------------
- return my.getApplicationRootPath() + "skin/";
- }
- public static Converter getConverter (DocumentType type, String format) {
-// -----------------------------------------------------------------------
- return my.convertmap.get(format + type.getName()); // May be null;
- }
- public static DocumentType getDefaultDocumentType (Step step, String format) {
-// ----------------------------------------------------------------------------
- String[] table = format.split("\\x2E");
- return my.defdoctype.get(step.getNumber() + "." + table[table.length-1]); // May be null
- }
- public static String getDownloadURL (User user) {
-// --------------------------------------------------
- StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/download/").append(user.getUsername()).append("/");
- return url.toString(); // The download Tomcat context is supposed being defined
- }
- public static Locale getCurrentLocale () {
-// ----------------------------------------
- return my.locale;
- }
- public static SimpleMenu getMenu (String name) {
-// ----------------------------------------------
- return my.menus.get(name);
- }
- public static PopupMenu getPopupMenu (String name) {
-// --------------------------------------------------
- return my.popups.get(name);
- }
- public static String getRepositoryURL () {
-// ----------------------------------------
- StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/repository/");
- return url.toString(); // The repository Tomcat context is supposed being defined
- }
- public static Locale[] getSupportedLocales () {
-// ---------------------------------------------
- String[] code = my.wapprops.getProperty("locale.supported").split(",");
- Locale[] result = new Locale[code.length];
- for (int i=0; i<code.length; i++) result[i] = new Locale(code[i]);
- return result;
- }
- public static String[] getViewersMapping () {
-// -------------------------------------------
- return my.viewermap;
- }
- public static String getWebSiteURL () {
-// -------------------------------------
- return my.getApplicationProperty("wapp.website");
- }
- public static String getHelpURL () {
-// ----------------------------------
- return my.getApplicationProperty("wapp.onlinehelp");
- }
-// ==============================================================================================================================
-// Private services
-// ==============================================================================================================================
-
- private List<String> getDefaultFormats (ProjectSettingsService.Step step) {
-// ------------------------------------------------------------------
- Set<String> keys = defdoctype.keySet();
- int number = step.getNumber();
- Vector<String> result = new Vector<String>();
-
- for (Iterator<String> i=keys.iterator(); i.hasNext();) {
- String[] key = i.next().split("\\x2E");
- if (Integer.valueOf(key[0]) != number) continue;
- if (key[1].equals("pdf")) continue; // PDF is not an authoring format
- result.add(key[1]); // Formats are unique
- }
- return result;
- }
-
- private void loadCustomization (File config) {
-// --------------------------------------------
- try {
- DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
- DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
-
- org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
- HashMap<String, Node> children = XDOM.getNamedChildNodes(conf.getDocumentElement());
-
-// Default document types tag
- Node child = children.get("default-doctypes");
- NodeList nlist = child.getChildNodes();
-
- List<DocumentType> listype = Document.selectAllTypes();
- HashMap<String,DocumentType> maptype = new HashMap<String,DocumentType>();
- for (Iterator<DocumentType> i=listype.iterator(); i.hasNext();) {
- DocumentType type = i.next();
- maptype.put(type.getName(), type);
- }
- for (int i=0; i<nlist.getLength(); i++) {
- child = nlist.item(i);
- if (!child.getNodeName().equals("step")) continue;
-
- String nstep = child.getAttributes().getNamedItem("number").getNodeValue();
- NodeList map = child.getChildNodes();
- for (int j=0; j<map.getLength(); j++) {
- child = map.item(j);
- if (!child.getNodeName().equals("mapping")) continue;
- NamedNodeMap natr = child.getAttributes();
- String dext = natr.getNamedItem("extension").getNodeValue();
- String type = natr.getNamedItem("type").getNodeValue();
- defdoctype.put(nstep + "." + dext, maptype.get(type));
- }
- }
-// Modules tag
- child = children.get("modules");
- nlist = child.getChildNodes();
- for (int i=0; i<nlist.getLength(); i++) {
- child = nlist.item(i);
- if (!child.getNodeName().equals("mapping")) continue;
-
- NamedNodeMap natr = child.getAttributes();
- String dext = natr.getNamedItem("extension").getNodeValue();
- String exec = natr.getNamedItem("executable").getNodeValue();
- wapprops.put("executable." + dext, exec);
- }
-// Viewer mappings tag
- child = children.get("viewers");
- viewermap = child.getAttributes().getNamedItem("extension").getNodeValue().split(",");
-
-// Converters tag
- child = children.get("converters");
- nlist = child.getChildNodes();
- for (int i=0; i<nlist.getLength(); i++) {
- child = nlist.item(i);
-
- if (child.getNodeName().equals("geometry")) {
- NamedNodeMap natr = child.getAttributes();
- String from = natr.getNamedItem("from").getNodeValue();
- String to = natr.getNamedItem("to").getNodeValue();
- String exec = natr.getNamedItem("executable").getNodeValue();
- convertmap.put(from + "geometry", new Converter("geometry", from, to, exec));
- }
- }
-
-// Templates tag
- child = children.get("templates");
- nlist = child.getChildNodes();
- for (int i=0; i<nlist.getLength(); i++) {
- child = nlist.item(i);
- if (!child.getNodeName().equals("document")) continue;
-
- NamedNodeMap natr = child.getAttributes();
- String type = natr.getNamedItem("type").getNodeValue();
- String file = natr.getNamedItem("file").getNodeValue();
- tempfile.put(type, file);
- }
- }
- catch (Exception error) {
- logger.info("Error in customization", error);
- }
- }
+ public ApplicationSettings init(String wappurl, Locale lang)
+ throws IOException {
+ ClassLoader cloader = getClass().getClassLoader();
+ String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
+
+ locale = lang;
+ wappserver = wurl[2];
+ wappname = wurl[3];
+ wapprops = new Properties();
+ jndprops = new Properties();
+ wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
+ jndprops.load(cloader.getResourceAsStream("jndi.properties"));
+
+ logger.info("Application root set to "
+ + wapprops.getProperty("wapp.root"));
+ my = this;
+ return this;
+ }
+
+ // ==============================================================================================================================
+ // Public member functions
+ // ==============================================================================================================================
+
+ public void configure(String filename) {
+ // ---------------------------------------
+ // Non customizable settings
+ menus = new HashMap<String, SimpleMenu>();
+ SimpleMenu menu = new NewMenu();
+ menus.put(menu.getName(), menu);
+ menu = new SearchMenu();
+ menus.put(menu.getName(), menu);
+ menu = new DatadminMenu();
+ menus.put(menu.getName(), menu);
+ menu = new SysadminMenu();
+ menus.put(menu.getName(), menu);
+ menu = new PropertiesMenu();
+ menus.put(menu.getName(), menu);
+
+ popups = new HashMap<String, PopupMenu>();
+ popups.put("steditable", new EditableStudyPopup());
+ popups.put("editable", new EditableDocumentPopup());
+ popups.put("notresult", new NotResultDocumentPopup());
+ popups.put("reviewable", new ReviewableDocumentPopup());
+ popups.put("approvable", new ApprovableDocumentPopup());
+ popups.put("approved", new ApprovedPopup());
+ popups.put("extern", new ExternPopup());
+ popups.put("scontext", new ScontextPopup());
+ popups.put("feedbex", new FeedbexPopup());
+
+ // Default customizable mandatory settings
+ Map<String, Object> fprop = new HashMap<String, Object>();
+ fprop.put("visibility", "PRIVATE");
+ fprop.put("matchamong", "all");
+ fprop.put("matcontext", "all");
+ fprop.put("state", "END");
+ fprop.put("author", "0");
+ fprop.put("reference", "");
+ fprop.put("title", "");
+ fprop.put("context", new Vector<SimulationContext>());
+
+ Map<String, Object> gprop = new HashMap<String, Object>();
+ gprop.put("visibility", "PUBLIC");
+ gprop.put("matchamong", "all");
+ gprop.put("matcontext", "all");
+ gprop.put("type", "2"); // TODO: Get the index from the type name
+ gprop.put("author", "0");
+ gprop.put("reference", "");
+ gprop.put("title", "");
+ gprop.put("context", new Vector<SimulationContext>());
+
+ defdoctype = new LinkedHashMap<String, DocumentType>();
+ tempfile = new HashMap<String, String>();
+ viewermap = new String[0];
+ convertmap = new HashMap<String, Converter>();
+ filter = new HashMap<String, Map<String, Object>>();
+ filter.put("study", fprop);
+ filter.put("knowledge", gprop);
+
+ // Customization (must be done after above default settings)
+ File config = new File(filename);
+ if (config.exists()) {
+ loadCustomization(config); // Sets default document types, installed modules and available templates
+ } else {
+ logger.info("Could not find the application configuration file \""
+ + config.getAbsolutePath() + "\", using default settings");
+ }
+ // Settings based on the customization
+ bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
+
+ List<ProjectSettingsService.Step> steps = getProjectSettings()
+ .getAllSteps();
+ for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
+ .hasNext();) {
+ ProjectSettingsService.Step step = i.next();
+ List<String> formats = getDefaultFormats(step);
+ if (formats.size() == 0)
+ continue;
+
+ ToolBar bar = new ToolBar(24); // Height of the module-bar
+ HashSet<String> module = new HashSet<String>(); // For not duplicating modules
+ for (Iterator<String> j = formats.iterator(); j.hasNext();) {
+ String format = j.next();
+ String command = getApplicationProperty("executable." + format);
+ if (command == null)
+ continue; // Module not installed
+ if (module.contains(command))
+ continue;
+ module.add(command);
+ String[] parsed = command.split("/");
+ String[] name = parsed[parsed.length - 1].split("\\x2E");
+ String docname = my.defdoctype.get(
+ step.getNumber() + "." + format).getName();
+ if (tempfile.get(docname) == null) { // No available template
+ String tool = parsed[parsed.length - 1];
+ String icon = name[0];
+ if (icon.equals("index")) {
+ tool = parsed[parsed.length - 2];
+ icon = "tool." + tool.toLowerCase() + ".png";
+ } else {
+ icon = "tool." + icon.toLowerCase() + ".png";
+ }
+ File image = new File(ApplicationSettings
+ .getApplicationSkinPath()
+ + icon);
+ if (!image.exists())
+ icon = "tool.any.png";
+ bar.addTool(tool, icon, command);
+ } else {
+ docname = "/jsp/newDocument.jsp?type=" + docname;
+ String icon = "tool." + name[0].toLowerCase() + ".png";
+ File image = new File(ApplicationSettings
+ .getApplicationSkinPath()
+ + icon);
+ if (!image.exists())
+ icon = "tool.any.png";
+ bar.addTool(name[0], icon, command, docname);
+ }
+ }
+ if (!bar.isEmpty())
+ bars.put(step.getNumber(), bar);
+ }
+ }
+
+ public String getApplicationProperty(String name) {
+ // --------------------------------------------------
+ return wapprops.getProperty(name); // May be null
+ }
+
+ public String getApplicationRootPath() {
+ // ---------------------------------------
+ return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
+ }
+
+ public String getApplicationURL() {
+ // ----------------------------------
+ StringBuffer url = new StringBuffer("http://").append(my.wappserver)
+ .append("/").append(wappname);
+ return url.toString();
+ }
+
+ public Map<String, Object> getFilter(String name) {
+ // --------------------------------------------------
+ return filter.get(name);
+ }
+
+ public ToolBar getModuleBar(Step step) {
+ // -----------------------------------------
+ return bars.get(step.getNumber());
+ }
+
+ public Properties getNamingProperties() {
+ // ----------------------------------------
+ return jndprops;
+ }
+
+ // ==============================================================================================================================
+ // Public services
+ // ==============================================================================================================================
+
+ public static String getApplicationPluginPath() {
+ // ------------------------------------------------
+ return my.getApplicationRootPath() + "plugin/";
+ }
+
+ public static String getApplicationResourcePath() {
+ // --------------------------------------------------
+ return my.getApplicationRootPath() + "WEB-INF/classes/";
+ }
+
+ public static String getApplicationSkinPath() {
+ // ----------------------------------------------
+ return my.getApplicationRootPath() + "skin/";
+ }
+
+ public static Converter getConverter(DocumentType type, String format) {
+ // -----------------------------------------------------------------------
+ return my.convertmap.get(format + type.getName()); // May be null;
+ }
+
+ public static DocumentType getDefaultDocumentType(Step step, String format) {
+ // ----------------------------------------------------------------------------
+ String[] table = format.split("\\x2E");
+ return my.defdoctype.get(step.getNumber() + "."
+ + table[table.length - 1]); // May be null
+ }
+
+ public static String getDownloadURL(User user) {
+ // --------------------------------------------------
+ StringBuffer url = new StringBuffer("http://").append(my.wappserver)
+ .append("/download/").append(user.getUsername()).append("/");
+ return url.toString(); // The download Tomcat context is supposed being defined
+ }
+
+ public static Locale getCurrentLocale() {
+ // ----------------------------------------
+ return my.locale;
+ }
+
+ public static SimpleMenu getMenu(String name) {
+ // ----------------------------------------------
+ return my.menus.get(name);
+ }
+
+ public static PopupMenu getPopupMenu(String name) {
+ // --------------------------------------------------
+ return my.popups.get(name);
+ }
+
+ public static String getRepositoryURL() {
+ // ----------------------------------------
+ StringBuffer url = new StringBuffer("http://").append(my.wappserver)
+ .append("/repository/");
+ return url.toString(); // The repository Tomcat context is supposed being defined
+ }
+
+ public static Locale[] getSupportedLocales() {
+ // ---------------------------------------------
+ String[] code = my.wapprops.getProperty("locale.supported").split(",");
+ Locale[] result = new Locale[code.length];
+ for (int i = 0; i < code.length; i++)
+ result[i] = new Locale(code[i]);
+ return result;
+ }
+
+ public static String[] getViewersMapping() {
+ // -------------------------------------------
+ return my.viewermap;
+ }
+
+ public static String getWebSiteURL() {
+ // -------------------------------------
+ return my.getApplicationProperty("wapp.website");
+ }
+
+ public static String getHelpURL() {
+ // ----------------------------------
+ return my.getApplicationProperty("wapp.onlinehelp");
+ }
+
+ // ==============================================================================================================================
+ // Private services
+ // ==============================================================================================================================
+
+ private List<String> getDefaultFormats(ProjectSettingsService.Step step) {
+ // ------------------------------------------------------------------
+ Set<String> keys = defdoctype.keySet();
+ int number = step.getNumber();
+ Vector<String> result = new Vector<String>();
+
+ for (Iterator<String> i = keys.iterator(); i.hasNext();) {
+ String[] key = i.next().split("\\x2E");
+ if (Integer.valueOf(key[0]) != number)
+ continue;
+ if (key[1].equals("pdf"))
+ continue; // PDF is not an authoring format
+ result.add(key[1]); // Formats are unique
+ }
+ return result;
+ }
+
+ private void loadCustomization(File config) {
+ // --------------------------------------------
+ try {
+ DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
+
+ org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
+ HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
+ .getDocumentElement());
+
+ // Default document types tag
+ Node child = children.get("default-doctypes");
+ NodeList nlist = child.getChildNodes();
+
+ List<DocumentType> listype = getDocumentTypeService()
+ .selectAllTypes();
+ HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
+ for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ maptype.put(type.getName(), type);
+ }
+ for (int i = 0; i < nlist.getLength(); i++) {
+ child = nlist.item(i);
+ if (!child.getNodeName().equals("step"))
+ continue;
+
+ String nstep = child.getAttributes().getNamedItem("number")
+ .getNodeValue();
+ NodeList map = child.getChildNodes();
+ for (int j = 0; j < map.getLength(); j++) {
+ child = map.item(j);
+ if (!child.getNodeName().equals("mapping"))
+ continue;
+ NamedNodeMap natr = child.getAttributes();
+ String dext = natr.getNamedItem("extension").getNodeValue();
+ String type = natr.getNamedItem("type").getNodeValue();
+ defdoctype.put(nstep + "." + dext, maptype.get(type));
+ }
+ }
+ // Modules tag
+ child = children.get("modules");
+ nlist = child.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++) {
+ child = nlist.item(i);
+ if (!child.getNodeName().equals("mapping"))
+ continue;
+
+ NamedNodeMap natr = child.getAttributes();
+ String dext = natr.getNamedItem("extension").getNodeValue();
+ String exec = natr.getNamedItem("executable").getNodeValue();
+ wapprops.put("executable." + dext, exec);
+ }
+ // Viewer mappings tag
+ child = children.get("viewers");
+ viewermap = child.getAttributes().getNamedItem("extension")
+ .getNodeValue().split(",");
+
+ // Converters tag
+ child = children.get("converters");
+ nlist = child.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++) {
+ child = nlist.item(i);
+
+ if (child.getNodeName().equals("geometry")) {
+ NamedNodeMap natr = child.getAttributes();
+ String from = natr.getNamedItem("from").getNodeValue();
+ String to = natr.getNamedItem("to").getNodeValue();
+ String exec = natr.getNamedItem("executable")
+ .getNodeValue();
+ convertmap.put(from + "geometry", new Converter("geometry",
+ from, to, exec));
+ }
+ }
+
+ // Templates tag
+ child = children.get("templates");
+ nlist = child.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++) {
+ child = nlist.item(i);
+ if (!child.getNodeName().equals("document"))
+ continue;
+
+ NamedNodeMap natr = child.getAttributes();
+ String type = natr.getNamedItem("type").getNodeValue();
+ String file = natr.getNamedItem("file").getNodeValue();
+ tempfile.put(type, file);
+ }
+ } catch (Exception error) {
+ logger.info("Error in customization", error);
+ }
+ }
+
+ /**
+ * Get the documentTypeService.
+ *
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
}
\ No newline at end of file
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.service.PublicationService;
+import org.splat.service.StepService;
import org.splat.service.technical.RepositoryService;
import org.splat.som.Step;
* Injected publication service.
*/
private PublicationService _publicationService;
+ /**
+ * Injected step service.
+ */
+ private StepService _stepService;
/**
* Injected repository service.
*/
Publication doc = step.getDocument(Integer.valueOf(index));
if (todo == Execute.renameDocument) {
- doc.rename(title);
+ getPublicationService().rename(doc, title);
// Useless to update the document presentation
} else if (todo == Execute.accept) {
doc.actualize();
String[] parse = filename.split("\\x2E");
Publication edited = step.getDocument(Integer.valueOf(index));
- ConvertsRelation export = edited.attach(parse[parse.length - 1]);
+ ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
if (logger.isInfoEnabled())
logger.info("Moving \"" + upfile.getName() + "\" to \""
Step step = mystudy.getSelectedStep();
Publication doctag = step.getDocument(Integer.valueOf(index));
- step.removeDocument(doctag); // Updates the data structure
+ getStepService().removeDocument(step, doctag); // Updates the data structure
transax.commit();
mystudy.remove(doctag); // Updates the presentation
public void setRepositoryService(RepositoryService repositoryService) {
_repositoryService = repositoryService;
}
+
+ /**
+ * Get the stepService.
+ * @return the stepService
+ */
+ public StepService getStepService() {
+ return _stepService;
+ }
+
+ /**
+ * Set the stepService.
+ * @param stepService the stepService to set
+ */
+ public void setStepService(StepService stepService) {
+ _stepService = stepService;
+ }
}
\ No newline at end of file
package org.splat.simer;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.splat.dal.bo.kernel.User;
-import org.splat.dal.dao.som.Database;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.Scenario;
import org.splat.service.KnowledgeElementService;
+import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.ScenarioService;
import org.splat.som.Step;
-
+/**
+ * Action for addition and modification of knowledge elements in the selected scenario.
+ */
public class EditKnowledgeElementAction extends DisplayStudyStepAction {
- private String type = null; // Edited knowledge type
- private String title = null;
- private String value = null;
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = 4636919137087687068L;
+
+ /**
+ * Edited knowledge element type.
+ */
+ private String type = null; // Edited knowledge type
+ /**
+ * Edited knowledge element title.
+ */
+ private String title = null;
+ /**
+ * Edited knowledge element value.
+ */
+ private String value = null;
+ /**
+ * Injected scenario service.
+ */
private ScenarioService _scenarioService;
+ /**
+ * Injected knowledge element service.
+ */
private KnowledgeElementService _knowledgeElementService;
+ /**
+ * Injected knowledge element type service.
+ */
+ private KnowledgeElementTypeService _knowledgeElementTypeService;
+
+ // ==============================================================================================================================
+ // Action methods
+ // ==============================================================================================================================
/**
- * Serial version ID.
+ * Initialize the action. Get selected study from the session.
+ *
+ * @return SUCCESS if no exceptions
*/
- private static final long serialVersionUID = 4636919137087687068L;
-
-// ==============================================================================================================================
-// Action methods
-// ==============================================================================================================================
-
- public String doInitialize () {
-// -----------------------------
-// Session connex = Database.getSession();
-// Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
-
-// transax.commit();
- return SUCCESS;
- }
-
- public String doSetKnowledge () {
-// -------------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- User user = getConnectedUser();
- mystudy = getOpenStudy();
-
- Step step = mystudy.getSelectedStep();
- Scenario scene = (Scenario)step.getOwner(); // It is necessarily a Scenario
-
- if (title != null && value != null) { // Addition of a new Knowledge Element
- KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
- KnowledgeElementType ktype = KnowledgeElement.selectType(Integer.valueOf(type));
- kprop.setType(ktype)
- .setTitle(title)
- .setValue(value)
- .setAuthor(user);
- mystudy.add( getScenarioService().addKnowledgeElement(scene, kprop) );
- getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
- } else
- if (title != null) { // Renaming of an existing Knowledge Element
- KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
- getKnowledgeElementService().rename(kelm, title);
-// Useless to update the open study
- } else
- if (value != null) { // Edition of a knowledge
- KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
- kelm.update(value);
- mystudy.update(kelm); // For updating the truncated value
- }
- transax.commit();
- return SUCCESS;
- }
- catch (RuntimeException saverror) {
- logger.error("Reason:", saverror);
- if (transax != null && transax.isActive()) {
-// Second try-catch as the rollback could fail as well
- try {
- transax.rollback();
- } catch (HibernateException backerror) {
- logger.debug("Error rolling back transaction", backerror);
- }
- }
- return ERROR;
- }
- catch (Exception error) {
- transax.commit();
- return INPUT;
- }
- }
-
- public String doDeleteKnowledge () {
-// ----------------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- mystudy = getOpenStudy();
- Step step = mystudy.getSelectedStep();
- Scenario scene = (Scenario)step.getOwner(); // It is necessarily a Scenario
-
- KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(myindex));
- scene.removeKnowledgeElement(kelm); // The knowledge element necessarily exists
-
- mystudy.remove(kelm);
- getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
-
- transax.commit();
- return SUCCESS;
- }
- catch (RuntimeException saverror) {
- logger.error("Reason:", saverror);
- if (transax != null && transax.isActive()) {
-// Second try-catch as the rollback could fail as well
- try {
- transax.rollback();
- } catch (HibernateException backerror) {
- logger.debug("Error rolling back transaction", backerror);
- }
- }
- return ERROR;
- }
- }
-
-// ==============================================================================================================================
-// Getters and setters
-// ==============================================================================================================================
-
- public String getKnowledgeType () {
-// ---------------------------------
- return type;
- }
- public String getSelectedKnowledge () {
-// -------------------------------------
- return myindex;
- }
-
- public void setKnowledgeType (String type) {
-// ------------------------------------------
- this.type = type;
- }
- public void setKnowledgeTitle (String title) {
-// --------------------------------------------
- this.title = title;
- }
- public void setKnowledgeValue (String value) {
-// --------------------------------------------
- this.value = value;
- }
+ public String doInitialize() {
+ mystudy = getOpenStudy();
+ return SUCCESS;
+ }
+
+ /**
+ * Add a new or update an existing knowledge element of the selected scenario in the open study.
+ *
+ * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
+ */
+ public String doSetKnowledge() {
+ try {
+ User user = getConnectedUser();
+ mystudy = getOpenStudy();
+
+ Step step = mystudy.getSelectedStep();
+ Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
+
+ if (title != null && value != null) { // Addition of a new Knowledge Element
+ KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
+ KnowledgeElementType ktype = getKnowledgeElementTypeService()
+ .selectType(Integer.valueOf(type));
+ kprop.setType(ktype).setTitle(title).setValue(value).setAuthor(
+ user);
+ mystudy.add(getScenarioService().addKnowledgeElement(scene,
+ kprop));
+ getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
+ } else if (title != null) { // Renaming of an existing Knowledge Element
+ KnowledgeElement kelm = scene.getKnowledgeElement(Integer
+ .valueOf(type));
+ getKnowledgeElementService().rename(kelm, title);
+ // Useless to update the open study
+ } else if (value != null) { // Edition of a knowledge
+ KnowledgeElement kelm = scene.getKnowledgeElement(Integer
+ .valueOf(type));
+ getKnowledgeElementService().update(kelm, value);
+ mystudy.update(kelm); // For updating the truncated value
+ }
+ return SUCCESS;
+ } catch (RuntimeException saverror) {
+ logger.error("Reason:", saverror);
+ return ERROR;
+ } catch (Exception error) {
+ return INPUT;
+ }
+ }
+
+ /**
+ * Delete a knowledge element from the current scenario.
+ *
+ * @return SUCCESS if no exceptions
+ */
+ public String doDeleteKnowledge() {
+ mystudy = getOpenStudy();
+ Step step = mystudy.getSelectedStep();
+ Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
+
+ KnowledgeElement kelm = scene.getKnowledgeElement(Integer
+ .valueOf(myindex));
+ scene.removeKnowledgeElement(kelm); // The knowledge element necessarily exists
+
+ mystudy.remove(kelm);
+ getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
+
+ return SUCCESS;
+ }
+
+ // ==============================================================================================================================
+ // Getters and setters
+ // ==============================================================================================================================
+
+ /**
+ * Get the type of the modified knowledge element.
+ *
+ * @return the knowledge type name
+ */
+ public String getKnowledgeType() {
+ // ---------------------------------
+ return type;
+ }
+
+ /**
+ * Get the id of the modified knowledge element.
+ *
+ * @return the knowledge element id
+ */
+ public String getSelectedKnowledge() {
+ // -------------------------------------
+ return myindex;
+ }
+
+ /**
+ * Set the type of the modified knowledge element.
+ *
+ * @param type
+ * the knowledge type name
+ */
+ public void setKnowledgeType(String type) {
+ // ------------------------------------------
+ this.type = type;
+ }
+
+ /**
+ * Set the title of the modified knowledge element.
+ *
+ * @param title
+ * the new knowledge title
+ */
+ public void setKnowledgeTitle(String title) {
+ // --------------------------------------------
+ this.title = title;
+ }
+
+ /**
+ * Set the value of the modified knowledge element.
+ *
+ * @param value
+ * the knowledge value
+ */
+ public void setKnowledgeValue(String value) {
+ // --------------------------------------------
+ this.value = value;
+ }
+
/**
* Get the scenarioService.
+ *
* @return the scenarioService
*/
public ScenarioService getScenarioService() {
/**
* Set the scenarioService.
- * @param scenarioService the scenarioService to set
+ *
+ * @param scenarioService
+ * the scenarioService to set
*/
public void setScenarioService(ScenarioService scenarioService) {
_scenarioService = scenarioService;
/**
* Get the knowledgeElementService.
+ *
* @return the knowledgeElementService
*/
public KnowledgeElementService getKnowledgeElementService() {
/**
* Set the knowledgeElementService.
- * @param knowledgeElementService the knowledgeElementService to set
+ *
+ * @param knowledgeElementService
+ * the knowledgeElementService to set
*/
public void setKnowledgeElementService(
KnowledgeElementService knowledgeElementService) {
_knowledgeElementService = knowledgeElementService;
}
+
+ /**
+ * Get the knowledgeElementTypeService.
+ * @return the knowledgeElementTypeService
+ */
+ public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+ return _knowledgeElementTypeService;
+ }
+
+ /**
+ * Set the knowledgeElementTypeService.
+ * @param knowledgeElementTypeService the knowledgeElementTypeService to set
+ */
+ public void setKnowledgeElementTypeService(
+ KnowledgeElementTypeService knowledgeElementTypeService) {
+ _knowledgeElementTypeService = knowledgeElementTypeService;
+ }
}
\ No newline at end of file
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.ProgressState;
import org.splat.service.DocumentService;
+import org.splat.service.DocumentTypeService;
import org.splat.service.PublicationService;
import org.splat.service.StepService;
import org.splat.service.technical.ProjectSettingsService;
* Injected document service.
*/
private DocumentService _documentService;
-
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
/**
* Injected repository service.
*/
mystudy = getOpenStudy();
Step step = mystudy.getSelectedStep();
- doctypes = step.getValidDocumentTypes();
+ doctypes = getStepService().getValidDocumentTypes(step);
deftype = ApplicationSettings.getDefaultDocumentType(step, filext);
defuses = new Vector<Document>();
state = ProgressState.inWORK;
mystudy = getOpenStudy();
User user = getConnectedUser();
Step step = mystudy.getSelectedStep();
- DocumentType type = Document.selectType((int)doctype);
+ DocumentType type = getDocumentTypeService().selectType((int)doctype);
File updir = getRepositoryService().getDownloadDirectory(user);
File upfile = new File(updir.getPath() + "/" + filename);
String[] table = filename.split("\\x2E");
public void setRepositoryService(RepositoryService repositoryService) {
_repositoryService = repositoryService;
}
+
+ /**
+ * Get the documentTypeService.
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ * @param documentTypeService the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
}
\ No newline at end of file
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.service.ProjectElementService;
-import org.splat.service.StudyService;
+import org.splat.service.ScenarioService;
import org.splat.som.Step;
import org.splat.dal.bo.som.Study;
import org.splat.wapp.Menu;
private long scindex;
private int bastep;
private ToDo action;
- private StudyService _studyService;
+ /**
+ * Injected scenario service.
+ */
+ private ScenarioService _scenarioService;
+ /**
+ * Injected project element service.
+ */
private ProjectElementService _projectElementService;
private Menu _menu;
step = getProjectElementService().getSteps(bascene);
sprop.setBaseStep(step[number-bastep]);
}
- bascene = getStudyService().addScenario(study, sprop);
+ bascene = getScenarioService().addScenario(study, sprop);
transax.commit();
// Update of the display
// ----------------------------
return (Integer.valueOf(getSharedStep()) > bastep);
}
- /**
- * Get the studyService.
- *
- * @return the studyService
- */
- public StudyService getStudyService() {
- return _studyService;
- }
-
- /**
- * Set the studyService.
- *
- * @param studyService
- * the studyService to set
- */
- public void setStudyService(StudyService studyService) {
- _studyService = studyService;
- }
/**
* Get the projectElementService.
*
public void setMenu(Menu menu) {
_menu = menu;
}
+
+ /**
+ * Get the scenarioService.
+ * @return the scenarioService
+ */
+ public ScenarioService getScenarioService() {
+ return _scenarioService;
+ }
+
+ /**
+ * Set the scenarioService.
+ * @param scenarioService the scenarioService to set
+ */
+ public void setScenarioService(ScenarioService scenarioService) {
+ _scenarioService = scenarioService;
+ }
}
\ No newline at end of file
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.SimulationContextType;
import org.splat.dal.bo.som.Study;
+import org.splat.service.ScenarioService;
import org.splat.service.SimulationContextService;
import org.splat.service.StudyService;
*/
private StudyService _studyService;
private SimulationContextService _simulationContextService;
+ /**
+ * Injected scenario service.
+ */
+ private ScenarioService _scenarioService;
// ==============================================================================================================================
// Action methods
ApplicationSettings.getCurrentLocale());
Scenario.Properties oprop = new Scenario.Properties();
oprop.setTitle(locale.getString("label.scenario") + " 1");
- getStudyService().addScenario(study, oprop);
+ getScenarioService().addScenario(study, oprop);
// Addition of the entered project context
if (valid == 0) { // Input of new project context
SimulationContextService simulationContextService) {
_simulationContextService = simulationContextService;
}
+
+ /**
+ * Get the scenarioService.
+ * @return the scenarioService
+ */
+ public ScenarioService getScenarioService() {
+ return _scenarioService;
+ }
+
+ /**
+ * Set the scenarioService.
+ * @param scenarioService the scenarioService to set
+ */
+ public void setScenarioService(ScenarioService scenarioService) {
+ _scenarioService = scenarioService;
+ }
}
\ No newline at end of file
private KnowledgeElement myknelm;
private String credate;
- private ProjectElementService _projectElementService;
-
public class Menu extends SimpleMenu {
// ------------------------------------
public Menu(List<Step> context) {
return result;
}
- /**
- * Get the projectElementService.
- *
- * @return the projectElementService
- */
- public ProjectElementService getProjectElementService() {
- return _projectElementService;
- }
-
- /**
- * Set the projectElementService.
- *
- * @param projectElementService
- * the projectElementService to set
- */
- public void setProjectElementService(
- ProjectElementService projectElementService) {
- _projectElementService = projectElementService;
- }
-
}
\ No newline at end of file
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.ProgressState;
+import org.splat.service.KnowledgeElementService;
+import org.splat.service.KnowledgeElementTypeService;
+import org.splat.service.ProjectElementService;
import org.splat.service.PublicationService;
import org.splat.service.dto.Proxy;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.wapp.Menu;
import org.splat.wapp.PopupMenu;
-
public abstract class OpenObject implements Proxy {
- protected User cuser = null; // Connected user
- protected String selection = null; // Menu selected by the user
- protected Step ustep = null; // Corresponding selected step
- protected String description = null; // Object description (rich text)
- protected List<Step> involving = null;
- protected List<SimulationContextFacade> context = null; // Simulation Context display representations
- protected List<DocumentFacade> contents = null; // Document display representations
- protected List<KnowledgeIterator> knowledge = null; // Knowledge Element display representations structured by knowledge types
-
- protected Menu menu = null; // Left pane menu of this object
- protected PopupMenu popup = null; // Pop-up menu of this object, if the user has write access
+ protected static HashMap<Long, DocumentFacade> docpres = null;
+ protected static HashMap<Long, KnowledgeElementFacade> knowpres = null;
+
+ protected User cuser = null; // Connected user
+ protected String selection = null; // Menu selected by the user
+ protected Step ustep = null; // Corresponding selected step
+ protected String description = null; // Object description (rich text)
+ protected List<Step> involving = null;
+ protected List<SimulationContextFacade> context = null; // Simulation Context display representations
+ protected List<DocumentFacade> contents = null; // Document display representations
+ protected List<KnowledgeIterator> knowledge = null; // Knowledge Element display representations structured by knowledge types
+
+ protected Menu menu = null; // Left pane menu of this object
+ protected PopupMenu popup = null; // Pop-up menu of this object, if the user has write access
+ /**
+ * Injected project settings service.
+ */
private ProjectSettingsService _projectSettingsService;
+ /**
+ * Injected publication service.
+ */
private PublicationService _publicationService;
-
- protected static HashMap<Long, DocumentFacade> docpres = null;
- protected static HashMap<Long, KnowledgeElementFacade> knowpres = null;
+ /**
+ * Injected knowledge element service.
+ */
+ private KnowledgeElementTypeService _knowledgeElementTypeService;
+ /**
+ * Injected project element service.
+ */
+ private ProjectElementService _projectElementService;
public class KnowledgeIterator {
-// ------------------------------
- protected KnowledgeElementType type;
- protected List<KnowledgeElementFacade> list;
-
- public KnowledgeIterator (KnowledgeElementType type, List<KnowledgeElementFacade> list)
- {
- this.type = type;
- this.list = list;
- }
- public String getIndex ()
- {
- return String.valueOf(type.getIndex());
- }
- public String getType ()
- {
- return type.getName();
- }
- public List<KnowledgeElementFacade> getKnowledgeElements ()
- {
- return list;
- }
+ protected KnowledgeElementType type;
+ protected List<KnowledgeElementFacade> list;
+
+ public KnowledgeIterator(KnowledgeElementType type,
+ List<KnowledgeElementFacade> list) {
+ this.type = type;
+ this.list = list;
+ }
+
+ public String getIndex() {
+ return String.valueOf(type.getIndex());
+ }
+
+ public String getType() {
+ return type.getName();
+ }
+
+ public List<KnowledgeElementFacade> getKnowledgeElements() {
+ return list;
+ }
+ }
+
+ // ==============================================================================================================================
+ // Constructor
+ // ==============================================================================================================================
+
+ protected OpenObject() {
+ // -----------------------
+ // All member fields are supposed initialized by subclasses
+ if (docpres == null)
+ docpres = new HashMap<Long, DocumentFacade>();
+ if (knowpres == null)
+ knowpres = new HashMap<Long, KnowledgeElementFacade>();
+ }
+
+ // ==============================================================================================================================
+ // Public member functions
+ // ==============================================================================================================================
+
+ public void developDocument(String index) {
+ // ------------------------------------------
+ for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
+ DocumentFacade doc = i.next();
+ if (!doc.getIndex().equals(index))
+ continue;
+ doc.develop();
+ return;
+ }
+ }
+
+ public void developKnowledge(String index) {
+ // -------------------------------------------
+ for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
+ List<KnowledgeElementFacade> knowelms = i.next()
+ .getKnowledgeElements();
+ for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
+ .hasNext();) {
+ KnowledgeElementFacade kelm = j.next();
+ if (!kelm.getIndex().equals(index))
+ continue;
+ kelm.develop();
+ return;
+ }
+ }
+ }
+
+ public void clearFacades() {
+ // ---------------------------
+ docpres.clear(); // For eventually reopening the knowledge from a fresh context
+ knowpres.clear(); // For eventually reopening the knowledge from a fresh context
+ }
+
+ public List<Document> collectInvolvedDocuments(DocumentType type) {
+ // ------------------------------------------------------------------
+ List<Document> found = new Vector<Document>();
+ for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
+ Step step = i.next();
+ List<Publication> exist = step.getAllDocuments();
+ for (Iterator<Publication> j = exist.iterator(); j.hasNext();) {
+ Document doc = j.next().value();
+ if (doc.getType().equals(type))
+ found.add(doc);
+ }
+ }
+ return found;
+ }
+
+ public String getDisplayedDescription() {
+ // ----------------------------------------
+ return description;
+ }
+
+ public List<DocumentFacade> getDisplayedDocuments() {
+ // -----------------------------------------------------
+ return contents;
+ }
+
+ public List<SimulationContextFacade> getDisplayedSimulationContexts() {
+ // ----------------------------------------------------------------------
+ return context;
+ }
+
+ public List<KnowledgeIterator> getDisplayedKnowledges() {
+ // --------------------------------------------------------
+ return knowledge;
+ }
+
+ public List<Step> getInvolvedSteps() {
+ // -------------------------------------
+ return involving;
+ }
+
+ public Menu getMenu() {
+ // ----------------------
+ return menu;
+ }
+
+ public PopupMenu getPopup() {
+ // ----------------------------
+ return popup;
+ }
+
+ public Step getSelectedStep() {
+ // ------------------------------
+ return ustep;
+ }
+
+ public String getSelection() {
+ // -----------------------------
+ return selection;
+ }
+
+ public User getUser() {
+ // ----------------------
+ return cuser;
+ }
+
+ public boolean isOpenForWriting() {
+ // ----------------------------------
+ return (popup != null); // The pop-up is supposed existed when the user is staffed on the study
+ }
+
+ public void reduceDocument(String index) {
+ // -----------------------------------------
+ for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
+ DocumentFacade doc = i.next();
+ if (!doc.getIndex().equals(index))
+ continue;
+ doc.reduceAll();
+ return;
+ }
+ }
+
+ public void reduceHistory(String index) {
+ // ----------------------------------------
+ for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
+ DocumentFacade doc = i.next();
+ if (!doc.getIndex().equals(index))
+ continue;
+ doc.reduce();
+ return;
+ }
+ }
+
+ public void reduceKnowledge(String index) {
+ // ------------------------------------------
+ for (Iterator<KnowledgeIterator> i = knowledge.iterator(); i.hasNext();) {
+ List<KnowledgeElementFacade> knowelms = i.next()
+ .getKnowledgeElements();
+ for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j
+ .hasNext();) {
+ KnowledgeElementFacade kelm = j.next();
+ if (!kelm.getIndex().equals(index))
+ continue;
+ kelm.reduce();
+ return;
+ }
+ }
+ }
+
+ // ==============================================================================================================================
+ // Protected services
+ // ==============================================================================================================================
+
+ protected void setupContents() {
+ // -------------------------------
+ // Description
+ // Initialized in subclasses
+
+ // Knowledge elements supposed ordered by type
+ if (ustep.mayContain(KnowledgeElement.class)) {
+ Scenario scene = (Scenario) ustep.getOwner();
+ List<KnowledgeElementType> types = getKnowledgeElementTypeService()
+ .selectTypesWhere(ProgressState.APPROVED);
+ List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
+ Iterator<KnowledgeElement> more = kelms.iterator();
+ KnowledgeElement current = null;
+ if (more.hasNext())
+ current = more.next();
+
+ knowledge = new Vector<KnowledgeIterator>(types.size());
+ for (Iterator<KnowledgeElementType> i = types.iterator(); i
+ .hasNext();) {
+ KnowledgeElementType type = i.next();
+ List<KnowledgeElementFacade> display = new Vector<KnowledgeElementFacade>(
+ kelms.size());
+ while (current != null && current.getType().equals(type)) {
+ KnowledgeElementFacade facade = knowpres.get(current
+ .getIndex());
+ if (facade == null) {
+ facade = new KnowledgeElementFacade(current);
+ knowpres.put(current.getIndex(), facade);
+ }
+ display.add(facade);
+ if (more.hasNext())
+ current = more.next();
+ else
+ current = null;
+ }
+ knowledge.add(new KnowledgeIterator(type, display));
+ }
+ } else {
+ knowledge = null;
+ }
+ // Documents
+ if (ustep.mayContain(Document.class)) {
+ List<Publication> list = ustep.getAllDocuments();
+
+ contents = new Vector<DocumentFacade>(list.size());
+ for (Iterator<Publication> i = list.iterator(); i.hasNext();) {
+ Publication present = i.next();
+ Long index = present.getIndex();
+ DocumentFacade facade = docpres.get(index);
+ if (facade == null) {
+ facade = new DocumentFacade(this, present,
+ getProjectSettings(), getPublicationService());
+ docpres.put(index, facade);
+ }
+ contents.add(facade);
+ }
+ } else {
+ contents = null;
+ }
}
-
-// ==============================================================================================================================
-// Constructor
-// ==============================================================================================================================
-
- protected OpenObject () {
-// -----------------------
-// All member fields are supposed initialized by subclasses
- if (docpres == null) docpres = new HashMap<Long, DocumentFacade>();
- if (knowpres == null) knowpres = new HashMap<Long, KnowledgeElementFacade>();
- }
-
-// ==============================================================================================================================
-// Public member functions
-// ==============================================================================================================================
-
- public void developDocument (String index) {
-// ------------------------------------------
- for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
- DocumentFacade doc = i.next();
- if (!doc.getIndex().equals(index)) continue;
- doc.develop();
- return;
- }
- }
-
- public void developKnowledge (String index) {
-// -------------------------------------------
- for (Iterator<KnowledgeIterator> i=knowledge.iterator(); i.hasNext();) {
- List<KnowledgeElementFacade> knowelms = i.next().getKnowledgeElements();
- for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j.hasNext(); ) {
- KnowledgeElementFacade kelm = j.next();
- if (!kelm.getIndex().equals(index)) continue;
- kelm.develop();
- return;
- }
- }
- }
-
- public void clearFacades () {
-// ---------------------------
- docpres.clear(); // For eventually reopening the knowledge from a fresh context
- knowpres.clear(); // For eventually reopening the knowledge from a fresh context
- }
-
- public List<Document> collectInvolvedDocuments (DocumentType type) {
-// ------------------------------------------------------------------
- List<Document> found = new Vector<Document>();
- for (Iterator<Step> i=involving.iterator(); i.hasNext();) {
- Step step = i.next();
- List<Publication> exist = step.getAllDocuments();
- for (Iterator<Publication> j=exist.iterator(); j.hasNext();) {
- Document doc = j.next().value();
- if (doc.getType().equals(type)) found.add(doc);
- }
- }
- return found;
- }
-
- public String getDisplayedDescription () {
-// ----------------------------------------
- return description;
- }
-
- public List<DocumentFacade> getDisplayedDocuments () {
-// -----------------------------------------------------
- return contents;
- }
-
- public List<SimulationContextFacade> getDisplayedSimulationContexts () {
-// ----------------------------------------------------------------------
- return context;
- }
-
- public List<KnowledgeIterator> getDisplayedKnowledges () {
-// --------------------------------------------------------
- return knowledge;
- }
-
- public List<Step> getInvolvedSteps () {
-// -------------------------------------
- return involving;
- }
-
- public Menu getMenu () {
-// ----------------------
- return menu;
- }
-
- public PopupMenu getPopup () {
-// ----------------------------
- return popup;
- }
-
- public Step getSelectedStep () {
-// ------------------------------
- return ustep;
- }
-
- public String getSelection () {
-// -----------------------------
- return selection;
- }
-
- public User getUser () {
-// ----------------------
- return cuser;
- }
-
- public boolean isOpenForWriting () {
-// ----------------------------------
- return (popup != null); // The pop-up is supposed existed when the user is staffed on the study
- }
-
- public void reduceDocument (String index) {
-// -----------------------------------------
- for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
- DocumentFacade doc = i.next();
- if (!doc.getIndex().equals(index)) continue;
- doc.reduceAll();
- return;
- }
- }
-
- public void reduceHistory (String index) {
-// ----------------------------------------
- for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext();) {
- DocumentFacade doc = i.next();
- if (!doc.getIndex().equals(index)) continue;
- doc.reduce();
- return;
- }
- }
-
- public void reduceKnowledge (String index) {
-// ------------------------------------------
- for (Iterator<KnowledgeIterator> i=knowledge.iterator(); i.hasNext();) {
- List<KnowledgeElementFacade> knowelms = i.next().getKnowledgeElements();
- for (Iterator<KnowledgeElementFacade> j = knowelms.iterator(); j.hasNext(); ) {
- KnowledgeElementFacade kelm = j.next();
- if (!kelm.getIndex().equals(index)) continue;
- kelm.reduce();
- return;
- }
- }
- }
-
-// ==============================================================================================================================
-// Protected services
-// ==============================================================================================================================
-
- protected void setupContents () {
-// -------------------------------
-// Description
-// Initialized in subclasses
-
-// Knowledge elements supposed ordered by type
- if (ustep.mayContain(KnowledgeElement.class)) {
- Scenario scene = (Scenario)ustep.getOwner();
- List<KnowledgeElementType> types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
- List<KnowledgeElement> kelms = scene.getAllKnowledgeElements();
- Iterator<KnowledgeElement> more = kelms.iterator();
- KnowledgeElement current = null;
- if (more.hasNext()) current = more.next();
-
- knowledge = new Vector<KnowledgeIterator>(types.size());
- for (Iterator<KnowledgeElementType> i=types.iterator(); i.hasNext();) {
- KnowledgeElementType type = i.next();
- List<KnowledgeElementFacade> display = new Vector<KnowledgeElementFacade>(kelms.size());
- while (current != null && current.getType().equals(type)) {
- KnowledgeElementFacade facade = knowpres.get(current.getIndex());
- if (facade == null) {
- facade = new KnowledgeElementFacade(current);
- knowpres.put(current.getIndex(), facade);
- }
- display.add(facade);
- if (more.hasNext()) current = more.next();
- else current = null;
- }
- knowledge.add( new KnowledgeIterator(type, display) );
- }
- } else {
- knowledge = null;
- }
-// Documents
- if (ustep.mayContain(Document.class)) {
- List<Publication> list = ustep.getAllDocuments();
-
- contents = new Vector<DocumentFacade>(list.size());
- for (Iterator<Publication> i=list.iterator(); i.hasNext();) {
- Publication present = i.next();
- Long index = present.getIndex();
- DocumentFacade facade = docpres.get(index);
- if (facade == null) {
- facade = new DocumentFacade(this, present, getProjectSettings(), getPublicationService());
- docpres.put(index, facade);
- }
- contents.add(facade);
- }
- } else {
- contents = null;
- }
- }
/**
* Get project settings.
+ *
* @return Project settings service
*/
- public ProjectSettingsService getProjectSettings() {
+ public ProjectSettingsService getProjectSettings() {
return _projectSettingsService;
}
/**
* 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;
}
/**
* Set the menu.
- * @param menu the menu to set
+ *
+ * @param menu
+ * the menu to set
*/
public void setMenu(Menu menu) {
this.menu = menu;
}
+
+ /**
+ * Get the projectElementService.
+ *
+ * @return the projectElementService
+ */
+ public ProjectElementService getProjectElementService() {
+ return _projectElementService;
+ }
+
+ /**
+ * Set the projectElementService.
+ *
+ * @param projectElementService
+ * the projectElementService to set
+ */
+ public void setProjectElementService(
+ ProjectElementService projectElementService) {
+ _projectElementService = projectElementService;
+ }
+
+ /**
+ * Get the knowledgeElementTypeService.
+ * @return the knowledgeElementTypeService
+ */
+ public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+ return _knowledgeElementTypeService;
+ }
+
+ /**
+ * Set the knowledgeElementTypeService.
+ * @param knowledgeElementTypeService the knowledgeElementTypeService to set
+ */
+ public void setKnowledgeElementTypeService(
+ KnowledgeElementTypeService knowledgeElementTypeService) {
+ _knowledgeElementTypeService = knowledgeElementTypeService;
+ }
}
\ No newline at end of file
package org.splat.simer;
+
/**
*
* @author Daniel Brunier-Coulin
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.ProgressState;
-import org.splat.service.ProjectElementService;
-import org.splat.service.ScenarioService;
+import org.splat.service.DocumentTypeService;
import org.splat.service.StepService;
+import org.splat.service.StudyService;
import org.splat.service.technical.RepositoryService;
import org.splat.dal.bo.som.Publication;
import org.splat.som.Revision;
import org.splat.som.StepRights;
import org.splat.dal.bo.som.Study;
import org.splat.som.StudyRights;
-import org.splat.wapp.Menu;
import org.splat.wapp.ToolBar;
-
public class OpenStudy extends OpenObject implements OpenStudyServices {
/**
* Serial version ID.
*/
- protected final static Logger logger = org.splat.simer.Action.logger;
-
- private Study mystudy;
- private StudyRights urightstudy; // User rights on the open study
- private StepRights urightstep; // User rights on the selected step
- private String version;
- private String credate;
- private String lasdate;
- private Publication selecdoc;
- /**
- * Injected project element service.
- */
- private ProjectElementService _projectElementService;
- /**
- * Injected scenario service.
- */
- private ScenarioService _scenarioService;
+ protected final static Logger logger = org.splat.simer.Action.logger;
+
+ private Study mystudy;
+ private StudyRights urightstudy; // User rights on the open study
+ private StepRights urightstep; // User rights on the selected step
+ private String version;
+ private String credate;
+ private String lasdate;
+ private Publication selecdoc;
/**
* Injected step service.
*/
* Injected repository service.
*/
private RepositoryService _repositoryService;
-// ==============================================================================================================================
-// Constructor
-// ==============================================================================================================================
-
- /**
- * Open the given study in the current http session.
- * @param user the current user
- * @param study the study to open
- * @return this open study object
- */
- public OpenStudy open (User user, Study study) {
-// -----------------------------------------
- ResourceBundle custom = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
- SimpleDateFormat datstring = new SimpleDateFormat(custom.getString("date.format"));
- Revision.Format verstring = new Revision.Format(getProjectSettings().getRevisionPattern());
-
- cuser = user; // May be null if nobody connected
- mystudy = study;
- selection = "0.1"; // Default selection
- selecdoc = null;
-
-// Preparation of the display
- version = verstring.format(mystudy.getVersion());
- credate = datstring.format(mystudy.getDate());
- lasdate = ""; // Not yet supported
- description = mystudy.getDescription();
- involving = new ArrayList<Step>(1);
- context = new ArrayList<SimulationContextFacade>();
- ustep = getProjectElementService().getFirstStep(mystudy);
- ustep.setActor(cuser);
- involving.add(ustep);
- for (Iterator<SimulationContext> i=ustep.getAllSimulationContexts().iterator(); i.hasNext(); ) {
- context.add( new SimulationContextFacade(i.next(), getProjectSettings().getAllSteps()) );
- }
- if (mystudy.isStaffedBy(cuser) || mystudy.hasActor(cuser)) {
-// ProgressState state = mystudy.getProgressState();
-// if (state == ProgressState.inCHECK) popup = ApplicationSettings.getPopupMenu("stapprovable");
-// else if (state == ProgressState.APPROVED) popup = ApplicationSettings.getPopupMenu("stapproved");
-/* else */ popup = ApplicationSettings.getPopupMenu("steditable");
- popup.setContext("study", new StudyRights(cuser, mystudy));
- }
- urightstudy = new StudyRights(cuser, mystudy);
- urightstep = new StepRights(cuser, ustep);
-
-//RKV menu = new StudyMenu(mystudy);
- menu = ((StudyMenu)getMenu()).init(mystudy); //RKV
- menu.selects(selection); // Initializes menu items to be displayed
- setupContents(); // Initializes documents and knowledge at ustep
- return this;
- }
-
-// ==============================================================================================================================
-// Getters
-// ==============================================================================================================================
-
- public String getAuthorName() {
-// -----------------------------
- return mystudy.getAuthor().toString();
- }
- public Long getIndex() {
-// -------------------------
- return mystudy.getIndex();
- }
- public String getDate () {
-// ------------------------
- return credate;
- }
- public StudyMenu getMenu () {
-// ---------------------------
- return (StudyMenu)menu;
- }
- public ProgressState getProgressState() {
-// ----------------------------------------
- return mystudy.getProgressState();
- }
- public String getLastModificationDate () {
-// ----------------------------------------
- return lasdate;
- }
- public ToolBar getModuleBar () {
-// ------------------------------
- return ApplicationSettings.getMe().getModuleBar(getSelectedStep());
- }
- public String getReference() {
-// ----------------------------
- return mystudy.getReference();
- }
- public Publication getSelectedDocument () {
-// -----------------------------------------
- return selecdoc;
- }
- public StepRights getSelectedStepRights () {
-// ------------------------------------------
- return urightstep;
- }
- public StudyRights getStudyRights () {
-// ------------------------------------
- return urightstudy;
- }
- public Study getStudyObject () {
-// ------------------------------
- return mystudy;
- }
- public String getTitle() {
-// ------------------------
- return mystudy.getTitle();
- }
- public String getType () {
-// ------------------------
- return ResourceBundle.getBundle("labels", ApplicationSettings.getCurrentLocale()).getString("label.study");
- }
- public String getVersion () {
-// ---------------------------
- return version;
- }
- public boolean isStepEnabled () {
-// -------------------------------
- return urightstep.isEnabled();
- }
-
-// ==============================================================================================================================
-// Public services
-// ==============================================================================================================================
-
- public URL newTemplateBasedDocument (String typename, User author) {
-// ------------------------------------------------------------------
- String filename = typename + ".xml"; // Only XML templates are writeable
- File template = new File(getRepositoryService().getTemplatePath() + filename);
- if (!template.exists()) return null;
-
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- File udir = getRepositoryService().getDownloadDirectory(author);
- File credoc = new File(udir.getPath() + "/" + filename);
-
-// Creation of the meta-document
- Step step = getSelectedStep(); // Should we check if the given document type is compatible ?
- DocumentType type = Document.selectType(typename);
- Document.Properties dprop = new Document.Properties();
- Document medoc = getStepService().createDocument(step, dprop.setType(type).setFormat("xml").setAuthor(author)).value();
- transax.commit();
-
-// Instantiation of the template into the user download directory
- if (!udir.exists()) udir.mkdir();
- if (credoc.exists()) credoc.delete();
- Do.copy(template, credoc);
-
-// Transfer to the document of all known properties
- ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
- SimpleDateFormat get = new SimpleDateFormat(locale.getString("date.format"));
- Writer tool = Toolbox.getWriter(credoc);
- List<Step> slist = getInvolvedSteps();
- for (Iterator<Step> i=slist.iterator(); i.hasNext(); ) {
- List<SimulationContext> clist = i.next().getAllSimulationContexts();
- for (Iterator<SimulationContext> j=clist.iterator(); j.hasNext(); ) {
- SimulationContext context = j.next();
- tool.updateProperty(context.getType().getName(), context.getValue());
- }
- }
- tool.updateProperty("reference", medoc.getReference());
- tool.updateProperty("study", mystudy.getTitle());
- tool.updateProperty("step", locale.getString("folder.step." + step.getNumber()).replaceAll("''", "'"));
- tool.updateProperty("author", author.getUsername().toUpperCase());
- tool.updateProperty("date", get.format(medoc.getCreationDate()));
- tool.updateProperty("history", locale.getString("label.creation").replaceAll("''", "'"));
- tool.save();
-
- return new URL(ApplicationSettings.getDownloadURL(author) + filename);
- }
- catch (Exception saverror) {
- logger.error("Reason:", saverror);
- if (transax != null && transax.isActive()) {
-// Second try-catch as the rollback could fail as well
- try {
- transax.rollback();
- } catch (HibernateException backerror) {
- logger.debug("Error rolling back transaction", backerror);
- }
- }
- return null;
- }
- }
-
- public void selectDocument (String docurl) {
-// ------------------------------------------
- String prefix = ApplicationSettings.getRepositoryURL();
-
- if (docurl.startsWith(prefix)) try {
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- String path = docurl.substring(prefix.length());
- String[] parse = path.split("'");
-
- path = parse[0];
- for (int i=1; i<parse.length; i++) path = path + "''" + parse[i];
-// Better call Database.selectDocument(path), but this service does not exist (overloading issue)
- String query = "from Document where path='" + path + "'";
- Document value = (Document)Database.getSession().createQuery(query).uniqueResult();
-
- selecdoc = ustep.getDocument(value.getIndex());
- transax.commit();
- }
- catch (Exception error) {
- logger.error("Reason:", error);
- }
- }
-
- public void setSelection (String step) {
-// --------------------------------------
- if (!step.equals(selection)) {
- selection = step;
- selecdoc = null;
- setupPreviousToSelectedSteps();
- updateSimulationContexts(); // Initializes contexts according to the selected steps
- }
- ustep = involving.get(involving.size()-1);
- urightstep = new StepRights(cuser, ustep);
- ustep.setActor(cuser);
- menu.selects(selection); // Updates menu items to be displayed
- setupContents(); // The contents may have changed even if the selection is the same
- }
-
-// ==============================================================================================================================
-// Protected services
-// ==============================================================================================================================
-
- protected void add (Publication doc) {
-// ------------------------------------
- DocumentFacade facade = new DocumentFacade(this, doc, getProjectSettings(), getPublicationService());
- boolean first = (contents.size() == 0);
-
- docpres.put(doc.getIndex(), facade);
- contents.add(0, facade); // Prepend the new publication
- if (first) this.getMenu().refreshSelectedItem();
-
- }
-
- protected void add (SimulationContext contex) {
-// ---------------------------------------------
- SimulationContextFacade facade = new SimulationContextFacade(contex, getProjectSettings().getAllSteps());
-
- context.add(facade);
- }
-
- protected void add (KnowledgeElement kelm) {
-// ------------------------------------------
- KnowledgeElementFacade facade = new KnowledgeElementFacade(kelm);
-//RKV KnowledgeIterator known = knowledge.get(kelm.getType().getIndex() - 2);
- // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
- //RKV:Begin: Find a knowledge iterator for appropriate knowledge type
- KnowledgeIterator known = null;
- for (KnowledgeIterator aKnowledgeSection : knowledge) {
- if (aKnowledgeSection.getIndex().equals(String.valueOf(kelm.getType().getIndex()))) {
- known = aKnowledgeSection;
- break;
- }
- }
- if (known != null) { //RKV:End
- knowpres.put(kelm.getIndex(), facade);
- known.list.add(facade); // Insert the new knowledge at the end of the corresponding knowledge type
- }
- }
-
- protected void remove (Publication doctag) {
-// ------------------------------------------
- for (Iterator<DocumentFacade> i=contents.iterator(); i.hasNext(); ) {
- DocumentFacade facade = i.next();
- if (!facade.isFacadeOf(doctag)) continue;
- i.remove();
- break;
- }
- if (contents.size() == 0) this.getMenu().refreshSelectedItem();
- }
-
- protected void changeUser (User user) {
-// -------------------------------------
- cuser = user;
- popup = null;
- if (mystudy.isStaffedBy(cuser)) {
- popup = ApplicationSettings.getPopupMenu("steditable");
- popup.setContext("study", new StudyRights(cuser, mystudy));
- }
- ustep.setActor(cuser);
- urightstudy = new StudyRights(cuser, mystudy);
- urightstep = new StepRights(cuser, ustep);
- }
-
- protected void remove (SimulationContext contex) {
-// ------------------------------------------------
- for (Iterator<SimulationContextFacade> i=context.iterator(); i.hasNext(); ) {
- SimulationContextFacade facade = i.next();
- if (!facade.isFacadeOf(contex)) continue;
- i.remove();
- break;
- }
- }
-
- protected void remove (KnowledgeElement kelm) {
-// ---------------------------------------------
- KnowledgeIterator known = knowledge.get((int)(kelm.getType().getIndex() - 2));
- // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
- knowpres.remove(kelm.getIndex());
- for (Iterator<KnowledgeElementFacade> i=known.list.iterator(); i.hasNext(); ) {
- KnowledgeElementFacade facade = i.next();
- if (!facade.isFacadeOf(kelm)) continue;
- i.remove();
- break;
- }
- }
-
- protected void update (Publication doc) {
-// ---------------------------------------
- DocumentFacade facade = docpres.get(doc.getIndex());
- if (facade != null) {
- facade.refresh();
- }
- }
-
- protected void update (KnowledgeElement kelm) {
-// ---------------------------------------------
- KnowledgeElementFacade facade = knowpres.get(kelm.getIndex());
- if (facade != null) {
- facade.refresh();
- }
- }
-
- protected void updateSimulationContexts () {
-// ------------------------------------------
- context.clear();
- for (Iterator<Step> i=involving.iterator(); i.hasNext(); ) {
- for (Iterator<SimulationContext> j=i.next().getAllSimulationContexts().iterator(); j.hasNext(); ) {
- context.add( new SimulationContextFacade(j.next(), getProjectSettings().getAllSteps()) );
- }
- }
- }
-
-// ==============================================================================================================================
-// Private services
-// ==============================================================================================================================
-
- private void setupPreviousToSelectedSteps () {
-// --------------------------------------------
- String[] item = selection.split("\\x2E");
- int major = Integer.valueOf(item[0]);
- int minor = Integer.valueOf(item[1]);
- int base = minor;
- Step[] step;
-
- involving.clear();
- if (major > 0) {
- Scenario[] branch = mystudy.getScenarii();
- Scenario scenar = branch[0];
- for (int i=0; i<branch.length; i++) {
- scenar = branch[i];
- if (scenar.getIndex() == major) break; // Supposed exist
- }
- step = getProjectElementService().getSteps(scenar);
- base = step[0].getNumber() - 1;
- for (int i=0; i+base<minor; i++) {
- involving.add(step[i]);
- }
- }
- step = getProjectElementService().getSteps(mystudy);
- for (int i=step.length-1; i>-1; i--) {
- Step firstep = step[i];
- if(firstep.getNumber() > base) continue;
- involving.add(0, firstep);
- }
- }
-
- /**
- * Get the projectElementService.
- *
- * @return the projectElementService
+ /**
+ * Injected document type service.
*/
- public ProjectElementService getProjectElementService() {
- return _projectElementService;
- }
+ private DocumentTypeService _documentTypeService;
/**
- * Set the projectElementService.
- *
- * @param projectElementService
- * the projectElementService to set
+ * The injected Study service.
*/
- public void setProjectElementService(
- ProjectElementService projectElementService) {
- _projectElementService = projectElementService;
- }
+ private StudyService _studyService;
+
+ // ==============================================================================================================================
+ // Constructor
+ // ==============================================================================================================================
/**
- * Get the scenarioService.
+ * Open the given study in the current http session.
*
- * @return the scenarioService
+ * @param user
+ * the current user
+ * @param study
+ * the study to open
+ * @return this open study object
*/
- public ScenarioService getScenarioService() {
- return _scenarioService;
+ public OpenStudy open(User user, Study study) {
+ // -----------------------------------------
+ ResourceBundle custom = ResourceBundle.getBundle("som",
+ ApplicationSettings.getCurrentLocale());
+ SimpleDateFormat datstring = new SimpleDateFormat(custom
+ .getString("date.format"));
+ Revision.Format verstring = new Revision.Format(getProjectSettings()
+ .getRevisionPattern());
+
+ cuser = user; // May be null if nobody connected
+ mystudy = study;
+ selection = "0.1"; // Default selection
+ selecdoc = null;
+
+ // Preparation of the display
+ version = verstring.format(mystudy.getVersion());
+ credate = datstring.format(mystudy.getDate());
+ lasdate = ""; // Not yet supported
+ description = mystudy.getDescription();
+ involving = new ArrayList<Step>(1);
+ context = new ArrayList<SimulationContextFacade>();
+ ustep = getProjectElementService().getFirstStep(mystudy);
+ ustep.setActor(cuser);
+ involving.add(ustep);
+ for (Iterator<SimulationContext> i = ustep.getAllSimulationContexts()
+ .iterator(); i.hasNext();) {
+ context.add(new SimulationContextFacade(i.next(),
+ getProjectSettings().getAllSteps()));
+ }
+ if (getStudyService().isStaffedBy(mystudy, cuser) || getStudyService().hasActor(mystudy, cuser)) {
+ // ProgressState state = mystudy.getProgressState();
+ // if (state == ProgressState.inCHECK) popup = ApplicationSettings.getPopupMenu("stapprovable");
+ // else if (state == ProgressState.APPROVED) popup = ApplicationSettings.getPopupMenu("stapproved");
+ /* else */popup = ApplicationSettings
+ .getPopupMenu("steditable");
+ popup.setContext("study", new StudyRights(cuser, mystudy));
+ }
+ urightstudy = new StudyRights(cuser, mystudy);
+ urightstep = new StepRights(cuser, ustep);
+
+ // RKV menu = new StudyMenu(mystudy);
+ menu = ((StudyMenu) getMenu()).init(mystudy); // RKV
+ menu.selects(selection); // Initializes menu items to be displayed
+ setupContents(); // Initializes documents and knowledge at ustep
+ return this;
}
- /**
- * Set the scenarioService.
- *
- * @param scenarioService
- * the scenarioService to set
- */
- public void setScenarioService(ScenarioService scenarioService) {
- _scenarioService = scenarioService;
+ // ==============================================================================================================================
+ // Getters
+ // ==============================================================================================================================
+
+ public String getAuthorName() {
+ // -----------------------------
+ return mystudy.getAuthor().toString();
+ }
+
+ public Long getIndex() {
+ // -------------------------
+ return mystudy.getIndex();
+ }
+
+ public String getDate() {
+ // ------------------------
+ return credate;
+ }
+
+ public StudyMenu getMenu() {
+ // ---------------------------
+ return (StudyMenu) menu;
+ }
+
+ public void setMenu(StudyMenu aMenu) {
+ menu = aMenu;
+ }
+
+ public ProgressState getProgressState() {
+ // ----------------------------------------
+ return mystudy.getProgressState();
+ }
+
+ public String getLastModificationDate() {
+ // ----------------------------------------
+ return lasdate;
+ }
+
+ public ToolBar getModuleBar() {
+ // ------------------------------
+ return ApplicationSettings.getMe().getModuleBar(getSelectedStep());
+ }
+
+ public String getReference() {
+ // ----------------------------
+ return mystudy.getReference();
+ }
+
+ public Publication getSelectedDocument() {
+ // -----------------------------------------
+ return selecdoc;
+ }
+
+ public StepRights getSelectedStepRights() {
+ // ------------------------------------------
+ return urightstep;
+ }
+
+ public StudyRights getStudyRights() {
+ // ------------------------------------
+ return urightstudy;
+ }
+
+ public Study getStudyObject() {
+ // ------------------------------
+ return mystudy;
+ }
+
+ public String getTitle() {
+ // ------------------------
+ return mystudy.getTitle();
+ }
+
+ public String getType() {
+ // ------------------------
+ return ResourceBundle.getBundle("labels",
+ ApplicationSettings.getCurrentLocale())
+ .getString("label.study");
+ }
+
+ public String getVersion() {
+ // ---------------------------
+ return version;
+ }
+
+ public boolean isStepEnabled() {
+ // -------------------------------
+ return urightstep.isEnabled();
+ }
+
+ // ==============================================================================================================================
+ // Public services
+ // ==============================================================================================================================
+
+ public URL newTemplateBasedDocument(String typename, User author) {
+ // ------------------------------------------------------------------
+ String filename = typename + ".xml"; // Only XML templates are writeable
+ File template = new File(getRepositoryService().getTemplatePath()
+ + filename);
+ if (!template.exists())
+ return null;
+
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+ try {
+ File udir = getRepositoryService().getDownloadDirectory(author);
+ File credoc = new File(udir.getPath() + "/" + filename);
+
+ // Creation of the meta-document
+ Step step = getSelectedStep(); // Should we check if the given document type is compatible ?
+ DocumentType type = getDocumentTypeService().selectType(typename);
+ Document.Properties dprop = new Document.Properties();
+ Document medoc = getStepService().createDocument(step,
+ dprop.setType(type).setFormat("xml").setAuthor(author))
+ .value();
+ transax.commit();
+
+ // Instantiation of the template into the user download directory
+ if (!udir.exists())
+ udir.mkdir();
+ if (credoc.exists())
+ credoc.delete();
+ Do.copy(template, credoc);
+
+ // Transfer to the document of all known properties
+ ResourceBundle locale = ResourceBundle.getBundle("som",
+ ApplicationSettings.getCurrentLocale());
+ SimpleDateFormat get = new SimpleDateFormat(locale
+ .getString("date.format"));
+ Writer tool = Toolbox.getWriter(credoc);
+ List<Step> slist = getInvolvedSteps();
+ for (Iterator<Step> i = slist.iterator(); i.hasNext();) {
+ List<SimulationContext> clist = i.next()
+ .getAllSimulationContexts();
+ for (Iterator<SimulationContext> j = clist.iterator(); j
+ .hasNext();) {
+ SimulationContext context = j.next();
+ tool.updateProperty(context.getType().getName(), context
+ .getValue());
+ }
+ }
+ tool.updateProperty("reference", medoc.getReference());
+ tool.updateProperty("study", mystudy.getTitle());
+ tool.updateProperty("step", locale.getString(
+ "folder.step." + step.getNumber()).replaceAll("''", "'"));
+ tool.updateProperty("author", author.getUsername().toUpperCase());
+ tool.updateProperty("date", get.format(medoc.getCreationDate()));
+ tool.updateProperty("history", locale.getString("label.creation")
+ .replaceAll("''", "'"));
+ tool.save();
+
+ return new URL(ApplicationSettings.getDownloadURL(author)
+ + filename);
+ } catch (Exception saverror) {
+ logger.error("Reason:", saverror);
+ if (transax != null && transax.isActive()) {
+ // Second try-catch as the rollback could fail as well
+ try {
+ transax.rollback();
+ } catch (HibernateException backerror) {
+ logger.debug("Error rolling back transaction", backerror);
+ }
+ }
+ return null;
+ }
+ }
+
+ public void selectDocument(String docurl) {
+ // ------------------------------------------
+ String prefix = ApplicationSettings.getRepositoryURL();
+
+ if (docurl.startsWith(prefix))
+ try {
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+ String path = docurl.substring(prefix.length());
+ String[] parse = path.split("'");
+
+ path = parse[0];
+ for (int i = 1; i < parse.length; i++)
+ path = path + "''" + parse[i];
+ // Better call Database.selectDocument(path), but this service does not exist (overloading issue)
+ String query = "from Document where path='" + path + "'";
+ Document value = (Document) Database.getSession().createQuery(
+ query).uniqueResult();
+
+ selecdoc = ustep.getDocument(value.getIndex());
+ transax.commit();
+ } catch (Exception error) {
+ logger.error("Reason:", error);
+ }
+ }
+
+ public void setSelection(String step) {
+ // --------------------------------------
+ if (!step.equals(selection)) {
+ selection = step;
+ selecdoc = null;
+ setupPreviousToSelectedSteps();
+ updateSimulationContexts(); // Initializes contexts according to the selected steps
+ }
+ ustep = involving.get(involving.size() - 1);
+ urightstep = new StepRights(cuser, ustep);
+ ustep.setActor(cuser);
+ menu.selects(selection); // Updates menu items to be displayed
+ setupContents(); // The contents may have changed even if the selection is the same
+ }
+
+ // ==============================================================================================================================
+ // Protected services
+ // ==============================================================================================================================
+
+ protected void add(Publication doc) {
+ // ------------------------------------
+ DocumentFacade facade = new DocumentFacade(this, doc,
+ getProjectSettings(), getPublicationService());
+ boolean first = (contents.size() == 0);
+
+ docpres.put(doc.getIndex(), facade);
+ contents.add(0, facade); // Prepend the new publication
+ if (first)
+ this.getMenu().refreshSelectedItem();
+
+ }
+
+ protected void add(SimulationContext contex) {
+ // ---------------------------------------------
+ SimulationContextFacade facade = new SimulationContextFacade(contex,
+ getProjectSettings().getAllSteps());
+
+ context.add(facade);
+ }
+
+ protected void add(KnowledgeElement kelm) {
+ // ------------------------------------------
+ KnowledgeElementFacade facade = new KnowledgeElementFacade(kelm);
+ // RKV KnowledgeIterator known = knowledge.get(kelm.getType().getIndex() - 2);
+ // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
+ // RKV:Begin: Find a knowledge iterator for appropriate knowledge type
+ KnowledgeIterator known = null;
+ for (KnowledgeIterator aKnowledgeSection : knowledge) {
+ if (aKnowledgeSection.getIndex().equals(
+ String.valueOf(kelm.getType().getIndex()))) {
+ known = aKnowledgeSection;
+ break;
+ }
+ }
+ if (known != null) { // RKV:End
+ knowpres.put(kelm.getIndex(), facade);
+ known.list.add(facade); // Insert the new knowledge at the end of the corresponding knowledge type
+ }
+ }
+
+ protected void remove(Publication doctag) {
+ // ------------------------------------------
+ for (Iterator<DocumentFacade> i = contents.iterator(); i.hasNext();) {
+ DocumentFacade facade = i.next();
+ if (!facade.isFacadeOf(doctag))
+ continue;
+ i.remove();
+ break;
+ }
+ if (contents.size() == 0)
+ this.getMenu().refreshSelectedItem();
+ }
+
+ protected void changeUser(User user) {
+ // -------------------------------------
+ cuser = user;
+ popup = null;
+ if (getStudyService().isStaffedBy(mystudy, cuser)) {
+ popup = ApplicationSettings.getPopupMenu("steditable");
+ popup.setContext("study", new StudyRights(cuser, mystudy));
+ }
+ ustep.setActor(cuser);
+ urightstudy = new StudyRights(cuser, mystudy);
+ urightstep = new StepRights(cuser, ustep);
+ }
+
+ protected void remove(SimulationContext contex) {
+ // ------------------------------------------------
+ for (Iterator<SimulationContextFacade> i = context.iterator(); i
+ .hasNext();) {
+ SimulationContextFacade facade = i.next();
+ if (!facade.isFacadeOf(contex))
+ continue;
+ i.remove();
+ break;
+ }
+ }
+
+ protected void remove(KnowledgeElement kelm) {
+ // ---------------------------------------------
+ KnowledgeIterator known = knowledge.get((int) (kelm.getType()
+ .getIndex() - 2));
+ // Knowledges are ordered by type index, from 0 to n-1, the first one being reserved (reason for -2)
+ knowpres.remove(kelm.getIndex());
+ for (Iterator<KnowledgeElementFacade> i = known.list.iterator(); i
+ .hasNext();) {
+ KnowledgeElementFacade facade = i.next();
+ if (!facade.isFacadeOf(kelm))
+ continue;
+ i.remove();
+ break;
+ }
+ }
+
+ protected void update(Publication doc) {
+ // ---------------------------------------
+ DocumentFacade facade = docpres.get(doc.getIndex());
+ if (facade != null) {
+ facade.refresh();
+ }
+ }
+
+ protected void update(KnowledgeElement kelm) {
+ // ---------------------------------------------
+ KnowledgeElementFacade facade = knowpres.get(kelm.getIndex());
+ if (facade != null) {
+ facade.refresh();
+ }
+ }
+
+ protected void updateSimulationContexts() {
+ // ------------------------------------------
+ context.clear();
+ for (Iterator<Step> i = involving.iterator(); i.hasNext();) {
+ for (Iterator<SimulationContext> j = i.next()
+ .getAllSimulationContexts().iterator(); j.hasNext();) {
+ context.add(new SimulationContextFacade(j.next(),
+ getProjectSettings().getAllSteps()));
+ }
+ }
+ }
+
+ // ==============================================================================================================================
+ // Private services
+ // ==============================================================================================================================
+
+ private void setupPreviousToSelectedSteps() {
+ // --------------------------------------------
+ String[] item = selection.split("\\x2E");
+ int major = Integer.valueOf(item[0]);
+ int minor = Integer.valueOf(item[1]);
+ int base = minor;
+ Step[] step;
+
+ involving.clear();
+ if (major > 0) {
+ Scenario[] branch = mystudy.getScenarii();
+ Scenario scenar = branch[0];
+ for (int i = 0; i < branch.length; i++) {
+ scenar = branch[i];
+ if (scenar.getIndex() == major)
+ break; // Supposed exist
+ }
+ step = getProjectElementService().getSteps(scenar);
+ base = step[0].getNumber() - 1;
+ for (int i = 0; i + base < minor; i++) {
+ involving.add(step[i]);
+ }
+ }
+ step = getProjectElementService().getSteps(mystudy);
+ for (int i = step.length - 1; i > -1; i--) {
+ Step firstep = step[i];
+ if (firstep.getNumber() > base)
+ continue;
+ involving.add(0, firstep);
+ }
}
/**
* Get the stepService.
+ *
* @return the stepService
*/
public StepService getStepService() {
/**
* Set the stepService.
- * @param stepService the stepService to set
+ *
+ * @param stepService
+ * the stepService to set
*/
public void setStepService(StepService stepService) {
_stepService = stepService;
/**
* Get the repositoryService.
+ *
* @return the repositoryService
*/
public RepositoryService getRepositoryService() {
/**
* Set the repositoryService.
- * @param repositoryService the repositoryService to set
+ *
+ * @param repositoryService
+ * the repositoryService to set
*/
public void setRepositoryService(RepositoryService repositoryService) {
_repositoryService = repositoryService;
}
+
+ /**
+ * Get the documentTypeService.
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ * @param documentTypeService the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
+
+ /**
+ * Get the studyService.
+ *
+ * @return the studyService
+ */
+ public StudyService getStudyService() {
+ return _studyService;
+ }
+
+ /**
+ * Set the studyService.
+ *
+ * @param studyService
+ * the studyService to set
+ */
+ public void setStudyService(StudyService studyService) {
+ _studyService = studyService;
+ }
}
\ No newline at end of file
import java.util.List;
import java.util.Map;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.splat.kernel.InvalidPropertyException;
import org.splat.dal.bo.kernel.User;
import org.splat.kernel.UserDirectory;
+import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.SearchService;
import org.splat.service.SimulationContextService;
-import org.splat.dal.dao.som.Database;
import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.KnowledgeElementType;
import org.splat.dal.bo.som.ProgressState;
import org.splat.dal.bo.som.SimulationContextType;
import org.splat.dal.bo.som.Visibility;
-
+/**
+ * Action for searching a knowledge in the database.
+ */
public class SearchKnowledgeAction extends SearchBaseAction {
- private String visibility = null; // "Private", "Public", "All"
- private String typid = null; // Knowledge type index when among all
- private String matchamong = null; // "all" or "any"
- private String matcontext = null; // "all" or "any"
- private String refid = null; // Knowledge reference when among ref
- private String words = null; // Full text search words
- private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
- private SearchService _searchService;
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = -3104321907432838476L;
+
+ private String visibility = null; // "Private", "Public", "All"
+ private String typid = null; // Knowledge type index when among all
+ private String matchamong = null; // "all" or "any"
+ private String matcontext = null; // "all" or "any"
+ private String refid = null; // Knowledge reference when among ref
+ private String words = null; // Full text search words
+ private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
+ private SearchService _searchService;
/**
* Injected simulation context service.
*/
private SimulationContextService _simulationContextService;
+ /**
+ * Injected knowledge element service.
+ */
+ private KnowledgeElementTypeService _knowledgeElementTypeService;
+
+ // ==============================================================================================================================
+ // Action methods
+ // ==============================================================================================================================
/**
- * Serial version ID.
+ * The action initialization.
+ *
+ * @return SUCCESS if succeeded, ERROR if doSearch() is failed
*/
- private static final long serialVersionUID = -3104321907432838476L;
+ public String doInitialize() {
+ try {
+ loadFilter();
+ doSearch();
+
+ // Final initialization of the form
+ types = getKnowledgeElementTypeService().selectTypesWhere(
+ ProgressState.APPROVED);
+ setCandidates();
+ setContextTypeOptions(getInvolvedContexts());
+
+ return SUCCESS;
+ } catch (Exception error) {
+ // No need to roll back the transaction as it is read only
+ logger.error("Reason: ", error);
+ return ERROR;
+ }
+ }
-// ==============================================================================================================================
-// Action methods
-// ==============================================================================================================================
-
- public String doInitialize () {
-// -----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- loadFilter();
- doSearch();
-
-// Final initialization of the form
- types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
- setCandidates();
- setContextTypeOptions(getInvolvedContexts());
-
- transax.commit();
- return SUCCESS;
- }
- catch (Exception error) {
-// No need to roll back the transaction as it is read only
- logger.error("Reason: ", error);
- return ERROR;
- }
- }
-
- protected String doSearch () throws InvalidPropertyException {
-// ----------------------------
- Map<String, Object> session = getSession();
- User user = getConnectedUser();
-
- KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
-
-// Search matching all criteria
- sprop.setType( KnowledgeElement.selectType(Integer.valueOf(typid)) );
- if (words.length() > 0) sprop.setTitle(words);
- if (refid.length() > 0) sprop.setReference(refid);
- if (context.size() > 0) sprop.setSimulationContexts(context);
- int index = Integer.valueOf(author);
- if (index > 0) {
- User him = UserDirectory.selectUser(index);
- sprop.setAuthor(him);
- }
-// Set of the visibility
- if (visibility.equals("all")) {
- KnowledgeElement.Properties other = sprop.copy();
-
- other.setVisibility(Visibility.PUBLIC);
- sprop.setVisibility(Visibility.PRIVATE);
- sprop.setActor(user);
-
- result = getSearchService().selectKnowledgeElementsWhere(sprop, other);
- }
- else {
- Visibility reparea = null;
- if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
- else reparea = Visibility.valueOf(visibility);
- sprop.setVisibility(reparea);
- if (reparea == Visibility.PRIVATE) sprop.setActor(user);
-
- result = getSearchService().selectKnowledgeElementsWhere(sprop);
- }
- session.put("search.result", result); // For redisplaying the page without re-executing the search
- return "refresh";
- }
-
-// ==============================================================================================================================
-// Getters
-// ==============================================================================================================================
-
- public String getContextMatch () {
-// --------------------------------
- return matcontext;
- }
- public String getCriteriaMatch () {
-// ---------------------------------
- return matchamong;
- }
- public List<KnowledgeElementType> getKnowledgeTypes () {
-// ------------------------------------------------------
- return types;
- }
- public String getReference () {
-// -----------------------------
- return refid;
- }
- public String getState () {
-// ------------------------
- return typid;
- }
- public String getVisibility () {
-// ------------------------------
- return visibility;
- }
- public String getWords () {
-// -------------------------
- return words;
- }
-
-// ==============================================================================================================================
-// Setters
-// ==============================================================================================================================
-
- public void setContextMatch (String value) {
-// ------------------------------------------
- this.matcontext = value;
- }
- public void setCriteriaMatch (String value) {
-// -------------------------------------------
- this.matchamong = value;
- }
- public void setReference (String value) {
-// ---------------------------------------
- this.refid = value;
- }
- public void setState (String value) {
-// ----------------------------------
- this.typid = value;
- }
- public void setVisibility (String value) {
-// ----------------------------------------
- this.visibility = value;
- }
- public void setWords (String value) {
-// -----------------------------------
- this.words = value;
- }
-
-// ==============================================================================================================================
-// Implementation of abstract services
-// ==============================================================================================================================
-
- protected List<SimulationContextType> getInvolvedContexts () {
-// ------------------------------------------------------------
- return getSimulationContextService().selectAllTypes();
- }
-
- @SuppressWarnings("unchecked")
- protected void loadFilter () {
-// ----------------------------
- Map<String,Object> session = getSession();
- User user = getConnectedUser();
- Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
-
- visibility = (String)filter.get("visibility");
- matchamong = (String)filter.get("matchamong");
- matcontext = (String)filter.get("matcontext");
- typid = (String)filter.get("type");
- author = (String)filter.get("author");
- refid = (String)filter.get("reference");
- words = (String)filter.get("title");
- context = (List<SimulationContext>)filter.get("context");
-
- if (user == null) {
- visibility = "onlypublic";
- }
- }
+ protected String doSearch() throws InvalidPropertyException {
+ // ----------------------------
+ Map<String, Object> session = getSession();
+ User user = getConnectedUser();
+
+ KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
+
+ // Search matching all criteria
+ sprop.setType(getKnowledgeElementTypeService().selectType(
+ Integer.valueOf(typid)));
+ if (words.length() > 0)
+ sprop.setTitle(words);
+ if (refid.length() > 0)
+ sprop.setReference(refid);
+ if (context.size() > 0)
+ sprop.setSimulationContexts(context);
+ int index = Integer.valueOf(author);
+ if (index > 0) {
+ User him = UserDirectory.selectUser(index);
+ sprop.setAuthor(him);
+ }
+ // Set of the visibility
+ if (visibility.equals("all")) {
+ KnowledgeElement.Properties other = sprop.copy();
+
+ other.setVisibility(Visibility.PUBLIC);
+ sprop.setVisibility(Visibility.PRIVATE);
+ sprop.setActor(user);
+
+ result = getSearchService().selectKnowledgeElementsWhere(sprop,
+ other);
+ } else {
+ Visibility reparea = null;
+ if (visibility.equals("onlypublic"))
+ reparea = Visibility.PUBLIC;
+ else
+ reparea = Visibility.valueOf(visibility);
+ sprop.setVisibility(reparea);
+ if (reparea == Visibility.PRIVATE)
+ sprop.setActor(user);
+
+ result = getSearchService().selectKnowledgeElementsWhere(sprop);
+ }
+ session.put("search.result", result); // For redisplaying the page without re-executing the search
+ return "refresh";
+ }
- @SuppressWarnings("unchecked")
- protected void saveFilter () {
-// ----------------------------
- Map<String,Object> session = getSession();
- Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
+ // ==============================================================================================================================
+ // Getters
+ // ==============================================================================================================================
- filter.put("visibility", this.visibility);
- filter.put("matchamong", this.matchamong);
- filter.put("matcontext", this.matcontext);
- filter.put("type", this.typid);
- filter.put("author", this.author);
- filter.put("reference", "");
- filter.put("title", this.words);
+ public String getContextMatch() {
+ // --------------------------------
+ return matcontext;
+ }
- context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form
+ public String getCriteriaMatch() {
+ // ---------------------------------
+ return matchamong;
+ }
+
+ public List<KnowledgeElementType> getKnowledgeTypes() {
+ // ------------------------------------------------------
+ return types;
+ }
+
+ public String getReference() {
+ // -----------------------------
+ return refid;
+ }
+
+ public String getState() {
+ // ------------------------
+ return typid;
+ }
-// Initialization required by all do functions
- types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
+ public String getVisibility() {
+ // ------------------------------
+ return visibility;
}
- /**
+
+ public String getWords() {
+ // -------------------------
+ return words;
+ }
+
+ // ==============================================================================================================================
+ // Setters
+ // ==============================================================================================================================
+
+ public void setContextMatch(String value) {
+ // ------------------------------------------
+ this.matcontext = value;
+ }
+
+ public void setCriteriaMatch(String value) {
+ // -------------------------------------------
+ this.matchamong = value;
+ }
+
+ public void setReference(String value) {
+ // ---------------------------------------
+ this.refid = value;
+ }
+
+ public void setState(String value) {
+ // ----------------------------------
+ this.typid = value;
+ }
+
+ public void setVisibility(String value) {
+ // ----------------------------------------
+ this.visibility = value;
+ }
+
+ public void setWords(String value) {
+ // -----------------------------------
+ this.words = value;
+ }
+
+ // ==============================================================================================================================
+ // Implementation of abstract services
+ // ==============================================================================================================================
+
+ protected List<SimulationContextType> getInvolvedContexts() {
+ // ------------------------------------------------------------
+ return getSimulationContextService().selectAllTypes();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void loadFilter() {
+ // ----------------------------
+ Map<String, Object> session = getSession();
+ User user = getConnectedUser();
+ Map<String, Object> filter = (Map<String, Object>) session
+ .get("knowledge.filter"); // A default filter is supposed being set at start
+
+ visibility = (String) filter.get("visibility");
+ matchamong = (String) filter.get("matchamong");
+ matcontext = (String) filter.get("matcontext");
+ typid = (String) filter.get("type");
+ author = (String) filter.get("author");
+ refid = (String) filter.get("reference");
+ words = (String) filter.get("title");
+ context = (List<SimulationContext>) filter.get("context");
+
+ if (user == null) {
+ visibility = "onlypublic";
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void saveFilter() {
+ // ----------------------------
+ Map<String, Object> session = getSession();
+ Map<String, Object> filter = (Map<String, Object>) session
+ .get("knowledge.filter"); // A default filter is supposed being set at start
+
+ filter.put("visibility", this.visibility);
+ filter.put("matchamong", this.matchamong);
+ filter.put("matcontext", this.matcontext);
+ filter.put("type", this.typid);
+ filter.put("author", this.author);
+ filter.put("reference", "");
+ filter.put("title", this.words);
+
+ context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
+
+ // Initialization required by all do functions
+ types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
+ }
+
+ /**
* Get the searchService.
+ *
* @return the searchService
*/
public SearchService getSearchService() {
/**
* Set the searchService.
- * @param searchService the searchService to set
+ *
+ * @param searchService
+ * the searchService to set
*/
public void setSearchService(SearchService searchService) {
_searchService = searchService;
SimulationContextService simulationContextService) {
_simulationContextService = simulationContextService;
}
+
+ /**
+ * Get the knowledgeElementTypeService.
+ *
+ * @return the knowledgeElementTypeService
+ */
+ public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+ return _knowledgeElementTypeService;
+ }
+
+ /**
+ * Set the knowledgeElementTypeService.
+ *
+ * @param knowledgeElementTypeService
+ * the knowledgeElementTypeService to set
+ */
+ public void setKnowledgeElementTypeService(
+ KnowledgeElementTypeService knowledgeElementTypeService) {
+ _knowledgeElementTypeService = knowledgeElementTypeService;
+ }
}
\ No newline at end of file
import org.splat.kernel.Name;
import org.splat.dal.bo.kernel.User;
import org.splat.kernel.UserDirectory;
+import org.splat.service.DocumentTypeService;
import org.splat.service.StudyService;
import org.splat.som.ApplicationRights;
import org.splat.dal.dao.som.Database;
-import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.DocumentType;
import org.splat.dal.bo.som.Study;
import org.splat.som.StudyRights;
import org.splat.dal.bo.som.ValidationCycle;
import org.splat.dal.bo.som.ValidationStep;
-
+/**
+ * Edit/display study properties (study configuration) screen action.
+ */
public class StudyPropertiesAction extends DisplayStudyStepAction {
-// Presentation fields
- private List<User> staff;
- private List<User> member;
- private List<Name> validor;
- private List<ValidationFacade> validation;
- private ValidationFacade validefault;
- private List<DocumentType> other;
-
-// User input fields
- private Save tosave; // Edition action (title, contributors or cycle)
- private String edicycle;
- private String stitle; // Title of the study
- private String contributors; // List of existing contributors, some of them may have been removed
- private String candidates; // List of added contributors
- private long type; // Type of document to be included in the validation process
- private int publisher;
- private int reviewer;
- private int approver;
- private StudyService _studyService;
-
/**
* Serial version ID.
*/
private static final long serialVersionUID = 4210696018741092900L;
- private enum Save { title, contributor, cycle }
-
-// ==============================================================================================================================
-// Action methods
-// ==============================================================================================================================
-
- public String doInitialize () {
-// -----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
- validation = new Vector<ValidationFacade>();
- validefault = null;
- other = Document.selectResultTypes();
-
- Study study = mystudy.getStudyObject();
- StudyRights user = mystudy.getStudyRights();
- for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
- DocumentType type = i.next();
- ValidationCycle cycle = study.getValidationCycleOf(type);
- if (cycle.isDefault()) {
- validefault = new ValidationFacade(cycle);
- continue;
- }
- validation.add( new ValidationFacade(cycle) );
- i.remove();
- }
- if (validefault != null) validation.add(validefault); // In order to be at the end
- member = study.getContributors();
- staff = null;
- validor = null;
-
- transax.commit();
- if (mystudy.isOpenForWriting() && user.canEditProperties()) return "edit";
- else return "display";
- }
-
- public String doEditTitle () {
-// ----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
- validation = new Vector<ValidationFacade>();
- validefault = null;
- other = Document.selectResultTypes();
-
- Study study = mystudy.getStudyObject();
- for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
- DocumentType type = i.next();
- ValidationCycle cycle = study.getValidationCycleOf(type);
- if (cycle.isDefault()) {
- validefault = new ValidationFacade(cycle);
- continue;
- }
- validation.add( new ValidationFacade(cycle) );
- }
- if (validefault != null) validation.add(validefault); // In order to be at the end
- member = study.getContributors();
- staff = null;
- validor = null;
- other = null;
-
- transax.commit();
- return SUCCESS;
- }
-
- public String doEditContributors () {
-// -----------------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
- validation = new Vector<ValidationFacade>();
- validefault = null;
- other = Document.selectAllTypes();
-
- Study study = mystudy.getStudyObject();
- for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
- DocumentType type = i.next();
- ValidationCycle cycle = study.getValidationCycleOf(type);
- if (cycle.isDefault()) {
- validefault = new ValidationFacade(cycle);
- continue;
- }
- validation.add( new ValidationFacade(cycle) );
- }
- if (validefault != null) validation.add(validefault); // In order to be at the end
- member = study.getContributors();
- staff = UserDirectory.selectAllUsers();
- validor = null;
- other = null;
- User me = this.getConnectedUser();
- for (Iterator<User> i=staff.iterator(); i.hasNext(); ) {
- User next = i.next();
- ApplicationRights he = new ApplicationRights(next);
- if (next.equals(me) || member.contains(next) || !he.canContributeToStudy()) i.remove();
- }
- transax.commit();
- return SUCCESS;
- }
-
- public String doEditCycle () {
-// ----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
- validation = new Vector<ValidationFacade>();
- validefault = null;
- other = Document.selectResultTypes();
-
- Study study = mystudy.getStudyObject();
- for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
- DocumentType type = i.next();
- ValidationCycle cycle = study.getValidationCycleOf(type);
- if (cycle.isDefault()) {
- validefault = new ValidationFacade(cycle);
- continue;
- }
- if (type.getName().equals(edicycle)) {
- this.type = type.getIndex();
- }
- validation.add( new ValidationFacade(cycle) );
- i.remove();
- }
- if (validefault != null) validation.add(validefault); // In order to be at the end
- member = study.getContributors();
- validor = new Vector<Name>();
- staff = null;
- List<User> user = UserDirectory.selectAllUsers();
- for (Iterator<User> i=user.iterator(); i.hasNext(); ) {
- User next = i.next();
- ApplicationRights he = new ApplicationRights(next);
- if (he.canValidate()) {
- if (next.equals(study.getAuthor())) validor.add( new ValidationFacade.ByManager(next) );
- else validor.add(next);
- }
- }
- transax.commit();
- return SUCCESS;
- }
-
- public String doEdition () {
-// --------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- Study study = getOpenStudy().getStudyObject();
-
- if (tosave == Save.title) {
-
-// Edition of the title
- Study.Properties sprop = new Study.Properties();
- try {
- getStudyService().update(study, sprop.setTitle(stitle));
- }
- catch (InvalidPropertyException e) {
-//TODO
- }
- } else
- if (tosave == Save.contributor) {
-
-// Edition of contributors
- if (contributors == null) contributors = "";
- if (candidates == null) candidates = "";
-
- String[] parsekept = contributors.split(",");
- String[] parsenew = candidates.split(",");
- Vector<User> toremove = new Vector<User>(study.getContributors());
-
- for (int i=0; i<parsekept.length; i++) {
- if (parsekept[i].length() == 0) continue; // Yet no contributor
- int index = Integer.valueOf(parsekept[i].trim());
- for (Iterator<User> j=toremove.iterator(); j.hasNext(); ){
- long present = j.next().getIndex();
- if (present != index) continue;
- j.remove();
- break;
- }
- }
- int size = toremove.size();
- if (size > 0) getStudyService().removeContributor(study, toremove.toArray(new User[size]));
-
- for (int i=0; i<parsenew.length; i++) {
- if (parsenew[i].length() == 0) continue; // No any new contributor
- int index = Integer.valueOf(parsenew[i].trim());
- User newser = UserDirectory.selectUser(index);
-
- getStudyService().addContributor(study, newser);
- }
- } else
- if (tosave == Save.cycle) {
-
-// Addition of a document validation cycle
- DocumentType apply = Document.selectType(type);
- ValidationCycle.Properties vprop = new ValidationCycle.Properties();
- if (publisher > 0) {
- User actor = UserDirectory.selectUser(publisher);
- vprop.setActor(ValidationStep.PROMOTION, actor);
- }
- if (reviewer > 0) {
- User actor = UserDirectory.selectUser(reviewer);
- vprop.setActor(ValidationStep.REVIEW, actor);
- }
- if (approver > 0) {
- User actor = UserDirectory.selectUser(approver);
- vprop.setActor(ValidationStep.APPROVAL, actor);
- }
- getStudyService().setValidationCycle(study, apply, vprop);
- }
- transax.commit();
-
- doInitialize(); // Re-initialization following the above edition
- return SUCCESS;
+ // Presentation fields
+ private List<User> staff;
+ private List<User> member;
+ private List<Name> validor;
+ private List<ValidationFacade> validation;
+ private ValidationFacade validefault;
+ private List<DocumentType> other;
+
+ // User input fields
+ private Save tosave; // Edition action (title, contributors or cycle)
+ private String edicycle;
+ private String stitle; // Title of the study
+ private String contributors; // List of existing contributors, some of them may have been removed
+ private String candidates; // List of added contributors
+ private long type; // Type of document to be included in the validation process
+ private int publisher;
+ private int reviewer;
+ private int approver;
+
+ /**
+ * Injected study service.
+ */
+ private StudyService _studyService;
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
+
+ /**
+ * Save operation type enumeration pointing which section of properties has been edited.
+ */
+ private enum Save {
+ /**
+ * Save study title.
+ */
+ title,
+ /**
+ * Save contributors.
+ */
+ contributor,
+ /**
+ * Save validation cycle.
+ */
+ cycle
+ }
+
+ // ==============================================================================================================================
+ // Action methods
+ // ==============================================================================================================================
+
+ /**
+ * Initialize study properties action.
+ *
+ * @return "edit" if user can edit study properties, otherwise return "display"
+ */
+ public String doInitialize() {
+
+ mystudy = getOpenStudy();
+ validation = new Vector<ValidationFacade>();
+ validefault = null;
+ other = getDocumentTypeService().selectResultTypes();
+
+ Study study = mystudy.getStudyObject();
+ StudyRights user = mystudy.getStudyRights();
+ for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
+ if (cycle.isDefault()) {
+ validefault = new ValidationFacade(cycle);
+ continue;
+ }
+ validation.add(new ValidationFacade(cycle));
+ i.remove();
+ }
+ if (validefault != null)
+ validation.add(validefault); // In order to be at the end
+ member = getStudyService().getContributors(study);
+ staff = null;
+ validor = null;
+
+ if (mystudy.isOpenForWriting() && user.canEditProperties())
+ return "edit";
+ else
+ return "display";
+ }
+
+ public String doEditTitle() {
+ // ----------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+
+ mystudy = getOpenStudy();
+ validation = new Vector<ValidationFacade>();
+ validefault = null;
+ other = getDocumentTypeService().selectResultTypes();
+
+ Study study = mystudy.getStudyObject();
+ for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
+ if (cycle.isDefault()) {
+ validefault = new ValidationFacade(cycle);
+ continue;
+ }
+ validation.add(new ValidationFacade(cycle));
+ }
+ if (validefault != null)
+ validation.add(validefault); // In order to be at the end
+ member = getStudyService().getContributors(study);
+ staff = null;
+ validor = null;
+ other = null;
+
+ transax.commit();
+ return SUCCESS;
+ }
+
+ public String doEditContributors() {
+ // -----------------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+
+ mystudy = getOpenStudy();
+ validation = new Vector<ValidationFacade>();
+ validefault = null;
+ other = getDocumentTypeService().selectAllTypes();
+
+ Study study = mystudy.getStudyObject();
+ for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
+ if (cycle.isDefault()) {
+ validefault = new ValidationFacade(cycle);
+ continue;
+ }
+ validation.add(new ValidationFacade(cycle));
+ }
+ if (validefault != null)
+ validation.add(validefault); // In order to be at the end
+ member = getStudyService().getContributors(study);
+ staff = UserDirectory.selectAllUsers();
+ validor = null;
+ other = null;
+ User me = this.getConnectedUser();
+ for (Iterator<User> i = staff.iterator(); i.hasNext();) {
+ User next = i.next();
+ ApplicationRights he = new ApplicationRights(next);
+ if (next.equals(me) || member.contains(next)
+ || !he.canContributeToStudy())
+ i.remove();
+ }
+ transax.commit();
+ return SUCCESS;
+ }
+
+ public String doEditCycle() {
+ // ----------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+
+ mystudy = getOpenStudy();
+ validation = new Vector<ValidationFacade>();
+ validefault = null;
+ other = getDocumentTypeService().selectResultTypes();
+
+ Study study = mystudy.getStudyObject();
+ for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
+ if (cycle.isDefault()) {
+ validefault = new ValidationFacade(cycle);
+ continue;
+ }
+ if (type.getName().equals(edicycle)) {
+ this.type = type.getIndex();
+ }
+ validation.add(new ValidationFacade(cycle));
+ i.remove();
+ }
+ if (validefault != null)
+ validation.add(validefault); // In order to be at the end
+ member = getStudyService().getContributors(study);
+ validor = new Vector<Name>();
+ staff = null;
+ List<User> user = UserDirectory.selectAllUsers();
+ for (Iterator<User> i = user.iterator(); i.hasNext();) {
+ User next = i.next();
+ ApplicationRights he = new ApplicationRights(next);
+ if (he.canValidate()) {
+ if (next.equals(study.getAuthor()))
+ validor.add(new ValidationFacade.ByManager(next));
+ else
+ validor.add(next);
+ }
+ }
+ transax.commit();
+ return SUCCESS;
+ }
+
+ public String doEdition() {
+ // --------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+ Study study = getOpenStudy().getStudyObject();
+
+ if (tosave == Save.title) {
+
+ // Edition of the title
+ Study.Properties sprop = new Study.Properties();
+ try {
+ getStudyService().update(study, sprop.setTitle(stitle));
+ } catch (InvalidPropertyException e) {
+ // TODO
+ }
+ } else if (tosave == Save.contributor) {
+
+ // Edition of contributors
+ if (contributors == null)
+ contributors = "";
+ if (candidates == null)
+ candidates = "";
+
+ String[] parsekept = contributors.split(",");
+ String[] parsenew = candidates.split(",");
+ Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
+
+ for (int i = 0; i < parsekept.length; i++) {
+ if (parsekept[i].length() == 0)
+ continue; // Yet no contributor
+ int index = Integer.valueOf(parsekept[i].trim());
+ for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
+ long present = j.next().getIndex();
+ if (present != index)
+ continue;
+ j.remove();
+ break;
+ }
+ }
+ int size = toremove.size();
+ if (size > 0)
+ getStudyService().removeContributor(study,
+ toremove.toArray(new User[size]));
+
+ for (int i = 0; i < parsenew.length; i++) {
+ if (parsenew[i].length() == 0)
+ continue; // No any new contributor
+ int index = Integer.valueOf(parsenew[i].trim());
+ User newser = UserDirectory.selectUser(index);
+
+ getStudyService().addContributor(study, newser);
+ }
+ } else if (tosave == Save.cycle) {
+
+ // Addition of a document validation cycle
+ DocumentType apply = getDocumentTypeService().selectType(type);
+ ValidationCycle.Properties vprop = new ValidationCycle.Properties();
+ if (publisher > 0) {
+ User actor = UserDirectory.selectUser(publisher);
+ vprop.setActor(ValidationStep.PROMOTION, actor);
+ }
+ if (reviewer > 0) {
+ User actor = UserDirectory.selectUser(reviewer);
+ vprop.setActor(ValidationStep.REVIEW, actor);
+ }
+ if (approver > 0) {
+ User actor = UserDirectory.selectUser(approver);
+ vprop.setActor(ValidationStep.APPROVAL, actor);
+ }
+ getStudyService().setValidationCycle(study, apply, vprop);
+ }
+ transax.commit();
+
+ doInitialize(); // Re-initialization following the above edition
+ return SUCCESS;
+ }
+
+ // ==============================================================================================================================
+ // Getters
+ // ==============================================================================================================================
+
+ public User getAuthor() {
+ // ------------------------
+ return mystudy.getStudyObject().getAuthor();
+ }
+
+ public List<User> getCandidates() {
+ // ----------------------------------
+ return staff;
+ }
+
+ public String getCycle() {
+ // -------------------------
+ return edicycle;
+ }
+
+ public List<User> getContributors() {
+ // ------------------------------------
+ return member;
+ }
+
+ public ValidationFacade getDefaultValidation() {
+ // -----------------------------------------------
+ return validefault;
+ }
+
+ public long getDocumentTypeIndex() {
+ // ----------------------------------
+ return type;
+ }
+
+ public List<DocumentType> getOtherDocumentTypes() {
+ // --------------------------------------------------
+ return other;
+ }
+
+ public String getStudyTitle() {
+ // ------------------------------
+ return mystudy.getTitle();
+ }
+
+ public List<ValidationFacade> getValidations() {
+ // -----------------------------------------------
+ return validation;
+ }
+
+ public List<Name> getValidationActors() {
+ // ----------------------------------------
+ return validor;
+ }
+
+ // ==============================================================================================================================
+ // Setters
+ // ==============================================================================================================================
+
+ public void setCandidates(String indices) {
+ // ------------------------------------------
+ candidates = indices;
+ }
+
+ public void setCycle(String type) {
+ // ----------------------------------
+ edicycle = type;
+ }
+
+ public void setMembers(String indices) {
+ // ---------------------------------------
+ contributors = indices;
+ }
+
+ public void setDocumentType(String index) {
+ // ------------------------------------------
+ type = Integer.valueOf(index);
+ }
+
+ public void setApprover(String index) {
+ // --------------------------------------
+ approver = Integer.valueOf(index);
+ }
+
+ public void setPublisher(String index) {
+ // ---------------------------------------
+ publisher = Integer.valueOf(index);
+ }
+
+ public void setReviewer(String index) {
+ // --------------------------------------
+ reviewer = Integer.valueOf(index);
+ }
+
+ public void setTitle(String title) {
+ // -----------------------------------
+ stitle = title;
+ }
+
+ public void setSaveTitle(String save) {
+ // --------------------------------------
+ tosave = Save.title;
+ }
+
+ public void setSaveContributors(String save) {
+ // ---------------------------------------------
+ tosave = Save.contributor;
+ }
+
+ public void setSaveCycle(String save) {
+ // --------------------------------------
+ tosave = Save.cycle;
}
-// ==============================================================================================================================
-// Getters
-// ==============================================================================================================================
-
- public User getAuthor () {
-// ------------------------
- return mystudy.getStudyObject().getAuthor();
- }
- public List<User> getCandidates () {
-// ----------------------------------
- return staff;
- }
- public String getCycle () {
-// -------------------------
- return edicycle;
- }
- public List<User> getContributors () {
-// ------------------------------------
- return member;
- }
- public ValidationFacade getDefaultValidation () {
-// -----------------------------------------------
- return validefault;
- }
- public long getDocumentTypeIndex () {
-// ----------------------------------
- return type;
- }
- public List<DocumentType> getOtherDocumentTypes () {
-// --------------------------------------------------
- return other;
- }
- public String getStudyTitle () {
-// ------------------------------
- return mystudy.getTitle();
- }
- public List<ValidationFacade> getValidations () {
-// -----------------------------------------------
- return validation;
- }
- public List<Name> getValidationActors () {
-// ----------------------------------------
- return validor;
- }
-
-// ==============================================================================================================================
-// Setters
-// ==============================================================================================================================
-
- public void setCandidates (String indices) {
-// ------------------------------------------
- candidates = indices;
- }
- public void setCycle (String type) {
-// ----------------------------------
- edicycle = type;
- }
- public void setMembers (String indices) {
-// ---------------------------------------
- contributors = indices;
- }
- public void setDocumentType (String index) {
-// ------------------------------------------
- type = Integer.valueOf(index);
- }
- public void setApprover (String index) {
-// --------------------------------------
- approver = Integer.valueOf(index);
- }
- public void setPublisher (String index) {
-// ---------------------------------------
- publisher = Integer.valueOf(index);
- }
- public void setReviewer (String index) {
-// --------------------------------------
- reviewer = Integer.valueOf(index);
- }
- public void setTitle (String title) {
-// -----------------------------------
- stitle = title;
- }
- public void setSaveTitle (String save) {
-// --------------------------------------
- tosave = Save.title;
- }
- public void setSaveContributors (String save) {
-// ---------------------------------------------
- tosave = Save.contributor;
- }
- public void setSaveCycle (String save) {
-// --------------------------------------
- tosave = Save.cycle;
- }
/**
* Get the studyService.
*
public void setStudyService(StudyService studyService) {
_studyService = studyService;
}
+
+ /**
+ * Get the documentTypeService.
+ *
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
+ */
+ public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
}
\ No newline at end of file
<bean id="applicationSettings"
class="org.splat.simer.ApplicationSettings">
<property name="projectSettings" ref="projectSettings" />
+ <property name="documentTypeService" ref="documentTypeService" />
</bean>
<bean id="importedStudy" class="org.splat.simer.admin.ImportedStudy"
<property name="scenarioService" ref="scenarioService" />
</bean>
- <bean id="studyMenu" class="org.splat.simer.StudyMenu"
- scope="session" parent="slidMenu"/>
+ <bean id="studyMenu" class="org.splat.simer.StudyMenu"
+ scope="session" parent="slidMenu" />
- <bean id="newScenarioMenu" class="org.splat.simer.NewScenarioMenu"
- scope="session" parent="slidMenu"/>
+ <bean id="newScenarioMenu" class="org.splat.simer.NewScenarioMenu"
+ scope="session" parent="slidMenu" />
- <bean id="openStudy" class="org.splat.simer.OpenStudy"
- scope="session">
+ <bean id="openObject" abstract="true"
+ class="org.splat.simer.OpenObject" scope="session">
<property name="projectElementService"
ref="projectElementService" />
<property name="projectSettings" ref="projectSettings" />
+ <property name="knowledgeElementTypeService"
+ ref="knowledgeElementTypeService" />
+ </bean>
+
+ <bean id="openStudy" class="org.splat.simer.OpenStudy"
+ parent="openObject" scope="session">
+ <property name="projectElementService"
+ ref="projectElementService" />
<property name="publicationService" ref="publicationService" />
- <property name="scenarioService" ref="scenarioService" />
+ <property name="studyService" ref="studyService" />
<property name="stepService" ref="stepService" />
- <property name="repositoryService" ref="repositoryService" />
- <property name="menu" ref="studyMenu" />
+ <property name="repositoryService" ref="repositoryService" />
+ <property name="menu" ref="studyMenu" />
+ <property name="documentTypeService" ref="documentTypeService" />
</bean>
<bean id="openKnowledge" class="org.splat.simer.OpenKnowledge"
- scope="session">
- <property name="projectElementService"
- ref="projectElementService" />
- <property name="projectSettings" ref="projectSettings" />
+ parent="openObject" scope="session">
</bean>
<bean id="baseAction" class="org.splat.simer.Action"
scope="prototype">
<property name="projectElementService"
ref="projectElementService" />
- <property name="studyService" ref="studyService" />
- <property name="menu" ref="newScenarioMenu" />
+ <property name="scenarioService" ref="scenarioService" />
+ <property name="menu" ref="newScenarioMenu" />
</bean>
<bean id="importDocumentAction"
<property name="projectSettings" ref="projectSettings" />
<property name="publicationService" ref="publicationService" />
<property name="repositoryService" ref="repositoryService" />
+ <property name="documentTypeService" ref="documentTypeService" />
</bean>
<bean id="displayStudyStepAction"
<bean id="studyPropertiesAction"
class="org.splat.simer.StudyPropertiesAction" scope="prototype"
parent="displayStudyStepAction">
+ <property name="documentTypeService" ref="documentTypeService" />
</bean>
<bean id="editStudyAction" class="org.splat.simer.EditStudyAction"
<bean id="editDocumentAction"
class="org.splat.simer.EditDocumentAction" scope="prototype"
parent="displayStudyStepAction">
+ <property name="stepService" ref="stepService" />
<property name="publicationService" ref="publicationService" />
<property name="repositoryService" ref="repositoryService" />
</bean>
parent="displayStudyStepAction">
<property name="knowledgeElementService"
ref="knowledgeElementService" />
+ <property name="knowledgeElementTypeService"
+ ref="knowledgeElementTypeService" />
<property name="scenarioService" ref="scenarioService" />
</bean>
<property name="searchService" ref="searchService" />
<property name="simulationContextService"
ref="simulationContextService" />
+ <property name="knowledgeElementTypeService"
+ ref="knowledgeElementTypeService" />
</bean>
<bean id="searchDocumentAction"
<bean id="saveDocumentAction"
class="org.splat.module.SaveDocumentAction" scope="prototype">
+ <property name="documentTypeService" ref="documentTypeService" />
<property name="publicationService" ref="publicationService" />
<property name="repositoryService" ref="repositoryService" />
<property name="scenarioService" ref="scenarioService" />