private Schema . BaseType getBaseType ( VertexElement vertex ) { try { return Schema . BaseType . valueOf ( vertex . label ( ) ) ; } catch ( IllegalArgumentException e ) { //Base type appears to be invalid. Let's try getting the type via the shard edge Optional < VertexElement > type = vertex . getEdgesOfType ( Direction . OUT , Schema . EdgeLabel . SHARD ) . map ( EdgeElement :: target ) . findAny ( ) ; if ( type . isPresent ( ) ) { String label = type . get ( ) . label ( ) ; if ( label . equals ( Schema . BaseType . ENTITY_TYPE . name ( ) ) ) return Schema . BaseType . ENTITY ; if ( label . equals ( RELATION_TYPE . name ( ) ) ) return Schema . BaseType . RELATION ; if ( label . equals ( Schema . BaseType . ATTRIBUTE_TYPE . name ( ) ) ) return Schema . BaseType . ATTRIBUTE ; } } throw new IllegalStateException ( "Could not determine the base type of vertex [" + vertex + "]" ) ; }
This is a helper method to get the base type of a vertex . It first tried to get the base type via the label . If this is not possible it then tries to get the base type via the Shard Edge .