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