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.contenttype.MetadataType; 021import org.ametys.cms.repository.Content; 022import org.ametys.cms.search.SearchField; 023import org.ametys.cms.search.model.SystemProperty; 024import org.ametys.cms.search.query.Query; 025import org.ametys.cms.search.query.Query.Operator; 026import org.ametys.cms.search.systemprop.AbstractSystemProperty; 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 035{ 036 @Override 037 public MetadataType getType() 038 { 039 return MetadataType.STRING; 040 } 041 042 @Override 043 public boolean isMultiple() 044 { 045 return false; 046 } 047 048 @Override 049 public boolean isSortable() 050 { 051 return true; 052 } 053 054 @Override 055 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters) 056 { 057 return new SiteTypeQuery(operator, (String) value); 058 } 059 060 061 @Override 062 public SearchField getSearchField() 063 { 064 return new SiteTypeSearchField(); 065 } 066 067 @Override 068 public Object getValue(Content content) 069 { 070 if (content instanceof WebContent) 071 { 072 return ((WebContent) content).getSite().getType(); 073 } 074 075 return null; 076 } 077 078 @Override 079 public Object getSortValue(Content content) 080 { 081 if (content instanceof WebContent) 082 { 083 return ((WebContent) content).getSite().getType(); 084 } 085 086 return null; 087 } 088 089}