Search in sources :

Example 1 with Judgement

use of ch.hsr.sa.radiotour.dataaccess.models.Judgement 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 Judgement

use of ch.hsr.sa.radiotour.dataaccess.models.Judgement 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 3 with Judgement

use of ch.hsr.sa.radiotour.dataaccess.models.Judgement in project app by TourLive.

the class JudgmentRepositoryInstrumentedTest method clearAllJudgments.

@Test
public void clearAllJudgments() {
    Judgement judgement = new Judgement();
    judgement.setDistance(100);
    judgement.setName("judgment");
    judgement.setRewardId(93);
    synchronized (this) {
        judgmentRepository.addJudgment(judgement, onSaveJudgmentCallback);
        judgement.setName("judgment2");
        judgmentRepository.addJudgment(judgement, onSaveJudgmentCallback);
    }
    synchronized (this) {
        judgmentRepository.clearAllJudgments();
    }
    Assert.assertEquals(0, realm.where(Judgement.class).findAll().size());
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Test(org.junit.Test)

Example 4 with Judgement

use of ch.hsr.sa.radiotour.dataaccess.models.Judgement in project app by TourLive.

the class Parser method parseJudgmentsAndPersist.

public static void parseJudgmentsAndPersist(JSONArray judgments, final int STAGE_NR) throws InterruptedException {
    final JSONArray judgmentsJson = judgments;
    Runnable runnable = (() -> {
        for (int i = 0; i < judgmentsJson.length(); i++) {
            try {
                JSONObject jsonJudgment = judgmentsJson.getJSONObject(i);
                if (jsonJudgment.getInt("etappe") == STAGE_NR) {
                    Judgement judgment = new Judgement();
                    judgment.setDistance(jsonJudgment.getInt("rennkm"));
                    judgment.setName(jsonJudgment.getString("name"));
                    judgment.setRewardId(jsonJudgment.getInt("rewardId"));
                    Context.addJudgment(judgment);
                }
            } catch (JSONException e) {
                Log.d(Parser.class.getSimpleName(), "APP - PARSER - JUDGMENTS - " + e.getMessage());
            }
        }
    });
    Thread threadJudgments = new Thread(runnable);
    threadJudgments.start();
    threadJudgments.join();
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 5 with Judgement

use of ch.hsr.sa.radiotour.dataaccess.models.Judgement in project app by TourLive.

the class JudgmentRepository method addJudgment.

@Override
public void addJudgment(Judgement judgement, OnSaveJudgmentCallback callback) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    final Judgement transferJudgment = judgement;
    realm.executeTransaction((Realm db) -> {
        Judgement realmJudgment = db.createObject(Judgement.class, UUID.randomUUID().toString());
        realmJudgment.setName(transferJudgment.getName());
        realmJudgment.setDistance(transferJudgment.getDistance());
        realmJudgment.setRewardId(transferJudgment.getRewardId());
    });
    if (callback != null)
        callback.onSuccess();
}
Also used : Judgement(ch.hsr.sa.radiotour.dataaccess.models.Judgement) Realm(io.realm.Realm)

Aggregations

Judgement (ch.hsr.sa.radiotour.dataaccess.models.Judgement)16 Test (org.junit.Test)7 RealmList (io.realm.RealmList)6 JudgmentRiderConnection (ch.hsr.sa.radiotour.dataaccess.models.JudgmentRiderConnection)4 Reward (ch.hsr.sa.radiotour.dataaccess.models.Reward)4 Realm (io.realm.Realm)4 Rider (ch.hsr.sa.radiotour.dataaccess.models.Rider)3 RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)2 Toast (android.widget.Toast)1 IJudgmentRepository (ch.hsr.sa.radiotour.dataaccess.interfaces.IJudgmentRepository)1 IRewardRepository (ch.hsr.sa.radiotour.dataaccess.interfaces.IRewardRepository)1 JudgmentRepository (ch.hsr.sa.radiotour.dataaccess.repositories.JudgmentRepository)1 RewardRepository (ch.hsr.sa.radiotour.dataaccess.repositories.RewardRepository)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Before (org.junit.Before)1