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.search.BaseIndexer;
018    import com.liferay.portal.kernel.search.DDMStructureIndexer;
019    import com.liferay.portal.kernel.search.Document;
020    import com.liferay.portal.kernel.search.IndexWriterHelperUtil;
021    import com.liferay.portal.kernel.search.Indexer;
022    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
023    import com.liferay.portal.kernel.search.SearchException;
024    import com.liferay.portal.kernel.search.Summary;
025    import com.liferay.portal.kernel.util.ArrayUtil;
026    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
027    import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata;
028    import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
029    
030    import java.util.List;
031    import java.util.Locale;
032    
033    import javax.portlet.PortletRequest;
034    import javax.portlet.PortletResponse;
035    
036    /**
037     * @author Marcellus Tavares
038     */
039    public class DLFileEntryMetadataIndexer
040            extends BaseIndexer<DLFileEntryMetadata> implements DDMStructureIndexer {
041    
042            public static final String CLASS_NAME = DLFileEntryMetadata.class.getName();
043    
044            @Override
045            public String getClassName() {
046                    return CLASS_NAME;
047            }
048    
049            @Override
050            public void reindexDDMStructures(List<Long> ddmStructureIds)
051                    throws SearchException {
052    
053                    if (IndexWriterHelperUtil.isIndexReadOnly() || !isIndexerEnabled()) {
054                            return;
055                    }
056    
057                    try {
058                            Indexer<DLFileEntry> indexer =
059                                    IndexerRegistryUtil.nullSafeGetIndexer(DLFileEntry.class);
060    
061                            List<DLFileEntry> dlFileEntries =
062                                    DLFileEntryLocalServiceUtil.getDDMStructureFileEntries(
063                                            ArrayUtil.toLongArray(ddmStructureIds));
064    
065                            for (DLFileEntry dlFileEntry : dlFileEntries) {
066                                    indexer.reindex(dlFileEntry);
067                            }
068                    }
069                    catch (Exception e) {
070                            throw new SearchException(e);
071                    }
072            }
073    
074            @Override
075            protected void doDelete(DLFileEntryMetadata object) throws Exception {
076            }
077    
078            @Override
079            protected Document doGetDocument(DLFileEntryMetadata object)
080                    throws Exception {
081    
082                    return null;
083            }
084    
085            @Override
086            protected Summary doGetSummary(
087                            Document document, Locale locale, String snippet,
088                            PortletRequest portletRequest, PortletResponse portletResponse)
089                    throws Exception {
090    
091                    return null;
092            }
093    
094            @Override
095            protected void doReindex(DLFileEntryMetadata object) throws Exception {
096            }
097    
098            @Override
099            protected void doReindex(String className, long classPK) throws Exception {
100            }
101    
102            @Override
103            protected void doReindex(String[] ids) throws Exception {
104            }
105    
106    }