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.cdmfr.components.impl;
017
018import java.util.List;
019import java.util.Map;
020
021import javax.jcr.RepositoryException;
022
023import org.apache.commons.lang3.StringUtils;
024import org.slf4j.Logger;
025
026import org.ametys.cms.repository.ModifiableDefaultContent;
027import org.ametys.plugins.contentio.synchronize.expression.CollectionExpression;
028import org.ametys.plugins.odfsync.cdmfr.components.AbstractImportCDMFrComponent;
029import org.ametys.plugins.repository.query.expression.Expression;
030
031/**
032 * Component to import a CDM-fr input stream in SCC context.
033 */
034public class SCCImportCDMFrComponent extends AbstractImportCDMFrComponent
035{
036    /** The collectionID */
037    protected String _collectionId;
038    
039    /** Validate after import */
040    protected boolean _validateAfterImport;
041
042    /** True if removal sync */
043    protected boolean _removalSync;
044    
045    @Override
046    protected void additionalParameters(Map<String, Object> parameters)
047    {
048        _collectionId = (String) parameters.get("collectionId");
049        _validateAfterImport = (boolean) parameters.getOrDefault("validateAfterImport", false);
050        _removalSync = (boolean) parameters.getOrDefault("removalSync", false);
051    }
052
053    @Override
054    protected void additionalOperationsBeforeSave(ModifiableDefaultContent content, Logger logger) throws RepositoryException
055    {
056        _synchroComponent.updateSCCProperty(content, _collectionId);
057    }
058    
059    @Override
060    public List<Expression> getExpressionsList(String lang, String idValue, String contentType, String catalog)
061    {
062        List<Expression> expList = super.getExpressionsList(lang, idValue, contentType, catalog);
063        
064        if (StringUtils.isNotBlank(_collectionId))
065        {
066            expList.add(new CollectionExpression(_collectionId));
067        }
068        
069        return expList;
070    }
071
072    @Override
073    protected boolean validateAfterImport()
074    {
075        return _validateAfterImport;
076    }
077
078    @Override
079    protected boolean removalSync()
080    {
081        return _removalSync;
082    }
083}