use of com.github.dedis.popstellar.model.objects.RollCall in project popstellar by dedis.
the class WalletListAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
RollCallEventLayoutBinding binding;
if (view == null) {
// inflate
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
binding = RollCallEventLayoutBinding.inflate(inflater, viewGroup, false);
} else {
binding = DataBindingUtil.getBinding(view);
}
if (binding == null)
throw new IllegalStateException("Binding could not be find in the view");
RollCall rollCall = rollCalls.get(position);
binding.rollcallDate.setText("Ended: " + DATE_FORMAT.format(new Date(1000 * rollCall.getEnd())));
binding.rollcallTitle.setText("Roll Call: " + rollCall.getName());
binding.rollcallLocation.setText("Location: " + rollCall.getLocation());
binding.rollcallOpenButton.setVisibility(View.GONE);
binding.rollcallReopenButton.setVisibility(View.GONE);
binding.rollcallScheduledButton.setVisibility(View.GONE);
binding.rollcallEnterButton.setVisibility(View.GONE);
binding.rollcallClosedButton.setVisibility(View.GONE);
binding.rollcallAttendeesListButton.setVisibility(View.VISIBLE);
binding.rollcallAttendeesListButton.setOnClickListener(clicked -> viewModel.openAttendeesList(rollCall.getId()));
Boolean isOrganizer = viewModel.isOrganizer().getValue();
if (isOrganizer != null && !isOrganizer) {
binding.rollcallTokenButton.setVisibility(View.VISIBLE);
binding.rollcallTokenButton.setOnClickListener(clicked -> viewModel.openRollCallToken(rollCall.getId()));
}
binding.setLifecycleOwner(lifecycleOwner);
binding.executePendingBindings();
return binding.getRoot();
}
use of com.github.dedis.popstellar.model.objects.RollCall in project popstellar by dedis.
the class ElectionHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, IOException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(SENDER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(SENDER);
laoRepository = new LAORepository();
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
// Create one LAO
lao = new Lao(CREATE_LAO.getName(), CREATE_LAO.getOrganizer(), CREATE_LAO.getCreation());
lao.setLastModified(lao.getCreation());
// Create one Roll Call and add it to the LAO
rollCall = new RollCall(lao.getId(), Instant.now().getEpochSecond(), "roll call 1");
lao.setRollCalls(new HashMap<String, RollCall>() {
{
put(rollCall.getId(), rollCall);
}
});
// Create one Election and add it to the LAO
election = new Election(lao.getId(), Instant.now().getEpochSecond(), "election 1");
election.setStart(Instant.now().getEpochSecond());
election.setEnd(Instant.now().getEpochSecond() + 20L);
election.setChannel(lao.getChannel().subChannel(election.getId()));
electionQuestion = new ElectionQuestion("question", "Plurality", false, Arrays.asList("a", "b"), election.getId());
election.setElectionQuestions(Collections.singletonList(electionQuestion));
lao.setElections(new HashMap<String, Election>() {
{
put(election.getId(), election);
}
});
// Add the LAO to the LAORepository
laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
laoRepository.setAllLaoSubject();
// Add the CreateLao message to the LAORepository
MessageGeneral createLaoMessage = new MessageGeneral(SENDER_KEY, CREATE_LAO, GSON);
laoRepository.getMessageById().put(createLaoMessage.getMessageId(), createLaoMessage);
}
use of com.github.dedis.popstellar.model.objects.RollCall 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());
}
use of com.github.dedis.popstellar.model.objects.RollCall 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.model.objects.RollCall 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));
}
Aggregations