This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
gaffer_operations.py
executable file
·2938 lines (2338 loc) · 96.6 KB
/
gaffer_operations.py
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 2016-2019 Crown Copyright
#
# 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.
#
"""
This module contains Python copies of Gaffer operation java classes
"""
import gafferpy.gaffer_binaryoperators as gaffer_binaryoperators
import gafferpy.gaffer_functions as gaffer_functions
import gafferpy.gaffer_predicates as gaffer_predicates
from gafferpy.gaffer_core import *
class NamedOperationParameter(ToJson, ToCodeString):
CLASS = 'gaffer.NamedOperationParameter'
def __init__(self,
name,
value_class,
description=None,
default_value=None,
required=False):
self.name = name
self.value_class = value_class
self.description = description
self.default_value = default_value
self.required = required
def get_detail(self):
detail = {
"valueClass": self.value_class,
"required": self.required
}
if self.description is not None:
detail['description'] = self.description
if self.default_value is not None:
detail['defaultValue'] = self.default_value
return detail
def to_json(self):
return {
"description": self.description,
"defaultValue": self.default_value,
"valueClass": self.value_class,
"required": self.required
}
class NamedViewParameter(ToJson, ToCodeString):
CLASS = 'gaffer.NamedViewParameter'
def __init__(self,
name,
value_class,
description=None,
default_value=None,
required=False):
self.name = name
self.value_class = value_class
self.description = description
self.default_value = default_value
self.required = required
def get_detail(self):
detail = {
"valueClass": self.value_class,
"required": self.required
}
if self.description is not None:
detail['description'] = self.description
if self.default_value is not None:
detail['defaultValue'] = self.default_value
return detail
def to_json(self):
return {
"description": self.description,
"defaultValue": self.default_value,
"valueClass": self.value_class,
"required": self.required
}
class View(ToJson, ToCodeString):
CLASS = 'uk.gov.gchq.gaffer.data.elementdefinition.view.View'
def __init__(self, entities=None, edges=None, global_elements=None,
global_entities=None, global_edges=None, all_edges=False,
all_entities=False):
super().__init__()
self.entities = None
self.edges = None
self.global_elements = None
self.global_entities = None
self.global_edges = None
self.all_edges = all_edges
self.all_entities = all_entities
if entities is not None:
self.entities = []
if isinstance(entities, list):
for el_def in entities:
if not isinstance(el_def, ElementDefinition):
el_def = JsonConverter.from_json(
el_def, ElementDefinition)
self.entities.append(el_def)
else:
for group, el_def in entities.items():
if not isinstance(el_def, ElementDefinition):
el_def = JsonConverter.from_json(
el_def, ElementDefinition)
el_def.group = group
self.entities.append(el_def)
if edges is not None:
self.edges = []
if isinstance(edges, list):
for el_def in edges:
if not isinstance(el_def, ElementDefinition):
el_def = JsonConverter.from_json(
el_def, ElementDefinition)
self.edges.append(el_def)
else:
for group, el_def in edges.items():
if not isinstance(el_def, ElementDefinition):
el_def = JsonConverter.from_json(
el_def, ElementDefinition)
el_def.group = group
self.edges.append(el_def)
if global_elements is not None:
self.global_elements = []
if isinstance(global_elements, list):
for el_def in global_elements:
if not isinstance(el_def, GlobalElementDefinition):
el_def = JsonConverter.from_json(
el_def, GlobalElementDefinition)
self.global_elements.append(el_def)
elif isinstance(global_elements, GlobalElementDefinition):
self.global_elements.append(global_elements)
else:
for group, el_def in global_elements.items():
if not isinstance(el_def, GlobalElementDefinition):
el_def = JsonConverter.from_json(
el_def, GlobalElementDefinition)
self.global_elements.append(el_def)
if global_entities is not None:
self.global_entities = []
if isinstance(global_entities, list):
for el_def in global_entities:
if not isinstance(el_def, GlobalElementDefinition):
el_def = JsonConverter.from_json(
el_def, GlobalElementDefinition)
self.global_entities.append(el_def)
elif isinstance(global_entities, GlobalElementDefinition):
self.global_entities.append(global_entities)
else:
for group, el_def in global_entities.items():
if not isinstance(el_def, GlobalElementDefinition):
el_def = JsonConverter.from_json(
el_def, GlobalElementDefinition)
self.global_entities.append(el_def)
if global_edges is not None:
self.global_edges = []
if isinstance(global_edges, list):
for el_def in global_edges:
if not isinstance(el_def, GlobalElementDefinition):
el_def = JsonConverter.from_json(
el_def, GlobalElementDefinition)
self.global_edges.append(el_def)
elif isinstance(global_edges, GlobalElementDefinition):
self.global_edges.append(global_edges)
else:
for group, el_def in global_edges.items():
if not isinstance(el_def, GlobalElementDefinition):
el_def = JsonConverter.from_json(
el_def, GlobalElementDefinition)
self.global_edges.append(el_def)
def to_json(self):
view = {}
if self.entities is not None:
el_defs = {}
for el_def in self.entities:
el_defs[el_def.group] = el_def.to_json()
view['entities'] = el_defs
if self.edges is not None:
el_defs = {}
for el_def in self.edges:
el_defs[el_def.group] = el_def.to_json()
view['edges'] = el_defs
if self.global_elements is not None:
el_defs = []
for el_def in self.global_elements:
el_defs.append(el_def.to_json())
view['globalElements'] = el_defs
if self.global_entities is not None:
el_defs = []
for el_def in self.global_entities:
el_defs.append(el_def.to_json())
view['globalEntities'] = el_defs
if self.global_edges is not None:
el_defs = []
for el_def in self.global_edges:
el_defs.append(el_def.to_json())
view['globalEdges'] = el_defs
if self.all_edges is True:
view['allEdges'] = True
if self.all_entities is True:
view['allEntities'] = True
return view
class NamedView(View):
CLASS = 'uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView'
def __init__(self, name, parameters=None, entities=None, edges=None,
global_elements=None,
global_entities=None, global_edges=None):
super().__init__(entities, edges, global_elements, global_entities,
global_edges)
self.name = name
self.parameters = parameters
def to_json(self):
view = super().to_json()
view['class'] = self.CLASS
view['name'] = self.name
if self.parameters is not None:
view['parameters'] = self.parameters
return view
class ElementDefinition(ToJson, ToCodeString):
CLASS = 'uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition'
def __init__(self, group='',
transient_properties=None,
group_by=None,
pre_aggregation_filter_functions=None,
aggregate_functions=None,
post_aggregation_filter_functions=None,
transform_functions=None,
post_transform_filter_functions=None,
properties=None,
exclude_properties=None):
super().__init__()
self.group = group
if transient_properties is None:
self.transient_properties = None
else:
self.transient_properties = {}
if isinstance(transient_properties, list):
for prop in transient_properties:
if not isinstance(prop, Property):
prop = JsonConverter.from_json(prop, Property)
self.transient_properties[prop.name] = prop.class_name
else:
for propName, propClass in transient_properties.items():
self.transient_properties[propName] = propClass
self.pre_aggregation_filter_functions = JsonConverter.from_json(
pre_aggregation_filter_functions,
gaffer_predicates.PredicateContext)
self.aggregate_functions = JsonConverter.from_json(
aggregate_functions, gaffer_predicates.PredicateContext)
self.post_aggregation_filter_functions = JsonConverter.from_json(
post_aggregation_filter_functions,
gaffer_predicates.PredicateContext)
self.transform_functions = JsonConverter.from_json(
transform_functions, gaffer_functions.FunctionContext)
self.post_transform_filter_functions = JsonConverter.from_json(
post_transform_filter_functions, gaffer_predicates.PredicateContext)
self.group_by = group_by
self.properties = properties
self.exclude_properties = exclude_properties
def to_json(self):
element_def = {}
if self.transient_properties is not None:
element_def['transientProperties'] = self.transient_properties
if self.pre_aggregation_filter_functions is not None:
funcs = []
for func in self.pre_aggregation_filter_functions:
funcs.append(func.to_json())
element_def['preAggregationFilterFunctions'] = funcs
if self.post_aggregation_filter_functions is not None:
funcs = []
for func in self.post_aggregation_filter_functions:
funcs.append(func.to_json())
element_def['postAggregationFilterFunctions'] = funcs
if self.transform_functions is not None:
funcs = []
for func in self.transform_functions:
funcs.append(func.to_json())
element_def['transformFunctions'] = funcs
if self.post_transform_filter_functions is not None:
funcs = []
for func in self.post_transform_filter_functions:
funcs.append(func.to_json())
element_def['postTransformFilterFunctions'] = funcs
if self.group_by is not None:
element_def['groupBy'] = self.group_by
if self.properties is not None:
element_def['properties'] = self.properties
if self.exclude_properties is not None:
element_def['excludeProperties'] = self.exclude_properties
return element_def
class ElementTransformDefinition(ToJson, ToCodeString):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.function.ElementTransformDefinition'
def __init__(self, group='',
functions=None):
super().__init__()
self.group = group
self.functions = JsonConverter.from_json(
functions, gaffer_functions.FunctionContext)
def to_json(self):
element_def = {}
if self.functions is not None:
funcs = []
for func in self.functions:
funcs.append(func.to_json())
element_def['functions'] = funcs
return element_def
class AggregatePair(ToJson, ToCodeString):
CLASS = 'uk.gov.gchq.gaffer.operation.util.AggregatePair'
def __init__(self,
group=None,
group_by=None,
element_aggregator=None):
super().__init__()
self.group = group
if group_by is not None and not isinstance(group_by, list):
group_by = [group_by]
self.group_by = group_by
if element_aggregator is not None and not isinstance(element_aggregator,
ElementAggregateDefinition):
element_aggregator = ElementAggregateDefinition(
operators=element_aggregator['operators'])
self.element_aggregator = element_aggregator
def to_json(self):
element_def = {}
if self.group_by is not None:
element_def['groupBy'] = self.group_by
if self.element_aggregator is not None:
element_def['elementAggregator'] = self.element_aggregator.to_json()
return element_def
class ElementAggregateDefinition(ToJson, ToCodeString):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.function.ElementAggregateDefinition'
def __init__(self, operators=None):
super().__init__()
self.operators = JsonConverter.from_json(
operators, gaffer_binaryoperators.BinaryOperatorContext)
def to_json(self):
element_def = {}
if self.operators is not None:
funcs = []
for function in self.operators:
funcs.append(function.to_json())
element_def['operators'] = funcs
return element_def
class ElementFilterDefinition(ToJson, ToCodeString):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.function.ElementFilterDefinition'
def __init__(self, group='',
predicates=None):
super().__init__()
self.group = group
self.predicates = JsonConverter.from_json(
predicates, gaffer_predicates.PredicateContext)
def to_json(self):
element_def = {}
if self.predicates is not None:
funcs = []
for function in self.predicates:
funcs.append(function.to_json())
element_def['predicates'] = funcs
return element_def
class GlobalElementFilterDefinition(ToJson, ToCodeString):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.function.GlobalElementFilterDefinition'
def __init__(self, predicates=None):
super().__init__()
self.predicates = JsonConverter.from_json(
predicates, gaffer_predicates.PredicateContext)
def to_json(self):
element_def = {}
if self.predicates is not None:
funcs = []
for func in self.predicates:
funcs.append(func.to_json())
element_def['predicates'] = funcs
return element_def
class GlobalElementDefinition(ToJson, ToCodeString):
CLASS = 'uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition'
def __init__(self,
transient_properties=None,
group_by=None,
pre_aggregation_filter_functions=None,
post_aggregation_filter_functions=None,
transform_functions=None,
post_transform_filter_functions=None,
properties=None,
exclude_properties=None):
super().__init__()
if transient_properties is None:
self.transient_properties = None
else:
self.transient_properties = {}
if isinstance(transient_properties, list):
for prop in transient_properties:
if not isinstance(prop, Property):
prop = JsonConverter.from_json(prop, Property)
self.transient_properties[prop.name] = prop.class_name
else:
for propName, propClass in transient_properties.items():
self.transient_properties[propName] = propClass
self.pre_aggregation_filter_functions = JsonConverter.from_json(
pre_aggregation_filter_functions,
gaffer_predicates.PredicateContext)
self.post_aggregation_filter_functions = JsonConverter.from_json(
post_aggregation_filter_functions,
gaffer_predicates.PredicateContext)
self.transform_functions = JsonConverter.from_json(
transform_functions, gaffer_functions.FunctionContext)
self.post_transform_filter_functions = JsonConverter.from_json(
post_transform_filter_functions, gaffer_predicates.PredicateContext)
self.group_by = group_by
self.properties = properties
self.exclude_properties = exclude_properties
def to_json(self):
element_def = {}
if self.transient_properties is not None:
element_def['transientProperties'] = self.transient_properties
if self.pre_aggregation_filter_functions is not None:
funcs = []
for func in self.pre_aggregation_filter_functions:
funcs.append(func.to_json())
element_def['preAggregationFilterFunctions'] = funcs
if self.post_aggregation_filter_functions is not None:
funcs = []
for func in self.post_aggregation_filter_functions:
funcs.append(func.to_json())
element_def['postAggregationFilterFunctions'] = funcs
if self.transform_functions is not None:
funcs = []
for func in self.transform_functions:
funcs.append(func.to_json())
element_def['transformFunctions'] = funcs
if self.post_transform_filter_functions is not None:
funcs = []
for func in self.post_transform_filter_functions:
funcs.append(func.to_json())
element_def['postTransformFilterFunctions'] = funcs
if self.group_by is not None:
element_def['groupBy'] = self.group_by
if self.properties is not None:
element_def['properties'] = self.properties
if self.exclude_properties is not None:
element_def['excludeProperties'] = self.exclude_properties
return element_def
class Property(ToJson, ToCodeString):
CLASS = "uk.gov.gchq.gaffer.data.element.Property"
def __init__(self, name, class_name):
super().__init__()
if not isinstance(name, str):
raise TypeError('Name must be a string')
if not isinstance(class_name, str):
raise TypeError('ClassName must be a class name string')
self.name = name
self.class_name = class_name
def to_json(self):
return {self.name: self.class_name}
class Operation(ToJson, ToCodeString):
def __init__(self,
_class_name,
view=None,
options=None,
views=None):
self._class_name = _class_name
if view is not None and isinstance(view, list):
views = view
view = None
if view is not None and isinstance(view, dict):
view = JsonConverter.from_json(view, View)
self.view = view
self.views = None
if views is not None and isinstance(views, list):
self.views = []
for view in views:
if not isinstance(view, View):
view = JsonConverter.from_json(view, View)
self.views.append(view)
# Helper so that lists will be interpreted as federated graphIds
# e.g. options = ["graph_1", "graph_2"]
if isinstance(options, list):
options = {
"gaffer.federatedstore.operation.graphIds": ','.join(options)
}
self.options = options
def to_json(self):
operation = {'class': self._class_name}
if self.options is not None:
operation['options'] = self.options
if self.view is not None:
operation['view'] = self.view.to_json()
if self.views is not None:
operation['views'] = []
for view in self.views:
operation['views'].append(view.to_json())
return operation
def validate_operation_chain(self, operation_chain, allow_none=False):
if isinstance(operation_chain, list):
for operation in operation_chain:
JsonConverter.validate(operation, Operation)
return OperationChain(operation_chain)
try:
return JsonConverter.validate(
operation_chain, OperationChain, allow_none
)
except:
return OperationChain([
JsonConverter.validate(
operation_chain, Operation, allow_none
)
])
class Match(ToJson, ToCodeString):
def __init__(self, _class_name):
self._class_name = _class_name
def to_json(self):
return {
'class': self._class_name
}
class ElementMatch(Match):
CLASS = "uk.gov.gchq.gaffer.store.operation.handler.join.match.ElementMatch"
def __init__(self, group_by_properties=None):
super().__init__(_class_name=self.CLASS)
self.group_by_properties = group_by_properties
def to_json(self):
match_json = super().to_json()
if (self.group_by_properties is not None):
match_json['groupByProperties'] = self.group_by_properties
return match_json
class KeyFunctionMatch(Match):
CLASS = "uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch"
def __init__(self, first_key_function=None, second_key_function=None):
super().__init__(_class_name=self.CLASS)
if not isinstance(first_key_function, gaffer_functions.Function):
self.first_key_function = JsonConverter.from_json(first_key_function, class_obj=gaffer_functions.Function)
else:
self.first_key_function = first_key_function
if not isinstance(second_key_function, gaffer_functions.Function):
self.second_key_function = JsonConverter.from_json(second_key_function, class_obj=gaffer_functions.Function)
else:
self.second_key_function = second_key_function
def to_json(self):
match_json = super().to_json()
if self.first_key_function is not None:
match_json['firstKeyFunction'] = self.first_key_function.to_json()
if self.second_key_function is not None:
match_json['secondKeyFunction'] = self.second_key_function.to_json()
return match_json
class OperationChain(Operation):
CLASS = "uk.gov.gchq.gaffer.operation.OperationChain"
def __init__(self, operations, options=None):
super().__init__(
_class_name=self.CLASS,
options=options)
self._class_name = self.CLASS
self.operations = operations
def to_json(self):
operation_chain_json = super().to_json()
operations_json = []
for operation in self.operations:
if isinstance(operation, ToJson):
operations_json.append(operation.to_json())
else:
operations_json.append(operation)
operation_chain_json['operations'] = operations_json
return operation_chain_json
class OperationChainDAO(OperationChain):
CLASS = "uk.gov.gchq.gaffer.operation.OperationChainDAO"
def __init__(self, operations,
options=None):
super().__init__(operations=operations, options=options)
def to_json(self):
operation_chain_json = super().to_json()
operation_chain_json.pop('class', None)
return operation_chain_json
class GetTraits(Operation):
CLASS = 'uk.gov.gchq.gaffer.store.operation.GetTraits'
def __init__(self,
current_traits=True,
options=None):
super().__init__(
_class_name=self.CLASS, options=options)
self.current_traits = current_traits
def to_json(self):
operation = super().to_json()
operation['currentTraits'] = self.current_traits
return operation
class HasTrait(Operation):
CLASS = 'uk.gov.gchq.gaffer.store.operation.HasTrait'
def __init__(self,
trait,
current_traits=True,
options=None):
super().__init__(
_class_name=self.CLASS, options=options)
self.trait = trait
self.current_traits = current_traits
def to_json(self):
operation = super().to_json()
operation['trait'] = self.trait
operation['currentTraits'] = self.current_traits
return operation
class AddElements(Operation):
"""
This class defines a Gaffer Add Operation.
"""
CLASS = 'uk.gov.gchq.gaffer.operation.impl.add.AddElements'
def __init__(self,
input=None,
skip_invalid_elements=None,
validate=None,
options=None):
super().__init__(
_class_name=self.CLASS,
options=options)
self.input = input
self.skip_invalid_elements = skip_invalid_elements
self.validate = validate
def to_json(self):
operation = super().to_json()
if self.skip_invalid_elements is not None:
operation['skipInvalidElements'] = self.skip_invalid_elements
if self.validate is not None:
operation['validate'] = self.validate
if self.input is not None:
elements_json = []
for element in self.input:
elements_json.append(element.to_json())
operation['input'] = elements_json
return operation
class GenerateElements(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateElements'
def __init__(self,
element_generator,
input=None,
options=None):
super().__init__(
_class_name=self.CLASS,
options=options)
if not isinstance(element_generator, gaffer_functions.ElementGenerator):
element_generator = gaffer_functions.ElementGenerator(
element_generator['class'],
element_generator)
self.element_generator = element_generator
self.input = input
def to_json(self):
operation = super().to_json()
if self.input is not None:
input_json = []
for item in self.input:
if isinstance(item, ToJson):
input_json.append(item.to_json())
else:
input_json.append(item)
operation['input'] = input_json
operation['elementGenerator'] = self.element_generator.to_json()
return operation
class GenerateObjects(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects'
def __init__(self,
element_generator,
input=None,
options=None):
super().__init__(
_class_name=self.CLASS,
options=options)
if not isinstance(element_generator, gaffer_functions.ElementGenerator):
element_generator = gaffer_functions.ElementGenerator(
element_generator['class'],
element_generator)
self.element_generator = element_generator
self.input = input
def to_json(self):
operation = super().to_json()
if self.input is not None:
elements_json = []
for element in self.input:
if isinstance(element, ToJson):
elements_json.append(element.to_json())
else:
elements_json.append(element)
operation['input'] = elements_json
operation['elementGenerator'] = self.element_generator.to_json()
return operation
class Validate(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.Validate'
def __init__(self,
validate,
skip_invalid_elements=True,
options=None):
super().__init__(
_class_name=self.CLASS, options=options)
self.validate = validate
self.skip_invalid_elements = skip_invalid_elements
def to_json(self):
operation = super().to_json()
operation['validate'] = self.validate
operation['skipInvalidElements'] = self.skip_invalid_elements
return operation
class ExportToGafferResultCache(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache'
def __init__(self,
key=None,
op_auths=None,
options=None):
super().__init__(
_class_name=self.CLASS,
view=None,
options=options)
if not isinstance(key, str) and key is not None:
raise TypeError('key must be a string')
self.key = key
self.op_auths = op_auths
def to_json(self):
operation = super().to_json()
if self.key is not None:
operation['key'] = self.key
if self.op_auths is not None:
operation['opAuths'] = self.op_auths
return operation
class GetGafferResultCacheExport(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport'
def __init__(self,
job_id=None,
key=None,
options=None):
super().__init__(
_class_name=self.CLASS,
view=None,
options=options)
self.job_id = job_id
self.key = key
def to_json(self):
operation = super().to_json()
if self.job_id is not None:
operation['jobId'] = self.job_id
if self.key is not None:
operation['key'] = self.key
return operation
class ExportToSet(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet'
def __init__(self, key=None, options=None):
super().__init__(
_class_name=self.CLASS,
view=None,
options=options)
if not isinstance(key, str) and key is not None:
raise TypeError('key must be a string')
self.key = key
def to_json(self):
operation = super().to_json()
if self.key is not None:
operation['key'] = self.key
return operation
class GetSetExport(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport'
def __init__(self,
job_id=None,
key=None,
start=None,
end=None,
options=None):
super().__init__(
_class_name=self.CLASS,
view=None,
options=options)
self.job_id = job_id
self.key = key
self.start = start
self.end = end
def to_json(self):
operation = super().to_json()
if self.job_id is not None:
operation['jobId'] = self.job_id
if self.key is not None:
operation['key'] = self.key
if self.start is not None:
operation['start'] = self.start
if self.end is not None:
operation['end'] = self.end
return operation
class GetExports(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.export.GetExports'
def __init__(self,
get_exports,
options=None):
super().__init__(
_class_name=self.CLASS,
view=None,
options=options)
self.get_exports = []
for export in get_exports:
self.get_exports.append(JsonConverter.validate(export, Operation, False))
def to_json(self):
operation = super().to_json()
operation['getExports'] = [export.to_json() for export in self.get_exports]
return operation
class GetJobDetails(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails'
def __init__(self,
job_id=None,
options=None):
super().__init__(
_class_name=self.CLASS,
view=None,
options=options)
self.job_id = job_id
def to_json(self):
operation = super().to_json()
if self.job_id is not None:
operation['jobId'] = self.job_id
return operation
class GetAllJobDetails(Operation):
CLASS = 'uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails'
def __init__(self, options=None):
super().__init__(
_class_name=self.CLASS,
view=None,
options=options)
def to_json(self):
operation = super().to_json()
return operation