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.model.SystemProperty; 022import org.ametys.cms.search.query.Query; 023import org.ametys.cms.search.query.Query.Operator; 024import org.ametys.cms.search.systemprop.AbstractIndexableSystemProperty; 025import org.ametys.runtime.model.type.ModelItemTypeConstants; 026import org.ametys.web.repository.content.WebContent; 027import org.ametys.web.search.query.OrphanQuery; 028 029/** 030 * {@link SystemProperty} which represents the orphan status of a Content. 031 */ 032public class OrphanSystemProperty extends AbstractIndexableSystemProperty<Boolean, Boolean, Content> 033{ 034 /** System property identifier */ 035 public static final String SYSTEM_PROPERTY_ID = "orphan"; 036 037 /** Solr field name. */ 038 public static final String SOLR_FIELD_NAME = SYSTEM_PROPERTY_ID; 039 040 @Override 041 public Integer getColumnWidth() 042 { 043 return 80; 044 } 045 046 @Override 047 public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters) 048 { 049 if (value == null) 050 { 051 return new OrphanQuery(); 052 } 053 return new OrphanQuery((Boolean) value, operator); 054 } 055 056 @Override 057 public String getSolrFieldName() 058 { 059 return SOLR_FIELD_NAME; 060 } 061 062 @Override 063 public String getSolrSortFieldName() 064 { 065 return SOLR_FIELD_NAME; 066 } 067 068 @Override 069 public String getSolrFacetFieldName() 070 { 071 return SOLR_FIELD_NAME; 072 } 073 074 @Override 075 public Object getValue(Content content) 076 { 077 if (content instanceof WebContent webContent) 078 { 079 return webContent.getReferencingPages().isEmpty(); 080 } 081 082 return null; 083 } 084 085 @Override 086 protected String getTypeId() 087 { 088 return ModelItemTypeConstants.BOOLEAN_TYPE_ID; 089 } 090}