Ejemplo n.º 1
0
        protected internal virtual void parseFormField(Element formField, BpmnParse bpmnParse, ExpressionManager expressionManager)
        {
            FormFieldHandler formFieldHandler = new FormFieldHandler();

            // parse Id
            string id = formField.attribute("id");

            if (string.ReferenceEquals(id, null) || id.Length == 0)
            {
                bpmnParse.addError("attribute id must be set for FormFieldGroup and must have a non-empty value", formField);
            }
            else
            {
                formFieldHandler.Id = id;
            }

            if (id.Equals(businessKeyFieldId))
            {
                formFieldHandler.BusinessKey = true;
            }

            // parse name
            string name = formField.attribute("label");

            if (!string.ReferenceEquals(name, null))
            {
                Expression nameExpression = expressionManager.createExpression(name);
                formFieldHandler.Label = nameExpression;
            }

            // parse properties
            parseProperties(formField, formFieldHandler, bpmnParse, expressionManager);

            // parse validation
            parseValidation(formField, formFieldHandler, bpmnParse, expressionManager);

            // parse type
            FormTypes             formTypes = FormTypes;
            AbstractFormFieldType formType  = formTypes.parseFormPropertyType(formField, bpmnParse);

            formFieldHandler.setType(formType);

            // parse default value
            string defaultValue = formField.attribute("defaultValue");

            if (!string.ReferenceEquals(defaultValue, null))
            {
                Expression defaultValueExpression = expressionManager.createExpression(defaultValue);
                formFieldHandler.DefaultValueExpression = defaultValueExpression;
            }

            formFieldHandlers.Add(formFieldHandler);
        }
Ejemplo n.º 2
0
        /// <exception cref="BpmnParseException"> if the parameter is invalid </exception>
        protected internal static ParameterValueProvider parseParamValueProvider(Element parameterElement)
        {
            // LIST
            if ("list".Equals(parameterElement.TagName))
            {
                IList <ParameterValueProvider> providerList = new List <ParameterValueProvider>();
                foreach (Element element in parameterElement.elements())
                {
                    // parse nested provider
                    providerList.Add(parseParamValueProvider(element));
                }
                return(new ListValueProvider(providerList));
            }

            // MAP
            if ("map".Equals(parameterElement.TagName))
            {
                SortedDictionary <ParameterValueProvider, ParameterValueProvider> providerMap = new SortedDictionary <ParameterValueProvider, ParameterValueProvider>();
                foreach (Element entryElement in parameterElement.elements("entry"))
                {
                    // entry must provide key
                    string keyAttribute = entryElement.attribute("key");
                    if (string.ReferenceEquals(keyAttribute, null) || keyAttribute.Length == 0)
                    {
                        throw new BpmnParseException("Missing attribute 'key' for 'entry' element", entryElement);
                    }
                    // parse nested provider
                    providerMap[new ElValueProvider(ExpressionManager.createExpression(keyAttribute))] = parseNestedParamValueProvider(entryElement);
                }
                return(new MapValueProvider(providerMap));
            }

            // SCRIPT
            if ("script".Equals(parameterElement.TagName))
            {
                ExecutableScript executableScript = parseCamundaScript(parameterElement);
                if (executableScript != null)
                {
                    return(new ScriptValueProvider(executableScript));
                }
                else
                {
                    return(new NullValueProvider());
                }
            }

            string textContent = parameterElement.Text.Trim();

            if (textContent.Length > 0)
            {
                // EL
                return(new ElValueProvider(ExpressionManager.createExpression(textContent)));
            }
            else
            {
                // NULL value
                return(new NullValueProvider());
            }
        }
Ejemplo n.º 3
0
        protected internal virtual void initializeTaskDefinitionFollowUpDate(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context)
        {
            HumanTask definition = getDefinition(element);

            string followUpDate = definition.CamundaFollowUpDate;

            if (!string.ReferenceEquals(followUpDate, null))
            {
                ExpressionManager expressionManager      = context.ExpressionManager;
                Expression        followUpDateExpression = expressionManager.createExpression(followUpDate);
                taskDefinition.FollowUpDateExpression = followUpDateExpression;
            }
        }
Ejemplo n.º 4
0
        protected internal virtual TaskListener initializeTaskListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaTaskListener listener)
        {
            ICollection <CamundaField> fields            = listener.CamundaFields;
            IList <FieldDeclaration>   fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields);

            ExpressionManager expressionManager = context.ExpressionManager;

            TaskListener taskListener = null;

            string        className          = listener.CamundaClass;
            string        expression         = listener.CamundaExpression;
            string        delegateExpression = listener.CamundaDelegateExpression;
            CamundaScript scriptElement      = listener.CamundaScript;

            if (!string.ReferenceEquals(className, null))
            {
                taskListener = new ClassDelegateTaskListener(className, fieldDeclarations);
            }
            else if (!string.ReferenceEquals(expression, null))
            {
                Expression expressionExp = expressionManager.createExpression(expression);
                taskListener = new ExpressionTaskListener(expressionExp);
            }
            else if (!string.ReferenceEquals(delegateExpression, null))
            {
                Expression delegateExp = expressionManager.createExpression(delegateExpression);
                taskListener = new DelegateExpressionTaskListener(delegateExp, fieldDeclarations);
            }
            else if (scriptElement != null)
            {
                ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement);
                if (executableScript != null)
                {
                    taskListener = new ScriptTaskListener(executableScript);
                }
            }

            return(taskListener);
        }
Ejemplo n.º 5
0
        protected internal virtual void initializeTaskDefinitionPriority(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context)
        {
            HumanTask definition = getDefinition(element);

            string priority = definition.CamundaPriority;

            if (!string.ReferenceEquals(priority, null))
            {
                ExpressionManager expressionManager  = context.ExpressionManager;
                Expression        priorityExpression = expressionManager.createExpression(priority);
                taskDefinition.PriorityExpression = priorityExpression;
            }
        }
Ejemplo n.º 6
0
        protected internal virtual void initializeTaskDefinitionCandidateGroups(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context)
        {
            HumanTask         definition        = getDefinition(element);
            ExpressionManager expressionManager = context.ExpressionManager;

            IList <string> candidateGroups = definition.CamundaCandidateGroupsList;

            foreach (string candidateGroup in candidateGroups)
            {
                Expression candidateGroupExpression = expressionManager.createExpression(candidateGroup);
                taskDefinition.addCandidateGroupIdExpression(candidateGroupExpression);
            }
        }
Ejemplo n.º 7
0
        protected internal virtual CaseControlRule initializeCaseControlRule(ConditionExpression condition, CmmnHandlerContext context)
        {
            Expression expression = null;

            if (condition != null)
            {
                string rule = condition.Text;
                if (!string.ReferenceEquals(rule, null) && rule.Length > 0)
                {
                    ExpressionManager expressionManager = context.ExpressionManager;
                    expression = expressionManager.createExpression(rule);
                }
            }

            return(new CaseControlRuleImpl(expression));
        }
Ejemplo n.º 8
0
        protected internal virtual void initializeTaskDefinitionName(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context)
        {
            string name = getName(element);

            if (string.ReferenceEquals(name, null))
            {
                HumanTask definition = getDefinition(element);
                name = definition.Name;
            }

            if (!string.ReferenceEquals(name, null))
            {
                ExpressionManager expressionManager = context.ExpressionManager;
                Expression        nameExpression    = expressionManager.createExpression(name);
                taskDefinition.NameExpression = nameExpression;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// factory method for creating validator instances
        ///
        /// </summary>
        public virtual FormFieldValidator createValidator(Element constraint, BpmnParse bpmnParse, ExpressionManager expressionManager)
        {
            string name   = constraint.attribute("name");
            string config = constraint.attribute("config");

            if ("validator".Equals(name))
            {
                // custom validators

                if (string.ReferenceEquals(config, null) || config.Length == 0)
                {
                    bpmnParse.addError("validator configuration needs to provide either a fully " + "qualified classname or an expression resolving to a custom FormFieldValidator implementation.", constraint);
                }
                else
                {
                    if (StringUtil.isExpression(config))
                    {
                        // expression
                        Expression validatorExpression = expressionManager.createExpression(config);
                        return(new DelegateFormFieldValidator(validatorExpression));
                    }
                    else
                    {
                        // classname
                        return(new DelegateFormFieldValidator(config));
                    }
                }
            }
            else
            {
                // built-in validators

                Type validator = validators[name];
                if (validator != null)
                {
                    FormFieldValidator validatorInstance = createValidatorInstance(validator);
                    return(validatorInstance);
                }
                else
                {
                    bpmnParse.addError("Cannot find validator implementation for name '" + name + "'.", constraint);
                }
            }

            return(null);
        }
Ejemplo n.º 10
0
        protected internal virtual void initializeTaskDescription(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context)
        {
            string description = getDesciption(element);

            if (!string.ReferenceEquals(description, null) && description.Length > 0)
            {
                ExpressionManager expressionManager     = context.ExpressionManager;
                Expression        descriptionExpression = expressionManager.createExpression(description);
                taskDefinition.DescriptionExpression = descriptionExpression;
            }
            else
            {
                string documentation = getDocumentation(element);
                if (!string.ReferenceEquals(documentation, null) && documentation.Length > 0)
                {
                    ExpressionManager expressionManager       = context.ExpressionManager;
                    Expression        documentationExpression = expressionManager.createExpression(documentation);
                    taskDefinition.DescriptionExpression = documentationExpression;
                }
            }
        }
Ejemplo n.º 11
0
        public static FailedJobRetryConfiguration parseRetryIntervals(string retryIntervals)
        {
            if (!string.ReferenceEquals(retryIntervals, null) && retryIntervals.Length > 0)
            {
                if (StringUtil.isExpression(retryIntervals))
                {
                    ExpressionManager expressionManager = Context.ProcessEngineConfiguration.ExpressionManager;
                    Expression        expression        = expressionManager.createExpression(retryIntervals);
                    return(new FailedJobRetryConfiguration(expression));
                }

                string[] intervals = StringUtil.Split(retryIntervals, ",");
                int      retries   = intervals.Length + 1;

                if (intervals.Length == 1)
                {
                    try
                    {
                        DurationHelper durationHelper = new DurationHelper(intervals[0]);

                        if (durationHelper.Repeat)
                        {
                            retries = durationHelper.Times;
                        }
                    }
                    catch (Exception e)
                    {
                        LOG.logParsingRetryIntervals(intervals[0], e);
                        return(null);
                    }
                }
                return(new FailedJobRetryConfiguration(retries, Arrays.asList(intervals)));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
        protected internal virtual void initializeTaskDefinitionAssignee(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context)
        {
            HumanTask definition = getDefinition(element);
            Role      performer  = definition.Performer;

            string assignee = null;

            if (performer != null)
            {
                assignee = performer.Name;
            }
            else
            {
                assignee = definition.CamundaAssignee;
            }

            if (!string.ReferenceEquals(assignee, null))
            {
                ExpressionManager expressionManager  = context.ExpressionManager;
                Expression        assigneeExpression = expressionManager.createExpression(assignee);
                taskDefinition.AssigneeExpression = assigneeExpression;
            }
        }
Ejemplo n.º 13
0
        protected internal virtual Expression getExpressionValue(CamundaField field, ExpressionManager expressionManager)
        {
            CamundaExpression expression = field.CamundaExpressionChild;

            string value = null;

            if (expression != null)
            {
                value = expression.TextContent;
            }

            if (string.ReferenceEquals(value, null))
            {
                value = field.CamundaExpression;
            }

            if (!string.ReferenceEquals(value, null))
            {
                return(expressionManager.createExpression(value));
            }

            return(null);
        }
Ejemplo n.º 14
0
        protected internal virtual void initializeIfPart(IfPart ifPart, CmmnSentryDeclaration sentryDeclaration, CmmnHandlerContext context)
        {
            if (ifPart == null)
            {
                return;
            }

            ICollection <ConditionExpression> conditions = ifPart.Conditions;

            if (conditions.Count > 1)
            {
                string id = sentryDeclaration.Id;
                LOG.multipleIgnoredConditions(id);
            }

            ExpressionManager   expressionManager   = context.ExpressionManager;
            ConditionExpression condition           = conditions.GetEnumerator().next();
            Expression          conditionExpression = expressionManager.createExpression(condition.Text);

            CmmnIfPartDeclaration ifPartDeclaration = new CmmnIfPartDeclaration();

            ifPartDeclaration.Condition = conditionExpression;
            sentryDeclaration.IfPart    = ifPartDeclaration;
        }
Ejemplo n.º 15
0
        protected internal virtual void parseFormProperties(BpmnParse bpmnParse, ExpressionManager expressionManager, Element extensionElement)
        {
            FormTypes formTypes = FormTypes;

            IList <Element> formPropertyElements = extensionElement.elementsNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, FORM_PROPERTY_ELEMENT);

            foreach (Element formPropertyElement in formPropertyElements)
            {
                FormPropertyHandler formPropertyHandler = new FormPropertyHandler();

                string id = formPropertyElement.attribute("id");
                if (string.ReferenceEquals(id, null))
                {
                    bpmnParse.addError("attribute 'id' is required", formPropertyElement);
                }
                formPropertyHandler.Id = id;

                string name = formPropertyElement.attribute("name");
                formPropertyHandler.Name = name;

                AbstractFormFieldType type = formTypes.parseFormPropertyType(formPropertyElement, bpmnParse);
                formPropertyHandler.setType(type);

                string requiredText = formPropertyElement.attribute("required", "false");
                bool?  required     = bpmnParse.parseBooleanAttribute(requiredText);
                if (required != null)
                {
                    formPropertyHandler.Required = required.Value;
                }
                else
                {
                    bpmnParse.addError("attribute 'required' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
                }

                string readableText = formPropertyElement.attribute("readable", "true");
                bool?  readable     = bpmnParse.parseBooleanAttribute(readableText);
                if (readable != null)
                {
                    formPropertyHandler.Readable = readable.Value;
                }
                else
                {
                    bpmnParse.addError("attribute 'readable' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
                }

                string writableText = formPropertyElement.attribute("writable", "true");
                bool?  writable     = bpmnParse.parseBooleanAttribute(writableText);
                if (writable != null)
                {
                    formPropertyHandler.Writable = writable.Value;
                }
                else
                {
                    bpmnParse.addError("attribute 'writable' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
                }

                string variableName = formPropertyElement.attribute("variable");
                formPropertyHandler.VariableName = variableName;

                string expressionText = formPropertyElement.attribute("expression");
                if (!string.ReferenceEquals(expressionText, null))
                {
                    Expression expression = expressionManager.createExpression(expressionText);
                    formPropertyHandler.VariableExpression = expression;
                }

                string defaultExpressionText = formPropertyElement.attribute("default");
                if (!string.ReferenceEquals(defaultExpressionText, null))
                {
                    Expression defaultExpression = expressionManager.createExpression(defaultExpressionText);
                    formPropertyHandler.DefaultExpression = defaultExpression;
                }

                formPropertyHandlers.Add(formPropertyHandler);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Checks whether a <seealso cref="string"/> seams to be a composite expression or not. In contrast to an eval expression
 /// is the composite expression also allowed to consist of a combination of literal and eval expressions, e.g.,
 /// "Welcome ${customer.name} to our site".
 ///
 /// Note: If you just want to allow eval expression, then the expression must always start with "#{" or "${".
 /// Use <seealso cref="isExpression(string)"/> to conduct these kind of checks.
 ///
 /// </summary>
 public static bool isCompositeExpression(string text, ExpressionManager expressionManager)
 {
     return(!expressionManager.createExpression(text).LiteralText);
 }