package org.splat.simer;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.splat.kernel.InvalidPropertyException;
-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;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.service.SearchService;
+import org.splat.service.dto.StudySearchFilterDTO;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.StepsConfigService;
+import org.splat.wapp.Constants;
/**
* Search studies form action.
- *
- * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
*/
-public class SearchStudyAction extends SearchBaseAction {
+public class SearchStudyAction extends
+ AbstractSearchBaseAction<StudySearchFilterDTO> {
+
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = -1910481357051393077L;
- 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;
+ private StepsConfigService _stepsConfigService;
/**
* Injected search service.
*/
private SearchService _searchService;
- /**
- * Injected simulation context service.
- */
- private SimulationContextService _simulationContextService;
- /**
- * Injected user service.
- */
- private UserService _userService;
-
- /**
- * Value of the menu property.
- * It can be: none, create, open, study, knowledge, sysadmin, help.
- */
- private String _menuProperty;
-
- /**
- * Value of the tool bar property.
- * It can be: none, standard, study, back.
- */
- private String _toolProperty;
-
- /**
- * Value of the left menu property.
- * It can be: open, study, knowledge, scenario.
- */
- private String _leftMenuProperty;
-
- /**
- * Serial version ID.
- */
- private static final long serialVersionUID = -1910481357051393077L;
-
- enum UserAction {
- refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
- }
// ==============================================================================================================================
// Action methods
/**
* Initialize study search form.
+ *
* @return SUCCESS if no exception, otherwise return ERROR
*/
public String doInitialize() {
+ String res = SUCCESS;
try {
loadFilter();
doSearch();
// Final initialization of the form
setCandidates();
setContextTypeOptions(getInvolvedContexts());
-
- setMenuProperty("open");
- setToolProperty("none");
- setLeftMenuProperty("open");
- initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
+ initializationFullScreenContext(Constants.OPEN, Constants.NONE,
+ Constants.OPEN);
- return SUCCESS;
} catch (Exception error) {
// No need to roll back the transaction as it is read only
LOG.error("Reason: ", error);
-
- setMenuProperty("none");
- initializationScreenContext(_menuProperty);
-
- return ERROR;
- }
- }
-
- protected String doSearch() throws InvalidPropertyException {
- // ----------------------------
- Map<String, Object> session = getSession();
- User user = getConnectedUser();
- Study.Properties sprop = new Study.Properties();
+ initializationScreenContext(Constants.NONE);
- // 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);
+ res = ERROR;
}
- // 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);
+ return res;
+ }
- result = getSearchService().selectStudiesWhere(sprop);
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
+ */
+ @Override
+ protected String doSearch() throws InvalidPropertyException {
+ if (getConnectedUser() != null) {
+ getFilter().setConnectedUserId(getConnectedUser().getIndex());
}
- session.put("search.result", result); // For redisplaying the page without re-executing the search
+ _result = getSearchService().selectStudiesWhere(getFilter());
+ getSession().put(RESULT_KEY, _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
- // ==============================================================================================================================
-
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.AbstractSearchBaseAction#getInvolvedContexts()
+ */
+ @Override
protected List<SimulationContextType> getInvolvedContexts() {
- // ------------------------------------------------------------
- List<ProjectSettingsService.Step> steps = getProjectSettings()
+ List<ProjectSettingsService.Step> steps = getStepsConfigService()
.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";
+ /**
+ * Get match options.
+ *
+ * @return array of options with key and value properties
+ */
+ public Map<String, String> getStateOptions() {
+ Map<String, String> options = new LinkedHashMap<String, String>();
+ addStateOption(options, "ANY");
+ if (getConnectedUser() != null) {
+ addStateOption(options, ProgressState.inWORK.name());
+ addStateOption(options, ProgressState.inDRAFT.name());
+ addStateOption(options, ProgressState.inCHECK.name());
}
+ addStateOption(options, ProgressState.APPROVED.name());
+ addStateOption(options, ProgressState.TEMPLATE.name());
+ return options;
}
- @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
-
+ /**
+ * Add a state and its translation to the list (map) of options.
+ *
+ * @param options
+ * the map of options
+ * @param state
+ * the state to add
+ */
+ private void addStateOption(final Map<String, String> options,
+ final String state) {
+ options.put(state, getText("criterion." + state.toLowerCase()));
}
/**
* @param searchService
* the searchService to set
*/
- public void setSearchService(SearchService searchService) {
+ public void setSearchService(final SearchService searchService) {
_searchService = searchService;
}
/**
- * Get project settings.
+ * Get StepsConfigService.
*
- * @return Project settings service
+ * @return StepsConfigService
*/
- private ProjectSettingsService getProjectSettings() {
- return _projectSettingsService;
+ private StepsConfigService getStepsConfigService() {
+ return _stepsConfigService;
}
/**
- * Set project settings service.
+ * Set StepsConfigService.
*
- * @param projectSettingsService
- * project settings service
+ * @param stepsConfigService
+ * StepsConfigService
*/
- public void setProjectSettings(ProjectSettingsService projectSettingsService) {
- _projectSettingsService = projectSettingsService;
+ public void setStepsConfigService(
+ final StepsConfigService stepsConfigService) {
+ _stepsConfigService = stepsConfigService;
}
/**
- * Get the simulationContextService.
+ * {@inheritDoc}
*
- * @return the simulationContextService
+ * @see org.splat.simer.AbstractSearchBaseAction#getFilterName()
*/
- public SimulationContextService getSimulationContextService() {
- return _simulationContextService;
+ @Override
+ protected String getFilterName() {
+ return "study.filter";
}
/**
- * Set the simulationContextService.
+ * {@inheritDoc}
*
- * @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;
- }
-
- /**
- * Get the menuProperty.
- * @return the menuProperty
- */
- public String getMenuProperty() {
- return _menuProperty;
- }
-
- /**
- * Set the menuProperty.
- * @param menuProperty the menuProperty to set
- */
- public void setMenuProperty(String menuProperty) {
- this._menuProperty = menuProperty;
- }
-
- /**
- * Get the toolProperty.
- * @return the toolProperty
- */
- public String getToolProperty() {
- return _toolProperty;
- }
-
- /**
- * Set the toolProperty.
- * @param toolProperty the toolProperty to set
- */
- public void setToolProperty(final String toolProperty) {
- _toolProperty = toolProperty;
- }
-
- /**
- * Get the leftMenuProperty.
- * @return the leftMenuProperty
- */
- public String getLeftMenuProperty() {
- return _leftMenuProperty;
- }
-
- /**
- * Set the leftMenuProperty.
- * @param leftMenuProperty the leftMenuProperty to set
+ * @see org.splat.simer.AbstractSearchBaseAction#getNewFilter()
*/
- public void setLeftMenuProperty(final String leftMenuProperty) {
- _leftMenuProperty = leftMenuProperty;
+ @Override
+ protected StudySearchFilterDTO getNewFilter() {
+ return new StudySearchFilterDTO();
}
}
\ No newline at end of file