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