Skip to content

Commit

Permalink
Merge pull request #111 from PROCEED-Labs/bpmn-helper-update
Browse files Browse the repository at this point in the history
Bpmn helper update
  • Loading branch information
LucasMGo authored Oct 12, 2023
2 parents bee2351 + 8fb5ee6 commit 660d9f4
Show file tree
Hide file tree
Showing 20 changed files with 1,584 additions and 240 deletions.
29 changes: 13 additions & 16 deletions src/helper-modules/bpmn-helper/__tests__/getters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ jest.doMock('bpmn-moddle', () => {
};
});

mockToXML.mockImplementation((_, a, callback) => {
callback(undefined, '');
});
mockToXML.mockImplementation((_, a) => ({ xml: '' }));
mockCreate.mockImplementation((name) => ({ $type: name }));

mockFromXML.mockImplementation((_, a, callback) => {
callback(undefined, JSON.parse(JSON.stringify(baseJSON)));
});
mockFromXML.mockImplementation((_, a) => ({
rootElement: JSON.parse(JSON.stringify(baseJSON)),
}));

const getters = require('../src/getters.js');
const { get } = require('http');
Expand Down Expand Up @@ -67,17 +64,17 @@ describe('Tests for getter functions of this library', () => {

describe('getDeploymentMethod', () => {
it('returns the deploymentMethod for the given process', async () => {
mockFromXML.mockImplementationOnce((_a, _b, callback) =>
callback(undefined, JSON.parse(JSON.stringify(deploymentObj))),
);
mockFromXML.mockImplementationOnce((_a, _b) => ({
rootElement: JSON.parse(JSON.stringify(deploymentObj)),
}));
expect(await getters.getDeploymentMethod(deploymentXML)).toBe('static');
});
});
describe('getElementMachineMapping', () => {
it('returns a mapping from task ids to assigned machineIds or addresses', async () => {
mockFromXML.mockImplementationOnce((_a, _b, callback) =>
callback(undefined, JSON.parse(JSON.stringify(deploymentObj))),
);
mockFromXML.mockImplementationOnce((_a, _b) => ({
rootElement: JSON.parse(JSON.stringify(deploymentObj)),
}));
expect(await getters.getElementMachineMapping(deploymentXML)).toStrictEqual({
StartEvent_1: { machineId: '1234', machineAddress: undefined },
EndEvent_1d3ier5: { machineId: undefined, machineAddress: '192.168.1.1:1234' },
Expand All @@ -87,9 +84,9 @@ describe('Tests for getter functions of this library', () => {
});
describe('getProcessIds', () => {
it('returns the ids of all processes in the process definition', async () => {
mockFromXML.mockImplementationOnce((_a, _b, callback) =>
callback(undefined, JSON.parse(JSON.stringify(twoProcessObj))),
);
mockFromXML.mockImplementationOnce((_a, _b) => ({
rootElement: JSON.parse(JSON.stringify(twoProcessObj)),
}));
expect(await getters.getProcessIds(twoProcessXML)).toStrictEqual([
'Process_02x86ax',
'Process_0xqodb2',
Expand Down
11 changes: 4 additions & 7 deletions src/helper-modules/bpmn-helper/__tests__/setters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ jest.doMock('bpmn-moddle', () => {
};
});

mockToXML.mockImplementation((_, a, callback) => {
callback(undefined, '');
});
mockToXML.mockImplementation((_, a) => ({ xml: '' }));
mockCreate.mockImplementation((name) => ({ $type: name }));

mockFromXML.mockImplementation((_, a, callback) => {
callback(undefined, JSON.parse(JSON.stringify(baseJSON)));
});
mockFromXML.mockImplementation((_, a) => ({
rootElement: JSON.parse(JSON.stringify(baseJSON)),
}));

const setters = require('../src/setters.js');

Expand Down
11 changes: 4 additions & 7 deletions src/helper-modules/bpmn-helper/__tests__/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ jest.doMock('bpmn-moddle', () => {
};
});

mockToXML.mockImplementation((_, a, callback) => {
callback(undefined, '');
});
mockToXML.mockImplementation((_, a) => ({ xml: '' }));
mockCreate.mockImplementation((name) => ({ $type: name }));

mockFromXML.mockImplementation((_, a, callback) => {
callback(undefined, JSON.parse(JSON.stringify(baseJSON)));
});
mockFromXML.mockImplementation((_, a) => ({
rootElement: JSON.parse(JSON.stringify(baseJSON)),
}));

const util = require('../src/util.js');

Expand Down
91 changes: 91 additions & 0 deletions src/helper-modules/bpmn-helper/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
declare const _exports: {
ensureExtensionElements: typeof proceedExtensions.ensureExtensionElements;
removeEmptyExtensionElements: typeof proceedExtensions.removeEmptyExtensionElements;
ensureContainerElement: typeof proceedExtensions.ensureContainerElement;
removeEmptyContainerElement: typeof proceedExtensions.removeEmptyContainerElement;
setMetaData: typeof proceedExtensions.setMetaData;
setProceedElement: typeof proceedExtensions.setProceedElement;
getExporterName: typeof proceedConstants.getExporterName;
getExporterVersion: typeof proceedConstants.getExporterVersion;
generateBpmnId: typeof proceedConstants.generateBpmnId;
generateDefinitionsId: typeof proceedConstants.generateDefinitionsId;
generateProcessId: typeof proceedConstants.generateProcessId;
generateUserTaskFileName: typeof proceedConstants.generateUserTaskFileName;
getUserTaskImplementationString: typeof proceedConstants.getUserTaskImplementationString;
generateTargetNamespace: typeof proceedConstants.generateTargetNamespace;
initXml: typeof proceedConstants.initXml;
validateCalledProcess: typeof validators.validateCalledProcess;
setDefinitionsId: typeof setters.setDefinitionsId;
setDefinitionsName: typeof setters.setDefinitionsName;
setDefinitionsVersionInformation: typeof setters.setDefinitionsVersionInformation;
setProcessId: typeof setters.setProcessId;
setTemplateId: typeof setters.setTemplateId;
setTargetNamespace: typeof setters.setTargetNamespace;
setStandardDefinitions: typeof setters.setStandardDefinitions;
setDeploymentMethod: typeof setters.setDeploymentMethod;
setMachineInfo: typeof setters.setMachineInfo;
setUserTaskData: typeof setters.setUserTaskData;
addConstraintsToElementById: typeof setters.addConstraintsToElementById;
addCallActivityReference: typeof setters.addCallActivityReference;
removeCallActivityReference: typeof setters.removeCallActivityReference;
removeUnusedCallActivityReferences: typeof setters.removeUnusedCallActivityReferences;
removeColorFromAllElements: typeof setters.removeColorFromAllElements;
addDocumentation: typeof setters.addDocumentation;
addDocumentationToProcessObject: typeof setters.addDocumentationToProcessObject;
updatePerformersOnElement: typeof setters.updatePerformersOnElement;
updatePerformersOnElementById: typeof setters.updatePerformersOnElementById;
getDefinitionsId: typeof getters.getDefinitionsId;
getOriginalDefinitionsId: typeof getters.getOriginalDefinitionsId;
getDefinitionsName: typeof getters.getDefinitionsName;
getDefinitionsInfos: typeof getters.getDefinitionsInfos;
getImports: typeof getters.getImports;
getDefinitionsVersionInformation: typeof getters.getDefinitionsVersionInformation;
getProcessIds: typeof getters.getProcessIds;
getDeploymentMethod: typeof getters.getDeploymentMethod;
getProcessConstraints: typeof getters.getProcessConstraints;
getProcessDocumentation: typeof getters.getProcessDocumentation;
getProcessDocumentationByObject: typeof getters.getProcessDocumentationByObject;
getUserTaskFileNameMapping: typeof getters.getUserTaskFileNameMapping;
getAllUserTaskFileNamesAndUserTaskIdsMapping: typeof getters.getAllUserTaskFileNamesAndUserTaskIdsMapping;
getSubprocess: typeof getters.getSubprocess;
getSubprocessContent: typeof getters.getSubprocessContent;
getTargetDefinitionsAndProcessIdForCallActivityByObject: typeof getters.getTargetDefinitionsAndProcessIdForCallActivityByObject;
getDefinitionsAndProcessIdForEveryCallActivity: typeof getters.getDefinitionsAndProcessIdForEveryCallActivity;
getStartEvents: typeof getters.getStartEvents;
getAllBpmnFlowElements: typeof getters.getAllBpmnFlowElements;
getAllBpmnFlowNodeIds: typeof getters.getAllBpmnFlowNodeIds;
getAllBpmnFlowElementIds: typeof getters.getAllBpmnFlowElementIds;
getChildrenFlowElements: typeof getters.getChildrenFlowElements;
getElementMachineMapping: typeof getters.getElementMachineMapping;
getTaskConstraintMapping: typeof getters.getTaskConstraintMapping;
getIdentifyingInfos: typeof getters.getIdentifyingInfos;
getRootFromElement: typeof getters.getRootFromElement;
getMetaDataFromElement: typeof getters.getMetaDataFromElement;
getMetaData: typeof getters.getMetaData;
getMilestonesFromElement: typeof getters.getMilestonesFromElement;
getMilestonesFromElementById: typeof getters.getMilestonesFromElementById;
getResourcesFromElement: typeof getters.getResourcesFromElement;
getLocationsFromElement: typeof getters.getLocationsFromElement;
getPerformersFromElement: typeof getters.getPerformersFromElement;
getPerformersFromElementById: typeof getters.getPerformersFromElementById;
parseISODuration: typeof getters.parseISODuration;
convertISODurationToMiliseconds: typeof getters.convertISODurationToMiliseconds;
moddle: any;
ensureCorrectProceedNamespace: typeof util.ensureCorrectProceedNamespace;
toBpmnObject: typeof util.toBpmnObject;
toBpmnXml: typeof util.toBpmnXml;
getChildren: typeof util.getChildren;
getElementsByTagName: typeof util.getElementsByTagName;
getAllElements: typeof util.getAllElements;
getElementById: typeof util.getElementById;
getElementDI: typeof util.getElementDI;
manipulateElementById: typeof util.manipulateElementById;
manipulateElementsByTagName: typeof util.manipulateElementsByTagName;
};
export = _exports;
import proceedExtensions = require('./src/proceedExtensions');
import proceedConstants = require('./src/PROCEED-CONSTANTS.js');
import validators = require('./src/validators.js');
import setters = require('./src/setters.js');
import getters = require('./src/getters.js');
import util = require('./src/util.js');
2 changes: 1 addition & 1 deletion src/helper-modules/bpmn-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "eslint ."
},
"dependencies": {
"bpmn-moddle": "^6.0.0",
"bpmn-moddle": "^8.0.1",
"ids": "^1.0.0",
"uuid": "^9.0.0"
}
Expand Down
50 changes: 50 additions & 0 deletions src/helper-modules/bpmn-helper/src/PROCEED-CONSTANTS.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @module @proceed/bpmn-helper
*/
/**
* Exporter name is used in the bpmn definitions parts
*
* @returns {string} static exporter name
*/
export function getExporterName(): string;
/**
* Exporter version is used in the bpmn definitions parts
*
* This version should be adjusted when this module (bpmn-helper)
* changes or any changes in the management-system occur regarding the export
*
* @returns {string} static exporter version
*/
export function getExporterVersion(): string;
/**
* Generate a new ID for PROCEED BPMN elements
*
* @param {string} [prefix] optional prefix for the id
* @returns {string} short id in the form '0bkz1kb'
*/
export function generateBpmnId(prefix?: string): string;
/**
* Generate a new ID for the 'definitions' element in a PROCEED process
* @returns {string} a new PROCEED definitions 'id'
*/
export function generateDefinitionsId(): string;
export function generateProcessId(): string;
/**
* Generates the 'fileName' attribute string of a PROCEED UserTask
* @returns A new 'filename' value
*/
export function generateUserTaskFileName(): string;
/**
* Return the string for the 'implementation' attribute in a UserTask
* @returns {String} URL of the HTML spec
*/
export function getUserTaskImplementationString(): string;
export function generateTargetNamespace(id: any): string;
/**
* Creates a minimal valid proceed bpmn
*
* @param {*} processId the id to use for the contained process
* @param {string} startEventId the id to use for the start event
* @returns {string} a minimal valid proceed bpmn
*/
export function initXml(processId?: any, startEventId?: string): string;
6 changes: 3 additions & 3 deletions src/helper-modules/bpmn-helper/src/PROCEED-CONSTANTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const idGenerator = new Ids([32, 36, 1]);
/**
* Generate a new ID for PROCEED BPMN elements
*
* @param {String} [prefix] optional prefix for the id
* @param {string} [prefix] optional prefix for the id
* @returns {string} short id in the form '0bkz1kb'
*/
function generateBpmnId(prefix) {
Expand Down Expand Up @@ -90,8 +90,8 @@ function generateTargetNamespace(id) {
* Creates a minimal valid proceed bpmn
*
* @param {*} processId the id to use for the contained process
* @param {String} startEventId the id to use for the start event
* @returns {String} a minimal valid proceed bpmn
* @param {string} startEventId the id to use for the start event
* @returns {string} a minimal valid proceed bpmn
*/
function initXml(
processId = `Process_${generateBpmnId()}`,
Expand Down
Loading

0 comments on commit 660d9f4

Please sign in to comment.