Skip to content

Instantly share code, notes, and snippets.

@pedrosan7os
Created November 12, 2014 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrosan7os/12286574202612a66017 to your computer and use it in GitHub Desktop.
Save pedrosan7os/12286574202612a66017 to your computer and use it in GitHub Desktop.
InitializeAdministrativeOffices
package pt.ist.fenix.webapp;
import org.fenixedu.academic.domain.administrativeOffice.AdministrativeOffice;
import org.fenixedu.academic.domain.organizationalStructure.Accountability;
import org.fenixedu.academic.domain.organizationalStructure.PersonFunction;
import org.fenixedu.academic.domain.organizationalStructure.Unit;
import org.fenixedu.bennu.core.domain.Bennu;
import org.fenixedu.bennu.core.domain.User;
import org.fenixedu.bennu.scheduler.custom.CustomTask;
public class InitializeAdministrativeOffices extends CustomTask {
@Override
public void runTask() throws Exception {
for (AdministrativeOffice office : Bennu.getInstance().getAdministrativeOfficesSet()) {
office.setName(office.getUnit().getPartyName().toLocalizedString());
office.setCoordinator(getActiveUnitCoordinator(office.getUnit()));
office.setCampus(office.getUnit().getCampus());
}
}
private static User getActiveUnitCoordinator(Unit unit) {
for (final Accountability accountability : unit.getUnitCoordinatorFunction().getAccountabilitiesSet()) {
if (accountability.isPersonFunction() && accountability.isActive()) {
return ((PersonFunction) accountability).getPerson().getUser();
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment