001/*
002 *  Copyright 2023 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.contentio.synchronize.systemprop;
017
018import java.util.Map;
019
020import org.apache.solr.common.SolrInputDocument;
021
022import org.ametys.cms.data.type.ModelItemTypeConstants;
023import org.ametys.cms.data.type.indexing.IndexableDataContext;
024import org.ametys.cms.repository.Content;
025import org.ametys.cms.search.SearchField;
026import org.ametys.cms.search.model.SystemProperty;
027import org.ametys.cms.search.query.Query;
028import org.ametys.cms.search.query.Query.Operator;
029import org.ametys.cms.search.systemprop.AbstractUserSystemProperty;
030import org.ametys.core.user.UserIdentity;
031import org.ametys.plugins.contentio.synchronize.SynchronizableContentsCollection;
032
033/**
034 * {@link SystemProperty} which represents the last synchronization user of a content.
035 */
036public class LastSynchronizationUserSystemProperty extends AbstractUserSystemProperty<Content>
037{
038    @Override
039    protected UserIdentity _getUserIdentityValue(Content content)
040    {
041        return content.getInternalDataHolder()
042                      .getValueOfType(SynchronizableContentsCollection.LAST_SYNCHRONIZATION_USER_DATA_NAME, ModelItemTypeConstants.USER_ELEMENT_TYPE_ID);
043    }
044    
045    @Override
046    public void indexValue(SolrInputDocument document, Content ametysObject, IndexableDataContext context)
047    {
048        // Do nothing, this metadata is not indexed
049    }
050    
051    @Override
052    public Query getQuery(Object value, Operator operator, String language, Map<String, Object> contextualParameters)
053    {
054        // No query available for synchronization metadata
055        return null;
056    }
057
058    public SearchField getSearchField()
059    {
060        // No search field available for synchronization metadata
061        return null;
062    }
063
064    @Override
065    protected String _getSolrFieldName()
066    {
067        throw new UnsupportedOperationException("synchronization metadata is not indexed, so it has no solr field name");
068    }
069}