Subversion Repositories bacoAlunos

Compare Revisions

Ignore whitespace Rev 798 → Rev 799

/impl/src/java/pt/estgp/estgweb/utils/DatesUtils.java
206,6 → 206,7
 
public static void main(String [] args)
{
System.out.println(getImportYearIntranet("201213"));
System.out.println(getImportYearBefore("200001"));
System.out.println(getImportYear());
System.out.println(getImportYearFormatted("201314"));
/impl/src/java/pt/estgp/estgweb/services/courseunits/CreateCourseUnitDirPackageService.java
41,11 → 41,12
{
if(importYear == null || importYear.trim().length() == 0)
importYear = DatesUtils.getImportYear();
String importYearIntranet = DatesUtils.getImportYearIntranet();
String importYearIntranet = DatesUtils.getImportYearIntranet(importYear);
String tmpName = BytesUtils.generateHexKey();
String tmpDir = Globals.TMP_DIR + "/" + tmpName;
new File(tmpDir).mkdirs();
List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(importYear);
//List<Course> courses = DaoFactory.getCourseDaoImpl().findAll(importYear);
List<Course> courses = DaoFactory.getCourseDaoImpl().findAll();
try
{
FileWriter batRunner = new FileWriter(tmpDir + "/create.bat");
53,98 → 54,107
String back = "";
for(Course c: courses)
{
String couseDirPath = tmpDir + "/" + StringsUtils.normalizeResourceName(c.getName()) + '.' + c.getCode();
File courseDir = new File(couseDirPath);
courseDir.mkdirs();
try
//O curso é sempre o mesmo ID mas muda de Ano consoante o ano de importação
List<CourseUnit> courseUnits = DaoFactory.getCourseUnitDaoImpl().loadByCourse(c.getId(),importYear);
if(courseUnits == null || courseUnits.size() == 0)
{
String courseImportYearPathDos = couseDirPath + "\\" + importYearIntranet;
String courseImportYearPath = couseDirPath + "/" + importYearIntranet;
File courseImportYearDir = new File(courseImportYearPath);
courseImportYearDir.mkdirs();
new File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1).mkdirs();
new File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2).mkdirs();
new File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A).mkdirs();
FilesUtils.copy(CreateCourseUnitDirPackageService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1 + "/" + Globals.INTRANET_SETUP_FILE_NAME);
FilesUtils.copy(CreateCourseUnitDirPackageService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2 + "/" + Globals.INTRANET_SETUP_FILE_NAME);
FilesUtils.copy(CreateCourseUnitDirPackageService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A + "/" + Globals.INTRANET_SETUP_FILE_NAME);
logger.info("Skipping course: " + c.getCode() + ":" + c.getName() + " zero units in " + importYear);
}
else{
String couseDirPath = tmpDir + "/" + StringsUtils.normalizeResourceName(c.getName()) + '.' + c.getCode();
File courseDir = new File(couseDirPath);
courseDir.mkdirs();
try
{
 
String callPathS1 = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_S1 + "\\").substring(tmpDir.length() + 1);
String callPathS2 = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_S2 + "\\").substring(tmpDir.length() + 1);
String callPathA = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_A + "\\").substring(tmpDir.length() + 1);
batRunner.write("cd " + back + callPathS1);
back = "..\\..\\..\\";
batRunner.write("\n");
batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
batRunner.write("\n");
batRunner.write("cd " + back + callPathS2);
batRunner.write("\n");
batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
batRunner.write("\n");
batRunner.write("cd " + back + callPathA);
batRunner.write("\n");
batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
batRunner.write("\n");
FileWriter confWriterSemestre1 = new FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1 + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
FileWriter confWriterSemestre2 = new FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2 + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
FileWriter confWriterA = new FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
String courseImportYearPathDos = couseDirPath + "\\" + importYearIntranet;
String courseImportYearPath = couseDirPath + "/" + importYearIntranet;
File courseImportYearDir = new File(courseImportYearPath);
courseImportYearDir.mkdirs();
new File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1).mkdirs();
new File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2).mkdirs();
new File(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A).mkdirs();
FilesUtils.copy(CreateCourseUnitDirPackageService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1 + "/" + Globals.INTRANET_SETUP_FILE_NAME);
FilesUtils.copy(CreateCourseUnitDirPackageService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2 + "/" + Globals.INTRANET_SETUP_FILE_NAME);
FilesUtils.copy(CreateCourseUnitDirPackageService.class.getResourceAsStream(Globals.INTRANET_SETUP_FILE),courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A + "/" + Globals.INTRANET_SETUP_FILE_NAME);
 
String callPathS1 = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_S1 + "\\").substring(tmpDir.length() + 1);
String callPathS2 = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_S2 + "\\").substring(tmpDir.length() + 1);
String callPathA = (courseImportYearPathDos + "\\" + Globals.INTRANET_SEMESTRE_A + "\\").substring(tmpDir.length() + 1);
batRunner.write("cd " + back + callPathS1);
back = "..\\..\\..\\";
batRunner.write("\n");
batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
batRunner.write("\n");
batRunner.write("cd " + back + callPathS2);
batRunner.write("\n");
batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
batRunner.write("\n");
batRunner.write("cd " + back + callPathA);
batRunner.write("\n");
batRunner.write(Globals.INTRANET_SETUP_FILE_NAME + " " + Globals.INTRANET_USERS_SETUP_FILE_NAME);
batRunner.write("\n");
FileWriter confWriterSemestre1 = new FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S1 + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
FileWriter confWriterSemestre2 = new FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_S2 + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
FileWriter confWriterA = new FileWriter(courseImportYearPath + "/" + Globals.INTRANET_SEMESTRE_A + "/" + Globals.INTRANET_USERS_SETUP_FILE_NAME);
 
List<CourseUnit> courseUnits = DaoFactory.getCourseUnitDaoImpl().loadByCourse(c.getId(),importYear);
for(CourseUnit courseUnit: courseUnits)
{
FileWriter nowWriter;
String semestre;
if(courseUnit.getSemestre().equals("S1"))
 
// List<CourseUnit> courseUnits = DaoFactory.getCourseUnitDaoImpl().loadByCourse(c.getId(),importYear);
for(CourseUnit courseUnit: courseUnits)
{
nowWriter = confWriterSemestre1;
semestre = Globals.INTRANET_SEMESTRE_S1;
}
else if(courseUnit.getSemestre().equals("S2"))
{
nowWriter = confWriterSemestre2;
semestre = Globals.INTRANET_SEMESTRE_S2;
}
else
{
nowWriter = confWriterA;
semestre = Globals.INTRANET_SEMESTRE_A;
}
FileWriter nowWriter;
String semestre;
if(courseUnit.getSemestre().equals("S1"))
{
nowWriter = confWriterSemestre1;
semestre = Globals.INTRANET_SEMESTRE_S1;
}
else if(courseUnit.getSemestre().equals("S2"))
{
nowWriter = confWriterSemestre2;
semestre = Globals.INTRANET_SEMESTRE_S2;
}
else
{
nowWriter = confWriterA;
semestre = Globals.INTRANET_SEMESTRE_A;
}
 
String normalizedName = StringsUtils.normalizeResourceName(courseUnit.getName());
String unitPath = courseImportYearPath + "/" + semestre + "/" + normalizedName;
courseUnit.setNormalizedName(normalizedName);
courseUnit.setPathIntranet(unitPath.substring(tmpDir.length()));
nowWriter.write(normalizedName);
System.out.println("GENERATING LINE: " + normalizedName);
String normalizedName = StringsUtils.normalizeResourceName(courseUnit.getName());
String unitPath = courseImportYearPath + "/" + semestre + "/" + normalizedName;
courseUnit.setNormalizedName(normalizedName);
courseUnit.setPathIntranet(unitPath.substring(tmpDir.length()));
nowWriter.write(normalizedName);
System.out.println("GENERATING LINE: " + normalizedName);
 
if(courseUnit.getTeachers() != null)
{
String users = "";
int counter = 0;
for(Teacher t: courseUnit.getTeachers())
if(courseUnit.getTeachers() != null)
{
if(t.getUsername() != null)
String users = "";
int counter = 0;
for(Teacher t: courseUnit.getTeachers())
{
users += " " + t.getUsername();
counter++;
if(t.getUsername() != null)
{
users += " " + t.getUsername();
counter++;
}
}
nowWriter.write(" " + counter + users);
nowWriter.write("\n");
}
nowWriter.write(" " + counter + users);
nowWriter.write("\n");
}
confWriterSemestre1.flush();
confWriterSemestre2.flush();
confWriterA.flush();
confWriterSemestre1.close();
confWriterSemestre2.close();
confWriterA.close();
}
confWriterSemestre1.flush();
confWriterSemestre2.flush();
confWriterA.flush();
confWriterSemestre1.close();
confWriterSemestre2.close();
confWriterA.close();
catch (IOException e)
{
logger.error(e,e);
}
}
catch (IOException e)
{
logger.error(e,e);
}
}
batRunner.write("cd " + back);
batRunner.close();
161,8 → 171,8
 
public static void main(String[] args) throws ServiceException
{
String teste = "Sistemas Térmicos, Hidráulicos e Pneumáticos";
System.out.println(StringsUtils.normalizeResourceName(teste));
String teste = "Sistemas Térmicos, Hidráulicos e Pneumáticos";
System.out.println(StringsUtils.normalizeResourceName(teste));
// AbstractDao.getCurrentSession().beginTransaction();
// new CreateCourseUnitDirPackageService().run(null,null);
// AbstractDao.getCurrentSession().getTransaction().commit();
/impl/src/java/pt/estgp/estgweb/domain/dao/impl/CourseDaoImpl.java
186,6 → 186,8
.list();
}
 
 
// Duarte Santos
public List<String> loadAreas()
{