import {BpmnTags, Model} from '@process-engine/process_engine_contracts'; import { getModelPropertyAsArray, setCommonObjectPropertiesFromData, } from '../type_factory'; export function parseGatewaysFromProcessData(processData: any): Array { const exclusiveGateways: Array = parseGatewaysByType(processData, BpmnTags.GatewayElement.ExclusiveGateway, Model.Gateways.ExclusiveGateway); const parallelGateways: Array = parseGatewaysByType(processData, BpmnTags.GatewayElement.ParallelGateway, Model.Gateways.ParallelGateway); const inclusiveGateways: Array = parseGatewaysByType(processData, BpmnTags.GatewayElement.InclusiveGateway, Model.Gateways.InclusiveGateway); const complexGateways: Array = parseGatewaysByType(processData, BpmnTags.GatewayElement.ComplexGateway, Model.Gateways.ComplexGateway); return Array.prototype.concat(parallelGateways, exclusiveGateways, inclusiveGateways, complexGateways); } function parseGatewaysByType( processData: Array, gatewayType: BpmnTags.GatewayElement, type: Model.Base.IConstructor, ): Array { const gateways: Array = []; const gatewaysRaw: Array = getModelPropertyAsArray(processData, gatewayType); if (!gatewaysRaw || gatewaysRaw.length === 0) { return []; } for (const gatewayRaw of gatewaysRaw) { let gateway: TGateway = new type(); gateway = setCommonObjectPropertiesFromData(gatewayRaw, gateway); gateway.name = gatewayRaw.name; gateway.incoming = getModelPropertyAsArray(gatewayRaw, BpmnTags.FlowElementProperty.SequenceFlowIncoming); gateway.outgoing = getModelPropertyAsArray(gatewayRaw, BpmnTags.FlowElementProperty.SequenceFlowOutgoing); gateways.push(gateway); } return gateways; }