/**
  * Get all reports of a category.
  *
  * @param categoryId the category id
  */
 public static List<Reporting> getReportingAsListByCategory(Long categoryId) {
   return findReporting
       .where()
       .eq("deleted", false)
       .eq("reportingCategory.id", categoryId)
       .findList();
 }
 /**
  * Get the children categories of a category.
  *
  * @param parentId the category id for which we need the children
  */
 public static List<ReportingCategory> getReportingCategoryAsListByParent(Long parentId) {
   return findReportingCategory
       .orderBy("order")
       .where()
       .eq("deleted", false)
       .eq("parent.id", parentId)
       .findList();
 }
 /** Get the root categories (meaning categories without parent). */
 public static List<ReportingCategory> getReportingCategoryRootsAsList() {
   return findReportingCategory
       .orderBy("order")
       .where()
       .eq("deleted", false)
       .isNull("parent")
       .findList();
 }
  /**
   * Search categories.
   *
   * @param key the key word
   */
  public static List<ReportingCategory> getReportingCategoryAsListByKeywords(String key) {

    String sql =
        "SELECT rc.id FROM `reporting_category` rc LEFT OUTER JOIN `i18n_messages` im ON im.key = rc.name WHERE rc.deleted = 0";

    sql +=
        " AND (im.language = '"
            + Http.Context.current().lang().code()
            + "' OR im.language IS NULL)";

    sql += " AND (rc.name LIKE \"" + key + "%\" OR im.value LIKE \"" + key + "%\") ";

    RawSql rawSql = RawSqlBuilder.parse(sql).columnMapping("rc.id", "id").create();

    return findReportingCategory.query().setRawSql(rawSql).findList();
  }
 /**
  * Get by id.
  *
  * @param id the reporting authorization id
  */
 public static ReportingAuthorization getReportingAuthorizationById(Long id) {
   return findReportingAuthorization.where().eq("id", id).findUnique();
 }
 /** Get the all reports. */
 public static List<Reporting> getReportingAsList() {
   return findReporting.where().eq("deleted", false).findList();
 }
 /** Get the custom reports. */
 public static List<Reporting> getReportingCustomAsList() {
   return findReporting.where().eq("deleted", false).eq("isStandard", false).findList();
 }
 /**
  * Get a report by template name.
  *
  * @param template the template name
  */
 public static Reporting getReportingByTemplate(String template) {
   return findReporting.where().eq("deleted", false).eq("template", template).findUnique();
 }
 /**
  * Get a report by id.
  *
  * @param id the report id
  */
 public static Reporting getReportingById(Long id) {
   return findReporting.where().eq("deleted", false).eq("id", id).findUnique();
 }