Skip to content

Commit

Permalink
gchqgh-14 - added extra graph methods like get schema in the python s…
Browse files Browse the repository at this point in the history
…hell

Also added resultLimit and deduplicate fields to operations
  • Loading branch information
p013570 committed Nov 16, 2016
1 parent ad236e3 commit 16295ac
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 67 deletions.
113 changes: 109 additions & 4 deletions python-shell/example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def run_with_connector(gc):
print('--------------------------')
print()

get_schema(gc)
get_filter_functions(gc)
get_class_filter_functions((gc))
get_generators(gc)
get_operations(gc)
get_serialised_fields(gc)
get_store_traits(gc)

is_operation_supported(gc)

add_elements(gc)
get_elements(gc)
get_adj_seeds(gc)
Expand All @@ -43,6 +53,96 @@ def create_connector(host, verbose=False):
return gaffer_connector.GafferConnector(host, verbose)


def get_schema(gc):
# Get Schema
result = gc.execute_get(
g.GetSchema()
)

print('Schema:')
print(result)
print()


def get_filter_functions(gc):
# Get Schema
result = gc.execute_get(
g.GetFilterFunctions()
)

print('Filter Functions:')
print(result)
print()


def get_class_filter_functions(gc):
# Get Schema
class_name = 'gaffer.function.simple.filter.IsMoreThan'
result = gc.execute_get(
g.GetClassFilterFunctions(class_name=class_name)
)

print('Class Filter Functions (gaffer.function.simple.filter.IsMoreThan):')
print(result)
print()


def get_generators(gc):
# Get Schema
result = gc.execute_get(
g.GetGenerators()
)

print('Generators:')
print(result)
print()


def get_operations(gc):
# Get Schema
result = gc.execute_get(
g.GetOperations()
)

print('Operations:')
print(result)
print()


def get_serialised_fields(gc):
# Get Schema
class_name = 'gaffer.function.simple.filter.IsMoreThan'
result = gc.execute_get(
g.GetSerialisedFields(class_name=class_name)
)

print('Serialised Fields (gaffer.function.simple.filter.IsMoreThan):')
print(result)
print()


def get_store_traits(gc):
# Get Store Traits
result = gc.execute_get(
g.GetStoreTraits()
)

print('Store Traits:')
print(result)
print()


def is_operation_supported(gc):
operation = 'gaffer.operation.impl.add.AddElements'
result = gc.is_operation_supported(
g.IsOperationSupported(operation=operation)
)

print('\nOperation supported ("gaffer.operation.impl.add.AddElements"):')
print(result)
print()


def add_elements(gc):
# Add Elements
gc.execute_operation(
Expand Down Expand Up @@ -96,6 +196,8 @@ def add_elements(gc):

def get_elements(gc):
# Get Elements
filterClass = 'gaffer.function.simple.filter.IsEqual'
transformClass = 'gaffer.rest.example.ExampleTransformFunction'
elements = gc.execute_operation(
g.GetRelatedElements(
seeds=[g.EntitySeed('1')],
Expand Down Expand Up @@ -156,11 +258,14 @@ def get_adj_seeds(gc):


def get_all_elements(gc):
# Adjacent Elements - chain 2 adjacent entities together
# Get all elements, but limit the total results to 3, deduplication true
all_elements = gc.execute_operation(
g.GetAllElements()
g.GetAllElements(
result_limit=g.ResultLimit(3),
deduplicate=True
)
)
print('All elements')
print('All elements (Limited to first 3)')
print(all_elements)
print()

Expand Down Expand Up @@ -258,5 +363,5 @@ def get_sub_graph(gc):
print()


if __name__ == '__main__':
if __name__ == "__main__":
run('http://localhost:8080/rest/v1')
Loading

0 comments on commit 16295ac

Please sign in to comment.