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.workflow;
017import java.util.ArrayList;
018import java.util.List;
019import java.util.Map;
020
021import org.ametys.plugins.workflow.component.WorkflowArgument;
022import org.ametys.plugins.workflow.support.WorkflowHelper.WorkflowVisibility;
023import org.ametys.runtime.i18n.I18nizableText;
024
025import com.opensymphony.workflow.FunctionProvider;
026
027/**
028 * Interface for adding description and arguments to {@link FunctionProvider}
029 */
030public interface EnhancedFunction extends FunctionProvider
031{
032    /** The order of execution for the function */
033    public static enum FunctionType
034    {
035        /** Function being executed before step change */
036        PRE,
037        /** Function being executed after step change */
038        POST,
039        /** Function that can be executed both before or after step change */
040        BOTH
041    }
042    
043    /**
044     * Get the list of accepted arguments for this function
045     * @return a List of argument names and associated description
046     */
047    public default List<WorkflowArgument> getArguments()
048    {
049        return new ArrayList<>();
050    }
051    
052    /**
053     * Get the label for this function
054     * @return the label
055     */
056    public I18nizableText getLabel();
057    
058    /**
059     * Get the function label depending on arguments values
060     * @param argumentsValues a map of the arguments with their values in current workflow
061     * @return a label to display in workflow editor vue
062     */
063    public default I18nizableText getFullLabel(Map<String, String> argumentsValues)
064    {
065        return getLabel();
066    }
067    
068    /**
069     * Return the type for the function
070     * @return the type 's code
071     */
072    public default FunctionType getFunctionExecType()
073    {
074        return  FunctionType.BOTH;
075    }
076    
077    /**
078     * Get the function's visibilities depending on rights
079     * @return a list of all the allowed right profiles
080     */
081    public default List<WorkflowVisibility> getVisibilities()
082    {
083        ArrayList<WorkflowVisibility> visibilityList = new ArrayList<>();
084        visibilityList.add(WorkflowVisibility.SYSTEM); //By default, none of the enhanced function can be visible without system rights 
085        return visibilityList;
086    }
087}