import java.util.Iterator;
import org.hibernate.Session;
+import org.splat.dal.bo.kernel.Relation;
+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.KnowledgeElement;
+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.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.UsedByRelation;
+import org.splat.dal.bo.som.UsesRelation;
+import org.splat.dal.bo.som.VersionsRelation;
+import org.splat.dal.dao.som.Database;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.MismatchException;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
import org.splat.kernel.NotApplicableException;
-import org.splat.kernel.Relation;
-import org.splat.kernel.User;
-import org.splat.som.Database;
+import org.splat.service.technical.IndexServiceImpl;
+import org.splat.service.technical.ProjectSettingsService;
public class Step {
- private ProjectSettings.Step step;
+ private ProjectSettingsService.Step step;
private ProjectElement owner;
private List<SimulationContext> contex;
- private List<Publication> docums;
+ private List<Publication> docums;
private User actor; // Actor involved in operations on published documents and requiring a time-stamp
// ==============================================================================================================================
// Constructor
// ==============================================================================================================================
- protected Step (ProjectSettings.Step step, ProjectElement owner) {
+ public Step (ProjectSettingsService.Step step, ProjectElement owner) {
// ----------------------------------------------------------------
this.step = step;
this.owner = owner;
return new Publication(newdoc, owner);
}
- public SimulationContext addSimulationContext (SimulationContext.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, RuntimeException {
-// ----------------------------------------------------------------------------------
- SimulationContext context = new SimulationContext(dprop.setStep(step));
- return addSimulationContext(context);
- }
-
- public SimulationContext addSimulationContext (SimulationContext context) {
-// -------------------------------------------------------------------------
- context.hold(); // Increments the reference count of simulation context
- if (owner.isSaved()) try {
- Session session = Database.getSession();
- Index lucin = Database.getIndex();
-
- if (!context.isSaved()) session.save(context);
- owner.add(context);
- contex.add(context); // The context is also referenced from this (transient) Step
- session.update(owner);
- updateKnowledgeElementsIndex(lucin);
- }
- catch (Exception error) {
- return null;
- }
- else { // Happens when copying a scenario
- owner.add(context);
- contex.add(context); // The context is also referenced from this (transient) Step
-// In case of owner scenario, the Knowledge Element index will be updated later, when saving the scenario
- }
- return context;
- }
-
public User getActor () {
// -----------------------
return actor;
return result;
}
- public ProjectSettings.Step getStep () {
+ public ProjectSettingsService.Step getStep () {
// --------------------------------------
return step;
}
return true;
}
- public boolean removeSimulationContext (SimulationContext context) {
-// ------------------------------------------------------------------
- SimulationContext torem = getSimulationContext(context.getIndex());
- Session session = Database.getSession();
-
- if (torem == null) return false;
- if (!owner.remove(torem)) return false;
-
- contex.remove(torem);
- session.update(owner);
- if (torem.isShared()) {
- torem.release();
- session.update(torem);
- } else {
- session.delete(torem);
- }
- return true;
- }
-
public void setActor (User user) {
// --------------------------------
actor = user;
// Protected member functions
// ==============================================================================================================================
- protected boolean add (Publication newdoc) {
+ public boolean add (Publication newdoc) {
// ------------------------------------------
if (!owner.add(newdoc)) return false; // Updates the study in memory
docums.add(0, newdoc); // Updates this step
return true;
}
- protected boolean remove (Publication oldoc) {
+ public boolean remove (Publication oldoc) {
// --------------------------------------------
if (!owner.remove(oldoc)) return false; // Updates the study in memory
docums.remove(oldoc); // Updates this step
return true;
}
-// ==============================================================================================================================
-// Private services
-// ==============================================================================================================================
+ public List<SimulationContext> getContex() {
+ return contex;
+ }
- private void updateKnowledgeElementsIndex(Index lucin) {
-// ------------------------------------------------------
- Scenario[] scenarii;
- if (owner instanceof Scenario) {
- scenarii = new Scenario[1];
- scenarii[0] = (Scenario)owner;
- } else {
- scenarii = getOwnerStudy().getScenarii();
- }
- try {
- for (int i=0; i<scenarii.length; i++) {
- Scenario scene = scenarii[i];
- List<KnowledgeElement> knelm = scene.getAllKnowledgeElements();
- for (Iterator<KnowledgeElement> j=knelm.iterator(); j.hasNext(); ) {
- KnowledgeElement kelm = j.next();
- lucin.update(kelm);
- }
- scene.updateMyIndex(lucin);
- }
- }
- catch (Exception error) {
-// logger.error("Unable to re-index Knowledge Elements, reason:", error);
- }
- }
}
\ No newline at end of file