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.Property;
021    import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
022    import com.liferay.portal.kernel.exception.PortalException;
023    import com.liferay.portal.kernel.log.Log;
024    import com.liferay.portal.kernel.log.LogFactoryUtil;
025    import com.liferay.portal.kernel.repository.model.FileEntry;
026    import com.liferay.portal.kernel.repository.model.FileVersion;
027    import com.liferay.portal.kernel.search.BaseIndexer;
028    import com.liferay.portal.kernel.search.BaseRelatedEntryIndexer;
029    import com.liferay.portal.kernel.search.BooleanClauseOccur;
030    import com.liferay.portal.kernel.search.BooleanQuery;
031    import com.liferay.portal.kernel.search.Document;
032    import com.liferay.portal.kernel.search.DocumentHelper;
033    import com.liferay.portal.kernel.search.DocumentImpl;
034    import com.liferay.portal.kernel.search.Field;
035    import com.liferay.portal.kernel.search.Indexer;
036    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
037    import com.liferay.portal.kernel.search.RelatedEntryIndexer;
038    import com.liferay.portal.kernel.search.SearchContext;
039    import com.liferay.portal.kernel.search.SearchEngineUtil;
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                    Document document = new DocumentImpl();
343    
344                    document.addUID(CLASS_NAME, dlFileEntry.getFileEntryId());
345    
346                    SearchEngineUtil.deleteDocument(
347                            getSearchEngineId(), dlFileEntry.getCompanyId(),
348                            document.get(Field.UID), isCommitImmediately());
349            }
350    
351            @Override
352            protected Document doGetDocument(DLFileEntry dlFileEntry) throws Exception {
353                    if (_log.isDebugEnabled()) {
354                            _log.debug("Indexing document " + dlFileEntry);
355                    }
356    
357                    boolean indexContent = true;
358    
359                    InputStream is = null;
360    
361                    try {
362                            String[] ignoreExtensions = PrefsPropsUtil.getStringArray(
363                                    PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);
364    
365                            if (ArrayUtil.contains(
366                                            ignoreExtensions,
367                                            StringPool.PERIOD + dlFileEntry.getExtension())) {
368    
369                                    indexContent = false;
370                            }
371    
372                            if (indexContent) {
373                                    is = dlFileEntry.getFileVersion().getContentStream(false);
374                            }
375                    }
376                    catch (Exception e) {
377                            if (_log.isDebugEnabled()) {
378                                    _log.debug("Error retrieving document stream", e);
379                            }
380                    }
381    
382                    DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();
383    
384                    try {
385                            Document document = getBaseModelDocument(
386                                    CLASS_NAME, dlFileEntry, dlFileVersion);
387    
388                            if (indexContent) {
389                                    if (is != null) {
390                                            try {
391                                                    document.addFile(
392                                                            Field.CONTENT, is, dlFileEntry.getTitle(),
393                                                            PropsValues.DL_FILE_INDEXING_MAX_SIZE);
394                                            }
395                                            catch (IOException ioe) {
396                                                    throw new SearchException(
397                                                            "Cannot extract text from file" + dlFileEntry);
398                                            }
399                                    }
400                                    else if (_log.isDebugEnabled()) {
401                                            _log.debug(
402                                                    "Document " + dlFileEntry +
403                                                            " does not have any content");
404                                    }
405                            }
406    
407                            document.addKeyword(
408                                    Field.CLASS_TYPE_ID, dlFileEntry.getFileEntryTypeId());
409                            document.addText(Field.DESCRIPTION, dlFileEntry.getDescription());
410                            document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
411                            document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
412                            document.addText(
413                                    Field.PROPERTIES, dlFileEntry.getLuceneProperties());
414                            document.addText(Field.TITLE, dlFileEntry.getTitle());
415                            document.addKeyword(
416                                    Field.TREE_PATH,
417                                    StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH));
418    
419                            document.addKeyword(
420                                    "dataRepositoryId", dlFileEntry.getDataRepositoryId());
421                            document.addText(
422                                    "ddmContent",
423                                    extractDDMContent(dlFileVersion, LocaleUtil.getSiteDefault()));
424                            document.addKeyword("extension", dlFileEntry.getExtension());
425                            document.addKeyword(
426                                    "fileEntryTypeId", dlFileEntry.getFileEntryTypeId());
427                            document.addKeyword(
428                                    "mimeType",
429                                    StringUtil.replace(
430                                            dlFileEntry.getMimeType(), CharPool.FORWARD_SLASH,
431                                            CharPool.UNDERLINE));
432                            document.addKeyword("path", dlFileEntry.getTitle());
433                            document.addKeyword("readCount", dlFileEntry.getReadCount());
434                            document.addKeyword("size", dlFileEntry.getSize());
435    
436                            ExpandoBridge expandoBridge =
437                                    ExpandoBridgeFactoryUtil.getExpandoBridge(
438                                            dlFileEntry.getCompanyId(), DLFileEntry.class.getName(),
439                                            dlFileVersion.getFileVersionId());
440    
441                            ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);
442    
443                            addFileEntryTypeAttributes(document, dlFileVersion);
444    
445                            if (dlFileEntry.isInHiddenFolder()) {
446                                    Indexer<?> indexer = IndexerRegistryUtil.getIndexer(
447                                            dlFileEntry.getClassName());
448    
449                                    if ((indexer != null) &&
450                                            (indexer instanceof RelatedEntryIndexer)) {
451    
452                                            RelatedEntryIndexer relatedEntryIndexer =
453                                                    (RelatedEntryIndexer)indexer;
454    
455                                            relatedEntryIndexer.addRelatedEntryFields(
456                                                    document, new LiferayFileEntry(dlFileEntry));
457    
458                                            DocumentHelper documentHelper = new DocumentHelper(
459                                                    document);
460    
461                                            documentHelper.setAttachmentOwnerKey(
462                                                    PortalUtil.getClassNameId(dlFileEntry.getClassName()),
463                                                    dlFileEntry.getClassPK());
464    
465                                            document.addKeyword(Field.RELATED_ENTRY, true);
466                                    }
467                            }
468    
469                            if (_log.isDebugEnabled()) {
470                                    _log.debug("Document " + dlFileEntry + " indexed successfully");
471                            }
472    
473                            return document;
474                    }
475                    finally {
476                            if (is != null) {
477                                    try {
478                                            is.close();
479                                    }
480                                    catch (IOException ioe) {
481                                    }
482                            }
483                    }
484            }
485    
486            @Override
487            protected Summary doGetSummary(
488                    Document document, Locale locale, String snippet,
489                    PortletRequest portletRequest, PortletResponse portletResponse) {
490    
491                    Summary summary = createSummary(document, Field.TITLE, Field.CONTENT);
492    
493                    summary.setMaxContentLength(200);
494    
495                    return summary;
496            }
497    
498            @Override
499            protected void doReindex(DLFileEntry dlFileEntry) throws Exception {
500                    DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();
501    
502                    if (!dlFileVersion.isApproved() && !dlFileEntry.isInTrash()) {
503                            return;
504                    }
505    
506                    Document document = getDocument(dlFileEntry);
507    
508                    if (document != null) {
509                            SearchEngineUtil.updateDocument(
510                                    getSearchEngineId(), dlFileEntry.getCompanyId(), document,
511                                    isCommitImmediately());
512                    }
513            }
514    
515            @Override
516            protected void doReindex(String className, long classPK) throws Exception {
517                    DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntry(
518                            classPK);
519    
520                    doReindex(dlFileEntry);
521            }
522    
523            @Override
524            protected void doReindex(String[] ids) throws Exception {
525                    if (ids.length == 1) {
526                            long companyId = GetterUtil.getLong(ids[0]);
527    
528                            reindexFolders(companyId);
529                            reindexRoot(companyId);
530                    }
531                    else {
532                            long companyId = GetterUtil.getLong(ids[0]);
533                            long groupId = GetterUtil.getLong(ids[1]);
534                            long dataRepositoryId = GetterUtil.getLong(ids[2]);
535    
536                            reindexFileEntries(companyId, groupId, dataRepositoryId);
537                    }
538            }
539    
540            protected String extractDDMContent(
541                            DLFileVersion dlFileVersion, Locale locale)
542                    throws Exception {
543    
544                    List<DLFileEntryMetadata> dlFileEntryMetadatas =
545                            DLFileEntryMetadataLocalServiceUtil.
546                                    getFileVersionFileEntryMetadatas(
547                                            dlFileVersion.getFileVersionId());
548    
549                    StringBundler sb = new StringBundler(dlFileEntryMetadatas.size());
550    
551                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
552                            DDMFormValues ddmFormValues = null;
553    
554                            try {
555                                    ddmFormValues = StorageEngineManagerUtil.getDDMFormValues(
556                                            dlFileEntryMetadata.getDDMStorageId());
557                            }
558                            catch (Exception e) {
559                            }
560    
561                            if (ddmFormValues != null) {
562                                    sb.append(
563                                            DDMStructureManagerUtil.extractAttributes(
564                                                    dlFileEntryMetadata.getDDMStructureId(), ddmFormValues,
565                                                    locale));
566                            }
567                    }
568    
569                    return sb.toString();
570            }
571    
572            protected void reindexFileEntries(
573                            long companyId, final long groupId, final long dataRepositoryId)
574                    throws PortalException {
575    
576                    final ActionableDynamicQuery actionableDynamicQuery =
577                            DLFileEntryLocalServiceUtil.getActionableDynamicQuery();
578    
579                    actionableDynamicQuery.setAddCriteriaMethod(
580                            new ActionableDynamicQuery.AddCriteriaMethod() {
581    
582                                    @Override
583                                    public void addCriteria(DynamicQuery dynamicQuery) {
584                                            Property property = PropertyFactoryUtil.forName("folderId");
585    
586                                            long folderId = DLFolderConstants.getFolderId(
587                                                    groupId, dataRepositoryId);
588    
589                                            dynamicQuery.add(property.eq(folderId));
590                                    }
591    
592                            });
593                    actionableDynamicQuery.setCompanyId(companyId);
594                    actionableDynamicQuery.setGroupId(groupId);
595                    actionableDynamicQuery.setPerformActionMethod(
596                            new ActionableDynamicQuery.PerformActionMethod<DLFileEntry>() {
597    
598                                    @Override
599                                    public void performAction(DLFileEntry dlFileEntry) {
600                                            try {
601                                                    Document document = getDocument(dlFileEntry);
602    
603                                                    if (document != null) {
604                                                            actionableDynamicQuery.addDocument(document);
605                                                    }
606                                            }
607                                            catch (PortalException pe) {
608                                                    if (_log.isWarnEnabled()) {
609                                                            _log.warn(
610                                                                    "Unable to index document library file entry " +
611                                                                            dlFileEntry.getFileEntryId(),
612                                                                    pe);
613                                                    }
614                                            }
615                                    }
616    
617                            });
618                    actionableDynamicQuery.setSearchEngineId(getSearchEngineId());
619    
620                    actionableDynamicQuery.performActions();
621            }
622    
623            protected void reindexFolders(final long companyId) throws PortalException {
624                    ActionableDynamicQuery actionableDynamicQuery =
625                            DLFolderLocalServiceUtil.getActionableDynamicQuery();
626    
627                    actionableDynamicQuery.setCompanyId(companyId);
628                    actionableDynamicQuery.setPerformActionMethod(
629                            new ActionableDynamicQuery.PerformActionMethod<DLFolder>() {
630    
631                                    @Override
632                                    public void performAction(DLFolder dlFolder)
633                                            throws PortalException {
634    
635                                            long groupId = dlFolder.getGroupId();
636                                            long folderId = dlFolder.getFolderId();
637    
638                                            String[] newIds = {
639                                                    String.valueOf(companyId), String.valueOf(groupId),
640                                                    String.valueOf(folderId)
641                                            };
642    
643                                            reindex(newIds);
644                                    }
645    
646                            });
647    
648                    actionableDynamicQuery.performActions();
649            }
650    
651            protected void reindexRoot(final long companyId) throws PortalException {
652                    ActionableDynamicQuery actionableDynamicQuery =
653                            GroupLocalServiceUtil.getActionableDynamicQuery();
654    
655                    actionableDynamicQuery.setCompanyId(companyId);
656                    actionableDynamicQuery.setPerformActionMethod(
657                            new ActionableDynamicQuery.PerformActionMethod<Group>() {
658    
659                                    @Override
660                                    public void performAction(Group group) throws PortalException {
661                                            long groupId = group.getGroupId();
662                                            long folderId = groupId;
663    
664                                            String[] newIds = {
665                                                    String.valueOf(companyId), String.valueOf(groupId),
666                                                    String.valueOf(folderId)
667                                            };
668    
669                                            reindex(newIds);
670                                    }
671    
672                            });
673    
674                    actionableDynamicQuery.performActions();
675            }
676    
677            private static final Log _log = LogFactoryUtil.getLog(
678                    DLFileEntryIndexer.class);
679    
680            private final RelatedEntryIndexer _relatedEntryIndexer =
681                    new BaseRelatedEntryIndexer();
682    
683    }