Example #1
0
def create_link(supported_property: Dict[str, Any]) -> HydraLink:
    """
    Creates the instances of HydraLink

    :param supported_property: expanded Property
    :return: instance of HydraLink
    """
    prop_title = 'The default Link title'
    prop_desc = 'The default Link description'

    prop_id = check_namespace(supported_property['@id'])
    if hydra['description'] in supported_property:
        prop_desc = supported_property[hydra['description']]
    if hydra['title'] in supported_property:
        prop_title = supported_property[hydra['title']][0]['@value']

    prop_domain = check_namespace(supported_property[rdfs['domain']][0]['@id'])
    prop_range = check_namespace(supported_property[rdfs['range']][0]['@id'])

    link_ = HydraLink(prop_id, prop_title, prop_desc, prop_domain, prop_range)

    if hydra['supportedOperation'] in supported_property:
        for operations in supported_property[hydra['supportedOperation']]:
            operation = create_operation(operations)
            link_.add_supported_op(operation)

    return link_
Example #2
0
def create_link_property(link_prop_dict: Dict[str, Any]) -> HydraLink:
    """Create HydraLink objects for link properties in the API Documentation."""
    id_ = link_prop_dict["@id"]

    doc_keys = {
        "title": False,
        "description": False,
        "supportedOperation": False,
        "range": False,
        "domain": False
    }

    result = {}
    for k, literal in doc_keys.items():
        result[k] = input_key_check(link_prop_dict, k, "link_prop", literal)

    # Create the HydraLink object
    link = HydraLink(id_, result["title"], result["description"],
                     result["domain"], result["range"])

    # Add supportedOperation for the Link
    for op in result["supportedOperation"]:
        op_obj = create_operation(op)
        link.add_supported_op(op_obj)

    return link
class_2_op4_status = [HydraStatus(code=200, desc="singleClass returned.")]
class_2_op4 = HydraClassOp("GetClass", "GET", None, class_2.id_, [], [],
                           class_2_op4_status)

class_1_op1_status = [
    HydraStatus(code=200, desc="anotherSingleClass returned.")
]
class_1_op1 = HydraClassOp("GetClass", "GET", None, class_1.id_, [], [],
                           class_1_op1_status)
# Add the properties to the classes
class_.add_supported_prop(dummyProp1)
class_.add_supported_prop(dummyProp2)
class_2.add_supported_prop(dummyProp1)
class_2.add_supported_prop(dummyProp2)
dummy_prop_link = HydraLink("singleClass/dummyProp",
                            "dummyProp",
                            domain=class_2.id_,
                            range_=class_.id_)
class_2.add_supported_prop(
    HydraClassProp(dummy_prop_link,
                   "dummyProp",
                   required=False,
                   read=False,
                   write=True))
class_2.add_supported_prop(
    HydraClassProp(class_1.id_,
                   "singleClassProp",
                   required=False,
                   read=False,
                   write=True))
class_1.add_supported_prop(dummyProp1)
# Add the operations to the classes
Example #4
0
class_2_op4_status = [HydraStatus(code=200, desc="singleClass returned.")]
class_2_op4 = HydraClassOp("GetClass", "GET", None, "vocab:singleClass", [],
                           [], class_2_op4_status)

class_1_op1_status = [
    HydraStatus(code=200, desc="anotherSingleClass returned.")
]
class_1_op1 = HydraClassOp("GetClass", "GET", None, "vocab:anotherSingleClass",
                           [], [], class_1_op1_status)
# Add the properties to the classes
class_.add_supported_prop(dummyProp1)
class_.add_supported_prop(dummyProp2)
class_2.add_supported_prop(dummyProp1)
class_2.add_supported_prop(dummyProp2)
dummy_prop_link = HydraLink("singleClass/dummyProp",
                            "dummyProp",
                            domain="vocab:singleClass",
                            range_="vocab:dummyClass")
class_2.add_supported_prop(
    HydraClassProp(dummy_prop_link,
                   "dummyProp",
                   required=False,
                   read=False,
                   write=True))
class_2.add_supported_prop(
    HydraClassProp("vocab:anotherSingleClass",
                   "singleClassProp",
                   required=False,
                   read=False,
                   write=True))
class_1.add_supported_prop(dummyProp1)
# Add the operations to the classes