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.systemprop;
017
018import java.util.LinkedHashMap;
019import java.util.Map;
020
021import org.ametys.cms.content.indexing.solr.SolrFieldNames;
022import org.ametys.cms.repository.Content;
023import org.ametys.cms.search.SearchField;
024import org.ametys.cms.search.model.SystemProperty;
025import org.ametys.cms.search.solr.field.ContributorSearchField;
026import org.ametys.core.user.UserIdentity;
027
028/**
029 * {@link SystemProperty} which represents the last contributor of a content.
030 */
031public class ContributorSystemProperty extends AbstractUserSystemProperty
032{
033    @Override
034    public boolean isMultiple()
035    {
036        return false;
037    }
038    
039    @Override
040    public boolean isSortable()
041    {
042        return true;
043    }
044    
045    @Override
046    protected String _getSolrFieldName()
047    {
048        return SolrFieldNames.CONTENT_LAST_CONTRIBUTOR;
049    }
050    
051    @Override
052    public SearchField getSearchField()
053    {
054        return new ContributorSearchField();
055    }
056    
057    @Override
058    public Object getValue(Content content)
059    {
060        return UserIdentity.userIdentityToString(content.getLastContributor());
061    }
062    
063    @Override
064    public Object getFullValue(Content content)
065    {
066        Map<String, Object> infos = new LinkedHashMap<>();
067        
068        setUserInfos(infos, content.getLastContributor());
069        
070        return infos;
071    }
072
073}