Source Code Cross Referenced for VerifyJournal.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portal » verify » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portal.verify 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003:         *
004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
005:         * of this software and associated documentation files (the "Software"), to deal
006:         * in the Software without restriction, including without limitation the rights
007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008:         * copies of the Software, and to permit persons to whom the Software is
009:         * furnished to do so, subject to the following conditions:
010:         *
011:         * The above copyright notice and this permission notice shall be included in
012:         * all copies or substantial portions of the Software.
013:         *
014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020:         * SOFTWARE.
021:         */package com.liferay.portal.verify;
022:
023:        import com.liferay.portal.kernel.util.GetterUtil;
024:        import com.liferay.portal.service.ResourceLocalServiceUtil;
025:        import com.liferay.portal.spring.hibernate.HibernateUtil;
026:        import com.liferay.portlet.journal.model.JournalArticle;
027:        import com.liferay.portlet.journal.model.JournalStructure;
028:        import com.liferay.portlet.journal.model.JournalTemplate;
029:        import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
030:        import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
031:        import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
032:        import com.liferay.portlet.tags.NoSuchAssetException;
033:        import com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil;
034:        import com.liferay.util.Html;
035:        import com.liferay.util.dao.DataAccess;
036:
037:        import java.sql.Connection;
038:        import java.sql.PreparedStatement;
039:        import java.sql.ResultSet;
040:
041:        import java.util.List;
042:
043:        import org.apache.commons.logging.Log;
044:        import org.apache.commons.logging.LogFactory;
045:
046:        /**
047:         * <a href="VerifyJournal.java.html"><b><i>View Source</i></b></a>
048:         *
049:         * @author Alexander Chow
050:         *
051:         */
052:        public class VerifyJournal extends VerifyProcess {
053:
054:            public void verify() throws VerifyException {
055:                _log.info("Verifying integrity");
056:
057:                try {
058:                    verifyJournal();
059:                } catch (Exception e) {
060:                    throw new VerifyException(e);
061:                }
062:            }
063:
064:            protected void verifyJournal() throws Exception {
065:
066:                // Structures
067:
068:                List structures = JournalStructureLocalServiceUtil
069:                        .getStructures();
070:
071:                for (int i = 0; i < structures.size(); i++) {
072:                    JournalStructure structure = (JournalStructure) structures
073:                            .get(i);
074:
075:                    ResourceLocalServiceUtil.addResources(structure
076:                            .getCompanyId(), 0, 0, JournalStructure.class
077:                            .getName(), structure.getId(), false, true, true);
078:                }
079:
080:                if (_log.isDebugEnabled()) {
081:                    _log.debug("Permissions verified for Journal structures");
082:                }
083:
084:                // Templates
085:
086:                List templates = JournalTemplateLocalServiceUtil.getTemplates();
087:
088:                for (int i = 0; i < templates.size(); i++) {
089:                    JournalTemplate template = (JournalTemplate) templates
090:                            .get(i);
091:
092:                    ResourceLocalServiceUtil.addResources(template
093:                            .getCompanyId(), 0, 0, JournalTemplate.class
094:                            .getName(), template.getId(), false, true, true);
095:                }
096:
097:                if (_log.isDebugEnabled()) {
098:                    _log.debug("Permissions verified for Journal templates");
099:                }
100:
101:                // Articles
102:
103:                List articles = JournalArticleLocalServiceUtil.getArticles();
104:
105:                for (int i = 0; i < articles.size(); i++) {
106:                    JournalArticle article = (JournalArticle) articles.get(i);
107:
108:                    long groupId = article.getGroupId();
109:                    String articleId = article.getArticleId();
110:                    double version = article.getVersion();
111:
112:                    if (article.getResourcePrimKey() <= 0) {
113:                        article = JournalArticleLocalServiceUtil
114:                                .checkArticleResourcePrimKey(groupId,
115:                                        articleId, version);
116:                    }
117:
118:                    ResourceLocalServiceUtil.addResources(article
119:                            .getCompanyId(), 0, 0, JournalArticle.class
120:                            .getName(), article.getResourcePrimKey(), false,
121:                            true, true);
122:
123:                    try {
124:                        TagsAssetLocalServiceUtil.getAsset(JournalArticle.class
125:                                .getName(), article.getResourcePrimKey());
126:                    } catch (NoSuchAssetException nsae) {
127:                        try {
128:                            JournalArticleLocalServiceUtil
129:                                    .updateTagsAsset(article.getUserId(),
130:                                            article, new String[0]);
131:                        } catch (Exception e) {
132:                            if (_log.isWarnEnabled()) {
133:                                _log
134:                                        .warn("Unable to update tags asset for article "
135:                                                + article.getId()
136:                                                + ": "
137:                                                + e.getMessage());
138:                            }
139:                        }
140:                    }
141:
142:                    String content = GetterUtil.getString(article.getContent());
143:
144:                    String newContent = Html.replaceMsWordCharacters(content);
145:
146:                    if (!content.equals(newContent)) {
147:                        JournalArticleLocalServiceUtil.updateContent(groupId,
148:                                articleId, version, newContent);
149:                    }
150:
151:                    JournalArticleLocalServiceUtil.checkStructure(groupId,
152:                            articleId, version);
153:
154:                    //verifyStaleJournalArticle(article);
155:                }
156:
157:                if (_log.isDebugEnabled()) {
158:                    _log
159:                            .debug("Permissions and Tags assets verified for Journal articles");
160:                }
161:            }
162:
163:            protected void verifyStaleJournalArticle(JournalArticle article)
164:                    throws Exception {
165:
166:                long groupId = article.getGroupId();
167:                String articleId = article.getArticleId();
168:                double version = article.getVersion();
169:
170:                if (article.getStructureId().equals("BASIC-RSS-ITEM")) {
171:                    return;
172:                }
173:
174:                long count = getPortletPreferencesCount(articleId);
175:
176:                if (count == 0) {
177:                    if (_log.isWarnEnabled()) {
178:                        _log.warn("Article {groupId=" + groupId
179:                                + ", articleId=" + articleId + ", version="
180:                                + version + "} is not used on any layouts");
181:                    }
182:                }
183:            }
184:
185:            protected long getPortletPreferencesCount(String articleId)
186:                    throws Exception {
187:
188:                Connection con = null;
189:                PreparedStatement ps = null;
190:                ResultSet rs = null;
191:
192:                try {
193:                    con = HibernateUtil.getConnection();
194:
195:                    ps = con.prepareStatement(_GET_PORTLET_PREFERENCES_COUNT);
196:
197:                    ps.setString(1, "%<name>article-id</name><value>"
198:                            + articleId + "</value>%");
199:
200:                    rs = ps.executeQuery();
201:
202:                    while (rs.next()) {
203:                        long count = rs.getLong("count_value");
204:
205:                        return count;
206:                    }
207:                } finally {
208:                    DataAccess.cleanUp(con, ps, rs);
209:                }
210:
211:                return 0;
212:            }
213:
214:            private static final String _GET_PORTLET_PREFERENCES_COUNT = "select count(*) as count_value from PortletPreferences where "
215:                    + "ownerId = 0 and ownerType = 3 and portletId like "
216:                    + "'56_INSTANCE_%' and preferences like ?";
217:
218:            private static Log _log = LogFactory.getLog(VerifyJournal.class);
219:
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.