/
AsyncPackageDataModelOracleImpl.java
1400 lines (1189 loc) · 58.2 KB
/
AsyncPackageDataModelOracleImpl.java
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
/*
* Copyright 2013 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.workbench.common.widgets.client.datamodel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import org.drools.workbench.models.datamodel.imports.Imports;
import org.drools.workbench.models.datamodel.oracle.Annotation;
import org.drools.workbench.models.datamodel.oracle.DataType;
import org.drools.workbench.models.datamodel.oracle.DropDownData;
import org.drools.workbench.models.datamodel.oracle.FieldAccessorsAndMutators;
import org.drools.workbench.models.datamodel.oracle.MethodInfo;
import org.drools.workbench.models.datamodel.oracle.ModelField;
import org.drools.workbench.models.datamodel.oracle.OperatorsOracle;
import org.drools.workbench.models.datamodel.oracle.TypeSource;
import org.drools.workbench.models.datamodel.rule.DSLSentence;
import org.jboss.errai.common.client.api.Caller;
import org.jboss.errai.common.client.api.RemoteCallback;
import org.kie.workbench.common.services.datamodel.model.LazyModelField;
import org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleIncrementalPayload;
import org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService;
import org.uberfire.backend.vfs.Path;
import org.uberfire.client.callbacks.Callback;
import org.uberfire.commons.validation.PortablePreconditions;
/**
* Default implementation of DataModelOracle
*/
@Dependent
public class AsyncPackageDataModelOracleImpl implements AsyncPackageDataModelOracle {
@Inject
protected Caller<IncrementalDataModelService> service;
//Path that this DMO is coupled to
private Path resourcePath;
//Project name
protected String projectName;
//Package for which this DMO relates
private String packageName = "";
//Imports from the Project into this Package
private Imports imports = new Imports();
// List of available package names
private List<String> packageNames = new ArrayList<String>();
// ####################################
// Project Scope
// ####################################
//Fact Types and their corresponding fields
protected Map<String, ModelField[]> projectModelFields = new HashMap<String, ModelField[]>();
//Map of the field that contains the parametrized type of a collection
//for example given "List<String> name", key = "name" value = "String"
protected Map<String, String> projectFieldParametersType = new HashMap<String, String>();
//Map {factType, isEvent} to determine which Fact Type can be treated as events.
protected Map<String, Boolean> projectEventTypes = new HashMap<String, Boolean>();
//Map {factType, TypeSource} to determine where a Fact Type as defined.
protected Map<String, TypeSource> projectTypeSources = new HashMap<String, TypeSource>();
//Map {factType, superType} to determine the Super Type of a FactType.
protected Map<String, List<String>> projectSuperTypes = new HashMap<String, List<String>>();
//Map {factType, Set<Annotation>} containing the FactType's annotations.
protected Map<String, Set<Annotation>> projectTypeAnnotations = new HashMap<String, Set<Annotation>>();
//Map {factType, Map<fieldName, Set<Annotation>>} containing the FactType's Field annotations.
protected Map<String, Map<String, Set<Annotation>>> projectTypeFieldsAnnotations = new HashMap<String, Map<String, Set<Annotation>>>();
// Scoped (current package and imports) map of { TypeName.field : String[] } - where a list is valid values to display in a drop down for a given Type.field combination.
protected Map<String, String[]> projectJavaEnumLists = new HashMap<String, String[]>();
//Method information used (exclusively) by ExpressionWidget and ActionCallMethodWidget
protected Map<String, List<MethodInfo>> projectMethodInformation = new HashMap<String, List<MethodInfo>>();
// A map of FactTypes {factType, isCollection} to determine which Fact Types are Collections.
protected Map<String, Boolean> projectCollectionTypes = new HashMap<String, Boolean>();
// ####################################
// Package Scope
// ####################################
// Filtered (current package and imports) Fact Types and their corresponding fields
private Map<String, ModelField[]> filteredModelFields = new HashMap<String, ModelField[]>();
// Filtered (current package and imports) map of the field that contains the parametrized type of a collection
// for example given "List<String> name", key = "name" value = "String"
private Map<String, String> filteredFieldParametersType = new HashMap<String, String>();
// Filtered (current package and imports) map of { TypeName.field : String[] } - where a list is valid values to display in a drop down for a given Type.field combination.
private Map<String, String[]> filteredEnumLists = new HashMap<String, String[]>();
// Filtered (current package and imports) Map {factType, isEvent} to determine which Fact Type can be treated as events.
private Map<String, Boolean> filteredEventTypes = new HashMap<String, Boolean>();
// Filtered (current package and imports) Map {factType, isCollection} to determine which Fact Types are Collections.
private Map<String, Boolean> filteredCollectionTypes = new HashMap<String, Boolean>();
// Filtered (current package and imports) Map {factType, TypeSource} to determine where a Fact Type as defined.
private Map<String, TypeSource> filteredTypeSources = new HashMap<String, TypeSource>();
// Filtered (current package and imports) Map {factType, superType} to determine the Super Type of a FactType.
protected Map<String, List<String>> filteredSuperTypes = new HashMap<String, List<String>>();
// Filtered (current package and imports) Map {factType, Set<Annotation>} containing the FactType's annotations.
protected Map<String, Set<Annotation>> filteredTypeAnnotations = new HashMap<String, Set<Annotation>>();
// Filtered (current package and imports) Map {factType, {fieldName, Set<Annotation>}} containing the FactType's Fields annotations.
protected Map<String, Map<String, Set<Annotation>>> filteredTypeFieldsAnnotations = new HashMap<String, Map<String, Set<Annotation>>>();
// Filtered (current package and imports) map of Globals {alias, class name}.
private Map<String, String> filteredGlobalTypes = new HashMap<String, String>();
// Package-level enumeration definitions derived from "Workbench" enumerations.
private Map<String, String[]> packageWorkbenchEnumLists = new HashMap<String, String[]>();
// Package-level DSL language extensions.
private List<DSLSentence> packageDSLConditionSentences = new ArrayList<DSLSentence>();
private List<DSLSentence> packageDSLActionSentences = new ArrayList<DSLSentence>();
// Package-level map of Globals {alias, class name}.
private Map<String, String> packageGlobalTypes = new HashMap<String, String>();
// This is used to calculate what fields an enum list may depend on.
private transient Map<String, Object> enumLookupFields;
// Keep the link between fact name and the full qualified class name inside the package
private FactNameToFQCNHandleRegistry factNameToFQCNHandleRegistry = new FactNameToFQCNHandleRegistry();
//Public constructor is needed for Errai Marshaller :(
public AsyncPackageDataModelOracleImpl() {
}
@Override
public void init( final Path resourcePath ) {
this.resourcePath = PortablePreconditions.checkNotNull( "resourcePath",
resourcePath );
}
// ####################################
// Packages
// ####################################
@Override
public List<String> getPackageNames() {
return packageNames;
}
// ####################################
// Fact Types
// ####################################
/**
* Returns fact types available for rule authoring, i.e. those within the same package and those that have been imported.
* @return
*/
@Override
public String[] getFactTypes() {
final String[] types = filteredModelFields.keySet().toArray( new String[ filteredModelFields.size() ] );
Arrays.sort( types );
return types;
}
/**
* Return all fact types available to the project, i.e. everything type defined within the project or externally imported
* @return
*/
@Override
public String[] getAllFactTypes() {
final List<String> types = new ArrayList<String>();
types.addAll( this.projectModelFields.keySet() );
final String[] result = new String[ types.size() ];
types.toArray( result );
Arrays.sort( result );
return result;
}
/**
* Return all fact types that are external to the package, i.e. they need to be imported to be used
* @return
*/
@Override
public String[] getExternalFactTypes() {
final String[] allTypes = getAllFactTypes();
final List<String> externalTypes = new ArrayList<String>();
for ( String type : allTypes ) {
final String packageName = AsyncPackageDataModelOracleUtilities.getPackageName( type );
if ( !packageName.equals( this.packageName ) ) {
externalTypes.add( type );
}
}
final String[] result = new String[ externalTypes.size() ];
externalTypes.toArray( result );
Arrays.sort( result );
return result;
}
public String getFQCNByFactName(String factName) {
if (factName.contains(".")) {
return factName;
} else {
return factNameToFQCNHandleRegistry.get(factName);
}
}
/**
* Returns fact's name from type
*
* @param type for example org.test.Person or Person
* @return Shorter type name Person, not org.test.Person
*/
@Override
public String getFactNameFromType( final String type ) {
if ( type == null || type.isEmpty() ) {
return null;
}
if ( filteredModelFields.containsKey( type ) ) {
return type;
}
for ( Map.Entry<String, ModelField[]> entry : filteredModelFields.entrySet() ) {
for ( ModelField mf : entry.getValue() ) {
if ( DataType.TYPE_THIS.equals( mf.getName() ) && type.equals( mf.getClassName() ) ) {
return entry.getKey();
}
}
}
String fgcnByFactName = getFQCNByFactName(type);
if(projectModelFields.containsKey(fgcnByFactName)){
return AsyncPackageDataModelOracleUtilities.getTypeName(fgcnByFactName);
}
return null;
}
/**
* Is the Fact Type known to the DataModelOracle
* @param factType
* @return
*/
@Override
public boolean isFactTypeRecognized( final String factType ) {
return filteredModelFields.containsKey( factType );
}
/**
* Check whether a given FactType is an Event for CEP purposes
* @param factType
* @return
*/
@Override
public void isFactTypeAnEvent( final String factType,
final Callback<Boolean> callback ) {
if ( factType == null || factType.isEmpty() ) {
callback.callback( false );
return;
}
final Boolean isFactTypeAnEvent = filteredEventTypes.get( factType );
//Load incremental content
if ( isFactTypeAnEvent == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
Boolean isFactTypeAnEvent = filteredEventTypes.get( factType );
if ( isFactTypeAnEvent == null ) {
isFactTypeAnEvent = false;
filteredEventTypes.put( factType,
isFactTypeAnEvent );
}
callback.callback( isFactTypeAnEvent );
}
} ).getUpdates( resourcePath,
imports,
factType );
} else {
callback.callback( isFactTypeAnEvent );
}
}
/**
* Return where a given FactType was defined
* @param factType
* @return
*/
@Override
public void getTypeSource( final String factType,
final Callback<TypeSource> callback ) {
final TypeSource typeSource = filteredTypeSources.get( factType );
//Load incremental content
if ( typeSource == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
final TypeSource typeSource = filteredTypeSources.get( factType );
callback.callback( typeSource );
}
} ).getUpdates( resourcePath,
imports,
factType );
} else {
callback.callback( typeSource );
}
}
/**
* Get the Super Type for a given FactType
* @param factType
* @return null if no Super Type
*/
@Override
public void getSuperType( final String factType,
final Callback<String> callback ) {
getSuperTypes(factType, new Callback<List<String>>() {
@Override
public void callback(List<String> result) {
if (result != null) {
callback.callback(result.get(0));
} else {
callback.callback(null);
}
}
});
}
@Override
public void getSuperTypes( final String factType,
final Callback<List<String>> callback) {
final List<String> superTypes = filteredSuperTypes.get(factType);
//Load incremental content
if ( superTypes == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
callback.callback( filteredSuperTypes.get( factType ) );
}
} ).getUpdates( resourcePath,
imports,
factType );
} else {
callback.callback( superTypes );
}
}
/**
* Get the Annotations for a given FactType
* @param factType
* @return Empty set if no annotations exist for the type
*/
@Override
public void getTypeAnnotations( final String factType,
final Callback<Set<Annotation>> callback ) {
final Set<Annotation> typeAnnotations = filteredTypeAnnotations.get( factType );
//Load incremental content
if ( typeAnnotations == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
Set<Annotation> typeAnnotations = filteredTypeAnnotations.get( factType );
if ( typeAnnotations == null ) {
typeAnnotations = Collections.EMPTY_SET;
filteredTypeAnnotations.put( factType,
typeAnnotations );
}
callback.callback( typeAnnotations );
}
} ).getUpdates( resourcePath,
imports,
factType );
} else {
callback.callback( typeAnnotations );
}
}
/**
* Get the Fields Annotations for a given FactType
* @param factType
* @return Empty Map if no annotations exist for the type
*/
@Override
public void getTypeFieldsAnnotations( final String factType,
final Callback<Map<String, Set<Annotation>>> callback ) {
final Map<String, Set<Annotation>> typeFieldsAnnotations = filteredTypeFieldsAnnotations.get( factType );
//Load incremental content
if ( typeFieldsAnnotations == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
Map<String, Set<Annotation>> typeFieldsAnnotations = filteredTypeFieldsAnnotations.get( factType );
if ( typeFieldsAnnotations == null ) {
typeFieldsAnnotations = Collections.EMPTY_MAP;
filteredTypeFieldsAnnotations.put( factType,
typeFieldsAnnotations );
}
callback.callback( typeFieldsAnnotations );
}
} ).getUpdates( resourcePath,
imports,
factType );
} else {
callback.callback( typeFieldsAnnotations );
}
}
// ####################################
// Fact Types' Fields
// ####################################
@Override
public void getFieldCompletions( final String factType,
final Callback<ModelField[]> callback ) {
ModelField[] fields = getModelFields( factType );
final String factTypeName;
if (getFQCNByFactName(factType) != null) {
factTypeName = getFQCNByFactName(factType);
} else {
factTypeName = factType;
}
if (fields == null || fields.length == 0) {
fields = projectModelFields.get(factTypeName);
if (fields == null || isLazyProxy(fields)) {
fields = null;
} else {
AsyncPackageDataModelOracleUtilities.correctModelFields(packageName, fields, imports);
}
}
//Load incremental content
if ( fields == null || fields.length == 0 ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback(final PackageDataModelOracleIncrementalPayload dataModel) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle(
AsyncPackageDataModelOracleImpl.this,
dataModel);
// This will stop an infinite loop if there are no fields to be found
if (dataModel.getModelFields().get(factTypeName) == null || dataModel.getModelFields().get(factTypeName).length == 0) {
callback.callback(new ModelField[0]);
} else {
getFieldCompletions(factType, callback);
}
}
}).getUpdates( resourcePath,
imports,
factTypeName);
} else {
callback.callback(fields);
}
}
private ModelField[] getModelFields( final String modelClassName ) {
final String shortName = getFactNameFromType( modelClassName );
if ( !filteredModelFields.containsKey( shortName ) ) {
return new ModelField[ 0 ];
}
//If fields do not exist return null; so they can be incrementally loaded
final ModelField[] fields = filteredModelFields.get( shortName );
if ( isLazyProxy( fields ) ) {
return null;
}
//Otherwise return existing fields
return fields;
}
@Override
public void getFieldCompletions(
final String factType,
final FieldAccessorsAndMutators accessorOrMutator,
final Callback<ModelField[]> callback) {
getFieldCompletions(factType, new Callback<ModelField[]>() {
@Override
public void callback(ModelField[] fields) {
ArrayList<ModelField> result = new ArrayList<ModelField>();
for (ModelField field : fields) {
if (FieldAccessorsAndMutators.compare(accessorOrMutator, field.getAccessorsAndMutators())) {
result.add(field);
}
}
callback.callback(result.toArray(new ModelField[result.size()]));
}
});
}
//Check whether the ModelField[] is a place-holder for more information
private boolean isLazyProxy( final ModelField[] modelFields ) {
if ( modelFields == null ) {
return false;
} else if ( modelFields.length != 1 ) {
return false;
}
return modelFields[ 0 ] instanceof LazyModelField;
}
@Override
public String getFieldType( final String modelClassName,
final String fieldName ) {
final ModelField field = getField( modelClassName,
fieldName );
return field == null ? null : field.getType();
}
@Override
public String getFieldClassName( final String modelClassName,
final String fieldName ) {
final ModelField field = getField( modelClassName,
fieldName );
return field == null ? null : field.getClassName();
}
private ModelField getField( final String modelClassName,
final String fieldName ) {
final ModelField[] fields = projectModelFields.get( getFQCNByFactName( modelClassName ) );
if ( fields == null ) {
return null;
}
for ( ModelField modelField : fields ) {
if ( modelField.getName().equals( fieldName ) ) {
return AsyncPackageDataModelOracleUtilities.correctModelFields( packageName, imports, modelField );
}
}
return null;
}
/**
* Get the parametric type of a Field.
* @param factType
* @param fieldName
* @return
*/
@Override
public String getParametricFieldType( final String factType,
final String fieldName ) {
final String qualifiedFactFieldName = factType + "#" + fieldName;
return filteredFieldParametersType.get( qualifiedFactFieldName );
}
// ####################################
// Operators
// ####################################
/**
* Get the Operators applicable Base Constraints
* @param factType
* @param fieldName
* @return
*/
@Override
public void getOperatorCompletions( final String factType,
final String fieldName,
final Callback<String[]> callback ) {
final String fieldType = getFieldType( factType,
fieldName );
if ( fieldType == null ) {
callback.callback( OperatorsOracle.STANDARD_OPERATORS );
return;
} else if ( fieldName.equals( DataType.TYPE_THIS ) ) {
isFactTypeAnEvent( factType,
new Callback<Boolean>() {
@Override
public void callback( final Boolean isFactTypeAnEvent ) {
if ( Boolean.TRUE.equals( isFactTypeAnEvent ) ) {
callback.callback( OracleUtils.joinArrays( OperatorsOracle.STANDARD_OPERATORS,
OperatorsOracle.SIMPLE_CEP_OPERATORS,
OperatorsOracle.COMPLEX_CEP_OPERATORS ) );
return;
} else {
callback.callback( OperatorsOracle.STANDARD_OPERATORS );
return;
}
}
} );
} else if ( fieldType.equals( DataType.TYPE_STRING ) ) {
callback.callback( OracleUtils.joinArrays( OperatorsOracle.STRING_OPERATORS,
OperatorsOracle.EXPLICIT_LIST_OPERATORS ) );
return;
} else if ( DataType.isNumeric( fieldType ) ) {
callback.callback( OracleUtils.joinArrays( OperatorsOracle.COMPARABLE_OPERATORS,
OperatorsOracle.EXPLICIT_LIST_OPERATORS ) );
return;
} else if ( fieldType.equals( DataType.TYPE_DATE ) ) {
callback.callback( OracleUtils.joinArrays( OperatorsOracle.COMPARABLE_OPERATORS,
OperatorsOracle.EXPLICIT_LIST_OPERATORS,
OperatorsOracle.SIMPLE_CEP_OPERATORS ) );
return;
} else if ( fieldType.equals( DataType.TYPE_COMPARABLE ) ) {
callback.callback( OperatorsOracle.COMPARABLE_OPERATORS );
return;
} else if ( fieldType.equals( DataType.TYPE_COLLECTION ) ) {
callback.callback( OperatorsOracle.COLLECTION_OPERATORS );
return;
} else {
callback.callback( OperatorsOracle.STANDARD_OPERATORS );
}
}
/**
* Get the Operators applicable for Connective Constraints
* @param factType
* @param fieldName
* @return
*/
@Override
public void getConnectiveOperatorCompletions( final String factType,
final String fieldName,
final Callback<String[]> callback ) {
final String fieldType = getFieldType( factType,
fieldName );
if ( fieldType == null ) {
callback.callback( OperatorsOracle.STANDARD_CONNECTIVES );
return;
} else if ( fieldName.equals( DataType.TYPE_THIS ) ) {
isFactTypeAnEvent( factType,
new Callback<Boolean>() {
@Override
public void callback( final Boolean isFactTypeAnEvent ) {
if ( Boolean.TRUE.equals( isFactTypeAnEvent ) ) {
callback.callback( OracleUtils.joinArrays( OperatorsOracle.STANDARD_CONNECTIVES,
OperatorsOracle.SIMPLE_CEP_CONNECTIVES,
OperatorsOracle.COMPLEX_CEP_CONNECTIVES ) );
return;
} else {
callback.callback( OperatorsOracle.STANDARD_CONNECTIVES );
return;
}
}
} );
} else if ( fieldType.equals( DataType.TYPE_STRING ) ) {
callback.callback( OperatorsOracle.STRING_CONNECTIVES );
return;
} else if ( DataType.isNumeric( fieldType ) ) {
callback.callback( OperatorsOracle.COMPARABLE_CONNECTIVES );
return;
} else if ( fieldType.equals( DataType.TYPE_DATE ) ) {
callback.callback( OracleUtils.joinArrays( OperatorsOracle.COMPARABLE_CONNECTIVES,
OperatorsOracle.SIMPLE_CEP_CONNECTIVES ) );
return;
} else if ( fieldType.equals( DataType.TYPE_COMPARABLE ) ) {
callback.callback( OperatorsOracle.COMPARABLE_CONNECTIVES );
return;
} else if ( fieldType.equals( DataType.TYPE_COLLECTION ) ) {
callback.callback( OperatorsOracle.COLLECTION_CONNECTIVES );
return;
} else {
callback.callback( OperatorsOracle.STANDARD_CONNECTIVES );
}
}
// ####################################
// Methods
// ####################################
/**
* Get a list of MethodInfos for a Fact Type
* @param factType
* @param callback
* @return
*/
@Override
public void getMethodInfos( final String factType,
final Callback<List<MethodInfo>> callback ) {
getMethodInfos( factType,
-1,
callback );
}
/**
* Get a list of MethodInfos for a Fact Type that have at least the specified number of parameters
* @param factType
* @param parameterCount
* @param callback
* @return
*/
@Override
public void getMethodInfos( final String factType,
final int parameterCount,
final Callback<List<MethodInfo>> callback ) {
final String fqcnByFactName = getFQCNByFactName(factType);
final List<MethodInfo> methodInformation = projectMethodInformation.get( fqcnByFactName );
//Load incremental content
if ( methodInformation == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
final List<MethodInfo> methodInformation = projectMethodInformation.get( fqcnByFactName );
callback.callback( getMethodInfos( parameterCount,
methodInformation ) );
}
} ).getUpdates( resourcePath,
imports,
fqcnByFactName );
} else {
callback.callback( getMethodInfos( parameterCount,
methodInformation ) );
}
}
private List<MethodInfo> getMethodInfos( final int paramCount,
final List<MethodInfo> allMethodInfos ) {
final List<MethodInfo> methodInfos = new ArrayList<MethodInfo>();
for ( MethodInfo mi : allMethodInfos ) {
if ( paramCount == -1 || mi.getParams().size() <= paramCount ) {
methodInfos.add( mi );
}
}
return methodInfos;
}
/**
* Get a list of parameters for a Method of a Fact Type
* @param factType
* @param methodNameWithParams
* @return
*/
@Override
public void getMethodParams( final String factType,
final String methodNameWithParams,
final Callback<List<String>> callback ) {
final List<MethodInfo> methodInformation = projectMethodInformation.get( factType );
//Load incremental content
if ( methodInformation == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
final List<MethodInfo> methodInformation = projectMethodInformation.get( factType );
callback.callback( getMethodParams( methodInformation,
methodNameWithParams ) );
}
} ).getUpdates( resourcePath,
imports,
factType );
} else {
callback.callback( getMethodParams( methodInformation,
methodNameWithParams ) );
}
}
private List<String> getMethodParams( final List<MethodInfo> methodInfos,
final String methodNameWithParams ) {
final List<String> methodParams = new ArrayList<String>();
for ( MethodInfo methodInfo : methodInfos ) {
if ( methodInfo.getNameWithParameters().startsWith( methodNameWithParams ) ) {
methodParams.addAll( methodInfo.getParams() );
}
}
return methodParams;
}
/**
* Get information on a Method of a Fact Type
* @param factType
* @param methodNameWithParams
* @return
*/
@Override
public void getMethodInfo( final String factType,
final String methodNameWithParams,
final Callback<MethodInfo> callback ) {
final List<MethodInfo> methodInformation = projectMethodInformation.get( factType );
//Load incremental content
if ( methodInformation == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
final List<MethodInfo> methodInformation = projectMethodInformation.get( factType );
callback.callback( getMethodInfo( methodInformation,
methodNameWithParams ) );
}
} ).getUpdates( resourcePath,
imports,
factType );
} else {
callback.callback( getMethodInfo( methodInformation,
methodNameWithParams ) );
}
}
private MethodInfo getMethodInfo( final List<MethodInfo> methodInfos,
final String methodNameWithParams ) {
for ( MethodInfo methodInfo : methodInfos ) {
if ( methodInfo.getNameWithParameters().equals( methodNameWithParams ) ) {
return methodInfo;
}
}
return null;
}
// ####################################
// Globals
// ####################################
@Override
public String[] getGlobalVariables() {
return OracleUtils.toStringArray( filteredGlobalTypes.keySet() );
}
@Override
public String getGlobalVariable( final String name ) {
return filteredGlobalTypes.get( name );
}
@Override
public boolean isGlobalVariable( final String name ) {
return filteredGlobalTypes.containsKey( name );
}
@Override
public void getFieldCompletionsForGlobalVariable(final String varName,
final Callback<ModelField[]> callback) {
getFieldCompletions(
getGlobalVariable(varName),
new Callback<ModelField[]>() {
@Override
public void callback(ModelField[] result) {
callback.callback(result);
}
});
}
@Override
public void getMethodInfosForGlobalVariable( final String varName,
final Callback<List<MethodInfo>> callback ) {
final String factType = getGlobalVariable( varName );
final List<MethodInfo> methodInformation = projectMethodInformation.get( factType );
//Load incremental content
if ( methodInformation == null ) {
service.call( new RemoteCallback<PackageDataModelOracleIncrementalPayload>() {
@Override
public void callback( final PackageDataModelOracleIncrementalPayload dataModel ) {
AsyncPackageDataModelOracleUtilities.populateDataModelOracle( AsyncPackageDataModelOracleImpl.this,
dataModel );
final List<MethodInfo> methodInformation = projectMethodInformation.get( factType );
callback.callback( methodInformation );
}
} ).getUpdates( resourcePath,
imports,
factType );
} else {
callback.callback( methodInformation );
}
}
@Override
public String[] getGlobalCollections() {
final List<String> globalCollections = new ArrayList<String>();
for ( Map.Entry<String, String> e : filteredGlobalTypes.entrySet() ) {
if ( filteredCollectionTypes.containsKey( e.getValue() ) ) {
if ( Boolean.TRUE.equals( filteredCollectionTypes.get( e.getValue() ) ) ) {
globalCollections.add( e.getKey() );
}
}
}
return OracleUtils.toStringArray( globalCollections );
}
// ####################################
// DSLs
// ####################################
@Override
public List<DSLSentence> getDSLConditions() {
return Collections.unmodifiableList( packageDSLConditionSentences );
}
@Override
public List<DSLSentence> getDSLActions() {
return Collections.unmodifiableList( packageDSLActionSentences );
}
// ####################################
// Enums
// ####################################
/**
* Get enums for a Type and Field.
*/
@Override
public DropDownData getEnums( final String type,
final String field ) {
return getEnums( type,
field,
new HashMap<String, String>() );
}
/**
* Get enums for a Type and Field where the enum list may depend upon the values of other fields.
*/
@Override
public DropDownData getEnums( final String type,
final String field,
final Map<String, String> currentValueMap ) {
final Map<String, Object> dataEnumLookupFields = loadDataEnumLookupFields();