Jump to content

BIRT Developer Center Download


Submitter

File Information

  • Submitted: Oct 24 2013 11:49 AM
  • Last Updated: Apr 23 2014 07:31 AM
  • File Size: Unknown
  • Views: 18573
  • Downloads: 0
  • Approved by: kclark
  • Approved on: 23 April 2014 - 07:31 AM
  • Summary: iPortal displays the files and folders in ascending order based on it names. This code shows how to display the files and folder in ascending or descending order based on modified date
  • Content Type: Designs & Code
  • BIRT Version: Actuate 11

Information Console: Display the folders and files an Ascending or Decending order of modified date

- - - - -
Folders Information Console Files



Screenshots
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"

For eg:

http://mywebserver:8...&SortByDate=DSC

Will sort the files and folder items in teh descending order and

http://mywebserver:8...&SortByDate=ASC

will sort the files and folder items in the ascending order.

Files needs to be customized in the iportal:
iportal\dashboard\jsp
iportal\activePortal\private\filesfolders\views\categories.jsp
iportal\activePortal\private\filesfolders\views\details.jsp
iportal\activePortal\private\filesfolders\views\icons.jsp
iportal\activePortal\private\filesfolders\view\list.jsp
Changes:

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: --%>
This adds the Parameter SortByDate to the session to be availabe to other JSP pages.

2. iportal\\activePortal\\private\\filesfolders\\views\\categories.jsp
<%
    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();
3. iportal\activePortal\private\filesfolders\views\list.jsp
iportal\activePortal\private\filesfolders\views\details.jsp
iportal\activePortal\private\filesfolders\views\icons.jsp

All the three files will have same changes

Replace the line:
com.actuate.schemas.File[] files = (com.actuate.schemas.File[])fileListActionForm.getArray(null);
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
All the three files will have same changes

4. FileCompartor.java

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.

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);
  }
}
\nThe jar file created by compiling this class file has to be put in Activ Portal's class path(i.e WEB-INF\\lib)







  • 997 Total Files
  • 8 Total Categories
  • 153 Total Authors
  • 31732 Total Downloads
  • Joyplot in iHub Latest File
  • Clement Wong Latest Submitter

1 user(s) are online (in the past 1 minutes)

0 members, 1 guests, 0 anonymous users