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);
}
}
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));
}
Aggregations