Search in sources :

Example 1 with OpenRollCall

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

the class RollCallHandlerTest method testHandleOpenRollCall.

@Test
public void testHandleOpenRollCall() throws DataHandlingException {
    // Create the open Roll Call message
    OpenRollCall openRollCall = new OpenRollCall(CREATE_LAO.getId(), rollCall.getId(), rollCall.getStart(), EventState.CREATED);
    MessageGeneral message = new MessageGeneral(SENDER_KEY, openRollCall, GSON);
    // Call the message handler
    messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
    // Check the Roll Call is present with state OPENED and the correct ID
    Optional<RollCall> rollCallOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getRollCall(openRollCall.getUpdateId());
    assertTrue(rollCallOpt.isPresent());
    assertEquals(EventState.OPENED, rollCallOpt.get().getState());
    assertEquals(openRollCall.getUpdateId(), rollCallOpt.get().getId());
    // Check the WitnessMessage has been created
    Optional<WitnessMessage> witnessMessage = laoRepository.getLaoByChannel(LAO_CHANNEL).getWitnessMessage(message.getMessageId());
    assertTrue(witnessMessage.isPresent());
    // Check the Witness message contains the expected title and description
    WitnessMessage expectedMessage = openRollCallWitnessMessage(message.getMessageId(), rollCallOpt.get());
    assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
    assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
Also used : MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) RollCall(com.github.dedis.popstellar.model.objects.RollCall) WitnessMessage(com.github.dedis.popstellar.model.objects.WitnessMessage) RollCallHandler.closeRollCallWitnessMessage(com.github.dedis.popstellar.utility.handler.data.RollCallHandler.closeRollCallWitnessMessage) RollCallHandler.createRollCallWitnessMessage(com.github.dedis.popstellar.utility.handler.data.RollCallHandler.createRollCallWitnessMessage) RollCallHandler.openRollCallWitnessMessage(com.github.dedis.popstellar.utility.handler.data.RollCallHandler.openRollCallWitnessMessage) Test(org.junit.Test)

Example 2 with OpenRollCall

use of com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall 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)

Example 3 with OpenRollCall

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

the class LaoDetailViewModel method openRollCall.

/**
 * Opens a roll call event.
 *
 * <p>Publish a GeneralMessage containing OpenRollCall data.
 *
 * @param id the roll call id to open
 */
public void openRollCall(String id) {
    Log.d(TAG, "call openRollCall");
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    long openedAt = Instant.now().getEpochSecond();
    Channel channel = lao.getChannel();
    String laoId = lao.getId();
    Optional<RollCall> optRollCall = lao.getRollCall(id);
    if (!optRollCall.isPresent()) {
        Log.d(TAG, "failed to retrieve roll call with id " + id + "laoID: " + laoId);
        return;
    }
    RollCall rollCall = optRollCall.get();
    OpenRollCall openRollCall = new OpenRollCall(laoId, id, openedAt, rollCall.getState());
    attendees = new HashSet<>(rollCall.getAttendees());
    try {
        attendees.add(keyManager.getPoPToken(lao, rollCall).getPublicKey());
    } catch (KeyException e) {
        ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
    }
    Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, openRollCall).subscribe(() -> {
        Log.d(TAG, "opened the roll call");
        currentRollCallId = openRollCall.getUpdateId();
        scanningAction = ScanningAction.ADD_ROLL_CALL_ATTENDEE;
        openScanning();
    }, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_open_rollcall));
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Channel(com.github.dedis.popstellar.model.objects.Channel) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) RollCall(com.github.dedis.popstellar.model.objects.RollCall) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException)

Aggregations

CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)3 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)3 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)3 RollCall (com.github.dedis.popstellar.model.objects.RollCall)3 Channel (com.github.dedis.popstellar.model.objects.Channel)2 Lao (com.github.dedis.popstellar.model.objects.Lao)2 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)1 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)1 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)1 WitnessMessage (com.github.dedis.popstellar.model.objects.WitnessMessage)1 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)1 LAORepository (com.github.dedis.popstellar.repository.LAORepository)1 InvalidDataException (com.github.dedis.popstellar.utility.error.InvalidDataException)1 KeyException (com.github.dedis.popstellar.utility.error.keys.KeyException)1 RollCallHandler.closeRollCallWitnessMessage (com.github.dedis.popstellar.utility.handler.data.RollCallHandler.closeRollCallWitnessMessage)1 RollCallHandler.createRollCallWitnessMessage (com.github.dedis.popstellar.utility.handler.data.RollCallHandler.createRollCallWitnessMessage)1 RollCallHandler.openRollCallWitnessMessage (com.github.dedis.popstellar.utility.handler.data.RollCallHandler.openRollCallWitnessMessage)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Test (org.junit.Test)1