Search in sources :

Example 21 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class UserAPI method delete.

@DELETE
@Timed
@Path("{id}")
@Consumes(APPLICATION_JSON)
public void delete(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id) {
    LOG.debug("Graph [{}] delete user: {}", graph, id);
    // just check if the graph exists
    @SuppressWarnings("unused") HugeGraph g = graph(manager, graph);
    try {
        manager.authManager().deleteUser(IdGenerator.of(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid user id: " + id);
    }
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) Path(jakarta.ws.rs.Path) DELETE(jakarta.ws.rs.DELETE) Consumes(jakarta.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed)

Example 22 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class EdgeId method parse.

public static EdgeId parse(String id, boolean returnNullIfError) throws NotFoundException {
    String[] idParts = SplicingIdGenerator.split(id);
    if (!(idParts.length == 4 || idParts.length == 5)) {
        if (returnNullIfError) {
            return null;
        }
        throw new NotFoundException("Edge id must be formatted as 4~5 " + "parts, but got %s parts: '%s'", idParts.length, id);
    }
    try {
        if (idParts.length == 4) {
            Id ownerVertexId = IdUtil.readString(idParts[0]);
            Id edgeLabelId = IdUtil.readLong(idParts[1]);
            String sortValues = idParts[2];
            Id otherVertexId = IdUtil.readString(idParts[3]);
            return new EdgeId(ownerVertexId, Directions.OUT, edgeLabelId, sortValues, otherVertexId);
        } else {
            assert idParts.length == 5;
            Id ownerVertexId = IdUtil.readString(idParts[0]);
            HugeType direction = HugeType.fromString(idParts[1]);
            Id edgeLabelId = IdUtil.readLong(idParts[2]);
            String sortValues = idParts[3];
            Id otherVertexId = IdUtil.readString(idParts[4]);
            return new EdgeId(ownerVertexId, Directions.convert(direction), edgeLabelId, sortValues, otherVertexId);
        }
    } catch (Throwable e) {
        if (returnNullIfError) {
            return null;
        }
        throw new NotFoundException("Invalid format of edge id '%s'", e, id);
    }
}
Also used : NotFoundException(com.baidu.hugegraph.exception.NotFoundException) HugeType(com.baidu.hugegraph.type.HugeType)

Example 23 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class GraphTransaction method queryVerticesByIds.

protected Iterator<Vertex> queryVerticesByIds(Object[] vertexIds, boolean adjacentVertex, boolean checkMustExist) {
    Query.checkForceCapacity(vertexIds.length);
    // NOTE: allowed duplicated vertices if query by duplicated ids
    List<Id> ids = InsertionOrderUtil.newList();
    Map<Id, HugeVertex> vertices = new HashMap<>(vertexIds.length);
    IdQuery query = new IdQuery(HugeType.VERTEX);
    for (Object vertexId : vertexIds) {
        HugeVertex vertex;
        Id id = HugeVertex.getIdValue(vertexId);
        if (id == null || this.removedVertices.containsKey(id)) {
            // The record has been deleted
            continue;
        } else if ((vertex = this.addedVertices.get(id)) != null || (vertex = this.updatedVertices.get(id)) != null) {
            if (vertex.expired()) {
                continue;
            }
            // Found from local tx
            vertices.put(vertex.id(), vertex);
        } else {
            // Prepare to query from backend store
            query.query(id);
        }
        ids.add(id);
    }
    if (!query.empty()) {
        // Query from backend store
        query.mustSortByInput(false);
        Iterator<HugeVertex> it = this.queryVerticesFromBackend(query);
        QueryResults.fillMap(it, vertices);
    }
    return new MapperIterator<>(ids.iterator(), id -> {
        HugeVertex vertex = vertices.get(id);
        if (vertex == null) {
            if (checkMustExist) {
                throw new NotFoundException("Vertex '%s' does not exist", id);
            } else if (adjacentVertex) {
                assert !checkMustExist;
                // Return undefined if adjacentVertex but !checkMustExist
                vertex = HugeVertex.undefined(this.graph(), id);
            } else {
                // Return null
                assert vertex == null;
            }
        }
        return vertex;
    });
}
Also used : MapperIterator(com.baidu.hugegraph.iterator.MapperIterator) FlatMapperIterator(com.baidu.hugegraph.iterator.FlatMapperIterator) BatchMapperIterator(com.baidu.hugegraph.iterator.BatchMapperIterator) HashMap(java.util.HashMap) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) IdQuery(com.baidu.hugegraph.backend.query.IdQuery) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 24 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class IndexLabelBuilder method eliminate.

@Override
public IndexLabel eliminate() {
    IndexLabel indexLabel = this.indexLabelOrNull(this.name);
    if (indexLabel == null) {
        throw new NotFoundException("Can't update index label '%s' " + "since it doesn't exist", this.name);
    }
    this.checkStableVars();
    Userdata.check(this.userdata, Action.ELIMINATE);
    indexLabel.removeUserdata(this.userdata);
    SchemaLabel schemaLabel = indexLabel.baseLabel();
    this.graph().addIndexLabel(schemaLabel, indexLabel);
    return indexLabel;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel)

Example 25 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class IndexLabelBuilder method append.

@Override
public IndexLabel append() {
    IndexLabel indexLabel = this.indexLabelOrNull(this.name);
    if (indexLabel == null) {
        throw new NotFoundException("Can't update index label '%s' " + "since it doesn't exist", this.name);
    }
    this.checkStableVars();
    Userdata.check(this.userdata, Action.APPEND);
    indexLabel.userdata(this.userdata);
    SchemaLabel schemaLabel = indexLabel.baseLabel();
    this.graph().addIndexLabel(schemaLabel, indexLabel);
    return indexLabel;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel)

Aggregations

NotFoundException (com.baidu.hugegraph.exception.NotFoundException)30 HugeGraph (com.baidu.hugegraph.HugeGraph)15 Timed (com.codahale.metrics.annotation.Timed)15 Path (jakarta.ws.rs.Path)15 Consumes (jakarta.ws.rs.Consumes)14 DELETE (jakarta.ws.rs.DELETE)8 Produces (jakarta.ws.rs.Produces)7 PUT (jakarta.ws.rs.PUT)6 Id (com.baidu.hugegraph.backend.id.Id)5 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)4 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)3 HugeProject (com.baidu.hugegraph.auth.HugeProject)2 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)2 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)2 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)2 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)2 HugeKeys (com.baidu.hugegraph.type.define.HugeKeys)2 ImmutableList (com.google.common.collect.ImmutableList)2 RolesAllowed (jakarta.annotation.security.RolesAllowed)2 ArrayList (java.util.ArrayList)2