This tip shows how to customoize getfolderitems page to sort files on ascending order of "Modified Date" when the URL contains parameters "SortByDate=ASC" and sort files in descending order of "Modifed date when the URL contains parameters "SortByDate=DSC"<br />
<br />
For eg:<br />
<br />
http://mywebserver:8900/iportal/dashboard?__vp=server1&SortByDate=DSC<br />
Will sort the files and folder items in teh descending order and<br />
<br />
http://mywebserver:8900/iportal/dashboard?__vp=server1&SortByDate=ASC<br />
will sort the files and folder items in the ascending order.<br />
<br />
Files needs to be customized in the iportal:<br />
iportal\dashboard\jsp<br />
iportal\activePortal\private\filesfolders\views\categories.jsp<br />
iportal\activePortal\private\filesfolders\views\details.jsp<br />
iportal\activePortal\private\filesfolders\views\icons.jsp<br />
iportal\activePortal\private\filesfolders\view\list.jsp<br />
<br />
Changes:<br />
<br />
1. iportal\dashboard\jsp
<%@ page import="com.actuate.reportcast.utils.StaticFuncs" %>
<%-- --------------------------------------------------------------------------
Customization done to Sort the folder items:
Custom code --- BEGINS HERE
-------------------------------------------------------------------------- --%>
<%
String SortStr = request.getParameter("SortByDate");
HttpSession asession = request.getSession();
asession.setAttribute("Gen",SortStr);
%>
<%--- Custom code ENDS here: --%>
<br />
<br />
This adds the Parameter SortByDate to the session to be availabe to other JSP pages.<br />
<br />
2. iportal\activePortal\private\filesfolders\views\categories.jsp<br />
<br />
<%
String emptyString = ""; // BUG NEEDED FOR WEBSPHERE
int printedCount = 0;
%>
<%-- --------------------------------------------------------------------------
Customization done to Sort the folder items:
Custom code --- BEGINS HERE
-------------------------------------------------------------------------- --%>
<%
String SortByDate = (String)request.getSession().getAttribute("SortByDate");
ifSortByDate != null)
{
if(SortByDate .contains("DSC") )
{SortByDate = "DSC";}
else if (SortByDate .contains("ASC"))
{ SortByDate = "ASC"; }
else
{SortByDate = ""; }
}
if ( SortByDate != null && SortByDate.length() != 0 )
{
if (SortByDate.equals("ASC") || SortByDate.equals("DSC"))
{
System.out.println("Input Valid");
}
else
{
SortByDate = "";
}
}
else
{
SortByDate = "";
}
if (null != SortByDate && !"".equals(SortByDate))
{
ObjectCompartor objComp = null;
boolean isAscending = true;
//Sort by ascending, if the parameter is "ASC"
if ("ASC".equals(SortByDate))
objComp = new ObjectComparator( isAscending );
//Sort by descending, if the parameter is "DSC"
if ( "DSC".equals(SortByDate) )
objComp = new ObjectComparator( !isAscending );
if ("ASC".equals(SortByDate) || "DSC".equals(SortByDate))
{
//Sort all the list based on the sort order.
Collections.sort(listOfDocuments, objComp);
Collections.sort(listOfExecutables, objComp);
Collections.sort(listOfFolders, objComp);
Collections.sort(listOfQuery, objComp);
Collections.sort(listOfDataSrc, objComp);
Collections.sort(listOfCubeProfiles, objComp);
Collections.sort(listOfDataCubes, objComp);
}
}
%>
<%--- Custom code ENDS here: --%>
<%
FeatureOptionsBean featureOptionsBean = userinfobean.getFeatureOptionsBean();
<br />
3.
iportal\activePortal\private\filesfolders\views\list.jsp<br />
iportal\activePortal\private\filesfolders\views\details.jsp<br />
iportal\activePortal\private\filesfolders\views\icons.jsp<br />
<br />
All the three files will have same changes<br />
<br />
Replace the line:<br />
<br />
com.actuate.schemas.File[] files = (com.actuate.schemas.File[])fileListActionForm.getArray(null);<br />
<br />
<br />
With the below lines:
//Custom code --> STARTS HERE...
String SortByDate = (String)request.getSession().getAttribute("Gen");
if(SortByDate != null)
{
if(SortByDate.contains("DSC") )
{SortByDate = "DSC";}
else if (SortByDate.contains("ASC"))
{ SortByDate = "ASC"; }
else
{SortByDate = ""; }
}
if ( SortByDate != null && SortByDate.length() != 0 ) { if (SortByDate.equals("ASC") || SortByDate.equals("DSC")) { System.out.println("Input Valid"); } else{ SortByDate = "";} } else { SortByDate = "";} //String SortByDate =request.getParameter("SortByDate");
com.actuate.schemas.File[] unsortedFiles =(com.actuate.schemas.File[])fileListActionForm.getArray(null);
List files = Arrays.asList(unsortedFiles);
if(null != SortByDate && !"".equals(SortByDate))
{
com.vsft.apr.FileComparator fileComp = null;
boolean isAscending = true;
//Sort by ascending, if the parameter is "ASC"
if ( "ASC".equals(SortByDate))
{
fileComp = new com.vsft.apr.FileComparator( isAscending );
Collections.sort(files, fileComp);
}
//Sort by ascending, if the parameter is "DSC"
if ( "DSC".equals(SortByDate))
{
fileComp = new com.vsft.apr.FileComparator( !isAscending );
Collections.sort(files, fileComp);
}
}
//Custom code --> ENDS HERE
<br />
<br />
All the three files will have same changes<br />
<br />
4. FileCompartor.java<br />
<br />
This class implements java.util.Compartor and compares its two arguments for oder. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or grater than the second.<br />
<br />
The sort order is determined by the boolean value passed to constructor of FileComparator.java
/**
* FileComparator constructor
* @param isAscending if true sorts the files in ascending order
*/
package com.vsft.apr;
import com.actuate.schemas.File;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
public class FileComparator
implements Comparator
{
private boolean isAscending = false;
public FileComparator(boolean paramBoolean) {
this.isAscending = paramBoolean;
}
public int compare(Object paramObject1, Object paramObject2)
{
File localFile1 = (File)paramObject1;
File localFile2 = (File)paramObject2;
Date localDate1 = localFile1.getTimeStamp().getTime();
Date localDate2 = localFile2.getTimeStamp().getTime();
if (this.isAscending)
{
return localDate1.compareTo(localDate2);
}
return localDate2.compareTo(localDate1);
}
}
<br />
The jar file created by compiling this class file has to be put in Activ Portal's class path(i.e WEB-INF\lib)