001/* 002 * Copyright 2018 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.web.frontoffice.search.metamodel; 017 018import java.util.Collection; 019import java.util.Collections; 020import java.util.Optional; 021 022import org.apache.avalon.framework.configuration.Configuration; 023 024import org.ametys.cms.search.query.Query; 025import org.ametys.runtime.i18n.I18nizableText; 026 027/** 028 * Brings a set of criteria, facets, sorts on a type of objects. 029 */ 030public interface Searchable 031{ 032 /** 033 * Gets the label of the searchable 034 * @return the label of the searchable 035 */ 036 I18nizableText getLabel(); 037 038 /** 039 * Retrieves the relations the type must have with some {@link Returnable}s. 040 * <br> It does not have to be exhaustive (for instance if {@link Returnable#relationsWith()} declares the relation, it is useless to declare it twice) 041 * @return some relations the type must have with some {@link Returnable}s 042 */ 043 default Collection<Returnable> relationsWith() 044 { 045 return Collections.emptyList(); 046 } 047 048 /** 049 * Retrieves the additional parameters to add to the search service 050 * <br>The ids of the parameters must be unique across all {@link Returnable}s and {@link Searchable}s 051 * @return some additional parameters to add to the search service 052 */ 053 default Collection<Configuration> additionalServiceParameters() 054 { 055 return Collections.emptyList(); 056 } 057 058 /** 059 * Gets the criteria 060 * @param additionalParameterValues The additional parameter values 061 * @return the criteria 062 */ 063 Collection<SearchCriterionDefinition> getCriteria(AdditionalParameterValueMap additionalParameterValues); 064 065 /** 066 * The position of the criteria provided by this {@link Searchable} among criteria provided by other {@link Searchable}s. 067 * <br>All criteria provided by the same {@link Searchable} are always packed together, this integer just affects the relative position compared to other {@link Searchable} criteria. 068 * <br>The lowest the integer, the higher it will appear in the UI. 069 * @return The position of the criteria of this {@link Searchable} 070 */ 071 default int criteriaPosition() 072 { 073 return 100; 074 } 075 076 /** 077 * Returns the query which joins the given one (on a criterion) with the given result types 078 * @param queryOnCriterion The query on the criterion to join from 079 * @param returnables The returnables to join to 080 * @param additionalParameters The additional parameters 081 * @return the joined query 082 */ 083 Optional<Query> joinQuery(Query queryOnCriterion, Collection<Returnable> returnables, AdditionalParameterValueMap additionalParameters); 084}