Program: 25732
Project: 25732
Buggy source:
@Test public void userWithSignatureAndNoDbRecordIsRepaired() throws Exception {
  TestUser user=helper.getBuilder(AuthenticationServiceTest.class).withConsent(true).withSignIn(true).build();
  try {
    authService.signOut(user.getSession());
    Account account=accountDao.getAccount(testUser.getStudy(),testUser.getEmail());
    List<Subpopulation> subpops=subpopService.getSubpopulations(user.getStudyIdentifier());
    for (    Subpopulation subpop : subpops) {
      userConsentDao.deleteAllConsents(user.getUser().getHealthCode(),subpop.getGuid());
      ConsentSignature sig=account.getConsentSignatureHistory(subpop.getGuid()).get(0);
      sig=new ConsentSignature.Builder().withConsentSignature(sig).withSignedOn(0L).build();
      com.stormpath.sdk.account.Account stormpathAcct=((StormpathAccount)account).getAccount();
      CustomData data=stormpathAcct.getCustomData();
      data.put(subpop.getGuidString() + "String_Node_Str",BridgeObjectMapper.get().writeValueAsString(sig));
      data.put(subpop.getGuidString() + "String_Node_Str",2);
      data.remove(subpop.getGuidString() + "String_Node_Str");
      data.remove(subpop.getGuidString() + "String_Node_Str");
    }
    accountDao.updateAccount(testUser.getStudy(),account);
    Study study=studyService.getStudy(user.getStudyIdentifier());
    CriteriaContext context=testUser.getCriteriaContext();
    UserSession session=authService.signIn(study,context,user.getSignIn());
    for (    ConsentStatus status : session.getUser().getConsentStatuses().values()) {
      assertTrue(!status.isRequired() || status.isConsented());
      UserConsent consent=userConsentDao.getActiveUserConsent(session.getUser().getHealthCode(),SubpopulationGuid.create(status.getSubpopulationGuid()));
      assertTrue(consent.getSignedOn() > 0L);
    }
  }
  finally {
    helper.deleteUser(user);
  }
}

Fixed version (ground truth):
@Test public void userWithSignatureAndNoDbRecordIsRepaired() throws Exception {
  TestUser user=helper.getBuilder(AuthenticationServiceTest.class).withConsent(true).withSignIn(true).build();
  try {
    authService.signOut(user.getSession());
    Account account=accountDao.getAccount(testUser.getStudy(),testUser.getEmail());
    List<Subpopulation> subpops=subpopService.getSubpopulations(user.getStudyIdentifier());
    for (    Subpopulation subpop : subpops) {
      userConsentDao.deleteAllConsents(user.getUser().getHealthCode(),subpop.getGuid());
      ConsentSignature sig=account.getConsentSignatureHistory(subpop.getGuid()).get(0);
      sig=new ConsentSignature.Builder().withConsentSignature(sig).withSignedOn(0L).build();
      com.stormpath.sdk.account.Account stormpathAcct=((StormpathAccount)account).getAccount();
      CustomData data=stormpathAcct.getCustomData();
      data.put(subpop.getGuidString() + "String_Node_Str",BridgeObjectMapper.get().writeValueAsString(sig));
      data.put(subpop.getGuidString() + "String_Node_Str",2);
      data.remove(subpop.getGuidString() + "String_Node_Str");
      data.remove(subpop.getGuidString() + "String_Node_Str");
    }
    accountDao.updateAccount(testUser.getStudy(),account);
    Study study=studyService.getStudy(user.getStudyIdentifier());
    CriteriaContext context=new CriteriaContext.Builder().withStudyIdentifier(study.getStudyIdentifier()).withLanguages(TestUtils.newLinkedHashSet("String_Node_Str")).withClientInfo(ClientInfo.UNKNOWN_CLIENT).build();
    UserSession session=authService.signIn(study,context,user.getSignIn());
    for (    ConsentStatus status : session.getUser().getConsentStatuses().values()) {
      assertTrue(!status.isRequired() || status.isConsented());
      UserConsent consent=userConsentDao.getActiveUserConsent(session.getUser().getHealthCode(),SubpopulationGuid.create(status.getSubpopulationGuid()));
      assertTrue(consent.getSignedOn() > 0L);
    }
  }
  finally {
    helper.deleteUser(user);
  }
}