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