Search in sources :

Example 6 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.

the class ReferenceImpl method setReferenceTargetElement.

/**
 * Set the reference target model element instance
 *
 * @param referenceSourceElement the reference source model element instance
 * @param referenceTargetElement the reference target model element instance
 * @throws ModelReferenceException if element is not already added to the model
 */
public void setReferenceTargetElement(ModelElementInstance referenceSourceElement, T referenceTargetElement) {
    ModelInstance modelInstance = referenceSourceElement.getModelInstance();
    String referenceTargetIdentifier = referenceTargetAttribute.getValue(referenceTargetElement);
    ModelElementInstance existingElement = modelInstance.getModelElementById(referenceTargetIdentifier);
    if (existingElement == null || !existingElement.equals(referenceTargetElement)) {
        throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement + ": element is not part of model. Please connect element to the model first.");
    } else {
        setReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier);
    }
}
Also used : ModelInstance(org.camunda.bpm.model.xml.ModelInstance) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ModelReferenceException(org.camunda.bpm.model.xml.ModelReferenceException)

Example 7 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.

the class ModelInstanceValidator method validate.

@SuppressWarnings({ "unchecked", "rawtypes" })
public ValidationResults validate() {
    ValidationResultsCollectorImpl resultsCollector = new ValidationResultsCollectorImpl();
    for (ModelElementValidator validator : validators) {
        Class<? extends ModelElementInstance> elementType = validator.getElementType();
        Collection<? extends ModelElementInstance> modelElementsByType = modelInstanceImpl.getModelElementsByType(elementType);
        for (ModelElementInstance element : modelElementsByType) {
            resultsCollector.setCurrentElement(element);
            try {
                validator.validate(element, resultsCollector);
            } catch (RuntimeException e) {
                throw new RuntimeException("Validator " + validator + " threw an exception while validating " + element, e);
            }
        }
    }
    return resultsCollector.getResults();
}
Also used : ModelElementValidator(org.camunda.bpm.model.xml.validation.ModelElementValidator) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 8 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.

the class ModelValidationResultsImpl method write.

@Override
public void write(StringWriter writer, ValidationResultFormatter formatter) {
    for (Entry<ModelElementInstance, List<ValidationResult>> entry : collectedResults.entrySet()) {
        ModelElementInstance element = entry.getKey();
        List<ValidationResult> results = entry.getValue();
        formatter.formatElement(writer, element);
        for (ValidationResult result : results) {
            formatter.formatResult(writer, result);
        }
    }
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) List(java.util.List) ValidationResult(org.camunda.bpm.model.xml.validation.ValidationResult)

Example 9 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.

the class AbstractModelElementInstanceTest method testType.

@Test
public void testType() {
    assertThatType().isPartOfModel(model);
    TypeAssumption assumption = getTypeAssumption();
    assertThatType().hasTypeNamespace(assumption.namespaceUri);
    if (assumption.isAbstract) {
        assertThatType().isAbstract();
    } else {
        assertThatType().isNotAbstract();
    }
    if (assumption.extendsType == null) {
        assertThatType().extendsNoType();
    } else {
        assertThatType().extendsType(assumption.extendsType);
    }
    if (assumption.isAbstract) {
        try {
            modelInstance.newInstance(modelElementType);
            fail("Element type " + modelElementType.getTypeName() + " is abstract.");
        } catch (DOMException e) {
        // expected exception
        } catch (ModelTypeException e) {
        // expected exception
        } catch (Exception e) {
            fail("Unexpected exception " + e.getMessage());
        }
    } else {
        ModelElementInstance modelElementInstance = modelInstance.newInstance(modelElementType);
        assertThat(modelElementInstance).isNotNull();
    }
}
Also used : DOMException(org.w3c.dom.DOMException) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) DOMException(org.w3c.dom.DOMException) ModelTypeException(org.camunda.bpm.model.xml.impl.util.ModelTypeException) ModelTypeException(org.camunda.bpm.model.xml.impl.util.ModelTypeException) Test(org.junit.Test)

Example 10 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.

the class AbstractReferenceAssert method hasNoTargetElement.

public S hasNoTargetElement(ModelElementInstance instance) {
    isNotNull();
    ModelElementInstance actualTargetElement = actual.getReferenceTargetElement(instance);
    if (actualTargetElement != null) {
        failWithMessage("Expected reference <%s> to have no target element but has <%s>", actualTargetElement, actualTargetElement);
    }
    return myself;
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Aggregations

ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)55 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)8 ModelElementType (org.camunda.bpm.model.xml.type.ModelElementType)8 Process (org.camunda.bpm.model.bpmn.instance.Process)5 ModelInstanceImpl (org.camunda.bpm.model.xml.impl.ModelInstanceImpl)5 ModelReferenceException (org.camunda.bpm.model.xml.ModelReferenceException)4 DomElement (org.camunda.bpm.model.xml.instance.DomElement)4 List (java.util.List)3 Model (org.camunda.bpm.model.xml.Model)3 Deployment (org.camunda.bpm.engine.test.Deployment)2 Event (org.camunda.bpm.model.bpmn.instance.Event)2 SequenceFlow (org.camunda.bpm.model.bpmn.instance.SequenceFlow)2 BpmnShape (org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape)2 Case (org.camunda.bpm.model.cmmn.instance.Case)2 PlanItem (org.camunda.bpm.model.cmmn.instance.PlanItem)2 TestModelTest (org.camunda.bpm.model.xml.testmodel.TestModelTest)2 ModelElementValidator (org.camunda.bpm.model.xml.validation.ModelElementValidator)2 ValidationResult (org.camunda.bpm.model.xml.validation.ValidationResult)2