def test_list(self):
        """Lists of items should be represented properly"""
        params = {
            "name": "My thing",
            "items": [StringConstant("one"),
                      StringConstant("two")]
        }
        made_params = make_parameters(**params)
        expected = '''name: "My thing"\n        items: [one, two]'''
        assert expected == made_params

        params = {"name": "My thing", "items": ["val1", "val2"]}
        made_params = make_parameters(**params)
        expected = '''name: "My thing"\n        items: ["val1", "val2"]'''
        assert expected == made_params
def mutation_create_propertyvaluespecification(name: str, defaultValue: str, valueMaxLength: int,
                                               valueMinLength: int, multipleValues: bool, valueName: str,
                                               valuePattern: str, valueRequired: bool, description: str = None):
    """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.
    With these properties, a Component developer can set up the input field for this parameter.
    Arguments:
        name: The name of the property value specification.
        description: An account of the property
        defaultValue: the default value to use for the property value specification.
        valueMaxLength: The maximum length of the value.
        valueMinLength: The minimum length of the value.
        multipleValues: A boolean that states if multiple values are accepted or not.
        valueName: The name of the value.
        valuePattern: The format of the value.
        valueRequired: A boolean stating if the value is required or not.
    Returns:
        The string for the mutation for creating the property value specification.

    """

    args = {
        "name": name,
        "title": name,
        "description": description,
        "defaultValue": defaultValue,
        "valueMaxLength": valueMaxLength,
        "valueMinLength": valueMinLength,
        "multipleValues": multipleValues,
        "valueName": valueName,
        "valuePattern": StringConstant(valuePattern),
        "valueRequired": valueRequired
    }
    return format_mutation("CreatePropertyValueSpecification", args)
def update_defined_term_set(identifier: str, *, creator: str = None, name: str = None,
                            additionaltype: List[str] = None, broader_url: str = None,
                            broader_schema: annotation.AnnotationSchemaMotivation = None,
                            image: str = None):
    """Return a mutation for updating a DefinedTermSet.

    Arguments:
        identifier: The identifier of the DefinedTermSet in the CE to be updated (:dcterms:`identifier`).
        {definedtermset_args}

    Returns:
        A GraphQL Mutation to update a DefinedTermSet in the Trompa CE
    """

    additionaltype = _verify_additional_type(additionaltype)
    params = {"identifier": identifier,
              "creator": creator,
              "name": name,
              "additionalType": additionaltype,
              "broaderUrl": broader_url,
              "image": image}
    if broader_schema is not None:
        params["broaderMotivation"] = StringConstant(broader_schema.name)
    params = filter_none_args(params)

    return format_mutation(mutationname="UpdateDefinedTermSet", args=params)
def mutation_create_itemlist(
        name: str,
        creator: str,
        itemlistorder: ItemListOrderType = ItemListOrderType.ItemListUnordered,
        description: str = None,
        contributor: str = None,
        additionaltype: List[str] = None):
    """Returns a mutation for creating an ItemList object.
    (https://schema.org/ItemList)

    Arguments:
        {itemlist_args}

    Returns:
        The string for the mutation for creating the ItemList.
    """
    if not isinstance(itemlistorder, ItemListOrderType):
        raise trompace.exceptions.InvalidItemListOrderTypeException(
            itemlistorder)
    check_required_args(name=name, creator=creator)
    additionaltype = _verify_additional_type(additionaltype)

    args = {
        "creator": creator,
        "name": name,
        "contributor": contributor,
        "description": description,
        "additionalType": additionaltype
    }
    if itemlistorder:
        args["itemListOrder"] = StringConstant(itemlistorder)

    args = filter_none_args(args)

    return format_mutation("CreateItemList", args)
Beispiel #5
0
def mutation_update_audioobject(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,
                                license: str = None,
                                subject: str = None,
                                contenturl: str = None,
                                language: str = None,
                                inlanguage: str = None):
    """Returns a mutation for updating a AudioObject.

    Arguments:
        identifier: The identifier of the AudioObject in the CE to be updated.
        {audioobject_args}

    Returns:
        The string for the mutation for updating the AudioObject.

    Raises:
        Assertion error if the input language or inlanguage is not one of the supported languages.
    """
    if format_ is not None and "/" not in format_:
        raise NotAMimeTypeException(format_)

    if encodingformat is not None and "/" not in encodingformat:
        raise NotAMimeTypeException(encodingformat)

    if language is not None and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    args = {
        "identifier": identifier,
        "name": name,
        "title": title,
        "description": description,
        "creator": creator,
        "contributor": contributor,
        "format": format_,
        "encodingFormat": encodingformat,
        "source": source,
        "subject": subject,
        "contentUrl": contenturl,
        "license": license,
        "inLanguage": inlanguage,
    }
    if date:
        args["date"] = _Neo4jDate(date)
    if language:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("UpdateAudioObject", args)
Beispiel #6
0
def create_annotation(creator: str,
                      motivation: AnnotationSchemaMotivation,
                      target_url: str = None,
                      body_url: List[str] = None):
    """Return a mutation for making a web Annotation (https://www.w3.org/TR/annotation-model)

    Arguments:
        creator: a URI to the identity of the user who created this Annotation
        motivation: a AnnotationSchemaMotivation value, or the ID of an AnnotationCEMotivation node
        target_url: if the target is the URL of an external object, the URL
        body_url: if the body is the URL of an external object, the URL

    Returns:
        A GraphQL Mutation to create an Annotation in the Trompa CE
    """

    check_required_args(creator=creator, motivation=motivation)
    params = {
        "creator": creator,
        "motivation": StringConstant(motivation.name),
        "targetUrl": target_url,
        "bodyUrl": body_url,
    }
    params = filter_none_args(params)

    return format_mutation(mutationname="CreateAnnotation", args=params)
Beispiel #7
0
def create_annotation_textual_body(creator: str,
                                   value: str,
                                   format_: str = None,
                                   language: str = None):
    """Return a mutation for making an AnnotationTextualBody.
    An AnnotationTextualBody is the main written body of a
    web Annotation (https://www.w3.org/TR/annotation-model).

    Arguments:
        creator: a URI to the identity of the user who created this AnnotationTextualBody
        value: the text for the body of the annotation
        format_: the mimetype that value is formatted in
        language: the language that value is written in

    Returns:
        A GraphQL Mutation to create an AnnotationTextualBody in the Trompa CE
    """

    check_required_args(creator=creator, value=value)

    if language and language.lower() not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    params = {"creator": creator, "value": value, "format": format_}

    if language is not None:
        params["language"] = StringConstant(language.lower())

    return format_mutation(mutationname="CreateAnnotationTextualBody",
                           args=params)
Beispiel #8
0
def create_annotation_motivation(
        creator: str,
        title: str,
        description: str,
        broader_schema: AnnotationSchemaMotivation = None,
        broader_url: str = None):
    """Return a mutation for making an Annotation motivation
    A custom motivation should be a special case of one of the standard 13 motivations in
    the web annotation vocabulary (https://www.w3.org/TR/annotation-vocab/#named-individuals),
    or a URL pointing to an external motivation

    Arguments:
        creator: a URI to the identity of the user who created this Motivation
        title: a descriptive name for the motivation
        description: a detailed description of the motivation
        broader_schema: a AnnotationSchemaMotivation value describing what this motivation is
           a special case of
        broader_url: a URL to an oa:Motivation describing what this motivation is a special case of
    """
    params = {
        "creator": creator,
        "title": title,
        "description": description,
        "broaderUrl": broader_url,
    }
    if broader_schema:
        params["broaderMotivation"] = StringConstant(broader_schema.name)
    params = filter_none_args(params)
    return format_mutation(mutationname="CreateAnnotationCEMotivation",
                           args=params)
Beispiel #9
0
    def test_create(self):
        expected = self.read_file(
            os.path.join(self.data_dir, "create_propery.txt"))

        created_property = mutation_create_property(
            "MusicXML file",
            "targetFile", [StringConstant("DigitalDocument")],
            description="Select a MusicXML file to be converted.")
        self.assert_queries_equal(created_property, expected)
Beispiel #10
0
def mutation_create_entry_point(*,
                                name: str,
                                contributor: str,
                                subject: str,
                                creator: str,
                                source: str,
                                language: str,
                                actionPlatform: str,
                                contentType: List,
                                encodingType: list,
                                formatin="text/html",
                                identifier=None,
                                description: str = None):
    """Returns a mutation for creating an entry point object
    Arguments:
        name: The name of the entry point.
        contributor: A person, an organization, or a service responsible for contributing the aentry point to the web resource. This can be either a name or a base URL.
        creator: The person, organization or service who created the thing the entry point is about.
        source: The URL of the web resource to be represented by the node.
        description: An account of the entry point..
        language: The language the metadata is written in. Currently supported languages are en,es,ca,nl,de,fr.
        actionPlatform: The action platform.
        contentType: The content type associated with the entry point, should be a mimetype.
        encodingType: The encoding type associated with the entry point, should be a mimetype.
    Returns:
        The string for the mutation for creating the artist.
    Raises:
        Assertion error if the input language is not one of the supported languages.
    """
    if language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)
    if "/" not in formatin:
        raise NotAMimeTypeException(formatin)
    if not all("/" in x for x in contentType):
        missing_list = [x for x in contentType if "/" not in x]
        raise NotAMimeTypeException(missing_list)
    if not all("/" in x for x in encodingType):
        missing_list = [x for x in encodingType if "/" not in x]
        raise NotAMimeTypeException(missing_list)

    args = {
        "title": name,
        "name": name,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "subject": subject,
        "description": description,
        "format": formatin,
        "language": StringConstant(language.lower()),
        "actionPlatform": actionPlatform,
        "contentType": contentType,
        "encodingType": encodingType
    }
    if identifier:
        args["identifier"] = identifier
    return mutation_create(args, CREATE_ENTRYPOINT)
Beispiel #11
0
def mutation_create_music_composition(*,
                                      title: str,
                                      contributor: str,
                                      creator: str,
                                      source: str,
                                      format_: str,
                                      subject: str = None,
                                      language: str = None,
                                      inlanguage: str = None,
                                      name: str = None,
                                      description: str = None,
                                      position: int = None):
    """Returns a mutation for creating a music composition object

    Args:
        {musiccomposition_args}

    Returns:
        The string for the mutation for creating the music composition.

    Raises:
        UnsupportedLanguageException: if ``language`` is not one of the supported languages.
        NotAMimeTypeException: if ``format_`` is not a valid mimetype
    """
    check_required_args(title=title,
                        contributor=contributor,
                        creator=creator,
                        source=source,
                        format_=format_)
    if language and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    if "/" not in format_:
        raise NotAMimeTypeException(format_)

    args = {
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "format": format_,
        "subject": subject,
        "source": source,
        "inLanguage": inlanguage,
        "name": name,
        "description": description,
        "position": position
    }
    if language is not None:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("CreateMusicComposition", args)
Beispiel #12
0
def mutation_create_musicrecording(*,
                                   name: str = None,
                                   title: str,
                                   description: str,
                                   contributor: str,
                                   creator: str,
                                   source: str,
                                   format_: str,
                                   encodingformat: str = None,
                                   subject: str = None,
                                   language: str = None,
                                   date: str = None):
    """Returns a mutation for creating a MusicRecording object.
    https://schema.org/MusicRecording

    Arguments:
        {musicrecording_args}

    Returns:
        The string for the mutation for creating the MusicRecording.
    """
    check_required_args(title=title,
                        contributor=contributor,
                        creator=creator,
                        source=source,
                        format_=format_)

    if "/" not in format_:
        raise NotAMimeTypeException(format_)

    if language is not None and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    args = {
        "name": name,
        "title": title,
        "description": description,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "encodingFormat": encodingformat,
        "subject": subject
    }

    if language is not None:
        args["language"] = StringConstant(language.lower())
    if date is not None:
        args["date"] = _Neo4jDate(date)

    args = filter_none_args(args)

    return format_mutation("CreateMusicRecording", args)
Beispiel #13
0
def mutation_update_music_composition(identifier: str,
                                      *,
                                      title: str = None,
                                      contributor: str = None,
                                      creator: str = None,
                                      source: str = None,
                                      format_: str = None,
                                      subject: str = None,
                                      language: str = None,
                                      inlanguage: str = None,
                                      name: str = None,
                                      description: str = None,
                                      position: int = None):
    """Returns a mutation for updating a MusicComposition object.
    
    Args:
        identifier: The identifier of the MusicComposition in the CE to be updated
        {musiccomposition_args}

    Returns:
        The string for the mutation for updating the music composition.
    Raises:
        UnsupportedLanguageException: if ``language`` is not one of the supported languages.
        NotAMimeTypeException: if ``format_`` is not a valid mimetype
    """

    if language and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    if format_ and "/" not in format_:
        raise NotAMimeTypeException(format_)

    args = {
        "identifier": identifier,
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "subject": subject,
        "source": source,
        "inLanguage": inlanguage,
        "format": format_,
        "name": name,
        "description": description,
        "position": position
    }
    if language is not None:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("UpdateMusicComposition", args)
Beispiel #14
0
def mutation_update_controlaction_status(controlaction_id: str,
                                         action_status: ActionStatusType):
    """Returns a mutation for updating the status of a control action to an object
    Arguments:
        controlaction_id: The unique identifier of the control action.
        action_status: the action status enum object.
    Returns:
        The string for the mutation for adding a control action to an object.
        """
    args = {
        "identifier": controlaction_id,
        "actionStatus": StringConstant(str(action_status))
    }
    return format_mutation("UpdateControlAction", args)
Beispiel #15
0
def mutation_update_musicrecording(identifier: str,
                                   *,
                                   title: str = None,
                                   contributor: str = None,
                                   creator: str = None,
                                   source: str = None,
                                   encodingformat: str = None,
                                   format_: str = None,
                                   name: str = None,
                                   language: str = None,
                                   description: str = None,
                                   date: str = None,
                                   subject: str = None):
    """Returns a mutation for updating a MusicRecording object.
    https://schema.org/MusicRecording

    Arguments:
        identifier: The identifier of the MusicRecording in the CE to be updated
        {musicrecording_args}

    Returns:
        The string for the mutation for updating the MusicRecording.
    """
    if format_ is not None and "/" not in format_:
        raise NotAMimeTypeException(format_)

    if language is not None and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    args = {
        "identifier": identifier,
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "name": name,
        "description": description,
        "encodingFormat": encodingformat,
        "subject": subject
    }

    if date is not None:
        args["date"] = _Neo4jDate(date)
    if language is not None:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("UpdateMusicRecording", args)
Beispiel #16
0
def mutation_create_digitaldocument(*,
                                    title: str,
                                    contributor: str,
                                    creator: str,
                                    source: str,
                                    format_: str,
                                    subject: str = None,
                                    language: str = None,
                                    description: str = None):
    """Returns a mutation for creating a digital document object.

    Arguments:
        {digitaldocument_args}

    Returns:
        The string for the mutation for creating the digital document.

    Raises:
        UnsupportedLanguageException if the input language is not one of the supported languages.
        NotAMimeTypeException: if ``format_`` is not a valid mimetype.
    """
    check_required_args(title=title,
                        contributor=contributor,
                        creator=creator,
                        source=source,
                        format_=format_)
    if language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    if "/" not in format_:
        raise NotAMimeTypeException(format_)

    args = {
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "subject": subject,
        "description": description,
    }
    if language is not None:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("CreateDigitalDocument", args)
Beispiel #17
0
def mutation_update_musicgroup(identifier: str, *, title: str = None, contributor: str = None, creator: str = None,
                               source: str = None, format_: str = None, language: str = None, name: str = None,
                               founding_date: str = None, disolution_date: str = None,
                               description: str = None, image: str = None, publisher: str = None):
    """Returns a mutation for updating a MusicGroup

    Args:
        identifier: The identifier of the musicgroup in the CE to be updated
        {musicgroup_args}
    Returns:
        The string for the mutation for updating the musicgroup.
    Raises:
        UnsupportedLanguageException: if ``language`` is not one of the supported languages.
        ValueError: if ``gender`` is not a value supported by the Ce
        NotAMimeTypeException: if ``format_`` is not a valid mimetype.
    """

    if language and language.lower() not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    if format_ and "/" not in format_:
        raise NotAMimeTypeException(format_)

    args = {
        "identifier": identifier,
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "name": name,
        "description": description,
        "image": image,
        "publisher": publisher,
    }
    if language is not None:
        args["language"] = StringConstant(language.lower())
    if founding_date is not None:
        args["foundingDate"] = _Neo4jDate(founding_date)
    if disolution_date is not None:
        args["disolutionDate"] = _Neo4jDate(disolution_date)

    args = filter_none_args(args)

    return format_mutation("UpdateMusicGroup", args)
def query_musiccomposition(identifier: str = None, title: str = None, contributor: str = None, creator: str = None,
                           source: str = None, inlanguage: str = None, name: str = None, position: int = None,
                           filter_: dict = None, return_items: Union[list, str] = None):
    """Returns a query for querying the database for a music composition.
    Arguments:
        identifier: The identifier of the music composition in the CE.
        title: The title of the resource indicated by `source`
        creator: The person, organization or service who created the thing the web resource is about.
        contributor: A person, an organization, or a service responsible for contributing\
                  the music composition to the web resource. This can be either a name or a base URL.
        source: The source URL that an item comes from
        inlanguage: The language of the music composition. Currently supported languages are en,es,ca,nl,de,fr
        name: The name of the music composition.
        position: In the case that this is a movement of a larger work (e.g. a Symphony), the position of this
                  MusicComposition in the larger one.
        filter_: return nodes with this custom filter
        return_items: return these items in the response
    Returns:
        The string for the quereing the music composition.
    Raises:
        UnsupportedLanguageException if the input language is not one of the supported languages.
    """

    if return_items is None:
        return_items = ["identifier", "title", "source"]

    if inlanguage and inlanguage not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(inlanguage)

    args = {
        "identifier": identifier,
        "title": title,
        "source": source,
        "contributor": contributor,
        "creator": creator,
        "inLanguage": inlanguage,
        "name": name,
        "position": position
    }
    if filter_:
        args["filter"] = StringConstant(make_filter(filter_))

    args = filter_none_args(args)

    return format_query("MusicComposition", args, return_items)
Beispiel #19
0
def query_mediaobject(identifier: str = None,
                      creator: str = None,
                      contributor: str = None,
                      encodingformat: str = None,
                      source: str = None,
                      contenturl: str = None,
                      inlanguage: str = None,
                      filter_: dict = None,
                      return_items: Union[list, str] = None):
    """Returns a query for querying the database for a media object.
    Arguments:
        identifier: The identifier of the media object in the CE.
        creator: The person, organization or service who created the thing the web resource is about.
        contributor: A person, an organization, or a service responsible for contributing\
         the media object to the web resource. This can be either a name or a base URL.
        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.
        contenturl: The URL of the content encoded by the media object.
        inlanguage: The language of the media object. Currently supported languages are en,es,ca,nl,de,fr.
        filter_: return nodes with this custom filter
        return_items: return these items in the response
    Returns:
        The string for the quereing the media object.
    Raises:
        UnsupportedLanguageException if the input language is not one of the supported languages.
    """

    if return_items is None:
        return_items = ["identifier", "name"]

    args = {
        "identifier": identifier,
        "creator": creator,
        "contributor": contributor,
        "encodingFormat": encodingformat,
        "source": source,
        "contentUrl": contenturl,
        "inLanguage": inlanguage
    }
    if filter_:
        args["filter"] = StringConstant(make_filter(filter_))

    args = filter_none_args(args)

    return format_query("MediaObject", args, return_items)
Beispiel #20
0
def mutation_create_musicgroup(*, title: str, contributor: str, creator: str, source: str, format_: str,
                               language: str = None, name: str = None,
                               founding_date: str = None, disolution_date: str = None,
                               description: str = None, image: str = None, publisher: str = None):
    """Returns a mutation for creating a MusicGroup

    Args:
        {musicgroup_args}
    Returns:
        The string for the mutation for creating the musicgroup.
    Raises:
        UnsupportedLanguageException: if ``language`` is not one of the supported languages.
        NotAMimeTypeException: if ``format_`` is not a valid mimetype.
    """

    check_required_args(title=title, contributor=contributor, creator=creator, source=source, format_=format_)
    if language and language.lower() not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    if "/" not in format_:
        raise NotAMimeTypeException(format_)

    args = {
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "name": name,
        "description": description,
        "image": image,
        "publisher": publisher,
    }
    if language is not None:
        args["language"] = StringConstant(language.lower())
    if founding_date is not None:
        args["foundingDate"] = _Neo4jDate(founding_date)
    if disolution_date is not None:
        args["disolutionDate"] = _Neo4jDate(disolution_date)

    args = filter_none_args(args)

    return format_mutation("CreateMusicGroup", args)
def mutation_create_application(*, name: str, contributor: str, creator: str, source: str, title: str = None,
                                subject: str = None, language: str = None, description: str = None, format_: str = None,
                                softwareversion: str = None):
    """Returns a mutation for creating a software application object
    Arguments:
        name: The name of the software application.
        title: the html title of the page at `source`
        contributor: A person, an organization, or a service responsible for adding the software application. This can be either a name or a base URL.
        creator: The person, organization or service responsible for adding the software application.
        source: The URL of the web resource to be represented by the node.
        subject: The subject associated with the application.
        description: An account of the software application.
        language: The language of the page at `source`. Currently supported languages are en,es,ca,nl,de,fr
        softwareversion: the version of the software
    Returns:
        The string for the mutation for creating the artist.
    Raises:
        UnsupportedLanguageException if the input language is not one of the supported languages.
        NotAMimeTypeException if format_ is not a valid mimetype.
    """

    if language and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)
    if format_ and "/" not in format_:
        raise NotAMimeTypeException(format_)

    args = {
        "name": name,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "title": title,
        "subject": subject,
        "description": description,
        "format": format_,
        "softwareVersion": softwareversion
    }
    if language:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)
    return mutation_create(args, CREATE_APPLICATION)
def mutation_update_musicplaylist(identifier: str,
                                  *,
                                  title: str,
                                  contributor: str,
                                  creator: str,
                                  source: str,
                                  format_: str,
                                  name: str = None,
                                  language: str = None,
                                  num_tracks: int = None):
    """Returns a mutation for updating a MusicPlaylist object.

    Arguments:
        identifier: The identifier of the MusicPlaylist in the CE to be updated
        {musicplaylist_args}

    Returns:
        The string for the mutation for updating the MusicPlaylist.
    """
    if format_ is not None and "/" not in format_:
        raise NotAMimeTypeException(format_)

    if language is not None and language not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    args = {
        "identifier": identifier,
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "name": name,
        "numTracks": num_tracks
    }
    if language is not None:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("UpdateMusicPlaylist", args)
Beispiel #23
0
def update_annotation_textual_body(identifier: str,
                                   value: str = None,
                                   format_: str = None,
                                   language: str = None):
    """Return a mutation for updating an AnnotationTextualBody.

    Returns:
        A GraphQL Mutation to update an AnnotationTextualBody in the Trompa CE
    """
    check_required_args(identifier=identifier)
    if language and language.lower() not in SUPPORTED_LANGUAGES:
        raise UnsupportedLanguageException(language)

    params = {"identifier": identifier, "value": value, "format": format_}
    params = filter_none_args(params)

    if language is not None:
        params["language"] = StringConstant(language.lower())

    return format_mutation(mutationname="UpdateAnnotationTextualBody",
                           args=params)
Beispiel #24
0
def mutation_update_digitaldocument(identifier: str,
                                    *,
                                    title: str = None,
                                    contributor: str = None,
                                    creator: str = None,
                                    source: str = None,
                                    format_: str = None,
                                    subject: str = None,
                                    language: str = None,
                                    description: str = None):
    """Returns a mutation for updating a digital document object.

    Arguments:
        identifier: The identifier of the media object in the CE to be updated.
        {digitaldocument_args}

    Returns:
        The string for the mutation for creating the artist.

    Raises:
        Assertion error if the input language is not one of the supported languages.
    """

    args = {
        "identifier": identifier,
        "title": title,
        "contributor": contributor,
        "creator": creator,
        "source": source,
        "format": format_,
        "subject": subject,
        "description": description
    }
    if language is not None:
        args["language"] = StringConstant(language.lower())

    args = filter_none_args(args)

    return format_mutation("UpdateDigitalDocument", args)
Beispiel #25
0
def mutation_update_itemlist(identifier: str,
                             name: str = None,
                             creator: str = None,
                             itemlistorder: ItemListOrderType = None,
                             description: str = None,
                             contributor: str = None,
                             additionaltype: List[str] = None):
    """Returns a mutation for updating an ItemList object.
    (https://schema.org/ItemList)

    Arguments:
        identifier: The identifier of the ItemList in the CE to be updated.
        {itemlist_args}

    Returns:
        The string for the mutation for updating the ItemList.
    """
    if itemlistorder is not None and not isinstance(itemlistorder,
                                                    ItemListOrderType):
        raise trompace.exceptions.InvalidItemListOrderTypeException(
            itemlistorder)
    check_required_args(identifier=identifier)
    additionaltype = _verify_additional_type(additionaltype)

    args = {
        "identifier": identifier,
        "contributor": contributor,
        "name": name,
        "description": description,
        "creator": creator,
        "additionalType": additionaltype,
    }
    if itemlistorder is not None:
        args["itemListOrder"] = StringConstant(itemlistorder)

    args = filter_none_args(args)

    return format_mutation("UpdateItemList", args)
Beispiel #26
0
def update_annotation_motivation(
        identifier: str,
        creator: str,
        title: str,
        description: str,
        broader_schema: AnnotationSchemaMotivation = None,
        broader_url: str = None):
    """Return a mutation for updating an Annotation motivation

    """
    check_required_args(identifier=identifier)
    params = {
        "identifier": identifier,
        "creator": creator,
        "title": title,
        "description": description,
        "broaderUrl": broader_url,
    }
    if broader_schema:
        params["broaderMotivation"] = StringConstant(broader_schema.name)
    params = filter_none_args(params)
    return format_mutation(mutationname="UpdateAnnotationCEMotivation",
                           args=params)
Beispiel #27
0
def mutation_modify_controlaction(controlaction_id: str,
                                  actionstatus: ActionStatusType,
                                  error: str = None):
    """Returns a mutation for modifying the status and errors of the ControlAction
    Arguments:
        controlaction_id: The unique identifier of the ControlAction.
        actionstatus: the status to update to.
        error: An error to set if the actionstatus is FailedActionStatus
    Returns:
        The string for the mutation for modifying a ControlAction.
    """

    if not isinstance(actionstatus, ActionStatusType):
        raise trompace.exceptions.InvalidActionStatusException(actionstatus)

    args = {
        "identifier": controlaction_id,
        "actionStatus": StringConstant(actionstatus)
    }
    if error:
        args["error"] = error

    return mutation_create(args, UPDATE_CONTROLACTION)
Beispiel #28
0
def mutation_create_controlaction(
        name: str,
        actionstatus: ActionStatusType = ActionStatusType.
    PotentialActionStatus,
        description: str = None):
    """Returns a mutation for creating a ControlAction.
    If an action status is not set, defaults to a PotentialActionStatus
    Arguments:
        name: The name of the ControlAction.
        description: An account of the ControlAction.
        actionstatus: The status of the ControlAction.
    Returns:
        The string for the mutation for creating the ControlAction object.
    """

    if not isinstance(actionstatus, ActionStatusType):
        raise trompace.exceptions.InvalidActionStatusException(actionstatus)

    args = {
        "name": name,
        "description": description,
        "actionStatus": StringConstant(actionstatus)
    }
    return mutation_create(args, CREATE_CONTROLACTION)
def create_defined_term_set(*, creator: str, name: str, additionaltype: List[str], broader_url: str = None,
                            broader_schema: annotation.AnnotationSchemaMotivation = None, image: str = None):
    """Return a mutation for making a DefinedTermSet.
    A :schema:`DefinedTermSet` is a group of defined terms, e.g. categories or labels.

    Arguments:
        {definedtermset_args}

    Returns:
        A GraphQL Mutation to create a DefinedTermSet in the Trompa CE
    """

    check_required_args(creator=creator, name=name, additionaltype=additionaltype)
    additionaltype = _verify_additional_type(additionaltype)

    params = {"additionalType": additionaltype,
              "creator": creator,
              "name": name,
              "broaderUrl": broader_url,
              "image": image}
    if broader_schema is not None:
        params["broaderMotivation"] = StringConstant(broader_schema.name)
    params = filter_none_args(params)
    return format_mutation(mutationname="CreateDefinedTermSet", args=params)
async def request_controlaction(req_config_file='req_config1.ini'):
    """
    Request a control action based on the configurations in the req_config_file
    Arguments:
        req_config_file: The ini file with the configuration for the request to be sent.
    Raises:
        ValueNotFound exception if one of the required values for the property or property value specifications is not set.
    """
    config = configparser.ConfigParser()
    config.read(req_config_file)

    entrypoint_id = config['EntryPoint']['ce_id']
    controlaction_id = config['ControlAction']['ce_id']
    num_props = int(config['ControlAction']['numprops'])
    num_pvs = int(config['ControlAction']['numpvs'])
    props = []
    pvss = []
    for i in range(num_props):
        prop_dict = {}
        prop = config['Property{}'.format(i + 1)]
        prop_dict['potentialActionPropertyIdentifier'] = prop['ce_id']
        if prop['value'] == '':
            raise ValueNotFound('potentialActionPropertyIdentifier{}'.format(1 + 1))
        prop_dict['nodeIdentifier'] = prop['value']
        prop_dict['nodeType'] = StringConstant(prop['rangeincludes'])
        # TODO: Right now, assumes that only one value is given.
        prop_params = make_parameters(**prop_dict)
        props.append("{{{}}}".format(prop_params))

    for i in range(num_pvs):
        pvs_dict = {}
        pvs = config['PropertyValueSpecification{}'.format(i + 1)]
        pvs_dict['potentialActionPropertyValueSpecificationIdentifier'] = pvs['ce_id']
        if pvs['value'] == '' and pvs.getboolean('valuerequired'):
            raise ValueNotFound('potentialActionPropertyValueSpecificationIdentifier{}'.format(1 + 1))
        pvs_dict['value'] = pvs['value']
        pvs_dict['valuePattern'] = StringConstant(pvs['valuepattern'])
        pvs_params = make_parameters(**pvs_dict)
        pvss.append("{{{}}}".format(pvs_params))
    param_dict = {"entryPointIdentifier": entrypoint_id, "potentialActionIdentifier": controlaction_id, \
                  "propertyObject": props, "propertyValueObject": pvss}
    params = make_parameters(**param_dict)

    params = params.replace("\\n", "\n").replace("\\", "").replace("\"\"", "\"").replace("\"{", "{").replace("}\"", "}")

    query = q1.format(params=params)

    resp_1 = await submit_query(query)

    output_id = resp_1['data']['RequestControlAction']['identifier']

    # await subscribe_controlaction(control_id)

    status_query = q2.format(control_id=output_id)

    act_status = 'accepted'

    while act_status == 'accepted' or act_status == 'running':
        await asyncio.sleep(1)

        resp_2 = await submit_query(status_query)

        act_status = resp_2['data']['ControlAction'][0]['actionStatus']

        print("Action Status: {}".format(act_status))