001/*
002 *  Copyright 2015 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.content.indexing.solr;
017
018import java.util.List;
019
020import org.apache.avalon.framework.component.Component;
021import org.apache.solr.common.SolrInputDocument;
022
023import org.ametys.cms.model.CMSDataContext;
024import org.ametys.cms.trash.element.DefaultTrashElement;
025import org.ametys.runtime.plugin.component.AbstractLogEnabled;
026
027/**
028 * Component for {@link DefaultTrashElement} indexing into a Solr server.
029 */
030public class SolrTrashElementIndexer extends AbstractLogEnabled implements Component, SolrFieldNames
031{
032    /** The component role. */
033    public static final String ROLE = SolrTrashElementIndexer.class.getName();
034    
035    /**
036     * Populate a solr input document by adding fields to index into it.
037     * @param trashElement The trash element to index
038     * @param document The main solr document to index into
039     * @return Additional documents for repeater instances
040     * @throws Exception if an error occurred while indexing
041     */
042    public List<SolrInputDocument> indexTrashElement(DefaultTrashElement trashElement, SolrInputDocument document) throws Exception
043    {
044        // Properties specific to a stand-alone indexation.
045        document.addField(ID, trashElement.getId());
046        document.addField(DOCUMENT_TYPE, TYPE_TRASH_ELEMENT);
047        
048        // Index trash element properties and attributes
049        return trashElement.indexData(document, CMSDataContext.newInstance());
050    }
051}