Search in sources :

Example 21 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LaoDetailViewModel method closeRollCall.

/**
 * Closes the roll call event currently open
 *
 * <p>Publish a GeneralMessage containing CloseRollCall data.
 */
public void closeRollCall(int nextFragment) {
    Log.d(TAG, "call closeRollCall");
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    long end = Instant.now().getEpochSecond();
    Channel channel = lao.getChannel();
    CloseRollCall closeRollCall = new CloseRollCall(lao.getId(), currentRollCallId, end, new ArrayList<>(attendees));
    Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, closeRollCall).subscribe(() -> {
        Log.d(TAG, "closed the roll call");
        currentRollCallId = "";
        attendees.clear();
        mCloseRollCallEvent.setValue(new SingleEvent<>(nextFragment));
    }, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_close_rollcall));
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Channel(com.github.dedis.popstellar.model.objects.Channel) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) 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)

Example 22 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LaoDetailViewModel method terminateCurrentElection.

public void terminateCurrentElection() {
    if (mCurrentLao.getValue().removeElection(mCurrentElection.getValue().getId())) {
        Log.d(TAG, "Election deleted : " + mCurrentElection.getValue().getId());
        Lao lao = getCurrentLaoValue();
        mCurrentLao.postValue(lao);
        openLaoDetail();
    } else {
        Log.d(TAG, "Impossible to delete election : " + mCurrentElection.getValue().getId());
    }
}
Also used : 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)

Example 23 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LaoDetailViewModel method sendVote.

/**
 * Sends a ElectionCastVotes message .
 *
 * <p>Publish a GeneralMessage containing ElectionCastVotes data.
 *
 * @param votes the corresponding votes for that election
 */
public void sendVote(List<ElectionVote> votes) {
    Election election = mCurrentElection.getValue();
    if (election == null) {
        Log.d(TAG, "failed to retrieve current election");
        return;
    }
    Log.d(TAG, "sending a new vote in election : " + election + " with election start time" + election.getStartTimestamp());
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    try {
        PoPToken token = keyManager.getValidPoPToken(lao);
        CastVote castVote = new CastVote(votes, election.getId(), lao.getId());
        Channel electionChannel = election.getChannel();
        Log.d(TAG, PUBLISH_MESSAGE);
        Disposable disposable = networkManager.getMessageSender().publish(token, electionChannel, castVote).doFinally(this::openLaoDetail).subscribe(() -> {
            Log.d(TAG, "sent a vote successfully");
            // Toast ? + send back to election screen or details screen ?
            Toast.makeText(getApplication(), "vote successfully sent !", Toast.LENGTH_LONG).show();
        }, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_send_vote));
        disposables.add(disposable);
    } catch (KeyException e) {
        ErrorUtils.logAndShow(getApplication(), TAG, e, R.string.error_retrieve_own_token);
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) Channel(com.github.dedis.popstellar.model.objects.Channel) CastVote(com.github.dedis.popstellar.model.network.method.message.data.election.CastVote) 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) Election(com.github.dedis.popstellar.model.objects.Election) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException)

Example 24 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LaoDetailViewModel method sendConsensusElectAccept.

/**
 * Sends a ConsensusElectAccept message.
 *
 * <p>Publish a GeneralMessage containing ConsensusElectAccept data.
 *
 * @param electInstance the corresponding ElectInstance
 * @param accept true if accepted, false if rejected
 */
public void sendConsensusElectAccept(ElectInstance electInstance, boolean accept) {
    MessageID messageId = electInstance.getMessageId();
    Log.d(TAG, "sending a new elect_accept for consensus with messageId : " + messageId + " with value " + accept);
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    ConsensusElectAccept consensusElectAccept = new ConsensusElectAccept(electInstance.getInstanceId(), messageId, accept);
    Log.d(TAG, PUBLISH_MESSAGE);
    Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), electInstance.getChannel(), consensusElectAccept).subscribe(() -> Log.d(TAG, "sent an elect_accept successfully"), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_consensus_accept));
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) 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) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 25 with Lao

use of com.github.dedis.popstellar.model.objects.Lao 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);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Channel(com.github.dedis.popstellar.model.objects.Channel) 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) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)

Aggregations

Lao (com.github.dedis.popstellar.model.objects.Lao)46 Channel (com.github.dedis.popstellar.model.objects.Channel)31 LAORepository (com.github.dedis.popstellar.repository.LAORepository)24 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)18 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)18 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)16 Disposable (io.reactivex.disposables.Disposable)14 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)12 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)11 Election (com.github.dedis.popstellar.model.objects.Election)10 RollCall (com.github.dedis.popstellar.model.objects.RollCall)10 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)9 PoPToken (com.github.dedis.popstellar.model.objects.security.PoPToken)9 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)8 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)8 KeyException (com.github.dedis.popstellar.utility.error.keys.KeyException)8 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)7 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)6 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)6 LAOState (com.github.dedis.popstellar.repository.LAOState)6