-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathABFactoryCore.js
More file actions
1182 lines (1038 loc) · 34.6 KB
/
ABFactoryCore.js
File metadata and controls
1182 lines (1038 loc) · 34.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ABFactoryCore
* an object that contains the definitions and references for a single tenant.
* It is expected that an instance of this should be returned from an
* ABBootstrap.init(req).then((AB)=>{}) call.
*/
// const _ = require("lodash");
// const uuidv4 = require("uuid");
const ABClassManager = require("../platform/ABClassManager");
const ABApplication = require("../platform/ABApplication");
const ABApplicationMobile = require("../platform/ABApplicationMobile");
const ABDefinition = require("../platform/ABDefinition");
const ABComponent = require("../platform/ABComponent");
const ABFieldManager = require("./ABFieldManager");
const ABIndex = require("../platform/ABIndex");
const ABObject = require("../platform/ABObject");
const ABObjectExternal = require("../platform/ABObjectExternal");
const ABObjectImport = require("../platform/ABObjectImport");
const ABObjectApi = require("../platform/ABObjectApi");
const ABObjectApiNetsuite = require("../platform/ABObjectApiNetsuite");
const ABDataCollection = require("../platform/ABDataCollection");
const ABObjectQuery = require("../platform/ABObjectQuery");
const ABHint = require("../platform/ABHint");
const ABProcess = require("../platform/ABProcess");
const ABProcessParticipant = require("../platform/process/ABProcessParticipant");
const ABProcessLane = require("../platform/process/ABProcessLane");
const ABProcessTaskManager = require("./process/ABProcessTaskManager");
const ABStep = require("../platform/ABStep");
const ABViewDetailItem = require("../platform/views/ABViewDetailItem");
const ABViewFormItem = require("../platform/views/ABViewFormItem");
const ABMobileViewFormItem = require("../platform/mobile/ABMobileViewFormItem");
// const ABObjectWorkspaceViewGrid = require("../platform/workspaceViews/ABObjectWorkspaceViewGrid");
// const ABObjectWorkspaceViewKanban = require("../platform/workspaceViews/ABObjectWorkspaceViewKanban");
// const ABObjectWorkspaceViewGantt = require("../platform/workspaceViews/ABObjectWorkspaceViewGantt");
const RowFilter = require("../platform/RowFilter");
const FilterComplex = require("../platform/FilterComplex");
const ABMLClass = require("../platform/ABMLClass");
const EventEmitter = require("../platform/ABEmitter");
class ABFactory extends EventEmitter {
constructor(definitions) {
/**
* @param {hash} definitions
* { ABDefinition.id : {ABDefinition} }
* of all the definitions defined for the current Tenant
*/
super();
this.setMaxListeners(0);
this._definitions = definitions || {};
// {hash} { ABDefinition.id : {ABDefinition} }
// ensure ._definitions is a HASH{ ID : {ABDefinition}}
if (Array.isArray(definitions)) {
var hash = {};
definitions.forEach((d) => {
hash[d.id] = d;
});
this._definitions = hash;
}
//
//
// Manage our working objects
//
this._allApplications = [];
// {array} of all the ABApplication(s) in our site.
this._allObjects = [];
// {array} of all the ABObject(s) in our site.
this._allHints = [];
// {array} of all the ABHint(s) in our site.
this._allProcesses = [];
// {array} of all the ABProcess(s) in our site.
this._allQueries = [];
// {array} of all the ABObjectQuery(s) in our site.
this._allSteps = [];
// {array} of all the ABStep(s) in our site.
this._allDatacollections = [];
// {array} of all the ABDataCollection(s) in our site.
this.ClassManager = ABClassManager;
// {ClassManager} the single source for our Class Libraries.
//
// Class References
//
this.Class = {
ABApplication,
ABComponent,
ABDefinition,
ABFieldManager,
ABIndex,
ABMLClass,
ABObject,
ABObjectExternal,
ABObjectImport,
ABObjectApi,
ABObjectApiNetsuite,
ABObjectQuery,
ABProcessParticipant,
// ABRole // Do we need this anymore?
// ABObjectWorkspaceViewGrid,
// ABObjectWorkspaceViewKanban,
// ABObjectWorkspaceViewGantt,
ABProcessTaskManager,
ABViewDetailItem,
ABViewFormItem,
ABMobileViewFormItem,
};
//
// Rules
// These are a common set of "rules" for all platforms.
//
this.rules = {
/**
* @method AB.rules.isUUID
* evaluate a given value to see if it matches the format of a uuid
* @param {string} key
* @return {boolean}
*/
isUUID: function (key) {
var checker = RegExp(
"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",
"i"
);
return checker.test(key);
},
/**
* @method AB.rules.nameFilter()
* return a properly formatted name for an AppBuilder object.
* @param {string} name
* The name of the object we are conditioning.
* @return {string}
*/
nameFilter: function (name) {
return String(name).replace(/[^a-z0-9_.]/gi, "");
},
/**
* @method AB.rules.toApplicationNameFormat()
* return a properly formatted Application Name
* @param {string} name
* The name of the Application we are conditioning.
* @return {string}
*/
toApplicationNameFormat: function (name) {
return "AB_" + this.nameFilter(name);
},
/**
* @method AB.rules.toFieldRelationFormat()
* This function uses for define relation name of Knex Objection
* return a relation name of column
* @param {string} colName
* The name of the Column
* @return {string}
*/
toFieldRelationFormat: function (colName) {
return this.nameFilter(colName) + "__relation";
},
/**
* @method AB.rules.toJunctionTableFK()
* return foriegnkey (FK) column name for a junction table name
* @param {string} objectName
* The name of the Object with a connection
* @param {string} columnName
* The name of the connection columnName.
* @return {string}
*/
toJunctionTableFK: function (objectName, columnName) {
var fkName = objectName + "_" + columnName;
if (fkName.length > 64) fkName = fkName.substring(0, 64);
return fkName;
},
/**
* @method AB.rules.toJunctionTableNameFormat()
* return many-to-many junction table name
* @param {string} appName
* The name of the Application for this object
* @param {string} sourceTableName
* The name of the source object we are conditioning.
* @param {string} targetTableName
* The name of the target object we are conditioning.
* @param {string} colName
* @return {string}
*/
toJunctionTableNameFormat: function (
appName,
sourceTableName,
targetTableName,
colName
) {
// The maximum length of a table name in MySql is 64 characters
appName = this.toApplicationNameFormat(appName);
if (appName.length > 17) appName = appName.substring(0, 17);
if (sourceTableName.length > 15)
sourceTableName = sourceTableName.substring(0, 15);
if (targetTableName.length > 15)
targetTableName = targetTableName.substring(0, 15);
colName = this.nameFilter(colName);
if (colName.length > 14) colName = colName.substring(0, 14);
return "{appName}_{sourceName}_{targetName}_{colName}"
.replace("{appName}", appName)
.replace("{sourceName}", sourceTableName)
.replace("{targetName}", targetTableName)
.replace("{colName}", colName);
},
/**
* @method AB.rules.toObjectNameFormat
* return a properly formatted Object/Table Name
* @param {string} objectName
* The {ABObject}.name of the Object we are conditioning.
* @return {string}
*/
toObjectNameFormat: function (objectName) {
return `AB_${this.nameFilter(objectName)}`;
},
};
// Notify Helpers
this.notify.builder = (...params) => {
this.notify("builder", ...params);
};
this.notify.developer = (...params) => {
this.notify("developer", ...params);
};
}
/**
* @method definitionClean()
* make sure the provided ABDefinition values are properly formatted
* @param {ABDefinition} d
* The json settings of an ABDefinition object.
*/
definitionClean(d) {
if (typeof d.json == "string") {
try {
d.json = JSON.parse(d.json);
} catch (e) {
console.log(e);
console.error(` Error on definition id[${d.id}]`);
}
}
}
async init() {
// BEFORE Definitions are loaded,
// make sure any local Plugins are loaded.
// this.ClassManager.registerLocalPlugins(this.pluginAPI());
await this.pluginLocalLoad();
let allDefinitions = Object.keys(this._definitions).map(
(k) => this._definitions[k]
);
// {array} all our definitions in an Array format.
// make sure our definitions.json field is an {} and not string
allDefinitions.forEach((d) => {
this.definitionClean(d);
});
// perform these in order:
[
"object",
"query",
"datacollection",
"process",
"hint",
"step",
"application",
].forEach((type) => {
var objTypes = allDefinitions.filter((d) => d.type == type);
objTypes.forEach((def) => {
let { keyList, keyFn } = this.objectKeysByDef(def);
if (keyList) {
this[keyList].push(this[keyFn](def.json));
}
});
});
this.emit("init.objects_ready");
return Promise.resolve();
}
/**
* @method objectKeysByDef()
* Analyze the provided ABDefinition json and return which set of list and
* functions are used to create a new instance of this definition.
* @param {json} def
* the ABDefinition json of the definition we are evaluating
* @return { keyList, keyFn }
* keyList: {string} which of our internal lists to store this new
* object.
* keyFn: {string} which of our methods to call with the def.json
* as the param that will create the new object.
*
* ex: this[keyList].push( this[keyFn](def.json));
*
* if this def is not one of the types we track,
* keyList = keyFn = null;
*/
objectKeysByDef(def) {
switch (def.type) {
case "application":
return { keyList: "_allApplications", keyFn: "applicationNew" };
case "datacollection":
return {
keyList: "_allDatacollections",
keyFn: "datacollectionNew",
};
case "hint":
return { keyList: "_allHints", keyFn: "hintNew" };
case "steps":
return { keyList: "_allSteps", keyFn: "stepNew" };
case "object":
return { keyList: "_allObjects", keyFn: "objectNew" };
case "process":
return { keyList: "_allProcesses", keyFn: "processNew" };
case "query":
return { keyList: "_allQueries", keyFn: "queryNew" };
default:
// we don't manage any other
return { keyList: null, keyFn: null };
}
}
//
// Definitions
//
/**
* definitionByID(id)
* return an ABDefinition.json value ready for our objects to use.
* @param {string} id
* the uuid of the ABDefinition to delete
* @param {bool} isRaw
* indicates if we want the full ABDefinition, or the .json param
* true : returns full ABDefinition value.
* false: returns the .json parameter used by most ABObjects.
* @return {Promise}
*/
definitionByID(id, isRaw = false) {
if (this._definitions[id]) {
if (isRaw) {
return this._definitions[id];
} else {
return this._definitions[id].json;
}
}
return null;
}
/**
* definitionNew(values)
* return an ABDefinition object tied to this Tenant.
* @param {obj} values
* The value hash of the ABDefinition object to create.
* @return {ABDefinition}
*/
definitionNew(values) {
return new ABDefinition(values, this);
}
/**
* definitionsParse()
* include the incoming definitions into our ABFactory. These new
* definitions will replace any existing ones with the same .id.
* @param {array[ABDefinitioin]} defs
* the incoming array of ABDefinitions to parse.
* @return {Promise}
*/
definitionsParse(defs = []) {
if (!Array.isArray(defs)) {
defs = [defs];
}
// store/replace the incoming definitions
// 1st: insert ALL our definitions internally
defs.forEach((d) => {
this.definitionClean(d);
this._definitions[d.id] = d;
});
// 2nd: Now we can then go through and signal the "updates"
// and the related objects can find their dependent definitions.
defs.forEach((d) => {
this.definitionSync("updated", d.id, d);
});
return Promise.resolve();
}
/**
* definitionSync()
* Synchronize an individual definition into our repository of definitions.
* @param {string} op
* the type of synchronization this is
* [ "created", "updated", "destroyed"]
* @param {uuid} id
* the definition.id of the definition we are synchronizing
* @param {json} def
* the ABDefinition attributes we are storing.
*/
definitionSync(op, id, def) {
var { keyList, keyFn } = this.objectKeysByDef(def);
if (keyList) {
var curr;
switch (op) {
case "created":
this[keyList].push(this[keyFn](def.json));
this.emit("definition.created", def.json);
break;
case "updated":
// get the current object
curr = this[keyList].find((d) => d.id == id);
// remove from list
this[keyList] = this[keyList].filter((d) => d.id != id);
// add new one:
this[keyList].push(this[keyFn](def.json));
// signal this object needs to be updated:
// NOTE: if this is one of the objects we are tracking,
// we don't need to this.emit() the message.
if (curr) {
curr.emit("definition.updated", def.json);
} else {
this.emit("definition.updated", def.json);
}
break;
case "destroyed":
// get the current object
curr = this[keyList].find((d) => d.id == id);
if (curr) {
// remove from list
this[keyList] = this[keyList].filter((d) => d.id != id);
// signal this object needs to be updated:
curr.emit("definition.deleted", def.json);
this.emit("definition.deleted", def.json);
}
break;
}
}
}
//
// ABObjects
//
/**
* @method applications()
* return all the ABApplications that match the provided filter.
* @param {fn} fn
* A filter function to select specific ABApplications.
* Must return true to include the entry.
* @return {array}
*/
applications(fn = () => true) {
return (this._allApplications || []).filter(fn);
}
/**
* @method applicationByID()
* returns a single ABApplication that matches the given ID.
* @param {string} ID
* the .id/.name/.label of the ABApplication we are searching
* for.
* @return {ABApplication}
* the matching ABApplication object if found
* {null} if not found.
*/
applicationByID(ID) {
return this.applications((a) => a.id == ID)[0];
}
/**
* @method applicationNew()
* Return a new instance of an ABApplication object.
* @param {json} values
* the ABDefinition.json of the ABApplication object we are
* creating.
* @return {ABApplication}
*/
applicationNew(values) {
// just in case we got here by mistake:
if (values.appType == "mobile") {
return this.applicationMobileNew(values);
}
return new ABApplication(values, this);
}
/**
* @method applicationMobileNew()
* Return a new instance of an ABApplicationMobile object.
* @param {json} values
* the ABDefinition.json of the ABApplicationMobile object we are
* creating.
* @return {ABApplicationMobile}
*/
applicationMobileNew(values) {
return new ABApplicationMobile(values, this);
}
/**
* @method datacollections()
* return an array of all the ABDataCollection for this ABApplication.
* @param {fn} filter
* a filter fn to return a set of ABDataCollection that
* this fn returns true for.
* @return {array}
* array of ABDataCollection
*/
datacollections(filter = () => true) {
return (this._allDatacollections || []).filter(filter);
}
/**
* @method datacollectionByID()
* returns a single ABDatacollection that matches the given ID.
* @param {string} ID
* the .id/.name/.label of the ABDatacollection we are searching
* for.
* @return {ABDatacollection}
* the matching ABDatacollection object if found
* {null} if not found.
*/
datacollectionByID(ID) {
// an undefined or null ID should not match any DC.
if (!ID) return null;
return this.datacollections((dc) => {
return dc.id == ID || dc.name == ID || dc.label == ID;
})[0];
}
/**
* @method datacollectionNew()
* create a new instance of ABDataCollection
* @param {obj} values
* the initial values for the DC
* @return {ABDatacollection}
*/
datacollectionNew(values) {
var dc = new ABDataCollection(values, this);
dc.on("destroyed", () => {
// make sure it is no longer in our internal list
this._allDatacollections = this._allDatacollections.filter(
(d) => d.id != dc.id
);
});
return dc;
}
/**
* @method fieldNew()
* return an instance of a new (unsaved) ABField that is tied to a given
* ABObject.
* NOTE: this new field is not included in our this.fields until a .save()
* is performed on the field.
* @param {obj} values the initial values for this field.
* - { key:'{string}'} is required
* @param {ABObject} object the parent object this field belongs to.
* @return {ABField}
*/
fieldNew(values, object) {
// NOTE: ABFieldManager returns the proper ABFieldXXXX instance.
return ABFieldManager.newField(values, object);
}
/**
* @method indexNew()
* return an instance of a new (unsaved) ABIndex.
* @return {ABIndex}
*/
indexNew(values, object) {
return new ABIndex(values, object);
}
/**
* @method Label()
* a simple label factory.
* It is expected to be called like this:
* @codestart
* var L = AB.Label();
* var outputText = L("Hello World");
* var o2 = L("I'm {0} years old", [5]);
* @codeend
* @return {fn}
*/
Label() {
return (key, altText, values = []) => {
var label = key;
if (altText) {
if (Array.isArray(altText)) {
values = altText;
} else {
label = altText;
}
}
values.forEach((v, i) => {
var sub = `{${i}}`;
label = label.replaceAll(sub, v);
});
return label;
};
}
/**
* @method objects()
* return an array of all the ABObjects for this ABApplication.
* @param {fn} filter
* a filter fn to return a set of ABObjects that this fn
* returns true for.
* @return {array}
* array of ABObject
*/
objects(filter = () => true) {
return (this._allObjects || []).filter(filter);
}
/**
* @method objectByID()
* return the specific object requested by the provided id.
* @param {string} ID
* @return {obj}
*/
objectByID(ID) {
return this.objects((o) => {
return o.id == ID || o.name == ID || o.label == ID;
})[0];
}
/**
* @method objectNew()
* return an instance of a new (unsaved) ABObject that is tied to this
* ABApplication.
* NOTE: this new object is not included in our this.objects until a .save()
* is performed on the object.
* @return {ABObject}
*/
objectNew(values) {
var newObj = null;
if (values.plugin_key) {
// If this is from a plugin, create it from ClassManager
newObj = this.ClassManager.createObject(
values.plugin_key,
values,
this
);
} else if (values.isExternal == true)
newObj = new ABObjectExternal(values, this);
else if (values.isImported == true)
newObj = new ABObjectImport(values, this);
else if (values.isNetsuite == true) {
newObj = new ABObjectApiNetsuite(values, this);
} else if (values.isAPI == true) newObj = new ABObjectApi(values, this);
else newObj = new ABObject(values, this);
/*
// IS THIS CORRECT?
newObj.on("destroyed", () => {
// make sure it is no longer in our internal list
this._allObjects = this._allObjects.filter((o) => o.id != newObj.id);
});
*/
return newObj;
}
objectFile() {
return this.objectByID("4a9d89c9-f4eb-41af-91e4-909eff389f3e");
}
objectLanguage() {
return this.objectByID("d84cd351-d96c-490f-9afb-2a0b880ca0ec");
}
objectPlugin() {
return this.objectByID("8a20528a-e472-4e80-911a-b14285425caf");
}
objectPluginLinks() {
return this.objectByID("7ff322ff-3434-4611-9fd1-4d2996414c1a");
}
objectProcessDefinition() {
return this.objectByID("af91fc75-fb73-4d71-af14-e22832eb5915");
}
objectProcessForm() {
return this.objectByID("d36ae4c8-edef-48d8-bd9c-79a0edcaa067");
}
objectProcessInstance() {
return this.objectByID("2ba85be0-78db-4eda-ba43-c2c4e3831849");
}
objectRole() {
return this.objectByID("c33692f3-26b7-4af3-a02e-139fb519296d");
}
objectScope() {
return this.objectByID("af10e37c-9b3a-4dc6-a52a-85d52320b659");
}
objectToken() {
return this.objectByID("08826ac7-4b33-4745-a3d7-f7831ca4ff59");
}
objectUser() {
return this.objectByID("228e3d91-5e42-49ec-b37c-59323ae433a1");
}
objectKey() {
return this.objectByID("d734fe8c-b615-446c-8a5f-793ddece19f9");
}
objectSecret() {
return this.objectByID("db5b3b26-5300-4c92-bc73-8ce4f4696992");
}
//
// Plugin
//
pluginAPI() {
let api = this.ClassManager.getPluginAPI();
api.AB = this;
api.platform = this.platform ?? "service";
return api;
}
pluginLocalLoad() {
// This is a placeholder for a local plugin load.
// The platform version of this method will load the plugins from
// /platform/plugins/local/
return Promise.resolve();
}
pluginRegister(plugin) {
let pluginClass = plugin(this.pluginAPI());
if (Array.isArray(pluginClass)) {
pluginClass.forEach((p) => {
this.ClassManager.pluginRegister(p);
});
} else {
this.ClassManager.pluginRegister(pluginClass);
}
}
//
// Hints
//
/**
* @method hints()
* return all the ABHints that match the provided filter.
* @param {fn} fn
* A filter function to select specific ABHints.
* Must return true to include the entry.
* @return {array}
*/
hints(filter = () => true) {
return (this._allHints || []).filter(filter);
}
/**
* @method hintByID()
* return the specific hint requested by the provided id.
* @param {string} ID
* @return {obj}
*/
hintID(ID) {
return this.hints((h) => {
return h.id == ID || h.name == ID || h.label == ID;
})[0];
}
/**
* @method hintNew()
* return an instance of a new (unsaved) ABHint that is tied to this
* ABApplication.
* NOTE: this new hint is not included in our this.hints until a .save()
* is performed on the object.
* @return {ABHint}
*/
hintNew(values) {
var newHint = new ABHint(values, this);
return newHint;
}
//
// Steps
//
/**
* @method steps()
* return all the ABSteps that match the provided filter.
* @param {fn} fn
* A filter function to select specific ABSteps.
* Must return true to include the entry.
* @return {array}
*/
steps(filter = () => true) {
return (this._allSteps || []).filter(filter);
}
/**
* @method stepByID()
* return the specific step requested by the provided id.
* @param {string} ID
* @return {obj}
*/
stepID(ID) {
return this.steps((s) => {
return s.id == ID || s.name == ID || s.label == ID;
})[0];
}
/**
* @method stepNew()
* return an instance of a new (unsaved) ABStep that is tied to this
* ABApplication.
* NOTE: this new step is not included in our this.steps until a .save()
* is performed on the object.
* @return {ABHint}
*/
stepNew(id, hintID) {
var stepDef = this.definitionByID(id);
if (stepDef) {
var getStep = new ABStep(stepDef, this);
return getStep;
} else {
var params = {
settings: {
hint: hintID,
},
};
var newStep = new ABStep(params, this);
return newStep;
}
// return null;
}
//
// Processes
//
/**
* @method processes()
* return all the ABProcess that match the provided filter.
* @param {fn} fn
* A filter function to select specific ABProcess.
* Must return true to include the entry.
* @return {array}
*/
processes(filter = () => true) {
return (this._allProcesses || []).filter(filter);
}
/**
* @method processByID()
* return the specific process requested by the provided id.
* @param {string} ID
* @return {obj}
*/
processByID(ID) {
return this.processes((p) => {
return p.id == ID || p.name == ID || p.label == ID;
})[0];
}
/**
* @method processNew()
* Return a new instance of an ABProcess object.
* @param {json} values
* the ABDefinition.json of the ABProcess object we are
* creating.
* @return {ABProcess}
*/
processNew(values) {
return new ABProcess(values, this);
}
/**
* @method processElementNew(id)
* return an instance of a new ABProcessOBJ that is tied to a given
* ABProcess.
* @param {string} id
* the ABDefinition.id of the element we are creating
* @param {ABProcess} process
* the process this task is a part of.
* @return {ABProcessTask}
*/
processElementNew(id, process) {
var taskDef = this.definitionByID(id);
if (taskDef) {
switch (taskDef.type) {
case ABProcessParticipant.defaults().type:
return new ABProcessParticipant(taskDef, process, this);
// break;
case ABProcessLane.defaults().type:
return new ABProcessLane(taskDef, process, this);
// break;
default:
// default to a Task
return ABProcessTaskManager.newTask(taskDef, process, this);
// break;
}
}
return null;
}
/**
* @method processElementNewForModelDefinition(def)
*
* return an instance of a new ABProcess[OBJ] that is tied to the given
* BPMI:Element definition.
*
* @param {BPMI:Element} element the element definition from our BPMI
* modler.
* @return {ABProcess[OBJ]}
*/
processElementNewForModelDefinition(element, process) {
var newElement = null;
switch (element.type) {
case "bpmn:Participant":
newElement = new ABProcessParticipant({}, process, this);
break;
case "bpmn:Lane":
newElement = new ABProcessLane({}, process, this);
break;
default:
var defaultDef = ABProcessTaskManager.definitionForElement(element);
if (defaultDef) {
newElement = ABProcessTaskManager.newTask(
defaultDef,
process,
this
);
}
break;
}
// now make sure this new Obj pulls any relevant info from the
// diagram element
if (newElement) {
newElement.fromElement(element);
}