1
22
23 package com.liferay.portal.verify;
24
25 import com.liferay.portal.kernel.dao.db.DB;
26 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
27 import com.liferay.portal.kernel.log.Log;
28 import com.liferay.portal.kernel.log.LogFactoryUtil;
29 import com.liferay.portal.kernel.util.GetterUtil;
30 import com.liferay.portal.kernel.util.HtmlUtil;
31 import com.liferay.portal.kernel.util.Validator;
32 import com.liferay.portal.service.ResourceLocalServiceUtil;
33 import com.liferay.portlet.journal.model.JournalArticle;
34 import com.liferay.portlet.journal.model.JournalStructure;
35 import com.liferay.portlet.journal.model.JournalTemplate;
36 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
37 import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
38 import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
39 import com.liferay.portlet.tags.NoSuchAssetException;
40 import com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil;
41
42 import java.util.List;
43
44
49 public class VerifyJournal extends VerifyProcess {
50
51 public static final long DEFAULT_GROUP_ID = 14;
52
53 public static final int NUM_OF_ARTICLES = 5;
54
55 protected void doVerify() throws Exception {
56
57
59 verifyOracleNewLine();
60
61
63 List<JournalStructure> structures =
64 JournalStructureLocalServiceUtil.getStructures();
65
66 for (JournalStructure structure : structures) {
67 ResourceLocalServiceUtil.addResources(
68 structure.getCompanyId(), 0, 0,
69 JournalStructure.class.getName(), structure.getId(), false,
70 true, true);
71 }
72
73 if (_log.isDebugEnabled()) {
74 _log.debug("Permissions verified for Journal structures");
75 }
76
77
79 List<JournalTemplate> templates =
80 JournalTemplateLocalServiceUtil.getTemplates();
81
82 for (JournalTemplate template : templates) {
83 ResourceLocalServiceUtil.addResources(
84 template.getCompanyId(), 0, 0,
85 JournalTemplate.class.getName(), template.getId(), false, true,
86 true);
87 }
88
89 if (_log.isDebugEnabled()) {
90 _log.debug("Permissions verified for Journal templates");
91 }
92
93
95 List<JournalArticle> articles =
96 JournalArticleLocalServiceUtil.getArticles();
97
98 for (JournalArticle article : articles) {
99 long groupId = article.getGroupId();
100 String articleId = article.getArticleId();
101 double version = article.getVersion();
102 String structureId = article.getStructureId();
103
104 if (article.getResourcePrimKey() <= 0) {
105 article =
106 JournalArticleLocalServiceUtil.checkArticleResourcePrimKey(
107 groupId, articleId, version);
108 }
109
110 ResourceLocalServiceUtil.addResources(
111 article.getCompanyId(), 0, 0, JournalArticle.class.getName(),
112 article.getResourcePrimKey(), 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 new String[0]);
124 }
125 catch (Exception e) {
126 if (_log.isWarnEnabled()) {
127 _log.warn(
128 "Unable to update tags asset for article " +
129 article.getId() + ": " + e.getMessage());
130 }
131 }
132 }
133
134 String content = GetterUtil.getString(article.getContent());
135
136 String newContent = HtmlUtil.replaceMsWordCharacters(content);
137
138 if (Validator.isNotNull(structureId)) {
139
145 }
146
147 if (!content.equals(newContent)) {
148 JournalArticleLocalServiceUtil.updateContent(
149 groupId, articleId, version, newContent);
150 }
151
152 JournalArticleLocalServiceUtil.checkStructure(
153 groupId, articleId, version);
154 }
155
156 if (_log.isDebugEnabled()) {
157 _log.debug(
158 "Permissions and Tags assets verified for Journal articles");
159 }
160 }
161
162 protected void verifyOracleNewLine() throws Exception {
163 DB db = DBFactoryUtil.getDB();
164
165 if (!db.getType().equals(DB.TYPE_ORACLE)) {
166 return;
167 }
168
169
175 boolean checkNewLine = false;
176
177 List<JournalArticle> articles = null;
178
179 if (NUM_OF_ARTICLES <= 0) {
180 checkNewLine = true;
181
182 articles = JournalArticleLocalServiceUtil.getArticles(
183 DEFAULT_GROUP_ID);
184 }
185 else {
186 articles = JournalArticleLocalServiceUtil.getArticles(
187 DEFAULT_GROUP_ID, 0, NUM_OF_ARTICLES);
188 }
189
190 for (JournalArticle article : articles) {
191 String content = article.getContent();
192
193 if ((content != null) && (content.indexOf("\\n") != -1)) {
194 articles = JournalArticleLocalServiceUtil.getArticles(
195 DEFAULT_GROUP_ID);
196
197 for (int j = 0; j < articles.size(); j++) {
198 article = articles.get(j);
199
200 JournalArticleLocalServiceUtil.checkNewLine(
201 article.getGroupId(), article.getArticleId(),
202 article.getVersion());
203 }
204
205 checkNewLine = true;
206
207 break;
208 }
209 }
210
211
213 if (!checkNewLine) {
214 if (_log.isInfoEnabled()) {
215 _log.debug("Do not fix oracle new line");
216 }
217
218 return;
219 }
220 else {
221 if (_log.isInfoEnabled()) {
222 _log.info("Fix oracle new line");
223 }
224 }
225
226 List<JournalStructure> structures =
227 JournalStructureLocalServiceUtil.getStructures(
228 DEFAULT_GROUP_ID, 0, 1);
229
230 if (structures.size() == 1) {
231 JournalStructure structure = structures.get(0);
232
233 String xsd = structure.getXsd();
234
235 if ((xsd != null) && (xsd.indexOf("\\n") != -1)) {
236 structures = JournalStructureLocalServiceUtil.getStructures(
237 DEFAULT_GROUP_ID);
238
239 for (int i = 0; i < structures.size(); i++) {
240 structure = structures.get(i);
241
242 JournalStructureLocalServiceUtil.checkNewLine(
243 structure.getGroupId(), structure.getStructureId());
244 }
245 }
246 }
247
248 List<JournalTemplate> templates =
249 JournalTemplateLocalServiceUtil.getTemplates(
250 DEFAULT_GROUP_ID, 0, 1);
251
252 if (templates.size() == 1) {
253 JournalTemplate template = templates.get(0);
254
255 String xsl = template.getXsl();
256
257 if ((xsl != null) && (xsl.indexOf("\\n") != -1)) {
258 templates = JournalTemplateLocalServiceUtil.getTemplates(
259 DEFAULT_GROUP_ID);
260
261 for (int i = 0; i < templates.size(); i++) {
262 template = templates.get(i);
263
264 JournalTemplateLocalServiceUtil.checkNewLine(
265 template.getGroupId(), template.getTemplateId());
266 }
267 }
268 }
269 }
270
271 private static Log _log = LogFactoryUtil.getLog(VerifyJournal.class);
272
273 }