public PageResponse<QueryPageRow> queryMetaData(QueryMetadataPageRequest request)
      throws SerializationException {
    if (request == null) {
      throw new IllegalArgumentException("request cannot be null");
    }
    if (request.getPageSize() != null && request.getPageSize() < 0) {
      throw new IllegalArgumentException("pageSize cannot be less than zero.");
    }

    // Setup parameters for generic repository query
    Map<String, String[]> queryMap = createQueryMap(request.getMetadata());

    DateQuery[] dates = createDateQueryForRepository(request);

    long start = System.currentTimeMillis();
    AssetItemIterator iterator = rulesRepository.query(queryMap, request.isSearchArchived(), dates);
    log.debug("Search time: " + (System.currentTimeMillis() - start));

    List<QueryPageRow> rowList =
        new QueryMetadataPageRowBuilder().withPageRequest(request).withContent(iterator).build();
    boolean bHasMoreRows = iterator.hasNext();
    PageResponse<QueryPageRow> response =
        new PageResponseBuilder<QueryPageRow>()
            .withStartRowIndex(request.getStartRowIndex())
            .withPageRowList(rowList)
            .withLastPage(!bHasMoreRows)
            .buildWithTotalRowCount(
                -1); // its impossible to know the exact selected count until we'v reached
    // the end of iterator
    long methodDuration = System.currentTimeMillis() - start;
    log.debug("Queried repository (Metadata) in " + methodDuration + " ms.");
    return response;
  }
 private DateQuery[] createDateQueryForRepository(QueryMetadataPageRequest request) {
   DateQuery[] dates = new DateQuery[2];
   dates[0] =
       new DateQuery(
           "jcr:created",
           DateUtil.isoDate(request.getCreatedAfter()),
           DateUtil.isoDate(request.getCreatedBefore()));
   dates[1] =
       new DateQuery(
           AssetItem.LAST_MODIFIED_PROPERTY_NAME,
           DateUtil.isoDate(request.getLastModifiedAfter()),
           DateUtil.isoDate(request.getLastModifiedBefore()));
   return dates;
 }