summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/grow/ccb
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2017-10-15 19:00:56 -0700
committerJesse Morgan <jesse@jesterpm.net>2017-10-15 19:00:56 -0700
commitb14ec9a9282cb49951b790ce1b48b1a078616926 (patch)
treedeada14d4a407de18812d0e72c32136a2de2caa5 /src/main/java/com/p4square/grow/ccb
parent79b8aacbb7b347bba9d14b1332666e7263a3a058 (diff)
Refactor Chapter Ordering Logic20171015
The bug impacting the CCB integration was due to the "Introduction" chapter having a higher "score" than every other chapter. It was a mistake to use Score to compared chapter progress, particularly since there are more chapters than scores. This change gathers the chapter ordering logic, which was scattered throughout the code into a new Chapters enum. Playlist and Chapter now use Chapters as a key, instead of loose strings. Same for the ProgressReporter interface.
Diffstat (limited to 'src/main/java/com/p4square/grow/ccb')
-rw-r--r--src/main/java/com/p4square/grow/ccb/CCBProgressReporter.java12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/main/java/com/p4square/grow/ccb/CCBProgressReporter.java b/src/main/java/com/p4square/grow/ccb/CCBProgressReporter.java
index c352fc7..a89035d 100644
--- a/src/main/java/com/p4square/grow/ccb/CCBProgressReporter.java
+++ b/src/main/java/com/p4square/grow/ccb/CCBProgressReporter.java
@@ -3,12 +3,11 @@ package com.p4square.grow.ccb;
import com.p4square.ccbapi.CCBAPI;
import com.p4square.ccbapi.model.*;
import com.p4square.grow.frontend.ProgressReporter;
-import com.p4square.grow.model.Score;
+import com.p4square.grow.model.Chapters;
import org.apache.log4j.Logger;
import org.restlet.security.User;
import java.io.IOException;
-import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
@@ -41,11 +40,11 @@ public class CCBProgressReporter implements ProgressReporter {
}
final CCBUser ccbuser = (CCBUser) user;
- updateLevelAndDate(ccbuser, GROW_ASSESSMENT, level, date);
+ updateLevelAndDate(ccbuser, GROW_ASSESSMENT, level.toLowerCase(), date);
}
@Override
- public void reportChapterComplete(final User user, final String chapter, final Date date) throws IOException {
+ public void reportChapterComplete(final User user, final Chapters chapter, final Date date) throws IOException {
if (!(user instanceof CCBUser)) {
throw new IllegalArgumentException("Expected CCBUser but got " + user.getClass().getCanonicalName());
}
@@ -56,7 +55,8 @@ public class CCBProgressReporter implements ProgressReporter {
.getCustomPulldownFields().getByLabel(GROW_LEVEL);
if (currentLevel != null) {
- if (Score.numericScore(chapter) <= Score.numericScore(currentLevel.getSelection().getLabel())) {
+ Chapters currentChapter = Chapters.fromString(currentLevel.getSelection().getLabel());
+ if (chapter.compareTo(currentChapter) <= 0) {
LOG.debug("Not updating level for " + user.getIdentifier()
+ " because current level (" + currentLevel.getSelection().getLabel()
+ ") is greater than new level (" + chapter + ")");
@@ -64,7 +64,7 @@ public class CCBProgressReporter implements ProgressReporter {
}
}
- updateLevelAndDate(ccbuser, GROW_LEVEL, chapter, date);
+ updateLevelAndDate(ccbuser, GROW_LEVEL, chapter.identifier(), date);
}
private void updateLevelAndDate(final CCBUser user, final String field, final String level, final Date date)