Package com.esri.gpt.framework.request

Examples of com.esri.gpt.framework.request.PageCursor


  // intitalize
  PreparedStatement st = null;
  PreparedStatement stCount = null;
  HeQueryCriteria criteria = getQueryCriteria();
  HeRecords records = getQueryResult().getRecords();
  PageCursor pageCursor = getQueryResult().getPageCursor();
 
  try {
   
    // start the SQL expression
    StringBuffer sbSql   = new StringBuffer();
    StringBuffer sbCount = new StringBuffer();
    StringBuffer sbFrom  = new StringBuffer();
    StringBuffer sbWhere = new StringBuffer();

    sbSql.append("SELECT A.UUID, A.HARVEST_DATE,");
    sbSql.append("A.HARVESTED_COUNT,A.VALIDATED_COUNT,A.PUBLISHED_COUNT");
    sbCount.append("SELECT COUNT(*)");
   
    // append from clause
    sbFrom.append(" FROM ");
    sbFrom.append(getHarvestingHistoryTableName());
    sbFrom.append(" A");
    sbSql.append(sbFrom);
    sbCount.append(sbFrom);

    appendValueFilter(sbWhere,"UPPER(A.HARVEST_ID)",
      getOwner().getUuid(),false);
   
    // harvest event UUID
    String sEventUuid =
      UuidUtil.addCurlies(
      UuidUtil.removeCurlies(criteria.getEventUuid().toUpperCase()));
    if (sEventUuid.length() > 0) {
      sEventUuid = appendValueFilter(sbWhere,"UPPER(A.UUID)",sEventUuid,false);
    }
   
    // harvest date range
    Timestamp tsFrom = criteria.getDateRange().getFromTimestamp();
    Timestamp tsTo = criteria.getDateRange().getToTimestamp();
    if (tsFrom != null) {
      appendExpression(sbWhere,"A.HARVEST_DATE >= ?");
    }
    if (tsTo != null) {
      appendExpression(sbWhere,"A.HARVEST_DATE <= ?");
    }
   
    // append the where clause expressions
    if (sbWhere.length() > 0) {
      sbSql.append(" WHERE ").append(sbWhere.toString());
      sbCount.append(" WHERE ").append(sbWhere.toString());
    }
   
    // append the order by clause
    String sOrderByColumn = criteria.getSortOption().getColumnKey();
    String sOrderByDir =
      criteria.getSortOption().getDirection().name().toUpperCase();
    if (sOrderByColumn.equalsIgnoreCase("report_id")) {
      sOrderByColumn = "A.UUID";
    } else if (sOrderByColumn.equalsIgnoreCase("harvest_date")) {
      sOrderByColumn = "A.HARVEST_DATE";
    } else if (sOrderByColumn.equalsIgnoreCase("harvested_count")) {
      sOrderByColumn = "A.HARVESTED_COUNT";
    } else if (sOrderByColumn.equalsIgnoreCase("validated_count")) {
      sOrderByColumn = "A.VALIDATED_COUNT";
    } else if (sOrderByColumn.equalsIgnoreCase("published_count")) {
      sOrderByColumn = "A.PUBLISHED_COUNT";
    } else {
      sOrderByColumn = "A.HARVEST_DATE";
      sOrderByDir = "DESC";
    }
    if (sOrderByDir.length() == 0) {
      sOrderByDir = "ASC";
    }
    sbSql.append(" ORDER BY ");
    sbSql.append(sOrderByColumn).append(" ").append(sOrderByDir);

    // establish the connection
    ManagedConnection mc = returnConnection();
    Connection con = mc.getJdbcConnection();
   
    // prepare the statements
    int n = 0;
    st = con.prepareStatement(sbSql.toString());
    stCount = con.prepareStatement(sbCount.toString());
   
    // owner id
    n++;
    st.setString(n,getOwner().getUuid().toUpperCase());
    stCount.setString(n,getOwner().getUuid().toUpperCase());
   
    // harvest UUID
    if (sEventUuid.length() > 0) {
      n++;
      st.setString(n,sEventUuid);
      stCount.setString(n,sEventUuid);
    }
   
    // harvest update date range
    if (tsFrom != null) {
      n++;
      st.setTimestamp(n,tsFrom);
      stCount.setTimestamp(n,tsFrom);    
    }
    if (tsTo != null) {
      n++;
      st.setTimestamp(n,tsTo);
      stCount.setTimestamp(n,tsTo);    
    }
   
    // query the count
    logExpression(sbCount.toString());
    ResultSet rsCount = stCount.executeQuery();
    if (rsCount.next()) {
      pageCursor.setTotalRecordCount(rsCount.getInt(1));
    }
    closeStatement(stCount);
    stCount = null;
   
    // query records if a count was found
    if (pageCursor.getTotalRecordCount() > 0) {

      // set the start record and the number of records to retrieve
      int nCurPage = pageCursor.getCurrentPage();
      int nRecsPerPage = getQueryResult().getPageCursor().getRecordsPerPage();
      int nStartRecord = ((nCurPage - 1) * nRecsPerPage) + 1;
      int nMaxRecsToRetrieve = nCurPage * nRecsPerPage;
      st.setMaxRows(nMaxRecsToRetrieve);

View Full Code Here


    // intitalize
    PreparedStatement st = null;
    PreparedStatement stCount = null;
    HrQueryCriteria criteria = getQueryCriteria();
    HrRecords records = getQueryResult().getRecords();
    PageCursor pageCursor = getQueryResult().getPageCursor();

    try {

      // start the SQL expression
      StringBuffer sbSql = new StringBuffer();
      StringBuffer sbCount = new StringBuffer();
      StringBuffer sbFrom = new StringBuffer();
      StringBuffer sbWhere = new StringBuffer();
      StringBuffer sbJoin = new StringBuffer();

      sbSql.append("SELECT A.ID,A.DOCUUID,A.OWNER,A.INPUTDATE,A.UPDATEDATE");
      sbSql.append(",A.TITLE,A.HOST_URL,A.FREQUENCY");
      sbSql.append(",A.SEND_NOTIFICATION,A.PROTOCOL,H.LAST_HARVEST_DATE");
      sbSql.append(",A.FINDABLE,A.SEARCHABLE,A.SYNCHRONIZABLE,A.APPROVALSTATUS,A.LASTSYNCDATE");

      sbSql.append(",(SELECT COUNT(*) FROM " + getHarvestingJobTableName() + " HJ");
      sbSql.append(" WHERE HJ.HARVEST_ID=A.DOCUUID");
      if (getIsDbCaseSensitive(this.getRequestContext())) {
        sbSql.append(" AND UPPER(HJ.JOB_STATUS)='" + HjRecord.JobStatus.Submited.name().toUpperCase() + "') ");
      } else {
        sbSql.append(" AND HJ.JOB_STATUS='" + HjRecord.JobStatus.Submited.name().toUpperCase() + "') ");
      }

      sbSql.append(",(SELECT COUNT(*) FROM " + getHarvestingJobTableName() + " HJ");
      sbSql.append(" WHERE HJ.HARVEST_ID=A.DOCUUID");
      if (getIsDbCaseSensitive(this.getRequestContext())) {
        sbSql.append(" AND UPPER(HJ.JOB_STATUS)='" + HjRecord.JobStatus.Running.name().toUpperCase() + "') ");
      } else {
        sbSql.append(" AND HJ.JOB_STATUS='" + HjRecord.JobStatus.Running.name().toUpperCase() + "') ");
      }

      sbSql.append(",(SELECT COUNT(*) FROM " + getHarvestingJobTableName() + " HJ");
      sbSql.append(" WHERE HJ.HARVEST_ID=A.DOCUUID");
      if (getIsDbCaseSensitive(this.getRequestContext())) {
        sbSql.append(" AND UPPER(HJ.JOB_STATUS)='" + HjRecord.JobStatus.Completed.name().toUpperCase() + "') ");
      } else {
        sbSql.append(" AND HJ.JOB_STATUS='" + HjRecord.JobStatus.Completed.name().toUpperCase() + "') ");
      }

      sbSql.append(",(SELECT COUNT(*) FROM " + getHarvestingJobTableName() + " HJ");
      sbSql.append(" WHERE HJ.HARVEST_ID=A.DOCUUID");
      if (getIsDbCaseSensitive(this.getRequestContext())) {
        sbSql.append(" AND UPPER(HJ.JOB_STATUS)='" + HjRecord.JobStatus.Canceled.name().toUpperCase() + "') ");
      } else {
        sbSql.append(" AND HJ.JOB_STATUS='" + HjRecord.JobStatus.Canceled.name().toUpperCase() + "') ");
      }

      sbCount.append("SELECT COUNT(A.DOCUUID)");

      // append from clause
      sbFrom.append(" FROM ").append(getHarvestingTableName()).append(" A");

      sbSql.append(sbFrom);
      sbCount.append(sbFrom);

      // append join clause
      sbJoin.append(" LEFT JOIN (SELECT MAX(HH.HARVEST_DATE) AS LAST_HARVEST_DATE");
      sbJoin.append(",HH.HARVEST_ID AS UUID FROM GPT_HARVESTING_HISTORY HH ");
      sbJoin.append("GROUP BY HH.HARVEST_ID) H ON A.DOCUUID=H.UUID");

      sbSql.append(sbJoin);
      sbCount.append(sbJoin);

      // build the where clause
      // TODO remove for the final version after merging
      sbWhere.append(" (A.PROTOCOL IS NOT NULL) ");
      if (!_ignoreUser) {
        Users users = buildSelectablePublishers(getRequestContext());
        if (users.size() > 0) {
          StringBuilder sb = new StringBuilder();
          for (User u : users.values()) {
            if (sb.length() > 0) {
              sb.append(",");
            }
            sb.append(Integer.toString(u.getLocalID()));
          }
          if (sb.length() > 0) {
            if (sbWhere.length() > 0) {
              sbWhere.append(" and ");
            }
            sbWhere.append(" A.OWNER in (");
            sbWhere.append(sb.toString());
            sbWhere.append(") ");
          }
        }
      }

      // local harvest id
      String sLocalId = getQueryCriteria().getLocalId();
      if (sLocalId.length() > 0 && Val.chkInt(sLocalId, 0) > 0) {
        sLocalId = appendValueFilter(sbWhere, "A.ID", sLocalId, false);
      } else {
        sLocalId = "";
      }

      // harvest UUID
      String sHarvestUuid =
              UuidUtil.addCurlies(
              UuidUtil.removeCurlies(getQueryCriteria().getUuid().toUpperCase()));
      if (sHarvestUuid.length() > 0) {
        if (getIsDbCaseSensitive(this.getRequestContext())) {
          sHarvestUuid = appendValueFilter(sbWhere, "UPPER(A.DOCUUID)", sHarvestUuid, false);
        } else {
          sHarvestUuid = appendValueFilter(sbWhere, "A.DOCUUID", sHarvestUuid, false);
        }
      }

      // repository name
      String sName = criteria.getName().toUpperCase();
      if (sName.length() > 0) {
        if (getIsDbCaseSensitive(this.getRequestContext())) {
          sName = appendValueFilter(sbWhere, "UPPER(A.TITLE)", sName, true);
        } else {
          sName = appendValueFilter(sbWhere, "A.TITLE", sName, true);
        }
      }

      // host name
      String sHostUrl = criteria.getHost().toUpperCase();
      if (sHostUrl.length() > 0) {
        if (getIsDbCaseSensitive(this.getRequestContext())) {
          sHostUrl = appendValueFilter(sbWhere, "UPPER(A.HOST_URL)", sHostUrl, true);
        } else {
          sHostUrl = appendValueFilter(sbWhere, "A.HOST_URL", sHostUrl, true);
        }
      }

      // protocol type
      String sProtocolType = criteria.getProtocolTypeAsString().toUpperCase();
      if (criteria.getProtocolType() != HarvestProtocol.ProtocolType.None) {
        if (getIsDbCaseSensitive(this.getRequestContext())) {
          sProtocolType = appendValueFilter(sbWhere, "UPPER(A.PROTOCOL_TYPE)", sProtocolType, false);
        } else {
          sProtocolType = appendValueFilter(sbWhere, "A.PROTOCOL_TYPE", sProtocolType, false);
        }
      }

      // update date range
      Timestamp tsFrom = criteria.getDateRange().getFromTimestamp();
      Timestamp tsTo = criteria.getDateRange().getToTimestamp();
      if (tsFrom != null) {
        appendExpression(sbWhere, "A.UPDATEDATE >= ?");
      }
      if (tsTo != null) {
        appendExpression(sbWhere, "A.UPDATEDATE <= ?");
      }

      // harvest date range
      Timestamp tsHarvestFrom =
              criteria.getLastHarvestDateRange().getFromTimestamp();
      Timestamp tsHarvestTo = criteria.getLastHarvestDateRange().getToTimestamp();
      if (tsHarvestFrom != null) {
        appendExpression(sbWhere, "H.LAST_HARVEST_DATE >= ?");
      }
      if (tsHarvestTo != null) {
        appendExpression(sbWhere, "H.LAST_HARVEST_DATE <= ?");
      }

      // append the where clause expressions
      if (sbWhere.length() > 0) {
        sbSql.append(" WHERE ").append(sbWhere.toString());
        sbCount.append(" WHERE ").append(sbWhere.toString());
      }

      // append the order by clause
      String sOrderByColumn = criteria.getSortOption().getColumnKey();
      String sOrderByDir = criteria.getSortOption().getDirection().name();
      if (sOrderByColumn.equalsIgnoreCase("local_id")) {
        sOrderByColumn = "A.ID";
      } else if (sOrderByColumn.equalsIgnoreCase("harvest_id")) {
        sOrderByColumn = "A.DOCUUID";
      } else if (sOrderByColumn.equalsIgnoreCase("input_date")) {
        sOrderByColumn = "A.INPUTDATE";
      } else if (sOrderByColumn.equalsIgnoreCase("update_date")) {
        sOrderByColumn = "A.UPDATEDATE";
      } else if (sOrderByColumn.equalsIgnoreCase("last_harvest_date")) {
        sOrderByColumn = "H.LAST_HARVEST_DATE";
      } else if (sOrderByColumn.equalsIgnoreCase("name")) {
        sOrderByColumn = "A.TITLE";
      } else if (sOrderByColumn.equalsIgnoreCase("host_url")) {
        sOrderByColumn = "A.HOST_URL";
      } else if (sOrderByColumn.equalsIgnoreCase("protocol_type")) {
        sOrderByColumn = "A.PROTOCOL_TYPE";
      } else {
        sOrderByColumn = "A.INPUTDATE";
        sOrderByDir = "DESC";
      }
      if (sOrderByDir.length() == 0) {
        sOrderByDir = "ASC";
      }
      sbSql.append(" ORDER BY ");
      sbSql.append(sOrderByColumn).append(" ").append(sOrderByDir);

      // establish the connection
      ManagedConnection mc = returnConnection();
      Connection con = mc.getJdbcConnection();

      // prepare the statements
      int n = 0;
      st = con.prepareStatement(sbSql.toString());
      stCount = con.prepareStatement(sbCount.toString());

      // local harvest id
      if (sLocalId.length() > 0) {
        n++;
        st.setInt(n, Val.chkInt(sLocalId, 0));
        stCount.setInt(n, Val.chkInt(sLocalId, 0));
      }

      // harvest UUID
      if (sHarvestUuid.length() > 0) {
        n++;
        st.setString(n, sHarvestUuid);
        stCount.setString(n, sHarvestUuid);
      }

      // repository name
      if (sName.length() > 0) {
        n++;
        st.setString(n, sName);
        stCount.setString(n, sName);
      }

      // host name
      if (sHostUrl.length() > 0) {
        n++;
        st.setString(n, sHostUrl);
        stCount.setString(n, sHostUrl);
      }

      // protocol type
      if (criteria.getProtocolType() != HarvestProtocol.ProtocolType.None) {
        n++;
        st.setString(n, sProtocolType);
        stCount.setString(n, sProtocolType);
      }

      // update date range
      if (tsFrom != null) {
        n++;
        st.setTimestamp(n, tsFrom);
        stCount.setTimestamp(n, tsFrom);
      }
      if (tsTo != null) {
        n++;
        st.setTimestamp(n, tsTo);
        stCount.setTimestamp(n, tsTo);
      }


      // harvest date range
      if (tsHarvestFrom != null) {
        n++;
        st.setTimestamp(n, tsHarvestFrom);
        stCount.setTimestamp(n, tsHarvestFrom);
      }
      if (tsHarvestTo != null) {
        n++;
        st.setTimestamp(n, tsHarvestTo);
        stCount.setTimestamp(n, tsHarvestTo);
      }

      // query the count
      logExpression(sbCount.toString());
      ResultSet rsCount = stCount.executeQuery();

      int nTotalRecordCount = 0;
      if (rsCount.next()) {
        nTotalRecordCount = rsCount.getInt(1);
        pageCursor.setTotalRecordCount(nTotalRecordCount);
      }
      closeStatement(stCount);
      stCount = null;

      // query records if a count was found
      if (nTotalRecordCount > 0) {

        // set the start record and the number of records to retrieve
        int nCurPage = pageCursor.getCurrentPage();
        int nRecsPerPage = getQueryResult().getPageCursor().getRecordsPerPage();
        int nStartRecord = ((nCurPage - 1) * nRecsPerPage) + 1;
        int nMaxRecsToRetrieve = nCurPage * nRecsPerPage;
        if (_ignorePagination || criteria.getDueOnly()) {
          st.setMaxRows(nTotalRecordCount);
        } else {
          st.setMaxRows(nMaxRecsToRetrieve);
        }

        // execute the query
        logExpression(sbSql.toString());
        ResultSet rs = st.executeQuery();

        // build the record set
        int nCounter = 0;
        while (rs.next()) {
          try {
            HrRecord record = null;
            if (criteria.getDueOnly()) {
              record = readRecord(con, rs);
              if (record.getIsHarvestDue()) {
                nCounter++;
              } else {
                nTotalRecordCount = nTotalRecordCount > 0 ? nTotalRecordCount - 1 : 0;
              }
            } else {
              nCounter++;
            }
            if (nCounter >= nStartRecord) {
              if (record == null) {
                record = readRecord(con, rs);
              }
              if (criteria.getDueOnly()) {
                if (record.getIsHarvestDue()) {
                  records.add(record);
                }
              } else {
                records.add(record);
              }
              // break if we hit the max value for the cursor
              if (!_ignorePagination && records.size() >= nRecsPerPage) {
                break;
              }
            }
          } catch (ProtocolParseException ex) {
            LOGGER.log(Level.WARNING, "Error reading record.", ex);
          }
        }

      }

      pageCursor.setTotalRecordCount(nTotalRecordCount);

    } finally {
      closeStatement(st);
      closeStatement(stCount);
    }
View Full Code Here

  SearchCriteria criteria = this.getSearchCriteria();

  if(LOG.isLoggable(Level.FINER)) {
    LOG.log(Level.FINER, "Search Criteria Object = \n{0}", criteria.toString());
  }
  PageCursor pageCursor = this.getSearchResult().getPageCursor();

  //record this for resetting the page cursor
  int recordsPerPage = pageCursor.getRecordsPerPage();
  try {

    // if page < 0, then the page in the session (pageCursor) will be used
    if(page > 0){
      pageCursor.setCurrentPage(page);
    }


    // Changed below so that pre-fetch does not do hits.  Pagination
    // will be achieved by getting 1 more result the the records per page
    // to see if there will be more results (Peeking)



    // Controlling startposition since will be adjusting the
    // records per page
    if(pageCursor instanceof SearchFilterPagination && page >= 1) {
      ((SearchFilterPagination)pageCursor).setStartPostion(
          ((page - 1) * pageCursor.getRecordsPerPage()) + );

    }
    // if page == pageCursor total than we are on an edge, we should check
    // if next page exists.
    // if the total number of pages == 0 then we are also on a starting edge
    // we should check if next page exists (
    //
    /*if(page == pageCursor.getTotalPageCount() || pageCursor.getTotalPageCount()
        == 0) {
      pageCursor.setRecordsPerPage(recordsPerPage + 1);
    }*/

    ASearchEngine dao = this.getSearchDao();

    double time = 0;
    // checks if we are at the beginning border (totalPages == 0) or we
    // are at a late border (totalPages > 0
    int border = 0;


    border = 1;

    dao.doSearch();

    // If search criteria changes while you are in a page more than 1
    // then reset to page 1 if no results exists for this search
    /*
    if(page > 1 && this.getSearchResult().getRecords().size() < 1) {
      this.doSearch(urlBuilder, 1, doPrefetch);
    }
    */
   // RequestContext context = this.extractRequestContext();
   // this.getSearchResult().getRecords().buildResourceLinks(context);
    this.getSearchResult().setSearchTimeInSeconds(time += dao.getTimeInSeconds());

    // Insert maximum query hits if provided
    int maxQueryHits = this.getSearchResult().getMaxQueryHits();
    if (getSearchResult().getRecords().size() == 0) {
      maxQueryHits = 0;
    }
    if(maxQueryHits > pageCursor.getTotalPageCount()) {
      pageCursor.setTotalRecordCount(maxQueryHits);
    }
    //pageCursor.checkCurrentPage(); Resolves Ontime # 39321

    // If peek succeeded in getting extra records then adjust the total record
    // count accordingly
    /*if(maxQueryHits < 0 && page >= pageCursor.getTotalPageCount() || pageCursor.getTotalPageCount()
        == 0) {
      pageCursor.setTotalRecordCount(pageCursor.getTotalRecordCount()
          +  this.getSearchResult().getRecordSize() - border);
    }*/

    // Reduce the size of the results if we did a peek
    if(this.getSearchResult().getRecordSize() > recordsPerPage) {

      this.getSearchResult().getRecords().remove(recordsPerPage);

    }
    this.setNavigationOutcome(NAV_CRITERIA2RESULTS);
  } finally {
    // Readjust records per page incase it was affected by peeking
    //pageCursor.setRecordsPerPage(recordsPerPage);
    pageCursor.checkCurrentPage();
  }


}
View Full Code Here

  idPrefix = this.getId() + "_UIPagination" + index + "_"; //$NON-NLS-1$ //$NON-NLS-2$
  return idPrefix;
}

private PageCursor getCriteriaPageCursor() {
  PageCursor pageCursor = null;
  try {
   
  Object pageCursorObj = this.getAttributes()
  .get(ComponentMapKeys.criteriaCursor.name());
   pageCursorObj = ((ValueBinding) pageCursorObj)
View Full Code Here

* @param context the context
*/
@SuppressWarnings("unchecked"
private void setRenderComponents() {

  PageCursor pageCursor = this.getPageCursor();


  UIComponent component = null;

  // Next component
  component = uiSupport.findComponent(this, this.getIdNextPage());
  component.setRendered(pageCursor.getHasNextPage());
  if(component.isRendered()) {
   component.getAttributes().put
    (PageEvents.goToPage.name(), pageCursor.getNextPage());
   if(component instanceof HtmlOutputLink) {
     ((HtmlOutputLink)component).setOnclick(this.readJscriptOnclickPage(
         pageCursor.getCurrentPage() + 1));
   }
  }
 

  // Previous component
  component = uiSupport.findComponent(this, this.getIdPreviousPage());
  component.setRendered(pageCursor.getHasPreviousPage());
  if(component.isRendered()) {
    component.getAttributes().put
    (PageEvents.goToPage.name(), pageCursor.getPreviousPage());
    if(component instanceof HtmlOutputLink) {
      ((HtmlOutputLink)component).setOnclick(this.readJscriptOnclickPage(
          pageCursor.getCurrentPage() - 1));
    }
  }

  // First page component
  component = uiSupport.findComponent(this, this.getIdFirstPage());
  component.setRendered((pageCursor.getCurrentPage() > 1 )
      && this.getRenderFirstPageLink());
  if(component instanceof HtmlOutputLink) {
    ((HtmlOutputLink)component).setOnclick(this.readJscriptOnclickPage(1));
  }
  // this.getRenderFirstPageLink();


  // Last page component
  component = uiSupport.findComponent(this, this.getIdLastPage());
  component.setRendered(
      (pageCursor.getCurrentPage() != pageCursor.getTotalPageCount())
      && (pageCursor.getTotalPageCount() > 0)
      && this.getRenderFirstPageLink());
  if(component.isRendered()) {
    component.getAttributes().put
    (PageEvents.goToPage.name(), this.getPageCursor().getTotalPageCount());
    if(component instanceof HtmlOutputLink) {
      ((HtmlOutputLink)component).setOnclick(this.readJscriptOnclickPage(
          pageCursor.getTotalPageCount()));
    }
  }
 
  // Label component
  component = uiSupport.findComponent(this, this.getIdTxtStats());
View Full Code Here

        " maxEnumeratedPages not null but less than 2. " + //$NON-NLS-1$
        " if this number is defined in your JSP page it should be" + //$NON-NLS-1$
    " >= 2."); //$NON-NLS-1$
    return;
  }
  PageCursor pageCursor = this.getPageCursor();
  if(pageCursor.getTotalPageCount() <= 1) {
    pnlEnumPages.getChildren().clear();
    return;
  }

  MethodBinding pActionMethodBind = this.getActionListenerMethod();
  MethodBinding actionMethod = this.getActionBinding();

  int currentPage = pageCursor.getCurrentPage();
  int lowNum = currentPage -
  (int) Math.floor((numEnumPages / 2.0));
  int highNum = currentPage
  + (int) Math.floor(numEnumPages / 2.0);
  if(lowNum <= 0) {
    highNum = highNum + Math.abs(lowNum) + 1;
  }
  if(highNum > pageCursor.getTotalPageCount() && lowNum > 1) {
    lowNum = lowNum - (highNum - pageCursor.getTotalPageCount());
  }

  pnlEnumPages.getChildren().clear();
  if(pnlEnumPages instanceof HtmlPanelGrid) {
    ((HtmlPanelGrid) pnlEnumPages).setColumns((int)numEnumPages);
  }

  UIComponent link = null;
  HtmlOutputText outputText = null;
  String propertyPrefix =
    this.getProperty("catalog.general.pageCursor.pagesPrefix.alt"); //$NON-NLS-1$
  for(int i = lowNum; i <= highNum && i <= pageCursor.getTotalPageCount(); i++) {
    if(i <= 0) {
      continue;
    }
    if (useAjax) {
      link = new HtmlOutputLink();
View Full Code Here

* @param context
*/
@Override
public void decode(FacesContext context) {
 
  PageCursor cursor = this.getCriteriaPageCursor();
  if(cursor == null) {
    return;
  }
  UISupport support = new UISupport();
  Map requestMap = context.getExternalContext().getRequestParameterMap();
  String clientId = getClientId(context);
  String prefix = this.getIdPrefix();
  Iterator iter = requestMap.values().iterator();
  while(iter.hasNext()) {
    try {
      Object obj = iter.next();
      if (obj == null) {
        continue;
      }
      String value = null;
      UIComponent component = null;
      HtmlCommandLink link = null;
      HtmlOutputText txt = null;
      value = obj.toString();
      if (value.contains(clientId) && value.contains(prefix)) {
        component = support.findComponent(this, value.substring(value
            .indexOf(":") + 1));
      }
     
      if (!(component instanceof HtmlCommandLink )) {
        continue;
      }

      link = (HtmlCommandLink) component;
      if (link.getId().contains(this.getIdFirstPage())) {
        cursor.setCurrentPage(1);
      } else if (link.getId().contains(this.getIdLastPage())) {
        cursor.setCurrentPage(cursor.getTotalPageCount());
      } else if (link.getId().contains(this.getIdNextPage())) {
        cursor.setCurrentPage(cursor.getCurrentPage() + 1);
      } else if (link.getId().contains(this.getIdPreviousPage())) {
        cursor.setCurrentPage(cursor.getCurrentPage() - 1);
      } else {
        txt = (HtmlOutputText) component.getChildren().get(0);
        int page = Val.chkInt(txt.getValue().toString(), Integer.MIN_VALUE);
        if (page >= 1) {
          cursor.setCurrentPage(page);
        }
      }
    } catch (Throwable e) {
      LOG.log(Level.FINER, "", e);
View Full Code Here

  PreparedStatement stCount = null;
  PreparedStatement stUser = null;
  PreparedStatement stCol = null;
  MmdQueryCriteria criteria = getQueryCriteria();
  MmdRecords records = getQueryResult().getRecords();
  PageCursor pageCursor = getQueryResult().getPageCursor();
  criteria.getDateRange().check();
  pageCursor.setTotalRecordCount(0);

  adminDao = new ImsMetadataAdminDao(getRequestContext());
  tblImsUser = getRequestContext().getCatalogConfiguration().getUserTableName();
  Users editablePublishers = Publisher.buildSelectablePublishers(getRequestContext(), false);
  for (User u : editablePublishers.values()) {
    if (u.getName().length() > 0) {
      hmEditablePublishers.put(u.getName().toLowerCase(), u.getKey());
    }
  }
  User tmpUser = new User();
  tmpUser.setDistinguishedName("*");
  getRequestContext().newIdentityAdapter().readUserGroups(tmpUser);
  allGroups = tmpUser.getGroups();

  isGptAdministrator = new RoleMap(getRequestContext().getUser()).get("gptAdministrator");
 
  try {

    // establish the connection
    ManagedConnection mc = returnConnection();
    Connection con = mc.getJdbcConnection();
   
    // determine if the database is case sensitive
    StringAttributeMap params = getRequestContext().getCatalogConfiguration().getParameters();
    String s = Val.chkStr(params.getValue("database.isCaseSensitive"));
    boolean isDbCaseSensitive = !s.equalsIgnoreCase("false");
   
    s = Val.chkStr(params.getValue("catalog.enableEditForAllPubMethods"));
    this.enableEditForAllPubMethods = s.equalsIgnoreCase("true");
   
    // determine if collections are being used
    List<String[]> collections = null;
    CollectionDao colDao = new CollectionDao(getRequestContext());
    boolean hasCollections = false;
    boolean useCollections = colDao.getUseCollections();
    String sColMemberTable = colDao.getCollectionMemberTableName();
    String sqlCol = "SELECT COLUUID FROM "+sColMemberTable+
                    " WHERE DOCUUID=?";
    if (useCollections) {
      collections = colDao.queryCollections();
      hasCollections = (collections.size() > 0);
    }
   
    // username query
    String sqlUser = "SELECT USERNAME FROM "+tblImsUser+" WHERE USERID=?";

    // start the SQL expression
    StringBuilder sbSql = new StringBuilder();
    StringBuilder sbCount = new StringBuilder();
    StringBuilder sbFrom = new StringBuilder();
    StringBuilder sbWhere = new StringBuilder();
    sbSql.append("SELECT A.TITLE,A.DOCUUID,A.SITEUUID,A.OWNER");
    sbSql.append(",A.APPROVALSTATUS,A.PUBMETHOD,A.UPDATEDATE,A.ACL");
    sbSql.append(",A.ID,A.HOST_URL,A.FREQUENCY,A.SEND_NOTIFICATION,A.PROTOCOL");
    sbSql.append(",A.FINDABLE,A.SEARCHABLE,A.SYNCHRONIZABLE");
    sbCount.append("SELECT COUNT(*)");

    // append from clause
    sbFrom.append(" FROM ").append(getResourceTableName()).append(" A");
    sbSql.append(sbFrom);
    sbCount.append(sbFrom);

    // build the where clause
    Map<String,Object> args = criteria.appendWherePhrase(
        getRequestContext(),"A",sbWhere,getPublisher());

    // collection filter
    String sColUuid = Val.chkStr(criteria.getCollectionUuid());
    if (useCollections && hasCollections && (sColUuid.length() > 0)) {
      String sub = "SELECT DOCUUID FROM "+sColMemberTable+
                   " WHERE COLUUID=?";
      if (sbWhere.length() > 0) sbWhere.append(" AND ");
      sbWhere.append("(A.DOCUUID IN ("+sub+"))");
    }
   
    // append the where clause expressions
    if (sbWhere.length() > 0) {
      sbSql.append(" WHERE ").append(sbWhere.toString());
      sbCount.append(" WHERE ").append(sbWhere.toString());
    }

    // append the order by clause
    String sSortColumn = criteria.getSortOption().getColumnKey();
    String sSortDir = criteria.getSortOption().getDirection().toString();
    if (sSortColumn.equalsIgnoreCase("title")) {
      if (isDbCaseSensitive) {
        sSortColumn = "UPPER(A.TITLE)";
      } else {
        sSortColumn = "A.TITLE";
      }
    } else if (sSortColumn.equalsIgnoreCase("uuid")) {
      sSortColumn = "A.DOCUUID";
    } else if (sSortColumn.equalsIgnoreCase("status")) {
      sSortColumn = "A.APPROVALSTATUS";
    } else if (sSortColumn.equalsIgnoreCase("method")) {
      sSortColumn = "A.PUBMETHOD";
    } else if (sSortColumn.equalsIgnoreCase("acl")) {
      sSortColumn = "A.ACL";
    } else if (sSortColumn.equalsIgnoreCase("updatedate")) {
      sSortColumn = "A.UPDATEDATE";
    } else {
      sSortColumn = "A.UPDATEDATE";
      sSortDir = "DESC";
      criteria.getSortOption().setColumnKey("updatedate");
      criteria.getSortOption().setDirection("desc");
    }
    sbSql.append(" ORDER BY ");
    sbSql.append(sSortColumn).append(" ").append(sSortDir.toUpperCase());
    if (!sSortColumn.equalsIgnoreCase("A.UPDATEDATE")) {
      sbSql.append(", A.UPDATEDATE DESC");
    }

    // prepare the statements
    st = con.prepareStatement(sbSql.toString());
    stCount = con.prepareStatement(sbCount.toString());
    stUser = con.prepareStatement(sqlUser);
    int n = 1;
    criteria.applyArgs(st, n, args);
    n = criteria.applyArgs(stCount, n, args);
    if (useCollections && hasCollections) {
      stCol = con.prepareStatement(sqlCol);
      if (sColUuid.length() > 0) {
        st.setString(n,sColUuid);
        stCount.setString(n,sColUuid);
        n++;
      }
    }

    // query the count
    //System.err.println(sbCount.toString());
    //System.err.println(sbSql.toString());
    logExpression(sbCount.toString());
    ResultSet rsCount = stCount.executeQuery();
    if (rsCount.next()) {
      pageCursor.setTotalRecordCount(rsCount.getInt(1));
    }
    stCount.close();
    stCount = null;

    // query records if a count was found
    pageCursor.checkCurrentPage();
    if (pageCursor.getTotalRecordCount() > 0) {

      // set the start record and the number of records to retrieve
      int nCurPage = pageCursor.getCurrentPage();
      int nRecsPerPage = getQueryResult().getPageCursor().getRecordsPerPage();
      int nStartRecord = ((nCurPage - 1) * nRecsPerPage) + 1;
      int nMaxRecsToRetrieve = nCurPage * nRecsPerPage;
      st.setMaxRows(nMaxRecsToRetrieve);

View Full Code Here

    return;
  }
  SearchResult result = this.getRequestDefinition().getResult();
  SearchCriteria criteria = this.getRequestDefinition().getCriteria();
  ISearchFilterPagination criteriaCursor = criteria.getSearchFilterPageCursor();
  PageCursor resultsCursor = result.getPageCursor();
 
  resultsCursor.setRecordsPerPage(criteriaCursor.getRecordsPerPage());
  resultsCursor.setCurrentPage(criteriaCursor.getCurrentPage());

  if(result.getMaxQueryHits() >= result.getRecordSize()) {
    return;
  }
  if(result.getRecordSize() <= 0 &&
View Full Code Here

TOP

Related Classes of com.esri.gpt.framework.request.PageCursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.