001/*
002 *  Copyright 2026 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.impl;
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.holder.group.IndexableRepeater;
024import org.ametys.cms.data.holder.group.IndexableRepeaterEntry;
025import org.ametys.cms.data.holder.impl.IndexableDataHolderHelper;
026import org.ametys.cms.model.CMSDataContext;
027import org.ametys.plugins.repository.data.holder.group.impl.DefaultRepeater;
028import org.ametys.plugins.repository.data.repositorydata.RepositoryData;
029import org.ametys.plugins.repository.model.RepeaterDefinition;
030import org.ametys.runtime.model.exception.BadItemTypeException;
031
032/**
033 * Class for indexable model aware repeaters
034 */
035public class DefaultIndexableRepeater extends DefaultRepeater implements IndexableRepeater
036{
037    /**
038     * Creates a default indexable repeater
039     * @param repositoryData the repository data of the repeater
040     * @param definition the definition of the repeater
041     * @param parent the parent of the created repeater
042     * @param root the root {@link IndexableDataHolder}
043     */
044    public DefaultIndexableRepeater(RepositoryData repositoryData, RepeaterDefinition definition, IndexableDataHolder parent, IndexableDataHolder root)
045    {
046        super(repositoryData, definition, parent, root);
047    }
048
049    @SuppressWarnings("unchecked")
050    @Override
051    public List<? extends IndexableRepeaterEntry> getEntries()
052    {
053        return (List< ? extends IndexableRepeaterEntry>) super.getEntries();
054    }
055    
056    @Override
057    public IndexableRepeaterEntry getEntry(int position)
058    {
059        return (IndexableRepeaterEntry) super.getEntry(position);
060    }
061
062    @Override
063    protected IndexableRepeaterEntry createRepeaterEntryInstance(RepositoryData entryRepositoryData)
064    {
065        return new DefaultIndexableRepeaterEntry(entryRepositoryData, _definition, this);
066    }
067    
068    public List<SolrInputDocument> indexData(SolrInputDocument document, SolrInputDocument rootDocument, String solrFieldPrefix, CMSDataContext context) throws BadItemTypeException
069    {
070        return IndexableDataHolderHelper.indexRepeaterData(this, document, rootDocument, solrFieldPrefix, context);
071    }
072
073    @Override
074    public IndexableDataHolder getParentDataHolder()
075    {
076        return (IndexableDataHolder) _parent;
077    }
078
079    @Override
080    public IndexableDataHolder getRootDataHolder()
081    {
082        return (IndexableDataHolder) _root;
083    }
084}