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);
}
}
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);
}
}
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;
});
}
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;
}
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;
}
Aggregations