package pt.utl.ist.codeGenerator.database; import java.util.Calendar; import java.util.Locale; import net.sourceforge.fenixedu._development.PropertiesManager; import net.sourceforge.fenixedu.applicationTier.IUserView; import net.sourceforge.fenixedu.applicationTier.utils.MockUserView; import net.sourceforge.fenixedu.domain.Country; import net.sourceforge.fenixedu.domain.CurricularYear; import net.sourceforge.fenixedu.domain.EmptyDegree; import net.sourceforge.fenixedu.domain.EmptyDegreeCurricularPlan; import net.sourceforge.fenixedu.domain.Login; import net.sourceforge.fenixedu.domain.LoginAlias; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.ResourceAllocationRole; import net.sourceforge.fenixedu.domain.Role; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.User; import net.sourceforge.fenixedu.domain.organizationalStructure.AccountabilityType; import net.sourceforge.fenixedu.domain.organizationalStructure.AccountabilityTypeEnum; import net.sourceforge.fenixedu.domain.organizationalStructure.CountryUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.PartyType; import net.sourceforge.fenixedu.domain.organizationalStructure.PartyTypeEnum; import net.sourceforge.fenixedu.domain.organizationalStructure.PlanetUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.Unit; import net.sourceforge.fenixedu.domain.organizationalStructure.UnitClassification; import net.sourceforge.fenixedu.domain.person.Gender; import net.sourceforge.fenixedu.domain.person.IDDocumentType; import net.sourceforge.fenixedu.domain.person.IdDocumentTypeObject; import net.sourceforge.fenixedu.domain.person.RoleType; import org.joda.time.YearMonthDay; import pt.ist.fenixWebFramework.security.UserView; import pt.ist.fenixframework.Config; import pt.ist.fenixframework.FenixFramework; import pt.ist.fenixframework.pstm.Transaction; import pt.utl.ist.fenix.tools.util.DomainModelDirFileLister; import pt.utl.ist.fenix.tools.util.i18n.Language; import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString; import com.linkare.commons.metainfo.Linkare; public class DataInitializer { @Linkare(author = "Paulo Zenida", comments = "Changed code so that it uses a directory instead of a specific DML file.") public static void main(String[] args) { Config config = PropertiesManager.getFenixFrameworkConfig(DomainModelDirFileLister .listDomainModelFiles("build/WEB-INF/classes/")); FenixFramework.initialize(config); RootDomainObject.init(); try { Transaction.withTransaction(false, new jvstm.TransactionalCommand() { public void doIt() { try { initialize(); } catch (Exception e) { e.printStackTrace(); throw new Error("Found exception while processing script: " + e, e); } } }); } catch (Exception ex) { ex.printStackTrace(); } System.out.println("Initialization complete."); System.exit(0); } @Linkare(author = "Paulo Zenida", comments = "Added the invocation of the last three methods") private static void initialize() { if (RootDomainObject.getInstance() == null) { System.out.println("You need to manually create a RootDomainObject in the database first"); return; } createRoles(); createCurricularYearsAndSemesters(); createCountries(); createManagerUser(); createPartyTypeEnums(); createAccountabilityTypeEnums(); createOrganizationalStructure(); // Linkare createExternalUnitStructure(); createEmptyDegree(); createIDDocumentTypeObjects(); createEmptyDegreeCurricularPlan(); } @Linkare(author = "Paulo Zenida", comments = "Added missing roles for the initialization of the database") private static void createRoles() { new Role(RoleType.PERSON, "/person", "/index.do", "portal.person"); new Role(RoleType.STUDENT, "/student", "/index.do", "portal.student"); new Role(RoleType.TEACHER, "/teacher", "/index.do", "portal.teacher"); new Role(RoleType.MASTER_DEGREE_CANDIDATE, "/masterDegreeCandidate", "/index.do", "portal.candidate"); new Role(RoleType.MASTER_DEGREE_ADMINISTRATIVE_OFFICE, "/masterDegreeAdministrativeOffice", "/index.do", "portal.masterDegree"); new Role(RoleType.TREASURY, "/treasury", "/index.do", "portal.treasury"); new Role(RoleType.COORDINATOR, "/coordinator", "/index.do", "portal.coordinator"); new Role(RoleType.EMPLOYEE, "/employee", "/index.do", "portal.employee"); new Role(RoleType.PERSONNEL_SECTION, "/personnelSection", "/index.do", "portal.personnelSection"); new Role(RoleType.MANAGER, "/manager", "/index.do", "portal.manager"); new Role(RoleType.CREDITS_MANAGER, "/facultyAdmOffice", "/index.do", "portal.credits"); new Role(RoleType.DEPARTMENT_CREDITS_MANAGER, "/departmentAdmOffice", "/index.do", "portal.credits.department"); new Role(RoleType.GRANT_OWNER, "/grantOwner", "/index.do", "portal.grantOwner"); new Role(RoleType.SEMINARIES_COORDINATOR, "/teacher", "/seminariesIndex.do", "portal.seminariesCoordinator"); new Role(RoleType.OPERATOR, "/operator", "/index.do", "portal.operator"); new Role(RoleType.WEBSITE_MANAGER, "/webSiteManager", "/index.do", "portal.webSiteManager"); new Role(RoleType.GRANT_OWNER_MANAGER, "/facultyAdmOffice", "/index.do", "portal.facultyAdmOffice"); new Role(RoleType.DEPARTMENT_ADMINISTRATIVE_OFFICE, "/departmentAdmOffice", "/index.do", "portal.departmentAdmOffice"); new Role(RoleType.GEP, "/gep", "/index.do", "portal.gep"); new Role(RoleType.DIRECTIVE_COUNCIL, "/directiveCouncil", "/index.do", "portal.directiveCouncil"); new Role(RoleType.DEGREE_ADMINISTRATIVE_OFFICE, "/degreeAdministrativeOffice", "/index.do", "portal.degreeAdministrativeOffice"); new Role(RoleType.DEGREE_ADMINISTRATIVE_OFFICE_SUPER_USER, "/degreeAdministrativeOffice", "/index.do", "portal.degreeAdministrativeOfficeSuperUser"); new Role(RoleType.DELEGATE, "/delegate", "/index.do", "portal.delegate"); new Role(RoleType.PROJECTS_MANAGER, "/projectsManagement", "/index.do", "portal.projectsManager"); new Role(RoleType.INSTITUCIONAL_PROJECTS_MANAGER, "/institucionalProjectsManagement", "/institucionalProjectIndex.do", "portal.institucionalProjectsManager"); new Role(RoleType.DEPARTMENT_MEMBER, "/departmentMember", "/index.do", "portal.departmentMember"); new Role(RoleType.BOLONHA_MANAGER, "/bolonhaManager", "/index.do", "portal.bolonhaManager"); new Role(RoleType.SCIENTIFIC_COUNCIL, "/scientificCouncil", "/index.do", "portal.scientificCouncil"); new Role(RoleType.SPACE_MANAGER, "/SpaceManager", "/index.do", "portal.SpaceManager"); new Role(RoleType.RESEARCHER, "/researcher", "/index.do", "portal.researcher"); new Role(RoleType.PEDAGOGICAL_COUNCIL, "/pedagogicalCouncil", "/index.do", "portal.PedagogicalCouncil"); new Role(RoleType.ALUMNI, "/alumin", "/in-dex.do", "portal.alumni"); new Role(RoleType.CANDIDATE, "/candidate", "/index.do", "portal.candidate"); new Role(RoleType.EXAM_COORDINATOR, "/examCoordination", "/index.do", "portal.examCoordinator"); new Role(RoleType.PARKING_MANAGER, "/parkingManager", "/index.do", "portal.parkingManager"); new Role(RoleType.ACADEMIC_ADMINISTRATIVE_OFFICE, "/academicAdminOffice", "/index.do", "portal.academicAdminOffice"); new Role(RoleType.MESSAGING, "/messaging", "/index.do", "portal.messaging"); new Role(RoleType.SPACE_MANAGER_SUPER_USER, "/spaceManagerSuperUser", "/index.do", "portal.spaceManagerSuperUser"); new Role(RoleType.INTERNATIONAL_RELATION_OFFICE, "/internationalRelatOffice", "/index.do", "portal.internRelationOffice"); new ResourceAllocationRole("/resourceAllocationManager", "/paginaPrincipal.jsp", "portal.resourceAllocationManager"); new Role(RoleType.RESOURCE_MANAGER, "/resourceManager", "/index.do", "portal.resourceManager"); new Role(RoleType.IDENTIFICATION_CARD_MANAGER, "/identificationCardManager", "/index.do", "portal.identificationCardManager"); new Role(RoleType.TUTORSHIP, "/pedagogicalCouncil", "/index.do", "portal.PedagogicalCouncil"); // Linkare! new Role(RoleType.ERASMUS, "/student", "/index.do", "portal.student"); new Role(RoleType.IT_PROJECTS_MANAGER, "/itProjectsManagement", "/itProjectIndex.do", "portal.itProjectsManager"); new Role(RoleType.CMS_MANAGER, "/CMSManager", "/index.do", "portal.CMSManager"); new Role(RoleType.LIBRARY, "/library", "/index.do", "portal.library"); } private static void createCurricularYearsAndSemesters() { new CurricularYear(Integer.valueOf(1), 2); new CurricularYear(Integer.valueOf(2), 2); new CurricularYear(Integer.valueOf(3), 2); new CurricularYear(Integer.valueOf(4), 2); new CurricularYear(Integer.valueOf(5), 2); } @Linkare(author = "Paulo Zenida", comments = "Set the default locale to pt") private static void createCountries() { Language.setDefaultLocale(new Locale("pt")); new Country("Portugal", "Portuguesa", "pt"); new Country("Angola", "Angolana", "ao"); new Country("Cabo Verde", "Cabo-Verdiana", "cv"); new Country("Guiné-Bissau", "Guineense-Bissau", "gw"); new Country("Moçambique", "Moçambicana", "mz"); new Country("São Tomé e Principe", "São Tomense", "st"); new Country("Brasil", "Brasileira", "br"); new Country("Bélgica", "Belga", "be"); new Country("Espanha", "Espanhola", "es"); new Country("França", "Francesa", "fr"); new Country("Holanda", "Holandesa", "nl"); new Country("Irlanda", "Irlandesa", "ie"); new Country("Itália", "Italiana", "it"); new Country("Luxemburgo", "Luxemburguesa", "lu"); new Country("Alemanha", "Alemã", "de"); new Country("Reino Unido", "Britânica", "uk"); new Country("Grécia", "Grega", "gr"); new Country("Finlândia", "Finlandesa", "fi"); new Country("Áustria", "Austríaca", "at"); new Country("Noruega", "Norueguesa", "no"); new Country("Suécia", "Sueca", "se"); new Country("Polónia", "Polaca", "pl"); new Country("Rússia", "Russa", "ru"); new Country("Roménia", "Romena", "ro"); new Country("Suiça", "Suiça", "ch"); new Country("África do Sul", "Sul-Africana", "za"); new Country("Marrocos", "Marroquina", "ma"); new Country("Républica do Zaire", "Zairense", "zr"); new Country("Quénia", "Queniana", "ke"); new Country("Líbia", "Líbia", "ly"); new Country("Zimbabué", "Zimbabué", "zw"); new Country("Palestina", "Palestina", "ps"); new Country("Irão", "Iraniana", "ir"); new Country("Paquistão", "Paquistanesa", "pk"); new Country("Austrália", "Australiana", "au"); new Country("Estados Unidos da América", "Norte Americana", "us"); new Country("Paraguai", "Paraguaia", "py"); new Country("Canadá", "Canadiana", "ca"); new Country("Argentina", "Argentina", "ar"); new Country("Chile", "Chilena", "cl"); new Country("Equador", "Equatoriana", "ec"); new Country("Venezuela", "Venezuelana", "ve"); new Country("México", "Mexicana", "mx"); new Country("Bulgária", "Bulgara", "bg"); new Country("Colombia", "Colombiana", "co"); new Country("Eslováquia", "Eslovaca", "sk"); new Country("China", "Chinesa", "cn"); new Country("Timor Loro Sae", "Timorense", "tp"); new Country("Dinamarca", "Dinamarquesa", "dk"); new Country("Iraque", "Iraquiana", "iq"); new Country("Perú", "Peruana", "pe"); new Country("República Checa", "Checa", "cz"); new Country("Turquia", "Turca", "tk"); new Country("Sérvia e Montenegro", "Sérvia e Montenegro", "cs"); new Country("Jugoslávia", "Jugoslava", "yu"); new Country("Índia", "Indiana", "in"); new Country("Ucrânia", "Ucraniana", "ua"); new Country("Eslovénia", "Eslovena", "si"); new Country("Vietname", "Vietnamita", "vn"); new Country("Estónia", "Estónia", "ee"); new Country("Senegal", "Senegalesa", "sn"); new Country("Singapura", "Singapura", "sg"); new Country("Tailândia", "Tailandesa", "th"); new Country("Botswana", "Botswana", "bw"); new Country("Bolívia", "Boliviana", "bo"); new Country("Tunísia", "Tunisina", "tn"); new Country("Kuwait", "Kuwait", "kw"); new Country("Costa Rica", "Costariquenho", "cr"); new Country("Indonésia", "Indonésia", "id"); new Country("Japão", "Japonesa", "jp"); new Country("Israel", "Israelita", "il"); new Country("Guatemala", "Guatemalteco", "gp"); new Country("Egipto", "Egípcia", "eg"); new Country("Húngria", "Hungara", "hu"); new Country("Croácia", "Croata", "hr"); new Country("Maurícias", "Maurícias", "mu"); new Country("Malta", "Maltês", "mt"); new Country("Porto Rico", "Portoriquenha", "pr"); new Country("Chipre", "Cipriota", "cy"); new Country("Lituânia", "Lituana", "lt"); new Country("Letónia", "Letónia", "lv"); new Country("Malásia", "Malaia", "my"); new Country("Macau", "Macaense", "mc"); new Country("Macedónia", "Macedónia", "mk"); new Country("Coreia do Sul", "Coreana", "kr"); new Country("Mauritânia", "Mauritânia", "mr"); new Country("Hong Kong", "Hong Kong", "hk"); } @Linkare(author = "Paulo Zenida", comments = "Added the set of the password") private static void createManagerUser() { final Person person = new Person("Fenix System Administrator", Gender.MALE, String.valueOf(Calendar.getInstance() .getTimeInMillis()), IDDocumentType.OTHER); person.setName("Fenix System Administrator"); person.addPersonRoles(Role.getRoleByRoleType(RoleType.PERSON)); person.addPersonRoles(Role.getRoleByRoleType(RoleType.MANAGER)); person.setIsPassInKerberos(Boolean.FALSE); final User user = person.getUser(); final Login login = user.readUserLoginIdentification(); login.setActive(Boolean.TRUE); login.setPassword("fenixadmin"); LoginAlias.createNewCustomLoginAlias(login, "adminportal"); login.openLoginIfNecessary(RoleType.MANAGER); final IUserView userView = new MockUserView(user.getUserUId(), person.getPersonRoles(), person); UserView.setUser(userView); } private static void createPartyTypeEnums() { for (final PartyTypeEnum partyTypeEnum : PartyTypeEnum.values()) { new PartyType(partyTypeEnum); } } private static void createAccountabilityTypeEnums() { for (final AccountabilityTypeEnum accountabilityTypeEnum : AccountabilityTypeEnum.values()) { new AccountabilityType(accountabilityTypeEnum, new MultiLanguageString(accountabilityTypeEnum.getName())); } } private static void createOrganizationalStructure() { final RootDomainObject rootDomainObject = RootDomainObject.getInstance(); final PlanetUnit planetUnit = PlanetUnit.createNewPlanetUnit(new MultiLanguageString(Language.getDefaultLanguage(), "Earth"), null, "E", new YearMonthDay(), null, null, null, null, false, null); rootDomainObject.setEarthUnit(planetUnit); createCountryUnits(rootDomainObject, planetUnit); } private static void createCountryUnits(final RootDomainObject rootDomainObject, final PlanetUnit planetUnit) { for (final Country country : rootDomainObject.getCountrysSet()) { CountryUnit.createNewCountryUnit(new MultiLanguageString(Language.getDefaultLanguage(), country.getName()), null, country.getCode(), new YearMonthDay(), null, planetUnit, null, null, false, null); } } @Linkare(author = "Paulo Zenida") private static void createExternalUnitStructure() { final Unit externalInstitutionUnit = Unit.createNewUnit(new MultiLanguageString(Language.pt, "Instituições Externas"), null, "IE", new YearMonthDay(), null, null, AccountabilityType .readByType(AccountabilityTypeEnum.ORGANIZATIONAL_STRUCTURE), null, UnitClassification.OUT, Boolean.FALSE, null); RootDomainObject.getInstance().setExternalInstitutionUnit(externalInstitutionUnit); } @Linkare(author = "Paulo Zenida") private static void createEmptyDegree() { EmptyDegree.getInstance(); } @Linkare(author = "Paulo Zenida") private static void createIDDocumentTypeObjects() { for (final IDDocumentType idDocumentType : IDDocumentType.values()) { new IdDocumentTypeObject(idDocumentType); } } @Linkare(author = "Paulo Zenida") private static void createEmptyDegreeCurricularPlan() { EmptyDegreeCurricularPlan.getInstance(); } }