package pt.utl.ist.scripts.runOnce.person; import java.util.HashMap; import java.util.Map; import net.sourceforge.fenixedu.domain.Person; import pt.utl.ist.scripts.commons.AtomicScript; public class FindDuplicatedPersonsByNameAndId extends AtomicScript { private static final Map> duplicatedPersonsById = new HashMap>(); private static final Map> duplicatedPersonsByName = new HashMap>(); @Override protected void run() throws Exception { for (Person person : Person.readAllPersons()) { String name = person.getName().trim(); String identification = person.getDocumentIdNumber().trim(); java.util.List personListById = duplicatedPersonsById.get(identification); java.util.List personListByName = duplicatedPersonsByName.get(name); personListById = personListById != null ? personListById : new java.util.ArrayList(); personListByName = personListByName != null ? personListByName : new java.util.ArrayList(); personListById.add(person); personListByName.add(person); duplicatedPersonsById.put(identification, personListById); duplicatedPersonsByName.put(identification, personListByName); } System.out.println("------------------- Duplicated Ids -------------------"); for (String id : duplicatedPersonsById.keySet()) { java.util.List personList = duplicatedPersonsById.get(id); if (personList.size() <= 1) { continue; } System.out.println(String.format("For this id %s", id)); for (Person person : personList) { System.out.println(String.format("\tNome - %s; Identification Type - %s: ", person.getName(), person .getIdDocumentType().getLocalizedName())); } } System.out.println("------------------- Duplicated Names -------------------"); for (String name : duplicatedPersonsByName.keySet()) { java.util.List personList = duplicatedPersonsByName.get(name); if (personList.size() <= 1) { continue; } System.out.println(String.format("For this name %s", name)); for (Person person : personList) { System.out.println(String.format("\tName - %s; Identification Type - %s: ", person.getName(), person .getIdDocumentType().getLocalizedName())); } } } /** * @param args */ public static void main(String[] args) { process(new FindDuplicatedPersonsByNameAndId()); } }