use of com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall in project popstellar by dedis.
the class LaoDetailViewModel method createNewRollCall.
/**
* Creates new roll call event.
*
* <p>Publish a GeneralMessage containing CreateRollCall data.
*
* @param title the title of the roll call
* @param description the description of the roll call, can be empty
* @param creation the creation time of the roll call
* @param proposedStart the proposed start time of the roll call
* @param proposedEnd the proposed end time of the roll call
* @param open true if we want to directly open the roll call
*/
public void createNewRollCall(String title, String description, long creation, long proposedStart, long proposedEnd, boolean open) {
Log.d(TAG, "creating a new roll call with title " + title);
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
Channel channel = lao.getChannel();
// FIXME Location : Lausanne ?
CreateRollCall createRollCall = new CreateRollCall(title, creation, proposedStart, proposedEnd, "Lausanne", description, lao.getId());
Log.d(TAG, PUBLISH_MESSAGE);
Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, createRollCall).subscribe(() -> {
Log.d(TAG, "created a roll call with id: " + createRollCall.getId());
if (open) {
openRollCall(createRollCall.getId());
} else {
mCreatedRollCallEvent.postValue(new SingleEvent<>(true));
}
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_create_rollcall));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall in project popstellar by dedis.
the class RollCallHandler method handleCreateRollCall.
/**
* Process a CreateRollCall message.
*
* @param context the HandlerContext of the message
* @param createRollCall the message that was received
*/
public static void handleCreateRollCall(HandlerContext context, CreateRollCall createRollCall) {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
Lao lao = laoRepository.getLaoByChannel(channel);
Log.d(TAG, "handleCreateRollCall: " + channel + " name " + createRollCall.getName());
RollCall rollCall = new RollCall(createRollCall.getId());
rollCall.setCreation(createRollCall.getCreation());
rollCall.setState(EventState.CREATED);
rollCall.setStart(createRollCall.getProposedStart());
rollCall.setEnd(createRollCall.getProposedEnd());
rollCall.setName(createRollCall.getName());
rollCall.setLocation(createRollCall.getLocation());
rollCall.setLocation(createRollCall.getLocation());
rollCall.setDescription(createRollCall.getDescription().orElse(""));
lao.updateRollCall(rollCall.getId(), rollCall);
lao.updateWitnessMessage(messageId, createRollCallWitnessMessage(messageId, rollCall));
}
use of com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall in project popstellar by dedis.
the class RollCallHandlerTest method testHandleCreateRollCall.
@Test
public void testHandleCreateRollCall() throws DataHandlingException {
// Create the create Roll Call message
CreateRollCall createRollCall = new CreateRollCall("roll call 2", rollCall.getCreation(), rollCall.getStart(), rollCall.getEnd(), rollCall.getLocation(), rollCall.getDescription(), CREATE_LAO.getId());
MessageGeneral message = new MessageGeneral(SENDER_KEY, createRollCall, GSON);
// Call the message handler
messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
// Check the new Roll Call is present with state CREATED and the correct ID
Optional<RollCall> rollCallOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getRollCall(createRollCall.getId());
assertTrue(rollCallOpt.isPresent());
assertEquals(EventState.CREATED, rollCallOpt.get().getState());
assertEquals(createRollCall.getId(), 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 = createRollCallWitnessMessage(message.getMessageId(), rollCallOpt.get());
assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
Aggregations