// Gets
  public CalendarReminder getCalendarReminder(long userId, String eventId, Date sendDate) {

    /**
     * Find an CalenderReminder, based on the user, event and date of the reminder
     *
     * @param userId userId of the CalendarReminder to retrieve
     * @param eventId eventId of the CalendarReminder to retrieve
     * @param sendDate Date of the CalendarReminder to retrieve
     * @return
     */
    CalendarReminder returnValue = new CalendarReminder();
    try {
      String query =
          "from calendar_reminder in class com.dotmarketing.portlets.calendar.model.CalendarReminder where user_id = ? and event_id = ? and send_date = ?";
      HibernateUtil dh = new HibernateUtil(CalendarReminder.class);
      dh.setQuery(query);
      dh.setParam(userId);
      dh.setParam(eventId);
      dh.setParam(eventId);
      dh.setParam(sendDate);
      returnValue = (CalendarReminder) dh.load();
    } catch (Exception e) {
      Logger.warn(
          CalendarReminderFactoryImpl.class, "getCalendarReminder failed:" + e.getMessage(), e);
    } finally {
      return returnValue;
    }
  }
 /**
  * Return all the CalendarReminders of the system
  *
  * @return
  * @throws DotDataException
  */
 public List<CalendarReminder> getAll() {
   List<CalendarReminder> returnValue = new ArrayList<CalendarReminder>();
   try {
     String query =
         "from calendar_reminder in class com.dotmarketing.portlets.calendar.model.CalendarReminder";
     HibernateUtil dh = new HibernateUtil(CalendarReminder.class);
     dh.setQuery(query);
     returnValue = (List<CalendarReminder>) dh.list();
   } catch (Exception ex) {
     Logger.warn(CalendarReminderFactoryImpl.class, "getAll failed:" + ex.getMessage(), ex);
   }
   return returnValue;
 }
  /**
   * Return all the CalendarReminders of the system
   *
   * @return
   * @throws DotDataException
   */
  public List<CalendarReminder> getAll() {
    List<CalendarReminder> returnValue = new ArrayList<CalendarReminder>();
    try {
      String query =
          "from calendar_reminder in class com.dotmarketing.portlets.calendar.model.CalendarReminder";
      HibernateUtil dh = new HibernateUtil(CalendarReminder.class);
      dh.setQuery(query);
      returnValue = (List<CalendarReminder>) dh.list();
    } catch (Exception ex) {

    } finally {
      return returnValue;
    }
  }
 /**
  * Retrieve all the CalendarReminders before the specified date
  *
  * @param sendDate The Date used to retrieve the CalendarReminders
  * @return
  */
 public List<CalendarReminder> getCalendarReminderBefore(Date sendDate) {
   List<CalendarReminder> returnValue = new ArrayList<CalendarReminder>();
   try {
     String query =
         "from calendar_reminder in class com.dotmarketing.portlets.calendar.model.CalendarReminder where send_date <= ?";
     HibernateUtil dh = new HibernateUtil(CalendarReminder.class);
     dh.setQuery(query);
     dh.setParam(sendDate);
     returnValue = (List<CalendarReminder>) dh.list();
   } catch (Exception ex) {
     Logger.warn(
         CalendarReminderFactoryImpl.class, "getCalendareReminder failed:" + ex.getMessage(), ex);
   } finally {
     return returnValue;
   }
 }
  public List<File> findFiles(
      User user,
      boolean includeArchived,
      Map<String, Object> params,
      String hostId,
      String inode,
      String identifier,
      String parent,
      int offset,
      int limit,
      String orderBy)
      throws DotSecurityException, DotDataException {

    PaginatedArrayList<File> assets = new PaginatedArrayList<File>();
    List<Permissionable> toReturn = new ArrayList<Permissionable>();
    int internalLimit = 500;
    int internalOffset = 0;
    boolean done = false;

    StringBuilder conditionBuffer =
        new StringBuilder().append(" asset.inode=versioninfo.workingInode ");
    String condition =
        !includeArchived ? " and versioninfo.deleted = " + DbConnectionFactory.getDBFalse() : " ";
    conditionBuffer.append(condition);

    List<Object> paramValues = null;
    if (params != null && params.size() > 0) {
      conditionBuffer.append(" and (");
      paramValues = new ArrayList<Object>();
      int counter = 0;
      for (Map.Entry<String, Object> entry : params.entrySet()) {
        if (counter == 0) {
          if (entry.getValue() instanceof String) {
            if (entry.getKey().equalsIgnoreCase("inode")) {
              conditionBuffer
                  .append(" asset.")
                  .append(entry.getKey())
                  .append(" = '")
                  .append(entry.getValue())
                  .append("'");
            } else {
              conditionBuffer.append(" lower(asset.").append(entry.getKey()).append(") like ? ");
              paramValues.add("%" + ((String) entry.getValue()).toLowerCase() + "%");
            }
          } else {
            conditionBuffer
                .append(" asset.")
                .append(entry.getKey())
                .append(" = ")
                .append(entry.getValue());
          }
        } else {
          if (entry.getValue() instanceof String) {
            if (entry.getKey().equalsIgnoreCase("inode")) {
              conditionBuffer
                  .append(" OR asset.")
                  .append(entry.getKey())
                  .append(" = '")
                  .append(entry.getValue())
                  .append("'");
            } else {
              conditionBuffer.append(" OR lower(asset.").append(entry.getKey()).append(") like ? ");
              paramValues.add("%" + ((String) entry.getValue()).toLowerCase() + "%");
            }
          } else {
            conditionBuffer
                .append(" OR asset.")
                .append(entry.getKey())
                .append(" = ")
                .append(entry.getValue());
          }
        }

        counter += 1;
      }
      conditionBuffer.append(" ) ");
    }

    StringBuilder query = new StringBuilder();
    query
        .append("select asset from asset in class ")
        .append(File.class.getName())
        .append(", ")
        .append("inode in class ")
        .append(Inode.class.getName())
        .append(", identifier in class ")
        .append(Identifier.class.getName())
        .append(", versioninfo in class ")
        .append(FileAssetVersionInfo.class.getName());
    if (UtilMethods.isSet(parent)) {
      query
          .append(" ,tree in class ")
          .append(Tree.class.getName())
          .append(" where asset.inode=inode.inode ")
          .append("and asset.identifier = identifier.id and tree.parent = '")
          .append(parent)
          .append("' and tree.child=asset.inode");

    } else {
      query.append(" where asset.inode=inode.inode and asset.identifier = identifier.id");
    }
    query.append(" and versioninfo.identifier=identifier.id ");
    if (UtilMethods.isSet(hostId)) {
      query.append(" and identifier.hostId = '").append(hostId).append("'");
    }
    if (UtilMethods.isSet(inode)) {
      query.append(" and asset.inode = '").append(inode).append("'");
    }
    if (UtilMethods.isSet(identifier)) {
      query.append(" and asset.identifier = '").append(identifier).append("'");
    }
    if (!UtilMethods.isSet(orderBy)) {
      orderBy = "modDate desc";
    }

    List<File> resultList = new ArrayList<File>();
    HibernateUtil dh = new HibernateUtil(File.class);
    String type;
    int countLimit = 100;
    int size = 0;
    try {
      type = ((Inode) File.class.newInstance()).getType();
      query.append(" and asset.type='").append(type).append("' ");
      final String conditions = conditionBuffer.toString().trim();
      if (conditions.length() > 0) query.append(" and ").append(conditions);
      query.append(" order by asset.").append(orderBy);
      dh.setQuery(query.toString());

      if (paramValues != null && paramValues.size() > 0) {
        for (Object value : paramValues) {
          dh.setParam((String) value);
        }
      }

      while (!done) {
        dh.setFirstResult(internalOffset);
        dh.setMaxResults(internalLimit);
        resultList = dh.list();
        PermissionAPI permAPI = APILocator.getPermissionAPI();
        toReturn.addAll(
            permAPI.filterCollection(resultList, PermissionAPI.PERMISSION_READ, false, user));
        if (countLimit > 0 && toReturn.size() >= countLimit + offset) done = true;
        else if (resultList.size() < internalLimit) done = true;

        internalOffset += internalLimit;
      }

      if (offset > toReturn.size()) {
        size = 0;
      } else if (countLimit > 0) {
        int toIndex = offset + countLimit > toReturn.size() ? toReturn.size() : offset + countLimit;
        size = toReturn.subList(offset, toIndex).size();
      } else if (offset > 0) {
        size = toReturn.subList(offset, toReturn.size()).size();
      }
      assets.setTotalResults(size);

      if (limit != -1) {
        int from = offset < toReturn.size() ? offset : 0;
        int pageLimit = 0;
        for (int i = from; i < toReturn.size(); i++) {
          if (pageLimit < limit) {
            assets.add((File) toReturn.get(i));
            pageLimit += 1;
          } else {
            break;
          }
        }
      } else {
        for (int i = 0; i < toReturn.size(); i++) {
          assets.add((File) toReturn.get(i));
        }
      }

    } catch (Exception e) {

      Logger.error(FileFactoryImpl.class, "findFiles failed:" + e, e);
      throw new DotRuntimeException(e.toString());
    }

    return assets;
  }