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.portlet.journal.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.StringPool;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.model.Group;
028: import com.liferay.portal.model.Layout;
029: import com.liferay.portal.model.LayoutTypePortlet;
030: import com.liferay.portal.model.impl.PortletImpl;
031: import com.liferay.portal.util.PortletKeys;
032: import com.liferay.portlet.journal.model.JournalContentSearch;
033: import com.liferay.portlet.journal.service.base.JournalContentSearchLocalServiceBaseImpl;
034: import com.liferay.util.dao.hibernate.QueryUtil;
035:
036: import java.util.ArrayList;
037: import java.util.Iterator;
038: import java.util.List;
039:
040: import javax.portlet.PortletPreferences;
041:
042: import org.apache.commons.logging.Log;
043: import org.apache.commons.logging.LogFactory;
044:
045: /**
046: * <a href="JournalContentSearchLocalServiceImpl.java.html"><b><i>View Source
047: * </i></b></a>
048: *
049: * @author Brian Wing Shun Chan
050: *
051: */
052: public class JournalContentSearchLocalServiceImpl extends
053: JournalContentSearchLocalServiceBaseImpl {
054:
055: public void checkContentSearches(long companyId)
056: throws PortalException, SystemException {
057:
058: if (_log.isInfoEnabled()) {
059: _log.info("Checking journal content search for "
060: + companyId);
061: }
062:
063: List layouts = new ArrayList();
064:
065: List groups = groupLocalService.search(companyId, null, null,
066: null, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
067:
068: for (int i = 0; i < groups.size(); i++) {
069: Group group = (Group) groups.get(i);
070:
071: // Private layouts
072:
073: deleteOwnerContentSearches(group.getGroupId(), true);
074:
075: layouts.addAll(layoutLocalService.getLayouts(group
076: .getGroupId(), true));
077:
078: // Public layouts
079:
080: deleteOwnerContentSearches(group.getGroupId(), false);
081:
082: layouts.addAll(layoutLocalService.getLayouts(group
083: .getGroupId(), false));
084: }
085:
086: for (int i = 0; i < layouts.size(); i++) {
087: Layout layout = (Layout) layouts.get(i);
088:
089: LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout
090: .getLayoutType();
091:
092: List portletIds = layoutTypePortlet.getPortletIds();
093:
094: for (int j = 0; j < portletIds.size(); j++) {
095: String portletId = (String) portletIds.get(j);
096:
097: String rootPortletId = PortletImpl
098: .getRootPortletId(portletId);
099:
100: if (rootPortletId.equals(PortletKeys.JOURNAL_CONTENT)) {
101: PortletPreferences prefs = portletPreferencesLocalService
102: .getPreferences(
103: layout.getCompanyId(),
104: PortletKeys.PREFS_OWNER_ID_DEFAULT,
105: PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
106: layout.getPlid(), portletId);
107:
108: String articleId = prefs.getValue("article-id",
109: StringPool.BLANK);
110:
111: if (Validator.isNotNull(articleId)) {
112: updateContentSearch(layout.getGroupId(), layout
113: .isPrivateLayout(), layout
114: .getLayoutId(), portletId, articleId);
115: }
116: }
117: }
118: }
119: }
120:
121: public void deleteArticleContentSearch(long groupId,
122: boolean privateLayout, long layoutId, String portletId,
123: String articleId) throws PortalException, SystemException {
124:
125: journalContentSearchPersistence.removeByG_P_L_P_A(groupId,
126: privateLayout, layoutId, portletId, articleId);
127: }
128:
129: public void deleteArticleContentSearches(long groupId,
130: String articleId) throws SystemException {
131:
132: journalContentSearchPersistence.removeByG_A(groupId, articleId);
133: }
134:
135: public void deleteLayoutContentSearches(long groupId,
136: boolean privateLayout, long layoutId)
137: throws SystemException {
138:
139: journalContentSearchPersistence.removeByG_P_L(groupId,
140: privateLayout, layoutId);
141: }
142:
143: public void deleteOwnerContentSearches(long groupId,
144: boolean privateLayout) throws SystemException {
145:
146: journalContentSearchPersistence.removeByG_P(groupId,
147: privateLayout);
148: }
149:
150: public List getArticleContentSearches() throws SystemException {
151: return journalContentSearchPersistence.findAll();
152: }
153:
154: public List getArticleContentSearches(long groupId, String articleId)
155: throws SystemException {
156:
157: return journalContentSearchPersistence.findByG_A(groupId,
158: articleId);
159: }
160:
161: public List getLayoutIds(long groupId, boolean privateLayout,
162: String articleId) throws SystemException {
163:
164: List layoutIds = new ArrayList();
165:
166: Iterator itr = journalContentSearchPersistence.findByG_P_A(
167: groupId, privateLayout, articleId).iterator();
168:
169: while (itr.hasNext()) {
170: JournalContentSearch contentSearch = (JournalContentSearch) itr
171: .next();
172:
173: layoutIds.add(new Long(contentSearch.getLayoutId()));
174: }
175:
176: return layoutIds;
177: }
178:
179: public int getLayoutIdsCount(long groupId, boolean privateLayout,
180: String articleId) throws SystemException {
181:
182: return journalContentSearchPersistence.countByG_P_A(groupId,
183: privateLayout, articleId);
184: }
185:
186: public JournalContentSearch updateContentSearch(long groupId,
187: boolean privateLayout, long layoutId, String portletId,
188: String articleId) throws PortalException, SystemException {
189:
190: return updateContentSearch(groupId, privateLayout, layoutId,
191: portletId, articleId, false);
192: }
193:
194: public JournalContentSearch updateContentSearch(long groupId,
195: boolean privateLayout, long layoutId, String portletId,
196: String articleId, boolean purge) throws PortalException,
197: SystemException {
198:
199: if (purge) {
200: journalContentSearchPersistence.removeByG_P_L_P(groupId,
201: privateLayout, layoutId, portletId);
202: }
203:
204: Group group = groupPersistence.findByPrimaryKey(groupId);
205:
206: JournalContentSearch contentSearch = journalContentSearchPersistence
207: .fetchByG_P_L_P_A(groupId, privateLayout, layoutId,
208: portletId, articleId);
209:
210: if (contentSearch == null) {
211: long contentSearchId = counterLocalService.increment();
212:
213: contentSearch = journalContentSearchPersistence
214: .create(contentSearchId);
215:
216: contentSearch.setGroupId(groupId);
217: contentSearch.setCompanyId(group.getCompanyId());
218: contentSearch.setPrivateLayout(privateLayout);
219: contentSearch.setLayoutId(layoutId);
220: contentSearch.setPortletId(portletId);
221: contentSearch.setArticleId(articleId);
222: }
223:
224: journalContentSearchPersistence.update(contentSearch);
225:
226: return contentSearch;
227: }
228:
229: public List updateContentSearch(long groupId,
230: boolean privateLayout, long layoutId, String portletId,
231: String[] articleIds) throws PortalException,
232: SystemException {
233:
234: journalContentSearchPersistence.removeByG_P_L_P(groupId,
235: privateLayout, layoutId, portletId);
236:
237: List contentSearches = new ArrayList();
238:
239: for (int i = 0; i < articleIds.length; i++) {
240: JournalContentSearch contentSearch = updateContentSearch(
241: groupId, privateLayout, layoutId, portletId,
242: articleIds[i], false);
243:
244: contentSearches.add(contentSearch);
245: }
246:
247: return contentSearches;
248: }
249:
250: private static Log _log = LogFactory
251: .getLog(JournalContentSearchLocalServiceImpl.class);
252:
253: }
|