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.KnowledgeElement;
-import org.splat.som.KnowledgeElementType;
-import org.splat.som.ProgressState;
-import org.splat.som.SimulationContext;
-import org.splat.som.SimulationContextType;
-import org.splat.som.Visibility;
-
+import org.splat.dal.bo.kernel.User;
+import org.splat.service.KnowledgeElementTypeService;
+import org.splat.service.SearchService;
+import org.splat.service.SimulationContextService;
+import org.splat.service.UserService;
+import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.KnowledgeElementType;
+import org.splat.dal.bo.som.ProgressState;
+import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.SimulationContextType;
+import org.splat.dal.bo.som.Visibility;
+/**
+ * Action for searching a knowledge in the database.
+ */
public class SearchKnowledgeAction extends SearchBaseAction {
- private String visibility = null; // "Private", "Public", "All"
- private String typid = null; // Knowledge type index when among all
- private String matchamong = null; // "all" or "any"
- private String matcontext = null; // "all" or "any"
- private String refid = null; // Knowledge reference when among ref
- private String words = null; // Full text search words
- private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
-
- private static final long serialVersionUID = -3104321907432838476L;
-
-// ==============================================================================================================================
-// Action methods
-// ==============================================================================================================================
-
- public String doInitialize () {
-// -----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- loadFilter();
- doSearch();
-
-// Final initialization of the form
- types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
- 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();
-
- KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
-
-// Search matching all criteria
- sprop.setType( KnowledgeElement.selectType(Integer.valueOf(typid)) );
- 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 = UserDirectory.selectUser(index);
- sprop.setAuthor(him);
- }
-// Set of the visibility
- if (visibility.equals("all")) {
- KnowledgeElement.Properties other = sprop.copy();
-
- other.setVisibility(Visibility.PUBLIC);
- sprop.setVisibility(Visibility.PRIVATE);
- sprop.setActor(user);
-
- result = Database.selectKnowledgeElementsWhere(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 = Database.selectKnowledgeElementsWhere(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 List<KnowledgeElementType> getKnowledgeTypes () {
-// ------------------------------------------------------
- return types;
- }
- public String getReference () {
-// -----------------------------
- return refid;
- }
- public String getState () {
-// ------------------------
- return typid;
- }
- 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.typid = 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 () {
-// ------------------------------------------------------------
- return SimulationContext.selectAllTypes();
- }
-
- @SuppressWarnings("unchecked")
- protected void loadFilter () {
-// ----------------------------
- Map<String,Object> session = getSession();
- User user = getConnectedUser();
- Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.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");
- typid = (String)filter.get("type");
- 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";
- }
- }
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = -3104321907432838476L;
+
+ private String visibility = null; // "Private", "Public", "All"
+ private String typid = null; // Knowledge type index when among all
+ private String matchamong = null; // "all" or "any"
+ private String matcontext = null; // "all" or "any"
+ private String refid = null; // Knowledge reference when among ref
+ private String words = null; // Full text search words
+ private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
+ private SearchService _searchService;
+ /**
+ * Injected simulation context service.
+ */
+ private SimulationContextService _simulationContextService;
+ /**
+ * Injected knowledge element service.
+ */
+ private KnowledgeElementTypeService _knowledgeElementTypeService;
+
+ /**
+ * Injected user service.
+ */
+ private UserService _userService;
+
+ /**
+ * Value of the menu property.
+ * It can be: none, create, open, study, knowledge, sysadmin, help.
+ */
+ private String _menuProperty;
+
+ // ==============================================================================================================================
+ // Action methods
+ // ==============================================================================================================================
+
+ /**
+ * The action initialization.
+ *
+ * @return SUCCESS if succeeded, ERROR if doSearch() is failed
+ */
+ public String doInitialize() {
+
+ setMenuProperty("open");
+ initializationScreenContext(_menuProperty);
+
+ try {
+ loadFilter();
+ doSearch();
+
+ // Final initialization of the form
+ types = getKnowledgeElementTypeService().selectTypesWhere(
+ ProgressState.APPROVED);
+ 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 {
+ // ----------------------------
+ setMenuProperty("open");
+ initializationScreenContext(_menuProperty);
+
+ Map<String, Object> session = getSession();
+ User user = getConnectedUser();
+
+ KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
+
+ // Search matching all criteria
+ sprop.setType(getKnowledgeElementTypeService().selectType(
+ Integer.valueOf(typid)));
+ 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.setAuthor(him);
+ }
+ // Set of the visibility
+ if (visibility.equals("all")) {
+ KnowledgeElement.Properties other = sprop.copy();
+
+ other.setVisibility(Visibility.PUBLIC);
+ sprop.setVisibility(Visibility.PRIVATE);
+ sprop.setActor(user);
+
+ result = getSearchService().selectKnowledgeElementsWhere(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().selectKnowledgeElementsWhere(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 List<KnowledgeElementType> getKnowledgeTypes() {
+ // ------------------------------------------------------
+ return types;
+ }
+
+ public String getReference() {
+ // -----------------------------
+ return refid;
+ }
+
+ public String getState() {
+ // ------------------------
+ return typid;
+ }
+
+ 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.typid = 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() {
+ // ------------------------------------------------------------
+ return getSimulationContextService().selectAllTypes();
+ }
@SuppressWarnings("unchecked")
- protected void saveFilter () {
-// ----------------------------
- Map<String,Object> session = getSession();
- Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.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("type", this.typid);
- 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
-
-// Initialization required by all do functions
- types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
+ protected void loadFilter() {
+ // ----------------------------
+ Map<String, Object> session = getSession();
+ User user = getConnectedUser();
+ Map<String, Object> filter = (Map<String, Object>) session
+ .get("knowledge.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");
+ typid = (String) filter.get("type");
+ 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("knowledge.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("type", this.typid);
+ 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
+
+ // Initialization required by all do functions
+ types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
+ }
+
+ /**
+ * 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 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 knowledgeElementTypeService.
+ *
+ * @return the knowledgeElementTypeService
+ */
+ public KnowledgeElementTypeService getKnowledgeElementTypeService() {
+ return _knowledgeElementTypeService;
+ }
+
+ /**
+ * Set the knowledgeElementTypeService.
+ *
+ * @param knowledgeElementTypeService
+ * the knowledgeElementTypeService to set
+ */
+ public void setKnowledgeElementTypeService(
+ KnowledgeElementTypeService knowledgeElementTypeService) {
+ _knowledgeElementTypeService = knowledgeElementTypeService;
+ }
+
+ /**
+ * 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;
}
}
\ No newline at end of file