Search in sources :

Example 1 with Objects

use of com.github.dedis.popstellar.model.network.method.message.data.Objects in project popstellar by dedis.

the class MessageHandler method handleMessage.

/**
 * Send messages to the corresponding handler.
 *
 * @param laoRepository the repository to access the messages and LAOs
 * @param messageSender the service used to send messages to the backend
 * @param channel the channel on which the message was received
 * @param message the message that was received
 */
public void handleMessage(LAORepository laoRepository, MessageSender messageSender, Channel channel, MessageGeneral message) throws DataHandlingException {
    Log.d(TAG, "handle incoming message");
    // Put the message in the state
    laoRepository.getMessageById().put(message.getMessageId(), message);
    Data data = message.getData();
    Log.d(TAG, "data with class: " + data.getClass());
    Objects dataObj = Objects.find(data.getObject());
    Action dataAction = Action.find(data.getAction());
    registry.handle(new HandlerContext(laoRepository, keyManager, messageSender, channel, message), data, dataObj, dataAction);
    notifyLaoUpdate(laoRepository, data, channel);
}
Also used : Action(com.github.dedis.popstellar.model.network.method.message.data.Action) HandlerContext(com.github.dedis.popstellar.utility.handler.data.HandlerContext) Objects(com.github.dedis.popstellar.model.network.method.message.data.Objects) Data(com.github.dedis.popstellar.model.network.method.message.data.Data)

Example 2 with Objects

use of com.github.dedis.popstellar.model.network.method.message.data.Objects in project popstellar by dedis.

the class JsonDataSerializer method deserialize.

@Override
public Data deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject obj = json.getAsJsonObject();
    JsonUtils.verifyJson(JsonUtils.DATA_SCHEMA, obj.toString());
    Objects object = Objects.find(obj.get(OBJECT).getAsString());
    Action action = Action.find(obj.get(ACTION).getAsString());
    if (object == null) {
        throw new JsonParseException("Unknown object type : " + obj.get(OBJECT).getAsString());
    }
    if (action == null) {
        throw new JsonParseException("Unknown action type : " + obj.get(ACTION).getAsString());
    }
    Optional<Class<? extends Data>> clazz = dataRegistry.getType(object, action);
    if (!clazz.isPresent()) {
        throw new JsonParseException("The pair (" + object.getObject() + ", " + action.getAction() + ") does not exists in the protocol");
    }
    return context.deserialize(json, clazz.get());
}
Also used : Action(com.github.dedis.popstellar.model.network.method.message.data.Action) Objects(com.github.dedis.popstellar.model.network.method.message.data.Objects) JsonObject(com.google.gson.JsonObject) Data(com.github.dedis.popstellar.model.network.method.message.data.Data) JsonParseException(com.google.gson.JsonParseException)

Aggregations

Action (com.github.dedis.popstellar.model.network.method.message.data.Action)2 Data (com.github.dedis.popstellar.model.network.method.message.data.Data)2 Objects (com.github.dedis.popstellar.model.network.method.message.data.Objects)2 HandlerContext (com.github.dedis.popstellar.utility.handler.data.HandlerContext)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1