Source:
<code>private Person resolvePerson(Application application) throws DuplicatePersonException { EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO(); PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO(); UserDAO userDAO = DAOFactory.getInstance().getUserDAO(); JSONObject applicationData = JSONObject.fromObject(application.getFormData()); Map<Long, Person> existingPersons = new HashMap<Long, Person>(); boolean hasSsn = applicationData.getString("field-ssn-end") != null; if (hasSsn) { <START> String ssn = hasSsn ? ApplicationUtils.constructSSN(applicationData.getString("field-birthday"), applicationData.getString("field-ssn-end")) : null; <END> List<Person> persons = personDAO.listBySSNUppercase(ssn); for (Person person : persons) { existingPersons.put(person.getId(), person); } char[] ssnChars = ssn.toCharArray(); ssnChars[6] = ssnChars[6] == 'A' ? '-' : 'A'; ssn = ssnChars.toString(); persons = personDAO.listBySSNUppercase(ssn); for (Person person : persons) { existingPersons.put(person.getId(), person); } } String emailAddress = StringUtils.lowerCase(StringUtils.trim(applicationData.getString("field-email"))); List<Email> emails = emailDAO.listByAddressLowercase(emailAddress); for (Email email : emails) { if (email.getContactType() != null && Boolean.FALSE.equals(email.getContactType().getNonUnique())) { User user = userDAO.findByContactInfo(email.getContactInfo()); if (user != null) { Person person = user.getPerson(); if (person != null) { existingPersons.put(person.getId(), person); } } } } if (existingPersons.size() > 1) { StringBuilder sb = new StringBuilder(); for (Person person : existingPersons.values()) { if (sb.length() > 0) { sb.append(","); } sb.append(person.getId()); } logger.severe(String.format("Persons with duplicate SSN or unique email: %s", sb)); throw new DuplicatePersonException(); } else { return existingPersons.values().iterator().next(); } }</code><technical_language>hasSsn checked</technical_language>

Target:
private Person resolvePerson(Application application) throws DuplicatePersonException { EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO(); PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO(); UserDAO userDAO = DAOFactory.getInstance().getUserDAO(); JSONObject applicationData = JSONObject.fromObject(application.getFormData()); Map<Long, Person> existingPersons = new HashMap<Long, Person>(); boolean hasSsn = applicationData.getString("field-ssn-end") != null; if (hasSsn) { String ssn = ApplicationUtils.constructSSN(applicationData.getString("field-birthday"), applicationData.getString("field-ssn-end")); List<Person> persons = personDAO.listBySSNUppercase(ssn); for (Person person : persons) { existingPersons.put(person.getId(), person); } char[] ssnChars = ssn.toCharArray(); ssnChars[6] = ssnChars[6] == 'A' ? '-' : 'A'; ssn = ssnChars.toString(); persons = personDAO.listBySSNUppercase(ssn); for (Person person : persons) { existingPersons.put(person.getId(), person); } } String emailAddress = StringUtils.lowerCase(StringUtils.trim(applicationData.getString("field-email"))); List<Email> emails = emailDAO.listByAddressLowercase(emailAddress); for (Email email : emails) { if (email.getContactType() != null && Boolean.FALSE.equals(email.getContactType().getNonUnique())) { User user = userDAO.findByContactInfo(email.getContactInfo()); if (user != null) { Person person = user.getPerson(); if (person != null) { existingPersons.put(person.getId(), person); } } } } if (existingPersons.size() > 1) { StringBuilder sb = new StringBuilder(); for (Person person : existingPersons.values()) { if (sb.length() > 0) { sb.append(","); } sb.append(person.getId()); } logger.severe(String.format("Persons with duplicate SSN or unique email: %s", sb)); throw new DuplicatePersonException(); } else { return existingPersons.values().iterator().next(); } }