use of ch.hsr.sa.radiotour.dataaccess.models.Reward in project app by TourLive.
the class JudgmentRiderConnectionRepository method removeOldJudgmentRiderConnections.
private void removeOldJudgmentRiderConnections(RealmResults<JudgmentRiderConnection> res) {
for (JudgmentRiderConnection jRc : res) {
int rank = jRc.getRank();
Judgement judgement = jRc.getJudgements().first();
Reward reward = judgement.getRewards();
RiderStageConnection riderStageConnection = jRc.getRider().first().getRiderStages().first();
if (reward.getType() == RewardType.POINTS) {
if (judgement.getName().toLowerCase().contains("sprint")) {
riderStageConnection.removeSprintBonusPoints(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
riderStageConnection.removeBonusPoint(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
} else if (judgement.getName().toLowerCase().contains("bergpreis")) {
riderStageConnection.removeMountainBonusPoints(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
} else {
riderStageConnection.removeBonusPoint(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
}
}
if (reward.getType() == RewardType.TIME) {
riderStageConnection.removeBonusTime(RiderStageConnectionUtilities.getPointsAtPosition(rank, reward));
}
riderStageConnection.removeMoney(RiderStageConnectionUtilities.getMoneyAtPosition(rank, reward));
jRc.deleteFromRealm();
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.Reward in project app by TourLive.
the class RewardRepository method addReward.
@Override
public void addReward(Reward reward, OnSaveRewardCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
final Reward transferReward = reward;
realm.executeTransaction((Realm db) -> {
Reward realmReward = db.createObject(Reward.class, UUID.randomUUID().toString());
realmReward.setMoney(transferReward.getMoney());
realmReward.setPoints(transferReward.getPoints());
realmReward.setRewardId(transferReward.getRewardId());
realmReward.setType(transferReward.getType());
realmReward.setRewardJudgements(transferReward.getRewardJudgements());
});
if (callback != null)
callback.onSuccess();
}
use of ch.hsr.sa.radiotour.dataaccess.models.Reward in project app by TourLive.
the class JudgmentRepositoryInstrumentedTest method checkJudgmentRewardConnection.
@Test
public void checkJudgmentRewardConnection() {
Judgement judgement = new Judgement();
judgement.setDistance(100);
judgement.setName("judgment");
judgement.setRewardId(93);
synchronized (this) {
judgmentRepository.addJudgment(judgement, onSaveJudgmentCallback);
}
Reward reward = new Reward();
reward.setPoints(new RealmList<Integer>(1, 3, 5));
reward.setMoney(new RealmList<Integer>(100, 300, 500));
reward.setRewardId(93);
reward.setType(RewardType.POINTS);
reward.setRewardJudgements(judgmentRepository.getJudgmentsById(93));
synchronized (this) {
rewardRepository.addReward(reward, onSaveRewardCallback);
}
Assert.assertEquals(300, judgmentRepository.getJudgmentsById(93).first().getRewards().getMoney().get(1).intValue());
}
use of ch.hsr.sa.radiotour.dataaccess.models.Reward in project app by TourLive.
the class RewardRepositoryInstrumentedTest method addReward.
@Test
public void addReward() {
RealmList<Judgement> judgements = new RealmList<>();
RealmResults<Judgement> realmJudgments = realm.where(Judgement.class).findAll();
judgements.addAll(realmJudgments);
Reward reward = new Reward();
reward.setPoints(new RealmList<Integer>(1, 3, 5));
reward.setMoney(new RealmList<Integer>(100, 300, 500));
reward.setType(RewardType.POINTS);
reward.setRewardId(93);
reward.setRewardJudgements(judgements);
synchronized (this) {
rewardRepository.addReward(reward, onSaveRewardCallback);
}
Assert.assertEquals(93, realm.where(Reward.class).findAll().first().getRewardId().intValue());
Assert.assertEquals(300, realm.where(Reward.class).findAll().first().getMoney().get(1).intValue());
Assert.assertEquals(2, realm.where(Reward.class).findAll().first().getRewardJudgements().size());
Assert.assertEquals(93, realm.where(Reward.class).findAll().first().getRewardJudgements().first().getRewardId());
}
use of ch.hsr.sa.radiotour.dataaccess.models.Reward in project app by TourLive.
the class RewardRepositoryInstrumentedTest method clearAllRewards.
@Test
public void clearAllRewards() {
Reward reward = new Reward();
reward.setPoints(new RealmList<Integer>(1, 3, 5));
reward.setMoney(new RealmList<Integer>(100, 300, 500));
reward.setType(RewardType.POINTS);
reward.setRewardId(93);
synchronized (this) {
rewardRepository.addReward(reward, onSaveRewardCallback);
}
synchronized (this) {
rewardRepository.clearAllRewards();
}
Assert.assertEquals(0, realm.where(Reward.class).findAll().size());
}
Aggregations