Search in sources :

Example 1 with InvalidDataException

use of com.github.dedis.popstellar.utility.error.InvalidDataException in project popstellar by dedis.

the class RollCallHandler method handleCloseRollCall.

/**
 * Process a CloseRollCall message.
 *
 * @param context the HandlerContext of the message
 * @param closeRollCall the message that was received
 */
public static void handleCloseRollCall(HandlerContext context, CloseRollCall closeRollCall) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Log.d(TAG, "handleCloseRollCall: " + channel);
    String updateId = closeRollCall.getUpdateId();
    String closes = closeRollCall.getCloses();
    Optional<RollCall> rollCallOptional = lao.getRollCall(closes);
    if (!rollCallOptional.isPresent()) {
        Log.w(TAG, "Cannot find roll call to close : " + closes);
        throw new InvalidDataException(closeRollCall, "close id", closes);
    }
    RollCall rollCall = rollCallOptional.get();
    rollCall.setEnd(closeRollCall.getClosedAt());
    rollCall.setId(updateId);
    rollCall.getAttendees().addAll(closeRollCall.getAttendees());
    rollCall.setState(EventState.CLOSED);
    lao.updateRollCall(closes, rollCall);
    lao.updateWitnessMessage(messageId, closeRollCallWitnessMessage(messageId, rollCall));
    // Subscribe to the social media channels
    try {
        PoPToken token = context.getKeyManager().getValidPoPToken(lao, rollCall);
        context.getMessageSender().subscribe(channel.subChannel("social").subChannel(token.getPublicKey().getEncoded())).subscribe();
    } catch (InvalidPoPTokenException e) {
        Log.i(TAG, "Received a close roll-call that you did not attend");
    } catch (KeyException e) {
        Log.e(TAG, "Could not retrieve your PoP Token to subscribe you to your social media channel", e);
    }
}
Also used : PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) InvalidPoPTokenException(com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) InvalidDataException(com.github.dedis.popstellar.utility.error.InvalidDataException) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) RollCall(com.github.dedis.popstellar.model.objects.RollCall) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) Lao(com.github.dedis.popstellar.model.objects.Lao) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 2 with InvalidDataException

use of com.github.dedis.popstellar.utility.error.InvalidDataException in project popstellar by dedis.

the class RollCallHandler method handleOpenRollCall.

/**
 * Process an OpenRollCall message.
 *
 * @param context the HandlerContext of the message
 * @param openRollCall the message that was received
 */
public static void handleOpenRollCall(HandlerContext context, OpenRollCall openRollCall) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Log.d(TAG, "handleOpenRollCall: " + channel + " msg=" + openRollCall);
    String updateId = openRollCall.getUpdateId();
    String opens = openRollCall.getOpens();
    Optional<RollCall> rollCallOptional = lao.getRollCall(opens);
    if (!rollCallOptional.isPresent()) {
        Log.w(TAG, "Cannot find roll call to open : " + opens);
        throw new InvalidDataException(openRollCall, "open id", opens);
    }
    RollCall rollCall = rollCallOptional.get();
    rollCall.setStart(openRollCall.getOpenedAt());
    rollCall.setState(EventState.OPENED);
    // We might be opening a closed one
    rollCall.setEnd(0);
    rollCall.setId(updateId);
    lao.updateRollCall(opens, rollCall);
    lao.updateWitnessMessage(messageId, openRollCallWitnessMessage(messageId, rollCall));
}
Also used : Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) InvalidDataException(com.github.dedis.popstellar.utility.error.InvalidDataException) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) RollCall(com.github.dedis.popstellar.model.objects.RollCall) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) Lao(com.github.dedis.popstellar.model.objects.Lao) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Aggregations

CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)2 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)2 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)2 Channel (com.github.dedis.popstellar.model.objects.Channel)2 Lao (com.github.dedis.popstellar.model.objects.Lao)2 RollCall (com.github.dedis.popstellar.model.objects.RollCall)2 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)2 LAORepository (com.github.dedis.popstellar.repository.LAORepository)2 InvalidDataException (com.github.dedis.popstellar.utility.error.InvalidDataException)2 PoPToken (com.github.dedis.popstellar.model.objects.security.PoPToken)1 InvalidPoPTokenException (com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException)1 KeyException (com.github.dedis.popstellar.utility.error.keys.KeyException)1