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.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.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
035{
036    
037    @Override
038    public MetadataType getType()
039    {
040        return MetadataType.BOOLEAN;
041    }
042    
043    @Override
044    public boolean isMultiple()
045    {
046        return false;
047    }
048    
049    @Override
050    public boolean isSortable()
051    {
052        return true;
053    }
054    
055    @Override
056    public Integer getColumnWidth()
057    {
058        return 80;
059    }
060    
061    @Override
062    public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters)
063    {
064        if (value == null)
065        {
066            return new OrphanQuery();
067        }
068        return new OrphanQuery(parseBoolean(value), operator);
069    }
070    
071    @Override
072    public SearchField getSearchField()
073    {
074        return new OrphanSearchField();
075    }
076    
077    @Override
078    public Object getValue(Content content)
079    {
080        if (content instanceof WebContent)
081        {
082            return ((WebContent) content).getReferencingPages().isEmpty();
083        }
084        
085        return null;
086    }
087
088}