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.plugins.odfweb.service.search.criterion;
017
018import java.util.Map;
019
020import org.ametys.cms.contenttype.ContentType;
021import org.ametys.cms.contenttype.ContentTypeExtensionPoint;
022import org.ametys.cms.data.ContentValue;
023import org.ametys.runtime.model.ElementDefinition;
024import org.ametys.runtime.model.Enumerator;
025import org.ametys.web.frontoffice.search.metamodel.RestrictedEnumerator;
026import org.ametys.web.frontoffice.search.metamodel.impl.ContentEnumerator;
027import org.ametys.web.frontoffice.search.metamodel.impl.ContentReferencingSearchServiceCriterionDefinition;
028import org.ametys.web.frontoffice.search.metamodel.impl.RestrictedWrappedEnumerator;
029
030/**
031 * {@link ContentReferencingSearchServiceCriterionDefinition} for a orgUnit content attribute.
032 */
033public class OrgUnitCriterionDefinition extends ContentReferencingSearchServiceCriterionDefinition
034{
035    /**
036     * Constructor used to create a FO criterion definition referencing the orgUnit
037     * @param reference the item referenced by this criterion
038     * @param referencePath the path of the criterion's reference
039     * @param baseContentType the content type defining the reference
040     */
041    public OrgUnitCriterionDefinition(ElementDefinition reference, String referencePath, ContentType baseContentType)
042    {
043        super(reference, referencePath, baseContentType);
044    }
045    
046    @Override
047    public RestrictedEnumerator<ContentValue> getRestrictedEnumerator(Map<String, Object> contextualParameters)
048    {
049        Enumerator<ContentValue> enumerator = new OrgUnitEnumerator(this, _getContentTypeExtensionPoint(), contextualParameters);
050        return new RestrictedWrappedEnumerator<>(enumerator, getName());
051    }
052
053    static class OrgUnitEnumerator extends ContentEnumerator
054    {
055        OrgUnitEnumerator(ContentReferencingSearchServiceCriterionDefinition criterionDefinition, ContentTypeExtensionPoint contentTypeExtensionPoint, Map<String, Object> contextualParameters)
056        {
057            super(criterionDefinition, contentTypeExtensionPoint, contextualParameters);
058        }
059        
060        @Override
061        protected boolean allowLanguageExpression()
062        {
063            // ODF-4218: The orgUnit content is never translated, so the language expression is not relevant for this criterion definition
064            return false;
065        }
066    }
067}