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.impl; 017 018import java.util.Map; 019import java.util.Optional; 020 021import org.ametys.cms.contenttype.MetadataType; 022import org.ametys.cms.search.query.Query; 023import org.ametys.cms.search.query.Query.Operator; 024import org.ametys.runtime.i18n.I18nizableText; 025import org.ametys.web.frontoffice.search.metamodel.SearchCriterionDefinition; 026import org.ametys.web.frontoffice.search.metamodel.Searchable; 027import org.ametys.web.search.misc.SiteQueryHelper; 028import org.ametys.web.site.SiteEnumerator; 029 030/** 031 * {@link SearchCriterionDefinition} proposing a search criterion on the site of the indexed document. 032 */ 033public class SiteSearchCriterionDefinition extends AbstractDefaultSearchCriterionDefinition 034{ 035 private SiteQueryHelper _siteQueryHelper; 036 037 /** 038 * Default constructor 039 * @param id The id 040 * @param pluginName The plugin name 041 * @param label The label 042 * @param siteEnumerator The {@link SiteEnumerator} 043 * @param siteQueryHelper The {@link SiteQueryHelper} 044 * @param searchable The {@link Searchable} 045 */ 046 public SiteSearchCriterionDefinition( 047 String id, 048 String pluginName, 049 I18nizableText label, 050 SiteEnumerator siteEnumerator, 051 SiteQueryHelper siteQueryHelper, 052 Optional<Searchable> searchable) 053 { 054 super(id, pluginName, label, MetadataType.STRING, _widget(), _widgetParameters(), Optional.of(siteEnumerator), Optional.empty(), Optional.empty(), searchable); 055 _siteQueryHelper = siteQueryHelper; 056 } 057 058 private static Optional<String> _widget() 059 { 060 return Optional.of("edition.select-sites-criterion"); 061 } 062 063 private static Optional<Map<String, I18nizableText>> _widgetParameters() 064 { 065 return Optional.empty(); 066 } 067 068 @Override 069 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters) 070 { 071 return _siteQueryHelper.getQuery(value, operator, contextualParameters, getId()); 072 } 073}