001
014
015 package com.liferay.portlet.journal.service.persistence;
016
017 import com.liferay.portal.kernel.dao.orm.QueryDefinition;
018 import com.liferay.portal.kernel.dao.orm.QueryPos;
019 import com.liferay.portal.kernel.dao.orm.QueryUtil;
020 import com.liferay.portal.kernel.dao.orm.SQLQuery;
021 import com.liferay.portal.kernel.dao.orm.Session;
022 import com.liferay.portal.kernel.dao.orm.Type;
023 import com.liferay.portal.kernel.exception.SystemException;
024 import com.liferay.portal.kernel.util.ArrayUtil;
025 import com.liferay.portal.kernel.util.CalendarUtil;
026 import com.liferay.portal.kernel.util.OrderByComparator;
027 import com.liferay.portal.kernel.util.StringBundler;
028 import com.liferay.portal.kernel.util.StringPool;
029 import com.liferay.portal.kernel.util.StringUtil;
030 import com.liferay.portal.kernel.util.Validator;
031 import com.liferay.portal.kernel.workflow.WorkflowConstants;
032 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
033 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
034 import com.liferay.portal.util.PropsValues;
035 import com.liferay.portlet.journal.NoSuchArticleException;
036 import com.liferay.portlet.journal.model.JournalArticle;
037 import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
038 import com.liferay.util.dao.orm.CustomSQLUtil;
039
040 import java.sql.Timestamp;
041
042 import java.util.Date;
043 import java.util.Iterator;
044 import java.util.List;
045
046
051 public class JournalArticleFinderImpl
052 extends BasePersistenceImpl<JournalArticle>
053 implements JournalArticleFinder {
054
055 public static final String COUNT_BY_G_F =
056 JournalArticleFinder.class.getName() + ".countByG_F";
057
058 public static final String COUNT_BY_G_C_S =
059 JournalArticleFinder.class.getName() + ".countByG_C_S";
060
061 public static final String COUNT_BY_G_U_F_C =
062 JournalArticleFinder.class.getName() + ".countByG_U_F_C";
063
064 public static final String COUNT_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R =
065 JournalArticleFinder.class.getName() +
066 ".countByC_G_F_C_A_V_T_D_C_T_S_T_D_R";
067
068 public static final String FIND_BY_EXPIRATION_DATE =
069 JournalArticleFinder.class.getName() + ".findByExpirationDate";
070
071 public static final String FIND_BY_REVIEW_DATE =
072 JournalArticleFinder.class.getName() + ".findByReviewDate";
073
074 public static final String FIND_BY_R_D =
075 JournalArticleFinder.class.getName() + ".findByR_D";
076
077 public static final String FIND_BY_G_F =
078 JournalArticleFinder.class.getName() + ".findByG_F";
079
080 public static final String FIND_BY_G_C_S =
081 JournalArticleFinder.class.getName() + ".findByG_C_S";
082
083 public static final String FIND_BY_G_U_F_C =
084 JournalArticleFinder.class.getName() + ".findByG_U_F_C";
085
086 public static final String FIND_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R =
087 JournalArticleFinder.class.getName() +
088 ".findByC_G_F_C_A_V_T_D_C_T_S_T_D_R";
089
090 @Override
091 public int countByKeywords(
092 long companyId, long groupId, List<Long> folderIds,
093 long classNameId, String keywords, Double version, String type,
094 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
095 Date displayDateLT, int status, Date reviewDate)
096 throws SystemException {
097
098 String[] articleIds = null;
099 String[] titles = null;
100 String[] descriptions = null;
101 String[] contents = null;
102 String[] ddmStructureKeys = CustomSQLUtil.keywords(
103 ddmStructureKey, false);
104 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
105 ddmTemplateKey, false);
106 boolean andOperator = false;
107
108 if (Validator.isNotNull(keywords)) {
109 articleIds = CustomSQLUtil.keywords(keywords, false);
110 titles = CustomSQLUtil.keywords(keywords);
111 descriptions = CustomSQLUtil.keywords(keywords, false);
112
113 if (PropsValues.JOURNAL_ARTICLE_DATABASE_KEYWORD_SEARCH_CONTENT) {
114 contents = CustomSQLUtil.keywords(keywords, false);
115 }
116 }
117 else {
118 andOperator = true;
119 }
120
121 QueryDefinition queryDefinition = new QueryDefinition(status);
122
123 return doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
124 companyId, groupId, folderIds, classNameId, articleIds, version,
125 titles, descriptions, contents, type, ddmStructureKeys,
126 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
127 andOperator, queryDefinition, false);
128 }
129
130 @Override
131 public int countByG_F(
132 long groupId, List<Long> folderIds, QueryDefinition queryDefinition)
133 throws SystemException {
134
135 return doCountByG_F(groupId, folderIds, queryDefinition, false);
136 }
137
138 @Override
139 public int countByG_F_C(
140 long groupId, List<Long> folderIds, long classNameId,
141 QueryDefinition queryDefinition)
142 throws SystemException {
143
144 return doCountByG_F_C(
145 groupId, folderIds, classNameId, queryDefinition, false);
146 }
147
148 @Override
149 public int countByG_C_S(
150 long groupId, long classNameId, String ddmStructureKey,
151 QueryDefinition queryDefinition)
152 throws SystemException {
153
154 return doCountByG_C_S(
155 groupId, classNameId, ddmStructureKey, queryDefinition, false);
156 }
157
158 @Override
159 public int countByG_C_S(
160 long groupId, long classNameId, String[] ddmStructureKeys,
161 QueryDefinition queryDefinition)
162 throws SystemException {
163
164 return doCountByG_C_S(
165 groupId, classNameId, ddmStructureKeys, queryDefinition, false);
166 }
167
168
172 @Deprecated
173 @Override
174 public int countByG_U_F_C(
175 long groupId, long userId, List<Long> folderIds, long classNameId,
176 QueryDefinition queryDefinition)
177 throws SystemException {
178
179 return countByG_F_C(groupId, folderIds, classNameId, queryDefinition);
180 }
181
182 @Override
183 public int countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
184 long companyId, long groupId, List<Long> folderIds,
185 long classNameId, String articleId, Double version, String title,
186 String description, String content, String type,
187 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
188 Date displayDateLT, Date reviewDate, boolean andOperator,
189 QueryDefinition queryDefinition)
190 throws SystemException {
191
192 String[] ddmStructureKeys = CustomSQLUtil.keywords(
193 ddmStructureKey, false);
194 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
195 ddmTemplateKey, false);
196
197 return countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
198 companyId, groupId, folderIds, classNameId, articleId, version,
199 title, description, content, type, ddmStructureKeys,
200 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
201 andOperator, queryDefinition);
202 }
203
204 @Override
205 public int countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
206 long companyId, long groupId, List<Long> folderIds,
207 long classNameId, String articleId, Double version, String title,
208 String description, String content, String type,
209 String[] ddmStructureKeys, String[] ddmTemplateKeys,
210 Date displayDateGT, Date displayDateLT, Date reviewDate,
211 boolean andOperator, QueryDefinition queryDefinition)
212 throws SystemException {
213
214 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
215 String[] titles = CustomSQLUtil.keywords(title);
216 String[] descriptions = CustomSQLUtil.keywords(description, false);
217 String[] contents = CustomSQLUtil.keywords(content, false);
218
219 return countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
220 companyId, groupId, folderIds, classNameId, articleIds, version,
221 titles, descriptions, contents, type, ddmStructureKeys,
222 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
223 andOperator, queryDefinition);
224 }
225
226 @Override
227 public int countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
228 long companyId, long groupId, List<Long> folderIds,
229 long classNameId, String[] articleIds, Double version,
230 String[] titles, String[] descriptions, String[] contents,
231 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
232 Date displayDateGT, Date displayDateLT, Date reviewDate,
233 boolean andOperator, QueryDefinition queryDefinition)
234 throws SystemException {
235
236 return doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
237 companyId, groupId, folderIds, classNameId, articleIds, version,
238 titles, descriptions, contents, type, ddmStructureKeys,
239 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
240 andOperator, queryDefinition, false);
241 }
242
243 @Override
244 public int filterCountByKeywords(
245 long companyId, long groupId, List<Long> folderIds,
246 long classNameId, String keywords, Double version, String type,
247 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
248 Date displayDateLT, int status, Date reviewDate)
249 throws SystemException {
250
251 String[] articleIds = null;
252 String[] titles = null;
253 String[] descriptions = null;
254 String[] contents = null;
255 String[] ddmStructureKeys = CustomSQLUtil.keywords(
256 ddmStructureKey, false);
257 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
258 ddmTemplateKey, false);
259 boolean andOperator = false;
260
261 if (Validator.isNotNull(keywords)) {
262 articleIds = CustomSQLUtil.keywords(keywords, false);
263 titles = CustomSQLUtil.keywords(keywords);
264 descriptions = CustomSQLUtil.keywords(keywords, false);
265
266 if (PropsValues.JOURNAL_ARTICLE_DATABASE_KEYWORD_SEARCH_CONTENT) {
267 contents = CustomSQLUtil.keywords(keywords, false);
268 }
269 }
270 else {
271 andOperator = true;
272 }
273
274 QueryDefinition queryDefinition = new QueryDefinition(status);
275
276 return doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
277 companyId, groupId, folderIds, classNameId, articleIds, version,
278 titles, descriptions, contents, type, ddmStructureKeys,
279 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
280 andOperator, queryDefinition, true);
281 }
282
283 @Override
284 public int filterCountByG_F(
285 long groupId, List<Long> folderIds, QueryDefinition queryDefinition)
286 throws SystemException {
287
288 return doCountByG_F(groupId, folderIds, queryDefinition, true);
289 }
290
291 @Override
292 public int filterCountByG_F_C(
293 long groupId, List<Long> folderIds, long classNameId,
294 QueryDefinition queryDefinition)
295 throws SystemException {
296
297 return doCountByG_F_C(
298 groupId, folderIds, classNameId, queryDefinition, true);
299 }
300
301 @Override
302 public int filterCountByG_C_S(
303 long groupId, long classNameId, String ddmStructureKey,
304 QueryDefinition queryDefinition)
305 throws SystemException {
306
307 return doCountByG_C_S(
308 groupId, classNameId, ddmStructureKey, queryDefinition, true);
309 }
310
311
315 @Deprecated
316 @Override
317 public int filterCountByG_U_F_C(
318 long groupId, long userId, List<Long> folderIds, long classNameId,
319 QueryDefinition queryDefinition)
320 throws SystemException {
321
322 return filterCountByG_F_C(
323 groupId, folderIds, classNameId, queryDefinition);
324 }
325
326 @Override
327 public int filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
328 long companyId, long groupId, List<Long> folderIds,
329 long classNameId, String articleId, Double version, String title,
330 String description, String content, String type,
331 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
332 Date displayDateLT, Date reviewDate, boolean andOperator,
333 QueryDefinition queryDefinition)
334 throws SystemException {
335
336 String[] ddmStructureKeys = CustomSQLUtil.keywords(
337 ddmStructureKey, false);
338 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
339 ddmTemplateKey, false);
340
341 return filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
342 companyId, groupId, folderIds, classNameId, articleId, version,
343 title, description, content, type, ddmStructureKeys,
344 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
345 andOperator, queryDefinition);
346 }
347
348 @Override
349 public int filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
350 long companyId, long groupId, List<Long> folderIds,
351 long classNameId, String articleId, Double version, String title,
352 String description, String content, String type,
353 String[] ddmStructureKeys, String[] ddmTemplateKeys,
354 Date displayDateGT, Date displayDateLT, Date reviewDate,
355 boolean andOperator, QueryDefinition queryDefinition)
356 throws SystemException {
357
358 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
359 String[] titles = CustomSQLUtil.keywords(title);
360 String[] descriptions = CustomSQLUtil.keywords(description, false);
361 String[] contents = CustomSQLUtil.keywords(content, false);
362
363 return filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
364 companyId, groupId, folderIds, classNameId, articleIds, version,
365 titles, descriptions, contents, type, ddmStructureKeys,
366 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
367 andOperator, queryDefinition);
368 }
369
370 @Override
371 public int filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
372 long companyId, long groupId, List<Long> folderIds,
373 long classNameId, String[] articleIds, Double version,
374 String[] titles, String[] descriptions, String[] contents,
375 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
376 Date displayDateGT, Date displayDateLT, Date reviewDate,
377 boolean andOperator, QueryDefinition queryDefinition)
378 throws SystemException {
379
380 return doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
381 companyId, groupId, folderIds, classNameId, articleIds, version,
382 titles, descriptions, contents, type, ddmStructureKeys,
383 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
384 andOperator, queryDefinition, true);
385 }
386
387 @Override
388 public List<JournalArticle> filterFindByKeywords(
389 long companyId, long groupId, List<Long> folderIds,
390 long classNameId, String keywords, Double version, String type,
391 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
392 Date displayDateLT, int status, Date reviewDate, int start, int end,
393 OrderByComparator orderByComparator)
394 throws SystemException {
395
396 String[] articleIds = null;
397 String[] titles = null;
398 String[] descriptions = null;
399 String[] contents = null;
400 String[] ddmStructureKeys = CustomSQLUtil.keywords(
401 ddmStructureKey, false);
402 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
403 ddmTemplateKey, false);
404 boolean andOperator = false;
405
406 if (Validator.isNotNull(keywords)) {
407 articleIds = CustomSQLUtil.keywords(keywords, false);
408 titles = CustomSQLUtil.keywords(keywords);
409 descriptions = CustomSQLUtil.keywords(keywords, false);
410
411 if (PropsValues.JOURNAL_ARTICLE_DATABASE_KEYWORD_SEARCH_CONTENT) {
412 contents = CustomSQLUtil.keywords(keywords, false);
413 }
414 }
415 else {
416 andOperator = true;
417 }
418
419 QueryDefinition queryDefinition = new QueryDefinition(
420 status, start, end, orderByComparator);
421
422 return doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
423 companyId, groupId, folderIds, classNameId, articleIds, version,
424 titles, descriptions, contents, type, ddmStructureKeys,
425 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
426 andOperator, queryDefinition, true);
427 }
428
429 @Override
430 public List<JournalArticle> filterFindByG_F(
431 long groupId, List<Long> folderIds, QueryDefinition queryDefinition)
432 throws SystemException {
433
434 return doFindByG_F(groupId, folderIds, queryDefinition, true);
435 }
436
437 @Override
438 public List<JournalArticle> filterFindByG_F_C(
439 long groupId, List<Long> folderIds, long classNameId,
440 QueryDefinition queryDefinition)
441 throws SystemException {
442
443 return doFindByG_F_C(
444 groupId, folderIds, classNameId, queryDefinition, true);
445 }
446
447 @Override
448 public List<JournalArticle> filterFindByG_C_S(
449 long groupId, long classNameId, String ddmStructureKey,
450 QueryDefinition queryDefinition)
451 throws SystemException {
452
453 return doFindByG_C_S(
454 groupId, classNameId, ddmStructureKey, queryDefinition, true);
455 }
456
457
461 @Deprecated
462 @Override
463 public List<JournalArticle> filterFindByG_U_F_C(
464 long groupId, long userId, List<Long> folderIds, long classNameId,
465 QueryDefinition queryDefinition)
466 throws SystemException {
467
468 return filterFindByG_F_C(
469 groupId, folderIds, classNameId, queryDefinition);
470 }
471
472 @Override
473 public List<JournalArticle> filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
474 long companyId, long groupId, List<Long> folderIds,
475 long classNameId, String articleId, Double version, String title,
476 String description, String content, String type,
477 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
478 Date displayDateLT, Date reviewDate, boolean andOperator,
479 QueryDefinition queryDefinition)
480 throws SystemException {
481
482 String[] ddmStructureKeys = CustomSQLUtil.keywords(
483 ddmStructureKey, false);
484 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
485 ddmTemplateKey, false);
486
487 return filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
488 companyId, groupId, folderIds, classNameId, articleId, version,
489 title, description, content, type, ddmStructureKeys,
490 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
491 andOperator, queryDefinition);
492 }
493
494 @Override
495 public List<JournalArticle> filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
496 long companyId, long groupId, List<Long> folderIds,
497 long classNameId, String articleId, Double version, String title,
498 String description, String content, String type,
499 String[] ddmStructureKeys, String[] ddmTemplateKeys,
500 Date displayDateGT, Date displayDateLT, Date reviewDate,
501 boolean andOperator, QueryDefinition queryDefinition)
502 throws SystemException {
503
504 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
505 String[] titles = CustomSQLUtil.keywords(title);
506 String[] descriptions = CustomSQLUtil.keywords(description, false);
507 String[] contents = CustomSQLUtil.keywords(content, false);
508
509 return filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
510 companyId, groupId, folderIds, classNameId, articleIds, version,
511 titles, descriptions, contents, type, ddmStructureKeys,
512 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
513 andOperator, queryDefinition);
514 }
515
516 @Override
517 public List<JournalArticle> filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
518 long companyId, long groupId, List<Long> folderIds,
519 long classNameId, String[] articleIds, Double version,
520 String[] titles, String[] descriptions, String[] contents,
521 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
522 Date displayDateGT, Date displayDateLT, Date reviewDate,
523 boolean andOperator, QueryDefinition queryDefinition)
524 throws SystemException {
525
526 return doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
527 companyId, groupId, folderIds, classNameId, articleIds, version,
528 titles, descriptions, contents, type, ddmStructureKeys,
529 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
530 andOperator, queryDefinition, true);
531 }
532
533 @Override
534 public List<JournalArticle> findByExpirationDate(
535 long classNameId, Date expirationDateLT,
536 QueryDefinition queryDefinition)
537 throws SystemException {
538
539 Timestamp expirationDateLT_TS = CalendarUtil.getTimestamp(
540 expirationDateLT);
541
542 Session session = null;
543
544 try {
545 session = openSession();
546
547 String sql = CustomSQLUtil.get(
548 FIND_BY_EXPIRATION_DATE, queryDefinition);
549
550 SQLQuery q = session.createSQLQuery(sql);
551
552 q.addEntity(
553 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
554
555 QueryPos qPos = QueryPos.getInstance(q);
556
557 qPos.add(classNameId);
558 qPos.add(queryDefinition.getStatus());
559 qPos.add(expirationDateLT_TS);
560
561 return q.list(true);
562 }
563 catch (Exception e) {
564 throw new SystemException(e);
565 }
566 finally {
567 closeSession(session);
568 }
569 }
570
571 @Override
572 public List<JournalArticle> findByKeywords(
573 long companyId, long groupId, List<Long> folderIds,
574 long classNameId, String keywords, Double version, String type,
575 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
576 Date displayDateLT, int status, Date reviewDate, int start, int end,
577 OrderByComparator orderByComparator)
578 throws SystemException {
579
580 String[] articleIds = null;
581 String[] titles = null;
582 String[] descriptions = null;
583 String[] contents = null;
584 String[] ddmStructureKeys = CustomSQLUtil.keywords(
585 ddmStructureKey, false);
586 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
587 ddmTemplateKey, false);
588 boolean andOperator = false;
589
590 if (Validator.isNotNull(keywords)) {
591 articleIds = CustomSQLUtil.keywords(keywords, false);
592 titles = CustomSQLUtil.keywords(keywords);
593 descriptions = CustomSQLUtil.keywords(keywords, false);
594
595 if (PropsValues.JOURNAL_ARTICLE_DATABASE_KEYWORD_SEARCH_CONTENT) {
596 contents = CustomSQLUtil.keywords(keywords, false);
597 }
598 }
599 else {
600 andOperator = true;
601 }
602
603 QueryDefinition queryDefinition = new QueryDefinition(
604 status, start, end, orderByComparator);
605
606 return findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
607 companyId, groupId, folderIds, classNameId, articleIds, version,
608 titles, descriptions, contents, type, ddmStructureKeys,
609 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
610 andOperator, queryDefinition);
611 }
612
613 @Override
614 public List<JournalArticle> findByReviewDate(
615 long classNameId, Date reviewDateLT, Date reviewDateGT)
616 throws SystemException {
617
618 Timestamp reviewDateLT_TS = CalendarUtil.getTimestamp(reviewDateLT);
619 Timestamp reviewDateGT_TS = CalendarUtil.getTimestamp(reviewDateGT);
620
621 Session session = null;
622 try {
623 session = openSession();
624
625 String sql = CustomSQLUtil.get(FIND_BY_REVIEW_DATE);
626
627 SQLQuery q = session.createSQLQuery(sql);
628
629 q.addEntity(
630 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
631
632 QueryPos qPos = QueryPos.getInstance(q);
633
634 qPos.add(classNameId);
635 qPos.add(reviewDateGT_TS);
636 qPos.add(reviewDateLT_TS);
637
638 return q.list(true);
639 }
640 catch (Exception e) {
641 throw new SystemException(e);
642 }
643 finally {
644 closeSession(session);
645 }
646 }
647
648 @Override
649 public JournalArticle findByR_D(long resourcePrimKey, Date displayDate)
650 throws NoSuchArticleException, SystemException {
651
652 Timestamp displayDate_TS = CalendarUtil.getTimestamp(displayDate);
653
654 Session session = null;
655
656 try {
657 session = openSession();
658
659 String sql = CustomSQLUtil.get(FIND_BY_R_D);
660
661 SQLQuery q = session.createSQLQuery(sql);
662
663 q.addEntity(
664 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
665
666 QueryPos qPos = QueryPos.getInstance(q);
667
668 qPos.add(resourcePrimKey);
669 qPos.add(displayDate_TS);
670
671 List<JournalArticle> articles = q.list();
672
673 if (!articles.isEmpty()) {
674 return articles.get(0);
675 }
676 }
677 catch (Exception e) {
678 throw new SystemException(e);
679 }
680 finally {
681 closeSession(session);
682 }
683
684 StringBundler sb = new StringBundler(6);
685
686 sb.append("No JournalArticle exists with the key ");
687 sb.append("{resourcePrimKey=");
688 sb.append(resourcePrimKey);
689 sb.append(", displayDate=");
690 sb.append(displayDate);
691 sb.append("}");
692
693 throw new NoSuchArticleException(sb.toString());
694 }
695
696 @Override
697 public List<JournalArticle> findByG_F(
698 long groupId, List<Long> folderIds, QueryDefinition queryDefinition)
699 throws SystemException {
700
701 return doFindByG_F(groupId, folderIds, queryDefinition, false);
702 }
703
704 @Override
705 public List<JournalArticle> findByG_F_C(
706 long groupId, List<Long> folderIds, long classNameId,
707 QueryDefinition queryDefinition)
708 throws SystemException {
709
710 return doFindByG_F_C(
711 groupId, folderIds, classNameId, queryDefinition, false);
712 }
713
714 @Override
715 public List<JournalArticle> findByG_C_S(
716 long groupId, long classNameId, String ddmStructureKey,
717 QueryDefinition queryDefinition)
718 throws SystemException {
719
720 return doFindByG_C_S(
721 groupId, classNameId, ddmStructureKey, queryDefinition, false);
722 }
723
724 @Override
725 public List<JournalArticle> findByG_C_S(
726 long groupId, long classNameId, String[] ddmStructureKeys,
727 QueryDefinition queryDefinition)
728 throws SystemException {
729
730 return doFindByG_C_S(
731 groupId, classNameId, ddmStructureKeys, queryDefinition, false);
732 }
733
734
738 @Deprecated
739 @Override
740 public List<JournalArticle> findByG_U_F_C(
741 long groupId, long userId, List<Long> folderIds, long classNameId,
742 QueryDefinition queryDefinition)
743 throws SystemException {
744
745 return findByG_F_C(groupId, folderIds, classNameId, queryDefinition);
746 }
747
748 @Override
749 public List<JournalArticle> findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
750 long companyId, long groupId, List<Long> folderIds,
751 long classNameId, String articleId, Double version, String title,
752 String description, String content, String type,
753 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
754 Date displayDateLT, Date reviewDate, boolean andOperator,
755 QueryDefinition queryDefinition)
756 throws SystemException {
757
758 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
759 String[] titles = CustomSQLUtil.keywords(title);
760 String[] descriptions = CustomSQLUtil.keywords(description, false);
761 String[] contents = CustomSQLUtil.keywords(content, false);
762 String[] ddmStructureKeys = CustomSQLUtil.keywords(
763 ddmStructureKey, false);
764 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
765 ddmTemplateKey, false);
766
767 return findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
768 companyId, groupId, folderIds, classNameId, articleIds, version,
769 titles, descriptions, contents, type, ddmStructureKeys,
770 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
771 andOperator, queryDefinition);
772 }
773
774 @Override
775 public List<JournalArticle> findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
776 long companyId, long groupId, List<Long> folderIds,
777 long classNameId, String articleId, Double version, String title,
778 String description, String content, String type,
779 String[] ddmStructureKeys, String[] ddmTemplateKeys,
780 Date displayDateGT, Date displayDateLT, Date reviewDate,
781 boolean andOperator, QueryDefinition queryDefinition)
782 throws SystemException {
783
784 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
785 String[] titles = CustomSQLUtil.keywords(title);
786 String[] descriptions = CustomSQLUtil.keywords(description, false);
787 String[] contents = CustomSQLUtil.keywords(content, false);
788
789 return findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
790 companyId, groupId, folderIds, classNameId, articleIds, version,
791 titles, descriptions, contents, type, ddmStructureKeys,
792 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
793 andOperator, queryDefinition);
794 }
795
796 @Override
797 public List<JournalArticle> findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
798 long companyId, long groupId, List<Long> folderIds,
799 long classNameId, String[] articleIds, Double version,
800 String[] titles, String[] descriptions, String[] contents,
801 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
802 Date displayDateGT, Date displayDateLT, Date reviewDate,
803 boolean andOperator, QueryDefinition queryDefinition)
804 throws SystemException {
805
806 return doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
807 companyId, groupId, folderIds, classNameId, articleIds, version,
808 titles, descriptions, contents, type, ddmStructureKeys,
809 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
810 andOperator, queryDefinition, false);
811 }
812
813 protected int doCountByG_F(
814 long groupId, List<Long> folderIds, QueryDefinition queryDefinition,
815 boolean inlineSQLHelper)
816 throws SystemException {
817
818 Session session = null;
819
820 try {
821 session = openSession();
822
823 String sql = CustomSQLUtil.get(
824 COUNT_BY_G_F, queryDefinition, "JournalArticle");
825
826 sql = replaceStatusJoin(sql, queryDefinition);
827
828 if (inlineSQLHelper) {
829 sql = InlineSQLHelperUtil.replacePermissionCheck(
830 sql, JournalArticle.class.getName(),
831 "JournalArticle.resourcePrimKey", groupId);
832 }
833
834 sql = StringUtil.replace(
835 sql, "[$FOLDER_ID$]",
836 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
837
838 SQLQuery q = session.createSQLQuery(sql);
839
840 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
841
842 QueryPos qPos = QueryPos.getInstance(q);
843
844 qPos.add(groupId);
845 qPos.add(queryDefinition.getStatus());
846
847 for (int i = 0; i < folderIds.size(); i++) {
848 Long folderId = folderIds.get(i);
849
850 qPos.add(folderId);
851 }
852
853 Iterator<Long> itr = q.iterate();
854
855 if (itr.hasNext()) {
856 Long count = itr.next();
857
858 if (count != null) {
859 return count.intValue();
860 }
861 }
862
863 return 0;
864 }
865 catch (Exception e) {
866 throw new SystemException(e);
867 }
868 finally {
869 closeSession(session);
870 }
871 }
872
873 protected int doCountByG_C_S(
874 long groupId, long classNameId, String ddmStructureKey,
875 QueryDefinition queryDefinition, boolean inlineSQLHelper)
876 throws SystemException {
877
878 return doCountByG_C_S(
879 groupId, classNameId, new String[] {ddmStructureKey},
880 queryDefinition, inlineSQLHelper);
881 }
882
883 protected int doCountByG_F_C(
884 long groupId, List<Long> folderIds, long classNameId,
885 QueryDefinition queryDefinition, boolean inlineSQLHelper)
886 throws SystemException {
887
888 Session session = null;
889
890 try {
891 session = openSession();
892
893 String sql = CustomSQLUtil.get(
894 COUNT_BY_G_U_F_C, queryDefinition, "JournalArticle");
895
896 sql = replaceStatusJoin(sql, queryDefinition);
897
898 if (folderIds.isEmpty()) {
899 sql = StringUtil.replace(
900 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
901 }
902 else {
903 sql = StringUtil.replace(
904 sql, "[$FOLDER_ID$]",
905 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
906 }
907
908 if (inlineSQLHelper) {
909 sql = InlineSQLHelperUtil.replacePermissionCheck(
910 sql, JournalArticle.class.getName(),
911 "JournalArticle.resourcePrimKey", groupId);
912 }
913
914 SQLQuery q = session.createSQLQuery(sql);
915
916 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
917
918 QueryPos qPos = QueryPos.getInstance(q);
919
920 qPos.add(groupId);
921 qPos.add(classNameId);
922
923 if (queryDefinition.getOwnerUserId() > 0) {
924 qPos.add(queryDefinition.getOwnerUserId());
925
926 if (queryDefinition.isIncludeOwner()) {
927 qPos.add(WorkflowConstants.STATUS_IN_TRASH);
928 }
929 }
930
931 for (long folderId : folderIds) {
932 qPos.add(folderId);
933 }
934
935 qPos.add(queryDefinition.getStatus());
936
937 Iterator<Long> itr = q.iterate();
938
939 if (itr.hasNext()) {
940 Long count = itr.next();
941
942 if (count != null) {
943 return count.intValue();
944 }
945 }
946
947 return 0;
948 }
949 catch (Exception e) {
950 throw new SystemException(e);
951 }
952 finally {
953 closeSession(session);
954 }
955 }
956
957 protected int doCountByG_C_S(
958 long groupId, long classNameId, String[] ddmStructureKeys,
959 QueryDefinition queryDefinition, boolean inlineSQLHelper)
960 throws SystemException {
961
962 Session session = null;
963
964 try {
965 session = openSession();
966
967 String sql = CustomSQLUtil.get(
968 COUNT_BY_G_C_S, queryDefinition, "JournalArticle");
969
970 sql = replaceStatusJoin(sql, queryDefinition);
971
972 if (groupId <= 0) {
973 sql = StringUtil.replace(
974 sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
975 }
976
977 sql = StringUtil.replace(
978 sql, "[$DDM_STRUCTURE_KEY$]",
979 getDDMStructureKeys(
980 ddmStructureKeys, JournalArticleImpl.TABLE_NAME));
981
982 if (inlineSQLHelper) {
983 sql = InlineSQLHelperUtil.replacePermissionCheck(
984 sql, JournalArticle.class.getName(),
985 "JournalArticle.resourcePrimKey", groupId);
986 }
987
988 SQLQuery q = session.createSQLQuery(sql);
989
990 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
991
992 QueryPos qPos = QueryPos.getInstance(q);
993
994 if (groupId > 0) {
995 qPos.add(groupId);
996 }
997
998 qPos.add(classNameId);
999 qPos.add(ddmStructureKeys);
1000 qPos.add(queryDefinition.getStatus());
1001
1002 Iterator<Long> itr = q.iterate();
1003
1004 if (itr.hasNext()) {
1005 Long count = itr.next();
1006
1007 if (count != null) {
1008 return count.intValue();
1009 }
1010 }
1011
1012 return 0;
1013 }
1014 catch (Exception e) {
1015 throw new SystemException(e);
1016 }
1017 finally {
1018 closeSession(session);
1019 }
1020 }
1021
1022 protected int doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
1023 long companyId, long groupId, List<Long> folderIds,
1024 long classNameId, String[] articleIds, Double version,
1025 String[] titles, String[] descriptions, String[] contents,
1026 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
1027 Date displayDateGT, Date displayDateLT, Date reviewDate,
1028 boolean andOperator, QueryDefinition queryDefinition,
1029 boolean inlineSQLHelper)
1030 throws SystemException {
1031
1032 articleIds = CustomSQLUtil.keywords(articleIds, false);
1033 titles = CustomSQLUtil.keywords(titles);
1034 descriptions = CustomSQLUtil.keywords(descriptions, false);
1035 contents = CustomSQLUtil.keywords(contents, false);
1036 ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
1037 ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
1038 Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
1039 Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
1040 Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);
1041
1042 Session session = null;
1043
1044 try {
1045 session = openSession();
1046
1047 String sql = CustomSQLUtil.get(
1048 COUNT_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R, queryDefinition,
1049 "JournalArticle");
1050
1051 sql = replaceStatusJoin(sql, queryDefinition);
1052
1053 if (groupId <= 0) {
1054 sql = StringUtil.replace(
1055 sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
1056 }
1057
1058 if (folderIds.isEmpty()) {
1059 sql = StringUtil.replace(
1060 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
1061 }
1062 else {
1063 sql = StringUtil.replace(
1064 sql, "[$FOLDER_ID$]",
1065 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1066 }
1067
1068 sql = CustomSQLUtil.replaceKeywords(
1069 sql, "JournalArticle.articleId", StringPool.LIKE, false,
1070 articleIds);
1071
1072 if ((version == null) || (version <= 0)) {
1073 sql = StringUtil.replace(
1074 sql, "(JournalArticle.version = ?) [$AND_OR_CONNECTOR$]",
1075 StringPool.BLANK);
1076 }
1077
1078 sql = CustomSQLUtil.replaceKeywords(
1079 sql, "lower(JournalArticle.title)", StringPool.LIKE, false,
1080 titles);
1081 sql = CustomSQLUtil.replaceKeywords(
1082 sql, "JournalArticle.description", StringPool.LIKE, false,
1083 descriptions);
1084 sql = CustomSQLUtil.replaceKeywords(
1085 sql, "JournalArticle.content", StringPool.LIKE, false,
1086 contents);
1087
1088 sql = replaceTypeStructureTemplate(
1089 sql, type, ddmStructureKeys, ddmTemplateKeys);
1090
1091 if (!isNullArray(ddmStructureKeys)) {
1092 sql = CustomSQLUtil.replaceKeywords(
1093 sql, "JournalArticle.structureId", StringPool.LIKE, false,
1094 ddmStructureKeys);
1095 }
1096
1097 if (!isNullArray(ddmTemplateKeys)) {
1098 sql = CustomSQLUtil.replaceKeywords(
1099 sql, "JournalArticle.templateId", StringPool.LIKE, false,
1100 ddmTemplateKeys);
1101 }
1102
1103 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
1104
1105 if (inlineSQLHelper) {
1106 sql = InlineSQLHelperUtil.replacePermissionCheck(
1107 sql, JournalArticle.class.getName(),
1108 "JournalArticle.resourcePrimKey", groupId);
1109
1110 sql = StringUtil.replace(
1111 sql, "(companyId", "(JournalArticle.companyId");
1112 }
1113
1114 SQLQuery q = session.createSQLQuery(sql);
1115
1116 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1117
1118 QueryPos qPos = QueryPos.getInstance(q);
1119
1120 qPos.add(companyId);
1121
1122 if (groupId > 0) {
1123 qPos.add(groupId);
1124 }
1125
1126 for (long folderId : folderIds) {
1127 qPos.add(folderId);
1128 }
1129
1130 qPos.add(classNameId);
1131 qPos.add(queryDefinition.getStatus());
1132
1133 if (Validator.isNotNull(type)) {
1134 qPos.add(type);
1135 qPos.add(type);
1136 }
1137
1138 if (!isNullArray(ddmStructureKeys)) {
1139 qPos.add(ddmStructureKeys, 2);
1140 }
1141
1142 if (!isNullArray(ddmTemplateKeys)) {
1143 qPos.add(ddmTemplateKeys, 2);
1144 }
1145
1146 qPos.add(articleIds, 2);
1147
1148 if ((version != null) && (version > 0)) {
1149 qPos.add(version);
1150 }
1151
1152 qPos.add(titles, 2);
1153 qPos.add(descriptions, 2);
1154 qPos.add(contents, 2);
1155 qPos.add(displayDateGT_TS);
1156 qPos.add(displayDateGT_TS);
1157 qPos.add(displayDateLT_TS);
1158 qPos.add(displayDateLT_TS);
1159 qPos.add(reviewDate_TS);
1160 qPos.add(reviewDate_TS);
1161
1162 Iterator<Long> itr = q.iterate();
1163
1164 if (itr.hasNext()) {
1165 Long count = itr.next();
1166
1167 if (count != null) {
1168 return count.intValue();
1169 }
1170 }
1171
1172 return 0;
1173 }
1174 catch (Exception e) {
1175 throw new SystemException(e);
1176 }
1177 finally {
1178 closeSession(session);
1179 }
1180 }
1181
1182 protected List<JournalArticle> doFindByG_F(
1183 long groupId, List<Long> folderIds, QueryDefinition queryDefinition,
1184 boolean inlineSQLHelper)
1185 throws SystemException {
1186
1187 Session session = null;
1188
1189 try {
1190 session = openSession();
1191
1192 String sql = CustomSQLUtil.get(
1193 FIND_BY_G_F, queryDefinition, "JournalArticle");
1194
1195 sql = replaceStatusJoin(sql, queryDefinition);
1196
1197 sql = CustomSQLUtil.replaceOrderBy(
1198 sql, queryDefinition.getOrderByComparator("JournalArticle"));
1199
1200 if (inlineSQLHelper) {
1201 sql = InlineSQLHelperUtil.replacePermissionCheck(
1202 sql, JournalArticle.class.getName(),
1203 "JournalArticle.resourcePrimKey", groupId);
1204 }
1205
1206 sql = StringUtil.replace(
1207 sql, "[$FOLDER_ID$]",
1208 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1209
1210 SQLQuery q = session.createSQLQuery(sql);
1211
1212 q.addEntity(
1213 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1214
1215 QueryPos qPos = QueryPos.getInstance(q);
1216
1217 qPos.add(groupId);
1218 qPos.add(queryDefinition.getStatus());
1219
1220 for (int i = 0; i < folderIds.size(); i++) {
1221 Long folderId = folderIds.get(i);
1222
1223 qPos.add(folderId);
1224 }
1225
1226 return (List<JournalArticle>)QueryUtil.list(
1227 q, getDialect(), queryDefinition.getStart(),
1228 queryDefinition.getEnd());
1229 }
1230 catch (Exception e) {
1231 throw new SystemException(e);
1232 }
1233 finally {
1234 closeSession(session);
1235 }
1236 }
1237
1238 protected List<JournalArticle> doFindByG_C_S(
1239 long groupId, long classNameId, String ddmStructureKey,
1240 QueryDefinition queryDefinition, boolean inlineSQLHelper)
1241 throws SystemException {
1242
1243 return doFindByG_C_S(
1244 groupId, classNameId, new String[] {ddmStructureKey},
1245 queryDefinition, inlineSQLHelper);
1246 }
1247
1248 protected List<JournalArticle> doFindByG_F_C(
1249 long groupId, List<Long> folderIds, long classNameId,
1250 QueryDefinition queryDefinition, boolean inlineSQLHelper)
1251 throws SystemException {
1252
1253 Session session = null;
1254
1255 try {
1256 session = openSession();
1257
1258 String sql = CustomSQLUtil.get(
1259 FIND_BY_G_U_F_C, queryDefinition, "JournalArticle");
1260
1261 sql = replaceStatusJoin(sql, queryDefinition);
1262
1263 sql = CustomSQLUtil.replaceOrderBy(
1264 sql, queryDefinition.getOrderByComparator("JournalArticle"));
1265
1266 if (folderIds.isEmpty()) {
1267 sql = StringUtil.replace(
1268 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
1269 }
1270 else {
1271 sql = StringUtil.replace(
1272 sql, "[$FOLDER_ID$]",
1273 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1274 }
1275
1276 if (inlineSQLHelper) {
1277 sql = InlineSQLHelperUtil.replacePermissionCheck(
1278 sql, JournalArticle.class.getName(),
1279 "JournalArticle.resourcePrimKey", groupId);
1280 }
1281
1282 SQLQuery q = session.createSQLQuery(sql);
1283
1284 q.addEntity(
1285 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1286
1287 QueryPos qPos = QueryPos.getInstance(q);
1288
1289 qPos.add(groupId);
1290 qPos.add(classNameId);
1291
1292 if (queryDefinition.getOwnerUserId() > 0) {
1293 qPos.add(queryDefinition.getOwnerUserId());
1294
1295 if (queryDefinition.isIncludeOwner()) {
1296 qPos.add(WorkflowConstants.STATUS_IN_TRASH);
1297 }
1298 }
1299
1300 for (long folderId : folderIds) {
1301 qPos.add(folderId);
1302 }
1303
1304 qPos.add(queryDefinition.getStatus());
1305
1306 return (List<JournalArticle>)QueryUtil.list(
1307 q, getDialect(), queryDefinition.getStart(),
1308 queryDefinition.getEnd());
1309 }
1310 catch (Exception e) {
1311 throw new SystemException(e);
1312 }
1313 finally {
1314 closeSession(session);
1315 }
1316 }
1317
1318 protected List<JournalArticle> doFindByG_C_S(
1319 long groupId, long classNameId, String[] ddmStructureKeys,
1320 QueryDefinition queryDefinition, boolean inlineSQLHelper)
1321 throws SystemException {
1322
1323 Session session = null;
1324
1325 try {
1326 session = openSession();
1327
1328 String sql = CustomSQLUtil.get(
1329 FIND_BY_G_C_S, queryDefinition, "JournalArticle");
1330
1331 sql = replaceStatusJoin(sql, queryDefinition);
1332
1333 sql = CustomSQLUtil.replaceOrderBy(
1334 sql, queryDefinition.getOrderByComparator("JournalArticle"));
1335
1336 if (groupId <= 0) {
1337 sql = StringUtil.replace(
1338 sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
1339 }
1340
1341 sql = StringUtil.replace(
1342 sql, "[$DDM_STRUCTURE_KEY$]",
1343 getDDMStructureKeys(
1344 ddmStructureKeys, JournalArticleImpl.TABLE_NAME));
1345
1346 if (inlineSQLHelper) {
1347 sql = InlineSQLHelperUtil.replacePermissionCheck(
1348 sql, JournalArticle.class.getName(),
1349 "JournalArticle.resourcePrimKey", groupId);
1350 }
1351
1352 SQLQuery q = session.createSQLQuery(sql);
1353
1354 q.addEntity(
1355 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1356
1357 QueryPos qPos = QueryPos.getInstance(q);
1358
1359 if (groupId > 0) {
1360 qPos.add(groupId);
1361 }
1362
1363 qPos.add(classNameId);
1364 qPos.add(ddmStructureKeys);
1365 qPos.add(queryDefinition.getStatus());
1366
1367 return (List<JournalArticle>)QueryUtil.list(
1368 q, getDialect(), queryDefinition.getStart(),
1369 queryDefinition.getEnd());
1370 }
1371 catch (Exception e) {
1372 throw new SystemException(e);
1373 }
1374 finally {
1375 closeSession(session);
1376 }
1377 }
1378
1379 protected List<JournalArticle> doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
1380 long companyId, long groupId, List<Long> folderIds,
1381 long classNameId, String[] articleIds, Double version,
1382 String[] titles, String[] descriptions, String[] contents,
1383 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
1384 Date displayDateGT, Date displayDateLT, Date reviewDate,
1385 boolean andOperator, QueryDefinition queryDefinition,
1386 boolean inlineSQLHelper)
1387 throws SystemException {
1388
1389 articleIds = CustomSQLUtil.keywords(articleIds, false);
1390 titles = CustomSQLUtil.keywords(titles);
1391 descriptions = CustomSQLUtil.keywords(descriptions, false);
1392 contents = CustomSQLUtil.keywords(contents, false);
1393 ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
1394 ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
1395 Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
1396 Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
1397 Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);
1398
1399 Session session = null;
1400
1401 try {
1402 session = openSession();
1403
1404 String sql = CustomSQLUtil.get(
1405 FIND_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R, queryDefinition,
1406 "JournalArticle");
1407
1408 sql = replaceStatusJoin(sql, queryDefinition);
1409
1410 if (groupId <= 0) {
1411 sql = StringUtil.replace(
1412 sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
1413 }
1414
1415 if (folderIds.isEmpty()) {
1416 sql = StringUtil.replace(
1417 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
1418 }
1419 else {
1420 sql = StringUtil.replace(
1421 sql, "[$FOLDER_ID$]",
1422 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1423 }
1424
1425 sql = CustomSQLUtil.replaceKeywords(
1426 sql, "JournalArticle.articleId", StringPool.LIKE, false,
1427 articleIds);
1428
1429 if ((version == null) || (version <= 0)) {
1430 sql = StringUtil.replace(
1431 sql, "(JournalArticle.version = ?) [$AND_OR_CONNECTOR$]",
1432 StringPool.BLANK);
1433 }
1434
1435 sql = CustomSQLUtil.replaceKeywords(
1436 sql, "lower(JournalArticle.title)", StringPool.LIKE, false,
1437 titles);
1438 sql = CustomSQLUtil.replaceKeywords(
1439 sql, "JournalArticle.description", StringPool.LIKE, false,
1440 descriptions);
1441 sql = CustomSQLUtil.replaceKeywords(
1442 sql, "JournalArticle.content", StringPool.LIKE, false,
1443 contents);
1444
1445 sql = replaceTypeStructureTemplate(
1446 sql, type, ddmStructureKeys, ddmTemplateKeys);
1447
1448 if (!isNullArray(ddmStructureKeys)) {
1449 sql = CustomSQLUtil.replaceKeywords(
1450 sql, "JournalArticle.structureId", StringPool.LIKE, false,
1451 ddmStructureKeys);
1452 }
1453
1454 if (!isNullArray(ddmTemplateKeys)) {
1455 sql = CustomSQLUtil.replaceKeywords(
1456 sql, "JournalArticle.templateId", StringPool.LIKE, false,
1457 ddmTemplateKeys);
1458 }
1459
1460 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
1461 sql = CustomSQLUtil.replaceOrderBy(
1462 sql, queryDefinition.getOrderByComparator("JournalArticle"));
1463
1464 if (inlineSQLHelper) {
1465 sql = InlineSQLHelperUtil.replacePermissionCheck(
1466 sql, JournalArticle.class.getName(),
1467 "JournalArticle.resourcePrimKey", groupId);
1468
1469 sql = StringUtil.replace(
1470 sql, "(companyId", "(JournalArticle.companyId");
1471 }
1472
1473 SQLQuery q = session.createSQLQuery(sql);
1474
1475 q.addEntity(
1476 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1477
1478 QueryPos qPos = QueryPos.getInstance(q);
1479
1480 qPos.add(companyId);
1481
1482 if (groupId > 0) {
1483 qPos.add(groupId);
1484 }
1485
1486 for (long folderId : folderIds) {
1487 qPos.add(folderId);
1488 }
1489
1490 qPos.add(classNameId);
1491 qPos.add(queryDefinition.getStatus());
1492
1493 if (Validator.isNotNull(type)) {
1494 qPos.add(type);
1495 qPos.add(type);
1496 }
1497
1498 if (!isNullArray(ddmStructureKeys)) {
1499 qPos.add(ddmStructureKeys, 2);
1500 }
1501
1502 if (!isNullArray(ddmTemplateKeys)) {
1503 qPos.add(ddmTemplateKeys, 2);
1504 }
1505
1506 qPos.add(articleIds, 2);
1507
1508 if ((version != null) && (version > 0)) {
1509 qPos.add(version);
1510 }
1511
1512 qPos.add(titles, 2);
1513 qPos.add(descriptions, 2);
1514 qPos.add(contents, 2);
1515 qPos.add(displayDateGT_TS);
1516 qPos.add(displayDateGT_TS);
1517 qPos.add(displayDateLT_TS);
1518 qPos.add(displayDateLT_TS);
1519 qPos.add(reviewDate_TS);
1520 qPos.add(reviewDate_TS);
1521
1522 return (List<JournalArticle>)QueryUtil.list(
1523 q, getDialect(), queryDefinition.getStart(),
1524 queryDefinition.getEnd());
1525 }
1526 catch (Exception e) {
1527 throw new SystemException(e);
1528 }
1529 finally {
1530 closeSession(session);
1531 }
1532 }
1533
1534 protected String getDDMStructureKeys(
1535 String[] ddmStructureKeys, String tableName) {
1536
1537 if (ArrayUtil.isEmpty(ddmStructureKeys)) {
1538 return StringPool.BLANK;
1539 }
1540
1541 StringBundler sb = new StringBundler(ddmStructureKeys.length * 3 + 1);
1542
1543 sb.append(StringPool.OPEN_PARENTHESIS);
1544
1545 for (int i = 0; i < ddmStructureKeys.length; i++) {
1546 sb.append(tableName);
1547 sb.append(".structureId = ? ");
1548 sb.append(WHERE_OR);
1549 }
1550
1551 sb.setIndex(sb.index() - 1);
1552
1553 sb.append(StringPool.CLOSE_PARENTHESIS);
1554
1555 return sb.toString();
1556 }
1557
1558 protected String getFolderIds(List<Long> folderIds, String tableName) {
1559 if (folderIds.isEmpty()) {
1560 return StringPool.BLANK;
1561 }
1562
1563 StringBundler sb = new StringBundler(folderIds.size() * 3 + 1);
1564
1565 sb.append(StringPool.OPEN_PARENTHESIS);
1566
1567 for (int i = 0; i < folderIds.size(); i++) {
1568 sb.append(tableName);
1569 sb.append(".folderId = ? ");
1570
1571 if ((i + 1) != folderIds.size()) {
1572 sb.append(WHERE_OR);
1573 }
1574 }
1575
1576 sb.append(StringPool.CLOSE_PARENTHESIS);
1577
1578 return sb.toString();
1579 }
1580
1581 protected JournalArticle getLatestArticle(
1582 long groupId, String articleId, int status)
1583 throws SystemException {
1584
1585 List<JournalArticle> articles = null;
1586
1587 if (status == WorkflowConstants.STATUS_ANY) {
1588 articles = JournalArticleUtil.findByG_A(groupId, articleId, 0, 1);
1589 }
1590 else {
1591 articles = JournalArticleUtil.findByG_A_ST(
1592 groupId, articleId, status, 0, 1);
1593 }
1594
1595 if (articles.isEmpty()) {
1596 return null;
1597 }
1598
1599 return articles.get(0);
1600 }
1601
1602 protected boolean isNullArray(Object[] array) {
1603 if (ArrayUtil.isEmpty(array)) {
1604 return true;
1605 }
1606
1607 for (Object obj : array) {
1608 if (Validator.isNotNull(obj)) {
1609 return false;
1610 }
1611 }
1612
1613 return true;
1614 }
1615
1616 protected String replaceStatusJoin(
1617 String sql, QueryDefinition queryDefinition) {
1618
1619 if (queryDefinition.getStatus() == WorkflowConstants.STATUS_ANY) {
1620 return StringUtil.replace(
1621 sql, "[$STATUS_JOIN$] AND", StringPool.BLANK);
1622 }
1623
1624 if (queryDefinition.isExcludeStatus()) {
1625 StringBundler sb = new StringBundler(5);
1626
1627 sb.append("(JournalArticle.status != ");
1628 sb.append(queryDefinition.getStatus());
1629 sb.append(") AND (tempJournalArticle.status != ");
1630 sb.append(queryDefinition.getStatus());
1631 sb.append(")");
1632
1633 sql = StringUtil.replace(sql, "[$STATUS_JOIN$]", sb.toString());
1634 }
1635 else {
1636 StringBundler sb = new StringBundler(5);
1637
1638 sb.append("(JournalArticle.status = ");
1639 sb.append(queryDefinition.getStatus());
1640 sb.append(") AND (tempJournalArticle.status = ");
1641 sb.append(queryDefinition.getStatus());
1642 sb.append(")");
1643
1644 sql = StringUtil.replace(sql, "[$STATUS_JOIN$]", sb.toString());
1645 }
1646
1647 return sql;
1648 }
1649
1650 protected String replaceTypeStructureTemplate(
1651 String sql, String type, String[] ddmStructureKeys,
1652 String[] ddmTemplateKeys) {
1653
1654 StringBundler sb = new StringBundler(5);
1655
1656 if (Validator.isNull(type) && isNullArray(ddmStructureKeys) &&
1657 isNullArray(ddmTemplateKeys)) {
1658
1659 return StringUtil.replace(
1660 sql, "([$TYPE_STRUCTURE_TEMPLATE$]) AND", StringPool.BLANK);
1661 }
1662
1663 if (Validator.isNotNull(type)) {
1664 sb.append(_TYPE_SQL);
1665 }
1666
1667 if (!isNullArray(ddmStructureKeys)) {
1668 if (Validator.isNotNull(type)) {
1669 sb.append(_AND_OR_CONNECTOR);
1670 }
1671
1672 sb.append(_STRUCTURE_ID_SQL);
1673 }
1674
1675 if (!isNullArray(ddmTemplateKeys)) {
1676 if (Validator.isNotNull(type) || !isNullArray(ddmStructureKeys)) {
1677 sb.append(_AND_OR_CONNECTOR);
1678 }
1679
1680 sb.append(_TEMPLATE_ID_SQL);
1681 }
1682
1683 return StringUtil.replace(
1684 sql, "[$TYPE_STRUCTURE_TEMPLATE$]", sb.toString());
1685 }
1686
1687 private static final String _AND_OR_CONNECTOR = "[$AND_OR_CONNECTOR$] ";
1688
1689 private static final String _STRUCTURE_ID_SQL =
1690 "(JournalArticle.structureId LIKE ? [$AND_OR_NULL_CHECK$]) ";
1691
1692 private static final String _TEMPLATE_ID_SQL =
1693 "(JournalArticle.templateId LIKE ? [$AND_OR_NULL_CHECK$]) ";
1694
1695 private static final String _TYPE_SQL =
1696 "(JournalArticle.type_ = ? [$AND_OR_NULL_CHECK$]) ";
1697
1698 }