001/* 002 * Copyright 2015 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.cms.search.model; 017 018import java.util.Collection; 019import java.util.Map; 020 021import org.ametys.cms.data.ametysobject.ModelAwareDataAwareAmetysObject; 022import org.ametys.cms.model.properties.Property; 023import org.ametys.cms.search.SearchField; 024import org.ametys.cms.search.query.Query; 025import org.ametys.cms.search.query.Query.Operator; 026import org.ametys.cms.search.solr.schema.SchemaDefinition; 027 028/** 029 * Represents a universal property of a supported {@link ModelAwareDataAwareAmetysObject} 030 * Ex: content types, language or current workflow steps are some system properties supporting contents 031 * @param <T> type of the property values 032 * @param <X> type of ametys object supported by this property 033 */ 034public interface SystemProperty<T, X extends ModelAwareDataAwareAmetysObject> extends Property<T, X> 035{ 036 /** 037 * Get if the property can be searched on (i.e. used in a SearchCriterion). 038 * @return <code>true</code> if the property can be searched on, <code>false</code> otherwise. 039 */ 040 public default boolean isSearchable() 041 { 042 // Default to true: override when the property is not searchable. 043 return true; 044 } 045 046 /** 047 * Get if the property can be displayed (i.e. used in a ResultField). 048 * @return <code>true</code> if the property can be displayed, <code>false</code> otherwise. 049 */ 050 public default boolean isDisplayable() 051 { 052 // Default to true: override when the property is not displayable. 053 return true; 054 } 055 056 /** 057 * Get if the property can be sorted on. 058 * @return <code>true</code> if the property can be sorted on, <code>false</code> otherwise. 059 */ 060 public default boolean isSortable() 061 { 062 // Default to true: override when the property is not sortable. 063 return true; 064 } 065 066 /** 067 * Gets if the property can be facetable 068 * @return <code>true</code> if the property can be facetable, <code>false</code> otherwise. 069 */ 070 public default boolean isFacetable() 071 { 072 SearchField searchField = getSearchField(); 073 return searchField != null ? searchField.getFacetField() != null : false; 074 } 075 076 /** 077 * Get the {@link Query} associated to the given value. 078 * @param value the user-submitted value for this property. 079 * @param operator In advanced search mode, the operator chosen by the user. <code>null</code> to use the criterion-defined operator (simple search mode). 080 * @param language The current search language. 081 * @param contextualParameters the search contextual parameters. 082 * @return The {@link Query} associated to the given value. 083 */ 084 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters); 085 086 /** 087 * Get the renderer. 088 * @return The column renderer. 089 */ 090 public default String getRenderer() 091 { 092 return null; 093 } 094 095 /** 096 * Get the property column converter. 097 * @return The property column converter. 098 */ 099 public default String getConverter() 100 { 101 return null; 102 } 103 104 /** 105 * Get the column width. 106 * @return the default column width, can be null. 107 */ 108 public default Integer getColumnWidth() 109 { 110 return null; 111 } 112 113 /** 114 * Get the {@link SearchField} representing this system property. 115 * @return The search field representing this system property. 116 */ 117 public SearchField getSearchField(); 118 119 /** 120 * Get the sort value represented by this field in the given result ametys object. 121 * @param ametysObject the result ametys object. 122 * @return the content sort value, must be scalar (String, long, double, Date). 123 */ 124 public default Object getSortValue(X ametysObject) 125 { 126 // Not sortable by default; 127 return null; 128 } 129 130 /** 131 * Get the schema definitions brought by this property. 132 * @return The schema definitions used by this property. 133 */ 134 public Collection<SchemaDefinition> getSchemaDefinitions(); 135}