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();
}
}
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());
}
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());
}
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();
}
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();
}
Aggregations