Search in sources :

Example 1 with NotFoundException

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

the class StandardTaskScheduler method findTask.

public <V> HugeTask<V> findTask(Id id) {
    HugeTask<V> result = this.call(() -> {
        Iterator<Vertex> vertices = this.tx().queryVertices(id);
        Vertex vertex = QueryResults.one(vertices);
        if (vertex == null) {
            return null;
        }
        return HugeTask.fromVertex(vertex);
    });
    if (result == null) {
        throw new NotFoundException("Can't find task with id '%s'", id);
    }
    return result;
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) NotFoundException(com.baidu.hugegraph.exception.NotFoundException)

Example 2 with NotFoundException

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

the class PropertyKeyBuilder method eliminate.

@Override
public PropertyKey eliminate() {
    PropertyKey propertyKey = this.propertyKeyOrNull(this.name);
    if (propertyKey == null) {
        throw new NotFoundException("Can't update property key '%s' " + "since it doesn't exist", this.name);
    }
    this.checkStableVars();
    Userdata.check(this.userdata, Action.ELIMINATE);
    propertyKey.removeUserdata(this.userdata);
    this.graph().addPropertyKey(propertyKey);
    return propertyKey;
}
Also used : NotFoundException(com.baidu.hugegraph.exception.NotFoundException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 3 with NotFoundException

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

the class EdgeLabelBuilder method append.

@Override
public EdgeLabel append() {
    EdgeLabel edgeLabel = this.edgeLabelOrNull(this.name);
    if (edgeLabel == null) {
        throw new NotFoundException("Can't update edge label '%s' " + "since it doesn't exist", this.name);
    }
    // These methods will check params and fill to member variables
    this.checkStableVars();
    this.checkProperties(Action.APPEND);
    this.checkNullableKeys(Action.APPEND);
    Userdata.check(this.userdata, Action.APPEND);
    for (String key : this.properties) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        edgeLabel.property(propertyKey.id());
    }
    for (String key : this.nullableKeys) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        edgeLabel.nullableKey(propertyKey.id());
    }
    edgeLabel.userdata(this.userdata);
    this.graph().addEdgeLabel(edgeLabel);
    return edgeLabel;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 4 with NotFoundException

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

the class CassandraTable method queryId2Select.

protected List<Select> queryId2Select(Query query, Select select) {
    // Query by id(s)
    if (query.idsSize() == 0) {
        return ImmutableList.of(select);
    }
    List<HugeKeys> nameParts = this.idColumnName();
    List<List<Object>> ids = new ArrayList<>(query.idsSize());
    for (Id id : query.ids()) {
        List<Object> idParts = this.idColumnValue(id);
        if (nameParts.size() != idParts.size()) {
            throw new NotFoundException("Unsupported ID format: '%s' (should contain %s)", id, nameParts);
        }
        ids.add(idParts);
    }
    // Query only by partition-key
    if (nameParts.size() == 1) {
        List<Object> idList = new ArrayList<>(ids.size());
        for (List<Object> id : ids) {
            assert id.size() == 1;
            idList.add(id.get(0));
        }
        return this.ids2IdSelects(select, nameParts.get(0), idList);
    }
    /*
         * Query by partition-key + clustering-key
         * NOTE: Error if multi-column IN clause include partition key:
         * error: multi-column relations can only be applied to clustering
         * columns when using: select.where(QueryBuilder.in(names, idList));
         * So we use multi-query instead of IN
         */
    List<Select> selects = new ArrayList<>(ids.size());
    for (List<Object> id : ids) {
        assert nameParts.size() == id.size();
        Select idSelect = cloneSelect(select, this.table());
        /*
             * NOTE: concat with AND relation, like:
             * "pk = id and ck1 = v1 and ck2 = v2"
             */
        for (int i = 0, n = nameParts.size(); i < n; i++) {
            idSelect.where(formatEQ(nameParts.get(i), id.get(i)));
        }
        selects.add(idSelect);
    }
    return selects;
}
Also used : ArrayList(java.util.ArrayList) Select(com.datastax.driver.core.querybuilder.Select) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Id(com.baidu.hugegraph.backend.id.Id) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Example 5 with NotFoundException

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

the class GroupAPI 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 group: {}", graph, id);
    // just check if the graph exists
    @SuppressWarnings("unused") HugeGraph g = graph(manager, graph);
    try {
        manager.authManager().deleteGroup(IdGenerator.of(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid group 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)

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