@Override
  public List<JournalArticle> findByReviewDate(
      long classNameId, Date reviewDateLT, Date reviewDateGT) {

    Timestamp reviewDateLT_TS = CalendarUtil.getTimestamp(reviewDateLT);
    Timestamp reviewDateGT_TS = CalendarUtil.getTimestamp(reviewDateGT);

    Session session = null;
    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_REVIEW_DATE);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(classNameId);
      qPos.add(reviewDateGT_TS);
      qPos.add(reviewDateLT_TS);

      return q.list(true);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
Exemple #2
0
  @Override
  public int countByG_SD_T(
      long groupId, Date startDateGT, Date startDateLT, boolean timeZoneSensitive, String[] types)
      throws SystemException {

    Timestamp startDateGT_TS = CalendarUtil.getTimestamp(startDateGT);
    Timestamp startDateLT_TS = CalendarUtil.getTimestamp(startDateLT);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_G_SD_T);

      sql = StringUtil.replace(sql, "[$TYPE$]", getTypes(types));

      SQLQuery q = session.createSQLQuery(sql);

      q.addEntity("CalEvent", CalEventImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(startDateGT_TS);
      qPos.add(startDateLT_TS);
      qPos.add(timeZoneSensitive);
      qPos.add(false);

      if ((types != null)
          && (types.length > 0)
          && ((types.length > 1) || Validator.isNotNull(types[0]))) {

        for (String type : types) {
          qPos.add(type);
        }
      }

      Iterator<Long> itr = q.iterate();

      if (itr.hasNext()) {
        Long count = itr.next();

        if (count != null) {
          return count.intValue();
        }
      }

      return 0;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
Exemple #3
0
  @Override
  public List<CalEvent> findByG_SD_T(
      long groupId,
      Date startDateGT,
      Date startDateLT,
      boolean timeZoneSensitive,
      String[] types,
      int start,
      int end)
      throws SystemException {

    Timestamp startDateGT_TS = CalendarUtil.getTimestamp(startDateGT);
    Timestamp startDateLT_TS = CalendarUtil.getTimestamp(startDateLT);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_G_SD_T);

      sql = StringUtil.replace(sql, "[$TYPE$]", getTypes(types));

      SQLQuery q = session.createSQLQuery(sql);

      q.addEntity("CalEvent", CalEventImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(groupId);
      qPos.add(startDateGT_TS);
      qPos.add(startDateLT_TS);
      qPos.add(timeZoneSensitive);
      qPos.add(false);

      if ((types != null)
          && (types.length > 0)
          && ((types.length > 1) || Validator.isNotNull(types[0]))) {

        for (String type : types) {
          qPos.add(type);
        }
      }

      return (List<CalEvent>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  public List<JIRAAction> findByCD_P(Date createDate, long projectId, int start, int end)
      throws SystemException {

    Timestamp createDate_TS = CalendarUtil.getTimestamp(createDate);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_CD_P);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity("jiraaction", JIRAActionImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(projectId);
      qPos.add(createDate_TS);

      return (List<JIRAAction>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  @Override
  public List<CalEvent> findByFutureReminders() {
    Calendar calendar = Calendar.getInstance();

    calendar.add(Calendar.HOUR, -24);

    Timestamp calendar_TS = CalendarUtil.getTimestamp(calendar.getTime());

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_FUTURE_REMINDERS);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity("CalEvent", CalEventImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(CalEventConstants.REMIND_BY_NONE);
      qPos.add(calendar_TS);
      qPos.add(calendar_TS);

      return q.list(true);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  @Override
  public List<JournalArticle> findByExpirationDate(
      long classNameId, Date expirationDateLT, QueryDefinition<JournalArticle> queryDefinition) {

    Timestamp expirationDateLT_TS = CalendarUtil.getTimestamp(expirationDateLT);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_EXPIRATION_DATE, queryDefinition);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(classNameId);
      qPos.add(queryDefinition.getStatus());
      qPos.add(expirationDateLT_TS);

      return q.list(true);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  @Override
  public int countByOrganizationIds(
      List<Long> organizationIds, Date displayDate, QueryDefinition<BlogsEntry> queryDefinition) {

    Timestamp displayDate_TS = CalendarUtil.getTimestamp(displayDate);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_ORGANIZATION_IDS);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        if (queryDefinition.isExcludeStatus()) {
          sql = CustomSQLUtil.appendCriteria(sql, "AND (BlogsEntry.status != ?)");
        } else {
          sql = CustomSQLUtil.appendCriteria(sql, "AND (BlogsEntry.status = ?)");
        }
      }

      sql = StringUtil.replace(sql, "[$ORGANIZATION_ID$]", getOrganizationIds(organizationIds));

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      for (int i = 0; i < organizationIds.size(); i++) {
        Long organizationId = organizationIds.get(i);

        qPos.add(organizationId);
      }

      qPos.add(displayDate_TS);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        qPos.add(queryDefinition.getStatus());
      }

      Iterator<Long> itr = q.iterate();

      if (itr.hasNext()) {
        Long count = itr.next();

        if (count != null) {
          return count.intValue();
        }
      }

      return 0;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  @Override
  public List<BlogsEntry> findByOrganizationIds(
      List<Long> organizationIds, Date displayDate, QueryDefinition<BlogsEntry> queryDefinition) {

    Timestamp displayDate_TS = CalendarUtil.getTimestamp(displayDate);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_ORGANIZATION_IDS);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        if (queryDefinition.isExcludeStatus()) {
          sql = CustomSQLUtil.appendCriteria(sql, "AND (BlogsEntry.status != ?)");
        } else {
          sql = CustomSQLUtil.appendCriteria(sql, "AND (BlogsEntry.status = ?)");
        }
      }

      sql = StringUtil.replace(sql, "[$ORGANIZATION_ID$]", getOrganizationIds(organizationIds));
      sql = CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator());

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity("BlogsEntry", BlogsEntryImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      for (int i = 0; i < organizationIds.size(); i++) {
        Long organizationId = organizationIds.get(i);

        qPos.add(organizationId);
      }

      qPos.add(displayDate_TS);

      if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) {
        qPos.add(queryDefinition.getStatus());
      }

      return (List<BlogsEntry>)
          QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd());
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  @Override
  public JournalArticle findByR_D(long resourcePrimKey, Date displayDate)
      throws NoSuchArticleException {

    Timestamp displayDate_TS = CalendarUtil.getTimestamp(displayDate);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_R_D);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(resourcePrimKey);
      qPos.add(displayDate_TS);

      List<JournalArticle> articles = q.list();

      if (!articles.isEmpty()) {
        return articles.get(0);
      }
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }

    StringBundler sb = new StringBundler(6);

    sb.append("No JournalArticle exists with the key ");
    sb.append("{resourcePrimKey=");
    sb.append(resourcePrimKey);
    sb.append(", displayDate=");
    sb.append(displayDate);
    sb.append("}");

    throw new NoSuchArticleException(sb.toString());
  }
  public int countByCD_P(Date createDate, long projectId) throws SystemException {

    Timestamp createDate_TS = CalendarUtil.getTimestamp(createDate);

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(COUNT_BY_CD_P);

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(projectId);
      qPos.add(createDate_TS);

      Iterator<Long> itr = q.iterate();

      if (itr.hasNext()) {
        Long count = itr.next();

        if (count != null) {
          return count.intValue();
        }
      }

      return 0;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  protected List<JournalArticle> doFindByC_G_F_C_A_V_T_D_C_S_T_D_R(
      long companyId,
      long groupId,
      List<Long> folderIds,
      long classNameId,
      String[] articleIds,
      Double version,
      String[] titles,
      String[] descriptions,
      String[] contents,
      String[] ddmStructureKeys,
      String[] ddmTemplateKeys,
      Date displayDateGT,
      Date displayDateLT,
      Date reviewDate,
      boolean andOperator,
      QueryDefinition<JournalArticle> queryDefinition,
      boolean inlineSQLHelper) {

    articleIds = CustomSQLUtil.keywords(articleIds, false);
    titles = CustomSQLUtil.keywords(titles);
    descriptions = CustomSQLUtil.keywords(descriptions, false);
    contents = CustomSQLUtil.keywords(contents, false);
    ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
    ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
    Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
    Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
    Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);

    Session session = null;

    try {
      session = openSession();

      String sql =
          CustomSQLUtil.get(FIND_BY_C_G_F_C_A_V_T_D_C_S_T_D_R, queryDefinition, "JournalArticle");

      sql = replaceStatusJoin(sql, queryDefinition);

      if (groupId <= 0) {
        sql = StringUtil.replace(sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
      }

      if (folderIds.isEmpty()) {
        sql = StringUtil.replace(sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
      } else {
        sql =
            StringUtil.replace(
                sql, "[$FOLDER_ID$]", getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
      }

      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.articleId", StringPool.LIKE, false, articleIds);

      if ((version == null) || (version <= 0)) {
        sql =
            StringUtil.replace(
                sql, "(JournalArticle.version = ?) [$AND_OR_CONNECTOR$]", StringPool.BLANK);
      }

      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(JournalArticle.title)", StringPool.LIKE, false, titles);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.description", StringPool.LIKE, false, descriptions);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "JournalArticle.content", StringPool.LIKE, false, contents);

      sql = replaceStructureTemplate(sql, ddmStructureKeys, ddmTemplateKeys);

      if (!isNullArray(ddmStructureKeys)) {
        sql =
            CustomSQLUtil.replaceKeywords(
                sql, "JournalArticle.DDMStructureKey", StringPool.LIKE, false, ddmStructureKeys);
      }

      if (!isNullArray(ddmTemplateKeys)) {
        sql =
            CustomSQLUtil.replaceKeywords(
                sql, "JournalArticle.DDMTemplateKey", StringPool.LIKE, false, ddmTemplateKeys);
      }

      sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
      sql =
          CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator("JournalArticle"));

      if (inlineSQLHelper) {
        sql =
            InlineSQLHelperUtil.replacePermissionCheck(
                sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId);

        sql = StringUtil.replace(sql, "(companyId", "(JournalArticle.companyId");
      }

      SQLQuery q = session.createSynchronizedSQLQuery(sql);

      q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);

      QueryPos qPos = QueryPos.getInstance(q);

      qPos.add(companyId);

      if (groupId > 0) {
        qPos.add(groupId);
      }

      for (long folderId : folderIds) {
        qPos.add(folderId);
      }

      qPos.add(classNameId);
      qPos.add(queryDefinition.getStatus());

      if (!isNullArray(ddmStructureKeys)) {
        qPos.add(ddmStructureKeys, 2);
      }

      if (!isNullArray(ddmTemplateKeys)) {
        qPos.add(ddmTemplateKeys, 2);
      }

      qPos.add(articleIds, 2);

      if ((version != null) && (version > 0)) {
        qPos.add(version);
      }

      qPos.add(titles, 2);
      qPos.add(descriptions, 2);
      qPos.add(contents, 2);
      qPos.add(displayDateGT_TS);
      qPos.add(displayDateGT_TS);
      qPos.add(displayDateLT_TS);
      qPos.add(displayDateLT_TS);
      qPos.add(reviewDate_TS);
      qPos.add(reviewDate_TS);

      return (List<JournalArticle>)
          QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd());
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }