X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Workspace%2FSiman%2Fsrc%2Forg%2Fsplat%2Fsimer%2FSearchStudyAction.java;fp=Workspace%2FSiman%2Fsrc%2Forg%2Fsplat%2Fsimer%2FSearchStudyAction.java;h=e6e8c06ff0a9dfcb1f2492b5916c2c041da83efd;hb=f36135f335811f85897f27467d3b42eefcc30acf;hp=188e5f07f6e3d79eef7de7228222477d720af81b;hpb=c67536311c955b7cff290cc0d9001da1710e9cd5;p=tools%2Fsiman.git diff --git a/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java b/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java index 188e5f0..e6e8c06 100644 --- a/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java +++ b/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java @@ -3,11 +3,8 @@ package org.splat.simer; import java.util.List; import java.util.Map; -import org.hibernate.Session; -import org.hibernate.Transaction; import org.splat.kernel.InvalidPropertyException; import org.splat.dal.bo.kernel.User; -import org.splat.dal.dao.som.Database; import org.splat.dal.bo.som.ProgressState; import org.splat.service.SearchService; import org.splat.service.SimulationContextService; @@ -18,17 +15,27 @@ import org.splat.dal.bo.som.SimulationContextType; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.Visibility; - +/** + * Search studies form action. + * + * @author Roman Kozlov (RKV) + */ public class SearchStudyAction extends SearchBaseAction { - private String visibility = null; // "Private", "Public", "All" - private String state = null; // "In-Work", "In-Draft", "In-Check"... - private String matchamong = null; // "all" or "any" - private String matcontext = null; // "all" or "any" - private String refid = null; // Study reference - private String words = null; // Full text search words - private SearchService _searchService; + private String visibility = null; // "Private", "Public", "All" + private String state = null; // "In-Work", "In-Draft", "In-Check"... + private String matchamong = null; // "all" or "any" + private String matcontext = null; // "all" or "any" + private String refid = null; // Study reference + private String words = null; // Full text search words + /** + * Injected project settings service. + */ private ProjectSettingsService _projectSettingsService; + /** + * Injected search service. + */ + private SearchService _searchService; /** * Injected simulation context service. */ @@ -43,184 +50,207 @@ public class SearchStudyAction extends SearchBaseAction { */ private static final long serialVersionUID = -1910481357051393077L; - enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext } - -// ============================================================================================================================== -// Action methods -// ============================================================================================================================== - - public String doInitialize () { -// ----------------------------- - Session connex = Database.getCurSession(); - Transaction transax = connex.beginTransaction(); - try { - loadFilter(); - doSearch(); - -// Final initialization of the form - 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 session = getSession(); - User user = getConnectedUser(); - - Study.Properties sprop = new Study.Properties(); - -// Search matching all criteria - if (!this.state.equals("ANY")) sprop.setState( ProgressState.valueOf(this.state) ); - 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 = getUserService().selectUser(index); - sprop.setManager(him); - } -// Set of the visibility - if (visibility.equals("all")) { - Study.Properties other = sprop.copy(); - - other.setVisibility(Visibility.PUBLIC); - sprop.setVisibility(Visibility.PRIVATE); - sprop.setActor(user); - - result = getSearchService().selectStudiesWhere(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().selectStudiesWhere(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 String getReference () { -// ----------------------------- - return refid; - } - public String getState () { -// ------------------------- - return state; - } - 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.state = value; - } - public void setVisibility (String value) { -// ---------------------------------------- - this.visibility = value; - } - public void setWords (String value) { -// ----------------------------------- - this.words = value; - } - -// ============================================================================================================================== -// Implementation of abstract services -// ============================================================================================================================== - - protected List getInvolvedContexts () { -// ------------------------------------------------------------ - List steps = getProjectSettings().getStepsOf(Study.class); - ProjectSettingsService.Step[] number = steps.toArray(new ProjectSettingsService.Step[steps.size()]); - - return getSimulationContextService().selectTypesOf(number); + enum UserAction { + refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext + } + + // ============================================================================================================================== + // Action methods + // ============================================================================================================================== + + /** + * Initialize study search form. + * @return SUCCESS if no exception, otherwise return ERROR + */ + public String doInitialize() { + try { + loadFilter(); + doSearch(); + + // Final initialization of the form + 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; + } + } + + protected String doSearch() throws InvalidPropertyException { + // ---------------------------- + Map session = getSession(); + User user = getConnectedUser(); + + Study.Properties sprop = new Study.Properties(); + + // Search matching all criteria + if (!this.state.equals("ANY")) + sprop.setState(ProgressState.valueOf(this.state)); + 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 = getUserService().selectUser(index); + sprop.setManager(him); + } + // Set of the visibility + if (visibility.equals("all")) { + Study.Properties other = sprop.copy(); + + other.setVisibility(Visibility.PUBLIC); + sprop.setVisibility(Visibility.PRIVATE); + sprop.setActor(user); + + result = getSearchService().selectStudiesWhere(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().selectStudiesWhere(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 String getReference() { + // ----------------------------- + return refid; + } + + public String getState() { + // ------------------------- + return state; + } + + public String getVisibility() { + // ------------------------------ + return visibility; + } + + public String getWords() { + // ------------------------- + return words; + } + + // ============================================================================================================================== + // Setters + // ============================================================================================================================== + + public void setContextMatch(String value) { + // ------------------------------------------ + this.matcontext = value; } - @SuppressWarnings("unchecked") - protected void loadFilter () { -// ---------------------------- - Map session = getSession(); - User user = getConnectedUser(); - Map filter = (Map)session.get("study.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"); - state = (String)filter.get("state"); - author = (String)filter.get("author"); - refid = (String)filter.get("reference"); - words = (String)filter.get("title"); - context = (List)filter.get("context"); - - if (user == null) { - visibility = "onlypublic"; - } - } - - @SuppressWarnings("unchecked") - protected void saveFilter () { -// ---------------------------- - Map session = getSession(); - Map filter = (Map)session.get("study.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("state", this.state); - filter.put("author", this.author); - filter.put("reference", this.refid); - filter.put("title", this.words); - - context = (List)filter.get("context"); // Only criteria not part of the form - - } - /** + public void setCriteriaMatch(String value) { + // ------------------------------------------- + this.matchamong = value; + } + + public void setReference(String value) { + // --------------------------------------- + this.refid = value; + } + + public void setState(String value) { + // ----------------------------------- + this.state = value; + } + + public void setVisibility(String value) { + // ---------------------------------------- + this.visibility = value; + } + + public void setWords(String value) { + // ----------------------------------- + this.words = value; + } + + // ============================================================================================================================== + // Implementation of abstract services + // ============================================================================================================================== + + protected List getInvolvedContexts() { + // ------------------------------------------------------------ + List steps = getProjectSettings() + .getStepsOf(Study.class); + ProjectSettingsService.Step[] number = steps + .toArray(new ProjectSettingsService.Step[steps.size()]); + + return getSimulationContextService().selectTypesOf(number); + } + + @SuppressWarnings("unchecked") + protected void loadFilter() { + // ---------------------------- + Map session = getSession(); + User user = getConnectedUser(); + Map filter = (Map) session + .get("study.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"); + state = (String) filter.get("state"); + author = (String) filter.get("author"); + refid = (String) filter.get("reference"); + words = (String) filter.get("title"); + context = (List) filter.get("context"); + + if (user == null) { + visibility = "onlypublic"; + } + } + + @SuppressWarnings("unchecked") + protected void saveFilter() { + // ---------------------------- + Map session = getSession(); + Map filter = (Map) session + .get("study.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("state", this.state); + filter.put("author", this.author); + filter.put("reference", this.refid); + filter.put("title", this.words); + + context = (List) filter.get("context"); // Only criteria not part of the form + + } + + /** * Get the searchService. + * * @return the searchService */ public SearchService getSearchService() { @@ -229,13 +259,17 @@ public class SearchStudyAction extends SearchBaseAction { /** * Set the searchService. - * @param searchService the searchService to set + * + * @param searchService + * the searchService to set */ public void setSearchService(SearchService searchService) { _searchService = searchService; } - /** - * Get project settings. + + /** + * Get project settings. + * * @return Project settings service */ private ProjectSettingsService getProjectSettings() { @@ -244,10 +278,11 @@ public class SearchStudyAction extends SearchBaseAction { /** * 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; } @@ -273,6 +308,7 @@ public class SearchStudyAction extends SearchBaseAction { /** * Get the userService. + * * @return the userService */ public UserService getUserService() { @@ -281,7 +317,9 @@ public class SearchStudyAction extends SearchBaseAction { /** * Set the userService. - * @param userService the userService to set + * + * @param userService + * the userService to set */ public void setUserService(UserService userService) { _userService = userService;