PageRenderTime 61ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/portal-impl/src/com/liferay/portlet/journal/service/impl/JournalArticleLocalServiceImpl.java

https://github.com/viktorkovacs/liferay-portal-trunk
Java | 1655 lines | 1224 code | 379 blank | 52 comment | 116 complexity | 2626eb759b535eec2204fc03161cb48b MD5 | raw file
  1. /**
  2. * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.portlet.journal.service.impl;
  15. import com.liferay.portal.NoSuchImageException;
  16. import com.liferay.portal.kernel.dao.orm.QueryUtil;
  17. import com.liferay.portal.kernel.exception.PortalException;
  18. import com.liferay.portal.kernel.exception.SystemException;
  19. import com.liferay.portal.kernel.log.Log;
  20. import com.liferay.portal.kernel.log.LogFactoryUtil;
  21. import com.liferay.portal.kernel.mail.MailMessage;
  22. import com.liferay.portal.kernel.search.Indexer;
  23. import com.liferay.portal.kernel.search.IndexerRegistryUtil;
  24. import com.liferay.portal.kernel.servlet.ImageServletTokenUtil;
  25. import com.liferay.portal.kernel.util.CalendarFactoryUtil;
  26. import com.liferay.portal.kernel.util.CharPool;
  27. import com.liferay.portal.kernel.util.ContentTypes;
  28. import com.liferay.portal.kernel.util.FileUtil;
  29. import com.liferay.portal.kernel.util.GetterUtil;
  30. import com.liferay.portal.kernel.util.HtmlUtil;
  31. import com.liferay.portal.kernel.util.HttpUtil;
  32. import com.liferay.portal.kernel.util.LocaleUtil;
  33. import com.liferay.portal.kernel.util.LocalizationUtil;
  34. import com.liferay.portal.kernel.util.MathUtil;
  35. import com.liferay.portal.kernel.util.OrderByComparator;
  36. import com.liferay.portal.kernel.util.PropsKeys;
  37. import com.liferay.portal.kernel.util.StringPool;
  38. import com.liferay.portal.kernel.util.StringUtil;
  39. import com.liferay.portal.kernel.util.Time;
  40. import com.liferay.portal.kernel.util.Validator;
  41. import com.liferay.portal.kernel.workflow.WorkflowConstants;
  42. import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
  43. import com.liferay.portal.kernel.xml.Document;
  44. import com.liferay.portal.kernel.xml.DocumentException;
  45. import com.liferay.portal.kernel.xml.Element;
  46. import com.liferay.portal.kernel.xml.Node;
  47. import com.liferay.portal.kernel.xml.SAXReaderUtil;
  48. import com.liferay.portal.kernel.xml.XPath;
  49. import com.liferay.portal.model.Company;
  50. import com.liferay.portal.model.Group;
  51. import com.liferay.portal.model.Image;
  52. import com.liferay.portal.model.ResourceConstants;
  53. import com.liferay.portal.model.User;
  54. import com.liferay.portal.security.permission.ActionKeys;
  55. import com.liferay.portal.service.ServiceContext;
  56. import com.liferay.portal.service.ServiceContextUtil;
  57. import com.liferay.portal.servlet.filters.cache.CacheUtil;
  58. import com.liferay.portal.theme.ThemeDisplay;
  59. import com.liferay.portal.util.PortalUtil;
  60. import com.liferay.portal.util.PortletKeys;
  61. import com.liferay.portal.util.PrefsPropsUtil;
  62. import com.liferay.portal.util.PropsValues;
  63. import com.liferay.portal.util.SubscriptionSender;
  64. import com.liferay.portlet.asset.NoSuchEntryException;
  65. import com.liferay.portlet.asset.model.AssetEntry;
  66. import com.liferay.portlet.dynamicdatamapping.util.DDMXMLUtil;
  67. import com.liferay.portlet.expando.model.ExpandoBridge;
  68. import com.liferay.portlet.journal.ArticleContentException;
  69. import com.liferay.portlet.journal.ArticleDisplayDateException;
  70. import com.liferay.portlet.journal.ArticleExpirationDateException;
  71. import com.liferay.portlet.journal.ArticleIdException;
  72. import com.liferay.portlet.journal.ArticleReviewDateException;
  73. import com.liferay.portlet.journal.ArticleSmallImageNameException;
  74. import com.liferay.portlet.journal.ArticleSmallImageSizeException;
  75. import com.liferay.portlet.journal.ArticleTitleException;
  76. import com.liferay.portlet.journal.ArticleTypeException;
  77. import com.liferay.portlet.journal.ArticleVersionException;
  78. import com.liferay.portlet.journal.DuplicateArticleIdException;
  79. import com.liferay.portlet.journal.NoSuchArticleException;
  80. import com.liferay.portlet.journal.NoSuchArticleResourceException;
  81. import com.liferay.portlet.journal.NoSuchStructureException;
  82. import com.liferay.portlet.journal.NoSuchTemplateException;
  83. import com.liferay.portlet.journal.StructureXsdException;
  84. import com.liferay.portlet.journal.model.JournalArticle;
  85. import com.liferay.portlet.journal.model.JournalArticleConstants;
  86. import com.liferay.portlet.journal.model.JournalArticleDisplay;
  87. import com.liferay.portlet.journal.model.JournalStructure;
  88. import com.liferay.portlet.journal.model.JournalTemplate;
  89. import com.liferay.portlet.journal.model.impl.JournalArticleDisplayImpl;
  90. import com.liferay.portlet.journal.service.base.JournalArticleLocalServiceBaseImpl;
  91. import com.liferay.portlet.journal.util.JournalUtil;
  92. import com.liferay.portlet.journal.util.comparator.ArticleIDComparator;
  93. import com.liferay.portlet.journal.util.comparator.ArticleVersionComparator;
  94. import com.liferay.portlet.journalcontent.util.JournalContentUtil;
  95. import java.io.File;
  96. import java.io.IOException;
  97. import java.util.Calendar;
  98. import java.util.Date;
  99. import java.util.HashSet;
  100. import java.util.List;
  101. import java.util.Locale;
  102. import java.util.Map;
  103. import java.util.Set;
  104. import javax.mail.internet.InternetAddress;
  105. import javax.portlet.PortletPreferences;
  106. /**
  107. * @author Brian Wing Shun Chan
  108. * @author Raymond Augé
  109. * @author Bruno Farache
  110. * @author Juan Fernández
  111. */
  112. public class JournalArticleLocalServiceImpl
  113. extends JournalArticleLocalServiceBaseImpl {
  114. public JournalArticle addArticle(
  115. long userId, long groupId, String articleId, boolean autoArticleId,
  116. double version, Map<Locale, String> titleMap,
  117. Map<Locale, String> descriptionMap, String content, String type,
  118. String structureId, String templateId, String layoutUuid,
  119. int displayDateMonth, int displayDateDay, int displayDateYear,
  120. int displayDateHour, int displayDateMinute, int expirationDateMonth,
  121. int expirationDateDay, int expirationDateYear,
  122. int expirationDateHour, int expirationDateMinute,
  123. boolean neverExpire, int reviewDateMonth, int reviewDateDay,
  124. int reviewDateYear, int reviewDateHour, int reviewDateMinute,
  125. boolean neverReview, boolean indexable, boolean smallImage,
  126. String smallImageURL, File smallFile, Map<String, byte[]> images,
  127. String articleURL, ServiceContext serviceContext)
  128. throws PortalException, SystemException {
  129. // Article
  130. User user = userPersistence.findByPrimaryKey(userId);
  131. articleId = articleId.trim().toUpperCase();
  132. Date displayDate = PortalUtil.getDate(
  133. displayDateMonth, displayDateDay, displayDateYear,
  134. displayDateHour, displayDateMinute, user.getTimeZone(),
  135. new ArticleDisplayDateException());
  136. Date expirationDate = null;
  137. if (!neverExpire) {
  138. expirationDate = PortalUtil.getDate(
  139. expirationDateMonth, expirationDateDay, expirationDateYear,
  140. expirationDateHour, expirationDateMinute, user.getTimeZone(),
  141. new ArticleExpirationDateException());
  142. }
  143. Date reviewDate = null;
  144. if (!neverReview) {
  145. reviewDate = PortalUtil.getDate(
  146. reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
  147. reviewDateMinute, user.getTimeZone(),
  148. new ArticleReviewDateException());
  149. }
  150. byte[] smallBytes = null;
  151. try {
  152. smallBytes = FileUtil.getBytes(smallFile);
  153. }
  154. catch (IOException ioe) {
  155. }
  156. Date now = new Date();
  157. validate(
  158. user.getCompanyId(), groupId, articleId, autoArticleId, version,
  159. titleMap, content, type, structureId, templateId,smallImage,
  160. smallImageURL, smallFile, smallBytes);
  161. if (autoArticleId) {
  162. articleId = String.valueOf(counterLocalService.increment());
  163. }
  164. long id = counterLocalService.increment();
  165. long resourcePrimKey =
  166. journalArticleResourceLocalService.getArticleResourcePrimKey(
  167. serviceContext.getUuid(), groupId, articleId);
  168. JournalArticle article = journalArticlePersistence.create(id);
  169. Locale locale = LocaleUtil.getDefault();
  170. String defaultLanguageId = GetterUtil.getString(
  171. serviceContext.getAttribute("defaultLanguageId"));
  172. if (Validator.isNotNull(defaultLanguageId)) {
  173. locale = LocaleUtil.fromLanguageId(defaultLanguageId);
  174. }
  175. String title = titleMap.get(locale);
  176. content = format(
  177. groupId, articleId, version, false, content, structureId, images);
  178. article.setResourcePrimKey(resourcePrimKey);
  179. article.setGroupId(groupId);
  180. article.setCompanyId(user.getCompanyId());
  181. article.setUserId(user.getUserId());
  182. article.setUserName(user.getFullName());
  183. article.setCreateDate(serviceContext.getCreateDate(now));
  184. article.setModifiedDate(serviceContext.getModifiedDate(now));
  185. article.setArticleId(articleId);
  186. article.setVersion(version);
  187. article.setTitleMap(titleMap, locale);
  188. article.setUrlTitle(getUniqueUrlTitle(id, groupId, articleId, title));
  189. article.setDescriptionMap(descriptionMap, locale);
  190. article.setContent(content);
  191. article.setType(type);
  192. article.setStructureId(structureId);
  193. article.setTemplateId(templateId);
  194. article.setLayoutUuid(layoutUuid);
  195. article.setDisplayDate(displayDate);
  196. article.setExpirationDate(expirationDate);
  197. article.setReviewDate(reviewDate);
  198. article.setIndexable(indexable);
  199. article.setSmallImage(smallImage);
  200. article.setSmallImageId(counterLocalService.increment());
  201. article.setSmallImageURL(smallImageURL);
  202. if ((expirationDate == null) || expirationDate.after(now)) {
  203. article.setStatus(WorkflowConstants.STATUS_DRAFT);
  204. }
  205. else {
  206. article.setStatus(WorkflowConstants.STATUS_EXPIRED);
  207. }
  208. journalArticlePersistence.update(article, false);
  209. // Resources
  210. if (serviceContext.getAddCommunityPermissions() ||
  211. serviceContext.getAddGuestPermissions()) {
  212. addArticleResources(
  213. article, serviceContext.getAddCommunityPermissions(),
  214. serviceContext.getAddGuestPermissions());
  215. }
  216. else {
  217. addArticleResources(
  218. article, serviceContext.getCommunityPermissions(),
  219. serviceContext.getGuestPermissions());
  220. }
  221. // Expando
  222. ExpandoBridge expandoBridge = article.getExpandoBridge();
  223. expandoBridge.setAttributes(serviceContext);
  224. // Small image
  225. saveImages(
  226. smallImage, article.getSmallImageId(), smallFile, smallBytes);
  227. // Asset
  228. updateAsset(
  229. userId, article, serviceContext.getAssetCategoryIds(),
  230. serviceContext.getAssetTagNames());
  231. // Message boards
  232. if (PropsValues.JOURNAL_ARTICLE_COMMENTS_ENABLED) {
  233. mbMessageLocalService.addDiscussionMessage(
  234. userId, article.getUserName(), groupId,
  235. JournalArticle.class.getName(), resourcePrimKey,
  236. WorkflowConstants.ACTION_PUBLISH);
  237. }
  238. // Email
  239. PortletPreferences preferences =
  240. ServiceContextUtil.getPortletPreferences(serviceContext);
  241. try {
  242. sendEmail(article, articleURL, preferences, "requested");
  243. }
  244. catch (IOException ioe) {
  245. throw new SystemException(ioe);
  246. }
  247. // Workflow
  248. WorkflowHandlerRegistryUtil.startWorkflowInstance(
  249. user.getCompanyId(), groupId, userId,
  250. JournalArticle.class.getName(), article.getResourcePrimKey(),
  251. article, serviceContext);
  252. return article;
  253. }
  254. public void addArticleResources(
  255. JournalArticle article, boolean addCommunityPermissions,
  256. boolean addGuestPermissions)
  257. throws PortalException, SystemException {
  258. resourceLocalService.addResources(
  259. article.getCompanyId(), article.getGroupId(),
  260. article.getUserId(), JournalArticle.class.getName(),
  261. article.getResourcePrimKey(), false, addCommunityPermissions,
  262. addGuestPermissions);
  263. }
  264. public void addArticleResources(
  265. JournalArticle article, String[] communityPermissions,
  266. String[] guestPermissions)
  267. throws PortalException, SystemException {
  268. resourceLocalService.addModelResources(
  269. article.getCompanyId(), article.getGroupId(),
  270. article.getUserId(), JournalArticle.class.getName(),
  271. article.getResourcePrimKey(), communityPermissions,
  272. guestPermissions);
  273. }
  274. public void addArticleResources(
  275. long groupId, String articleId, boolean addCommunityPermissions,
  276. boolean addGuestPermissions)
  277. throws PortalException, SystemException {
  278. JournalArticle article = getLatestArticle(groupId, articleId);
  279. addArticleResources(
  280. article, addCommunityPermissions, addGuestPermissions);
  281. }
  282. public void addArticleResources(
  283. long groupId, String articleId, String[] communityPermissions,
  284. String[] guestPermissions)
  285. throws PortalException, SystemException {
  286. JournalArticle article = getLatestArticle(groupId, articleId);
  287. addArticleResources(article, communityPermissions, guestPermissions);
  288. }
  289. public JournalArticle checkArticleResourcePrimKey(
  290. long groupId, String articleId, double version)
  291. throws PortalException, SystemException {
  292. JournalArticle article = journalArticlePersistence.findByG_A_V(
  293. groupId, articleId, version);
  294. if (article.getResourcePrimKey() > 0) {
  295. return article;
  296. }
  297. long resourcePrimKey =
  298. journalArticleResourceLocalService.getArticleResourcePrimKey(
  299. groupId, articleId);
  300. article.setResourcePrimKey(resourcePrimKey);
  301. journalArticlePersistence.update(article, false);
  302. return article;
  303. }
  304. public void checkArticles() throws PortalException, SystemException {
  305. Date now = new Date();
  306. List<JournalArticle> articles =
  307. journalArticleFinder.findByExpirationDate(
  308. WorkflowConstants.STATUS_APPROVED, now,
  309. new Date(now.getTime() - _JOURNAL_ARTICLE_CHECK_INTERVAL));
  310. if (_log.isDebugEnabled()) {
  311. _log.debug("Expiring " + articles.size() + " articles");
  312. }
  313. Set<Long> companyIds = new HashSet<Long>();
  314. for (JournalArticle article : articles) {
  315. article.setStatus(WorkflowConstants.STATUS_EXPIRED);
  316. journalArticlePersistence.update(article, false);
  317. if (article.isIndexable()) {
  318. Indexer indexer = IndexerRegistryUtil.getIndexer(
  319. JournalArticle.class);
  320. indexer.delete(article);
  321. }
  322. JournalContentUtil.clearCache(
  323. article.getGroupId(), article.getArticleId(),
  324. article.getTemplateId());
  325. companyIds.add(article.getCompanyId());
  326. }
  327. for (long companyId : companyIds) {
  328. CacheUtil.clearCache(companyId);
  329. }
  330. articles = journalArticleFinder.findByReviewDate(
  331. now, new Date(now.getTime() - _JOURNAL_ARTICLE_CHECK_INTERVAL));
  332. if (_log.isDebugEnabled()) {
  333. _log.debug(
  334. "Sending review notifications for " + articles.size() +
  335. " articles");
  336. }
  337. for (JournalArticle article : articles) {
  338. String articleURL = StringPool.BLANK;
  339. long ownerId = article.getGroupId();
  340. int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
  341. long plid = PortletKeys.PREFS_PLID_SHARED;
  342. String portletId = PortletKeys.JOURNAL;
  343. PortletPreferences preferences =
  344. portletPreferencesLocalService.getPreferences(
  345. article.getCompanyId(), ownerId, ownerType, plid,
  346. portletId);
  347. try {
  348. sendEmail(article, articleURL, preferences, "review");
  349. }
  350. catch (IOException ioe) {
  351. throw new SystemException(ioe);
  352. }
  353. }
  354. }
  355. public void checkNewLine(long groupId, String articleId, double version)
  356. throws PortalException, SystemException {
  357. JournalArticle article = journalArticlePersistence.findByG_A_V(
  358. groupId, articleId, version);
  359. String content = GetterUtil.getString(article.getContent());
  360. if (content.indexOf("\\n") != -1) {
  361. content = StringUtil.replace(
  362. content,
  363. new String[] {"\\n", "\\r"},
  364. new String[] {"\n", "\r"});
  365. article.setContent(content);
  366. journalArticlePersistence.update(article, false);
  367. }
  368. }
  369. public void checkStructure(long groupId, String articleId, double version)
  370. throws PortalException, SystemException {
  371. JournalArticle article = journalArticlePersistence.findByG_A_V(
  372. groupId, articleId, version);
  373. if (Validator.isNull(article.getStructureId())) {
  374. return;
  375. }
  376. try {
  377. checkStructure(article);
  378. }
  379. catch (DocumentException de) {
  380. _log.error(de, de);
  381. }
  382. }
  383. public JournalArticle copyArticle(
  384. long userId, long groupId, String oldArticleId, String newArticleId,
  385. boolean autoArticleId, double version)
  386. throws PortalException, SystemException {
  387. // Article
  388. User user = userPersistence.findByPrimaryKey(userId);
  389. oldArticleId = oldArticleId.trim().toUpperCase();
  390. newArticleId = newArticleId.trim().toUpperCase();
  391. Date now = new Date();
  392. JournalArticle oldArticle = journalArticlePersistence.findByG_A_V(
  393. groupId, oldArticleId, version);
  394. if (autoArticleId) {
  395. newArticleId = String.valueOf(counterLocalService.increment());
  396. }
  397. else {
  398. validate(newArticleId);
  399. JournalArticle newArticle = journalArticlePersistence.fetchByG_A_V(
  400. groupId, newArticleId, version);
  401. if (newArticle != null) {
  402. throw new DuplicateArticleIdException();
  403. }
  404. }
  405. long id = counterLocalService.increment();
  406. long resourcePrimKey =
  407. journalArticleResourceLocalService.getArticleResourcePrimKey(
  408. groupId, newArticleId);
  409. JournalArticle newArticle = journalArticlePersistence.create(id);
  410. newArticle.setResourcePrimKey(resourcePrimKey);
  411. newArticle.setGroupId(groupId);
  412. newArticle.setCompanyId(user.getCompanyId());
  413. newArticle.setUserId(user.getUserId());
  414. newArticle.setUserName(user.getFullName());
  415. newArticle.setCreateDate(now);
  416. newArticle.setModifiedDate(now);
  417. newArticle.setArticleId(newArticleId);
  418. newArticle.setVersion(JournalArticleConstants.DEFAULT_VERSION);
  419. newArticle.setTitle(oldArticle.getTitle());
  420. newArticle.setDescription(oldArticle.getDescription());
  421. try {
  422. copyArticleImages(oldArticle, newArticle);
  423. }
  424. catch (Exception e) {
  425. newArticle.setContent(oldArticle.getContent());
  426. }
  427. newArticle.setType(oldArticle.getType());
  428. newArticle.setStructureId(oldArticle.getStructureId());
  429. newArticle.setTemplateId(oldArticle.getTemplateId());
  430. newArticle.setLayoutUuid(oldArticle.getLayoutUuid());
  431. newArticle.setDisplayDate(oldArticle.getDisplayDate());
  432. newArticle.setExpirationDate(oldArticle.getExpirationDate());
  433. newArticle.setReviewDate(oldArticle.getReviewDate());
  434. newArticle.setIndexable(oldArticle.isIndexable());
  435. newArticle.setSmallImage(oldArticle.isSmallImage());
  436. newArticle.setSmallImageId(counterLocalService.increment());
  437. newArticle.setSmallImageURL(oldArticle.getSmallImageURL());
  438. newArticle.setStatus(oldArticle.getStatus());
  439. journalArticlePersistence.update(newArticle, false);
  440. // Resources
  441. addArticleResources(newArticle, true, true);
  442. // Small image
  443. if (oldArticle.getSmallImage()) {
  444. Image image = imageLocalService.getImage(
  445. oldArticle.getSmallImageId());
  446. byte[] smallBytes = image.getTextObj();
  447. imageLocalService.updateImage(
  448. newArticle.getSmallImageId(), smallBytes);
  449. }
  450. // Asset
  451. String[] assetTagNames = assetTagLocalService.getTagNames(
  452. JournalArticle.class.getName(), oldArticle.getResourcePrimKey());
  453. updateAsset(userId, newArticle, null, assetTagNames);
  454. return newArticle;
  455. }
  456. public void deleteArticle(
  457. JournalArticle article, String articleURL,
  458. ServiceContext serviceContext)
  459. throws PortalException, SystemException {
  460. if (article.isApproved() &&
  461. isLatestVersion(
  462. article.getGroupId(), article.getArticleId(),
  463. article.getVersion(), WorkflowConstants.STATUS_APPROVED)) {
  464. updatePreviousApprovedArticle(article);
  465. }
  466. // Email
  467. PortletPreferences preferences =
  468. ServiceContextUtil.getPortletPreferences(serviceContext);
  469. if ((preferences != null) && !article.isApproved() &&
  470. isLatestVersion(
  471. article.getGroupId(), article.getArticleId(),
  472. article.getVersion())) {
  473. try {
  474. sendEmail(article, articleURL, preferences, "denied");
  475. }
  476. catch (IOException ioe) {
  477. throw new SystemException(ioe);
  478. }
  479. }
  480. // Images
  481. journalArticleImageLocalService.deleteImages(
  482. article.getGroupId(), article.getArticleId(), article.getVersion());
  483. // Workflow
  484. workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(
  485. article.getCompanyId(), article.getGroupId(),
  486. JournalArticle.class.getName(), article.getResourcePrimKey());
  487. int articlesCount = journalArticlePersistence.countByG_A(
  488. article.getGroupId(), article.getArticleId());
  489. if (articlesCount == 1) {
  490. // Ratings
  491. ratingsStatsLocalService.deleteStats(
  492. JournalArticle.class.getName(), article.getResourcePrimKey());
  493. // Message boards
  494. mbMessageLocalService.deleteDiscussionMessages(
  495. JournalArticle.class.getName(), article.getResourcePrimKey());
  496. // Asset
  497. assetEntryLocalService.deleteEntry(
  498. JournalArticle.class.getName(), article.getResourcePrimKey());
  499. // Content searches
  500. journalContentSearchLocalService.deleteArticleContentSearches(
  501. article.getGroupId(), article.getArticleId());
  502. // Small image
  503. imageLocalService.deleteImage(article.getSmallImageId());
  504. // Expando
  505. expandoValueLocalService.deleteValues(
  506. JournalArticle.class.getName(), article.getResourcePrimKey());
  507. // Resources
  508. resourceLocalService.deleteResource(
  509. article.getCompanyId(), JournalArticle.class.getName(),
  510. ResourceConstants.SCOPE_INDIVIDUAL,
  511. article.getResourcePrimKey());
  512. // Resource
  513. try {
  514. journalArticleResourceLocalService.deleteArticleResource(
  515. article.getGroupId(), article.getArticleId());
  516. }
  517. catch (NoSuchArticleResourceException nsare) {
  518. }
  519. }
  520. // Article
  521. journalArticlePersistence.remove(article);
  522. }
  523. public void deleteArticle(
  524. long groupId, String articleId, double version, String articleURL,
  525. ServiceContext serviceContext)
  526. throws PortalException, SystemException {
  527. JournalArticle article = journalArticlePersistence.findByG_A_V(
  528. groupId, articleId, version);
  529. deleteArticle(article, articleURL, serviceContext);
  530. }
  531. public void deleteArticle(
  532. long groupId, String articleId, ServiceContext serviceContext)
  533. throws PortalException, SystemException {
  534. List<JournalArticle> articles = journalArticlePersistence.findByG_A(
  535. groupId, articleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  536. new ArticleVersionComparator(true));
  537. for (JournalArticle article : articles) {
  538. deleteArticle(article, null, serviceContext);
  539. }
  540. }
  541. public void deleteArticles(long groupId)
  542. throws PortalException, SystemException {
  543. for (JournalArticle article :
  544. journalArticlePersistence.findByGroupId(groupId)) {
  545. deleteArticle(article, null, null);
  546. }
  547. }
  548. public JournalArticle expireArticle(
  549. long userId, long groupId, String articleId, double version,
  550. String articleURL, ServiceContext serviceContext)
  551. throws PortalException, SystemException {
  552. return updateStatus(
  553. userId, groupId, articleId, version,
  554. WorkflowConstants.STATUS_EXPIRED, articleURL, serviceContext);
  555. }
  556. public void expireArticle(
  557. long userId, long groupId, String articleId, String articleURL,
  558. ServiceContext serviceContext)
  559. throws PortalException, SystemException {
  560. List<JournalArticle> articles = journalArticlePersistence.findByG_A(
  561. groupId, articleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  562. new ArticleVersionComparator(true));
  563. for (JournalArticle article : articles) {
  564. expireArticle(
  565. userId, groupId, article.getArticleId(), article.getVersion(),
  566. articleURL, serviceContext);
  567. }
  568. }
  569. public JournalArticle getArticle(long id)
  570. throws PortalException, SystemException {
  571. return journalArticlePersistence.findByPrimaryKey(id);
  572. }
  573. public JournalArticle getArticle(long groupId, String articleId)
  574. throws PortalException, SystemException {
  575. // Get the latest article that is approved, if none are approved, get
  576. // the latest unapproved article
  577. try {
  578. return getLatestArticle(
  579. groupId, articleId, WorkflowConstants.STATUS_APPROVED);
  580. }
  581. catch (NoSuchArticleException nsae) {
  582. return getLatestArticle(
  583. groupId, articleId, WorkflowConstants.STATUS_ANY);
  584. }
  585. }
  586. public JournalArticle getArticle(
  587. long groupId, String articleId, double version)
  588. throws PortalException, SystemException {
  589. return journalArticlePersistence.findByG_A_V(
  590. groupId, articleId, version);
  591. }
  592. public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle)
  593. throws PortalException, SystemException {
  594. // Get the latest article that is approved, if none are approved, get
  595. // the latest unapproved article
  596. try {
  597. return getLatestArticleByUrlTitle(
  598. groupId, urlTitle, WorkflowConstants.STATUS_APPROVED);
  599. }
  600. catch (NoSuchArticleException nsae) {
  601. return getLatestArticleByUrlTitle(
  602. groupId, urlTitle, WorkflowConstants.STATUS_PENDING);
  603. }
  604. }
  605. public String getArticleContent(
  606. JournalArticle article, String templateId, String viewMode,
  607. String languageId, ThemeDisplay themeDisplay)
  608. throws PortalException, SystemException {
  609. JournalArticleDisplay articleDisplay = getArticleDisplay(
  610. article, templateId, viewMode, languageId, 1, null, themeDisplay);
  611. if (articleDisplay == null) {
  612. return StringPool.BLANK;
  613. }
  614. else {
  615. return articleDisplay.getContent();
  616. }
  617. }
  618. public String getArticleContent(
  619. long groupId, String articleId, double version, String viewMode,
  620. String templateId, String languageId, ThemeDisplay themeDisplay)
  621. throws PortalException, SystemException {
  622. JournalArticleDisplay articleDisplay = getArticleDisplay(
  623. groupId, articleId, version, templateId, viewMode, languageId,
  624. themeDisplay);
  625. if (articleDisplay == null) {
  626. return StringPool.BLANK;
  627. }
  628. else {
  629. return articleDisplay.getContent();
  630. }
  631. }
  632. public String getArticleContent(
  633. long groupId, String articleId, double version, String viewMode,
  634. String languageId, ThemeDisplay themeDisplay)
  635. throws PortalException, SystemException {
  636. return getArticleContent(
  637. groupId, articleId, version, viewMode, null, languageId,
  638. themeDisplay);
  639. }
  640. public String getArticleContent(
  641. long groupId, String articleId, String viewMode, String templateId,
  642. String languageId, ThemeDisplay themeDisplay)
  643. throws PortalException, SystemException {
  644. JournalArticleDisplay articleDisplay = getArticleDisplay(
  645. groupId, articleId, templateId, viewMode, languageId, themeDisplay);
  646. return articleDisplay.getContent();
  647. }
  648. public String getArticleContent(
  649. long groupId, String articleId, String viewMode, String languageId,
  650. ThemeDisplay themeDisplay)
  651. throws PortalException, SystemException {
  652. return getArticleContent(
  653. groupId, articleId, viewMode, null, languageId, themeDisplay);
  654. }
  655. public JournalArticleDisplay getArticleDisplay(
  656. JournalArticle article, String templateId, String viewMode,
  657. String languageId, int page, String xmlRequest,
  658. ThemeDisplay themeDisplay)
  659. throws PortalException, SystemException {
  660. String content = null;
  661. if (page < 1) {
  662. page = 1;
  663. }
  664. int numberOfPages = 1;
  665. boolean paginate = false;
  666. boolean pageFlow = false;
  667. boolean cacheable = true;
  668. if (Validator.isNull(xmlRequest)) {
  669. xmlRequest = "<request />";
  670. }
  671. Map<String, String> tokens = JournalUtil.getTokens(
  672. article.getGroupId(), themeDisplay, xmlRequest);
  673. tokens.put(
  674. "article_resource_pk",
  675. String.valueOf(article.getResourcePrimKey()));
  676. String defaultTemplateId = article.getTemplateId();
  677. if (article.isTemplateDriven()) {
  678. if (Validator.isNull(templateId)) {
  679. templateId = defaultTemplateId;
  680. }
  681. tokens.put("structure_id", article.getStructureId());
  682. tokens.put("template_id", templateId);
  683. }
  684. String xml = article.getContent();
  685. try {
  686. Document doc = null;
  687. Element root = null;
  688. if (article.isTemplateDriven()) {
  689. doc = SAXReaderUtil.read(xml);
  690. root = doc.getRootElement();
  691. Document request = SAXReaderUtil.read(xmlRequest);
  692. List<Element> pages = root.elements("page");
  693. if (pages.size() > 0) {
  694. pageFlow = true;
  695. String targetPage = request.valueOf(
  696. "/request/parameters/parameter[name='targetPage']/" +
  697. "value");
  698. Element pageEl = null;
  699. if (Validator.isNotNull(targetPage)) {
  700. XPath xpathSelector = SAXReaderUtil.createXPath(
  701. "/root/page[@id = '" + targetPage + "']");
  702. pageEl = (Element)xpathSelector.selectSingleNode(doc);
  703. }
  704. if (pageEl != null) {
  705. doc = SAXReaderUtil.createDocument(pageEl);
  706. root = doc.getRootElement();
  707. numberOfPages = pages.size();
  708. }
  709. else {
  710. if (page > pages.size()) {
  711. page = 1;
  712. }
  713. pageEl = pages.get(page - 1);
  714. doc = SAXReaderUtil.createDocument(pageEl);
  715. root = doc.getRootElement();
  716. numberOfPages = pages.size();
  717. paginate = true;
  718. }
  719. }
  720. root.add(request.getRootElement().createCopy());
  721. JournalUtil.addAllReservedEls(root, tokens, article);
  722. xml = DDMXMLUtil.formatXML(doc);
  723. }
  724. }
  725. catch (DocumentException de) {
  726. throw new SystemException(de);
  727. }
  728. catch (IOException ioe) {
  729. throw new SystemException(ioe);
  730. }
  731. try {
  732. if (_log.isDebugEnabled()) {
  733. _log.debug(
  734. "Transforming " + article.getArticleId() + " " +
  735. article.getVersion() + " " + languageId);
  736. }
  737. String script = null;
  738. String langType = null;
  739. if (article.isTemplateDriven()) {
  740. // Try with specified template first (in the current group and
  741. // the global group). If a template is not specified, use the
  742. // default one. If the specified template does not exit, use the
  743. // default one. If the default one does not exist, throw an
  744. // exception.
  745. JournalTemplate template = null;
  746. try {
  747. template = journalTemplatePersistence.findByG_T(
  748. article.getGroupId(), templateId);
  749. }
  750. catch (NoSuchTemplateException nste1) {
  751. try {
  752. Group companyGroup = groupLocalService.getCompanyGroup(
  753. article.getCompanyId());
  754. template = journalTemplatePersistence.findByG_T(
  755. companyGroup.getGroupId(), templateId);
  756. tokens.put(
  757. "group_id",
  758. String.valueOf(companyGroup.getGroupId()));
  759. }
  760. catch (NoSuchTemplateException nste2) {
  761. if (!defaultTemplateId.equals(templateId)) {
  762. template = journalTemplatePersistence.findByG_T(
  763. article.getGroupId(), defaultTemplateId);
  764. }
  765. else {
  766. throw nste1;
  767. }
  768. }
  769. }
  770. script = template.getXsl();
  771. langType = template.getLangType();
  772. cacheable = template.isCacheable();
  773. }
  774. content = JournalUtil.transform(
  775. themeDisplay, tokens, viewMode, languageId, xml, script,
  776. langType);
  777. if (!pageFlow) {
  778. String[] pieces = StringUtil.split(
  779. content, PropsValues.JOURNAL_ARTICLE_TOKEN_PAGE_BREAK);
  780. if (pieces.length > 1) {
  781. if (page > pieces.length) {
  782. page = 1;
  783. }
  784. content = pieces[page - 1];
  785. numberOfPages = pieces.length;
  786. paginate = true;
  787. }
  788. }
  789. }
  790. catch (Exception e) {
  791. throw new SystemException(e);
  792. }
  793. return new JournalArticleDisplayImpl(
  794. article.getCompanyId(), article.getId(),
  795. article.getResourcePrimKey(), article.getGroupId(),
  796. article.getUserId(), article.getArticleId(), article.getVersion(),
  797. article.getTitle(languageId), article.getUrlTitle(),
  798. article.getDescription(languageId), article.getAvailableLocales(),
  799. content, article.getType(), article.getStructureId(), templateId,
  800. article.isSmallImage(), article.getSmallImageId(),
  801. article.getSmallImageURL(), numberOfPages, page, paginate,
  802. cacheable);
  803. }
  804. public JournalArticleDisplay getArticleDisplay(
  805. long groupId, String articleId, double version, String templateId,
  806. String viewMode, String languageId, int page, String xmlRequest,
  807. ThemeDisplay themeDisplay)
  808. throws PortalException, SystemException {
  809. Date now = new Date();
  810. JournalArticle article = journalArticlePersistence.findByG_A_V(
  811. groupId, articleId, version);
  812. if (article.isExpired()) {
  813. Date expirationDate = article.getExpirationDate();
  814. if ((expirationDate != null) && expirationDate.before(now)) {
  815. return null;
  816. }
  817. }
  818. if (article.getDisplayDate().after(now)) {
  819. return null;
  820. }
  821. return getArticleDisplay(
  822. article, templateId, viewMode, languageId, page, xmlRequest,
  823. themeDisplay);
  824. }
  825. public JournalArticleDisplay getArticleDisplay(
  826. long groupId, String articleId, double version, String templateId,
  827. String viewMode, String languageId, ThemeDisplay themeDisplay)
  828. throws PortalException, SystemException {
  829. return getArticleDisplay(
  830. groupId, articleId, version, templateId, viewMode, languageId, 1,
  831. null, themeDisplay);
  832. }
  833. public JournalArticleDisplay getArticleDisplay(
  834. long groupId, String articleId, String viewMode, String languageId,
  835. int page, String xmlRequest, ThemeDisplay themeDisplay)
  836. throws PortalException, SystemException {
  837. return getArticleDisplay(
  838. groupId, articleId, null, viewMode, languageId, page, xmlRequest,
  839. themeDisplay);
  840. }
  841. public JournalArticleDisplay getArticleDisplay(
  842. long groupId, String articleId, String templateId, String viewMode,
  843. String languageId, int page, String xmlRequest,
  844. ThemeDisplay themeDisplay)
  845. throws PortalException, SystemException {
  846. JournalArticle article = getDisplayArticle(groupId, articleId);
  847. return getArticleDisplay(
  848. groupId, articleId, article.getVersion(), templateId, viewMode,
  849. languageId, page, xmlRequest, themeDisplay);
  850. }
  851. public JournalArticleDisplay getArticleDisplay(
  852. long groupId, String articleId, String templateId, String viewMode,
  853. String languageId, ThemeDisplay themeDisplay)
  854. throws PortalException, SystemException {
  855. JournalArticle article = getDisplayArticle(groupId, articleId);
  856. return getArticleDisplay(
  857. groupId, articleId, article.getVersion(), templateId, viewMode,
  858. languageId, themeDisplay);
  859. }
  860. public JournalArticleDisplay getArticleDisplay(
  861. long groupId, String articleId, String viewMode, String languageId,
  862. ThemeDisplay themeDisplay)
  863. throws PortalException, SystemException {
  864. return getArticleDisplay(
  865. groupId, articleId, null, viewMode, languageId, themeDisplay);
  866. }
  867. public List<JournalArticle> getArticles() throws SystemException {
  868. return journalArticlePersistence.findAll();
  869. }
  870. public List<JournalArticle> getArticles(long groupId)
  871. throws SystemException {
  872. return journalArticlePersistence.findByGroupId(groupId);
  873. }
  874. public List<JournalArticle> getArticles(long groupId, int start, int end)
  875. throws SystemException {
  876. return journalArticlePersistence.findByGroupId(groupId, start, end);
  877. }
  878. public List<JournalArticle> getArticles(
  879. long groupId, int start, int end, OrderByComparator obc)
  880. throws SystemException {
  881. return journalArticlePersistence.findByGroupId(
  882. groupId, start, end, obc);
  883. }
  884. public List<JournalArticle> getArticles(long groupId, String articleId)
  885. throws SystemException {
  886. return journalArticlePersistence.findByG_A(groupId, articleId);
  887. }
  888. public List<JournalArticle> getArticlesBySmallImageId(long smallImageId)
  889. throws SystemException {
  890. return journalArticlePersistence.findBySmallImageId(smallImageId);
  891. }
  892. public int getArticlesCount(long groupId) throws SystemException {
  893. return journalArticlePersistence.countByGroupId(groupId);
  894. }
  895. public List<JournalArticle> getCompanyArticles(
  896. long companyId, int status, int start, int end)
  897. throws SystemException {
  898. if (status == WorkflowConstants.STATUS_ANY) {
  899. return journalArticlePersistence.findByCompanyId(
  900. companyId, start, end, new ArticleIDComparator(true));
  901. }
  902. else {
  903. return journalArticlePersistence.findByC_ST(
  904. companyId, status, start, end, new ArticleIDComparator(true));
  905. }
  906. }
  907. public int getCompanyArticlesCount(long companyId, int status)
  908. throws SystemException {
  909. if (status == WorkflowConstants.STATUS_ANY) {
  910. return journalArticlePersistence.countByCompanyId(companyId);
  911. }
  912. else {
  913. return journalArticlePersistence.countByC_ST(companyId, status);
  914. }
  915. }
  916. public JournalArticle getDisplayArticle(long groupId, String articleId)
  917. throws PortalException, SystemException {
  918. List<JournalArticle> articles = journalArticlePersistence.findByG_A_ST(
  919. groupId, articleId, WorkflowConstants.STATUS_APPROVED);
  920. if (articles.size() == 0) {
  921. throw new NoSuchArticleException(
  922. "No approved JournalArticle with the key {groupId=" + groupId +
  923. ", " + "articleId=" + articleId + "}");
  924. }
  925. Date now = new Date();
  926. for (int i = 0; i < articles.size(); i++) {
  927. JournalArticle article = articles.get(i);
  928. Date expirationDate = article.getExpirationDate();
  929. if (article.getDisplayDate().before(now) &&
  930. ((expirationDate == null) || expirationDate.after(now))) {
  931. return article;
  932. }
  933. }
  934. return articles.get(0);
  935. }
  936. public JournalArticle getLatestArticle(long resourcePrimKey)
  937. throws PortalException, SystemException {
  938. return getLatestArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);
  939. }
  940. public JournalArticle getLatestArticle(long resourcePrimKey, int status)
  941. throws PortalException, SystemException {
  942. return getLatestArticle(resourcePrimKey, status, true);
  943. }
  944. public JournalArticle getLatestArticle(
  945. long resourcePrimKey, int status, boolean preferApproved)
  946. throws PortalException, SystemException {
  947. List<JournalArticle> articles = null;
  948. OrderByComparator orderByComparator = new ArticleVersionComparator();
  949. if (status == WorkflowConstants.STATUS_ANY) {
  950. if (preferApproved) {
  951. articles = journalArticlePersistence.findByR_ST(
  952. resourcePrimKey, WorkflowConstants.STATUS_APPROVED, 0, 1,
  953. orderByComparator);
  954. }
  955. if ((articles == null) || (articles.size() == 0)) {
  956. articles = journalArticlePersistence.findByResourcePrimKey(
  957. resourcePrimKey, 0, 1, orderByComparator);
  958. }
  959. }
  960. else {
  961. articles = journalArticlePersistence.findByR_ST(
  962. resourcePrimKey, status, 0, 1, orderByComparator);
  963. }
  964. if (articles.size() == 0) {
  965. throw new NoSuchArticleException(
  966. "No JournalArticle with the key {resourcePrimKey=" +
  967. resourcePrimKey + "}");
  968. }
  969. return articles.get(0);
  970. }
  971. public JournalArticle getLatestArticle(long groupId, String articleId)
  972. throws PortalException, SystemException {
  973. return getLatestArticle(
  974. groupId, articleId, WorkflowConstants.STATUS_ANY);
  975. }
  976. public JournalArticle getLatestArticle(
  977. long groupId, String articleId, int status)
  978. throws PortalException, SystemException {
  979. List<JournalArticle> articles = null;
  980. OrderByComparator orderByComparator = new ArticleVersionComparator();
  981. if (status == WorkflowConstants.STATUS_ANY) {
  982. articles = journalArticlePersistence.findByG_A(
  983. groupId, articleId, 0, 1, orderByComparator);
  984. }
  985. else {
  986. articles = journalArticlePersistence.findByG_A_ST(
  987. groupId, articleId, status, 0, 1, orderByComparator);
  988. }
  989. if (articles.size() == 0) {
  990. throw new NoSuchArticleException(
  991. "No JournalArticle with the key {groupId=" + groupId +
  992. ", articleId=" + articleId + ", status=" + status + "}");
  993. }
  994. return articles.get(0);
  995. }
  996. public JournalArticle getLatestArticleByUrlTitle(
  997. long groupId, String urlTitle, int status)
  998. throws PortalException, SystemException {
  999. List<JournalArticle> articles = null;
  1000. OrderByComparator orderByComparator = new ArticleVersionComparator();
  1001. if (status == WorkflowConstants.STATUS_ANY) {
  1002. articles = journalArticlePersistence.findByG_UT(
  1003. groupId, urlTitle, 0, 1, orderByComparator);
  1004. }
  1005. else {
  1006. articles = journalArticlePersistence.findByG_UT_ST(
  1007. groupId, urlTitle, status, 0, 1, orderByComparator);
  1008. }
  1009. if (articles.size() == 0) {
  1010. throw new NoSuchArticleException(
  1011. "No JournalArticle with the key {groupId=" + groupId +
  1012. ", urlTitle=" + urlTitle + ", status=" + status + "}");
  1013. }
  1014. return articles.get(0);
  1015. }
  1016. public double getLatestVersion(long groupId, String articleId)
  1017. throws PortalException, SystemException {
  1018. JournalArticle article = getLatestArticle(groupId, articleId);
  1019. return article.getVersion();
  1020. }
  1021. public double getLatestVersion(
  1022. long groupId, String articleId, int status)
  1023. throws PortalException, SystemException {
  1024. JournalArticle article = getLatestArticle(groupId, articleId, status);
  1025. return article.getVersion();
  1026. }
  1027. public List<JournalArticle> getStructureArticles(
  1028. long groupId, String structureId)
  1029. throws SystemException {
  1030. return journalArticlePersistence.findByG_S(groupId, structureId);
  1031. }
  1032. public List<JournalArticle> getStructureArticles(
  1033. long groupId, String structureId, int start, int end,
  1034. OrderByComparator obc)
  1035. throws SystemException {
  1036. return journalArticlePersistence.findByG_S(
  1037. groupId, structureId, start, end, obc);
  1038. }
  1039. public int getStructureArticlesCount(long groupId, String structureId)
  1040. throws SystemException {
  1041. return journalArticlePersistence.countByG_S(groupId, structureId);
  1042. }
  1043. public List<JournalArticle> getTemplateArticles(
  1044. long groupId, String templateId)
  1045. throws SystemException {
  1046. return journalArticlePersistence.findByG_T(groupId, templateId);
  1047. }
  1048. public List<JournalArticle> getTemplateArticles(
  1049. long groupId, String templateId, int start, int end,
  1050. OrderByComparator obc)
  1051. throws SystemException {
  1052. return journalArticlePersistence.findByG_T(
  1053. groupId, templateId, start, end, obc);
  1054. }
  1055. public int getTemplateArticlesCount(long groupId, String templateId)
  1056. throws SystemException {
  1057. return journalArticlePersistence.countByG_T(groupId, templateId);
  1058. }
  1059. public boolean hasArticle(long groupId, String articleId)
  1060. throws SystemException {
  1061. try {
  1062. getArticle(groupId, articleId);
  1063. return true;
  1064. }
  1065. catch (PortalException pe) {
  1066. return false;
  1067. }
  1068. }
  1069. public boolean isLatestVersion(
  1070. long groupId, String articleId, double version)
  1071. throws PortalException, SystemException {
  1072. if (getLatestVersion(groupId, articleId) == version) {
  1073. return true;
  1074. }
  1075. else {
  1076. return false;
  1077. }
  1078. }
  1079. public boolean isLatestVersion(
  1080. long groupId, String articleId, double version, int status)
  1081. throws PortalException, SystemException {
  1082. if (getLatestVersion(groupId, articleId, status) == version) {
  1083. return true;
  1084. }
  1085. else {
  1086. return false;
  1087. }
  1088. }
  1089. public JournalArticle removeArticleLocale(
  1090. long groupId, String articleId, double version, String languageId)
  1091. throws PortalException, SystemException {
  1092. JournalArticle article = journalArticlePersistence.findByG_A_V(
  1093. groupId, articleId, version);
  1094. String title = article.getTitle();
  1095. title = LocalizationUtil.removeLocalization(
  1096. title, "static-content", languageId, true);
  1097. article.setTitle(title);
  1098. String description = article.getDescription();
  1099. description = LocalizationUtil.removeLocalization(
  1100. description, "static-content", languageId, true);
  1101. article.setDescription(description);
  1102. String content = article.getContent();
  1103. if (article.isTemplateDriven()) {
  1104. content = JournalUtil.removeArticleLocale(content, languageId);
  1105. }
  1106. else {
  1107. content = LocalizationUtil.removeLocalization(
  1108. content, "static-content", languageId, true);
  1109. }
  1110. article.setContent(content);
  1111. journalArticlePersistence.update(article, false);
  1112. return article;
  1113. }
  1114. public List<JournalArticle> search(
  1115. long companyId, long groupId, String keywords, Double version,
  1116. String type, String structureId, String templateId,
  1117. Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
  1118. int start, int end, OrderByComparator obc)
  1119. throws SystemException {
  1120. return journalArticleFinder.findByKeywords(
  1121. companyId, groupId, keywords, version, type, structureId,
  1122. templateId, displayDateGT, displayDateLT, status, reviewDate, start,
  1123. end, obc);
  1124. }
  1125. public List<JournalArticle> search(
  1126. long companyId, long groupId, String articleId, Double version,
  1127. String title, String description, String content, String type,
  1128. String structureId, String templateId, Date displayDateGT,
  1129. Date displayDateLT, int status, Date reviewDate,
  1130. boolean andOperator, int start, int end, OrderByComparator obc)
  1131. throws SystemException {
  1132. return journalArticleFinder.findByC_G_A_V_T_D_C_T_S_T_D_S_R(
  1133. companyId, groupId, articleId, version, title, description, content,
  1134. type, structureId, templateId, displayDateGT, displayDateLT,
  1135. status, reviewDate, andOperator, start, end, obc);
  1136. }
  1137. public List<JournalArticle> search(
  1138. long companyId, long groupId, String articleId, Double version,
  1139. String title, String description, String content, String type,
  1140. String[] structureIds, String[] templateIds, Date displayDateGT,
  1141. Date displayDateLT, int status, Date reviewDate,
  1142. boolean andOperator, int start, int end, OrderByComparator obc)
  1143. throws SystemException {
  1144. return journalArticleFinder.findByC_G_A_V_T_D_C_T_S_T_D_S_R(
  1145. companyId, groupId, articleId, version, title, description, content,
  1146. type, structureIds, templateIds, displayDateGT, displayDateLT,
  1147. status, reviewDate, andOperator, start, end, obc);
  1148. }
  1149. public int searchCount(
  1150. long companyId, long groupId, String keywords, Double version,
  1151. String type, String structureId, String templateId,
  1152. Date displayDateGT, Date displayDateLT, int status, Date reviewDate)
  1153. throws SystemException {
  1154. return journalArticleFinder.countByKeywords(
  1155. companyId, groupId, keywords, version, type, structureId,
  1156. templateId, displayDateGT, displayDateLT, status, reviewDate);
  1157. }
  1158. public int searchCount(
  1159. long companyId, long groupId, String articleId, Double version,
  1160. String title, String description, String content, String type,
  1161. String structureId, String templateId, Date displayDateGT,
  1162. Date displayDateLT, int status, Date reviewDate,
  1163. boolean andOperator)
  1164. throws SystemException {
  1165. return journalArticleFinder.countByC_G_A_V_T_D_C_T_S_T_D_S_R(
  1166. companyId, groupId, articleId, version, title, description, content,
  1167. type, structureId, templateId, displayDateGT, displayDateLT,
  1168. status, reviewDate, andOperator);
  1169. }
  1170. public int searchCount(
  1171. long companyId, long groupId, String articleId, Double version,
  1172. String title, String description, String content, String type,
  1173. String[] structureIds, String[] templateIds, Date displayDateGT,
  1174. Date displayDateLT, int status, Date reviewDate,
  1175. boolean andOperator)
  1176. throws SystemException {
  1177. return journalArticleFinder.countByC_G_A_V_T_D_C_T_S_T_D_S_R(
  1178. companyId, groupId, articleId, version, title, description, content,
  1179. type, structureIds, templateIds, displayDateGT, displayDateLT,
  1180. status, reviewDate, andOperator);
  1181. }
  1182. public void subscribe(long userId, long groupId)
  1183. throws PortalException, SystemException {
  1184. subscriptionLocalService.addSubscription(
  1185. userId, groupId, JournalArticle.class.getName(), groupId);
  1186. }
  1187. public void unsubscribe(long userId, long groupId)
  1188. throws PortalException, SystemException {
  1189. subscriptionLocalService.deleteSubscription(
  1190. userId, JournalArticle.class.getName(), groupId);
  1191. }
  1192. public JournalArticle updateArticle(
  1193. long userId, long groupId, String articleId, double version,
  1194. Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
  1195. String content, String layoutUuid, ServiceContext serviceContext)
  1196. throws PortalException, SystemException {
  1197. User user = userPersistence.findByPrimaryKey(userId);
  1198. JournalArticle article = journalArticlePersistence.findByG_A_V(
  1199. groupId, articleId, version);
  1200. Date displayDate = article.getDisplayDate();
  1201. int displayDateMonth = 0;
  1202. int displayDateDay = 0;
  1203. int displayDateYear = 0;
  1204. int displayDateHour = 0;
  1205. int displayDateMinute = 0;
  1206. if (displayDate != null) {
  1207. Calendar displayCal = CalendarFactoryUtil.getCalendar(
  1208. user.getTimeZone());
  1209. displayCal.setTime(displayDate);
  1210. displayDateMonth = displayCal.get(Calendar.MONTH);
  1211. displayDateDay = displayCal.get(Calendar.DATE);
  1212. displayDateYear = displayCal.get(Calendar.YEAR);
  1213. displayDateHour = displayCal.get(Calendar.HOUR);
  1214. displayDateMinute = displayCal.get(Calendar.MINUTE);
  1215. if (displayCal.get(Calendar.AM_PM) == Calendar.PM) {
  1216. displayDateHour += 12;
  1217. }
  1218. }
  1219. Date expirationDate = article.getExpirationDate();
  1220. int expirationDateMonth = 0;
  1221. int expirationDateDay = 0;
  1222. int expirationDateYear = 0;
  1223. int expirationDateHour = 0;
  1224. int expirationDateMinute = 0;
  1225. boolean neverExpire = true;
  1226. if (expirationDate != null) {
  1227. Calendar expirationCal = CalendarFactoryUtil.getCalendar(
  1228. user.getTimeZone());
  1229. expirationCal.setTime(expirationDate);
  1230. expirationDateMonth = expirationCal.get(Calendar.MONTH);
  1231. expirationDateDay = expirationCal.get(Calendar.DATE);
  1232. expirationDateYear = expirationCal.get(Calendar.YEAR);
  1233. expirationDateHour = expirationCal.get(Calendar.HOUR);
  1234. expirationDateMinute = expirationCal.get(Calendar.MINUTE);
  1235. neverExpire = false;
  1236. if (expirationCal.get(Calendar.AM_PM) == Calendar.PM) {
  1237. expirationDateHour += 12;
  1238. }
  1239. }
  1240. Date reviewDate = article.getReviewDate();
  1241. int reviewDateMonth = 0;
  1242. int reviewDateDay = 0;
  1243. int reviewDateYear = 0;
  1244. int reviewDateHour = 0;
  1245. int reviewDateMinute = 0;
  1246. boolean neverReview = true;
  1247. if (reviewDate != null) {
  1248. Calendar reviewCal = CalendarFactoryUtil.getCalendar(
  1249. user.getTimeZone());
  1250. reviewCal.setTime(reviewDate);
  1251. reviewDateMonth = reviewCal.get(Calendar.MONTH);
  1252. reviewDateDay = reviewCal.get(Calendar.DATE);
  1253. reviewDateYear = reviewCal.get(Calendar.YEAR);
  1254. reviewDateHour = reviewCal.get(Calendar.HOUR);
  1255. reviewDateMinute = reviewCal.get(Calendar.MINUTE);
  1256. neverReview = false;
  1257. if (reviewCal.get(Calendar.AM_PM) == Calendar.PM) {
  1258. reviewDateHour += 12;
  1259. }
  1260. }
  1261. return updateArticle(
  1262. userId, groupId, articleId, version, titleMap, descriptionMap,
  1263. content, article.getType(), article.getStructureId(),
  1264. article.getTemplateId(), layoutUuid, displayDateMonth,
  1265. displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
  1266. expirationDateMonth, expirationDateDay, expirationDateYear,
  1267. expirationDateHour, expirationDateMinute, neverExpire,
  1268. reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
  1269. reviewDateMinute, neverReview, article.getIndexable(),
  1270. article.isSmallImage(), article.getSmallImageURL(), null, null,
  1271. null, serviceContext);
  1272. }
  1273. public JournalArticle updateArticle(
  1274. long userId, long groupId, String articleId, double version,
  1275. Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
  1276. String content, String type, String struct