package pt.utl.ist.scripts.runOnce.contacts; import java.util.List; import java.util.Set; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.contacts.PartyContact; import net.sourceforge.fenixedu.domain.contacts.PhysicalAddress; import net.sourceforge.fenixedu.domain.organizationalStructure.Party; import pt.ist.bennu.core.domain.Bennu; import pt.utl.ist.scripts.commons.AtomicScript; public class FixValidatePhysicalAddressOnlyOne extends AtomicScript { @Override protected void run() throws Exception { final Set partysSet = Bennu.getInstance().getPartysSet(); for (Party party : partysSet) { if (party instanceof Person) { Person person = (Person) party; final PhysicalAddress defaultPhysicalAddress = person.getDefaultPhysicalAddress(); if (defaultPhysicalAddress == null) { final List allPartyContacts = person.getAllPartyContacts(PhysicalAddress.class); if (allPartyContacts.size() == 1) { final PartyContact physicalAddress = allPartyContacts.get(0); physicalAddress.setValid(); physicalAddress.setDefaultContact(true); System.out.printf("set physicalAddress valid %s %s\n", physicalAddress.getExternalId(), person.getPresentationName()); } } } } } public static void main(String... args) { processWriteTransaction(new FixValidatePhysicalAddressOnlyOne()); } }