use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class Resource method info.
/**
* Return information on the node, like name etc.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public String info() {
final Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// TODO: Name the number of documents in the index
kresp.addMessage(680, "Server is up and running!");
return kresp.toJsonString();
}
use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class Resource method find.
// PUT: Return corpus info for virtual corpus
/**
* Find matches in the lucene index based on UIDs and return one
* match per doc.
*
* @param text_id
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String find(String json, @Context UriInfo uri) {
final Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// Search index
final Krill ks = new Krill(json);
// Get query parameters
final MultivaluedMap<String, String> qp = uri.getQueryParameters();
if (qp.get("uid") == null) {
kresp.addError(610, "Missing request parameters", "No unique IDs were given");
return kresp.toJsonString();
}
;
// Build Collection based on a list of uids
final List<String> uids = qp.get("uid");
// TODO: RESTRICT COLLECTION TO ONLY RESPECT SELF DOCS (REPLICATION)
// Ignore a Collection that may already be established
final KrillCollection kc = new KrillCollection();
kc.filterUIDs(uids.toArray(new String[uids.size()]));
ks.setCollection(kc);
// Only return the first match per text
ks.getMeta().setItemsPerResource(1);
return ks.apply(Node.getIndex()).toJsonString();
}
use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class Resource method add.
/**
* Add new documents to the index
*
* @param json
* JSON-LD string with search and potential meta
* filters.
*/
/*
* Support GZip:
* Or maybe it's already supported ...
* http://stackoverflow.com/questions/19765582/how-to-make-jersey-use-gzip-compression-for-the-response-message-body
*/
@PUT
@Path("/index/{textID}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String add(@PathParam("textID") Integer uid, @Context UriInfo uri, String json) {
// Todo: Parameter for server node
if (DEBUG)
log.trace("Added new document with unique identifier {}", uid);
final Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// Get index
index = Node.getIndex();
FieldDocument fd = index.addDoc(uid, json);
if (fd == null) {
// Set HTTP to ???
// TODO: This may be a field error!
kresp.addError(602, "Unable to add document to index");
return kresp.toJsonString();
}
;
// Set HTTP to 200
kresp.addMessage(681, "Document was added successfully", fd.getID() != null ? fd.getID() : "Unknown");
// Mirror meta data
kresp.addJsonNode("text", (ObjectNode) fd.toJsonNode());
return kresp.toJsonString();
}
use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class TestResponse method testResponseNotifications.
@Test
public void testResponseNotifications() throws IOException {
Response resp = new Response();
JsonNode respJson = mapper.readTree(resp.toJsonString());
assertEquals("http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld", respJson.at("/@context").asText());
assertEquals("", respJson.at("/meta").asText());
resp.setVersion("0.24");
resp.setNode("Tanja");
assertEquals("0.24", resp.getVersion());
assertEquals("Tanja", resp.getNode());
assertFalse(resp.hasWarnings());
assertFalse(resp.hasMessages());
assertFalse(resp.hasErrors());
respJson = mapper.readTree(resp.toJsonString());
assertEquals("0.24", respJson.at("/meta/version").asText());
assertEquals("Tanja", respJson.at("/meta/node").asText());
resp.addWarning(1, "Fehler 1");
resp.addWarning(2, "Fehler 2");
resp.addWarning(3, "Fehler 3");
resp.addError(4, "Fehler 4");
respJson = mapper.readTree(resp.toJsonString());
assertEquals("0.24", respJson.at("/meta/version").asText());
assertEquals("Tanja", respJson.at("/meta/node").asText());
assertEquals("Fehler 1", respJson.at("/warnings/0/1").asText());
assertEquals("Fehler 2", respJson.at("/warnings/1/1").asText());
assertEquals("Fehler 3", respJson.at("/warnings/2/1").asText());
assertEquals("Fehler 4", respJson.at("/errors/0/1").asText());
}
Aggregations