001/*
002 *  Copyright 2022 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.data.holder.group;
017
018import java.util.List;
019
020import org.apache.solr.common.SolrInputDocument;
021
022import org.ametys.cms.data.holder.IndexableDataHolder;
023import org.ametys.cms.model.CMSDataContext;
024import org.ametys.plugins.repository.data.holder.group.Repeater;
025import org.ametys.runtime.model.exception.BadItemTypeException;
026
027/**
028 * Interface for indexable repeaters
029 */
030public interface IndexableRepeater extends Repeater
031{
032    /**
033     * Indexes all data and properties of this {@link Repeater}
034     * @param document the solr document representing th {@link Repeater}
035     * @param rootDocument the solr document of the root object.
036     * @param solrFieldPrefix the prefix of the solr field
037     * @return additional solr documents that may have been created (ex: repeater entries)
038     * @throws BadItemTypeException if the saxed value's type does not matches the stored data
039     */
040    public default List<SolrInputDocument> indexData(SolrInputDocument document, SolrInputDocument rootDocument, String solrFieldPrefix) throws BadItemTypeException
041    {
042        return indexData(document, rootDocument, solrFieldPrefix, CMSDataContext.newInstance());
043    }
044    
045    /**
046     * Indexes all data and properties of this {@link Repeater}
047     * @param document the solr document representing this {@link Repeater}
048     * @param rootDocument the solr document of the root object.
049     * @param solrFieldPrefix the prefix of the solr field
050     * @param context The context of the data to index
051     * @return additional solr documents that may have been created (ex: repeater entries)
052     * @throws BadItemTypeException if the saxed value's type does not matches the stored data
053     */
054    public List<SolrInputDocument> indexData(SolrInputDocument document, SolrInputDocument rootDocument, String solrFieldPrefix, CMSDataContext context) throws BadItemTypeException;
055    
056    @Override
057    public List<? extends IndexableRepeaterEntry> getEntries();
058
059    @Override
060    public IndexableRepeaterEntry getEntry(int position);
061    
062    @Override
063    public IndexableDataHolder getParentDataHolder();
064    
065    @Override
066    public IndexableDataHolder getRootDataHolder();
067}