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