001/* 002 * Copyright 2017 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.search.systemprop; 017 018import java.util.Map; 019 020import org.ametys.cms.repository.Content; 021import org.ametys.cms.search.SearchField; 022import org.ametys.cms.search.model.SystemProperty; 023import org.ametys.cms.search.query.Query; 024import org.ametys.cms.search.query.Query.Operator; 025import org.ametys.cms.search.systemprop.AbstractSystemProperty; 026import org.ametys.runtime.model.type.ModelItemTypeConstants; 027import org.ametys.web.repository.content.WebContent; 028import org.ametys.web.search.query.SiteTypeQuery; 029import org.ametys.web.search.solr.field.SiteTypeSearchField; 030 031/** 032 * {@link SystemProperty} which represents the site type of a Content. 033 */ 034public class SiteTypeSystemProperty extends AbstractSystemProperty<String, Content> 035{ 036 @Override 037 public boolean isMultiple() 038 { 039 return false; 040 } 041 042 @Override 043 public boolean isSortable() 044 { 045 return true; 046 } 047 048 @Override 049 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters) 050 { 051 return new SiteTypeQuery(operator, (String) value); 052 } 053 054 055 @Override 056 public SearchField getSearchField() 057 { 058 return new SiteTypeSearchField(); 059 } 060 061 @Override 062 public Object getValue(Content content) 063 { 064 if (content instanceof WebContent webContent) 065 { 066 return webContent.getSite().getType(); 067 } 068 069 return null; 070 } 071 072 @Override 073 public Object getSortValue(Content content) 074 { 075 if (content instanceof WebContent webContent) 076 { 077 return webContent.getSite().getType(); 078 } 079 080 return null; 081 } 082 083 @Override 084 protected String _getTypeId() 085 { 086 return ModelItemTypeConstants.STRING_TYPE_ID; 087 } 088}