UNPKG

camunda-bpmn-js

Version:

Embeddable Camunda modeling distributions based on bpmn-js

62 lines (50 loc) 1.81 kB
/** * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH * under one or more contributor license agreements. See the NOTICE file * distributed with this work for additional information regarding copyright * ownership. * * Camunda licenses this file to you under the MIT; you may not use this file * except in compliance with the MIT License. */ import { getBusinessObject, is } from 'bpmn-js/lib/util/ModelUtil'; import { RPA_MAIN_SCRIPT_LINK_NAME, RPA_TEMPLATE_ID } from './constants'; /** * @typedef {{ * type: 'rpa', * name: string, * scriptId: string * }} RPA */ /** * Create a new BPMN element for the given RPA resource. * * @param {RPA} resource * @param {import('didi').Injector} injector * * @returns {import('bpmn-js/lib/model/Types').ModdleElement} */ export function createElement(resource, injector) { return createRPATask(resource, injector); } /** * Create an RPA task for the given RPA resource. Uses the latest RPA template * to create the task. * * @param {RPA} resource * @param {import('didi').Injector} injector * * @returns {import('bpmn-js/lib/model/Types').ModdleElement} */ function createRPATask(resource, injector) { const elementTemplates = injector.get('elementTemplates'); const templates = elementTemplates.getLatest(RPA_TEMPLATE_ID); const RPATask = elementTemplates.createElement(templates[0]); const bo = getBusinessObject(RPATask); const extensionElements = bo.get('extensionElements'); const linkedResources = extensionElements.get('values').find((el) => is(el, 'zeebe:LinkedResources')); const mainScript = linkedResources.values.find((el) => el.linkName === RPA_MAIN_SCRIPT_LINK_NAME); mainScript.set('resourceId', resource.scriptId); bo.set('name', resource.name); return bo; }