Search in sources :

Example 11 with Response

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();
}
Also used : Response(de.ids_mannheim.korap.response.Response) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with Response

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();
}
Also used : Response(de.ids_mannheim.korap.response.Response) Krill(de.ids_mannheim.korap.Krill) KrillCollection(de.ids_mannheim.korap.KrillCollection) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 13 with Response

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();
}
Also used : Response(de.ids_mannheim.korap.response.Response) FieldDocument(de.ids_mannheim.korap.index.FieldDocument) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 14 with Response

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());
}
Also used : Response(de.ids_mannheim.korap.response.Response) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Aggregations

Response (de.ids_mannheim.korap.response.Response)14 Produces (javax.ws.rs.Produces)9 Path (javax.ws.rs.Path)7 Consumes (javax.ws.rs.Consumes)4 GET (javax.ws.rs.GET)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Krill (de.ids_mannheim.korap.Krill)3 KrillIndex (de.ids_mannheim.korap.KrillIndex)3 POST (javax.ws.rs.POST)3 Test (org.junit.Test)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 PUT (javax.ws.rs.PUT)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 KrillCollection (de.ids_mannheim.korap.KrillCollection)1 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)1 MatchCollector (de.ids_mannheim.korap.response.MatchCollector)1 Result (de.ids_mannheim.korap.response.Result)1 MatchCollectorDB (de.ids_mannheim.korap.response.collector.MatchCollectorDB)1 QueryException (de.ids_mannheim.korap.util.QueryException)1