From: rkv Date: Tue, 5 Mar 2013 09:38:30 +0000 (+0000) Subject: Search actions have been improved. Searching by dates has been implemented. X-Git-Tag: Root_Delivery2_2013_04_22~124 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=13d2b28fcc2af11351fa43ec09c7d5f09befb77d;p=tools%2Fsiman.git Search actions have been improved. Searching by dates has been implemented. --- diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElementType.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElementType.java index 7209448..09b3d64 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElementType.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElementType.java @@ -1,4 +1,5 @@ package org.splat.dal.bo.som; + /** * * @author Daniel Brunier-Coulin @@ -7,74 +8,88 @@ package org.splat.dal.bo.som; import org.splat.dal.bo.kernel.Persistent; - public class KnowledgeElementType extends Persistent { - - private String name; - private ProgressState state; -// ============================================================================================================================== -// Constructors -// ============================================================================================================================== + private String name; + private ProgressState state; - // Database fetch constructor - protected KnowledgeElementType () { - } -// Initialization constructor - public KnowledgeElementType (String name) { -// -------------------------------------------- - super(); - this.name = name; - this.state = ProgressState.inCHECK; - } + // ============================================================================================================================== + // Constructors + // ============================================================================================================================== -// ============================================================================================================================== -// Public member functions -// ============================================================================================================================== + // Database fetch constructor + protected KnowledgeElementType() { + } - public boolean equals(Object entity) { -// ------------------------------------ - if (entity == null) return false; - if (entity instanceof String) { - return this.name.equals((String)entity); // Names are unique - } else - if (entity instanceof KnowledgeElementType) { - KnowledgeElementType object = (KnowledgeElementType)entity; - long he = object.getIndex(); - long me = this.getIndex(); - if (me*he != 0) return (he == me); - else return this.getName().equals(object.getName()); - } else { - return false; - } - } + // Initialization constructor + public KnowledgeElementType(final String name) { + super(); + this.name = name; + this.state = ProgressState.inCHECK; + } - public String getName () { -// ------------------------ - return name; - } + // ============================================================================================================================== + // Public member functions + // ============================================================================================================================== - public boolean isApproved () { -// ---------------------------- - return (state == ProgressState.APPROVED); - } + @Override + public boolean equals(final Object entity) { + if (entity == null) { + return false; + } + if (entity instanceof String) { + return this.name.equals(entity); // Names are unique + } else if (entity instanceof KnowledgeElementType) { + KnowledgeElementType object = (KnowledgeElementType) entity; + long he = object.getIndex(); + long me = this.getIndex(); + if (me * he != 0) { + return (he == me); + } else { + return this.getName().equals(object.getName()); + } + } else { + return false; + } + } - public boolean isReserved () { -// ---------------------------- - return (state == ProgressState.inWORK); - } - /** + public String getName() { + return name; + } + + /** + * Get i18n type name key. + * + * @return the i18n key + */ + public String getKey() { + return "type.knowledge." + name; + } + + public boolean isApproved() { + return (state == ProgressState.APPROVED); + } + + public boolean isReserved() { + return (state == ProgressState.inWORK); + } + + /** * Get the state. + * * @return the state */ public ProgressState getState() { return state; } + /** * Set the state. - * @param state the state to set + * + * @param state + * the state to set */ - public void setState(ProgressState state) { + public void setState(final ProgressState state) { this.state = state; } } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/service/SearchService.java b/Workspace/Siman-Common/src/org/splat/service/SearchService.java index 95e72d6..28dae50 100644 --- a/Workspace/Siman-Common/src/org/splat/service/SearchService.java +++ b/Workspace/Siman-Common/src/org/splat/service/SearchService.java @@ -15,6 +15,7 @@ import org.splat.dal.bo.som.KnowledgeElement; import org.splat.dal.bo.som.Study; import org.splat.service.dto.ImportedStudyDTO; import org.splat.service.dto.Proxy; +import org.splat.service.dto.StudySearchFilterDTO; /** * Search service interface. @@ -59,8 +60,7 @@ public interface SearchService { * search filter parameters * @return the list of found studies as proxy results */ - List selectStudiesWhere(boolean allCriteria, boolean allContexts, - Study.Properties sprop); + List selectStudiesWhere(final StudySearchFilterDTO filter); /** * Refresh lucene index for a study. diff --git a/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java index beaf1af..f49c14e 100644 --- a/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java @@ -46,11 +46,11 @@ import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.Visibility; -import org.splat.dal.bo.som.Study.Properties; import org.splat.dal.dao.som.StudyDAO; import org.splat.service.dto.ImportedStudyDTO; import org.splat.service.dto.Proxy; import org.splat.service.dto.StudyDTO; +import org.splat.service.dto.StudySearchFilterDTO; import org.splat.service.technical.IndexService; import org.splat.service.technical.IndexServiceImpl; import org.splat.service.technical.RepositoryService; @@ -265,20 +265,20 @@ public class SearchServiceImpl implements SearchService { * * @see org.splat.service.SearchService#selectStudiesWhere(org.splat.dal.bo.som.Study.Properties[]) */ - public List selectStudiesWhere(final boolean allCriteria, - final boolean allContexts, final Study.Properties sprop) { + public List selectStudiesWhere(final StudySearchFilterDTO filter) { List result = new ArrayList(); DetachedCriteria query = DetachedCriteria .forClass(Study.class, "study"); + // Creation of the query - initQuery(query, sprop); + Junction topJunction = initQuery(filter); - String title = sprop.getTitle(); // Title + String title = filter.getWords(); // Title if (title != null) { // Look for given words in study titles Junction critext; - if (allCriteria) { // AND + if (filter.isMatchAllCriteria()) { // AND critext = Restrictions.conjunction(); } else { // OR critext = Restrictions.disjunction(); @@ -288,15 +288,15 @@ public class SearchServiceImpl implements SearchService { for (int j = 0; j < word.length; j++) { critext.add(Restrictions.like("title", "%" + word[j] + "%")); } - query.add(critext); + topJunction.add(critext); } - List context = sprop.getSimulationContexts(); + List context = filter.getSimContexts(); if (context != null && (!context.isEmpty())) { // Get only studies which have given contexts query.createAlias("contex", "ctx", Criteria.INNER_JOIN); Junction critctx; - if (allContexts) { // AND + if (filter.isMatchAllContexts()) { // AND critctx = Restrictions.conjunction(); } else { // OR critctx = Restrictions.disjunction(); @@ -308,9 +308,10 @@ public class SearchServiceImpl implements SearchService { seltext.getType()))); } - query.add(critctx); + topJunction.add(critctx); } + query.add(topJunction); // Group by study query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Creation of the sort criteria @@ -335,44 +336,52 @@ public class SearchServiceImpl implements SearchService { /** * Initialize query with base criteria. * - * @param query - * the query - * @param sprop + * @param filter * the criteria + * @return top junction of the search filter */ - private void initQuery(final DetachedCriteria query, final Properties sprop) { - ProgressState state = sprop.getProgressState(); // State - if (state != null) { - query.add(Restrictions.eq("state", state)); + private Junction initQuery(final StudySearchFilterDTO filter) { + Junction topJunction; + if (filter.isMatchAllCriteria()) { // AND + topJunction = Restrictions.conjunction(); + } else { // OR + topJunction = Restrictions.disjunction(); + } + if (!StudySearchFilterDTO.ANY_STATE.equals(filter.getState())) { + ProgressState state = ProgressState.valueOf(filter.getState()); // State + if (state != null) { + topJunction.add(Restrictions.eq("state", state)); + } } - String refid = sprop.getReference(); // Reference - if (refid != null) { - query.add(Restrictions.eq("sid", refid)); + String refid = filter.getReference(); // Reference + if (refid != null && !refid.isEmpty()) { + topJunction.add(Restrictions.eq("sid", refid)); } - User manager = sprop.getManager(); // Author - if (manager != null) { - query.add(Restrictions.eq("manager", manager)); + + addDatesCriteria(topJunction, filter); + + int authorId = Integer.valueOf(filter.getAuthor()); + if (authorId > 0) { // Author + topJunction.add(Restrictions.eq("manager.rid", authorId)); } - User actor = sprop.getActor(); // Contributor, Reviewer or Approver - if (actor == null) { + long actorId = filter.getConnectedUserId(); // Contributor, Reviewer or Approver + if (actorId > 0) { // User is not logged in - show only public studies - query.add(Restrictions.eq("visibility", Visibility.PUBLIC)); + topJunction.add(Restrictions.eq("visibility", Visibility.PUBLIC)); } else { // User is loggen in - show public studies and studies where he is participating Disjunction orCrit = Restrictions.disjunction(); - query + topJunction .add(orCrit .add( /* If the user is a validation cycle participant */ Restrictions .sqlRestriction( "{alias}.rid in (select vcrel.owner from cycle_rel vcrel inner join cycle vc on vcrel.refer = vc.rid where {alias}.rid = vcrel.owner AND (vc.publisher = ? OR vc.reviewer = ? OR vc.approver = ? OR vc.signatory = ?) group by vcrel.owner)", - new Object[] { - actor.getIndex(), - actor.getIndex(), - actor.getIndex(), - actor.getIndex() }, + new Object[] { actorId, + actorId, actorId, + actorId }, new Type[] { Hibernate.LONG, Hibernate.LONG, @@ -383,14 +392,46 @@ public class SearchServiceImpl implements SearchService { Restrictions .sqlRestriction( "{alias}.rid in (select rel.owner from contributor_rel rel where {alias}.rid = rel.owner AND rel.refer = ?)", - actor.getIndex(), - Hibernate.LONG)).add( + actorId, Hibernate.LONG)) + .add( /* If the user is author */ - Restrictions.eq("study.manager", actor)).add( + Restrictions.eq("study.manager.rid", actorId)).add( /* If the study is public */ Restrictions.eq("study.visibility", Visibility.PUBLIC))); } + return topJunction; + } + + /** + * Add search criteria by dates to the junction filter condition. + * + * @param topJunction + * the junction filter condition + * @param filter + * search criteria + */ + private void addDatesCriteria(final Junction topJunction, + final StudySearchFilterDTO filter) { + // Filter by creation date + if (filter.getCreatedAfter() != null) { + topJunction.add(Restrictions + .gt("credate", filter.getCreatedAfter())); + } + if (filter.getCreatedBefore() != null) { + topJunction.add(Restrictions.lt("credate", filter + .getCreatedBefore())); + } + // Filter by modification date + if (filter.getUpdatedAfter() != null) { + topJunction.add(Restrictions + .gt("lasdate", filter.getUpdatedAfter())); + } + if (filter.getUpdatedBefore() != null) { + topJunction.add(Restrictions.lt("lasdate", filter + .getUpdatedBefore())); + } + } /** diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeSearchFilterDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeSearchFilterDTO.java new file mode 100644 index 0000000..2ce6621 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/service/dto/KnowledgeSearchFilterDTO.java @@ -0,0 +1,44 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 05.03.2013 + * @author $Author$ + * @version $Revision$ + * @copyright OPEN CASCADE 2012 + *****************************************************************************/ + +package org.splat.service.dto; + +/** + * Knowledge search criteria. + * + * @author Roman Kozlov (RKV) + */ +public class KnowledgeSearchFilterDTO extends SearchFilterDTO { + + /** + * Knowledge type index when among all. + */ + private String _ktype = "0"; + + /** + * Get id of knowledge type to search. + * + * @return knowledge type id to search + */ + public String getKtype() { + return _ktype; + } + + /** + * Set id of knowledge type to search. + * + * @param value + * knowledge type id to search + */ + public void setKtype(final String value) { + this._ktype = value; + } + +} diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/SearchFilterDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/SearchFilterDTO.java new file mode 100644 index 0000000..1fd296e --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/service/dto/SearchFilterDTO.java @@ -0,0 +1,262 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 04.03.2013 + * @author $Author$ + * @version $Revision$ + * @copyright OPEN CASCADE 2012 + *****************************************************************************/ + +package org.splat.service.dto; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.splat.dal.bo.som.SimulationContext; + +/** + * Base search criteria. + * + * @author Roman Kozlov (RKV) + */ +public class SearchFilterDTO { + + /** + * "all": match all criteria. + */ + public final static String MATCH_ALL = "all"; + /** + * "any": match any criteria. + */ + public final static String MATCH_ANY = "any"; + /** + * Study author id to search. + */ + protected String _author = "0"; + /** + * Current contexts search criteria. + */ + protected transient List _simContexts = new ArrayList(); + /** + * Simulation context match: "all" or "any". + */ + private String _contextMatch = MATCH_ALL; + /** + * Criteria match: "all" or "any". + */ + private String _criteriaMatch = MATCH_ALL; + /** + * Search studies created after this date. + */ + private Date _createdAfter; + /** + * Search studies created before this date. + */ + private Date _createdBefore; + /** + * Full text search words. + */ + private String _words = ""; + /** + * Study reference. + */ + private String _reference = ""; + /** + * Currently connected user id. + */ + private long _connectedUserId = 0; + + /** + * Get author id of objects to find. + * + * @return the author id criteria + */ + public String getAuthor() { + return _author; + } + + /** + * Get context criteria operation (all or any). + * + * @return the simulation context criteria operation value + */ + public String getContextMatch() { + return _contextMatch; + } + + /** + * Get the createdAfter. + * + * @return the createdAfter + */ + public Date getCreatedAfter() { + return _createdAfter; + } + + /** + * Get the createdBefore. + * + * @return the createdBefore + */ + public Date getCreatedBefore() { + return _createdBefore; + } + + /** + * Get main criteria operation (all or any). + * + * @return the main criteria operation value + */ + public String getCriteriaMatch() { + return _criteriaMatch; + } + + /** + * Get full text search criterion value. + * + * @return the full text search criterion value + */ + public String getWords() { + return _words; + } + + // ============================================================================================================================== + // Setters + // ============================================================================================================================== + + /** + * Set author id to search. + * + * @param index + * persistent user id + */ + public void setAuthor(final String index) { + this._author = index; + } + + /** + * Set context criteria operation (all or any). + * + * @param value + * "all" or "any" + */ + public void setContextMatch(final String value) { + this._contextMatch = value; + } + + /** + * Set the createdAfter. + * + * @param createdAfter + * the createdAfter to set + */ + public void setCreatedAfter(final Date createdAfter) { + _createdAfter = createdAfter; + } + + /** + * Set the createdBefore. + * + * @param createdBefore + * the createdBefore to set + */ + public void setCreatedBefore(final Date createdBefore) { + _createdBefore = createdBefore; + } + + /** + * Set main criteria operation (all or any). + * + * @param value + * "all" or "any" + */ + public void setCriteriaMatch(final String value) { + this._criteriaMatch = value; + } + + /** + * Set full text search criterion value. + * + * @param value + * the full text search criterion value + */ + public void setWords(final String value) { + this._words = value; + } + + /** + * Get the context. + * + * @return the context + */ + public List getSimContexts() { + return _simContexts; + } + + /** + * Check if it is necessary to satisfy all main criteria. + * + * @return true if it is necessary to satisfy all main criteria + */ + public boolean isMatchAllCriteria() { + return MATCH_ALL.equals(getCriteriaMatch()); + } + + /** + * Check if it is necessary to satisfy all simulation contexts criteria. + * + * @return true if it is necessary to satisfy all simulation contexts criteria + */ + public boolean isMatchAllContexts() { + return MATCH_ALL.equals(getContextMatch()); + } + + // ============================================================================================================================== + // Getters + // ============================================================================================================================== + + /** + * Get study reference criteria. + * + * @return study reference to search + */ + public String getReference() { + return _reference; + } + + /** + * Set study reference criteria. + * + * @param value + * the study reference to search + */ + public void setReference(final String value) { + this._reference = value; + } + + /** + * Set the simContexts. + * @param simContexts the simContexts to set + */ + public void setSimContexts(final List simContexts) { + _simContexts = simContexts; + } + + /** + * Get the connectedUserId. + * @return the connectedUserId + */ + public long getConnectedUserId() { + return _connectedUserId; + } + + /** + * Set the connectedUserId. + * @param connectedUserId the connectedUserId to set + */ + public void setConnectedUserId(final long connectedUserId) { + _connectedUserId = connectedUserId; + } +} diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/StudySearchFilterDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/StudySearchFilterDTO.java new file mode 100644 index 0000000..93d7ef4 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/service/dto/StudySearchFilterDTO.java @@ -0,0 +1,100 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 05.03.2013 + * @author $Author$ + * @version $Revision$ + * @copyright OPEN CASCADE 2012 + *****************************************************************************/ + +package org.splat.service.dto; + +import java.util.Date; + +/** + * Study search criteria. + * + * @author Roman Kozlov (RKV) + */ +public class StudySearchFilterDTO extends SearchFilterDTO { + + /** + * "ANY": match any status. + */ + public final static String ANY_STATE = "ANY"; + /** + * "In-Work", "In-Draft", "In-Check"... + */ + private String _state = ANY_STATE; + /** + * Search studies updated after this date. + */ + private Date _updatedAfter; + /** + * Search studies updated before this date. + */ + private Date _updatedBefore; + + // ============================================================================================================================== + // Getters + // ============================================================================================================================== + + /** + * Get progress state criteria. + * + * @return study progress state to search + */ + public String getState() { + return _state; + } + + /** + * Set progress state criteria. + * + * @param value + * the progress state to search + */ + public void setState(final String value) { + this._state = value; + } + + /** + * Get the updatedAfter. + * + * @return the updatedAfter + */ + public Date getUpdatedAfter() { + return _updatedAfter; + } + + /** + * Get the updatedBefore. + * + * @return the updatedBefore + */ + public Date getUpdatedBefore() { + return _updatedBefore; + } + + /** + * Set the updatedAfter. + * + * @param updatedAfter + * the updatedAfter to set + */ + public void setUpdatedAfter(final Date updatedAfter) { + _updatedAfter = updatedAfter; + } + + /** + * Set the updatedBefore. + * + * @param updatedBefore + * the updatedBefore to set + */ + public void setUpdatedBefore(final Date updatedBefore) { + _updatedBefore = updatedBefore; + } + +} diff --git a/Workspace/Siman/WebContent/study/searchKnowledge.jsp b/Workspace/Siman/WebContent/study/searchKnowledge.jsp index 22eec3f..d4ec04a 100644 --- a/Workspace/Siman/WebContent/study/searchKnowledge.jsp +++ b/Workspace/Siman/WebContent/study/searchKnowledge.jsp @@ -1,12 +1,12 @@ <%@page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1" -%> + pageEncoding="ISO-8859-1"%> <%@taglib prefix="s" uri="/struts-tags"%> - + @@ -19,7 +18,7 @@ $(document).ready(function () {
@@ -31,10 +30,10 @@ $(document).ready(function () { class="text">     - |       - @@ -49,18 +48,18 @@ $(document).ready(function () { - - - + - + - + - +
  + cssStyle="width: %{getText('size.search.select')}" onchange="changeFilter()" />
    " />    " />
   " />    " />
- + - +
" onKeydown="changeFilter()" - title="" />
" - onKeydown="changeFilter()" - title="" />
- + @@ -182,7 +181,7 @@ $(document).ready(function () {
diff --git a/Workspace/Siman/src/org/splat/conversion/DateConverter.java b/Workspace/Siman/src/org/splat/conversion/DateConverter.java new file mode 100644 index 0000000..7b4f00a --- /dev/null +++ b/Workspace/Siman/src/org/splat/conversion/DateConverter.java @@ -0,0 +1,94 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 01.03.2013 + * @author Author: Roman Kozlov + * @version Revision: + *****************************************************************************/ + +package org.splat.conversion; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.apache.struts2.util.StrutsTypeConverter; +import org.splat.i18n.I18nUtils; + +import com.opensymphony.xwork2.ActionContext; + +/** + * Date conversion methods for Struts 2.
+ * To enable the date conversion for all action classes put into the classpath the file xwork-conversion.properties + * containing the following line:
+ * java.util.Date=org.splat.conversion.DateConverter
+ *
+ * To enable the date conversion for the specific Struts 2 action class, place the file named + * {ActionClassName}-conversion.properties to the package of the action class.
+ * + * For example:
+ * class: ....CustomAction
+ * property file path: classes/.../CustomAction-conversion.properties
+ * This property file should contain a line for each form property.
+ *
+ * For example:
+ * createdAfter=org.splat.conversion.DateConverter
+ * filter.createdAfter=org.splat.conversion.DateConverter
+ * + * @author Roman Kozlov (RKV) + */ +public class DateConverter extends StrutsTypeConverter { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public Object convertFromString(final Map context, final String[] values, + final Class toClass) { // NOPMD: extends StrutsTypeConverter + Object result = null; + String value = null; + if (null != values && values.length > 0) { + value = values[0]; + } + if (StringUtils.isNotEmpty(value)) { + try { + result = DateUtils.parseDateStrictly(values[0], I18nUtils + .getMessage(ActionContext.getContext().getLocale(), + "date.format")); + if (result == null) { + // date can not be null so value is not in a good format + throw new ParseException("Bad format", 0); + } + } catch (ParseException e) { + throw new IllegalArgumentException( + "Cannot parse: " + values[0], e); + } + } + return result; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public String convertToString(final Map context, final Object o) { // NOPMD: extends StrutsTypeConverter + String result; + if (o instanceof Date) { + result = (new SimpleDateFormat(I18nUtils.getMessage(ActionContext + .getContext().getLocale(), "date.format"), ActionContext + .getContext().getLocale())).format((Date) o); + } else if (null == o) { + result = StringUtils.EMPTY; + } else { + result = o.toString(); + } + return result; + } + +} diff --git a/Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java b/Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java index b230240..a2c12dc 100644 --- a/Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java +++ b/Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java @@ -16,15 +16,18 @@ import org.splat.kernel.Name; import org.splat.service.SimulationContextService; import org.splat.service.UserService; import org.splat.service.dto.Proxy; +import org.splat.service.dto.SearchFilterDTO; import org.splat.service.technical.ProjectSettingsService; import org.splat.som.ApplicationRights; +import org.splat.wapp.Constants; /** * Base search action class used for searching studies and knowledge. * * @author Roman Kozlov (RKV) */ -public abstract class AbstractSearchBaseAction extends Action { +public abstract class AbstractSearchBaseAction + extends Action { /** * Serial version ID. @@ -47,9 +50,9 @@ public abstract class AbstractSearchBaseAction extends Action { */ protected transient String _cindex = ""; /** - * Study author to search. + * Search criteria. */ - protected String _author = null; + private FilterClass _filter; /** * List of users who can create studies. */ @@ -66,10 +69,6 @@ public abstract class AbstractSearchBaseAction extends Action { * Addable context types. */ protected transient List _critext; - /** - * Current contexts search criteria. - */ - protected transient List _context; /** * List of found objects. */ @@ -83,18 +82,6 @@ public abstract class AbstractSearchBaseAction extends Action { * Injected user service. */ private UserService _userService; - /** - * Simulation context match: "all" or "any". - */ - private String _contextMatch = null; - /** - * Criteria match: "all" or "any". - */ - private String _criteriaMatch = null; - /** - * Full text search words. - */ - private String _words = null; /** * Search action modes enumeration. @@ -158,7 +145,7 @@ public abstract class AbstractSearchBaseAction extends Action { * * @return "selectype" */ - @SuppressWarnings("unchecked") + @SuppressWarnings(Constants.UNCHECKED) protected String doSelectContextType() { SimulationContext.Properties sprop = new SimulationContext.Properties(); @@ -185,7 +172,7 @@ public abstract class AbstractSearchBaseAction extends Action { SimulationContext selected = getSimulationContextService() .selectSimulationContext(Integer.valueOf(_cvalue)); - _context.add(selected); + getFilter().getSimContexts().add(selected); setContextTypeOptions(getInvolvedContexts()); // Sets critext getSession().remove(RESULT_KEY); // The current result is obsolete return "refresh"; @@ -198,8 +185,8 @@ public abstract class AbstractSearchBaseAction extends Action { */ protected String doRemoveContext() { long index = Long.valueOf(_cindex); - for (Iterator selected = _context.iterator(); selected - .hasNext();) { + for (Iterator selected = getFilter() + .getSimContexts().iterator(); selected.hasNext();) { if (selected.next().getIndex() == index) { selected.remove(); break; @@ -211,10 +198,11 @@ public abstract class AbstractSearchBaseAction extends Action { } /** + * Cancel simulation context selection. * - * @return + * @return "refresh" */ - @SuppressWarnings("unchecked") + @SuppressWarnings(Constants.UNCHECKED) protected String doCancel() { _result = (List) getSession().get(RESULT_KEY); // Current result search setContextTypeOptions(getInvolvedContexts()); // Sets critext @@ -260,10 +248,6 @@ public abstract class AbstractSearchBaseAction extends Action { return result; } - public String getAuthor() { - return _author; - } - public List getCandidates() { return _candidates; } @@ -280,10 +264,6 @@ public abstract class AbstractSearchBaseAction extends Action { return _newtype; } - public List getSimulationContexts() { - return _context; - } - /** * Get list of found objects. * @@ -297,16 +277,6 @@ public abstract class AbstractSearchBaseAction extends Action { // Setters // ============================================================================================================================== - /** - * Set author id to search. - * - * @param index - * persistent user id - */ - public void setAuthor(final String index) { - this._author = index; - } - /** * Set applied simulation context type id to search. * @@ -367,8 +337,8 @@ public abstract class AbstractSearchBaseAction extends Action { */ protected void setContextTypeOptions( final List critext) { - for (Iterator i = _context.iterator(); i.hasNext();) { - critext.remove(i.next().getType()); // Already used context type + for (SimulationContext ctx : getFilter().getSimContexts()) { + critext.remove(ctx.getType()); // Already used context type } // Ordering by alphabetical order of localized context types SimulationContextType[] types = critext @@ -394,22 +364,81 @@ public abstract class AbstractSearchBaseAction extends Action { this._critext = Arrays.asList(types); } + /** + * Load the search filter. The filter is taken from the session by its name. + * + * @see #getFilterName() + * @return the loaded filter + */ + @SuppressWarnings(Constants.UNCHECKED) + protected Map loadFilter() { + Map filter = (Map) getSession().get( + getFilterName()); // A default filter is supposed being set at start + + setFilter((FilterClass) filter.get("criteria")); + return filter; + } + + /** + * Save search criteria in the session as a map with the defined name. + * + * @see #getFilterName() + * @return the saved filter + */ + @SuppressWarnings(Constants.UNCHECKED) + protected Map saveFilter() { + Map filter = (Map) getSession().get( + getFilterName()); // A default filter is supposed being set at start + + FilterClass savedCriteria = (FilterClass) filter.get("criteria"); + FilterClass newCriteria = getFilter(); + if (savedCriteria != null) { + // Only contexts are not part of the form so keep them between requests + newCriteria.setSimContexts(savedCriteria.getSimContexts()); + } + + filter.put("criteria", getFilter()); + return filter; + } + // ============================================================================================================================== // Abstract services // ============================================================================================================================== + /** + * Search objects according to the given criteria. + * + * @return string result key + * @throws InvalidPropertyException + * if some criteria values are incorrect + */ protected abstract String doSearch() throws InvalidPropertyException; + /** + * List of context types available for filtering. + * + * @return list of simulation context types + */ protected abstract List getInvolvedContexts(); - protected abstract void loadFilter(); + /** + * Get the name of the search criteria filter saved as a map of objects in the session. + * + * @return the search filter name in the session + */ + protected abstract String getFilterName(); - protected abstract void saveFilter(); + /** + * Get search filter implementation. + * + * @return the search filter + */ + protected abstract FilterClass getNewFilter(); // ============================================================================================================================== // Getters and Setters // ============================================================================================================================== - + /** * Get match options. * @@ -461,27 +490,29 @@ public abstract class AbstractSearchBaseAction extends Action { _userService = userService; } - public String getContextMatch() { - return _contextMatch; - } - - public String getCriteriaMatch() { - return _criteriaMatch; - } - - public void setContextMatch(final String value) { - this._contextMatch = value; - } - - public void setCriteriaMatch(final String value) { - this._criteriaMatch = value; - } - - public String getWords() { - return _words; + /** + * Get the filter. + * + * @return the filter + */ + public FilterClass getFilter() { + if (_filter == null) { + _filter = getNewFilter(); + } + return _filter; } - public void setWords(final String value) { - this._words = value; + /** + * Set the filter. + * + * @param filter + * the filter to set + */ + public void setFilter(final FilterClass filter) { + if (filter == null) { + _filter = getNewFilter(); + } else { + _filter = filter; + } } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java b/Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java index 5224806..031766f 100644 --- a/Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java +++ b/Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java @@ -1,5 +1,6 @@ package org.splat.simer; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -7,36 +8,29 @@ import org.splat.dal.bo.kernel.User; 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.dto.KnowledgeSearchFilterDTO; import org.splat.wapp.Constants; /** * Action for searching a knowledge in the database. */ -public class SearchKnowledgeAction extends AbstractSearchBaseAction { +public class SearchKnowledgeAction extends + AbstractSearchBaseAction { /** * Serial version ID. */ private static final long serialVersionUID = -3104321907432838476L; - /** - * Knowledge type index when among all. - */ - private String _state = null; - /** - * Knowledge reference when among ref. - */ - private String _reference = null; /** * Available knowledge types filter (initialized below). */ - private transient List _knowledgeTypes; + private transient Map _knowledgeTypes; /** * Injected search service. */ @@ -66,8 +60,9 @@ public class SearchKnowledgeAction extends AbstractSearchBaseAction { doSearch(); // Final initialization of the form - _knowledgeTypes = getKnowledgeElementTypeService() - .selectTypesWhere(ProgressState.APPROVED); + _knowledgeTypes = buildKnowledgeTypesOptions(); + getKnowledgeElementTypeService().selectTypesWhere( + ProgressState.APPROVED); setCandidates(); setContextTypeOptions(getInvolvedContexts()); } catch (Exception error) { @@ -78,40 +73,58 @@ public class SearchKnowledgeAction extends AbstractSearchBaseAction { return res; } + /** + * Build the map of translated knowledge types available for selection. + * + * @return the map of translated knowledge types + */ + private Map buildKnowledgeTypesOptions() { + Map options = new LinkedHashMap(); + List types = getKnowledgeElementTypeService() + .selectTypesWhere(ProgressState.APPROVED); + for (KnowledgeElementType ktype : types) { + options.put(ktype.getIndex(), getText(ktype.getKey())); + } + return options; + } + + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractSearchBaseAction#doSearch() + */ @Override protected String doSearch() throws InvalidPropertyException { initializationScreenContext(Constants.OPEN); - Map session = getSession(); KnowledgeElement.Properties sprop = new KnowledgeElement.Properties(); // Search matching all criteria sprop.setType(getKnowledgeElementTypeService().selectType( - Integer.valueOf(_state))); - if (getWords().length() > 0) { - sprop.setTitle(getWords()); + Integer.valueOf(getFilter().getKtype()))); + if (getFilter().getWords().length() > 0) { + sprop.setTitle(getFilter().getWords()); } - if (_reference.length() > 0) { - sprop.setReference(_reference); + if (getFilter().getReference().length() > 0) { + sprop.setReference(getFilter().getReference()); } - if (_context.size() > 0) { - sprop.setSimulationContexts(_context); + if (getFilter().getSimContexts().size() > 0) { + sprop.setSimulationContexts(getFilter().getSimContexts()); } - int index = Integer.valueOf(_author); + int index = Integer.valueOf(getFilter().getAuthor()); if (index > 0) { User him = getUserService().selectUser(index); sprop.setAuthor(him); } // Set of the visibility - KnowledgeElement.Properties other = sprop.copy(); + KnowledgeElement.Properties other = sprop.copy(); - other.setVisibility(Visibility.PUBLIC); - sprop.setVisibility(Visibility.PRIVATE); - sprop.setActor(getConnectedUser()); + other.setVisibility(Visibility.PUBLIC); + sprop.setVisibility(Visibility.PRIVATE); + sprop.setActor(getConnectedUser()); - _result = getSearchService().selectKnowledgeElementsWhere(sprop, - other); - session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search + _result = getSearchService().selectKnowledgeElementsWhere(sprop, other); + getSession().put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search return "refresh"; } @@ -119,66 +132,32 @@ public class SearchKnowledgeAction extends AbstractSearchBaseAction { // Getters // ============================================================================================================================== - public List getKnowledgeTypes() { + public Map getKnowledgeTypes() { return _knowledgeTypes; } - public String getReference() { - return _reference; - } - - public String getState() { - return _state; - } - - public void setReference(final String value) { - this._reference = value; - } - - public void setState(final String value) { - this._state = value; - } - + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractSearchBaseAction#getInvolvedContexts() + */ @Override protected List getInvolvedContexts() { return getSimulationContextService().selectAllTypes(); } + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractSearchBaseAction#saveFilter() + */ @Override - @SuppressWarnings("unchecked") - protected void loadFilter() { - Map session = getSession(); - Map filter = (Map) session - .get("knowledge.filter"); // A default filter is supposed being set at start - - setCriteriaMatch ((String) filter.get("matchamong")); - setContextMatch ((String) filter.get("matcontext")); - _state = (String) filter.get("type"); - _author = (String) filter.get("author"); - _reference = (String) filter.get("reference"); - setWords ((String) filter.get("title")); - _context = (List) filter.get("context"); - } - - @Override - @SuppressWarnings("unchecked") - protected void saveFilter() { - Map session = getSession(); - Map filter = (Map) session - .get("knowledge.filter"); // A default filter is supposed being set at start - - filter.put("matchamong", getCriteriaMatch()); - filter.put("matcontext", getContextMatch()); - filter.put("type", this._state); - filter.put("author", this._author); - filter.put("reference", ""); - filter.put("title", getWords()); - - _context = (List) filter.get("context"); // Only criteria not part of the form + protected Map saveFilter() { + Map filter = super.saveFilter(); // Initialization required by all do functions - _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere( - ProgressState.APPROVED); + _knowledgeTypes = buildKnowledgeTypesOptions(); + return filter; } /** @@ -219,4 +198,24 @@ public class SearchKnowledgeAction extends AbstractSearchBaseAction { final KnowledgeElementTypeService knowledgeElementTypeService) { _knowledgeElementTypeService = knowledgeElementTypeService; } + + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractSearchBaseAction#getFilterName() + */ + @Override + protected String getFilterName() { + return "knowledge.filter"; + } + + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractSearchBaseAction#getNewFilter() + */ + @Override + protected KnowledgeSearchFilterDTO getNewFilter() { + return new KnowledgeSearchFilterDTO(); + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java b/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java index 070c1de..61cbe0b 100644 --- a/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java +++ b/Workspace/Siman/src/org/splat/simer/SearchStudyAction.java @@ -4,34 +4,26 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.splat.dal.bo.kernel.User; 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.Study; 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.wapp.Constants; /** * Search studies form action. */ -public class SearchStudyAction extends AbstractSearchBaseAction { +public class SearchStudyAction extends + AbstractSearchBaseAction { /** * Serial version ID. */ private static final long serialVersionUID = -1910481357051393077L; - /** - * "In-Work", "In-Draft", "In-Check"... - */ - private String _state = null; - /** - * Study reference. - */ - private String _reference = null; /** * Injected project settings service. */ @@ -41,10 +33,6 @@ public class SearchStudyAction extends AbstractSearchBaseAction { */ private SearchService _searchService; - enum UserAction { - refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext - } - // ============================================================================================================================== // Action methods // ============================================================================================================================== @@ -84,33 +72,11 @@ public class SearchStudyAction extends AbstractSearchBaseAction { */ @Override protected String doSearch() throws InvalidPropertyException { - Map session = getSession(); - Study.Properties sprop = new Study.Properties(); - - // Search matching all criteria - if (!this._state.equals("ANY")) { - sprop.setState(ProgressState.valueOf(this._state)); - } - if (getWords().length() > 0) { - sprop.setTitle(getWords()); - } - 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.setManager(him); + if (getConnectedUser() != null) { + getFilter().setConnectedUserId(getConnectedUser().getIndex()); } - sprop.setActor(getConnectedUser()); - - _result = getSearchService().selectStudiesWhere( - "all".equals(getCriteriaMatch()), - "all".equals(getContextMatch()), sprop); - session.put(RESULT_KEY, _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"; } @@ -118,22 +84,11 @@ public class SearchStudyAction extends AbstractSearchBaseAction { // Getters // ============================================================================================================================== - public String getReference() { - return _reference; - } - - public String getState() { - return _state; - } - - public void setReference(final String value) { - this._reference = value; - } - - public void setState(final String value) { - this._state = value; - } - + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractSearchBaseAction#getInvolvedContexts() + */ @Override protected List getInvolvedContexts() { List steps = getProjectSettings() @@ -144,40 +99,6 @@ public class SearchStudyAction extends AbstractSearchBaseAction { return getSimulationContextService().selectTypesOf(number); } - @Override - @SuppressWarnings("unchecked") - protected void loadFilter() { - Map session = getSession(); - Map filter = (Map) session - .get("study.filter"); // A default filter is supposed being set at start - - setCriteriaMatch((String) filter.get("matchamong")); - setContextMatch((String) filter.get("matcontext")); - _state = (String) filter.get("state"); - _author = (String) filter.get("author"); - _reference = (String) filter.get("reference"); - setWords((String) filter.get("title")); - _context = (List) filter.get("context"); - } - - @Override - @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("matchamong", getCriteriaMatch()); - filter.put("matcontext", getContextMatch()); - filter.put("state", this._state); - filter.put("author", this._author); - filter.put("reference", this._reference); - filter.put("title", getWords()); - - _context = (List) filter.get("context"); // Only criteria not part of the form - - } - /** * Get match options. * @@ -247,4 +168,24 @@ public class SearchStudyAction extends AbstractSearchBaseAction { final ProjectSettingsService projectSettingsService) { _projectSettings = projectSettingsService; } + + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractSearchBaseAction#getFilterName() + */ + @Override + protected String getFilterName() { + return "study.filter"; + } + + /** + * {@inheritDoc} + * + * @see org.splat.simer.AbstractSearchBaseAction#getNewFilter() + */ + @Override + protected StudySearchFilterDTO getNewFilter() { + return new StudySearchFilterDTO(); + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/wapp/Constants.java b/Workspace/Siman/src/org/splat/wapp/Constants.java index e7f4e41..1011ac9 100644 --- a/Workspace/Siman/src/org/splat/wapp/Constants.java +++ b/Workspace/Siman/src/org/splat/wapp/Constants.java @@ -78,4 +78,8 @@ public class Constants { * Checked out element icon. */ public static final String IMG_CHECKEDOUT = "icon.checkedout.png"; + /** + * "unchecked" literal constant for annotations. + */ + public static final String UNCHECKED = "unchecked"; } diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 1481b2a..871896c 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -25,7 +25,8 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> class="org.springframework.context.support.ResourceBundleMessageSource"> - conf/log-messages + conf/log-messages + som diff --git a/Workspace/Siman/src/xwork-conversion.properties b/Workspace/Siman/src/xwork-conversion.properties new file mode 100644 index 0000000..621902d --- /dev/null +++ b/Workspace/Siman/src/xwork-conversion.properties @@ -0,0 +1 @@ +java.util.Date=org.splat.conversion.DateConverter \ No newline at end of file
')">