diff --git a/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/ElectionRepository.java b/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/ElectionRepository.java
index d7c61c80cb..717f8ef3dd 100644
--- a/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/ElectionRepository.java
+++ b/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/ElectionRepository.java
@@ -5,7 +5,6 @@
import com.github.dedis.popstellar.model.objects.Channel;
import com.github.dedis.popstellar.model.objects.Election;
import com.github.dedis.popstellar.utility.error.UnknownElectionException;
-import com.github.dedis.popstellar.utility.error.UnknownEventException;
import java.util.*;
@@ -22,7 +21,7 @@
*
Its main purpose is to store elections and publish updates
*/
@Singleton
-public class ElectionRepository implements EventRepository {
+public class ElectionRepository {
private final Map electionsByLao = new HashMap<>();
@@ -90,26 +89,10 @@ public Observable getElectionObservable(
* @return an observable that will be updated with the set of all election's ids
*/
@NonNull
- public Observable> getElectionsObservable(@NonNull String laoId) {
+ public Observable> getElectionsObservable(@NonNull String laoId) {
return getLaoElections(laoId).getElectionsSubject();
}
- @Override
- public Observable getEventObservable(String laoId, String eventId)
- throws UnknownEventException {
- return getElectionObservable(laoId, eventId);
- }
-
- @Override
- public Observable> getEventIdsObservable(String laoId) {
- return getElectionsObservable(laoId);
- }
-
- @Override
- public Class getType() {
- return Election.class;
- }
-
@NonNull
private synchronized LaoElections getLaoElections(String laoId) {
// Create the lao elections object if it is not present yet
@@ -119,7 +102,7 @@ private synchronized LaoElections getLaoElections(String laoId) {
private static final class LaoElections {
private final Map electionById = new HashMap<>();
private final Map> electionSubjects = new HashMap<>();
- private final BehaviorSubject> electionsSubject =
+ private final BehaviorSubject> electionsSubject =
BehaviorSubject.createDefault(Collections.emptySet());
public synchronized void updateElection(@NonNull Election election) {
@@ -130,7 +113,7 @@ public synchronized void updateElection(@NonNull Election election) {
//noinspection ConstantConditions
electionSubjects.get(id).onNext(election);
- electionsSubject.onNext(electionById.keySet());
+ electionsSubject.onNext(Collections.unmodifiableSet(new HashSet<>(electionById.values())));
}
public Election getElection(@NonNull String electionId) throws UnknownElectionException {
@@ -143,7 +126,7 @@ public Election getElection(@NonNull String electionId) throws UnknownElectionEx
}
}
- public Observable> getElectionsSubject() {
+ public Observable> getElectionsSubject() {
return electionsSubject;
}
diff --git a/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/EventRepository.java b/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/EventRepository.java
deleted file mode 100644
index 9662f524f1..0000000000
--- a/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/EventRepository.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.github.dedis.popstellar.repository;
-
-import com.github.dedis.popstellar.model.objects.event.Event;
-import com.github.dedis.popstellar.utility.error.UnknownEventException;
-
-import java.util.Set;
-
-import io.reactivex.Observable;
-
-public interface EventRepository {
-
- Observable getEventObservable(String laoId, String eventId) throws UnknownEventException;
-
- Observable> getEventIdsObservable(String laoId);
-
- Class getType();
-}
diff --git a/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/RollCallRepository.java b/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/RollCallRepository.java
index 7811addadd..16dac25ebe 100644
--- a/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/RollCallRepository.java
+++ b/fe2-android/app/src/main/java/com/github/dedis/popstellar/repository/RollCallRepository.java
@@ -6,7 +6,6 @@
import com.github.dedis.popstellar.model.objects.RollCall;
import com.github.dedis.popstellar.model.objects.security.PublicKey;
-import com.github.dedis.popstellar.utility.error.UnknownEventException;
import com.github.dedis.popstellar.utility.error.UnknownRollCallException;
import com.github.dedis.popstellar.utility.error.keys.NoRollCallException;
@@ -20,13 +19,16 @@
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.Subject;
+import static java.util.Collections.emptySet;
+import static java.util.Collections.unmodifiableSet;
+
/**
* This class is the repository of the roll call events
*
* Its main purpose is to store roll calls and publish updates
*/
@Singleton
-public class RollCallRepository implements EventRepository {
+public class RollCallRepository {
public static final String TAG = RollCallRepository.class.getSimpleName();
private final Map rollCallsByLao = new HashMap<>();
@@ -66,22 +68,6 @@ public Observable getRollCallObservable(String laoId, String persisten
return getLaoRollCalls(laoId).getRollCallObservable(persistentId);
}
- @Override
- public Observable getEventObservable(String laoId, String eventId)
- throws UnknownEventException {
- return getRollCallObservable(laoId, eventId);
- }
-
- @Override
- public Observable> getEventIdsObservable(String laoId) {
- return getRollCallsObservableInLao(laoId);
- }
-
- @Override
- public Class getType() {
- return RollCall.class;
- }
-
public RollCall getRollCallWithPersistentId(String laoId, String persistentId)
throws UnknownRollCallException {
return getLaoRollCalls(laoId).getRollCallWithPersistentId(persistentId);
@@ -97,7 +83,7 @@ public RollCall getRollCallWithId(String laoId, String rollCallId)
* @return an observable set of ids who correspond to the set of roll calls published on the given
* lao
*/
- public Observable> getRollCallsObservableInLao(String laoId) {
+ public Observable> getRollCallsObservableInLao(String laoId) {
return getLaoRollCalls(laoId).getRollCallsSubject();
}
@@ -134,8 +120,8 @@ private static final class LaoRollCalls {
private final Map> rollCallSubjects = new HashMap<>();
// This allows to observe the collection of roll calls as a whole
- private final Subject> rollCallsSubject =
- BehaviorSubject.createDefault(Collections.emptySet());
+ private final Subject> rollCallsSubject =
+ BehaviorSubject.createDefault(unmodifiableSet(emptySet()));
/**
* This either updates the roll call in the repository or adds it if absent
@@ -161,7 +147,7 @@ public synchronized void update(RollCall rollCall) {
rollCallSubjects.put(persistentId, BehaviorSubject.createDefault(rollCall));
}
- rollCallsSubject.onNext(this.rollCallByPersistentId.keySet());
+ rollCallsSubject.onNext(unmodifiableSet(new HashSet<>(this.rollCallByPersistentId.values())));
}
public RollCall getRollCallWithPersistentId(String persistentId)
@@ -189,8 +175,8 @@ public Observable getRollCallObservable(String id) throws UnknownRollC
}
}
- public Observable> getRollCallsSubject() {
- return rollCallsSubject.map(HashSet::new);
+ public Observable> getRollCallsSubject() {
+ return rollCallsSubject;
}
public Set getAllAttendees() {
diff --git a/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/detail/LaoDetailViewModel.java b/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/detail/LaoDetailViewModel.java
index 3fdc93d5ea..1e8f626457 100644
--- a/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/detail/LaoDetailViewModel.java
+++ b/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/detail/LaoDetailViewModel.java
@@ -52,8 +52,6 @@
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
-import static com.github.dedis.popstellar.utility.PoPRXOperators.suppressErrors;
-
@HiltViewModel
public class LaoDetailViewModel extends NavigationViewModel
implements QRCodeScanningViewModel {
@@ -684,7 +682,8 @@ public void subscribeToLao(String laoId) {
//
// Thus, we need to create the rollcall event list twice ¯\_(ツ)_/¯
this.attendedRollCalls =
- createEventListObservable(rollCallRepo, laoId)
+ rollCallRepo
+ .getRollCallsObservableInLao(laoId)
.map(
rcs ->
rcs.stream()
@@ -695,8 +694,8 @@ public void subscribeToLao(String laoId) {
// Create the events set observable
this.events =
Observable.combineLatest(
- createEventListObservable(rollCallRepo, laoId),
- createEventListObservable(electionRepo, laoId),
+ rollCallRepo.getRollCallsObservableInLao(laoId),
+ electionRepo.getElectionsObservable(laoId),
(rcs, elecs) -> {
Set union = new HashSet<>(rcs);
union.addAll(elecs);
@@ -725,41 +724,6 @@ public void subscribeToLao(String laoId) {
error -> Log.d(TAG, "error updating LAO :" + error)));
}
- public static Observable> createEventListObservable(
- EventRepository eventRepo, String laoId) {
- return eventRepo
- .getEventIdsObservable(laoId)
- .map(
- idSet ->
- idSet.stream()
- .map(
- id -> {
- try {
- return eventRepo.getEventObservable(laoId, id);
- } catch (UnknownEventException e) {
- // Roll calls whose ids are in that list may not be absent
- throw new IllegalStateException(
- "Could not fetch "
- + eventRepo.getType().getSimpleName()
- + " with id "
- + id);
- }
- })
- .collect(Collectors.toList()))
- .flatMap(
- subjects ->
- // If there are no subjects, returns an empty set rather than no value
- subjects.isEmpty()
- ? Observable.just(new HashSet())
- : Observable.combineLatest(
- subjects,
- events ->
- Arrays.stream(events)
- .map(eventRepo.getType()::cast)
- .collect(Collectors.toSet())))
- .lift(suppressErrors(err -> Log.e(TAG, "Error creating rollcall list : ", err)));
- }
-
public PoPToken getCurrentPopToken(RollCall rollCall) throws KeyException, UnknownLaoException {
return keyManager.getPoPToken(getLaoView(), rollCall);
}
diff --git a/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/digitalcash/DigitalCashViewModel.java b/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/digitalcash/DigitalCashViewModel.java
index ea56441bd3..6922ad6907 100644
--- a/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/digitalcash/DigitalCashViewModel.java
+++ b/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/digitalcash/DigitalCashViewModel.java
@@ -12,8 +12,7 @@
import com.github.dedis.popstellar.SingleEvent;
import com.github.dedis.popstellar.model.network.method.message.MessageGeneral;
import com.github.dedis.popstellar.model.network.method.message.data.digitalcash.*;
-import com.github.dedis.popstellar.model.objects.Channel;
-import com.github.dedis.popstellar.model.objects.Wallet;
+import com.github.dedis.popstellar.model.objects.*;
import com.github.dedis.popstellar.model.objects.digitalcash.TransactionObject;
import com.github.dedis.popstellar.model.objects.security.*;
import com.github.dedis.popstellar.model.objects.view.LaoView;
@@ -377,7 +376,7 @@ public Observable> getTransactionsObservable() {
}
}
- public Observable> getRollCallsObservable() {
+ public Observable> getRollCallsObservable() {
return rollCallRepo.getRollCallsObservableInLao(laoId);
}
diff --git a/fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/digitalcash/DigitalCashActivityTest.java b/fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/digitalcash/DigitalCashActivityTest.java
index 0368b884c0..a6464e2e04 100644
--- a/fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/digitalcash/DigitalCashActivityTest.java
+++ b/fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/digitalcash/DigitalCashActivityTest.java
@@ -132,8 +132,8 @@ protected void before() throws KeyException, GeneralSecurityException, UnknownLa
builder.setInputs(Collections.singletonList(io));
builder.setTransactionId("some id");
TransactionObject transaction = builder.build();
- Set rcIdSet = new HashSet<>();
- rcIdSet.add(ROLL_CALL.getId());
+ Set rcIdSet = new HashSet<>();
+ rcIdSet.add(ROLL_CALL);
when(digitalCashRepo.getTransactions(any(), any()))
.thenReturn(Collections.singletonList(transaction));
diff --git a/fe2-android/app/src/test/unit/java/com/github/dedis/popstellar/repository/ElectionRepositoryTest.java b/fe2-android/app/src/test/unit/java/com/github/dedis/popstellar/repository/ElectionRepositoryTest.java
index 0f8872bee3..0ae54e2743 100644
--- a/fe2-android/app/src/test/unit/java/com/github/dedis/popstellar/repository/ElectionRepositoryTest.java
+++ b/fe2-android/app/src/test/unit/java/com/github/dedis/popstellar/repository/ElectionRepositoryTest.java
@@ -31,13 +31,13 @@ public class ElectionRepositoryTest {
@Test
public void addingElectionUpdatesIds() {
ElectionRepository repo = new ElectionRepository();
- TestObserver> ids = repo.getElectionsObservable(LAO_ID).test();
+ TestObserver> elections = repo.getElectionsObservable(LAO_ID).test();
- assertCurrentValueIs(ids, emptySet());
+ assertCurrentValueIs(elections, emptySet());
repo.updateElection(ELECTION);
- assertCurrentValueIs(ids, singleton(ELECTION.getId()));
+ assertCurrentValueIs(elections, singleton(ELECTION));
}
@Test