Search in sources :

Example 1 with Reward

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();
    }
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward) JudgmentRiderConnection(ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)

Example 2 with Reward

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();
}
Also used : Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward) Realm(io.realm.Realm)

Example 3 with Reward

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());
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward) Test(org.junit.Test)

Example 4 with Reward

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());
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) RealmList(io.realm.RealmList) Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward) Test(org.junit.Test)

Example 5 with Reward

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());
}
Also used : Reward(ch.hsr.sa.radiotour.dataaccess.models.Reward) Test(org.junit.Test)

Aggregations

Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)7 Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)3 Test (org.junit.Test)3 RealmList (io.realm.RealmList)2 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)1 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)1 Realm (io.realm.Realm)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1