8,11 → 8,14 |
import pt.estgp.estgweb.services.jobs.JobDeamon; |
import pt.estgp.estgweb.services.jobs.ServiceJob; |
import pt.estgp.estgweb.services.logresults.ILogMessages; |
import pt.estgp.estgweb.services.logresults.LogMessageTypeEnum; |
import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessage; |
import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages; |
import pt.estgp.estgweb.services.questionarios.QuestionariosService; |
import pt.estgp.estgweb.web.exceptions.NotAuthorizedException; |
import pt.utl.ist.berserk.logic.serviceManager.IService; |
|
import java.util.ArrayList; |
import java.util.HashSet; |
import java.util.List; |
import java.util.Set; |
52,10 → 55,33 |
return new String[0]; |
|
String courses = job.getParameter(ServiceJob.JOB_questionario_courseList_KEY).getObject(); |
return deserializeCoursesList(courses); |
} |
|
public List<Course> getCoursesList(String coursesListJson) |
{ |
List<Course> courses = new ArrayList<Course>(); |
String[] courseIds = deserializeCoursesList(coursesListJson); |
for(String courseId: courseIds) |
{ |
try |
{ |
Course c = DaoFactory.getCourseDaoImpl().load(new Long(courseId)); |
courses.add(c); |
} |
catch(Throwable e) |
{ |
logger.info("Course not found in course list with id:" + courseId); |
} |
} |
return courses; |
} |
|
public String[] deserializeCoursesList(String json) |
{ |
try { |
|
JSONArray jsonArray = new JSONArray(courses); |
JSONArray jsonArray = new JSONArray(json); |
String[] coursesList = new String[jsonArray.length()]; |
for(int i=0;i <jsonArray.length();i++) |
{ |
103,34 → 129,128 |
return questionarioCleared; |
} |
|
|
@Override |
protected ILogMessages runJobServiceTask() throws Throwable |
{ |
DefaultLogMessages logMessages = new DefaultLogMessages(); |
long questionarioId = Long.parseLong(getParametersMap().get(ServiceJob.JOB_questionario_id_KEY).getObject()); |
QuestionarioImpl q = (QuestionarioImpl) DaoFactory.getQuestionarioDaoImpl().load(questionarioId); |
|
String[] coursesList = deserializeCoursesList((QuestionarioImpl) q); |
String[] coursesList = deserializeCoursesList(q); |
//Colocamos já aqui o estado para nao se poder mudar o Ano e o Semestre |
|
serviceLogInfo("Starting running service "); |
long total = 5000; |
long start = System.currentTimeMillis(); |
//Thread.sleep(20000); |
while(true) |
serviceLogInfo("Starting running service "); |
logger.info("Starting running service"); |
|
int count = 0; |
int totalCourses = coursesList.length; |
for(String courseStrId: coursesList) |
{ |
Thread.sleep(5000); |
long elapsed = System.currentTimeMillis() - start; |
setProgress((int) (((float)elapsed)/((float)total)*100.0f)); |
commitPartially(); |
DaoFactory.getQuestionarioDaoImpl().reattach(q); |
if(System.currentTimeMillis() - start > total) |
break; |
count++; |
try{ |
Long courseLong = Long.parseLong(courseStrId); |
/** logging **/ |
|
String msg = "Loading Course BACO ID: " + courseStrId; |
serviceLogInfo(msg); |
logger.info(msg); |
/** logging **/ |
|
Course c = DaoFactory.getCourseDaoImpl().load(courseLong); |
|
QuestionarioPedagogicoCursoAfeto cursoAfeto = DomainObjectFactory.createQuestionarioPedagogicoCursoAfeto(); |
cursoAfeto.setCourse(c); |
cursoAfeto.setAno(q.getYear()); |
cursoAfeto.setCodigoCurso(c.getCode()); |
cursoAfeto.setNome(c.getName()); |
cursoAfeto.setQuestionario(q); |
cursoAfeto.setSemestre(q.getSemestre()); |
cursoAfeto.setUnidadesAfetas(new HashSet<QuestionarioPedagogicoUnidadeCurricularAfeta>()); |
|
DaoFactory.getQuestionarioPedagogicoCursoAfetoDaoImpl().save(cursoAfeto); |
|
/** logging **/ |
msg = "(" + count + " of " + totalCourses + ")-> Course loaded: " + c.getName() + "(" + c.getCode() + ")"; |
serviceLogInfo(msg); |
logger.info(msg); |
/** logging **/ |
|
int countUnits = 0; |
int totalUnits = c.getCourseUnits().size(); |
for(CourseUnit cu : c.getCourseUnits()) |
{ |
countUnits++; |
/** logging **/ |
msg = "---->(" + countUnits + " of " + totalUnits +") CourseUnit loaded: " + cu.getName() + "(" + cu.getCode() + ")"; |
serviceLogInfo(msg); |
logger.info(msg); |
/** logging **/ |
|
|
QuestionarioPedagogicoUnidadeCurricularAfetaImpl unidadeAfeta = DomainObjectFactory.createQuestionarioPedagogicoUnidadeCurricularAfeta(); |
unidadeAfeta.setCourseUnit(cu); |
unidadeAfeta.setObs(""); |
|
unidadeAfeta.setCodigoUnidade(cu.getCode()); |
cursoAfeto.getUnidadesAfetas().add(unidadeAfeta);//so metemos de um dos lados |
|
unidadeAfeta.setMarked(false); |
if(cu.getTeachers() == null || cu.getTeachers().size() == 0) |
{ |
unidadeAfeta.setProfs(0); |
unidadeAfeta.setMarked(true); //WARNING |
unidadeAfeta.addObs("Não tem professores"); |
} |
else |
unidadeAfeta.setProfs(cu.getTeachers().size()); |
|
//todo falta as turmas verificacao de numero de profs |
// testar se ja tem notas acrescentar |
try{ |
unidadeAfeta.setTipologiasJson(((CourseUnitImpl)cu).getTipologiasClass().obtainMergeTipologiasSerialized()); |
} |
catch(Throwable e) |
{ |
unidadeAfeta.setMarked(true); |
unidadeAfeta.setTipologiasJson(CourseUnitImpl.Tipologias.serializeMergedList(new ArrayList<CourseUnitImpl.Tipologia>())); |
cursoAfeto.setMarcadas(cursoAfeto.getMarcadas()+1); |
//todo colocar as observacoes auqi e na unidade marcada |
} |
|
|
cursoAfeto.setCourse(c); |
cursoAfeto.setAno(q.getYear()); |
cursoAfeto.setCodigoCurso(c.getCode()); |
cursoAfeto.setNome(c.getName()); |
cursoAfeto.setQuestionario(q); |
cursoAfeto.setSemestre(q.getSemestre()); |
cursoAfeto.setUnidadesAfetas(new HashSet<QuestionarioPedagogicoUnidadeCurricularAfeta>()); |
|
DaoFactory.getQuestionarioPedagogicoCursoAfetoDaoImpl().save(cursoAfeto); |
|
|
} |
setProgress((int)((((float)count)/((float)totalCourses))*100.0f)); |
commitPartially(); |
} |
catch(Throwable t) |
{ |
logger.error(t,t); |
serviceLogError(t.toString(),t); |
logMessages.addMessage(new DefaultLogMessage("questionario.courses.selection", LogMessageTypeEnum.ERROR,t.toString())); |
} |
|
} |
setProgress(100); |
commitPartially(); |
|
serviceLogInfo("Set courses state as " + QuestionarioImpl.SubStatePedagogico.COURSES_ASSIGNED.name()); |
String msg = "Set courses state as " + QuestionarioImpl.SubStatePedagogico.COURSES_ASSIGNED.name(); |
serviceLogInfo(msg); |
logger.info(msg); |
q.setSubStatePedagogicoClass(QuestionarioImpl.SubStatePedagogico.COURSES_ASSIGNED); |
commitPartially(); |
return new DefaultLogMessages(); |
|
return logMessages; |
} |
} |