Search in sources :

Example 1 with Relationship

use of ai.grakn.engine.controller.response.Relationship in project grakn by graknlabs.

the class JsonConceptBuilder method build.

public static <X extends Concept> X build(String jsonRepresentation) {
    Schema.BaseType baseType = Schema.BaseType.valueOf(Json.read(jsonRepresentation).at("base-type").asString());
    Concept concept;
    try {
        switch(baseType) {
            case ROLE:
                concept = mapper.readValue(jsonRepresentation, Role.class);
                break;
            case RULE:
                concept = mapper.readValue(jsonRepresentation, Rule.class);
                break;
            case TYPE:
                concept = mapper.readValue(jsonRepresentation, MetaConcept.class);
                break;
            case ENTITY_TYPE:
                concept = mapper.readValue(jsonRepresentation, EntityType.class);
                break;
            case ENTITY:
                concept = mapper.readValue(jsonRepresentation, Entity.class);
                break;
            case ATTRIBUTE_TYPE:
                concept = mapper.readValue(jsonRepresentation, AttributeType.class);
                break;
            case ATTRIBUTE:
                concept = mapper.readValue(jsonRepresentation, Attribute.class);
                break;
            case RELATIONSHIP_TYPE:
                concept = mapper.readValue(jsonRepresentation, RelationshipType.class);
                break;
            case RELATIONSHIP:
                concept = mapper.readValue(jsonRepresentation, Relationship.class);
                break;
            default:
                throw new UnsupportedOperationException(String.format("Cannot wrap object of base type {%s}", baseType));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return (X) concept;
}
Also used : MetaConcept(ai.grakn.engine.controller.response.MetaConcept) Concept(ai.grakn.engine.controller.response.Concept) Entity(ai.grakn.engine.controller.response.Entity) Attribute(ai.grakn.engine.controller.response.Attribute) Schema(ai.grakn.util.Schema) RelationshipType(ai.grakn.engine.controller.response.RelationshipType) IOException(java.io.IOException) Role(ai.grakn.engine.controller.response.Role) EntityType(ai.grakn.engine.controller.response.EntityType) AttributeType(ai.grakn.engine.controller.response.AttributeType) Relationship(ai.grakn.engine.controller.response.Relationship) Rule(ai.grakn.engine.controller.response.Rule) MetaConcept(ai.grakn.engine.controller.response.MetaConcept)

Aggregations

Attribute (ai.grakn.engine.controller.response.Attribute)1 AttributeType (ai.grakn.engine.controller.response.AttributeType)1 Concept (ai.grakn.engine.controller.response.Concept)1 Entity (ai.grakn.engine.controller.response.Entity)1 EntityType (ai.grakn.engine.controller.response.EntityType)1 MetaConcept (ai.grakn.engine.controller.response.MetaConcept)1 Relationship (ai.grakn.engine.controller.response.Relationship)1 RelationshipType (ai.grakn.engine.controller.response.RelationshipType)1 Role (ai.grakn.engine.controller.response.Role)1 Rule (ai.grakn.engine.controller.response.Rule)1 Schema (ai.grakn.util.Schema)1 IOException (java.io.IOException)1