001/*
002 *  Copyright 2025 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.odf.skill;
017
018import java.util.ArrayList;
019import java.util.List;
020import java.util.Map;
021
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024
025import org.ametys.cms.search.model.impl.AbstractStaticSearchModelCriterionDefinition;
026import org.ametys.cms.search.query.BooleanQuery;
027import org.ametys.cms.search.query.OrQuery;
028import org.ametys.cms.search.query.Query;
029import org.ametys.cms.search.query.Query.Operator;
030import org.ametys.cms.search.query.StringQuery;
031import org.ametys.plugins.repository.AmetysObjectResolver;
032import org.ametys.runtime.model.type.ModelItemTypeConstants;
033
034/**
035 * UI criteria to exclude orphans skills
036 */
037public class ExcludeSkillsOrphansCriterionDefinition extends AbstractStaticSearchModelCriterionDefinition<String>
038{
039    /** The ametys object resolver. */
040    protected AmetysObjectResolver _resolver;
041    
042    @Override
043    public void service(ServiceManager manager) throws ServiceException
044    {
045        super.service(manager);
046        _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE);
047    }
048    
049    @Override
050    public Operator getOperator()
051    {
052        // Not suppose to be used
053        return Operator.EQ;
054    }
055    
056    @Override
057    protected String getTypeId()
058    {
059        return ModelItemTypeConstants.STRING_TYPE_ID;
060    }
061
062    @Override
063    public Query getQuery(Object value, Operator customOperator, Map<String, Object> allValues, String language, Map<String, Object> contextualParameters)
064    {
065        List<Query> queries = new ArrayList<>();
066        
067        queries.add(new BooleanQuery("transversal", true));
068        queries.add(new StringQuery("parentProgram"));
069        
070        return new OrQuery(queries);
071    }
072}