Passed
Push — master ( c5801a...8fec65 )
by Jeffrey
05:00
created

goblin.provider.JanusGraph.get_hashable_id()   A

Complexity

Conditions 5

Size

Total Lines 14
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 14
nop 1
dl 0
loc 14
rs 9.2333
c 0
b 0
f 0
1
from typing import Dict, Any
2
3
class Provider:
4
    """Superclass for provider plugins"""
5
    DEFAULT_OP_ARGS: Dict[Any, Any] = {}
6
7
    @classmethod
8
    def get_default_op_args(cls, processor):
9
        return cls.DEFAULT_OP_ARGS.get(processor, dict())
10
11
12
class TinkerGraph(Provider):  # TODO
13
    """Default provider"""
14
15
    @staticmethod
16
    def get_hashable_id(val):
17
        return val
18
19
class JanusGraph(Provider):  # TODO
20
    """Default provider"""
21
22
    @staticmethod
23
    def get_hashable_id(val):
24
        if not isinstance(val, dict):
25
            return val
26
        type_prop = val.get("@type", None)
27
        if not type_prop == "janusgraph:RelationIdentifier":
28
            return val
29
        val_prop = val.get("@value", None)
30
        if not isinstance(val_prop, dict):
31
            return val
32
        rel_prop = val_prop.get("relationId", None)
33
        if not rel_prop:
34
            return val
35
        return rel_prop
36
37