Search in sources :

Example 1 with CamundaVariableOnPart

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart in project camunda-bpm-platform by camunda.

the class SentryHandler method handleElement.

public CmmnSentryDeclaration handleElement(Sentry element, CmmnHandlerContext context) {
    String id = element.getId();
    Collection<OnPart> onParts = element.getOnParts();
    IfPart ifPart = element.getIfPart();
    List<CamundaVariableOnPart> variableOnParts = queryExtensionElementsByClass(element, CamundaVariableOnPart.class);
    if ((ifPart == null || ifPart.getConditions().isEmpty()) && variableOnParts.isEmpty()) {
        if (onParts == null || onParts.isEmpty()) {
            LOG.ignoredSentryWithMissingCondition(id);
            return null;
        } else {
            boolean atLeastOneOnPartsValid = false;
            for (OnPart onPart : onParts) {
                if (onPart instanceof PlanItemOnPart) {
                    PlanItemOnPart planItemOnPart = (PlanItemOnPart) onPart;
                    if (planItemOnPart.getSource() != null && planItemOnPart.getStandardEvent() != null) {
                        atLeastOneOnPartsValid = true;
                        break;
                    }
                }
            }
            if (!atLeastOneOnPartsValid) {
                LOG.ignoredSentryWithInvalidParts(id);
                return null;
            }
        }
    }
    CmmnSentryDeclaration sentryDeclaration = new CmmnSentryDeclaration(id);
    // the ifPart will be initialized immediately
    initializeIfPart(ifPart, sentryDeclaration, context);
    // the variableOnParts will be initialized immediately as it does not have any dependency
    initializeVariableOnParts(element, sentryDeclaration, context, variableOnParts);
    // ...whereas the onParts will be initialized later because the
    // the reference to the plan items (sourceRef) and the reference
    // to the sentry (sentryRef) cannot be set in this step. To set
    // the corresponding reference (sourceRef or sentryRef) on the
    // transformed sentry all planned items and all sentries inside
    // the current stage should be already transformed.
    CmmnActivity parent = context.getParent();
    if (parent != null) {
        parent.addSentry(sentryDeclaration);
    }
    return sentryDeclaration;
}
Also used : CamundaVariableOnPart(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart) PlanItemOnPart(org.camunda.bpm.model.cmmn.instance.PlanItemOnPart) OnPart(org.camunda.bpm.model.cmmn.instance.OnPart) CaseFileItemOnPart(org.camunda.bpm.model.cmmn.instance.CaseFileItemOnPart) PlanItemOnPart(org.camunda.bpm.model.cmmn.instance.PlanItemOnPart) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) IfPart(org.camunda.bpm.model.cmmn.instance.IfPart) CamundaVariableOnPart(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)

Example 2 with CamundaVariableOnPart

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart in project camunda-bpm-platform by camunda.

the class SentryHandlerTest method sentryTransformShouldFailWithMissingVariableEvent.

@Test
public void sentryTransformShouldFailWithMissingVariableEvent() {
    // given
    ExtensionElements extensionElements = createElement(sentry, "extensionElements", ExtensionElements.class);
    CamundaVariableOnPart variableOnPart = createElement(extensionElements, null, CamundaVariableOnPart.class);
    variableOnPart.setVariableName("aVariable");
    thrown.expect(CmmnTransformException.class);
    thrown.expectMessage("The variableOnPart of the sentry with id 'aSentry' must have one valid variable event.");
    sentryHandler.handleElement(sentry, context);
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) CamundaVariableOnPart(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart) Test(org.junit.Test)

Example 3 with CamundaVariableOnPart

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart in project camunda-bpm-platform by camunda.

the class SentryHandlerTest method sentryTransformWithSameVariableOnPartTwice.

@Test
public void sentryTransformWithSameVariableOnPartTwice() {
    // given
    ExtensionElements extensionElements = createElement(sentry, "extensionElements", ExtensionElements.class);
    CamundaVariableOnPart variableOnPart = createElement(extensionElements, null, CamundaVariableOnPart.class);
    createElement(variableOnPart, null, CamundaVariableTransitionEvent.class);
    variableOnPart.setVariableEvent(VariableTransition.create);
    variableOnPart.setVariableName("aVariable");
    CamundaVariableOnPart additionalVariableOnPart = createElement(extensionElements, null, CamundaVariableOnPart.class);
    createElement(additionalVariableOnPart, null, CamundaVariableTransitionEvent.class);
    additionalVariableOnPart.setVariableEvent(VariableTransition.create);
    additionalVariableOnPart.setVariableName("aVariable");
    CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);
    // then
    assertNotNull(sentryDeclaration);
    List<CmmnVariableOnPartDeclaration> variableOnParts = sentryDeclaration.getVariableOnParts();
    assertNotNull(variableOnParts);
    assertFalse(variableOnParts.isEmpty());
    assertEquals(1, variableOnParts.size());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) CmmnVariableOnPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnVariableOnPartDeclaration) CamundaVariableOnPart(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart) Test(org.junit.Test)

Example 4 with CamundaVariableOnPart

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart in project camunda-bpm-platform by camunda.

the class SentryHandlerTest method sentryTransformWithMultipleVariableEvent.

@Test
public void sentryTransformWithMultipleVariableEvent() {
    // given
    ExtensionElements extensionElements = createElement(sentry, "extensionElements", ExtensionElements.class);
    CamundaVariableOnPart variableOnPart = createElement(extensionElements, null, CamundaVariableOnPart.class);
    CamundaVariableTransitionEvent transitionEvent = createElement(variableOnPart, null, CamundaVariableTransitionEvent.class);
    transitionEvent.setTextContent("create");
    CamundaVariableTransitionEvent additionalTransitionEvent = createElement(variableOnPart, null, CamundaVariableTransitionEvent.class);
    additionalTransitionEvent.setTextContent("delete");
    variableOnPart.setVariableName("aVariable");
    CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);
    // then
    assertNotNull(sentryDeclaration);
    List<CmmnVariableOnPartDeclaration> variableOnParts = sentryDeclaration.getVariableOnParts();
    assertNotNull(variableOnParts);
    assertFalse(variableOnParts.isEmpty());
    assertEquals(1, variableOnParts.size());
    CmmnVariableOnPartDeclaration transformedVariableOnPart = variableOnParts.get(0);
    assertEquals("aVariable", transformedVariableOnPart.getVariableName());
    // when there are multiple variable events then, only first variable event is considered.
    assertEquals(VariableTransition.create.name(), transformedVariableOnPart.getVariableEvent());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) CmmnVariableOnPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnVariableOnPartDeclaration) CamundaVariableOnPart(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart) CamundaVariableTransitionEvent(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableTransitionEvent) Test(org.junit.Test)

Example 5 with CamundaVariableOnPart

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart in project camunda-bpm-platform by camunda.

the class SentryHandlerTest method sentryTransformWithMultipleVariableOnPart.

@Test
public void sentryTransformWithMultipleVariableOnPart() {
    // given
    ExtensionElements extensionElements = createElement(sentry, "extensionElements", ExtensionElements.class);
    CamundaVariableOnPart variableOnPart = createElement(extensionElements, null, CamundaVariableOnPart.class);
    createElement(variableOnPart, null, CamundaVariableTransitionEvent.class);
    variableOnPart.setVariableEvent(VariableTransition.create);
    variableOnPart.setVariableName("aVariable");
    CamundaVariableOnPart additionalVariableOnPart = createElement(extensionElements, null, CamundaVariableOnPart.class);
    createElement(additionalVariableOnPart, null, CamundaVariableTransitionEvent.class);
    additionalVariableOnPart.setVariableEvent(VariableTransition.update);
    additionalVariableOnPart.setVariableName("bVariable");
    CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);
    // then
    assertNotNull(sentryDeclaration);
    List<CmmnVariableOnPartDeclaration> variableOnParts = sentryDeclaration.getVariableOnParts();
    assertNotNull(variableOnParts);
    assertFalse(variableOnParts.isEmpty());
    assertEquals(2, variableOnParts.size());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) CmmnVariableOnPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnVariableOnPartDeclaration) CamundaVariableOnPart(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart) Test(org.junit.Test)

Aggregations

CamundaVariableOnPart (org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart)9 ExtensionElements (org.camunda.bpm.model.cmmn.instance.ExtensionElements)7 Test (org.junit.Test)7 CmmnSentryDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration)5 CmmnVariableOnPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnVariableOnPartDeclaration)4 CamundaVariableTransitionEvent (org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableTransitionEvent)2 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)1 CaseFileItemOnPart (org.camunda.bpm.model.cmmn.instance.CaseFileItemOnPart)1 IfPart (org.camunda.bpm.model.cmmn.instance.IfPart)1 OnPart (org.camunda.bpm.model.cmmn.instance.OnPart)1 PlanItemOnPart (org.camunda.bpm.model.cmmn.instance.PlanItemOnPart)1 ModelTypeInstanceContext (org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)1 ModelElementTypeBuilder (org.camunda.bpm.model.xml.type.ModelElementTypeBuilder)1 SequenceBuilder (org.camunda.bpm.model.xml.type.child.SequenceBuilder)1