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.exportimport.lar;
016    
017    import com.liferay.portal.kernel.search.BaseIndexer;
018    import com.liferay.portal.kernel.search.Document;
019    import com.liferay.portal.kernel.search.Indexer;
020    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
021    import com.liferay.portal.kernel.search.Summary;
022    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
023    import com.liferay.portal.kernel.util.GetterUtil;
024    
025    import java.util.Locale;
026    import java.util.Map;
027    
028    import javax.portlet.PortletRequest;
029    import javax.portlet.PortletResponse;
030    
031    /**
032     * @author Mate Thurzo
033     */
034    @OSGiBeanProperties
035    public class PortletDataContextIndexer extends BaseIndexer {
036    
037            public static final String CLASS_NAME = PortletDataContext.class.getName();
038    
039            @Override
040            public String getClassName() {
041                    return CLASS_NAME;
042            }
043    
044            @Override
045            protected void doDelete(Object obj) throws Exception {
046            }
047    
048            @Override
049            protected Document doGetDocument(Object obj) throws Exception {
050                    return null;
051            }
052    
053            @Override
054            protected Summary doGetSummary(
055                            Document document, Locale locale, String snippet,
056                            PortletRequest portletRequest, PortletResponse portletResponse)
057                    throws Exception {
058    
059                    return null;
060            }
061    
062            @Override
063            protected void doReindex(Object obj) throws Exception {
064                    PortletDataContext portletDataContext = (PortletDataContext)obj;
065    
066                    Map<String, Map<?, ?>> newPrimaryKeysMaps =
067                            portletDataContext.getNewPrimaryKeysMaps();
068    
069                    for (Map.Entry<String, Map<?, ?>> entry :
070                                    newPrimaryKeysMaps.entrySet()) {
071    
072                            String className = entry.getKey();
073    
074                            Indexer indexer = IndexerRegistryUtil.getIndexer(className);
075    
076                            if (indexer == null) {
077                                    continue;
078                            }
079    
080                            Map<?, ?> newPrimaryKeysMap = entry.getValue();
081    
082                            for (Object object : newPrimaryKeysMap.values()) {
083                                    long classPK = GetterUtil.getLong(object);
084    
085                                    if (classPK > 0) {
086                                            indexer.reindex(className, classPK);
087                                    }
088                            }
089                    }
090            }
091    
092            @Override
093            protected void doReindex(String className, long classPK) throws Exception {
094            }
095    
096            @Override
097            protected void doReindex(String[] ids) throws Exception {
098            }
099    
100    }