001/* 002 * Copyright 2022 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 */ 016 017package org.ametys.plugins.calendar.search; 018 019import java.util.Arrays; 020import java.util.Collection; 021import java.util.HashSet; 022import java.util.Optional; 023import java.util.Set; 024 025import org.ametys.cms.search.query.Query; 026import org.ametys.web.frontoffice.search.metamodel.AdditionalParameterValueMap; 027import org.ametys.web.frontoffice.search.metamodel.Returnable; 028import org.ametys.web.frontoffice.search.metamodel.SearchServiceCriterionDefinition; 029import org.ametys.web.frontoffice.search.metamodel.Searchable; 030import org.ametys.web.frontoffice.search.metamodel.impl.AbstractContentBasedSearchable; 031 032/** 033 * {@link Searchable} for contents with a start date 034 * 035 */ 036public class CalendarContentSearchable extends AbstractContentBasedSearchable 037{ 038 /** Avalon Role */ 039 public static final String ROLE = CalendarContentSearchable.class.getName(); 040 041 /** The prefix for content with date searchable */ 042 public static final String CRITERION_DEFINITION_PREFIX_ID = "ContentWithDateSearchable$"; 043 044 public Optional<Query> joinQuery(Query queryOnCriterion, SearchServiceCriterionDefinition criterion, Collection<Returnable> returnables, AdditionalParameterValueMap additionalParameters) 045 { 046 if (returnables.contains(_associatedContentReturnable)) 047 { 048 return Optional.of(queryOnCriterion); 049 } 050 else 051 { 052 return Optional.empty(); 053 } 054 } 055 056 @Override 057 public Collection<Returnable> relationsWith() 058 { 059 return Arrays.asList(_associatedContentReturnable); 060 } 061 062 @Override 063 protected String associatedContentReturnableRole() 064 { 065 return CalendarContentReturnable.ROLE; 066 } 067 068 @Override 069 protected String getCriterionDefinitionPrefix() 070 { 071 return CRITERION_DEFINITION_PREFIX_ID; 072 } 073 074 @Override 075 protected Set<String> getContentTypeIds(AdditionalParameterValueMap additionalParameterValues) 076 { 077 Collection<String> contentTypeIds = additionalParameterValues.getValue(CalendarSearchService.SERVICE_PARAM_CONTENT_TYPES); 078 return contentTypeIds != null 079 ? new HashSet<>(contentTypeIds) 080 : Set.of(); 081 } 082 083}