@Override public List<MBThread> findByS_G_U(long groupId, long userId, QueryDefinition queryDefinition) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_S_G_U); sql = updateSQL(sql, queryDefinition); SQLQuery q = session.createSQLQuery(sql); q.addEntity("MBThread", MBThreadImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(PortalUtil.getClassNameId(MBThread.class.getName())); qPos.add(groupId); qPos.add(userId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } return (List<MBThread>) QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Override public int countByG_U_C_A( long groupId, long userId, long[] categoryIds, boolean anonymous, QueryDefinition queryDefinition) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_G_U_C); if (ArrayUtil.isEmpty(categoryIds)) { sql = StringUtil.replace(sql, "(MBThread.categoryId = ?) AND", StringPool.BLANK); } else { sql = StringUtil.replace( sql, "MBThread.categoryId = ?", "MBThread.categoryId = " + StringUtil.merge(categoryIds, " OR MBThread.categoryId = ")); } sql = updateSQL(sql, queryDefinition); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(userId); qPos.add(anonymous); 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); } }
@Test public void testCountByG_U_F_M_StatusInTrash() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true); Assert.assertEquals(2, doCountBy_G_U_F_M(0, null, queryDefinition)); }
@Test public void testCountByG_U_F_M_StatusInTrashByMimeType() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true); Assert.assertEquals(1, doCountBy_G_U_F_M(0, ContentTypes.TEXT_PLAIN, queryDefinition)); }
@Test public void testCountByG_U_F_M_StatusApproved() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED); Assert.assertEquals(2, doCountBy_G_U_F_M(0, null, queryDefinition)); }
@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); } }
@Test public void testCountByG_U_F_M_StatusInTrashByUserId() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true); Assert.assertEquals( 1, doCountBy_G_U_F_M(_defaultRepositoryFolder.getUserId(), null, queryDefinition)); }
@Test public void testCountByG_U_R_F_M_StatusAny_NewRepository() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_ANY); Assert.assertEquals(3, doCountBy_G_U_R_F_M_NewRepository(0, null, queryDefinition)); }
protected List<MBThread> doFindByS_G_U_C( long groupId, long userId, long[] categoryIds, QueryDefinition queryDefinition, boolean inlineSQLHelper) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_S_G_U_C); if (ArrayUtil.isEmpty(categoryIds)) { sql = StringUtil.replace(sql, "(MBThread.categoryId = ?) AND", StringPool.BLANK); } else { sql = StringUtil.replace( sql, "MBThread.categoryId = ?", "MBThread.categoryId = " + StringUtil.merge(categoryIds, " OR MBThread.categoryId = ")); } sql = updateSQL(sql, queryDefinition); if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck( sql, MBMessage.class.getName(), "MBThread.rootMessageId", groupId); } SQLQuery q = session.createSQLQuery(sql); q.addEntity("MBThread", MBThreadImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(PortalUtil.getClassNameId(MBThread.class.getName())); qPos.add(groupId); qPos.add(userId); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } return (List<MBThread>) QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Test public void testCountByG_U_R_F_M_StatusAnyByMimeType_NewRepository() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_ANY); Assert.assertEquals( 2, doCountBy_G_U_R_F_M_NewRepository(0, ContentTypes.TEXT_PLAIN, queryDefinition)); }
@Test public void testCountByG_U_F_M_StatusApprovedByMimeType_EmptyRepositories() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED); Assert.assertEquals( 2, doCountBy_G_U_R_F_M_EmptyRepositories(0, ContentTypes.TEXT_PLAIN, queryDefinition)); }
@Override public int getGroupThreadsCount(long groupId, QueryDefinition<MBThread> queryDefinition) { if (queryDefinition.isExcludeStatus()) { return mbThreadPersistence.countByG_NotC_NotS( groupId, MBCategoryConstants.DISCUSSION_CATEGORY_ID, queryDefinition.getStatus()); } else { return mbThreadPersistence.countByG_NotC_S( groupId, MBCategoryConstants.DISCUSSION_CATEGORY_ID, queryDefinition.getStatus()); } }
protected String updateSQL(String sql, QueryDefinition queryDefinition) { if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) { return sql; } if (queryDefinition.isExcludeStatus()) { return CustomSQLUtil.appendCriteria(sql, "AND (MBThread.status != ?)"); } return CustomSQLUtil.appendCriteria(sql, "AND (MBThread.status = ?)"); }
@Test public void testCountByG_U_R_F_M_StatusAnyByUserId_EmptyRepositories() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_ANY); Assert.assertEquals( 4, doCountBy_G_U_R_F_M_EmptyRepositories( _defaultRepositoryFolder.getUserId(), null, queryDefinition)); }
@Test public void testCountByG_U_F_M_StatusApprovedByUserIdAndMimeType() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED); Assert.assertEquals( 0, doCountBy_G_U_F_M( _defaultRepositoryFolder.getUserId(), ContentTypes.TEXT_PLAIN, queryDefinition)); }
@Override public int countByG_U_LPD( long groupId, long userId, Date lastPostDate, QueryDefinition queryDefinition) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_G_U_LPD); if (userId <= 0) { sql = StringUtil.replace(sql, _INNER_JOIN_SQL, StringPool.BLANK); sql = StringUtil.replace(sql, _USER_ID_SQL, StringPool.BLANK); } sql = updateSQL(sql, queryDefinition); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(lastPostDate); if (userId > 0) { qPos.add(userId); } 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); } }
@Test public void testCountByG_U_R_F_M_StatusApprovedByUserId_NewRepository() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED); Assert.assertEquals( 1, doCountBy_G_U_R_F_M_NewRepository( _defaultRepositoryFolder.getUserId(), null, queryDefinition)); }
@Test public void testFindByG_U_F_M_StatusInTrash_EmptyRepositories() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true); List<DLFileEntry> dlFileEntries = doFindBy_G_U_R_F_M_EmptyRepositories(0, ContentTypes.TEXT_PLAIN, queryDefinition); Assert.assertEquals(2, dlFileEntries.size()); }
@Test public void testCountByG_U_R_F_M_StatusInTrashByUserIdAndMimeType_NewRepository() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true); Assert.assertEquals( 0, doCountBy_G_U_R_F_M_NewRepository( _defaultRepositoryFolder.getUserId(), ContentTypes.TEXT_PLAIN, queryDefinition)); }
@Test public void testFindByG_U_F_M_StatusAny_BothRepositories() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_ANY); List<DLFileEntry> dlFileEntries = doFindBy_G_U_R_F_M_BothRepositories( _defaultRepositoryFolder.getUserId(), ContentTypes.TEXT_PLAIN, queryDefinition); Assert.assertEquals(2, dlFileEntries.size()); }
@Test public void testFindByG_U_F_M_StatusApproved_EmptyRepositories() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED); List<DLFileEntry> dlFileEntries = doFindBy_G_U_R_F_M_EmptyRepositories( _defaultRepositoryFolder.getUserId(), null, queryDefinition); Assert.assertEquals(2, dlFileEntries.size()); }
@Override public List<MBThread> findByG_U_C_A( long groupId, long userId, long[] categoryIds, boolean anonymous, QueryDefinition queryDefinition) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_G_U_C_A); if (ArrayUtil.isEmpty(categoryIds)) { sql = StringUtil.replace(sql, "(MBThread.categoryId = ?) AND", StringPool.BLANK); } else { sql = StringUtil.replace( sql, "MBThread.categoryId = ?", "MBThread.categoryId = " + StringUtil.merge(categoryIds, " OR MBThread.categoryId = ")); } sql = updateSQL(sql, queryDefinition); SQLQuery q = session.createSQLQuery(sql); q.addEntity("MBThread", MBThreadImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(userId); qPos.add(anonymous); if (queryDefinition.getStatus() != WorkflowConstants.STATUS_ANY) { qPos.add(queryDefinition.getStatus()); } return (List<MBThread>) QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
protected List<JournalArticle> doFindByG_F( long groupId, List<Long> folderIds, QueryDefinition<JournalArticle> queryDefinition, boolean inlineSQLHelper) { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_G_F, queryDefinition, "JournalArticle"); sql = replaceStatusJoin(sql, queryDefinition); sql = CustomSQLUtil.replaceOrderBy(sql, queryDefinition.getOrderByComparator("JournalArticle")); if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck( sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId); } sql = StringUtil.replace( sql, "[$FOLDER_ID$]", getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME)); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addEntity(JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(queryDefinition.getStatus()); for (int i = 0; i < folderIds.size(); i++) { Long folderId = folderIds.get(i); qPos.add(folderId); } return (List<JournalArticle>) QueryUtil.list(q, getDialect(), queryDefinition.getStart(), queryDefinition.getEnd()); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Test public void testFindByG_U_F_M_StatusInTrash() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true); List<DLFileEntry> dlFileEntries = doFindBy_G_U_F_M(0, ContentTypes.TEXT_PLAIN, queryDefinition); Assert.assertEquals(1, dlFileEntries.size()); DLFileEntry dlFileEntry = dlFileEntries.get(0); Assert.assertEquals("FE1.txt", dlFileEntry.getTitle()); }
@Test public void testFindByG_U_F_M_StatusApproved_NewRepository() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED); List<DLFileEntry> dlFileEntries = doFindBy_G_U_R_F_M_NewRepository(_newRepositoryFolder.getUserId(), null, queryDefinition); Assert.assertEquals(1, dlFileEntries.size()); DLFileEntry dlFileEntry = dlFileEntries.get(0); Assert.assertEquals("FE2.pdf-NewRepository", dlFileEntry.getTitle()); }
@Test public void testFindByG_U_F_M_StatusAny_NewRepository() throws Exception { QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(); queryDefinition.setStatus(WorkflowConstants.STATUS_ANY); List<DLFileEntry> dlFileEntries = doFindBy_G_U_R_F_M_NewRepository( _newRepositoryFolder.getUserId(), ContentTypes.TEXT_PLAIN, queryDefinition); Assert.assertEquals(1, dlFileEntries.size()); DLFileEntry dlFileEntry = dlFileEntries.get(0); Assert.assertEquals("FE3.txt", dlFileEntry.getDescription()); }
@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); } }
protected String replaceExcludeStatus(String sql, QueryDefinition<?> queryDefinition) { if (queryDefinition.isExcludeStatus()) { sql = StringUtil.replace(sql, ".status = ?)", ".status != ?)"); } return sql; }
@Override public int countByG_U_A( long groupId, long userId, boolean anonymous, QueryDefinition queryDefinition) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_G_U_A); sql = updateSQL(sql, queryDefinition); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(userId); qPos.add(anonymous); 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); } }
protected int doCountByG_F( long groupId, List<Long> folderIds, QueryDefinition<JournalArticle> queryDefinition, boolean inlineSQLHelper) { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_G_F, queryDefinition, "JournalArticle"); sql = replaceStatusJoin(sql, queryDefinition); if (inlineSQLHelper) { sql = InlineSQLHelperUtil.replacePermissionCheck( sql, JournalArticle.class.getName(), "JournalArticle.resourcePrimKey", groupId); } sql = StringUtil.replace( sql, "[$FOLDER_ID$]", getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME)); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(queryDefinition.getStatus()); for (int i = 0; i < folderIds.size(); i++) { Long folderId = folderIds.get(i); qPos.add(folderId); } 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); } }