1
22
23 package com.liferay.portal.verify;
24
25 import com.liferay.portal.service.ResourceLocalServiceUtil;
26 import com.liferay.portlet.journal.model.JournalArticle;
27 import com.liferay.portlet.journal.model.JournalStructure;
28 import com.liferay.portlet.journal.model.JournalTemplate;
29 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
30 import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
31 import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
32 import com.liferay.portlet.tags.NoSuchAssetException;
33 import com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil;
34
35 import java.util.List;
36
37 import org.apache.commons.logging.Log;
38 import org.apache.commons.logging.LogFactory;
39
40
46 public class VerifyJournal extends VerifyProcess {
47
48 public void verify() throws VerifyException {
49 _log.info("Verifying integrity");
50
51 try {
52 verifyJournal();
53 }
54 catch (Exception e) {
55 throw new VerifyException(e);
56 }
57 }
58
59 protected void verifyJournal() throws Exception {
60
61
63 List structures = JournalStructureLocalServiceUtil.getStructures();
64
65 for (int i = 0; i < structures.size(); i++) {
66 JournalStructure structure = (JournalStructure)structures.get(i);
67
68 ResourceLocalServiceUtil.addResources(
69 structure.getCompanyId(), 0, 0,
70 JournalStructure.class.getName(), structure.getId(), false,
71 true, true);
72 }
73
74 if (_log.isDebugEnabled()) {
75 _log.debug("Permissions verified for Journal structures");
76 }
77
78
80 List templates = JournalTemplateLocalServiceUtil.getTemplates();
81
82 for (int i = 0; i < templates.size(); i++) {
83 JournalTemplate template = (JournalTemplate)templates.get(i);
84
85 ResourceLocalServiceUtil.addResources(
86 template.getCompanyId(), 0, 0,
87 JournalTemplate.class.getName(), template.getId(), false, true,
88 true);
89 }
90
91 if (_log.isDebugEnabled()) {
92 _log.debug("Permissions verified for Journal templates");
93 }
94
95
97 List articles = JournalArticleLocalServiceUtil.getArticles();
98
99 for (int i = 0; i < articles.size(); i++) {
100 JournalArticle article = (JournalArticle)articles.get(i);
101
102 if (article.getResourcePrimKey() <= 0) {
103 article =
104 JournalArticleLocalServiceUtil.checkArticleResourcePrimKey(
105 article.getGroupId(), article.getArticleId(),
106 article.getVersion());
107 }
108
109 ResourceLocalServiceUtil.addResources(
110 article.getCompanyId(), 0, 0,
111 JournalArticle.class.getName(), article.getResourcePrimKey(),
112 false, true, true);
113
114 try {
115 TagsAssetLocalServiceUtil.getAsset(
116 JournalArticle.class.getName(),
117 article.getResourcePrimKey());
118 }
119 catch (NoSuchAssetException nsae) {
120 try {
121 JournalArticleLocalServiceUtil.updateTagsAsset(
122 article.getUserId(), article, new String[0]);
123 }
124 catch (Exception e) {
125 if (_log.isWarnEnabled()) {
126 _log.warn(
127 "Unable to update tags asset for article " +
128 article.getId(),
129 e);
130 }
131 }
132 }
133 }
134
135 if (_log.isDebugEnabled()) {
136 _log.debug(
137 "Permissions and Tags assets verified for Journal articles");
138 }
139 }
140
141 private static Log _log = LogFactory.getLog(VerifyJournal.class);
142
143 }