001/*
002 *  Copyright 2016 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.workflow;
017
018import java.util.Map;
019
020import org.ametys.cms.repository.WorkflowAwareContent;
021import org.ametys.cms.workflow.ValidateContentFunction;
022import org.ametys.runtime.i18n.I18nizableText;
023
024import com.opensymphony.module.propertyset.PropertySet;
025import com.opensymphony.workflow.WorkflowException;
026
027/**
028 * OSWorkflow function for validating a synchronizable content.
029 */
030public class ValidateSynchronizedContentFunction extends ValidateContentFunction
031{
032    @Override
033    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException
034    {
035        if ((boolean) getResultsMap(transientVars).getOrDefault(HAS_CHANGED_KEY, true))
036        {
037            super.execute(transientVars, args, ps);
038        }
039    }
040    
041    @Override
042    protected void _setCurrentStepIdAndNotify(WorkflowAwareContent content, Map transientVars) throws WorkflowException
043    {
044        if (content != null)
045        {
046            // Step doesn't change, just notify
047            _notify(content, transientVars);
048        }
049    }
050    
051    @Override
052    protected String _getDefaultEvent()
053    {
054        // Step doesn't change, so not workflow change to notify by default
055        return null;
056    }
057    
058    @Override
059    protected boolean _isMajorValidation(Map<String, Object> contextParameters, Map args)
060    {
061        return false;
062    }
063    
064    @Override
065    public I18nizableText getLabel()
066    {
067        return new I18nizableText("plugin.contentio", "PLUGINS_CONTENTIO_VALIDATE_SYNCHRONIZED_CONTENT_FUNCTION_LABEL");
068    }
069}