]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Sort study and knowledge results functionalities are implemented
authormka <mka@opencascade.com>
Thu, 19 Sep 2013 09:27:46 +0000 (09:27 +0000)
committermka <mka@opencascade.com>
Thu, 19 Sep 2013 09:27:46 +0000 (09:27 +0000)
Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/dto/StudyDTO.java
Workspace/Siman/WebContent/study/searchKnowledge.jsp
Workspace/Siman/WebContent/study/searchStudy.jsp
Workspace/Siman/src/org/splat/simer/AbstractSearchBaseAction.java
Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java
Workspace/Siman/src/org/splat/simer/SearchStudyAction.java
Workspace/Siman/src/struts.xml

index 2baaf40465a22fe33f4766392c8c34755c63da60..96bff1b1a11e65c61a0588ea42f6a16288a5c5b4 100644 (file)
@@ -201,9 +201,11 @@ public class SearchServiceImpl implements SearchService {
 
                // 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;
        }
@@ -308,9 +310,12 @@ public class SearchServiceImpl implements SearchService {
 
                // 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;
        }
index 6221a38f547765e782f6e95123ee26b6bcb6a54f..cd0ad8c7ff57ee614ba123799284b01256580c62 100644 (file)
@@ -11,6 +11,7 @@
 package org.splat.service.dto;
 
 import java.io.Serializable;
+import java.util.Date;
 
 import org.splat.dal.bo.som.ProgressState;
 
@@ -44,13 +45,21 @@ public class StudyDTO implements Proxy, Serializable {
         * 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
@@ -125,4 +134,36 @@ public class StudyDTO implements Proxy, Serializable {
        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;
+       }
 }
index 50e641ad5874bc476b94ee1c1d0594de592a9123..229a33248e90078972a3d48917c78893328d01ca 100644 (file)
@@ -187,14 +187,56 @@ $(document).ready(function () {
        <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>
@@ -207,6 +249,7 @@ $(document).ready(function () {
                                </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>
index aa73faf406643b35949097108780a751ae57cbae..2d4c909543e73de4019c9e6fab0e0e9ce5eb2e0a 100644 (file)
@@ -191,13 +191,65 @@ $(document).ready(function () {
                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>
@@ -210,6 +262,8 @@ $(document).ready(function () {
                                </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>
index 0ddb11e28bce992a64cc002ab33a10327ceb3b23..4b3808ebc72eb34ef29c0c52d897f74f640b8b49 100644 (file)
@@ -3,6 +3,8 @@ package org.splat.simer;
 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;
@@ -17,6 +19,7 @@ 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.dto.StudyDTO;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.som.ApplicationRights;
 import org.splat.wapp.Constants;
@@ -92,10 +95,126 @@ public abstract class AbstractSearchBaseAction<FilterClass extends SearchFilterD
                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.
         * 
@@ -517,4 +636,20 @@ public abstract class AbstractSearchBaseAction<FilterClass extends SearchFilterD
                        _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
index 8222dc2da0ef92a21c02ddc2c5ee6a73ce712254..661acd124b65b193a36867bd1b3688bd8ed40679 100644 (file)
@@ -11,6 +11,7 @@ import org.splat.kernel.InvalidPropertyException;
 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;
 
 /**
@@ -42,16 +43,9 @@ public class SearchKnowledgeAction extends
        // ==============================================================================================================================
 
        /**
-        * 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
@@ -62,6 +56,20 @@ public class SearchKnowledgeAction extends
                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) {
@@ -71,6 +79,16 @@ public class SearchKnowledgeAction extends
                }
                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.
@@ -100,6 +118,9 @@ public class SearchKnowledgeAction extends
                }
                _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";
        }
 
index 333fb73270c4f203fc6a335d930a2cfc322dda4e..96ba4e60a5015ac4c0a1ea35745b4cacd575b2f1 100644 (file)
@@ -78,6 +78,8 @@ public class SearchStudyAction extends
                }
                _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";
        }
 
index 250e0239b307d9e737669c052c9495d3c14f4bbf..972f706c6f7485ed49792cd86c7322d47b03d37a 100644 (file)
                        </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">