package pt.utl.ist.scripts.runOnce.delegates; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.organizationalStructure.DegreeUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.Function; import net.sourceforge.fenixedu.domain.organizationalStructure.FunctionType; import net.sourceforge.fenixedu.domain.organizationalStructure.PersonFunction; import org.joda.time.YearMonthDay; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; import pt.utl.ist.scripts.commons.AtomicScript; public class CreateDelegateRolesInDegreeUnits extends AtomicScript { private final String DELEGATE_OF_YEAR_NAME = "Delegado de Ano"; private final String DELEGATE_OF_DEGREE_NAME = "Delegado de Licenciatura"; private final String DELEGATE_OF_MASTER_DEGREE_NAME = "Delegado de Mestrado"; private final String DELEGATE_OF_INTEGRATED_MASTER_DEGREE_NAME = "Delegado de Mestrado Integrado"; @Override protected void run() throws Exception { YearMonthDay beginDate = new YearMonthDay(2007, 8, 1); for (FunctionType functionType : FunctionType.getAllDegreeDelegateFunctionTypes()) { for (Function function : Function.readAllActiveFunctionsByType(functionType)) { for (PersonFunction personFunction : function.getPersonFunctions()) { personFunction.delete(); } function.delete(); } } for (Degree degree : Degree.readAllByDegreeType(DegreeType.BOLONHA_DEGREE)) { DegreeUnit unit = degree.getUnit(); new Function(new MultiLanguageString(DELEGATE_OF_YEAR_NAME), beginDate, null, FunctionType.DELEGATE_OF_YEAR, unit); new Function(new MultiLanguageString(DELEGATE_OF_DEGREE_NAME), beginDate, null, FunctionType.DELEGATE_OF_DEGREE, unit); } for (Degree degree : Degree.readAllByDegreeType(DegreeType.BOLONHA_MASTER_DEGREE)) { DegreeUnit unit = degree.getUnit(); new Function(new MultiLanguageString(DELEGATE_OF_YEAR_NAME), beginDate, null, FunctionType.DELEGATE_OF_YEAR, unit); new Function(new MultiLanguageString(DELEGATE_OF_MASTER_DEGREE_NAME), beginDate, null, FunctionType.DELEGATE_OF_MASTER_DEGREE, unit); } for (Degree degree : Degree.readAllByDegreeType(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE)) { DegreeUnit unit = degree.getUnit(); new Function(new MultiLanguageString(DELEGATE_OF_YEAR_NAME), beginDate, null, FunctionType.DELEGATE_OF_YEAR, unit); new Function(new MultiLanguageString(DELEGATE_OF_DEGREE_NAME), beginDate, null, FunctionType.DELEGATE_OF_DEGREE, unit); new Function(new MultiLanguageString(DELEGATE_OF_MASTER_DEGREE_NAME), beginDate, null, FunctionType.DELEGATE_OF_MASTER_DEGREE, unit); new Function(new MultiLanguageString(DELEGATE_OF_INTEGRATED_MASTER_DEGREE_NAME), beginDate, null, FunctionType.DELEGATE_OF_INTEGRATED_MASTER_DEGREE, unit); } } public static void main(String[] args) { processWriteTransaction(new CreateDelegateRolesInDegreeUnits()); System.exit(0); } }