use of org.neo4j.server.rest.repr.BadInputException in project neo4j by neo4j.
the class RestfulGraphDatabase method addNodeLabel.
// Node Labels
@POST
@Path(PATH_NODE_LABELS)
public Response addNodeLabel(@PathParam("nodeId") long nodeId, String body) {
try {
Object rawInput = input.readValue(body);
if (rawInput instanceof String) {
ArrayList<String> s = new ArrayList<>();
s.add((String) rawInput);
actions.addLabelToNode(nodeId, s);
} else if (rawInput instanceof Collection) {
actions.addLabelToNode(nodeId, (Collection<String>) rawInput);
} else {
throw new InvalidArgumentsException(format("Label name must be a string. Got: '%s'", rawInput));
}
} catch (BadInputException e) {
return output.badRequest(e);
} catch (ArrayStoreException ase) {
return generateBadRequestDueToMangledJsonResponse(body);
} catch (NodeNotFoundException e) {
return output.notFound(e);
}
return nothing();
}
use of org.neo4j.server.rest.repr.BadInputException in project neo4j by neo4j.
the class UrlFormFormat method readMap.
@Override
public Map<String, Object> readMap(final String input, String... requiredKeys) throws BadInputException {
HashMap<String, Object> result = new HashMap<String, Object>();
if (input.isEmpty()) {
return result;
}
for (String pair : input.split("\\&")) {
String[] fields = pair.split("=");
String key;
String value;
try {
String charset = StandardCharsets.UTF_8.name();
key = ensureThatKeyDoesNotHavePhPStyleParenthesesAtTheEnd(URLDecoder.decode(fields[0], charset));
value = URLDecoder.decode(fields[1], charset);
} catch (UnsupportedEncodingException e) {
throw new BadInputException(e);
}
Object old = result.get(key);
if (old == null) {
result.put(key, value);
} else {
List<Object> list;
if (old instanceof List<?>) {
list = (List<Object>) old;
} else {
list = new ArrayList<Object>();
result.put(key, list);
list.add(old);
}
list.add(value);
}
}
return DefaultFormat.validateKeys(result, requiredKeys);
}
Aggregations