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