// Construction of the result list
for (KnowledgeElement kelm : found) {
- result.add(new StudyDTO(kelm.getIndex(), kelm.getReference(), kelm
+ StudyDTO studyDTO = new StudyDTO(kelm.getIndex(), kelm.getReference(), kelm
.getProgressState(), kelm.getTitle(), kelm.getAuthor()
- .getDisplayName()));
+ .getDisplayName());
+ studyDTO.setDate(kelm.getDate());
+ result.add(studyDTO);
}
return result;
}
// Construction of the result list
for (Study std : found) {
- result.add(new StudyDTO(std.getIndex(), std.getReference(), std
+ StudyDTO studyDTO = new StudyDTO(std.getIndex(), std.getReference(), std
.getProgressState(), std.getTitle(), std.getAuthor()
- .getDisplayName()));
+ .getDisplayName());
+ studyDTO.setDate(std.getDate());
+ studyDTO.setLastModificationDate(std.getLastModificationDate());
+ result.add(studyDTO);
}
return result;
}
package org.splat.service.dto;
import java.io.Serializable;
+import java.util.Date;
import org.splat.dal.bo.som.ProgressState;
* Type.
*/
private transient String _type;
+ /**
+ * Creation date.
+ */
+ private transient Date _date;
+ /**
+ * Last modification date.
+ */
+ private Date _lastModificationDate;
/**
* Serialization version id.
*/
private static final long serialVersionUID = -4386494192709562221L;
/**
- * Costructor from properties.
+ * Constructor from properties except for creation and modification dates.
*
* @param id
* study persistent id
public String getType() {
return _type;
}
+
+ /**
+ * Get the date.
+ * @return the date
+ */
+ public Date getDate() {
+ return _date;
+ }
+
+ /**
+ * Set the date.
+ * @param date the date to set
+ */
+ public void setDate(final Date date) {
+ _date = date;
+ }
+
+ /**
+ * Get the lastModificationDate.
+ * @return the lastModificationDate
+ */
+ public Date getLastModificationDate() {
+ return _lastModificationDate;
+ }
+
+ /**
+ * Set the lastModificationDate.
+ * @param lastModificationDate the lastModificationDate to set
+ */
+ public void setLastModificationDate(final Date lastModificationDate) {
+ _lastModificationDate = lastModificationDate;
+ }
}
<table width=100% cellpadding="0" cellspacing="0" border="0"
class="text">
<tr height="20" valign="bottom">
- <td width="20"></td>
- <td width="80"><s:text name="label.reference" /></td>
- <td><s:text name="label.title" /><img
- src="<s:url value="/skin/icon.sortup.png"/>" border="none" /></td>
- <td width="150"><s:text name="label.author" /></td>
- </tr>
+ <td width="20"></td>
+
+ <s:if test="#session.isDescendingOrder">
+ <s:url var="arrowURL" value="/skin/icon.sortup.png"/>
+ </s:if><s:else>
+ <s:url var="arrowURL" value="/skin/icon.sortdown.png"/>
+ </s:else>
+
+ <td width="80">
+ <s:a action="setKnowledgeOrder">
+ <s:param name="newSortedBy" value="%{'REFERENCE'}"/>
+ <s:text name="label.reference" />
+ <s:if test="#session.sortCriterion.toString() eq 'REFERENCE'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
+
+ <td>
+ <s:a action="setKnowledgeOrder">
+ <s:param name="newSortedBy" value="%{'NAME'}"/>
+ <s:text name="label.title" />
+ <s:if test="#session.sortCriterion.toString() eq 'NAME'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
+
+ <td width="80">
+ <s:a action="setKnowledgeOrder">
+ <s:param name="newSortedBy" value="%{'CREATEDATE'}"/>
+ <s:text name="label.created"/>
+ <s:if test="#session.sortCriterion.toString() eq 'CREATEDATE'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
+
+ <td width="150">
+ <s:a action="setKnowledgeOrder">
+ <s:param name="newSortedBy" value="%{'RESPONSIBLE'}"/>
+ <s:text name="label.author" />
+ <s:if test="#session.sortCriterion.toString() eq 'RESPONSIBLE'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
+ </tr>
<tr height="1" bgcolor="#AAAAAA">
- <td colspan="4"></td>
+ <td colspan="5"></td>
</tr>
<s:iterator value="result">
<tr>
</s:url> <s:a href="%{open}" cssClass="link">
<s:property value="title" />
</s:a></td>
+ <td><s:property value="%{date}"/></td>
<td><s:property value="getText(authorName)" /></td>
</tr>
</s:iterator>
class="text">
<tr height="20" valign="bottom">
<td width="20"></td>
- <td width="80"><s:text name="label.reference" /></td>
- <td><s:text name="label.title" /><img
- src="<s:url value="/skin/icon.sortup.png"/>" border="none" /></td>
- <td width="150"><s:text name="label.manager" /></td>
+
+ <s:if test="#session.isDescendingOrder">
+ <s:url var="arrowURL" value="/skin/icon.sortup.png"/>
+ </s:if><s:else>
+ <s:url var="arrowURL" value="/skin/icon.sortdown.png"/>
+ </s:else>
+
+ <td width="80">
+ <s:a action="setStudyOrder">
+ <s:param name="newSortedBy" value="%{'REFERENCE'}"/>
+ <s:text name="label.reference" />
+ <s:if test="#session.sortCriterion.toString() eq 'REFERENCE'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
+
+ <td>
+ <s:a action="setStudyOrder">
+ <s:param name="newSortedBy" value="%{'NAME'}"/>
+ <s:text name="label.title" />
+ <s:if test="#session.sortCriterion.toString() eq 'NAME'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
+
+ <td width="80">
+ <s:a action="setStudyOrder">
+ <s:param name="newSortedBy" value="%{'CREATEDATE'}"/>
+ <s:text name="label.created"/>
+ <s:if test="#session.sortCriterion.toString() eq 'CREATEDATE'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
+
+ <td width="80">
+ <s:a action="setStudyOrder">
+ <s:param name="newSortedBy" value="%{'MODIFDATE'}"/>
+ <s:text name="label.modified"/>
+ <s:if test="#session.sortCriterion.toString() eq 'MODIFDATE'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
+
+ <td width="150">
+ <s:a action="setStudyOrder">
+ <s:param name="newSortedBy" value="%{'RESPONSIBLE'}"/>
+ <s:text name="label.manager" />
+ <s:if test="#session.sortCriterion.toString() eq 'RESPONSIBLE'">
+ <img src="<s:property value="arrowURL"/>" border="none" />
+ </s:if>
+ </s:a>
+ </td>
</tr>
<tr height="1" bgcolor="#AAAAAA">
- <td colspan="4"></td>
+ <td colspan="6"></td>
</tr>
<s:iterator value="result">
<tr>
</s:url> <s:a href="%{open}" cssClass="link">
<s:property value="title" />
</s:a></td>
+ <td><s:property value="%{date}"/></td>
+ <td><s:property value="%{lastModificationDate}"/></td>
<td><s:property value="getText(authorName)" /></td>
</tr>
</s:iterator>
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import org.splat.service.UserService;
import org.splat.service.dto.Proxy;
import org.splat.service.dto.SearchFilterDTO;
+import org.splat.service.dto.StudyDTO;
import org.splat.service.technical.ProjectSettingsService;
import org.splat.som.ApplicationRights;
import org.splat.wapp.Constants;
refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
}
+ /**
+ * A criteria to sort studies by.
+ */
+ private SortCriterion _newSortedBy;
+
+ /**
+ * Sort order key in the session.
+ */
+ protected static final String ORDER_KEY = "isDescendingOrder";
+
+ /**
+ * Sort criterion key in the session.
+ */
+ protected static final String CRITERION_KEY = "sortCriterion";
+
// ==============================================================================================================================
// Action methods
// ==============================================================================================================================
+ /**
+ * StudyDTO sort criteria.
+ */
+ enum SortCriterion {
+ /**
+ * Reference.
+ */
+ REFERENCE,
+ /**
+ * Name.
+ */
+ NAME,
+ /**
+ * Creation date.
+ */
+ CREATEDATE,
+ /**
+ * Modification date.
+ */
+ MODIFDATE,
+ /**
+ * The person responsible.
+ */
+ RESPONSIBLE
+ }
+
+ /**
+ * StudyDTO comparator class.
+ */
+ private class StudyComparator implements Comparator<StudyDTO> {
+
+ /**
+ * The criteria by which studies are compared.
+ */
+ SortCriterion _criterion = SortCriterion.NAME;
+
+ /**
+ * Constructor from comparison criteria.
+ * @param criterion
+ * the criteria
+ */
+ public StudyComparator(final SortCriterion criterion) {
+ _criterion = criterion;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(final StudyDTO first, final StudyDTO second) {
+ switch (_criterion) {
+ case REFERENCE:
+ return first.getReference().compareTo(second.getReference());
+ case CREATEDATE:
+ return first.getDate().compareTo(second.getDate());
+ case MODIFDATE:
+ return first.getLastModificationDate().compareTo(
+ second.getLastModificationDate());
+ case RESPONSIBLE:
+ return getText(first.getAuthorName())
+ .compareTo(getText(second.getAuthorName()));
+ default:
+ return first.getTitle().compareTo(second.getTitle());
+ }
+ }
+ }
+
+ /**
+ * Set search results sort order.
+ * @return
+ * SUCCESS if successfully found and sorted search results;
+ * ERROR otherwise
+ */
+ public String doSetOrder() {
+ String res = ERROR;
+ _result = (List<Proxy>) getSession().get(RESULT_KEY);
+ Boolean order = (Boolean) getSession().get(ORDER_KEY);
+ SortCriterion oldSortedBy = (SortCriterion) getSession().get(CRITERION_KEY);
+
+ if (_result != null) {
+
+ if (_newSortedBy != null && !_newSortedBy.equals(oldSortedBy)) { // Sort by new criterion
+ // Direct cast into collection of another type just won't work in Java
+ Collections.sort((List<StudyDTO>)(List<?>) _result, new StudyComparator(_newSortedBy));
+ getSession().put(CRITERION_KEY, _newSortedBy);
+ getSession().put(ORDER_KEY, false);
+ } else {
+ if (order == null) {
+ order = false;
+ } else { // need to change the order
+ order = !order;
+ }
+ getSession().put(ORDER_KEY, order);
+ Collections.reverse(_result);
+ }
+ res = SUCCESS;
+ }
+
+ return res;
+ }
+
/**
* Perform actions according to the current mode.
*
_filter = filter;
}
}
+
+ /**
+ * Get the newSortedBy.
+ * @return the newSortedBy
+ */
+ public SortCriterion getNewSortedBy() {
+ return _newSortedBy;
+ }
+
+ /**
+ * Set the newSortedBy.
+ * @param newSortedBy the newSortedBy to set
+ */
+ public void setNewSortedBy(final SortCriterion newSortedBy) {
+ _newSortedBy = newSortedBy;
+ }
}
\ No newline at end of file
import org.splat.service.KnowledgeElementTypeService;
import org.splat.service.SearchService;
import org.splat.service.dto.KnowledgeSearchFilterDTO;
+import org.splat.simer.AbstractSearchBaseAction.SortCriterion;
import org.splat.wapp.Constants;
/**
// ==============================================================================================================================
/**
- * The action initialization.
- *
- * @return SUCCESS if succeeded, ERROR if doSearch() is failed
+ * Common initialization for doInitialize() and doSetOrder() methods.
*/
- public String doInitialize() {
-
- initializationFullScreenContext(Constants.OPEN, Constants.NONE,
- Constants.OPEN);
-
- String res = SUCCESS;
+ private void commonInit() {
// Final initialization of the form
_knowledgeTypes = buildKnowledgeTypesOptions();
setCandidates(); // not selected by default
if (ktypeId != null) {
getFilter().setKtype(String.valueOf(ktypeId));
}
+ }
+
+ /**
+ * The action initialization.
+ *
+ * @return SUCCESS if succeeded, ERROR if doSearch() is failed
+ */
+ public String doInitialize() {
+
+ initializationFullScreenContext(Constants.OPEN, Constants.NONE,
+ Constants.OPEN);
+
+ String res = SUCCESS;
+ commonInit();
try {
doSearch();
} catch (Exception error) {
}
return res;
}
+
+ /**
+ * {@inheritDoc}
+ * @see org.splat.simer.AbstractSearchBaseAction#doSetOrder()
+ */
+ @Override
+ public String doSetOrder() {
+ commonInit();
+ return super.doSetOrder();
+ }
/**
* Build the map of translated knowledge types available for selection.
}
_result = getSearchService().selectKnowledgeElementsWhere(getFilter());
getSession().put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
+ getSession().put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
+ getSession().put(ORDER_KEY, false);
+ getSession().put(CRITERION_KEY, SortCriterion.NAME);
return "refresh";
}
}
_result = getSearchService().selectStudiesWhere(getFilter());
getSession().put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
+ getSession().put(ORDER_KEY, false);
+ getSession().put(CRITERION_KEY, SortCriterion.NAME);
return "refresh";
}
</result>
<result name="error" type="tiles">page.home</result>
</action>
+ <action name="setStudyOrder" class="searchStudyAction"
+ method="setOrder">
+ <result name="success" type="tiles">
+ page.searchstudy
+ </result>
+ <result name="error" type="tiles">
+ page.searchstudy
+ </result>
+ </action>
<action name="refresh-study" class="searchStudyAction"
method="submitForm">
<result name="selectype" type="tiles">
page.searchknowledge
</result>
</action>
+ <action name="setKnowledgeOrder" class="searchKnowledgeAction"
+ method="setOrder">
+ <result name="success" type="tiles">
+ page.searchknowledge
+ </result>
+ <result name="error" type="tiles">
+ page.searchknowledge
+ </result>
+ </action>
<action name="refresh-knowledge" class="searchKnowledgeAction"
method="submitForm">
<result name="selectype" type="tiles">