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.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.OrphanQuery; 029import org.ametys.web.search.solr.field.OrphanSearchField; 030 031/** 032 * {@link SystemProperty} which represents the orphan status of a Content. 033 */ 034public class OrphanSystemProperty extends AbstractSystemProperty<Boolean, 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 Integer getColumnWidth() 050 { 051 return 80; 052 } 053 054 @Override 055 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters) 056 { 057 if (value == null) 058 { 059 return new OrphanQuery(); 060 } 061 return new OrphanQuery(parseBoolean(value), operator); 062 } 063 064 @Override 065 public SearchField getSearchField() 066 { 067 return new OrphanSearchField(); 068 } 069 070 @Override 071 public Object getValue(Content content) 072 { 073 if (content instanceof WebContent webContent) 074 { 075 return webContent.getReferencingPages().isEmpty(); 076 } 077 078 return null; 079 } 080 081 @Override 082 protected String _getTypeId() 083 { 084 return ModelItemTypeConstants.BOOLEAN_TYPE_ID; 085 } 086}