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