import org.splat.dal.bo.som.ProgressState;
import org.splat.service.KnowledgeElementService;
import org.splat.service.SearchService;
+import org.splat.service.SimulationContextService;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.service.dto.Proxy;
import org.splat.dal.bo.som.SimulationContext;
import org.splat.dal.bo.som.SimulationContextType;
import org.splat.dal.bo.som.Study;
-
+/**
+ * Action for operations on simulation contexts.
+ */
public class SimulationContextAction extends Action {
- private List<SimulationContextFacade> tocheck; // Simulation contexts to be approved
- private int selection; // Index of the selected simulation context presented in the approval form
- private SimulationContext edition; // Corresponding simulation context object
- private ProjectSettingsService.Step step; // Study step to which the selected simulation context is attached
- private Set<ProjectElementFacade> owner; // Study scenarios indexed by this simulation context
- private List<LocalizedContextTypes> existype; // Existing approved simulation context types ordered by localized names
- private List<SimulationContextType> exisname; // Existing approved simulation context types ordered by internal codes
- private List<SimulationContext> existing; // Existing simulation contexts of selected type
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = 7083323229359094699L;
+
+ private List<SimulationContextFacade> tocheck; // Simulation contexts to be approved
+ private int selection; // Index of the selected simulation context presented in the approval form
+ private SimulationContext edition; // Corresponding simulation context object
+ private ProjectSettingsService.Step step; // Study step to which the selected simulation context is attached
+ private Set<ProjectElementFacade> owner; // Study scenarios indexed by this simulation context
+ private List<LocalizedContextTypes> existype; // Existing approved simulation context types ordered by localized names
+ private List<SimulationContextType> exisname; // Existing approved simulation context types ordered by internal codes
+ private List<SimulationContext> existing; // Existing simulation contexts of selected type
+ /**
+ * Injected search service.
+ */
private SearchService _searchService;
+ /**
+ * Injected project settings service.
+ */
private ProjectSettingsService _projectSettingsService;
+ /**
+ * Injected knowledge element service.
+ */
private KnowledgeElementService _knowledgeElementService;
+ /**
+ * Injected simulation context service.
+ */
+ private SimulationContextService _simulationContextService;
- private static final long serialVersionUID = 7083323229359094699L;
-
- private class ContextNameComparator implements Comparator<SimulationContextType> {
-// ---------------------------------------------------------------------------------
- public int compare(SimulationContextType t1, SimulationContextType t2)
- {
- String name1 = t1.getName();
- String name2 = t2.getName();
-
- return name1.compareToIgnoreCase(name2);
- }
- }
-
- public class LocalizedContextTypes {
-// ----------------------------------
- private Locale locale;
- private List<String> sortype; // Existing approved simulation context types ordered by localized names
-
- public LocalizedContextTypes (List<SimulationContextType> types, Locale lang)
- {
- ResourceBundle bundle = ResourceBundle.getBundle("som", lang);
- SimulationContextType[] tosort = types.toArray( new SimulationContextType[types.size()] );
- String[] name = new String[types.size()];
-
- for (int i=0; i<name.length; i++) name[i] = bundle.getString("type.context." + tosort[i].getName());
- Arrays.sort(name);
- sortype = Arrays.asList(name);
- locale = lang;
- }
- public String getLocale ()
- {
- return locale.toString();
- }
- public List<String> getTypeNames ()
- {
- return sortype;
- }
- public boolean isCurrent ()
- {
- return (locale.equals(ApplicationSettings.getCurrentLocale()));
- }
- }
-
-// ==============================================================================================================================
-// Action methods
-// ==============================================================================================================================
-
- public String doInitialize () {
-// -----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- SimulationContext.Properties cprop = new SimulationContext.Properties();
- List<SimulationContext> context = Database.selectSimulationContextsWhere(cprop.setState(ProgressState.inCHECK));
-
- tocheck = new Vector<SimulationContextFacade>(context.size());
- for (Iterator<SimulationContext> i=context.iterator(); i.hasNext(); ) {
- tocheck.add( new SimulationContextFacade(i.next(), getProjectSettings().getAllSteps()) );
- }
- selection = 0;
- edition = null;
- owner = null;
-
- transax.commit();
- return SUCCESS;
- }
- catch (Exception error) {
- logger.error("Reason:", error);
- return ERROR; // No need to roll-back the transaction as it is read-only
- }
- }
-
- public String doSelect () {
-// -------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- SimulationContext.Properties cprop = new SimulationContext.Properties();
- List<SimulationContext> context = Database.selectSimulationContextsWhere(cprop.setState(ProgressState.inCHECK));
- List<SimulationContext> selected = new ArrayList<SimulationContext>(1);
-
- tocheck = new Vector<SimulationContextFacade>(context.size());
- for (Iterator<SimulationContext> i=context.iterator(); i.hasNext(); ) {
- SimulationContext next = i.next();
- if (next.getIndex() == selection) {
- edition = next;
- selected.add(edition);
- }
- tocheck.add( new SimulationContextFacade(next, getProjectSettings().getAllSteps()) );
- }
- KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
- List<Proxy> kelm = getSearchService().selectKnowledgeElementsWhere(kprop.setSimulationContexts(selected).setState(ProgressState.inWORK));
-
- step = edition.getType().getAttachedStep();
- owner = new HashSet<ProjectElementFacade>();
- for (Iterator<Proxy> i=kelm.iterator(); i.hasNext(); ) {
- KnowledgeElement next = getKnowledgeElementService().selectKnowledgeElement(i.next().getIndex());
- ProjectElementFacade facade;
- if (step.appliesTo(Study.class)) facade = new ProjectElementFacade(next.getOwnerScenario().getOwnerStudy(), step);
- else facade = new ProjectElementFacade(next.getOwnerScenario(), step);
- owner.add(facade);
- }
- SimulationContextType.Properties sprop = new SimulationContextType.Properties();
- List<SimulationContextType> types = SimulationContext.selectTypesWhere(sprop.setState(ProgressState.APPROVED));
- Locale[] support = ApplicationSettings.getSupportedLocales();
-
-// Sort localized type names
- existype = new ArrayList<LocalizedContextTypes>(support.length);
- for (int i=0; i<support.length; i++) {
- existype.add( new LocalizedContextTypes(types, support[i]) );
- }
- SimulationContextType[] names = types.toArray( new SimulationContextType[types.size()] );
-
- Arrays.sort(names, new ContextNameComparator() );
- exisname = Arrays.asList(names);
-
- existing = Database.selectSimulationContextsWhere(cprop.setType(edition.getType()).setState(ProgressState.APPROVED));
-
- transax.commit();
- return SUCCESS;
- }
- catch (Exception error) {
- logger.error("Reason:", error);
- return ERROR; // No need to roll-back the transaction as it is read-only
- }
- }
-
-// ==============================================================================================================================
-// Getters and setters
-// ==============================================================================================================================
-
- /**
- * @return
+ /**
+ * Context name comparator.
*/
- public SearchService getSearchService() {
- // TODO Auto-generated method stub
- return _searchService;
+ private class ContextNameComparator implements
+ Comparator<SimulationContextType> {
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(SimulationContextType t1, SimulationContextType t2) {
+ String name1 = t1.getName();
+ String name2 = t2.getName();
+
+ return name1.compareToIgnoreCase(name2);
+ }
}
- public void setSearchService(SearchService searchService) {
- _searchService = searchService;
+ public class LocalizedContextTypes {
+ // ----------------------------------
+ private Locale locale;
+ private List<String> sortype; // Existing approved simulation context types ordered by localized names
+
+ public LocalizedContextTypes(List<SimulationContextType> types,
+ Locale lang) {
+ ResourceBundle bundle = ResourceBundle.getBundle("som", lang);
+ SimulationContextType[] tosort = types
+ .toArray(new SimulationContextType[types.size()]);
+ String[] name = new String[types.size()];
+
+ for (int i = 0; i < name.length; i++)
+ name[i] = bundle.getString("type.context."
+ + tosort[i].getName());
+ Arrays.sort(name);
+ sortype = Arrays.asList(name);
+ locale = lang;
+ }
+
+ public String getLocale() {
+ return locale.toString();
+ }
+
+ public List<String> getTypeNames() {
+ return sortype;
+ }
+
+ public boolean isCurrent() {
+ return (locale.equals(ApplicationSettings.getCurrentLocale()));
+ }
+ }
+
+ // ==============================================================================================================================
+ // Action methods
+ // ==============================================================================================================================
+
+ public String doInitialize() {
+ // -----------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+ try {
+ SimulationContext.Properties cprop = new SimulationContext.Properties();
+ List<SimulationContext> context = getSimulationContextService()
+ .selectSimulationContextsWhere(
+ cprop.setState(ProgressState.inCHECK));
+
+ tocheck = new Vector<SimulationContextFacade>(context.size());
+ for (Iterator<SimulationContext> i = context.iterator(); i
+ .hasNext();) {
+ tocheck.add(new SimulationContextFacade(i.next(),
+ getProjectSettings().getAllSteps()));
+ }
+ selection = 0;
+ edition = null;
+ owner = null;
+
+ transax.commit();
+ return SUCCESS;
+ } catch (Exception error) {
+ logger.error("Reason:", error);
+ return ERROR; // No need to roll-back the transaction as it is read-only
+ }
+ }
+
+ public String doSelect() {
+ // -------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+ try {
+ SimulationContext.Properties cprop = new SimulationContext.Properties();
+ List<SimulationContext> context = getSimulationContextService()
+ .selectSimulationContextsWhere(
+ cprop.setState(ProgressState.inCHECK));
+ List<SimulationContext> selected = new ArrayList<SimulationContext>(
+ 1);
+
+ tocheck = new Vector<SimulationContextFacade>(context.size());
+ for (Iterator<SimulationContext> i = context.iterator(); i
+ .hasNext();) {
+ SimulationContext next = i.next();
+ if (next.getIndex() == selection) {
+ edition = next;
+ selected.add(edition);
+ }
+ tocheck.add(new SimulationContextFacade(next,
+ getProjectSettings().getAllSteps()));
+ }
+ KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
+ List<Proxy> kelm = getSearchService().selectKnowledgeElementsWhere(
+ kprop.setSimulationContexts(selected).setState(
+ ProgressState.inWORK));
+
+ step = edition.getType().getAttachedStep();
+ owner = new HashSet<ProjectElementFacade>();
+ for (Iterator<Proxy> i = kelm.iterator(); i.hasNext();) {
+ KnowledgeElement next = getKnowledgeElementService()
+ .selectKnowledgeElement(i.next().getIndex());
+ ProjectElementFacade facade;
+ if (step.appliesTo(Study.class))
+ facade = new ProjectElementFacade(next.getOwnerScenario()
+ .getOwnerStudy(), step);
+ else
+ facade = new ProjectElementFacade(next.getOwnerScenario(),
+ step);
+ owner.add(facade);
+ }
+ SimulationContextType.Properties sprop = new SimulationContextType.Properties();
+ List<SimulationContextType> types = getSimulationContextService()
+ .selectTypesWhere(sprop.setState(ProgressState.APPROVED));
+ Locale[] support = ApplicationSettings.getSupportedLocales();
+
+ // Sort localized type names
+ existype = new ArrayList<LocalizedContextTypes>(support.length);
+ for (int i = 0; i < support.length; i++) {
+ existype.add(new LocalizedContextTypes(types, support[i]));
+ }
+ SimulationContextType[] names = types
+ .toArray(new SimulationContextType[types.size()]);
+
+ Arrays.sort(names, new ContextNameComparator());
+ exisname = Arrays.asList(names);
+
+ existing = getSimulationContextService()
+ .selectSimulationContextsWhere(
+ cprop.setType(edition.getType()).setState(
+ ProgressState.APPROVED));
+
+ transax.commit();
+ return SUCCESS;
+ } catch (Exception error) {
+ logger.error("Reason:", error);
+ return ERROR; // No need to roll-back the transaction as it is read-only
+ }
+ }
+
+ // ==============================================================================================================================
+ // Getters and setters
+ // ==============================================================================================================================
+
+ public List<ProjectSettingsService.Step> getAllStudySteps() {
+ // -----------------------------------------------------
+ return getProjectSettings().getAllSteps();
}
- public List<ProjectSettingsService.Step> getAllStudySteps () {
-// -----------------------------------------------------
- return getProjectSettings().getAllSteps();
- }
- /**
- * Get project settings.
+ /**
+ * Get project settings.
+ *
* @return Project settings service
*/
private ProjectSettingsService getProjectSettings() {
/**
* Set project settings service.
- * @param projectSettingsService project settings service
+ *
+ * @param projectSettingsService
+ * project settings service
*/
- public void setProjectSettings(
- ProjectSettingsService projectSettingsService) {
+ public void setProjectSettings(ProjectSettingsService projectSettingsService) {
_projectSettingsService = projectSettingsService;
}
- public ProjectSettingsService.Step getAttachedStep () {
-// ----------------------------------------------
- return step;
- }
- public List<SimulationContextFacade> getContextsToBeApproved () {
-// ---------------------------------------------------------------
- return tocheck;
- }
- public SimulationContext getEdited () {
-// -------------------------------------
- return edition;
- }
- public List<SimulationContext> getExistingContexts () {
-// -----------------------------------------------------
- return existing;
- }
- public List<SimulationContextType> getExistingNames () {
-// ------------------------------------------------------
- return exisname;
- }
- public List<LocalizedContextTypes> getSupportedLocales () {
-// ---------------------------------------------------------
- return existype;
- }
- public Set<ProjectElementFacade> getIndexedElements () {
-// ------------------------------------------------------
- return owner;
- }
- public int getSelection () {
-// --------------------------
- return selection;
- }
-
- public void setSelection (String index) {
-// ---------------------------------------
- selection = Integer.valueOf(index);
- }
+ public ProjectSettingsService.Step getAttachedStep() {
+ // ----------------------------------------------
+ return step;
+ }
+
+ public List<SimulationContextFacade> getContextsToBeApproved() {
+ // ---------------------------------------------------------------
+ return tocheck;
+ }
+
+ public SimulationContext getEdited() {
+ // -------------------------------------
+ return edition;
+ }
+
+ public List<SimulationContext> getExistingContexts() {
+ // -----------------------------------------------------
+ return existing;
+ }
+
+ public List<SimulationContextType> getExistingNames() {
+ // ------------------------------------------------------
+ return exisname;
+ }
+
+ public List<LocalizedContextTypes> getSupportedLocales() {
+ // ---------------------------------------------------------
+ return existype;
+ }
+
+ public Set<ProjectElementFacade> getIndexedElements() {
+ // ------------------------------------------------------
+ return owner;
+ }
+
+ public int getSelection() {
+ // --------------------------
+ return selection;
+ }
+
+ public void setSelection(String index) {
+ // ---------------------------------------
+ selection = Integer.valueOf(index);
+ }
/**
* Get the knowledgeElementService.
+ *
* @return the knowledgeElementService
*/
public KnowledgeElementService getKnowledgeElementService() {
/**
* Set the knowledgeElementService.
- * @param knowledgeElementService the knowledgeElementService to set
+ *
+ * @param knowledgeElementService
+ * the knowledgeElementService to set
*/
public void setKnowledgeElementService(
KnowledgeElementService knowledgeElementService) {
_knowledgeElementService = knowledgeElementService;
}
+
+ /**
+ * Get the simulationContextService.
+ *
+ * @return the simulationContextService
+ */
+ public SimulationContextService getSimulationContextService() {
+ return _simulationContextService;
+ }
+
+ /**
+ * Set the simulationContextService.
+ *
+ * @param simulationContextService
+ * the simulationContextService to set
+ */
+ public void setSimulationContextService(
+ SimulationContextService simulationContextService) {
+ _simulationContextService = simulationContextService;
+ }
+
+ /**
+ * Get the searchService.
+ * @return the searchService
+ */
+ public SearchService getSearchService() {
+ return _searchService;
+ }
+
+ /**
+ * Set the searchService.
+ * @param searchService the searchService to set
+ */
+ public void setSearchService(SearchService searchService) {
+ _searchService = searchService;
+ }
}
\ No newline at end of file