001/*
002 *  Copyright 2018 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.odfsync.apogee.scc;
017
018import java.util.List;
019import java.util.Map;
020
021import org.apache.avalon.framework.service.ServiceException;
022import org.apache.avalon.framework.service.ServiceManager;
023
024import org.ametys.odf.ProgramItem;
025import org.ametys.odf.catalog.CatalogsManager;
026import org.ametys.odf.orgunit.OrgUnit;
027import org.ametys.odf.workflow.AbstractCreateODFContentFunction;
028import org.ametys.plugins.repository.query.expression.Expression;
029import org.ametys.plugins.repository.query.expression.Expression.Operator;
030import org.ametys.plugins.repository.query.expression.StringExpression;
031
032/**
033 * Abstract class for Apogee synchronization, contents with catalog (not {@link OrgUnit}).
034 */
035public abstract class AbstractApogeeSynchronizableContentsWithCatalogCollection extends AbstractApogeeSynchronizableContentsCollection
036{
037    /** The catalog manager */
038    protected CatalogsManager _catalogsManager;
039
040    @Override
041    public void service(ServiceManager manager) throws ServiceException
042    {
043        super.service(manager);
044        _catalogsManager = (CatalogsManager) manager.lookup(CatalogsManager.ROLE);
045    }
046    
047    @Override
048    protected Map<String, Object> _getAdditionalInputsForContentCreation()
049    {
050        Map<String, Object> inputs = super._getAdditionalInputsForContentCreation();
051        
052        String defaultCatalog = _catalogsManager.getDefaultCatalogName();
053        if (defaultCatalog != null)
054        {
055            inputs.put(AbstractCreateODFContentFunction.CONTENT_CATALOG_KEY, defaultCatalog);
056        }
057        
058        return inputs;
059    }
060    
061    @Override
062    protected List<Expression> _getExpressionsList(String lang, String idValue, String contentType)
063    {
064        List<Expression> expList = super._getExpressionsList(lang, idValue, contentType);
065        String defaultCatalog = _catalogsManager.getDefaultCatalogName();
066        if (defaultCatalog != null)
067        {
068            expList.add(new StringExpression(ProgramItem.CATALOG, Operator.EQ, defaultCatalog));
069        }
070        return expList;
071    }
072}