Search in sources :

Example 1 with Message

use of de.ids_mannheim.korap.response.Message in project Krill by KorAP.

the class Messages method add.

/**
 * Append a new message.
 *
 * @param code
 *            Integer code representation of the warning
 * @param msg
 *            String representation of the warning
 * @param terms
 *            Optional strings of additional information
 * @return New Message object
 */
public Message add(int code, String message, String... terms) {
    Message newMsg = new Message(code, message);
    messages.add(newMsg);
    if (terms != null)
        for (String t : terms) newMsg.addParameter(t);
    return newMsg;
}
Also used : Message(de.ids_mannheim.korap.response.Message)

Example 2 with Message

use of de.ids_mannheim.korap.response.Message in project Krill by KorAP.

the class Messages method add.

/**
 * Append an existing message comming from a JsonNode.
 *
 * @param node
 *            <code>JsonNode</code> representing a message
 * @return New Message object
 * @throws QueryException
 *             if notification is not well formed (Error 750)
 */
public Message add(JsonNode msg) throws QueryException {
    if (!msg.isArray() || !msg.has(0))
        throw new QueryException(750, "Passed notifications are not well formed");
    // Valid message
    Message newMsg = new Message();
    short i = 1;
    if (msg.get(0).isNumber()) {
        newMsg.setCode(msg.get(0).asInt());
        if (!msg.has(1))
            throw new QueryException(750, "Passed notifications are not well formed");
        newMsg.setMessage(msg.get(1).asText());
        i++;
    } else {
        newMsg.setMessage(msg.get(0).asText());
    }
    ;
    // Add parameters
    while (msg.has(i)) newMsg.addParameter(msg.get(i++).asText());
    // Add messages to list
    this.add(newMsg);
    return newMsg;
}
Also used : QueryException(de.ids_mannheim.korap.util.QueryException) Message(de.ids_mannheim.korap.response.Message)

Example 3 with Message

use of de.ids_mannheim.korap.response.Message in project Krill by KorAP.

the class TestMessage method CheckIterability.

@Test
public void CheckIterability() {
    Messages km = new Messages();
    km.add(612, "Foo");
    km.add(613, "Bar", "Instanz");
    km.add(614, "Test");
    String test = "";
    for (Message msg : km) test += msg.getCode();
    assertEquals(test, "612613614");
}
Also used : Messages(de.ids_mannheim.korap.response.Messages) Message(de.ids_mannheim.korap.response.Message) Test(org.junit.Test)

Example 4 with Message

use of de.ids_mannheim.korap.response.Message in project Krill by KorAP.

the class Messages method add.

/**
 * Append an existing message.
 *
 * @param msg
 *            Message object to be added. Message will be cloned.
 * @return Cloned Message object
 */
public Message add(Message msg) {
    try {
        Message msgClone = (Message) msg.clone();
        messages.add(msgClone);
        return msgClone;
    } catch (CloneNotSupportedException e) {
    }
    ;
    return (Message) null;
}
Also used : Message(de.ids_mannheim.korap.response.Message)

Aggregations

Message (de.ids_mannheim.korap.response.Message)4 Messages (de.ids_mannheim.korap.response.Messages)1 QueryException (de.ids_mannheim.korap.util.QueryException)1 Test (org.junit.Test)1