@simitgroup/simpleapp-generator 1.1.14 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/framework.js +3 -3
- package/dist/framework.js.map +1 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +20 -7
- package/dist/generate.js.map +1 -1
- package/dist/processors/bpmnbuilder.d.ts +2 -0
- package/dist/processors/bpmnbuilder.d.ts.map +1 -0
- package/dist/processors/bpmnbuilder.js +151 -0
- package/dist/processors/bpmnbuilder.js.map +1 -0
- package/dist/resource/camunda-moodle.d.ts +27 -0
- package/dist/resource/camunda-moodle.d.ts.map +1 -0
- package/dist/resource/camunda-moodle.js +91 -0
- package/dist/resource/camunda-moodle.js.map +1 -0
- package/package.json +3 -1
- package/src/framework.ts +3 -3
- package/src/generate.ts +25 -7
- package/src/processors/bpmnbuilder.ts +148 -0
- package/src/resource/camunda-moodle.ts +87 -0
- package/templates/basic/nuxt/pages.[id].vue.eta +4 -3
- package/templates/basic/nuxt/pages.form.vue.eta +0 -1
- package/templates/basic/nuxt/pages.landing.vue.eta +11 -11
- package/templates/basic/nuxt/pages.new.vue.eta +4 -3
- package/templates/basic/nuxt/pages.viewer.vue.eta +4 -7
- package/templates/nest/.env._eta +1 -1
- package/templates/nest/src/app.module.ts.eta +1 -3
- package/templates/nest/src/simpleapp/.gitignore.eta +2 -1
- package/templates/nest/src/simpleapp/generate/workflow/formschema/SimpleApproveReject.ts.eta +8 -0
- package/templates/nest/src/simpleapp/generate/workflow/formschema/index.ts.eta +1 -0
- package/templates/nest/src/{workflow → simpleapp/generate/workflow}/workflow.controller.ts.eta +4 -4
- package/templates/nest/src/simpleapp/generate/workflow/workflow.delegate.ts.eta +153 -0
- package/templates/nest/src/{workflow → simpleapp/generate/workflow}/workflow.service.ts.eta +11 -32
- package/templates/nest/src/{workflow → simpleapp/generate/workflow}/workflow.type.ts.eta +7 -0
- package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +17 -4
- package/templates/nest/src/simpleapp/workflows/bpmn/readme.md._eta +1 -0
- package/templates/nest/src/simpleapp/workflows/delegates/simpleapp.delegate.ts._eta +27 -0
- package/templates/nest/src/simpleapp/workflows/readme.md._eta +1 -0
- package/templates/nuxt/.gitignore.eta +5 -4
- package/templates/nuxt/components/header/button/task/HeaderButtonTaskList.vue.eta +47 -72
- package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +1 -1
- package/templates/nuxt/components/simpleApp/SimpleAppJsonSchemaForm.vue.eta +5 -6
- package/templates/nuxt/components/workflow/forms/dynamicfield.vue._eta +85 -0
- package/templates/nuxt/components/workflow/forms/index.ts._eta +10 -0
- package/templates/nuxt/components/workflow/forms/simpleapprove.vue._eta +43 -0
- package/templates/nuxt/lang/{df.ts.eta → df.ts._eta} +4 -1
- package/templates/nuxt/nuxt.config.ts.eta +1 -1
- package/templates/nuxt/simpleapp/workflows/bpmn/readme.md._eta +1 -0
- package/templates/nuxt/simpleapp/workflows/forms/readme.md._eta +1 -0
- package/templates/{nest/src/workflow/bpmn/suspendcustomer.bpmn.eta → project/workflows/bpmn/suspendcustomer.bpmn._eta} +13 -26
- package/templates/project/workflows/forms/index.ts.eta +2 -0
- package/templates/project/workflows/forms/simpleapprove.jsonschema.ts.eta +8 -0
- package/templates/workflow/next/delegate.ts.eta +31 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/processors/jsonschemabuilder.ts-old +0 -383
- package/templates/nest/src/workflow/delegates/customer.ts._eta +0 -8
- package/templates/nest/src/workflow/delegates/hello.ts._eta +0 -5
- package/templates/nest/src/workflow/delegates/index.ts._eta +0 -5
- package/templates/nest/src/workflow/delegates/invoice.delegates.ts._eta +0 -9
- package/templates/nest/src/workflow/delegates/usertask.ts._eta +0 -3
- package/templates/nest/src/workflow/formschema/SimpleApproveReject.ts._eta +0 -8
- package/templates/nest/src/workflow/formschema/index.ts._eta +0 -1
- package/templates/nest/src/workflow/workflow.delegate.ts.eta +0 -104
- package/templates/nest/src/workflow/workflow.delegateservice.ts._eta +0 -46
- package/templates/nest/src/workflow/workflow.module.ts.eta +0 -21
- /package/templates/nest/src/{workflow → simpleapp/generate/workflow}/workflow.apischema.ts.eta +0 -0
- /package/templates/nest/src/{workflow → simpleapp/generate/workflow}/workflow.config.ts.eta +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Logger, ILogObj } from "tslog";
|
|
2
|
+
import { capitalizeFirstLetter } from './../libs';
|
|
3
|
+
import {mkdirSync, readdir,readFileSync,writeFileSync,existsSync,copyFileSync, readdirSync} from 'fs'
|
|
4
|
+
import BpmnModdle from 'bpmn-moddle';
|
|
5
|
+
import _ from 'lodash'
|
|
6
|
+
import * as constants from '../constant'
|
|
7
|
+
import {moddleOptions} from '../resource/camunda-moodle'
|
|
8
|
+
const log: Logger<ILogObj> = new Logger();
|
|
9
|
+
const { Eta } = require('eta');
|
|
10
|
+
export const generateWorkflows = async (configs,genFor:string[]) =>{
|
|
11
|
+
const invalidDelegate = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
|
|
12
|
+
|
|
13
|
+
const moddle = new BpmnModdle({moddleOptions});
|
|
14
|
+
const frontendFolder=configs.frontendFolder
|
|
15
|
+
const backendFolder=configs.backendFolder
|
|
16
|
+
const bpmnFolder = configs.bpmnFolder
|
|
17
|
+
const filelist = readdirSync(bpmnFolder)
|
|
18
|
+
|
|
19
|
+
console.log("filelist",filelist)
|
|
20
|
+
const generateTemplatefolder = `${constants.templatedir}/workflow`
|
|
21
|
+
let workflows:string[] = []
|
|
22
|
+
|
|
23
|
+
if(genFor.includes('nest')){
|
|
24
|
+
mkdirSync(`${backendFolder}/src/simpleapp/workflows/bpmn`,{recursive:true})
|
|
25
|
+
mkdirSync(`${backendFolder}/src/simpleapp/workflows/delegates`,{recursive:true})
|
|
26
|
+
}
|
|
27
|
+
if(genFor.includes('nuxt')){
|
|
28
|
+
mkdirSync(`${frontendFolder}/simpleapp/workflows/bpmn`,{recursive:true})
|
|
29
|
+
mkdirSync(`${frontendFolder}/simpleapp/workflows/forms`,{recursive:true})
|
|
30
|
+
copyFormKeys(`${bpmnFolder}/../forms`,`${frontendFolder}/simpleapp/workflows/forms`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for(let w = 0; w< filelist.length;w++){
|
|
34
|
+
const bpmnfile = filelist[w]
|
|
35
|
+
if(bpmnfile=='.'){
|
|
36
|
+
continue
|
|
37
|
+
}
|
|
38
|
+
const bpmnfilepath = `${bpmnFolder}/${bpmnfile}`
|
|
39
|
+
const processName = bpmnfile.split('.')[0]
|
|
40
|
+
|
|
41
|
+
const xmlstring = readFileSync(`${bpmnfilepath}`, 'utf-8');
|
|
42
|
+
|
|
43
|
+
const xmlobj = await moddle.fromXML(xmlstring);
|
|
44
|
+
const elements = xmlobj.rootElement.rootElements[0].flowElements
|
|
45
|
+
let delegates:string[]=[]
|
|
46
|
+
for(let i=0; i<elements.length;i++){
|
|
47
|
+
const e = elements[i]
|
|
48
|
+
|
|
49
|
+
switch(e.$type){
|
|
50
|
+
case 'bpmn:UserTask':
|
|
51
|
+
const setting = e.get('extensionElements')
|
|
52
|
+
if(setting && setting.values){
|
|
53
|
+
for(let j=0;j<setting.values.length;j++){
|
|
54
|
+
const s = setting.values[j]
|
|
55
|
+
if(s.$type=='camunda:taskListener'){
|
|
56
|
+
if(!invalidDelegate.test(s.delegateExpression)){
|
|
57
|
+
delegates.push(s.delegateExpression)
|
|
58
|
+
}else{
|
|
59
|
+
log.error(`bpmn File : ${bpmnfile} -> UserTask(${s.name}/${s.id}) defined invalid symbol in delegate Expression: "${s.delegateExpression}"`);
|
|
60
|
+
throw "quite"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
console.log("Element user task type", e.$type, ", id:",e.id, setting)
|
|
69
|
+
break;
|
|
70
|
+
case 'bpmn:ServiceTask':
|
|
71
|
+
console.log("Element service type", e.$type, ", id:",e.id)
|
|
72
|
+
if(!invalidDelegate.test(e.delegateExpression)){
|
|
73
|
+
delegates.push(e.delegateExpression)
|
|
74
|
+
}else{
|
|
75
|
+
log.error(`bpmn File : ${bpmnfile} -> ServiceTask(${e.name}/${e.id}) defined invalid symbol in delegate Expression: "${e.delegateExpression}"`);
|
|
76
|
+
throw "quite"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
delegates = _.uniq(delegates)
|
|
84
|
+
const variables = {
|
|
85
|
+
processName: capitalizeFirstLetter(processName),
|
|
86
|
+
delegates: delegates
|
|
87
|
+
}
|
|
88
|
+
// console.log("sample--------sample",xmlobj.rootElement.rootElements[0].name, )
|
|
89
|
+
|
|
90
|
+
//copy workflow definition file to frontend and backend
|
|
91
|
+
if(genFor.includes('nest')){
|
|
92
|
+
copyFileSync(`${bpmnfilepath}`,`${backendFolder}/src/simpleapp/workflows/bpmn/${bpmnfile}`)
|
|
93
|
+
const targetdelegate = `${backendFolder}/src/simpleapp/workflows/delegates/${processName}.delegate.ts`
|
|
94
|
+
|
|
95
|
+
const eta = new Eta({
|
|
96
|
+
views: '/',
|
|
97
|
+
functionHeader: getCodeGenHelper()
|
|
98
|
+
});
|
|
99
|
+
if(!existsSync(targetdelegate) || readFileSync(targetdelegate, 'utf-8').includes('--remove-this-line-to-prevent-override--')){
|
|
100
|
+
// //write something
|
|
101
|
+
const templatepath = `${generateTemplatefolder}/next/delegate.ts.eta`
|
|
102
|
+
const filecontent = eta.render(templatepath, variables)
|
|
103
|
+
writeFileSync(targetdelegate,filecontent)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if(genFor.includes('nuxt')){
|
|
107
|
+
copyFileSync(`${bpmnfilepath}`,`${frontendFolder}/simpleapp/workflows/bpmn/${bpmnfile}`)
|
|
108
|
+
|
|
109
|
+
//create form key
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
workflows.push(processName)
|
|
118
|
+
|
|
119
|
+
//modify workflowdeletegate to import all files
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
//copy file backend
|
|
124
|
+
//copy file frontend
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
// const groupdata = JSON.parse(groupjsonstr);
|
|
128
|
+
// const documentname = groupfile.split('.')[0]
|
|
129
|
+
// const roles = prepareRoles(groupdata)
|
|
130
|
+
// allroles[documentname]=roles
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
return workflows
|
|
136
|
+
}
|
|
137
|
+
const copyFormKeys=(fromtPath:string , toPath:string)=>{
|
|
138
|
+
const files = readdirSync(fromtPath)
|
|
139
|
+
for(let i=0; i< files.length;i++){
|
|
140
|
+
const filename = files[i]
|
|
141
|
+
if(filename=='.') continue
|
|
142
|
+
|
|
143
|
+
copyFileSync(`${fromtPath}/${filename}`,`${toPath}/${filename}`)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const getCodeGenHelper = () => 'const capitalizeFirstLetter = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);' +
|
|
147
|
+
'const initType=(str)=>{return ["string","number","boolean","array","object"].includes(str) ? capitalizeFirstLetter(str) : str;};' +
|
|
148
|
+
'const camelCaseToWords = (s) => {const result = s.replace(/([A-Z])/g, \' $1\');return result.charAt(0).toUpperCase() + result.slice(1);}'
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const moddleOptions =
|
|
2
|
+
{
|
|
3
|
+
"name": "Node bpmn-engine",
|
|
4
|
+
"uri": "http://paed01.github.io/bpmn-engine/schema/2017/08/bpmn",
|
|
5
|
+
"prefix": "js",
|
|
6
|
+
"xml": {
|
|
7
|
+
"tagAlias": "lowerCase"
|
|
8
|
+
},
|
|
9
|
+
"types": [
|
|
10
|
+
{
|
|
11
|
+
"name": "Task",
|
|
12
|
+
"isAbstract": true,
|
|
13
|
+
"extends": ["bpmn:Task"],
|
|
14
|
+
"properties": [
|
|
15
|
+
{
|
|
16
|
+
"name": "result",
|
|
17
|
+
"isAttr": true,
|
|
18
|
+
"type": "String"
|
|
19
|
+
}]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "Output",
|
|
23
|
+
"superClass": ["Element"]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "Collectable",
|
|
27
|
+
"isAbstract": true,
|
|
28
|
+
"extends": ["bpmn:MultiInstanceLoopCharacteristics"],
|
|
29
|
+
"properties": [
|
|
30
|
+
{
|
|
31
|
+
"name": "collection",
|
|
32
|
+
"isAttr": true,
|
|
33
|
+
"type": "String"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "elementVariable",
|
|
37
|
+
"isAttr": true,
|
|
38
|
+
"type": "String"
|
|
39
|
+
} ]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "FormSupported",
|
|
43
|
+
"isAbstract": true,
|
|
44
|
+
"extends": [
|
|
45
|
+
"bpmn:StartEvent",
|
|
46
|
+
"bpmn:UserTask"
|
|
47
|
+
],
|
|
48
|
+
"properties": [
|
|
49
|
+
{
|
|
50
|
+
"name": "camunda:formKey",
|
|
51
|
+
"isAttr": true,
|
|
52
|
+
"type": "String"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "SendCall",
|
|
58
|
+
"isAbstract": true,
|
|
59
|
+
"extends": [
|
|
60
|
+
"bpmn:SendTask"
|
|
61
|
+
],
|
|
62
|
+
"properties": [
|
|
63
|
+
{
|
|
64
|
+
"name": "camunda:delegateExpression",
|
|
65
|
+
"isAttr": true,
|
|
66
|
+
"type": "String"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "ServiceCall",
|
|
72
|
+
"isAbstract": true,
|
|
73
|
+
"extends": [
|
|
74
|
+
"bpmn:ServiceTask"
|
|
75
|
+
],
|
|
76
|
+
"properties": [
|
|
77
|
+
{
|
|
78
|
+
"name": "camunda:delegateExpression",
|
|
79
|
+
"isAttr": true,
|
|
80
|
+
"type": "String"
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export {moddleOptions}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Crud :_id="_id"/>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
1
5
|
<script setup lang="ts">
|
|
2
6
|
/**
|
|
3
7
|
* This file was automatically generated by simpleapp everytime regenerate code.
|
|
@@ -9,6 +13,3 @@
|
|
|
9
13
|
import Crud from './form.vue'
|
|
10
14
|
defineProps(['_id'])
|
|
11
15
|
</script>
|
|
12
|
-
<template>
|
|
13
|
-
<Crud :_id="_id"/>
|
|
14
|
-
</template>
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
|
|
3
|
+
<DocPageList :document="doc" :columns="columns" :sorts="sorts">
|
|
4
|
+
<title v-if="!id">{{ t(doc.getDocName()) }} </title>
|
|
5
|
+
<div>
|
|
6
|
+
<NuxtPage :_id="id ?? 'new'"/>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
</DocPageList>
|
|
11
|
+
</template>
|
|
1
12
|
<script setup lang="ts">
|
|
2
13
|
/**
|
|
3
14
|
* This file was automatically generated by simpleapp everytime regenerate code.
|
|
@@ -38,16 +49,5 @@
|
|
|
38
49
|
|
|
39
50
|
const id=computed(()=>useRoute().params.id)
|
|
40
51
|
</script>
|
|
41
|
-
<template>
|
|
42
|
-
|
|
43
|
-
<DocPageList :document="doc" :columns="columns" :sorts="sorts">
|
|
44
|
-
<title v-if="!id">{{ t(doc.getDocName()) }} </title>
|
|
45
|
-
<div>
|
|
46
|
-
<NuxtPage :_id="id ?? 'new'"/>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</div>
|
|
50
|
-
</DocPageList>
|
|
51
|
-
</template>
|
|
52
52
|
|
|
53
53
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Crud _id="new" @after-create="redirect"/>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
1
5
|
<script setup lang="ts">
|
|
2
6
|
/**
|
|
3
7
|
* This file was automatically generated by simpleapp everytime regenerate code.
|
|
@@ -14,6 +18,3 @@ const redirect = (data:any)=>{
|
|
|
14
18
|
goTo(doc.getDocName(), data._id);
|
|
15
19
|
}
|
|
16
20
|
</script>
|
|
17
|
-
<template>
|
|
18
|
-
<Crud _id="new" @after-create="redirect"/>
|
|
19
|
-
</template>
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Crud _id="new" @after-create="afterCreate"/>
|
|
3
|
+
</template>
|
|
1
4
|
<script setup lang="ts">
|
|
2
5
|
/**
|
|
3
6
|
* This file was automatically generated by simpleapp everytime regenerate code.
|
|
@@ -12,10 +15,4 @@ const emits = defineEmits(['afterCreate'])
|
|
|
12
15
|
const afterCreate = (data:any)=>{
|
|
13
16
|
emits('afterCreate',data)
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<template>
|
|
20
|
-
<Crud _id="new" @after-create="afterCreate"/>
|
|
21
|
-
</template>
|
|
18
|
+
</script>
|
package/templates/nest/.env._eta
CHANGED
|
@@ -28,7 +28,6 @@ import {GenerateModule} from './simpleapp/simpleapp.module'
|
|
|
28
28
|
import { UserMongoSchema } from './simpleapp/generate/models/user.model';
|
|
29
29
|
import { PermissionMongoSchema } from './simpleapp/generate/models/perm.model';
|
|
30
30
|
import { ApiEventMongoSchema } from './simpleapp/generate/models/apievent.model';
|
|
31
|
-
import { WorkflowModule } from './workflow/workflow.module'
|
|
32
31
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
|
33
32
|
|
|
34
33
|
@Module({
|
|
@@ -69,8 +68,7 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
|
|
|
69
68
|
{ name: 'User', schema: UserMongoSchema },
|
|
70
69
|
{ name: 'Permission', schema: PermissionMongoSchema },
|
|
71
70
|
{ name: 'ApiEvent', schema: ApiEventMongoSchema },
|
|
72
|
-
]),
|
|
73
|
-
WorkflowModule,
|
|
71
|
+
]),
|
|
74
72
|
],
|
|
75
73
|
controllers: [AppController],
|
|
76
74
|
providers: [
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
generate
|
|
1
|
+
generate
|
|
2
|
+
workflows/bpmn
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SimpleApproveReject';
|
package/templates/nest/src/{workflow → simpleapp/generate/workflow}/workflow.controller.ts.eta
RENAMED
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
} from '@nestjs/common';
|
|
12
12
|
import { WorkflowService } from './workflow.service';
|
|
13
13
|
import { UserTaskActors } from './workflow.type';
|
|
14
|
-
import { Roles } from '../
|
|
15
|
-
import { Role } from '../
|
|
14
|
+
import { Roles } from '../commons/roles/roles.decorator';
|
|
15
|
+
import { Role } from '../commons/roles/roles.enum';
|
|
16
16
|
import {
|
|
17
17
|
WorkflowDataApiSchema,
|
|
18
18
|
WorkflowProcessApiSchema,
|
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
UserTaskApiSchema,
|
|
22
22
|
} from './workflow.apischema';
|
|
23
23
|
import { ApiTags, ApiBody, ApiResponse, ApiOperation } from '@nestjs/swagger';
|
|
24
|
-
import { AppUser } from '../
|
|
25
|
-
import { UserContext } from '../
|
|
24
|
+
import { AppUser } from '../commons/decorators/appuser.decorator';
|
|
25
|
+
import { UserContext } from '../commons/user.context';
|
|
26
26
|
@ApiTags('workflow')
|
|
27
27
|
@Controller('workflow')
|
|
28
28
|
export class WorkflowController {
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Injectable,Logger } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
IExecution,
|
|
4
|
+
Item,
|
|
5
|
+
NODE_ACTION,
|
|
6
|
+
FLOW_ACTION,
|
|
7
|
+
IAppDelegate,
|
|
8
|
+
IDefinition,
|
|
9
|
+
BPMNServer,
|
|
10
|
+
} from 'bpmn-server';
|
|
11
|
+
import { moddleOptions } from 'bpmn-server/src/elements/js-bpmn-moddle';
|
|
12
|
+
|
|
13
|
+
<%for(let i=0; i<it.allbpmn.length;i++){%><%let bpmn = it.allbpmn[i]%>
|
|
14
|
+
import { <%=capitalizeFirstLetter(bpmn)%>DelegateService } from 'src/simpleapp/workflows/delegates/<%=bpmn%>.delegate';
|
|
15
|
+
<%}%>
|
|
16
|
+
// import * as dservice from './delegates'
|
|
17
|
+
@Injectable()
|
|
18
|
+
export class WorkflowDelegate implements IAppDelegate {
|
|
19
|
+
protected logger = new Logger();
|
|
20
|
+
server: BPMNServer;
|
|
21
|
+
servicesProvider: any;
|
|
22
|
+
constructor(
|
|
23
|
+
<%for(let i=0; i<it.allbpmn.length;i++){%>
|
|
24
|
+
<%let bpmn = it.allbpmn[i]%>
|
|
25
|
+
private <%=bpmn%>DelegateService: <%=capitalizeFirstLetter(bpmn)%>DelegateService,
|
|
26
|
+
<%}%>
|
|
27
|
+
) {
|
|
28
|
+
this.servicesProvider = {
|
|
29
|
+
<%for(let i=0; i<it.allbpmn.length;i++){%>
|
|
30
|
+
<%let bpmn = it.allbpmn[i]%>
|
|
31
|
+
<%= bpmn%>: this.<%=bpmn%>DelegateService,
|
|
32
|
+
<%}%>
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//config will use setServer to define bpmnserver
|
|
36
|
+
setServer(server: BPMNServer) {
|
|
37
|
+
this.server = server;
|
|
38
|
+
let self = this;
|
|
39
|
+
server.listener.on('all', async function ({ context, event }) {
|
|
40
|
+
await self.executionEvent(context, event);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
startUp(options) {}
|
|
45
|
+
sendEmail(to, msg, body) {
|
|
46
|
+
throw Error('sendEmail must be implemented by AppDelegate');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get moddleOptions() {
|
|
50
|
+
return moddleOptions;
|
|
51
|
+
}
|
|
52
|
+
async executionStarted(execution: IExecution) {}
|
|
53
|
+
async executionEvent(context, event) {}
|
|
54
|
+
|
|
55
|
+
async messageThrown(messageId, data, messageMatchingKey: any, item: Item) {
|
|
56
|
+
const msgId = item.node.messageId;
|
|
57
|
+
item.context.logger.log('Message Issued' + msgId);
|
|
58
|
+
// issue it back for others to receive
|
|
59
|
+
const resp = await item.context.engine.throwMessage(
|
|
60
|
+
msgId,
|
|
61
|
+
data,
|
|
62
|
+
messageMatchingKey,
|
|
63
|
+
);
|
|
64
|
+
if (resp && resp.instance) {
|
|
65
|
+
item.context.logger.log(
|
|
66
|
+
' invoked another process ' +
|
|
67
|
+
resp.instance.id +
|
|
68
|
+
' for ' +
|
|
69
|
+
resp.instance.name,
|
|
70
|
+
);
|
|
71
|
+
} else await this.issueMessage(messageId, data);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async issueMessage(messageId, data) {}
|
|
75
|
+
async issueSignal(signalId, data) {}
|
|
76
|
+
async signalThrown(signalId, data, messageMatchingKey: any, item: Item) {
|
|
77
|
+
item.context.logger.log('Signal Issued' + signalId);
|
|
78
|
+
|
|
79
|
+
const resp = await item.context.engine.throwSignal(
|
|
80
|
+
signalId,
|
|
81
|
+
data,
|
|
82
|
+
messageMatchingKey,
|
|
83
|
+
);
|
|
84
|
+
if (resp && resp.instance) {
|
|
85
|
+
item.context.logger.log(
|
|
86
|
+
' invoked another process ' +
|
|
87
|
+
resp.instance.id +
|
|
88
|
+
' for ' +
|
|
89
|
+
resp.instance.name,
|
|
90
|
+
);
|
|
91
|
+
} else await this.issueSignal(signalId, data);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async serviceCalled(delegateServiceName:string, inputdata, item: Item) {
|
|
95
|
+
const processName = item['instance']['name']
|
|
96
|
+
const data = item['instance']['data']
|
|
97
|
+
const vars = item['instance']['vars']
|
|
98
|
+
const props = {
|
|
99
|
+
processName: processName,
|
|
100
|
+
delegateName: delegateServiceName,
|
|
101
|
+
inputData: inputdata,
|
|
102
|
+
vars: vars,
|
|
103
|
+
data: data
|
|
104
|
+
}
|
|
105
|
+
if (this.servicesProvider[processName] && this.servicesProvider[processName][delegateServiceName]) {
|
|
106
|
+
this.servicesProvider[processName][delegateServiceName](props,item);
|
|
107
|
+
}else{
|
|
108
|
+
this.logger.error(`Undefined delegate service "${processName}":"${delegateServiceName}"`,props)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
scopeEval(scope, script) {
|
|
114
|
+
let result;
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
var js = `
|
|
118
|
+
var item=this;
|
|
119
|
+
var data=this.data;
|
|
120
|
+
var input=this.input;
|
|
121
|
+
var output=this.output;
|
|
122
|
+
return (${script});`;
|
|
123
|
+
result = Function(js).bind(scope)();
|
|
124
|
+
} catch (exc) {
|
|
125
|
+
console.log('error in script evaluation', js);
|
|
126
|
+
console.log(exc);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
async scopeJS(scope, script) {
|
|
131
|
+
const AsyncFunction = Object.getPrototypeOf(
|
|
132
|
+
async function () {},
|
|
133
|
+
).constructor;
|
|
134
|
+
let result;
|
|
135
|
+
try {
|
|
136
|
+
var js = `
|
|
137
|
+
var item=this;
|
|
138
|
+
var data=this.data;
|
|
139
|
+
var input=this.input;
|
|
140
|
+
var output=this.output;
|
|
141
|
+
${script}`;
|
|
142
|
+
result = await new AsyncFunction(js).bind(scope)();
|
|
143
|
+
scope.token.log('..executing js is done ' + scope.id);
|
|
144
|
+
} catch (exc) {
|
|
145
|
+
scope.token.log(
|
|
146
|
+
'ERROR in executing Script ' + exc.message + '\n' + script,
|
|
147
|
+
);
|
|
148
|
+
console.log('error in script execution', js);
|
|
149
|
+
console.log(exc);
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
import { WorkflowConfig } from './workflow.config';
|
|
2
1
|
/**
|
|
3
|
-
* bpmn
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* 2. update existing process
|
|
10
|
-
* 3. cancel process *
|
|
11
|
-
* 4. find my process *
|
|
12
|
-
* 5. find all proccess by filter in current tenant *
|
|
13
|
-
* 6. invoke process (approve, accept and reject)
|
|
14
|
-
* 7.getproccessbyid
|
|
15
|
-
*
|
|
16
|
-
* supply callback
|
|
17
|
-
* 1. send messaging
|
|
18
|
-
* 2. obtain dynamic users, candidate users/groups
|
|
19
|
-
* 3.
|
|
20
|
-
|
|
2
|
+
* This file execute workflow bpmn-server command
|
|
3
|
+
* This file was automatically generated by simpleapp generator.
|
|
4
|
+
* DONT CHANGE THIS FILE !!
|
|
5
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
6
|
+
* last change 2023-10-28
|
|
7
|
+
* Author: Ks Tan
|
|
21
8
|
*/
|
|
22
|
-
|
|
9
|
+
import { WorkflowConfig } from './workflow.config';
|
|
23
10
|
import {
|
|
24
11
|
BadRequestException,
|
|
25
12
|
Injectable,
|
|
@@ -38,8 +25,8 @@ import {
|
|
|
38
25
|
import { OnEvent } from '@nestjs/event-emitter';
|
|
39
26
|
import { BPMNServer, Logger as bpmnlogger } from 'bpmn-server';
|
|
40
27
|
// import { configuration } from './configuration';
|
|
41
|
-
import { UserContext } from '../
|
|
42
|
-
import * as formschemas from '
|
|
28
|
+
import { UserContext } from '../commons/user.context';
|
|
29
|
+
//import * as formschemas from '../../workflow/formschema';
|
|
43
30
|
export {
|
|
44
31
|
WorkflowSettingApiSchema,
|
|
45
32
|
WorkflowDataApiSchema,
|
|
@@ -378,15 +365,7 @@ export class WorkflowService {
|
|
|
378
365
|
let node = definition.getNodeById(elementId);
|
|
379
366
|
if (node) {
|
|
380
367
|
const formKey = node.def.formKey;
|
|
381
|
-
let schema: string =
|
|
382
|
-
if (formKey.includes('jsonschema://')) {
|
|
383
|
-
const keyname = formKey.replace('jsonschema://', '');
|
|
384
|
-
schema = formschemas[keyname];
|
|
385
|
-
} else if (formKey.includes('custom://')) {
|
|
386
|
-
schema = formKey;
|
|
387
|
-
} else {
|
|
388
|
-
//others implementation like http://, https:// and etc
|
|
389
|
-
}
|
|
368
|
+
let schema: string = node.def.formKey;
|
|
390
369
|
|
|
391
370
|
if (schema) {
|
|
392
371
|
return {
|
|
@@ -396,7 +375,7 @@ export class WorkflowService {
|
|
|
396
375
|
};
|
|
397
376
|
} else {
|
|
398
377
|
throw new InternalServerErrorException(
|
|
399
|
-
`Cannot resolve schema from invalid formKey '${
|
|
378
|
+
`Cannot resolve schema from invalid formKey '${schema}', example: 'jsonschema://SimpleApproveReject' or 'custom://your-custom-key'`,
|
|
400
379
|
);
|
|
401
380
|
}
|
|
402
381
|
} else {
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator.
|
|
3
|
+
* DONT CHANGE THIS FILE !!
|
|
4
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
5
|
+
* last change 2023-10-28
|
|
6
|
+
* Author: Ks Tan
|
|
7
|
+
*/
|
|
1
8
|
export type WorkflowSettingApiSchema = {
|
|
2
9
|
userServiceUrl: string;
|
|
3
10
|
callBackUrl?: string;
|
|
@@ -18,7 +18,14 @@ import { <%= obj.docname %>MongoSchema } from './generate/models/<%= obj.doctype
|
|
|
18
18
|
<%}%>
|
|
19
19
|
import { ProfileController } from './profile/profile.controller';
|
|
20
20
|
import { ProfileService } from './profile/profile.service';
|
|
21
|
-
|
|
21
|
+
import { WorkflowController } from './generate/workflow/workflow.controller';
|
|
22
|
+
import { WorkflowDelegate } from './generate/workflow/workflow.delegate';
|
|
23
|
+
import { WorkflowConfig } from './generate/workflow/workflow.config';
|
|
24
|
+
import { WorkflowService } from './generate/workflow/workflow.service';
|
|
25
|
+
<%for(let i=0; i<it.allbpmn.length;i++){%>
|
|
26
|
+
<%let bpmn = it.allbpmn[i]%>
|
|
27
|
+
import { <%=capitalizeFirstLetter(bpmn)%>DelegateService } from 'src/simpleapp/workflows/delegates/<%=bpmn%>.delegate';
|
|
28
|
+
<%}%>
|
|
22
29
|
// import {ServiceModule} from "../services/service.module"
|
|
23
30
|
//import { <%= it.typename %>Service } from '../../generate/<%= it.doctype %>/<%= it.doctype %>.service';
|
|
24
31
|
|
|
@@ -35,8 +42,14 @@ import { ProfileService } from './profile/profile.service';
|
|
|
35
42
|
<%}%>
|
|
36
43
|
]),
|
|
37
44
|
],
|
|
38
|
-
controllers: [<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Controller,<%}%> ProfileController,],
|
|
39
|
-
providers: [
|
|
40
|
-
|
|
45
|
+
controllers: [<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Controller,<%}%> ProfileController,WorkflowController],
|
|
46
|
+
providers: [
|
|
47
|
+
AuditTrail,DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Service,<%}%> ProfileService,WorkflowDelegate,WorkflowConfig,WorkflowService,
|
|
48
|
+
<%for(let i=0; i<it.allbpmn.length;i++){%>
|
|
49
|
+
<%let bpmn = it.allbpmn[i]%>
|
|
50
|
+
<%=capitalizeFirstLetter(bpmn)%>DelegateService,
|
|
51
|
+
<%}%>
|
|
52
|
+
],
|
|
53
|
+
exports:[AuditTrail,DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Service,<%}%> ProfileService,WorkflowDelegate,WorkflowConfig,WorkflowService]
|
|
41
54
|
})
|
|
42
55
|
export class GenerateModule {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
put bpmn files here.
|