@Override public T get() { return ofy().load().now(key()); }
@Override protected boolean isMigrationNeeded(Key<FeedbackResponseComment> entity) { FeedbackResponseComment comment = ofy().load().key(entity).now(); try { Field commentGiverType = comment.getClass().getDeclaredField("commentGiverType"); commentGiverType.setAccessible(true); return commentGiverType.get(comment) == null; } catch (ReflectiveOperationException e) { return true; } }
@Override protected Query<FeedbackResponseComment> getFilterQuery() { return ofy().load().type(FeedbackResponseComment.class); }
@Override protected Query<CourseStudent> getFilterQuery() { return ofy().load().type(CourseStudent.class); }
@Override protected Query<Account> getFilterQuery() { return ofy().load().type(Account.class); }
@Override protected Query<Course> getFilterQuery() { return ofy().load().type(Course.class); }
@Override protected Query<Instructor> getFilterQuery() { return ofy().load().type(Instructor.class); }
@Override protected Query<Account> getFilterQuery() { return ofy().load().type(Account.class).filterKey(Key.create(Account.class, fromAccountGoogleId)); }
@Override protected boolean isMigrationNeeded(Key<Instructor> key) throws Exception { Instructor instructor = ofy().load().key(key).now(); if (SanitizationHelper.isSanitizedHtml(instructor.getRole())) { System.err.println(String.format("Instructor %s has unsanitized role %s, this should not happen", instructor.getUniqueId(), instructor.getRole())); } return SanitizationHelper.isSanitizedHtml(instructor.getDisplayedName()); }
@Override protected boolean isMigrationNeeded(Key<Account> key) throws Exception { Account account = ofy().load().key(key).now(); if (!isMigrationOfGoogleIdNeeded(account)) { return false; } String newGoogleId = generateNewGoogleId(account); println(String.format("Going to migrate account with googleId %s to new googleId %s", account.getGoogleId(), newGoogleId)); return true; }
@Override protected boolean isMigrationNeeded(Key<Course> key) throws Exception { Course course = ofy().load().key(key).now(); return SanitizationHelper.isSanitizedHtml(course.getName()); }
@Override public String load(String courseId) { List<Instructor> instructors = ofy().load().type(Instructor.class).filter("courseId =", courseId).list(); for (Instructor instructor : instructors) { if (StringHelper.isEmpty(instructor.getGoogleId())) { continue; } Account account = ofy().load().key(Key.create(Account.class, instructor.getGoogleId())).now(); if (account != null && !StringHelper.isEmpty(account.getInstitute())) { return account.getInstitute(); } } return UNKNOWN_INSTITUTE; } });
@Override protected boolean isMigrationNeeded(Key<CourseStudent> key) throws Exception { CourseStudent student = ofy().load().key(key).now(); if (SanitizationHelper.isSanitizedHtml(student.getCourseId())) { System.err.println(String.format("Student %s has unsanitized courseId %s, this should not happen", student.getUniqueId(), student.getCourseId())); } if (SanitizationHelper.isSanitizedHtml(student.getEmail())) { System.err.println(String.format("Student %s has unsanitized email %s, this should not happen", student.getUniqueId(), student.getEmail())); } if (SanitizationHelper.isSanitizedHtml(student.getGoogleId())) { System.err.println(String.format("Student %s has unsanitized googleId %s, this should not happen", student.getUniqueId(), student.getGoogleId())); } if (SanitizationHelper.isSanitizedHtml(student.getSectionName())) { System.err.println(String.format("Student %s has unsanitized sectionName %s, this should not happen", student.getUniqueId(), student.getSectionName())); } if (SanitizationHelper.isSanitizedHtml(student.getTeamName())) { System.err.println(String.format("Student %s has unsanitized teamName %s, this should not happen", student.getUniqueId(), student.getTeamName())); } return SanitizationHelper.isSanitizedHtml(student.getComments()) || SanitizationHelper.isSanitizedHtml(student.getLastName()) || SanitizationHelper.isSanitizedHtml(student.getName()); }
@Override protected void migrateEntity(Key<FeedbackResponseComment> entity) { FeedbackResponseComment comment = ofy().load().key(entity).now(); comment.setCommentGiverType(FeedbackParticipantType.INSTRUCTORS); comment.setIsCommentFromFeedbackParticipant(false); ofy().save().entity(comment).now(); } }
@Override protected void migrateEntity(Key<Course> key) throws Exception { Course course = ofy().load().key(key).now(); course.setName(SanitizationHelper.desanitizeIfHtmlSanitized(course.getName())); ofy().save().entity(course).now(); } }
@Override protected void migrateEntity(Key<Instructor> key) throws Exception { Instructor instructor = ofy().load().key(key).now(); instructor.setDisplayedName(SanitizationHelper.desanitizeIfHtmlSanitized(instructor.getDisplayedName())); ofy().save().entity(instructor).now(); } }
@Override protected void migrateEntity(Key<Account> oldAccountKey) throws Exception { Account oldAccount = ofy().load().key(oldAccountKey).now(); String oldGoogleId = oldAccount.getGoogleId(); String newGoogleId = generateNewGoogleId(oldAccount); StudentProfile oldStudentProfile = ofy().load().key(oldStudentProfileKey).now(); List<CourseStudent> oldStudents = ofy().load().type(CourseStudent.class) .filter("googleId =", oldGoogleId).list(); List<Instructor> oldInstructors = ofy().load().type(Instructor.class) .filter("googleId =", oldGoogleId).list(); if (ofy().load().type(Account.class).id(newGoogleId).now() == null) { ofy().save().entity(oldAccount).now(); } else {
@Override protected void migrateEntity(Key<CourseStudent> key) throws Exception { CourseStudent student = ofy().load().key(key).now(); student.setComments(SanitizationHelper.desanitizeIfHtmlSanitized(student.getComments())); student.setName(SanitizationHelper.desanitizeIfHtmlSanitized(student.getName())); student.setLastName(SanitizationHelper.desanitizeIfHtmlSanitized(student.getLastName())); ofy().save().entity(student).now(); } }
protected List<E> loadInternal(Iterable<Key<E>> keys) { if (Expressive.isEmpty(keys)) { return Collections.<E> emptyList(); } Map<Key<E>, E> results = ofy().load().keys(keys); return Expressive.Transformers.transformAllUsing(Expressive.Transformers.usingLookup(results)).from(keys); }