001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.util;
016    
017    import com.liferay.portal.kernel.comment.Comment;
018    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
019    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
020    import com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery;
021    import com.liferay.portal.kernel.dao.orm.Property;
022    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
023    import com.liferay.portal.kernel.exception.PortalException;
024    import com.liferay.portal.kernel.log.Log;
025    import com.liferay.portal.kernel.log.LogFactoryUtil;
026    import com.liferay.portal.kernel.repository.model.FileEntry;
027    import com.liferay.portal.kernel.repository.model.FileVersion;
028    import com.liferay.portal.kernel.search.BaseIndexer;
029    import com.liferay.portal.kernel.search.BaseRelatedEntryIndexer;
030    import com.liferay.portal.kernel.search.BooleanClauseOccur;
031    import com.liferay.portal.kernel.search.BooleanQuery;
032    import com.liferay.portal.kernel.search.Document;
033    import com.liferay.portal.kernel.search.DocumentHelper;
034    import com.liferay.portal.kernel.search.Field;
035    import com.liferay.portal.kernel.search.IndexWriterHelperUtil;
036    import com.liferay.portal.kernel.search.Indexer;
037    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
038    import com.liferay.portal.kernel.search.RelatedEntryIndexer;
039    import com.liferay.portal.kernel.search.SearchContext;
040    import com.liferay.portal.kernel.search.SearchException;
041    import com.liferay.portal.kernel.search.Summary;
042    import com.liferay.portal.kernel.search.filter.BooleanFilter;
043    import com.liferay.portal.kernel.search.filter.QueryFilter;
044    import com.liferay.portal.kernel.search.generic.BooleanQueryImpl;
045    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
046    import com.liferay.portal.kernel.util.ArrayUtil;
047    import com.liferay.portal.kernel.util.CharPool;
048    import com.liferay.portal.kernel.util.GetterUtil;
049    import com.liferay.portal.kernel.util.LocaleUtil;
050    import com.liferay.portal.kernel.util.PropsKeys;
051    import com.liferay.portal.kernel.util.StringBundler;
052    import com.liferay.portal.kernel.util.StringPool;
053    import com.liferay.portal.kernel.util.StringUtil;
054    import com.liferay.portal.kernel.util.Validator;
055    import com.liferay.portal.model.Group;
056    import com.liferay.portal.repository.liferayrepository.model.LiferayFileEntry;
057    import com.liferay.portal.security.permission.ActionKeys;
058    import com.liferay.portal.security.permission.PermissionChecker;
059    import com.liferay.portal.service.GroupLocalServiceUtil;
060    import com.liferay.portal.util.PortalUtil;
061    import com.liferay.portal.util.PrefsPropsUtil;
062    import com.liferay.portal.util.PropsValues;
063    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
064    import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata;
065    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
066    import com.liferay.portlet.documentlibrary.model.DLFolder;
067    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
068    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
069    import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
070    import com.liferay.portlet.documentlibrary.service.DLFileEntryMetadataLocalServiceUtil;
071    import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
072    import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
073    import com.liferay.portlet.dynamicdatamapping.DDMFormValues;
074    import com.liferay.portlet.dynamicdatamapping.DDMStructure;
075    import com.liferay.portlet.dynamicdatamapping.DDMStructureManager;
076    import com.liferay.portlet.dynamicdatamapping.DDMStructureManagerUtil;
077    import com.liferay.portlet.dynamicdatamapping.StorageEngineManagerUtil;
078    import com.liferay.portlet.expando.model.ExpandoBridge;
079    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
080    import com.liferay.portlet.expando.util.ExpandoBridgeIndexerUtil;
081    
082    import java.io.IOException;
083    import java.io.InputStream;
084    import java.io.Serializable;
085    
086    import java.util.LinkedHashMap;
087    import java.util.List;
088    import java.util.Locale;
089    
090    import javax.portlet.PortletRequest;
091    import javax.portlet.PortletResponse;
092    
093    /**
094     * @author Brian Wing Shun Chan
095     * @author Raymond Aug??
096     * @author Alexander Chow
097     */
098    @OSGiBeanProperties
099    public class DLFileEntryIndexer
100            extends BaseIndexer<DLFileEntry> implements RelatedEntryIndexer {
101    
102            public static final String CLASS_NAME = DLFileEntry.class.getName();
103    
104            public DLFileEntryIndexer() {
105                    setDefaultSelectedFieldNames(
106                            Field.ASSET_TAG_NAMES, Field.COMPANY_ID, Field.CONTENT,
107                            Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID,
108                            Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.TITLE, Field.UID);
109                    setFilterSearch(true);
110                    setPermissionAware(true);
111            }
112    
113            @Override
114            public void addRelatedClassNames(
115                            BooleanFilter contextBooleanFilter, SearchContext searchContext)
116                    throws Exception {
117    
118                    _relatedEntryIndexer.addRelatedClassNames(
119                            contextBooleanFilter, searchContext);
120            }
121    
122            @Override
123            public void addRelatedEntryFields(Document document, Object obj)
124                    throws Exception {
125    
126                    Comment comment = (Comment)obj;
127    
128                    FileEntry fileEntry = null;
129    
130                    try {
131                            fileEntry = DLAppLocalServiceUtil.getFileEntry(
132                                    comment.getClassPK());
133                    }
134                    catch (Exception e) {
135                            return;
136                    }
137    
138                    if (fileEntry instanceof LiferayFileEntry) {
139                            DLFileEntry dlFileEntry = (DLFileEntry)fileEntry.getModel();
140    
141                            document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
142                            document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
143                            document.addKeyword(
144                                    Field.TREE_PATH,
145                                    StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH));
146                    }
147            }
148    
149            @Override
150            public String getClassName() {
151                    return CLASS_NAME;
152            }
153    
154            @Override
155            public boolean hasPermission(
156                            PermissionChecker permissionChecker, String entryClassName,
157                            long entryClassPK, String actionId)
158                    throws Exception {
159    
160                    return DLFileEntryPermission.contains(
161                            permissionChecker, entryClassPK, ActionKeys.VIEW);
162            }
163    
164            @Override
165            public boolean isVisible(long classPK, int status) throws Exception {
166                    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);
167    
168                    FileVersion fileVersion = fileEntry.getFileVersion();
169    
170                    return isVisible(fileVersion.getStatus(), status);
171            }
172    
173            @Override
174            public boolean isVisibleRelatedEntry(long classPK, int status)
175                    throws Exception {
176    
177                    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);
178    
179                    if (fileEntry instanceof LiferayFileEntry) {
180                            DLFileEntry dlFileEntry = (DLFileEntry)fileEntry.getModel();
181    
182                            if (dlFileEntry.isInHiddenFolder()) {
183                                    Indexer<?> indexer = IndexerRegistryUtil.getIndexer(
184                                            dlFileEntry.getClassName());
185    
186                                    return indexer.isVisible(dlFileEntry.getClassPK(), status);
187                            }
188                    }
189    
190                    return true;
191            }
192    
193            @Override
194            public void postProcessContextBooleanFilter(
195                            BooleanFilter contextBooleanFilter, SearchContext searchContext)
196                    throws Exception {
197    
198                    addStatus(contextBooleanFilter, searchContext);
199    
200                    if (searchContext.isIncludeAttachments()) {
201                            addRelatedClassNames(contextBooleanFilter, searchContext);
202                    }
203    
204                    if (ArrayUtil.contains(
205                                    searchContext.getFolderIds(),
206                                    DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {
207    
208                            contextBooleanFilter.addRequiredTerm(
209                                    Field.HIDDEN, searchContext.isIncludeAttachments());
210                    }
211    
212                    addSearchClassTypeIds(contextBooleanFilter, searchContext);
213    
214                    String ddmStructureFieldName = (String)searchContext.getAttribute(
215                            "ddmStructureFieldName");
216                    Serializable ddmStructureFieldValue = searchContext.getAttribute(
217                            "ddmStructureFieldValue");
218    
219                    if (Validator.isNotNull(ddmStructureFieldName) &&
220                            Validator.isNotNull(ddmStructureFieldValue)) {
221    
222                            String[] ddmStructureFieldNameParts = StringUtil.split(
223                                    ddmStructureFieldName,
224                                    DDMStructureManager.STRUCTURE_INDEXER_FIELD_SEPARATOR);
225    
226                            DDMStructure ddmStructure = DDMStructureManagerUtil.getStructure(
227                                    GetterUtil.getLong(ddmStructureFieldNameParts[2]));
228    
229                            String fieldName = StringUtil.replaceLast(
230                                    ddmStructureFieldNameParts[3],
231                                    StringPool.UNDERLINE.concat(
232                                            LocaleUtil.toLanguageId(searchContext.getLocale())),
233                                    StringPool.BLANK);
234    
235                            try {
236                                    ddmStructureFieldValue =
237                                            DDMStructureManagerUtil.getIndexedFieldValue(
238                                                    ddmStructureFieldValue,
239                                                    ddmStructure.getFieldType(fieldName));
240                            }
241                            catch (Exception e) {
242                                    if (_log.isDebugEnabled()) {
243                                            _log.debug(e, e);
244                                    }
245                            }
246    
247                            BooleanQuery booleanQuery = new BooleanQueryImpl();
248    
249                            booleanQuery.addRequiredTerm(
250                                    ddmStructureFieldName,
251                                    StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);
252    
253                            contextBooleanFilter.add(
254                                    new QueryFilter(booleanQuery), BooleanClauseOccur.MUST);
255                    }
256    
257                    String[] mimeTypes = (String[])searchContext.getAttribute("mimeTypes");
258    
259                    if (ArrayUtil.isNotEmpty(mimeTypes)) {
260                            BooleanFilter mimeTypesBooleanFilter = new BooleanFilter();
261    
262                            for (String mimeType : mimeTypes) {
263                                    mimeTypesBooleanFilter.addTerm(
264                                            "mimeType",
265                                            StringUtil.replace(
266                                                    mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
267                            }
268    
269                            contextBooleanFilter.add(
270                                    mimeTypesBooleanFilter, BooleanClauseOccur.MUST);
271                    }
272            }
273    
274            @Override
275            public void postProcessSearchQuery(
276                            BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
277                            SearchContext searchContext)
278                    throws Exception {
279    
280                    String keywords = searchContext.getKeywords();
281    
282                    if (Validator.isNull(keywords)) {
283                            addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
284                            addSearchTerm(searchQuery, searchContext, Field.TITLE, false);
285                            addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);
286                    }
287    
288                    addSearchTerm(searchQuery, searchContext, "ddmContent", false);
289                    addSearchTerm(searchQuery, searchContext, "extension", false);
290                    addSearchTerm(searchQuery, searchContext, "fileEntryTypeId", false);
291                    addSearchTerm(searchQuery, searchContext, "path", false);
292    
293                    LinkedHashMap<String, Object> params =
294                            (LinkedHashMap<String, Object>)searchContext.getAttribute("params");
295    
296                    if (params != null) {
297                            String expandoAttributes = (String)params.get("expandoAttributes");
298    
299                            if (Validator.isNotNull(expandoAttributes)) {
300                                    addSearchExpando(searchQuery, searchContext, expandoAttributes);
301                            }
302                    }
303            }
304    
305            @Override
306            public void updateFullQuery(SearchContext searchContext) {
307                    if (searchContext.isIncludeAttachments()) {
308                            searchContext.addFullQueryEntryClassName(
309                                    DLFileEntry.class.getName());
310                    }
311            }
312    
313            protected void addFileEntryTypeAttributes(
314                            Document document, DLFileVersion dlFileVersion)
315                    throws PortalException {
316    
317                    List<DLFileEntryMetadata> dlFileEntryMetadatas =
318                            DLFileEntryMetadataLocalServiceUtil.
319                                    getFileVersionFileEntryMetadatas(
320                                            dlFileVersion.getFileVersionId());
321    
322                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
323                            DDMFormValues ddmFormValues = null;
324    
325                            try {
326                                    ddmFormValues = StorageEngineManagerUtil.getDDMFormValues(
327                                            dlFileEntryMetadata.getDDMStorageId());
328                            }
329                            catch (Exception e) {
330                            }
331    
332                            if (ddmFormValues != null) {
333                                    DDMStructureManagerUtil.addAttributes(
334                                            dlFileEntryMetadata.getDDMStructureId(), document,
335                                            ddmFormValues);
336                            }
337                    }
338            }
339    
340            @Override
341            protected void doDelete(DLFileEntry dlFileEntry) throws Exception {
342                    deleteDocument(
343                            dlFileEntry.getCompanyId(), dlFileEntry.getFileEntryId());
344            }
345    
346            @Override
347            protected Document doGetDocument(DLFileEntry dlFileEntry) throws Exception {
348                    if (_log.isDebugEnabled()) {
349                            _log.debug("Indexing document " + dlFileEntry);
350                    }
351    
352                    boolean indexContent = true;
353    
354                    InputStream is = null;
355    
356                    try {
357                            String[] ignoreExtensions = PrefsPropsUtil.getStringArray(
358                                    PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);
359    
360                            if (ArrayUtil.contains(
361                                            ignoreExtensions,
362                                            StringPool.PERIOD + dlFileEntry.getExtension())) {
363    
364                                    indexContent = false;
365                            }
366    
367                            if (indexContent) {
368                                    is = dlFileEntry.getFileVersion().getContentStream(false);
369                            }
370                    }
371                    catch (Exception e) {
372                            if (_log.isDebugEnabled()) {
373                                    _log.debug("Error retrieving document stream", e);
374                            }
375                    }
376    
377                    DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();
378    
379                    try {
380                            Document document = getBaseModelDocument(
381                                    CLASS_NAME, dlFileEntry, dlFileVersion);
382    
383                            if (indexContent) {
384                                    if (is != null) {
385                                            try {
386                                                    document.addFile(
387                                                            Field.CONTENT, is, dlFileEntry.getTitle(),
388                                                            PropsValues.DL_FILE_INDEXING_MAX_SIZE);
389                                            }
390                                            catch (IOException ioe) {
391                                                    throw new SearchException(
392                                                            "Cannot extract text from file" + dlFileEntry);
393                                            }
394                                    }
395                                    else if (_log.isDebugEnabled()) {
396                                            _log.debug(
397                                                    "Document " + dlFileEntry +
398                                                            " does not have any content");
399                                    }
400                            }
401    
402                            document.addKeyword(
403                                    Field.CLASS_TYPE_ID, dlFileEntry.getFileEntryTypeId());
404                            document.addText(Field.DESCRIPTION, dlFileEntry.getDescription());
405                            document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
406                            document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
407                            document.addText(
408                                    Field.PROPERTIES, dlFileEntry.getLuceneProperties());
409                            document.addText(Field.TITLE, dlFileEntry.getTitle());
410                            document.addKeyword(
411                                    Field.TREE_PATH,
412                                    StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH));
413    
414                            document.addKeyword(
415                                    "dataRepositoryId", dlFileEntry.getDataRepositoryId());
416                            document.addText(
417                                    "ddmContent",
418                                    extractDDMContent(dlFileVersion, LocaleUtil.getSiteDefault()));
419                            document.addKeyword("extension", dlFileEntry.getExtension());
420                            document.addKeyword(
421                                    "fileEntryTypeId", dlFileEntry.getFileEntryTypeId());
422                            document.addKeyword(
423                                    "mimeType",
424                                    StringUtil.replace(
425                                            dlFileEntry.getMimeType(), CharPool.FORWARD_SLASH,
426                                            CharPool.UNDERLINE));
427                            document.addKeyword("path", dlFileEntry.getTitle());
428                            document.addKeyword("readCount", dlFileEntry.getReadCount());
429                            document.addKeyword("size", dlFileEntry.getSize());
430    
431                            ExpandoBridge expandoBridge =
432                                    ExpandoBridgeFactoryUtil.getExpandoBridge(
433                                            dlFileEntry.getCompanyId(), DLFileEntry.class.getName(),
434                                            dlFileVersion.getFileVersionId());
435    
436                            ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);
437    
438                            addFileEntryTypeAttributes(document, dlFileVersion);
439    
440                            if (dlFileEntry.isInHiddenFolder()) {
441                                    Indexer<?> indexer = IndexerRegistryUtil.getIndexer(
442                                            dlFileEntry.getClassName());
443    
444                                    if ((indexer != null) &&
445                                            (indexer instanceof RelatedEntryIndexer)) {
446    
447                                            RelatedEntryIndexer relatedEntryIndexer =
448                                                    (RelatedEntryIndexer)indexer;
449    
450                                            relatedEntryIndexer.addRelatedEntryFields(
451                                                    document, new LiferayFileEntry(dlFileEntry));
452    
453                                            DocumentHelper documentHelper = new DocumentHelper(
454                                                    document);
455    
456                                            documentHelper.setAttachmentOwnerKey(
457                                                    PortalUtil.getClassNameId(dlFileEntry.getClassName()),
458                                                    dlFileEntry.getClassPK());
459    
460                                            document.addKeyword(Field.RELATED_ENTRY, true);
461                                    }
462                            }
463    
464                            if (_log.isDebugEnabled()) {
465                                    _log.debug("Document " + dlFileEntry + " indexed successfully");
466                            }
467    
468                            return document;
469                    }
470                    finally {
471                            if (is != null) {
472                                    try {
473                                            is.close();
474                                    }
475                                    catch (IOException ioe) {
476                                    }
477                            }
478                    }
479            }
480    
481            @Override
482            protected Summary doGetSummary(
483                    Document document, Locale locale, String snippet,
484                    PortletRequest portletRequest, PortletResponse portletResponse) {
485    
486                    Summary summary = createSummary(document, Field.TITLE, Field.CONTENT);
487    
488                    summary.setMaxContentLength(200);
489    
490                    return summary;
491            }
492    
493            @Override
494            protected void doReindex(DLFileEntry dlFileEntry) throws Exception {
495                    DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();
496    
497                    if (!dlFileVersion.isApproved() && !dlFileEntry.isInTrash()) {
498                            return;
499                    }
500    
501                    Document document = getDocument(dlFileEntry);
502    
503                    IndexWriterHelperUtil.updateDocument(
504                            getSearchEngineId(), dlFileEntry.getCompanyId(), document,
505                            isCommitImmediately());
506            }
507    
508            @Override
509            protected void doReindex(String className, long classPK) throws Exception {
510                    DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntry(
511                            classPK);
512    
513                    doReindex(dlFileEntry);
514            }
515    
516            @Override
517            protected void doReindex(String[] ids) throws Exception {
518                    if (ids.length == 1) {
519                            long companyId = GetterUtil.getLong(ids[0]);
520    
521                            reindexFolders(companyId);
522                            reindexRoot(companyId);
523                    }
524                    else {
525                            long companyId = GetterUtil.getLong(ids[0]);
526                            long groupId = GetterUtil.getLong(ids[1]);
527                            long dataRepositoryId = GetterUtil.getLong(ids[2]);
528    
529                            reindexFileEntries(companyId, groupId, dataRepositoryId);
530                    }
531            }
532    
533            protected String extractDDMContent(
534                            DLFileVersion dlFileVersion, Locale locale)
535                    throws Exception {
536    
537                    List<DLFileEntryMetadata> dlFileEntryMetadatas =
538                            DLFileEntryMetadataLocalServiceUtil.
539                                    getFileVersionFileEntryMetadatas(
540                                            dlFileVersion.getFileVersionId());
541    
542                    StringBundler sb = new StringBundler(dlFileEntryMetadatas.size());
543    
544                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
545                            DDMFormValues ddmFormValues = null;
546    
547                            try {
548                                    ddmFormValues = StorageEngineManagerUtil.getDDMFormValues(
549                                            dlFileEntryMetadata.getDDMStorageId());
550                            }
551                            catch (Exception e) {
552                            }
553    
554                            if (ddmFormValues != null) {
555                                    sb.append(
556                                            DDMStructureManagerUtil.extractAttributes(
557                                                    dlFileEntryMetadata.getDDMStructureId(), ddmFormValues,
558                                                    locale));
559                            }
560                    }
561    
562                    return sb.toString();
563            }
564    
565            protected void reindexFileEntries(
566                            long companyId, final long groupId, final long dataRepositoryId)
567                    throws PortalException {
568    
569                    final IndexableActionableDynamicQuery indexableActionableDynamicQuery =
570                            DLFileEntryLocalServiceUtil.getIndexableActionableDynamicQuery();
571    
572                    indexableActionableDynamicQuery.setAddCriteriaMethod(
573                            new ActionableDynamicQuery.AddCriteriaMethod() {
574    
575                                    @Override
576                                    public void addCriteria(DynamicQuery dynamicQuery) {
577                                            Property property = PropertyFactoryUtil.forName("folderId");
578    
579                                            long folderId = DLFolderConstants.getFolderId(
580                                                    groupId, dataRepositoryId);
581    
582                                            dynamicQuery.add(property.eq(folderId));
583                                    }
584    
585                            });
586                    indexableActionableDynamicQuery.setCompanyId(companyId);
587                    indexableActionableDynamicQuery.setGroupId(groupId);
588                    indexableActionableDynamicQuery.setPerformActionMethod(
589                            new ActionableDynamicQuery.PerformActionMethod<DLFileEntry>() {
590    
591                                    @Override
592                                    public void performAction(DLFileEntry dlFileEntry) {
593                                            try {
594                                                    Document document = getDocument(dlFileEntry);
595    
596                                                    indexableActionableDynamicQuery.addDocuments(document);
597                                            }
598                                            catch (PortalException pe) {
599                                                    if (_log.isWarnEnabled()) {
600                                                            _log.warn(
601                                                                    "Unable to index document library file entry " +
602                                                                            dlFileEntry.getFileEntryId(),
603                                                                    pe);
604                                                    }
605                                            }
606                                    }
607    
608                            });
609                    indexableActionableDynamicQuery.setSearchEngineId(getSearchEngineId());
610    
611                    indexableActionableDynamicQuery.performActions();
612            }
613    
614            protected void reindexFolders(final long companyId) throws PortalException {
615                    ActionableDynamicQuery actionableDynamicQuery =
616                            DLFolderLocalServiceUtil.getActionableDynamicQuery();
617    
618                    actionableDynamicQuery.setCompanyId(companyId);
619                    actionableDynamicQuery.setPerformActionMethod(
620                            new ActionableDynamicQuery.PerformActionMethod<DLFolder>() {
621    
622                                    @Override
623                                    public void performAction(DLFolder dlFolder)
624                                            throws PortalException {
625    
626                                            long groupId = dlFolder.getGroupId();
627                                            long folderId = dlFolder.getFolderId();
628    
629                                            String[] newIds = {
630                                                    String.valueOf(companyId), String.valueOf(groupId),
631                                                    String.valueOf(folderId)
632                                            };
633    
634                                            reindex(newIds);
635                                    }
636    
637                            });
638    
639                    actionableDynamicQuery.performActions();
640            }
641    
642            protected void reindexRoot(final long companyId) throws PortalException {
643                    ActionableDynamicQuery actionableDynamicQuery =
644                            GroupLocalServiceUtil.getActionableDynamicQuery();
645    
646                    actionableDynamicQuery.setCompanyId(companyId);
647                    actionableDynamicQuery.setPerformActionMethod(
648                            new ActionableDynamicQuery.PerformActionMethod<Group>() {
649    
650                                    @Override
651                                    public void performAction(Group group) throws PortalException {
652                                            long groupId = group.getGroupId();
653                                            long folderId = groupId;
654    
655                                            String[] newIds = {
656                                                    String.valueOf(companyId), String.valueOf(groupId),
657                                                    String.valueOf(folderId)
658                                            };
659    
660                                            reindex(newIds);
661                                    }
662    
663                            });
664    
665                    actionableDynamicQuery.performActions();
666            }
667    
668            private static final Log _log = LogFactoryUtil.getLog(
669                    DLFileEntryIndexer.class);
670    
671            private final RelatedEntryIndexer _relatedEntryIndexer =
672                    new BaseRelatedEntryIndexer();
673    
674    }