if (correctUserKeyStr == null)
// Reached the end
break;
final Long correctUserKey = Long.valueOf(correctUserKeyStr);
final User correctUser = userByKey.get(correctUserKey);
if (correctUser == null)
throw new IllegalStateException("Error in form, cannot find user with key " + correctUserKey);
final String guessedFullName = dynamicInput.getInput(correctUserKeyStr, String.class);
final boolean attemptGuess = guessedFullName != null;
final boolean correctGuess;
if (guessedFullName != null) {
correctGuess = guessedFullName.equals(correctUser.getFullName());
final Date now = Clock.now();
new KTrans.Void(pm) {
@Override protected void run() {
Query query = pm.newQuery(Guess.class);
query.setFilter(String.format("userKey == %s && correctUser == %s", user.getKey(), correctUserKey));
Guess guess = CollUtils.getOneOrNull(Utils.<Collection<Guess>>cast(query.execute()));
if (guess == null) {
guess = new Guess();
guess.setUserKey(user.getKey());
guess.setCorrectUser(correctUserKey);
} else {
if (!Guess.guessAllowed(now, guess))
throw new IllegalStateException("Error, user " + user.getFullName() + " is not currently allowed to guess on " + correctUser.getFullName());
}
guess.registerGuess(now, correctGuess);
pm.makePersistent(guess);