import java.util.List;
import java.util.Map;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.splat.kernel.InvalidPropertyException;
-import org.splat.kernel.User;
-import org.splat.kernel.UserDirectory;
-import org.splat.som.Database;
-import org.splat.som.ProgressState;
-import org.splat.som.ProjectSettings;
-import org.splat.som.SimulationContext;
-import org.splat.som.SimulationContextType;
-import org.splat.som.Study;
-import org.splat.som.Visibility;
-import org.splat.wapp.Item;
-import org.splat.wapp.TabBar;
-
+import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.service.SearchService;
+import org.splat.service.SimulationContextService;
+import org.splat.service.UserService;
+import org.splat.service.technical.ProjectSettingsService;
+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.Visibility;
+/**
+ * Search studies form action.
+ *
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
public class SearchStudyAction extends SearchBaseAction {
- private TabBar area = null; // Active repository area
- private String state = null; // "inPROGRESS", "inCHECK" or "END"
- private String among = null; // "all", "mine" or "ref"
- private String refid = null; // Study reference when among ref
- private String words = null; // Full text search words
+ 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.
+ */
+ private SimulationContextService _simulationContextService;
+ /**
+ * Injected user service.
+ */
+ private UserService _userService;
+ /**
+ * Serial version ID.
+ */
private static final long serialVersionUID = -1910481357051393077L;
- enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext }
-
-// ==============================================================================================================================
-// Action methods
-// ==============================================================================================================================
-
- public String doInitialize () {
-// -----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- loadFilter();
- if (newarea != null) { // New selected repository area
- area.selects(newarea);
- }
- 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<String, Object> session = getSession();
- User user = getConnectedUser();
-
- Study.Properties sprop = new Study.Properties();
- Study.Properties other = null;
-
-// Set of the selected repository area
- String selectab = area.getSelection().toUpperCase();
- Visibility reparea = Visibility.valueOf(selectab);
- sprop.setVisibility(reparea);
-
-// Search from a given reference
- if (among.equals("ref")) {
- if (refid.length() == 0) {
- getSession().remove("search.result"); // The current result is obsolete
- return "wait";
- }
- sprop.setReference(refid);
- if (reparea == Visibility.PRIVATE) { // Restriction to studies in which the connected user is involved
- other = sprop.copy().setActor(user);
- sprop.setManager(user);
- }
- } else {
-// Search from other available criteria
- if (this.state != null) {
- ProgressState state = ProgressState.APPROVED; // Trick for the Public and Reference areas to not share the APPROVED state
- if (!this.state.equals("ARCHIVED")) state = ProgressState.valueOf(this.state);
- sprop.setState(state);
- }
- if (words.length() > 0) sprop.setTitle(words);
- if (context.size() > 0) sprop.setSimulationContexts(context);
- if (among.equals("mine")) sprop.setManager(user);
- else if (among.equals("his")) {
- User him = UserDirectory.selectUser(Integer.valueOf(author));
- sprop.setManager(him);
- if (reparea == Visibility.PRIVATE) sprop.setActor(user);
- } else //among.equals("all")
- if (reparea == Visibility.PRIVATE) {
- other = sprop.copy().setActor(user);
- sprop.setManager(user);
- }
- }
- if (other == null) result = Database.selectStudiesWhere(sprop);
- else result = Database.selectStudiesWhere(sprop, other);
-
- session.put("search.result", result); // For redisplaying the page without re-executing the search
- return "refresh";
- }
-
-// ==============================================================================================================================
-// Getters
-// ==============================================================================================================================
-
- public String getArea () {
-// ------------------------
- return area.getSelection();
- }
- public String getOwner () {
-// -------------------------
- return among;
- }
- public String getReference () {
-// -----------------------------
- return refid;
- }
- public String getState () {
-// -------------------------
- return state;
- }
- public List<Item> getTabs () {
-// ----------------------------
- return area.asList();
- }
- public String getWords () {
-// -------------------------
- return words;
- }
-
-// ==============================================================================================================================
-// Setters
-// ==============================================================================================================================
-
- public void setOwner (String value) {
-// -----------------------------------
- this.among = value;
- }
- public void setReference (String value) {
-// ---------------------------------------
- this.refid = value;
- }
- public void setState (String value) {
-// -----------------------------------
- this.state = value;
- }
- public void setWords (String value) {
-// -----------------------------------
- this.words = value;
- }
-
-// ==============================================================================================================================
-// Implementation of abstract services
-// ==============================================================================================================================
-
- protected List<SimulationContextType> getInvolvedContexts () {
-// ------------------------------------------------------------
- List<ProjectSettings.Step> steps = ProjectSettings.getStepsOf(Study.class);
- ProjectSettings.Step[] number = steps.toArray(new ProjectSettings.Step[steps.size()]);
-
- return SimulationContext.selectTypesOf(number);
- }
-
- @SuppressWarnings("unchecked")
- protected void loadFilter () {
-// ----------------------------
- Map<String,Object> session = getSession();
- User user = getConnectedUser();
- Map<String,Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
-
- area = (TabBar)filter.get("area");
- state = (String)filter.get("state");
- among = (String)filter.get("owner");
- author = (String)filter.get("author");
- refid = (String)filter.get("reference");
- words = (String)filter.get("title");
- context = (List<SimulationContext>)filter.get("context");
-
- if (user == null) {
- area.disables("private");
- if (area.getSelection().equals("private")) area.selects("public");
- if (among.equals("mine")) among = "all";
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void saveFilter () {
-// ----------------------------
- Map<String, Object> session = getSession();
- Map<String, Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
-
- area = (TabBar)filter.get("area"); // The area being not an input, it is null when submitting the form
- if (among.equals("ref")) {
- filter.put("owner", "ref");
- filter.put("reference", this.refid);
- } else {
- filter.put("state", this.state);
- filter.put("owner", this.among);
- 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
- }
- }
+ 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<String, Object> 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<SimulationContextType> getInvolvedContexts() {
+ // ------------------------------------------------------------
+ List<ProjectSettingsService.Step> 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<String, Object> session = getSession();
+ User user = getConnectedUser();
+ Map<String, Object> filter = (Map<String, Object>) 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<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("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<SimulationContext>) filter.get("context"); // Only criteria not part of the form
+
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Get project settings.
+ *
+ * @return Project settings service
+ */
+ private ProjectSettingsService getProjectSettings() {
+ return _projectSettingsService;
+ }
+
+ /**
+ * Set project settings service.
+ *
+ * @param projectSettingsService
+ * project settings service
+ */
+ public void setProjectSettings(ProjectSettingsService projectSettingsService) {
+ _projectSettingsService = projectSettingsService;
+ }
+
+ /**
+ * Get the simulationContextService.
+ *
+ * @return the simulationContextService
+ */
+ public SimulationContextService getSimulationContextService() {
+ return _simulationContextService;
+ }
+
+ /**
+ * Set the simulationContextService.
+ *
+ * @param simulationContextService
+ * the simulationContextService to set
+ */
+ public void setSimulationContextService(
+ SimulationContextService simulationContextService) {
+ _simulationContextService = simulationContextService;
+ }
+
+ /**
+ * Get the userService.
+ *
+ * @return the userService
+ */
+ public UserService getUserService() {
+ return _userService;
+ }
+
+ /**
+ * Set the userService.
+ *
+ * @param userService
+ * the userService to set
+ */
+ public void setUserService(UserService userService) {
+ _userService = userService;
+ }
}
\ No newline at end of file