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