001/*
002 *  Copyright 2020 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.plugins.workspaces.wall;
017
018import org.apache.avalon.framework.configuration.Configurable;
019import org.apache.avalon.framework.configuration.Configuration;
020import org.apache.avalon.framework.configuration.ConfigurationException;
021
022import org.ametys.cms.contenttype.MetadataType;
023import org.ametys.cms.contenttype.indexing.CustomIndexingField;
024import org.ametys.cms.repository.Content;
025import org.ametys.cms.repository.TaggableAmetysObject;
026import org.ametys.plugins.workspaces.indexing.solr.SolrWorkspacesConstants;
027import org.ametys.runtime.i18n.I18nizableText;
028import org.ametys.runtime.plugin.component.PluginAware;
029
030/**
031 * {@link CustomIndexingField} for pinned wall content
032 *
033 */
034public class PinIndexingField implements CustomIndexingField, Configurable, PluginAware
035{
036    private String _pluginName;
037    private I18nizableText _label;
038    private I18nizableText _description;
039
040    public void setPluginInfo(String pluginName, String featureName, String id)
041    {
042        _pluginName = pluginName;
043    }
044    
045    public void configure(Configuration configuration) throws ConfigurationException
046    {
047        _label = I18nizableText.parseI18nizableText(configuration.getChild("label"), "plugin" + _pluginName);
048        _description = I18nizableText.parseI18nizableText(configuration.getChild("description"), "plugin" + _pluginName);
049        
050    }
051    
052    public String getName()
053    {
054        return SolrWorkspacesConstants.PINNED;
055    }
056
057    public I18nizableText getLabel()
058    {
059        return _label;
060    }
061
062    public I18nizableText getDescription()
063    {
064        return _description;
065    }
066
067    public MetadataType getType()
068    {
069        return MetadataType.BOOLEAN;
070    }
071
072    public Object[] getValues(Content content)
073    {
074        boolean isPinned = content instanceof TaggableAmetysObject && content.getTags().contains(WallContentManager.WALL_CONTENT_PIN_TAG);
075        return new Boolean[] {isPinned};
076    }
077}