Skip to content

Commit

Permalink
Fixed the extraction of tilt fields
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousjaki committed Feb 8, 2023
1 parent dd6ba1a commit f2d7898
Show file tree
Hide file tree
Showing 26 changed files with 568 additions and 363 deletions.
1 change: 1 addition & 0 deletions assets/accessible-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/bolt-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/compass-regular.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/eye-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/robot-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/section-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion bpmnlint-plugin-custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
rules: {
'process-must-contain-tilt-meta': 'off',
'third-country-transfers-are-disallowed':'off',
'controller-must-exist-once-and-only-once': 'error',
'fields-must-exist-once-and-only-once': 'error',
'controller-must-be-completely-filled':'warn',
'third-country-transfer-must-contain-country':'error'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
const {getTiltFromElementIfExists, tiltMustExistOnlyOnce} = require("../tilt-rule-helper");
const {
is
} = require('bpmnlint-utils');


/**
* Rule that reports manual tasks being used.
*/


module.exports = function() {
function check(node, reporter) {
Expand Down
18 changes: 18 additions & 0 deletions bpmnlint-plugin-custom/rules/dpo-must-exist-once-and-only-once.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const {getTiltFromElementIfExists, tiltMustExistOnlyOnce} = require("../tilt-rule-helper");

module.exports = function() {
function check(node, reporter) {
let check_passed = false;
let tilt_type = "tilt:DataProtectionOfficer";
if (getTiltFromElementIfExists(node, tilt_type)) {
check_passed = tiltMustExistOnlyOnce(tilt_type)
if(!check_passed){
reporter.report(node.id, `[ TILT ]\t ${tilt_type} must exist only once.`);
}
}
}

return {
check: check
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const {getTiltFromElementIfExists, tiltMustExistOnlyOnce} = require("../tilt-rule-helper");
const tiltToExistOnce = [
"tilt:Controller",
"tilt:DataProtectionOfficer",
"tilt:Meta",
"tilt:AccessAndDataPortability",
"tilt:RightToInformation",
"tilt:RightToRectificationOrDeletion",
"tilt:RightToDataPortability",
"tilt:RightToWithdrawConsent",
"tilt:RightToComplain",
"tilt:ChangesOfPurpose"
]

module.exports = function() {
function check(node, reporter) {
let check_passed = false;
for(let x in tiltToExistOnce){
debugger;
if (getTiltFromElementIfExists(node, tiltToExistOnce[x])) {
check_passed = tiltMustExistOnlyOnce(tiltToExistOnce[x])
if(!check_passed){
reporter.report(node.id, `[ TILT ]\t ${tiltToExistOnce[x]} must exist only once.`);
}
}
}
}

return {
check: check
};
};
18 changes: 18 additions & 0 deletions bpmnlint-plugin-custom/rules/meta-must-exist-once-and-only-once.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const {getTiltFromElementIfExists, tiltMustExistOnlyOnce} = require("../tilt-rule-helper");

module.exports = function() {
function check(node, reporter) {
let check_passed = false;
let tilt_type = "tilt:Meta";
if (getTiltFromElementIfExists(node, tilt_type)) {
check_passed = tiltMustExistOnlyOnce(tilt_type)
if(!check_passed){
reporter.report(node.id, `[ TILT ]\t ${tilt_type} must exist only once.`);
}
}
}

return {
check: check
};
};
11 changes: 9 additions & 2 deletions bpmnlint-plugin-custom/tilt-rule-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function test_if_properties_exists(node, tilt_type, propertiesToTest){
if ("extensionElements" in node){
for (let i = 0; i < node["extensionElements"]["values"].length; i++) {
if (node["extensionElements"]["values"][i].$type == tilt_type){
if (propertiesToTest.every(function(x) { return x in node["extensionElements"]["values"][i]})){
if (propertiesToTest.every(function(x) { return (x in node["extensionElements"]["values"][i]) && node["extensionElements"]["values"][i][x] != null})){
return true;
}
}
Expand All @@ -14,7 +14,14 @@ export function test_if_properties_exists(node, tilt_type, propertiesToTest){
}
export function tiltMustExistOnlyOnce(tilt_type){
let arr = filterObjectsWithTiltProperty(getBusinessObjectsFromCanvas(bpmnjsInjector.get("canvas")),tilt_type)
return arr.length == 1;
let counter = 0;
//debugger;
for(let a in arr){
if(arr[a].hasOwnProperty("main")&&arr[a].main){
counter++
}
}
return arr.length == 1 || counter == 1;
}

export function getTiltFromElementIfExists(node, tilt_type){
Expand Down
29 changes: 28 additions & 1 deletion client/descriptors/tilt.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
"label": "Meta information",
"superClass": [ "Element" ],
"properties": [
{
"name": "main",
"isAttr": true,
"type": "Boolean",
"label": "Main Meta Information",
"description": "Is this the primary TILT Element that should also appear in the extracted TILT-Document? ",
"regex": "",
"errMsg": ""
},
{
"name": "name",
"isAttr": true,
Expand Down Expand Up @@ -81,6 +90,15 @@
"label": "Controller information",
"superClass": [ "Element" ],
"properties": [
{
"name": "main",
"isAttr": true,
"type": "Boolean",
"label": "Main Controller",
"description": "Is this the primary TILT Element that should also appear in the extracted TILT-Document? ",
"regex": "",
"errMsg": ""
},
{
"name": "name",
"isAttr": true,
Expand Down Expand Up @@ -165,6 +183,15 @@
"label": "Data protection officer information",
"superClass": [ "Element" ],
"properties": [
{
"name": "main",
"isAttr": true,
"type": "Boolean",
"label": "Main DPO",
"description": "Is this the primary TILT Element that should also appear in the extracted TILT-Document? ",
"regex": "",
"errMsg": ""
},
{
"name": "name",
"isAttr": true,
Expand Down Expand Up @@ -218,7 +245,7 @@
"superClass": [ "Element" ],
"properties": [
{
"name": "id",
"name": "_id",
"isAttr": true,
"type": "String",
"label": "ID",
Expand Down
5 changes: 2 additions & 3 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ExtractButton from './tilt-extractor/extract-button';
import tiltOverlayProvider from './tilt-overlay'
import Assistant from './modeling-assistant';

//var tiltExtractor = require('./tilt-extractor/tilt-extractor');
import ExtractorMenu from './tilt-extractor/extractor-menu';

registerPlatformBpmnJSPlugin(tiltPropertiesExtensionModule);
registerBpmnJSModdleExtension(tiltModdleDescriptor);
Expand All @@ -22,6 +22,5 @@ registerPlatformBpmnJSPlugin(Assistant)
registerClientPlugin({ config, resolver }, 'lintRules.cloud-bpmn');
registerClientPlugin({ config, resolver }, 'lintRules.bpmn');

//registerBpmnJSPlugin(tiltExtractor);

registerBpmnJSPlugin(ExtractorMenu);
registerClientExtension(ExtractButton);
2 changes: 0 additions & 2 deletions client/modeling-assistant/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export function getPropertyOfObject(element,objectType,propertyName){
export function modifyCountryTransfer(element, injector){
var bo = getBusinessObject(element)
if(bo && "$type" in bo && bo.$type == "bpmn:MessageFlow"){
debugger;
let sourceCountry = getPropertyOfObject(element.source.parent,"tilt:Controller","country");
let targetCountry = getPropertyOfObject(element.target.parent,"tilt:Controller","country");
if(sourceCountry != targetCountry && sourceCountry != null && targetCountry != null){
Expand Down Expand Up @@ -137,7 +136,6 @@ export default class Assistant {
});
eventBus.on('commandStack.element.updateModdleProperties.postExecuted', function(e) {
if(e.context.oldProperties.hasOwnProperty("country") && e.context.moddleElement.$type == "tilt:Controller"){
debugger;
var element = e.context.element
var foundElements = findElements(element,"bpmn:MessageFlow")
for(let i in foundElements){
Expand Down
137 changes: 3 additions & 134 deletions client/tilt-extractor/extract-button.js
Original file line number Diff line number Diff line change
@@ -1,157 +1,26 @@
import React, { Fragment, PureComponent } from 'camunda-modeler-plugin-helpers/react';
import { Fill } from 'camunda-modeler-plugin-helpers/components';
import tiltIcon from "../../assets/tilt.svg"
const { getBusinessObject } = require('bpmn-js/lib/util/ModelUtil');
import { v4 as uuidv4 } from 'uuid';

import classNames from 'classnames';
import {getPropertyFromModdle } from '../tilt-properties/props/moddle-property-io';
import TILT from "../descriptors/tilt.json"
import { buildTiltDocument } from './extractor';
import { saveFile } from './extractor';

export default class ExtractButton extends PureComponent {
constructor() {
super();
this._buttonRef = React.createRef();
}

getTiltElements(element = null) {
// if(!element){
// element = getBusinessObject(canvas.getRootElement());
// }
var element_properties = [];
var tilt_properties = [];

if(element instanceof Object && !(element instanceof Array || element instanceof Function)){
element_properties = Object.getOwnPropertyNames(element);
element_properties = element_properties.filter(e =>
!e.startsWith("$") &&
!['di','messageFlows','sourceRef','targetRef','incoming','outgoing','flowNodeRef'].includes(e))

}else if(Array.isArray(element)){
for(let i in element){
tilt_properties.push(...this.getTiltElements(element[i]));
}
return tilt_properties;

}else{
return tilt_properties;

}

if(element.hasOwnProperty("$type") && element.$type.startsWith("tilt")){
tilt_properties.push(element);
//console.log(element)
return tilt_properties;

}

for(let p in element_properties){

if(element[element_properties[p]] instanceof Object && typeof(element[element_properties[p]]) != "string"){
tilt_properties.push(...this.getTiltElements(element[element_properties[p]]));

}
}
return tilt_properties;
};

getMeta(tilt_elements = []){
tilt_elements = tilt_elements.filter(e => e.$type == "tilt:Meta");
var meta = {};
var element_properties = tilt_descriptor.types.filter(e => e.name == "Meta")[0].properties
var property_names = [];
for(let i in element_properties){
property_names.push(element_properties[i].name.split(":")[1]);
}
for(m in tilt_elements){
for(p in property_names){
if(tilt_elements[m].hasOwnProperty(property_names[p])){
meta[property_names[p]] = tilt_elements[m][property_names[p]]
}else{
meta[property_names[p]] = null;
}
}

}
return meta
}

createTiltObject(){
debugger;
var canvas = window.bpmnjsInjector.get("canvas");
var rootElement = canvas.getRootElement();
var tilt_object = {}
var tilt_elements = getBusinessObject(this.getTiltElements(rootElement));
tilt_object["meta"] = this.getMeta(tilt_elements);
navigator.clipboard.writeText(tilt_object)

alert("Copied the extracted TILT Document to the clipboard.")
debugger;
}

createPropertyFromFile(){
var moddle = TILT;
debugger;
var x = getPropertyFromModdle("tilt:Meta",moddle);
}

saveFile(){
var object = buildTiltDocument(window.bpmnjsInjector.get("canvas"))
debugger;
var json_string = JSON.stringify(object, undefined, 2);
var link = document.createElement('a');
link.download = 'NewTiltDocument.tilt.json';
var blob = new Blob([json_string], {type: 'application/json'});
link.href = window.URL.createObjectURL(blob);
link.click();
}

async saveFile2(){
const opts = {
suggestedName: "NewProcessTiltDocument.tilt.json",
types: [{
description: 'TILT .json file',
accept: {'application/json': ['.tilt.json']},
}],
excludeAcceptAllOption: true,
};
try {
// Show the file save dialog.
const handle = await window.showSaveFilePicker(opts);
// Write to the file.
const writable = await handle.createWritable();
debugger;
await writable.write("Hello World");
await writable.close();
return;
} catch (err) {
if (err.name !== 'AbortError') {
alert(err.name +": "+ err.message);
return;
}
}
}


render() {
// we can use fills to hook React components into certain places of the UI
return <Fragment>
<Fill slot="status-bar__file" group="1_tilt_save">
<button
ref={ this._buttonRef }
className={ classNames('tilt-btn','btn') }
onClick={ () => this.saveFile()}>
onClick={ () => saveFile(window.bpmnjsInjector.get("canvas"))}>
TILT
</button>
</Fill>
</Fragment>;
}
}

//ExtractButton.$inject = [
// 'eventBus',
// 'canvas',
// 'injector',
// 'viewer'
//];
}
Loading

0 comments on commit f2d7898

Please sign in to comment.