Skip to content

Commit

Permalink
reformat some files
Browse files Browse the repository at this point in the history
  • Loading branch information
alastair committed May 7, 2020
1 parent b2b0f98 commit 0ec27fc
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 54 deletions.
5 changes: 2 additions & 3 deletions trompace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import json
from datetime import date
import datetime


def filter_none_args(args):
Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(self, value):
if isinstance(value, date):
self.value = "{{ year: {0} month: {1} day: {2} }}".format(value.year, value.month, value.day)
elif isinstance(value, list):
date_parts = ['year','month','day']
date_parts = ['year', 'month', 'day']
date_str = ""
for i in range(min(len(date_parts), len(value))):
date_str += "{0}: {1} ".format(date_parts[i], value[i])
Expand All @@ -81,4 +81,3 @@ def __init__(self, value):
QUERY = '''query {{
{query}
}}'''

2 changes: 1 addition & 1 deletion trompace/application/entrypoint_subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import asyncio
import configparser

from trompace import StringConstant
from trompace.application.application import create_entrypointcontrolaction_CE, create_property_CE, \
create_propertyvalue_CE, create_application_CE, subscribe_controlaction
from trompace.exceptions import IDNotFoundException, ConfigRequirementException
from trompace import StringConstant


async def main(app_config_file, ep_config_file):
Expand Down
2 changes: 1 addition & 1 deletion trompace/client/client_send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import websockets

from trompace import StringConstant, make_parameters
from trompace.connection import submit_query
from trompace.exceptions import ValueNotFound
from trompace import StringConstant, make_parameters
from trompace.subscriptions.controlaction import subscription_controlaction_client

INIT_STR = """{"type":"connection_init","payload":{}}"""
Expand Down
1 change: 1 addition & 0 deletions trompace/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async def submit_query(querystr: str):
raise QueryException(resp['errors'])
return resp


def submit_query_nasync(querystr: str):
q = {"query": querystr}
server = config.server_id
Expand Down
4 changes: 2 additions & 2 deletions trompace/mutations/document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generate GraphQL queries for mutations pertaining to digital document objects.
from trompace.exceptions import UnsupportedLanguageException, NotAMimeTypeException
from trompace import StringConstant, filter_none_args
from trompace.exceptions import UnsupportedLanguageException, NotAMimeTypeException
from .templates import mutation_create, mutation_delete, mutation_update, mutation_link
from ..constants import SUPPORTED_LANGUAGES

Expand Down Expand Up @@ -250,4 +250,4 @@ def mutation_add_digital_document_controlaction(document_id: str, controlaction_
The string for the mutation for adding the document as a subject of the composition.
"""

return mutation_link(document_id, controlaction_id, ADD_DIGITAL_DOCUMENT_TO_CONTROL_ACTION_MUTATION)
return mutation_link(document_id, controlaction_id, ADD_DIGITAL_DOCUMENT_TO_CONTROL_ACTION_MUTATION)
38 changes: 17 additions & 21 deletions trompace/mutations/mediaobject.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Generate GraphQL queries for mutations pertaining to media object objects.
from trompace.exceptions import UnsupportedLanguageException, NotAMimeTypeException
from trompace.mutations.templates import format_mutation, format_link_mutation
from trompace import StringConstant, _Neo4jDate, filter_none_args
from trompace.constants import SUPPORTED_LANGUAGES
from trompace.exceptions import UnsupportedLanguageException, NotAMimeTypeException
from trompace.mutations.templates import format_mutation, format_link_mutation


def mutation_create_media_object(name: str, description: str, date: str, creator: str, contributor: str, format_: str, encodingFormat: str, source: str, subject: str, \
contentUrl:str, language: str, title:str=None):

def mutation_create_media_object(name: str, description: str, date: str, creator: str, contributor: str, format_: str,
encodingFormat: str, source: str, subject: str, \
contentUrl: str, language: str, title: str = None):
"""Returns a mutation for creating a media object object
Arguments:
name: The name of the media object.
name: The name of the media object.
description: An account of the media object.
date: The date associated with the media object.
creator: The person, organization or service who created the thing the web resource is about.
Expand All @@ -19,10 +19,10 @@ def mutation_create_media_object(name: str, description: str, date: str, creator
encodingFormat: A MimeType of the format of object encoded by the media object.
source: The URL of the web resource to be represented by the node.
subject: The subject of the media object.
contentUrl: The URL of the content encoded by the media object.
contentUrl: The URL of the content encoded by the media object.
language: The language the metadata is written in. Currently supported languages are en,es,ca,nl,de,fr
inLanguage: The language of the media object. Currently supported languages are en,es,ca,nl,de,fr
title: The title of the page from which the media object information was extracted.
title: The title of the page from which the media object information was extracted.
Returns:
The string for the mutation for creating the media object.
Raises:
Expand Down Expand Up @@ -52,17 +52,18 @@ def mutation_create_media_object(name: str, description: str, date: str, creator
"language": StringConstant(language.lower())
}


args = filter_none_args(args)

return format_mutation("CreateMediaObject", args)


def mutation_update_media_object(identifier: str, name: str=None, title:str=None, description: str=None, date: str=None, creator: str=None, contributor: str=None,\
format_: str=None, encodingFormat: str=None, source: str=None, subject: str=None, contentUrl:str=None, language: str=None):
def mutation_update_media_object(identifier: str, name: str = None, title: str = None, description: str = None,
date: str = None, creator: str = None, contributor: str = None, \
format_: str = None, encodingFormat: str = None, source: str = None,
subject: str = None, contentUrl: str = None, language: str = None):
"""Returns a mutation for updating a media object object.
Arguments:
name: The name of the media object.
name: The name of the media object.
description: An account of the media object.
date: The date associated with the media object.
creator: The person, organization or service who created the thing the web resource is about.
Expand All @@ -71,10 +72,10 @@ def mutation_update_media_object(identifier: str, name: str=None, title:str=None
encodingFormat: A MimeType of the format of object encoded by the media object.
source: The URL of the web resource to be represented by the node.
subject: The subject of the media object.
contentUrl: The URL of the content encoded by the media object.
contentUrl: The URL of the content encoded by the media object.
language: The language the metadata is written in. Currently supported languages are en,es,ca,nl,de,fr
inLanguage: The language of the media object. Currently supported languages are en,es,ca,nl,de,fr
title: The title of the page from which the media object information was extracted.
title: The title of the page from which the media object information was extracted.
Returns:
The string for the mutation for updating the media object.
Raises:
Expand All @@ -86,7 +87,6 @@ def mutation_update_media_object(identifier: str, name: str=None, title:str=None
if encodingFormat is not None and "/" not in encodingFormat:
raise NotAMimeTypeException(encodingFormat)


args = {
"identifier": identifier,
"name": name,
Expand All @@ -113,7 +113,6 @@ def mutation_update_media_object(identifier: str, name: str=None, title:str=None
return format_mutation("UpdateMediaObject", args)



def mutation_delete_media_object(identifier: str):
"""Returns a mutation for deleting a media object object based on the identifier.
Arguments:
Expand All @@ -125,8 +124,6 @@ def mutation_delete_media_object(identifier: str):
return format_mutation("DeleteMediaObject", {"identifier": identifier})




def mutation_merge_media_object_work_example(media_object_identifier: str, work_identifier: str):
"""Returns a mutation for creating merging a media object as an example of a work.
Arguments:
Expand Down Expand Up @@ -157,7 +154,7 @@ def mutation_merge_media_object_encoding(media_object_identifier_1: str, media_o
media_object_identifier_1: The unique identifier of the media object that is encoding the other.
media_object_identifier_2: The unique identifier of the media object being encoded.
Returns:
The string for the mutation for merging a media object as an encoding of another media object.
The string for the mutation for merging a media object as an encoding of another media object.
"""

return format_link_mutation("MergeMediaObjectEncoding", media_object_identifier_1, media_object_identifier_2)
Expand All @@ -169,8 +166,7 @@ def mutation_remove_media_object_encoding(media_object_identifier_1: str, media_
media_object_identifier_1: The unique identifier of the media object that is encoding the other.
media_object_identifier_2: The unique identifier of the media object being encoded.
Returns:
The string for the mutation for removing a media object as an encoding of another media object.
The string for the mutation for removing a media object as an encoding of another media object.
"""

return format_link_mutation("RemoveMediaObjectEncoding", media_object_identifier_1, media_object_identifier_2)

7 changes: 3 additions & 4 deletions trompace/mutations/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
__typename
}}
to {{
__typename
__typename
... on Property{{
identifier
}}
Expand Down Expand Up @@ -71,9 +71,8 @@ def mutation_create_property(title: str, name: str, description: str, rangeInclu


def mutation_create_propertyvaluespecification(name: str, description: str, defaultValue: str, valueMaxLength: int,
valueMinLength: int
, multipleValues: bool, valueName: str, valuePattern: str,
valueRequired: bool):
valueMinLength: int, multipleValues: bool, valueName: str,
valuePattern: str, valueRequired: bool):
"""Returns a mutation for creating a property value specification
Each PropertyValueSpecification defines a scalar input parameter that the Component user should be prompted with when preparing
the request for an algorithm process job. There are numerous properties that can be used to set requirements, type and limits for a scalar parameter.
Expand Down
1 change: 0 additions & 1 deletion trompace/queries/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

29 changes: 13 additions & 16 deletions trompace/queries/document.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generate GraphQL queries pertaining to digital document objects.
from trompace.constants import SUPPORTED_LANGUAGES
from trompace.exceptions import UnsupportedLanguageException
from trompace.queries.templates import query_create
from trompace.constants import SUPPORTED_LANGUAGES
from .. import QUERY

QUERY_DIGITALDOCUMENT = '''DigitalDocument(
Expand Down Expand Up @@ -31,8 +31,9 @@
}'''


def query_document(identifier: str=None, document_name=None, publisher=None, contributor=None, format_=None, creator=None,
source=None, description=None, language=None):
def query_document(identifier: str = None, document_name=None, publisher=None, contributor=None, format_=None,
creator=None,
source=None, description=None, language=None):
"""Returns a query for a digital document object
Arguments:
identifier: The unique identifier of the digital document.
Expand All @@ -56,30 +57,26 @@ def query_document(identifier: str=None, document_name=None, publisher=None, con
args = {}

if identifier:
args["identifier"] = identifier
args["identifier"] = identifier

if document_name:
args["name"] = document_name
args["name"] = document_name
if publisher:
args["publisher"] = publisher
args["publisher"] = publisher
if contributor:
args["contributor"] = contributor
args["contributor"] = contributor
if creator:
args["creator"] = creator
args["creator"] = creator
if source:
args["source"] = source
args["source"] = source
if language:
args["language"] = language
args["language"] = language
if format_:
args["format"] = format_
args["format"] = format_
if description:
args["description"] = description

args["description"] = description

if len(args) == 0:
return QUERY.format(query=QUERY_DIGITALDOCUMENT_ALL)
else:
return query_create(args, QUERY_DIGITALDOCUMENT)



5 changes: 0 additions & 5 deletions trompace/queries/templates.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Templates for generate GraphQL queries for mutations.

# To be added EntryPoint, ControlAction, PropertyValueSpecification and Property
from trompace.exceptions import UnsupportedLanguageException
from .. import make_parameters, QUERY
from ..constants import SUPPORTED_LANGUAGES




def query_create(args, query_string: str):
Expand All @@ -21,4 +17,3 @@ def query_create(args, query_string: str):

create_query = query_string.format(parameters=make_parameters(**args))
return QUERY.format(query=create_query)

0 comments on commit 0ec27fc

Please sign in to comment.