Search in sources :

Example 1 with ModelElementInstance

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

the class ExtensionElementsImpl method addExtensionElement.

public <T extends ModelElementInstance> T addExtensionElement(Class<T> extensionElementClass) {
    ModelElementInstance extensionElement = modelInstance.newInstance(extensionElementClass);
    addChildElement(extensionElement);
    return extensionElementClass.cast(extensionElement);
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 2 with ModelElementInstance

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

the class ExtensionElementsImpl method addExtensionElement.

public ModelElementInstance addExtensionElement(String namespaceUri, String localName) {
    ModelElementType extensionElementType = modelInstance.registerGenericType(namespaceUri, localName);
    ModelElementInstance extensionElement = extensionElementType.newInstance(modelInstance);
    addChildElement(extensionElement);
    return extensionElement;
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 3 with ModelElementInstance

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

the class SimpleTest method shouldGetElements.

@Test
@CmmnModelResource
public void shouldGetElements() {
    ModelElementInstance modelElementById = cmmnModelInstance.getModelElementById("Case_1");
    assertThat(modelElementById).isNotNull();
    Collection<Case> caseElements = cmmnModelInstance.getDefinitions().getCases();
    assertThat(caseElements).hasSize(1);
    Case caseElement = caseElements.iterator().next();
    assertThat(caseElement.getId()).isEqualTo("Case_1");
    assertThat(caseElement.getName()).isNull();
    CasePlanModel casePlanModel = caseElement.getCasePlanModel();
    assertThat(casePlanModel).isNotNull();
    assertThat(casePlanModel.getId()).isEqualTo("CasePlanModel_1");
    Collection<PlanItemDefinition> planItemDefinitions = casePlanModel.getPlanItemDefinitions();
    assertThat(planItemDefinitions).hasSize(1);
    PlanItemDefinition planItemDefinition = planItemDefinitions.iterator().next();
    assertThat(planItemDefinition).isInstanceOf(HumanTask.class);
    assertThat(planItemDefinition.getId()).isEqualTo("HumanTask_1");
    assertThat(planItemDefinition.getName()).isEqualTo("A HumanTask");
    Collection<PlanItem> planItems = casePlanModel.getPlanItems();
    PlanItem planItem = planItems.iterator().next();
    assertThat(planItem.getId()).isEqualTo("PI_HumanTask_1");
    assertThat(planItem.getDefinition()).isEqualTo(planItemDefinition);
}
Also used : CasePlanModel(org.camunda.bpm.model.cmmn.instance.CasePlanModel) PlanItemDefinition(org.camunda.bpm.model.cmmn.instance.PlanItemDefinition) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) PlanItem(org.camunda.bpm.model.cmmn.instance.PlanItem) Case(org.camunda.bpm.model.cmmn.instance.Case) CmmnModelResource(org.camunda.bpm.model.cmmn.util.CmmnModelResource) Test(org.junit.Test)

Example 4 with ModelElementInstance

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

the class ElementReferenceImpl method setReferenceTargetElement.

public void setReferenceTargetElement(ModelElementInstanceImpl referenceSourceParentElement, Target referenceTargetElement) {
    ModelInstanceImpl modelInstance = referenceSourceParentElement.getModelInstance();
    String identifier = referenceTargetAttribute.getValue(referenceTargetElement);
    ModelElementInstance existingElement = modelInstance.getModelElementById(identifier);
    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 {
        Source referenceSourceElement = modelInstance.newInstance(getReferenceSourceElementType());
        setReferenceSource(referenceSourceParentElement, referenceSourceElement);
        setReferenceIdentifier(referenceSourceElement, identifier);
    }
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ModelReferenceException(org.camunda.bpm.model.xml.ModelReferenceException) ModelInstanceImpl(org.camunda.bpm.model.xml.impl.ModelInstanceImpl)

Example 5 with ModelElementInstance

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

the class IdsElementReferenceCollectionImpl method referencedElementRemoved.

@Override
public void referencedElementRemoved(ModelElementInstance referenceTargetElement, Object referenceIdentifier) {
    for (ModelElementInstance referenceSourceElement : findReferenceSourceElements(referenceTargetElement)) {
        List<String> referenceIdentifiers = getReferenceIdentifiers(referenceSourceElement);
        if (referenceIdentifiers.contains(referenceIdentifier)) {
            if (referenceIdentifiers.size() == 1) {
                // remove whole element
                removeReference(referenceSourceElement, referenceTargetElement);
            } else {
                // remove only single identifier
                referenceIdentifiers.remove(referenceIdentifier);
                setReferenceIdentifiers(referenceSourceElement, referenceIdentifiers);
            }
        }
    }
}
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