001/*
002 *  Copyright 2019 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;
017
018import java.util.Arrays;
019import java.util.Collection;
020import java.util.Collections;
021import java.util.Optional;
022
023import org.ametys.cms.search.query.Query;
024import org.ametys.odf.course.Course;
025import org.ametys.odf.course.CourseFactory;
026import org.ametys.web.frontoffice.search.metamodel.AdditionalParameterValueMap;
027import org.ametys.web.frontoffice.search.metamodel.Returnable;
028import org.ametys.web.frontoffice.search.metamodel.Searchable;
029import org.ametys.web.frontoffice.search.metamodel.impl.AbstractContentBasedSearchable;
030
031/**
032 * {@link Searchable} for {@link Course}s
033 */
034public class CourseSearchable extends AbstractContentBasedSearchable
035{
036    /** Avalon Role */
037    public static final String ROLE = CourseSearchable.class.getName();
038    
039    private static final String __CRITERION_DEFINITIONS_PREFIX_ID = "CourseSearchable$";
040    
041    @Override
042    protected String associatedContentReturnableRole()
043    {
044        return CourseReturnable.ROLE;
045    }
046    
047    @Override
048    protected String getCriterionDefinitionPrefix()
049    {
050        return __CRITERION_DEFINITIONS_PREFIX_ID;
051    }
052    
053    @Override
054    public Collection<Returnable> relationsWith()
055    {
056        return Arrays.asList(_associatedContentReturnable);
057    }
058    
059    @Override
060    protected Collection<String> getContentTypes(AdditionalParameterValueMap additionalParameterValues)
061    {
062        return Collections.singleton(CourseFactory.COURSE_CONTENT_TYPE);
063    }
064    
065    @Override
066    public Optional<Query> joinQuery(Query queryOnCriterion, Collection<Returnable> returnables, AdditionalParameterValueMap additionalParameters)
067    {
068        if (returnables.contains(_associatedContentReturnable))
069        {
070            return Optional.of(queryOnCriterion);
071        }
072        else
073        {
074            return Optional.empty();
075        }
076    }
077}
078