Search in sources :

Example 1 with DataHandlingException

use of com.github.dedis.popstellar.utility.error.DataHandlingException in project popstellar by dedis.

the class ElectionHandler method handleElectionResult.

/**
 * Process an ElectionResult message.
 *
 * @param context the HandlerContext of the message
 * @param electionResult the message that was received
 */
public static void handleElectionResult(HandlerContext context, ElectionResult electionResult) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    Log.d(TAG, "handling election result");
    Lao lao = laoRepository.getLaoByChannel(channel);
    Election election = laoRepository.getElectionByChannel(channel);
    List<ElectionResultQuestion> resultsQuestions = electionResult.getElectionQuestionResults();
    Log.d(TAG, "size of resultsQuestions is " + resultsQuestions.size());
    if (resultsQuestions.isEmpty())
        throw new DataHandlingException(electionResult, "the questions results is empty");
    election.setResults(resultsQuestions);
    election.setEventState(RESULTS_READY);
    lao.updateElection(election.getId(), election);
}
Also used : Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Lao(com.github.dedis.popstellar.model.objects.Lao) ElectionResultQuestion(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResultQuestion) DataHandlingException(com.github.dedis.popstellar.utility.error.DataHandlingException) Election(com.github.dedis.popstellar.model.objects.Election)

Example 2 with DataHandlingException

use of com.github.dedis.popstellar.utility.error.DataHandlingException in project popstellar by dedis.

the class LaoHandler method handleUpdateLao.

/**
 * Process an UpdateLao message.
 *
 * @param context the HandlerContext of the message
 * @param updateLao the message that was received
 */
public static void handleUpdateLao(HandlerContext context, UpdateLao updateLao) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    Log.d(TAG, " Receive Update Lao Broadcast msg=" + updateLao);
    Lao lao = laoRepository.getLaoByChannel(channel);
    if (lao.getLastModified() > updateLao.getLastModified()) {
        // the current state we have is more up to date
        throw new DataHandlingException(updateLao, "The current Lao is more up to date than the update lao message");
    }
    WitnessMessage message;
    if (!updateLao.getName().equals(lao.getName())) {
        message = updateLaoNameWitnessMessage(messageId, updateLao, lao);
    } else if (!updateLao.getWitnesses().equals(lao.getWitnesses())) {
        message = updateLaoWitnessesWitnessMessage(messageId, updateLao, lao);
    } else {
        Log.d(TAG, "Cannot set the witness message title to update lao");
        throw new DataHandlingException(updateLao, "Cannot set the witness message title to update lao");
    }
    lao.updateWitnessMessage(messageId, message);
    if (!lao.getWitnesses().isEmpty()) {
        // We send a pending update only if there are already some witness that need to sign this
        // UpdateLao
        lao.getPendingUpdates().add(new PendingUpdate(updateLao.getLastModified(), messageId));
    }
    laoRepository.updateNodes(channel);
}
Also used : Channel(com.github.dedis.popstellar.model.objects.Channel) PendingUpdate(com.github.dedis.popstellar.model.objects.PendingUpdate) LAORepository(com.github.dedis.popstellar.repository.LAORepository) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao) DataHandlingException(com.github.dedis.popstellar.utility.error.DataHandlingException) WitnessMessage(com.github.dedis.popstellar.model.objects.WitnessMessage) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Aggregations

Channel (com.github.dedis.popstellar.model.objects.Channel)2 Lao (com.github.dedis.popstellar.model.objects.Lao)2 LAORepository (com.github.dedis.popstellar.repository.LAORepository)2 DataHandlingException (com.github.dedis.popstellar.utility.error.DataHandlingException)2 ElectionResultQuestion (com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResultQuestion)1 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)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 Election (com.github.dedis.popstellar.model.objects.Election)1 PendingUpdate (com.github.dedis.popstellar.model.objects.PendingUpdate)1 WitnessMessage (com.github.dedis.popstellar.model.objects.WitnessMessage)1 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)1