001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
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 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.ecm.automation.core.annotations;
020
021import java.lang.annotation.ElementType;
022import java.lang.annotation.Retention;
023import java.lang.annotation.RetentionPolicy;
024import java.lang.annotation.Target;
025
026import org.nuxeo.ecm.automation.OperationParameters;
027
028/**
029 * To be used on an operation field to inject operation parameters from the current context. If the parameter to inject
030 * cannot be found in the operation parameters map (or it is set to null) then if required is true then an error is
031 * thrown otherwise the injection will not be done (and any default value set in the code will be preserved). The
032 * default is true - i.e. do not allow missing entries in operation parameter map.
033 *
034 * @see OperationParameters
035 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
036 */
037@Retention(RetentionPolicy.RUNTIME)
038@Target(ElementType.FIELD)
039public @interface Param {
040
041    /**
042     * The parameter key in the operation parameters map.
043     */
044    String name();
045
046    /**
047     * @since 5.7.3 The parameter description to explicit its purpose.
048     */
049    String description() default "";
050
051    /**
052     * If the parameter to inject cannot be found in the operation parameters map (or it is set to null) then if
053     * required is true then an error is thrown otherwise the injection will not be done (and any default value set in
054     * the code will be preserved). The default is true - i.e. do not allow missing entries in operation parameter map.
055     */
056    boolean required() default true;
057
058    /**
059     * Optional attribute - useful to generate operation documentation. Provide a widget type to be used by the UI to
060     * edit this parameter. If no widget is provided the default mechanism is to choose a widget compatible with the
061     * parameter type. For example if the parameter has the type String the default is to use a TextBox but you can
062     * override this by specifying a custom widget type like ListBox, TextArea etc.
063     */
064    String widget() default "";
065
066    /**
067     * Optional attribute - useful to generate operation documentation. Provide default values for the parameter widget.
068     * If the parameter is rendered using a ListBox or ComboBox then this attribute can be used to hold the choices
069     * available in the list. If the widget is not a list then this can be used to specify the default value for the
070     * widget.
071     */
072    String[] values() default {};
073
074    /**
075     * Optional attribute to set a parameter order, used for ordering them when presenting the UI form to fill.
076     */
077    int order() default 0;
078
079    /**
080     * Optional alias for the parameter key. If the operation parameters map does not contain the name, then alias will
081     * be used if any.
082     *
083     * @since 5.9.2
084     */
085    String[] alias() default {};
086}