import java.util.List;
import java.util.Map;
-import org.splat.kernel.InvalidPropertyException;
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;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.service.KnowledgeElementTypeService;
+import org.splat.service.SearchService;
+import org.splat.service.SimulationContextService;
+import org.splat.service.UserService;
/**
* Action for searching a knowledge in the database.
*/
-public class SearchKnowledgeAction extends SearchBaseAction {
+public class SearchKnowledgeAction extends AbstractSearchBaseAction {
/**
* 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", "Public", "All".
+ */
+ private String _visibility = null;
+ /**
+ * Knowledge type index when among all.
+ */
+ private String _state = null;
+ /**
+ * Criteria match: "all" or "any".
+ */
+ private String _criteriaMatch = null;
+ /**
+ * Simulation context match: "all" or "any".
+ */
+ private String _contextMatch = null;
+ /**
+ * Knowledge reference when among ref.
+ */
+ private String _reference = null;
+ /**
+ * Full text search words.
+ */
+ private String _words = null;
+ /**
+ * Available knowledge types filter (initialized below).
+ */
+ private transient List<KnowledgeElementType> _knowledgeTypes;
+ /**
+ * Injected search service.
+ */
private SearchService _searchService;
/**
* Injected simulation context service.
setLeftMenuProperty("open");
initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
+ String res = SUCCESS;
try {
loadFilter();
doSearch();
// Final initialization of the form
- types = getKnowledgeElementTypeService().selectTypesWhere(
+ _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(
ProgressState.APPROVED);
setCandidates();
setContextTypeOptions(getInvolvedContexts());
-
- return SUCCESS;
} catch (Exception error) {
// No need to roll back the transaction as it is read only
LOG.error("Reason: ", error);
- return ERROR;
+ res = ERROR;
}
+ return res;
}
+ @Override
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);
+ Integer.valueOf(_state)));
+ if (_words.length() > 0) {
+ sprop.setTitle(_words);
+ }
+ if (_reference.length() > 0) {
+ sprop.setReference(_reference);
+ }
+ 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")) {
+ if ("all".equals(_visibility)) {
KnowledgeElement.Properties other = sprop.copy();
other.setVisibility(Visibility.PUBLIC);
sprop.setVisibility(Visibility.PRIVATE);
- sprop.setActor(user);
+ sprop.setActor(getConnectedUser());
- result = getSearchService().selectKnowledgeElementsWhere(sprop,
+ _result = getSearchService().selectKnowledgeElementsWhere(sprop,
other);
} else {
- Visibility reparea = null;
- if (visibility.equals("onlypublic"))
+ Visibility reparea;
+ if ("onlypublic".equals(_visibility)) {
reparea = Visibility.PUBLIC;
- else
- reparea = Visibility.valueOf(visibility);
+ } else {
+ reparea = Visibility.valueOf(_visibility);
+ }
sprop.setVisibility(reparea);
- if (reparea == Visibility.PRIVATE)
- sprop.setActor(user);
+ if (reparea == Visibility.PRIVATE) {
+ sprop.setActor(getConnectedUser());
+ }
- result = getSearchService().selectKnowledgeElementsWhere(sprop);
+ _result = getSearchService().selectKnowledgeElementsWhere(sprop);
}
- session.put("search.result", result); // For redisplaying the page without re-executing the search
+ session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
return "refresh";
}
public String getContextMatch() {
// --------------------------------
- return matcontext;
+ return _contextMatch;
}
public String getCriteriaMatch() {
// ---------------------------------
- return matchamong;
+ return _criteriaMatch;
}
public List<KnowledgeElementType> getKnowledgeTypes() {
// ------------------------------------------------------
- return types;
+ return _knowledgeTypes;
}
public String getReference() {
// -----------------------------
- return refid;
+ return _reference;
}
public String getState() {
// ------------------------
- return typid;
+ return _state;
}
public String getVisibility() {
// ------------------------------
- return visibility;
+ return _visibility;
}
public String getWords() {
// -------------------------
- return words;
+ return _words;
}
// ==============================================================================================================================
// Setters
// ==============================================================================================================================
- public void setContextMatch(String value) {
+ public void setContextMatch(final String value) {
// ------------------------------------------
- this.matcontext = value;
+ this._contextMatch = value;
}
- public void setCriteriaMatch(String value) {
+ public void setCriteriaMatch(final String value) {
// -------------------------------------------
- this.matchamong = value;
+ this._criteriaMatch = value;
}
- public void setReference(String value) {
+ public void setReference(final String value) {
// ---------------------------------------
- this.refid = value;
+ this._reference = value;
}
- public void setState(String value) {
+ public void setState(final String value) {
// ----------------------------------
- this.typid = value;
+ this._state = value;
}
- public void setVisibility(String value) {
+ public void setVisibility(final String value) {
// ----------------------------------------
- this.visibility = value;
+ this._visibility = value;
}
- public void setWords(String value) {
+ public void setWords(final String value) {
// -----------------------------------
- this.words = value;
+ this._words = value;
}
// ==============================================================================================================================
// Implementation of abstract services
// ==============================================================================================================================
+ @Override
protected List<SimulationContextType> getInvolvedContexts() {
// ------------------------------------------------------------
return getSimulationContextService().selectAllTypes();
}
+ @Override
@SuppressWarnings("unchecked")
protected void loadFilter() {
// ----------------------------
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");
+ _visibility = (String) filter.get("visibility");
+ _criteriaMatch = (String) filter.get("matchamong");
+ _contextMatch = (String) filter.get("matcontext");
+ _state = (String) filter.get("type");
+ _author = (String) filter.get("author");
+ _reference = (String) filter.get("reference");
+ _words = (String) filter.get("title");
+ _context = (List<SimulationContext>) filter.get("context");
if (user == null) {
- visibility = "onlypublic";
+ _visibility = "onlypublic";
}
}
+ @Override
@SuppressWarnings("unchecked")
protected void saveFilter() {
// ----------------------------
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("visibility", this._visibility);
+ filter.put("matchamong", this._criteriaMatch);
+ filter.put("matcontext", this._contextMatch);
+ filter.put("type", this._state);
+ filter.put("author", this._author);
filter.put("reference", "");
- filter.put("title", this.words);
+ filter.put("title", this._words);
- context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
+ _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
// Initialization required by all do functions
- types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
+ _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
}
/**
* @param searchService
* the searchService to set
*/
- public void setSearchService(SearchService searchService) {
+ public void setSearchService(final SearchService searchService) {
_searchService = searchService;
}
*
* @return the simulationContextService
*/
+ @Override
public SimulationContextService getSimulationContextService() {
return _simulationContextService;
}
* @param simulationContextService
* the simulationContextService to set
*/
+ @Override
public void setSimulationContextService(
- SimulationContextService simulationContextService) {
+ final SimulationContextService simulationContextService) {
_simulationContextService = simulationContextService;
}
* the knowledgeElementTypeService to set
*/
public void setKnowledgeElementTypeService(
- KnowledgeElementTypeService knowledgeElementTypeService) {
+ final KnowledgeElementTypeService knowledgeElementTypeService) {
_knowledgeElementTypeService = knowledgeElementTypeService;
}
* Get the userService.
* @return the userService
*/
+ @Override
public UserService getUserService() {
return _userService;
}
* Set the userService.
* @param userService the userService to set
*/
- public void setUserService(UserService userService) {
+ @Override
+ public void setUserService(final UserService userService) {
_userService = userService;
}
* Set the menuProperty.
* @param menuProperty the menuProperty to set
*/
- public void setMenuProperty(String menuProperty) {
+ public void setMenuProperty(final String menuProperty) {
this._menuProperty = menuProperty;
}