Beispiel #1
0
        /// <summary>
        /// Creates an error event definition
        /// and returns a builder for the error event definition.
        /// </summary>
        /// <returns> the error event definition builder object </returns>
        public virtual ErrorEventDefinitionBuilder errorEventDefinition()
        {
            ErrorEventDefinition errorEventDefinition = createEmptyErrorEventDefinition();

            element.EventDefinitions.add(errorEventDefinition);
            return(new ErrorEventDefinitionBuilder(modelInstance, errorEventDefinition));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void getEventDefinition()
        public virtual void getEventDefinition()
        {
            ErrorEventDefinition eventDefinition = eventDefinitionQuery.filterByType(typeof(ErrorEventDefinition)).singleResult();

            assertThat(eventDefinition).NotNull;
            assertThat(eventDefinition.Error.Id).isEqualTo("error");
        }
Beispiel #3
0
        /// <summary>
        /// Sets an error definition for the given error code. If already an error
        /// with this code exists it will be used, otherwise a new error is created.
        /// </summary>
        /// <param name="errorCode"> the code of the error </param>
        /// <returns> the builder object </returns>
        public virtual B error(string errorCode)
        {
            ErrorEventDefinition errorEventDefinition = createErrorEventDefinition(errorCode);

            element.EventDefinitions.add(errorEventDefinition);

            return(myself);
        }
Beispiel #4
0
        /// <summary>
        /// Sets a catch all error definition.
        /// </summary>
        /// <returns> the builder object </returns>
        public virtual B error()
        {
            ErrorEventDefinition errorEventDefinition = createInstance(typeof(ErrorEventDefinition));

            element.EventDefinitions.add(errorEventDefinition);

            return(myself);
        }
Beispiel #5
0
        protected internal virtual ErrorEventDefinition createErrorEventDefinition(string errorCode)
        {
            Error error = findErrorForNameAndCode(errorCode);
            ErrorEventDefinition errorEventDefinition = createInstance(typeof(ErrorEventDefinition));

            errorEventDefinition.Error = error;
            return(errorEventDefinition);
        }
Beispiel #6
0
        public override BaseElement Clone()
        {
            ErrorEventDefinition clone = new ErrorEventDefinition
            {
                Values = this
            };

            return(clone);
        }
        protected internal virtual void WriteErrorDefinition(Event parentEvent, ErrorEventDefinition errorDefinition, XMLStreamWriter xtw)
        {
            xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_EVENT_ERRORDEFINITION, BpmnXMLConstants.BPMN2_NAMESPACE);
            WriteDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_ERROR_REF, errorDefinition.ErrorCode, xtw);
            bool didWriteExtensionStartElement = BpmnXMLUtil.WriteExtensionElements(errorDefinition, false, xtw);

            if (didWriteExtensionStartElement)
            {
                xtw.WriteEndElement();
            }
            xtw.WriteEndElement();
        }
Beispiel #8
0
        /// <summary>
        /// Creates an error event definition with an unique id
        /// and returns a builder for the error event definition.
        /// </summary>
        /// <returns> the error event definition builder object </returns>
        public virtual ErrorEventDefinitionBuilder errorEventDefinition(string id)
        {
            ErrorEventDefinition errorEventDefinition = createEmptyErrorEventDefinition();

            if (!string.ReferenceEquals(id, null))
            {
                errorEventDefinition.Id = id;
            }

            element.EventDefinitions.add(errorEventDefinition);
            return(new ErrorEventDefinitionBuilder(modelInstance, errorEventDefinition));
        }
Beispiel #9
0
        public virtual void visit(PvmScope scope)
        {
            IList <ErrorEventDefinition> errorEventDefinitions = scope.Properties.get(BpmnProperties.ERROR_EVENT_DEFINITIONS);

            foreach (ErrorEventDefinition errorEventDefinition in errorEventDefinitions)
            {
                PvmActivity activityHandler = scope.ProcessDefinition.findActivity(errorEventDefinition.HandlerActivityId);
                if ((!isReThrowingErrorEventSubprocess(activityHandler)) && ((exception != null && errorEventDefinition.catchesException(exception)) || (exception == null && errorEventDefinition.catchesError(errorCode))))
                {
                    errorHandlerActivity      = activityHandler;
                    this.errorEventDefinition = errorEventDefinition;
                    break;
                }
            }
        }
        public override void ParseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model)
        {
            if (!(parentElement is Event))
            {
                return;
            }

            ErrorEventDefinition eventDefinition = new ErrorEventDefinition();

            BpmnXMLUtil.AddXMLLocation(eventDefinition, xtr);
            eventDefinition.ErrorCode = xtr.GetAttributeValue("errorRef");

            BpmnXMLUtil.ParseChildElements(BpmnXMLConstants.ELEMENT_EVENT_ERRORDEFINITION, eventDefinition, xtr, model);

            ((Event)parentElement).EventDefinitions.Add(eventDefinition);
        }
            public virtual void Visit(IPvmScope scope)
            {
                var errorEventDefinitions = scope.Properties.Get(BpmnProperties.ErrorEventDefinitions);

                foreach (var errorEventDefinition in errorEventDefinitions)
                {
                    var activityHandler = scope.ProcessDefinition.FindActivity(errorEventDefinition.HandlerActivityId);
                    if (!IsReThrowingErrorEventSubprocess(activityHandler) &&
                        (((Exception != null) && errorEventDefinition.CatchesException(Exception)) ||
                         ((Exception == null) && errorEventDefinition.CatchesError(ErrorCode))))
                    {
                        errorHandlerActivity      = activityHandler;
                        this.errorEventDefinition = errorEventDefinition;
                        break;
                    }
                }
            }
Beispiel #12
0
 public AbstractErrorEventDefinitionBuilder(BpmnModelInstance modelInstance, ErrorEventDefinition element, Type selfType) : base(modelInstance, element, selfType)
 {
 }
Beispiel #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void propagateError(String errorCode, String errorMessage, Exception origException, org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution execution) throws Exception
        public static void propagateError(string errorCode, string errorMessage, Exception origException, ActivityExecution execution)
        {
            ActivityExecutionHierarchyWalker walker = new ActivityExecutionHierarchyWalker(execution);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ErrorDeclarationForProcessInstanceFinder errorDeclarationFinder = new ErrorDeclarationForProcessInstanceFinder(origException, errorCode, execution.getActivity());
            ErrorDeclarationForProcessInstanceFinder errorDeclarationFinder            = new ErrorDeclarationForProcessInstanceFinder(origException, errorCode, execution.Activity);
            ActivityExecutionMappingCollector        activityExecutionMappingCollector = new ActivityExecutionMappingCollector(execution);

            walker.addScopePreVisitor(errorDeclarationFinder);
            walker.addExecutionPreVisitor(activityExecutionMappingCollector);
            // map variables to super executions in the hierarchy of called process instances
            walker.addExecutionPreVisitor(new OutputVariablesPropagator());

            try
            {
                walker.walkUntil(new WalkConditionAnonymousInnerClass(errorDeclarationFinder));
            }
            catch (Exception e)
            {
                LOG.errorPropagationException(execution.ActivityInstanceId, e);

                // separate the exception handling to support a fail-safe error propagation
                throw new ErrorPropagationException(e.InnerException);
            }

            PvmActivity errorHandlingActivity = errorDeclarationFinder.ErrorHandlerActivity;

            // process the error
            if (errorHandlingActivity == null)
            {
                if (origException == null)
                {
                    if (Context.CommandContext.ProcessEngineConfiguration.EnableExceptionsAfterUnhandledBpmnError)
                    {
                        throw LOG.missingBoundaryCatchEventError(execution.Activity.Id, errorCode);
                    }
                    else
                    {
                        LOG.missingBoundaryCatchEvent(execution.Activity.Id, errorCode);
                        execution.end(true);
                    }
                }
                else
                {
                    // throw original exception
                    throw origException;
                }
            }
            else
            {
                ErrorEventDefinition errorDefinition        = errorDeclarationFinder.ErrorEventDefinition;
                PvmExecutionImpl     errorHandlingExecution = activityExecutionMappingCollector.getExecutionForScope(errorHandlingActivity.EventScope);

                if (!string.ReferenceEquals(errorDefinition.ErrorCodeVariable, null))
                {
                    errorHandlingExecution.setVariable(errorDefinition.ErrorCodeVariable, errorCode);
                }
                if (!string.ReferenceEquals(errorDefinition.ErrorMessageVariable, null))
                {
                    errorHandlingExecution.setVariable(errorDefinition.ErrorMessageVariable, errorMessage);
                }
                errorHandlingExecution.executeActivity(errorHandlingActivity);
            }
        }
        protected internal static IDictionary <string, IList <Event> > FindCatchingEventsForProcess(string processDefinitionId, string errorCode)
        {
            IDictionary <string, IList <Event> > eventMap = new Dictionary <string, IList <Event> >();
            Process   process   = ProcessDefinitionUtil.GetProcess(processDefinitionId);
            BpmnModel bpmnModel = ProcessDefinitionUtil.GetBpmnModel(processDefinitionId);

            string compareErrorCode = RetrieveErrorCode(bpmnModel, errorCode);

            IList <EventSubProcess> subProcesses = process.FindFlowElementsOfType <EventSubProcess>(true);

            foreach (EventSubProcess eventSubProcess in subProcesses)
            {
                foreach (FlowElement flowElement in eventSubProcess.FlowElements)
                {
                    if (flowElement is StartEvent startEvent)
                    {
                        if (CollectionUtil.IsNotEmpty(startEvent.EventDefinitions) && startEvent.EventDefinitions[0] is ErrorEventDefinition)
                        {
                            ErrorEventDefinition errorEventDef = (ErrorEventDefinition)startEvent.EventDefinitions[0];
                            string eventErrorCode = RetrieveErrorCode(bpmnModel, errorEventDef.ErrorCode);

                            if (eventErrorCode is null || compareErrorCode is null || eventErrorCode.Equals(compareErrorCode))
                            {
                                IList <Event> startEvents = new List <Event>
                                {
                                    startEvent
                                };
                                eventMap[eventSubProcess.Id] = startEvents;
                            }
                        }
                    }
                }
            }

            IList <BoundaryEvent> boundaryEvents = process.FindFlowElementsOfType <BoundaryEvent>(true);

            foreach (BoundaryEvent boundaryEvent in boundaryEvents)
            {
                if (boundaryEvent.AttachedToRefId is object && CollectionUtil.IsNotEmpty(boundaryEvent.EventDefinitions) && boundaryEvent.EventDefinitions[0] is ErrorEventDefinition)
                {
                    ErrorEventDefinition errorEventDef = (ErrorEventDefinition)boundaryEvent.EventDefinitions[0];
                    string eventErrorCode = RetrieveErrorCode(bpmnModel, errorEventDef.ErrorCode);

                    if (eventErrorCode is null || compareErrorCode is null || eventErrorCode.Equals(compareErrorCode))
                    {
                        IList <Event> elementBoundaryEvents = null;
                        if (!eventMap.ContainsKey(boundaryEvent.AttachedToRefId))
                        {
                            elementBoundaryEvents = new List <Event>();
                            eventMap[boundaryEvent.AttachedToRefId] = elementBoundaryEvents;
                        }
                        else
                        {
                            elementBoundaryEvents = eventMap[boundaryEvent.AttachedToRefId];
                        }
                        elementBoundaryEvents.Add(boundaryEvent);
                    }
                }
            }
            return(eventMap);
        }
 public virtual ErrorEndEventActivityBehavior CreateErrorEndEventActivityBehavior(EndEvent endEvent, ErrorEventDefinition errorEventDefinition)
 {
     return(new ErrorEndEventActivityBehavior(errorEventDefinition.ErrorCode));
 }
Beispiel #16
0
        protected internal virtual ErrorEventDefinition createEmptyErrorEventDefinition()
        {
            ErrorEventDefinition errorEventDefinition = createInstance(typeof(ErrorEventDefinition));

            return(errorEventDefinition);
        }
        public override object Create(object parent, IParseContext context, XElement element)
        {
            EventDefinition eventDefinition = null;
            var             localName       = Helper.GetRealLocalName(element);

            switch (localName)
            {
            case "cancelEventDefinition":
                eventDefinition = new CancelEventDefinition();
                break;

            case "errorEventDefinition":
                var errorEventDefinition = new ErrorEventDefinition();
                eventDefinition = errorEventDefinition;
                var errorRef = element.GetAttribute("errorRef");
                if (errorRef != null)
                {
                    context.AddReferenceRequest <Error>(errorRef, x => errorEventDefinition.ErrorRef = x);
                }
                break;

            case "timerEventDefinition":
                eventDefinition = new TimerEventDefinition();
                break;

            case "terminateEventDefinition":
                eventDefinition = new TerminateEventDefinition();
                break;

            case "messageEventDefinition":
                var messageEventDefinition = new MessageEventDefinition();
                eventDefinition = messageEventDefinition;

                var operationRef = element.GetAttribute("operationRef");
                if (operationRef != null)
                {
                    context.AddReferenceRequest <Operation>(operationRef, x => messageEventDefinition.OperationRef = x);
                }

                var messageRef = element.GetAttribute("messageRef");
                if (messageRef != null)
                {
                    context.AddReferenceRequest <Message>(messageRef, x => messageEventDefinition.MessageRef = x);
                }
                break;

            case "conditionalEventDefinition":
                eventDefinition = new ConditionalEventDefinition();
                break;

            case "compensateEventDefinition":
                var compensateEventDefinition = new CompensateEventDefinition();
                eventDefinition = compensateEventDefinition;

                compensateEventDefinition.WaitForCompletion = element.GetBoolean("waitForCompletion");
                var activityRef = element.GetAttribute("activityRef");
                if (activityRef != null)
                {
                    context.AddReferenceRequest <Activity>(activityRef, x => compensateEventDefinition.ActivityRef = x);
                }
                break;

            case "signalEventDefinition":
                var signalEventDefinition = new SignalEventDefinition();
                eventDefinition = signalEventDefinition;

                var signalRef = element.GetAttribute("signalRef");
                if (signalRef != null)
                {
                    context.AddReferenceRequest <Signal>(signalRef, x => signalEventDefinition.SignalRef = x);
                }
                break;

            case "escalationEventDefinition":
                eventDefinition = new EscalationEventDefinition()
                {
                    EscalationRef = element.GetAttribute("escalationRef")
                };
                break;

            case "linkEventDefinition":
                eventDefinition = new LinkEventDefinition()
                {
                    Name   = element.GetAttribute("name"),
                    Target = element.GetAttribute("target")
                };
                break;
            }

            if (this.callback != null)
            {
                this.callback(parent, context, element, eventDefinition);
            }

            base.Init(eventDefinition, context, element);

            context.Push(eventDefinition);

            return(eventDefinition);
        }