use of com.github.dedis.popstellar.repository.LAORepository in project popstellar by dedis.
the class ChirpHandler method handleChirpAdd.
/**
* Process an AddChirp message.
*
* @param context the HandlerContext of the message
* @param addChirp the data of the message that was received
*/
public static void handleChirpAdd(HandlerContext context, AddChirp addChirp) {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
PublicKey senderPk = context.getSenderPk();
Lao lao = laoRepository.getLaoByChannel(channel);
Chirp chirp = new Chirp(messageId);
chirp.setChannel(channel);
chirp.setSender(senderPk);
chirp.setText(addChirp.getText());
chirp.setTimestamp(addChirp.getTimestamp());
chirp.setParentId(addChirp.getParentId().orElse(new MessageID("")));
lao.updateAllChirps(messageId, chirp);
}
use of com.github.dedis.popstellar.repository.LAORepository in project popstellar by dedis.
the class ChirpHandler method handleDeleteChirp.
/**
* process a DeleteChirp message.
*
* @param context the HandlerContext of the message
* @param deleteChirp the data of the message that was received
*/
public static void handleDeleteChirp(HandlerContext context, DeleteChirp deleteChirp) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
Lao lao = laoRepository.getLaoByChannel(channel);
Optional<Chirp> chirpOptional = lao.getChirp(deleteChirp.getChirpId());
Chirp chirp;
if (!chirpOptional.isPresent()) {
throw new InvalidMessageIdException(deleteChirp, deleteChirp.getChirpId());
}
chirp = chirpOptional.get();
if (chirp.getIsDeleted()) {
Log.d(TAG, "The chirp is already deleted");
} else {
chirp.setIsDeleted(true);
chirp.setText("");
}
}
use of com.github.dedis.popstellar.repository.LAORepository in project popstellar by dedis.
the class ConsensusHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, DataHandlingException, IOException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(ORGANIZER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(ORGANIZER);
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
lao = new Lao(LAO_ID);
laoRepository.getLaoById().put(LAO_ID, new LAOState(lao));
MessageGeneral createLaoMessage = getMsg(ORGANIZER_KEY, CREATE_LAO);
messageHandler.handleMessage(laoRepository, messageSender, lao.getChannel(), createLaoMessage);
electMsg = getMsg(NODE_2_KEY, elect);
messageId = electMsg.getMessageId();
}
use of com.github.dedis.popstellar.repository.LAORepository in project popstellar by dedis.
the class LaoHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, IOException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(SENDER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(SENDER);
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
// Create one LAO and add it to the LAORepository
lao = new Lao(CREATE_LAO.getName(), CREATE_LAO.getOrganizer(), CREATE_LAO.getCreation());
lao.setLastModified(lao.getCreation());
laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
laoRepository.setAllLaoSubject();
// Add the CreateLao message to the LAORepository
createLaoMessage = new MessageGeneral(SENDER_KEY, CREATE_LAO, GSON);
laoRepository.getMessageById().put(createLaoMessage.getMessageId(), createLaoMessage);
}
use of com.github.dedis.popstellar.repository.LAORepository in project popstellar by dedis.
the class RollCallHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, IOException, KeyException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(SENDER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(SENDER);
lenient().when(keyManager.getValidPoPToken(any(), any())).thenReturn(POP_TOKEN);
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
// Create one LAO
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");
rollCall.setLocation("EPFL");
lao.setRollCalls(new HashMap<String, RollCall>() {
{
put(rollCall.getId(), rollCall);
}
});
// 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);
}
Aggregations