Rev 1692 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
116 | jmachado | 1 | package pt.estgp.estgweb.services.sigesimports; |
2 | |||
163 | jmachado | 3 | import jomm.dao.impl.AbstractDao; |
219 | jmachado | 4 | import jomm.utils.StringsUtils; |
116 | jmachado | 5 | import org.apache.log4j.Logger; |
995 | jmachado | 6 | import org.hibernate.HibernateException; |
7 | import org.hibernate.StaleStateException; |
||
1814 | jmachado | 8 | import pt.estgp.estgweb.utils.Globals; |
223 | jmachado | 9 | import pt.estgp.estgweb.domain.*; |
129 | susana | 10 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
995 | jmachado | 11 | import pt.estgp.estgweb.services.common.CommonServicesManager; |
12 | import pt.estgp.estgweb.services.email.SendEmailService; |
||
163 | jmachado | 13 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
995 | jmachado | 14 | import pt.estgp.estgweb.services.jobs.ServiceJob; |
165 | jmachado | 15 | import pt.estgp.estgweb.services.logresults.ILogMessages; |
16 | import pt.estgp.estgweb.services.logresults.LogMessageTypeEnum; |
||
995 | jmachado | 17 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessage; |
165 | jmachado | 18 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages; |
1298 | jmachado | 19 | import pt.estgp.estgweb.services.sigesimports.oracle.dao.AlunoDao; |
20 | import pt.estgp.estgweb.services.sigesimports.oracle.dao.TurmaDao; |
||
1312 | jmachado | 21 | import pt.estgp.estgweb.services.sigesimports.oracle.dao.connection.ConnectionManager; |
1298 | jmachado | 22 | import pt.estgp.estgweb.services.sigesimports.oracle.domain.Aluno; |
23 | import pt.estgp.estgweb.services.sigesimports.oracle.domain.AlunoHistorico; |
||
24 | import pt.estgp.estgweb.services.sigesimports.oracle.domain.Disciplina; |
||
1553 | jmachado | 25 | import pt.estgp.estgweb.services.sigesimports.oracle.domain.Nacionalidade; |
995 | jmachado | 26 | import pt.estgp.estgweb.utils.ConfigProperties; |
863 | jmachado | 27 | import pt.estgp.estgweb.utils.Email; |
116 | jmachado | 28 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
29 | |||
1312 | jmachado | 30 | import java.sql.Connection; |
31 | import java.sql.PreparedStatement; |
||
32 | import java.sql.ResultSet; |
||
1298 | jmachado | 33 | import java.sql.SQLException; |
1312 | jmachado | 34 | import java.text.MessageFormat; |
863 | jmachado | 35 | import java.util.*; |
129 | susana | 36 | |
37 | |||
116 | jmachado | 38 | /** |
39 | * @author Jorge Machado |
||
40 | * @date 11/May/2008 |
||
41 | * @time 12:51:32 |
||
42 | * @see pt.estgp.estgweb |
||
43 | */ |
||
995 | jmachado | 44 | public class ImportStudentsService extends ServiceJob implements IService |
116 | jmachado | 45 | { |
46 | |||
219 | jmachado | 47 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(ImportStudentsService.class); |
1312 | jmachado | 48 | private static final int MAX_COMMIT = 5; |
116 | jmachado | 49 | |
995 | jmachado | 50 | int studentsMerged = 0; |
51 | int studentsNew = 0; |
||
52 | int studentsZeroUnits = 0; |
||
53 | int unitsNotFound = 0; |
||
1145 | jmachado | 54 | int unitsNotFoundTurma = 0; |
995 | jmachado | 55 | int unitsRemovedToStudents = 0; |
56 | int unitsLocalAddedNotRemoved = 0; |
||
996 | jmachado | 57 | int unitsLocallyRemovedNotAdded = 0; |
1277 | jmachado | 58 | int unitsRepeated = 0; |
995 | jmachado | 59 | int alunosFound = 0; |
60 | int studentsChangeBI = 0; |
||
996 | jmachado | 61 | int unitsAddedToStudents = 0; |
1218 | jmachado | 62 | int alunosErasmusCadeirasEcontradas = 0; |
1396 | jmachado | 63 | int alunosSemTurmaParaAUnidades = 0; |
1229 | jmachado | 64 | int turmaMoreThanOneRegularCourse = 0; |
1341 | jmachado | 65 | int unidadesProcuradasNumCursoAleatorio = 0; |
1312 | jmachado | 66 | List<String> turmasMoreThanOneCourse = new ArrayList<String>(); |
67 | int turmasWrongSubscriptions = 0; |
||
68 | int estudantesDesaparecidosDoSigesNesteAno = 0; |
||
69 | int estudantesComCadeirasSemTurma = 0; |
||
70 | int turmasComCodigoNullRemovidas = 0; |
||
71 | int unidadesSoComAlunosExtra = 0; |
||
1396 | jmachado | 72 | int turmasVindasANullDoSIGES = 0; |
1400 | jmachado | 73 | int turmasVindasANullDoSIGESEncontradasNoutroCampo = 0; |
995 | jmachado | 74 | |
1312 | jmachado | 75 | |
76 | |||
77 | |||
1224 | jmachado | 78 | //Vasco da Gama |
79 | //Cadeiras a Vulso |
||
80 | //Erasmus |
||
1229 | jmachado | 81 | //disciplinas a vulso ESS |
1312 | jmachado | 82 | static 1.5.0/docs/api/java/lang/Integer.html">Integer[] cursosFicticios = null; |
1224 | jmachado | 83 | |
1279 | jmachado | 84 | static boolean studentComUnidadesRepetidas = false; |
85 | |||
1312 | jmachado | 86 | public ILogMessages run(1.5.0/docs/api/java/lang/String.html">String year,int institutionCode) throws ServiceException |
165 | jmachado | 87 | { |
995 | jmachado | 88 | studentsMerged = 0; |
89 | studentsNew = 0; |
||
90 | studentsZeroUnits = 0; |
||
91 | unitsNotFound = 0; |
||
1145 | jmachado | 92 | unitsNotFoundTurma = 0; |
995 | jmachado | 93 | unitsRemovedToStudents = 0; |
94 | unitsLocalAddedNotRemoved = 0; |
||
996 | jmachado | 95 | unitsLocallyRemovedNotAdded = 0; |
995 | jmachado | 96 | alunosFound = 0; |
996 | jmachado | 97 | studentsChangeBI = 0; |
98 | unitsAddedToStudents = 0; |
||
1218 | jmachado | 99 | alunosErasmusCadeirasEcontradas = 0; |
1277 | jmachado | 100 | unitsRepeated = 0; |
1229 | jmachado | 101 | turmaMoreThanOneRegularCourse = 0; |
1312 | jmachado | 102 | turmasMoreThanOneCourse = new ArrayList<String>(); |
103 | turmasWrongSubscriptions = 0; |
||
104 | estudantesDesaparecidosDoSigesNesteAno = 0; |
||
105 | estudantesComCadeirasSemTurma = 0; |
||
106 | turmasComCodigoNullRemovidas = 0; |
||
107 | unidadesSoComAlunosExtra = 0; |
||
1341 | jmachado | 108 | unidadesProcuradasNumCursoAleatorio = 0; |
1396 | jmachado | 109 | alunosSemTurmaParaAUnidades = 0; |
110 | turmasVindasANullDoSIGES = 0; |
||
1312 | jmachado | 111 | ImportCourseService.resetCourseYearTurmaPolicy(); |
995 | jmachado | 112 | |
1279 | jmachado | 113 | |
114 | |||
1312 | jmachado | 115 | 1.5.0/docs/api/java/lang/String.html">String activeImportYearParaVerificacaoDePropinasEmDia = DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear(); |
1048 | jmachado | 116 | |
995 | jmachado | 117 | 1.5.0/docs/api/java/lang/String.html">String msgS = "STARTING STUDENTS IMPORT SERVICE FOR YEAR: " + year; |
1140 | jmachado | 118 | |
119 | |||
995 | jmachado | 120 | serviceLogInfo(msgS); |
121 | logger.info(msgS); |
||
122 | |||
165 | jmachado | 123 | DefaultLogMessages logMessages = new DefaultLogMessages(); |
995 | jmachado | 124 | |
1312 | jmachado | 125 | logMessages.addMessage(new DefaultLogMessage("import.students", LogMessageTypeEnum.INFO, "instituicao " + institutionCode)); |
126 | |||
163 | jmachado | 127 | try |
128 | { |
||
1312 | jmachado | 129 | AlunoDao service = AlunoDao.getInstance(); |
130 | 1.5.0/docs/api/java/sql/Connection.html">Connection conn = ConnectionManager.openConnection(); |
||
1140 | jmachado | 131 | |
1553 | jmachado | 132 | HashMap<Integer,Nacionalidade> nacionalidades = service.loadNacionalidades(conn); |
1312 | jmachado | 133 | /** |
134 | * Carrega alunos do SIGES com cadeiras no ano requerido |
||
135 | */ |
||
136 | List<Integer> codigos = service.loadCodigosAlunos(institutionCode, year,conn); |
||
163 | jmachado | 137 | |
1312 | jmachado | 138 | /** |
139 | * Este método vai procurar alunos no BACO neste ano que não vieram do SIGES |
||
140 | * Os alunos que não vieram da extração do SIGES e terão de ser consistidos |
||
141 | * pois as suas unidades ter desaparecido todas de uma vez e vão aqui ficar penduradas |
||
142 | * Se foram adicionadas manualmente então nao serao removidas |
||
143 | */ |
||
144 | removerUnidadesDosDesaparecidosDoSiges(year, institutionCode, codigos); |
||
145 | |||
165 | jmachado | 146 | int i = 1; |
995 | jmachado | 147 | |
1298 | jmachado | 148 | for (1.5.0/docs/api/java/lang/Integer.html">Integer c : codigos) |
129 | susana | 149 | { |
995 | jmachado | 150 | alunosFound++; |
1312 | jmachado | 151 | if (i++ >= MAX_COMMIT) |
165 | jmachado | 152 | { |
153 | i = 0; |
||
1312 | jmachado | 154 | setProgress((int) ((((float) alunosFound) / ((float) codigos.size())) * 0.95f * 100.0f)); |
155 | conn.close(); |
||
1076 | jmachado | 156 | commitPartially(); |
1312 | jmachado | 157 | conn = ConnectionManager.openConnection(); |
165 | jmachado | 158 | } |
159 | |||
1312 | jmachado | 160 | Aluno alunoSiges = service.loadInscrito(c,institutionCode, year,conn); |
1341 | jmachado | 161 | if(alunoSiges.getCodigo()==15726) |
162 | 1.5.0/docs/api/java/lang/System.html">System.out.println(""); |
||
1553 | jmachado | 163 | Student s = loadStudent(alunoSiges,nacionalidades); |
165 | jmachado | 164 | boolean newUser = false; |
1312 | jmachado | 165 | if(s.getId() <= 0) |
165 | jmachado | 166 | { |
1312 | jmachado | 167 | i = MAX_COMMIT+1; //Para fazer commit já na póxima iteração |
411 | jmachado | 168 | DaoFactory.getStudentDaoImpl().save(s); |
412 | jmachado | 169 | newUser = true; |
165 | jmachado | 170 | } |
416 | jmachado | 171 | |
1423 | jmachado | 172 | //if(alunoSiges.getCodigo() == 11211) |
173 | // System.out.println("Aqui"); |
||
1396 | jmachado | 174 | |
1553 | jmachado | 175 | persist(alunoSiges, s, newUser,year,institutionCode,activeImportYearParaVerificacaoDePropinasEmDia,logMessages,service,nacionalidades); |
165 | jmachado | 176 | |
1298 | jmachado | 177 | if(studentComUnidadesRepetidas) |
178 | unitsRepeated++; |
||
1312 | jmachado | 179 | |
180 | |||
165 | jmachado | 181 | if (newUser) |
1298 | jmachado | 182 | { |
411 | jmachado | 183 | CommonServicesManager.getInstance().adviseNew(s); |
1298 | jmachado | 184 | } |
165 | jmachado | 185 | else |
223 | jmachado | 186 | { |
1312 | jmachado | 187 | //Advising CommonsServicesManager before change password at this time 03/2015 this does not do anything important |
411 | jmachado | 188 | 1.5.0/docs/api/java/lang/String.html">String password = s.getPassword(); |
189 | s.setPassword(null); |
||
190 | CommonServicesManager.getInstance().adviseUpdate(s); |
||
191 | s.setPassword(password); |
||
223 | jmachado | 192 | } |
129 | susana | 193 | } |
1312 | jmachado | 194 | |
195 | |||
196 | logMessages.addMessage(new DefaultLogMessage("import.students.consisting.turmas", LogMessageTypeEnum.INFO)); |
||
197 | logger.info("Consisting turma students"); |
||
198 | serviceLogInfo("Consisting turma students"); |
||
199 | |||
200 | setProgress(95); |
||
201 | commitPartially(); |
||
202 | |||
203 | |||
204 | /** |
||
205 | * Este metodo vai remover inconsistencias de alunos que têm unidades em Turmas |
||
206 | * e depois não as têm na lista de unidades subscritas |
||
207 | * TURMAS SEPARADAS_ANALISE: Usa codigos de Turma do Baco não é necessario comparacoes por codigos siges |
||
208 | * logo nao e afetado com pelos detalhes das turmas separadas |
||
209 | */ |
||
210 | removeUnitsFromTurmaSubscriptionsThatAreNotInCourseUnitSubscriptions(year,institutionCode,logMessages); |
||
211 | |||
212 | |||
213 | /** |
||
214 | * Este metodo e apenas uma verificação de consistência |
||
215 | * O normal será não produzir resultados, pois caso os produza significa que os alunos não foram removidos das |
||
216 | * cadeiras tal como deveriam ter sido |
||
217 | * ou então são alunos adicionados manualmente às cadeiras |
||
218 | * TURMAS SEPARADAS_ANALISE: Usa codigos de Turma do Baco não é necessario comparacoes por codigos siges |
||
219 | * logo nao e afetado com pelos detalhes das turmas separadas |
||
220 | */ |
||
221 | obterAlunosInconsitentesComCadeirasSemTurma(codigos,year,institutionCode); |
||
222 | |||
223 | /** |
||
224 | * Turmas penduradas com código vazio serão removidas |
||
225 | */ |
||
226 | eliminarTurmasInvalidas(year,logMessages); |
||
227 | |||
165 | jmachado | 228 | logMessages.addMessage(new DefaultLogMessage("import.students.terminating", LogMessageTypeEnum.INFO)); |
229 | logger.info("terminating student import"); |
||
995 | jmachado | 230 | serviceLogInfo("terminating student import"); |
1312 | jmachado | 231 | |
232 | |||
233 | |||
234 | conn.close(); |
||
129 | susana | 235 | } |
995 | jmachado | 236 | catch(StaleStateException e) |
237 | { |
||
238 | AbstractDao.getCurrentSession().getTransaction().rollback(); |
||
239 | AbstractDao.getCurrentSession().beginTransaction(); |
||
240 | logger.error(e,e); |
||
1312 | jmachado | 241 | logMessages.addMessage(new DefaultLogMessage("import.error",e.toString(), "see log for details", LogMessageTypeEnum.ERROR)); |
995 | jmachado | 242 | serviceLogError("Rolling back will lost previous updates: " + e.toString(),e); |
243 | sendNotificationAdmin("Erro de importacao de alunos",e.toString()); |
||
244 | } |
||
245 | catch(HibernateException e) |
||
246 | { |
||
247 | AbstractDao.getCurrentSession().getTransaction().rollback(); |
||
248 | AbstractDao.getCurrentSession().beginTransaction(); |
||
249 | logger.error(e,e); |
||
1312 | jmachado | 250 | logMessages.addMessage(new DefaultLogMessage("import.error",e.toString(), "see log for details", LogMessageTypeEnum.ERROR)); |
995 | jmachado | 251 | serviceLogError("Rolling back will lost previous updates: " + e.toString(),e); |
996 | jmachado | 252 | sendNotificationAdmin("Erro de base de dados importacao de alunos, provavelmente chave errada, corrigir no MySql",e.toString()); |
995 | jmachado | 253 | } |
165 | jmachado | 254 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
255 | { |
||
358 | jmachado | 256 | logger.error(e,e); |
165 | jmachado | 257 | logMessages.addMessage(new DefaultLogMessage("import.error",e.toString(), "see log for details", LogMessageTypeEnum.ERROR)); |
995 | jmachado | 258 | serviceLogError(e.toString(),e); |
1082 | jmachado | 259 | sendNotificationAdmin("Erro de importacao de alunos",e.toString()); |
995 | jmachado | 260 | } |
358 | jmachado | 261 | |
995 | jmachado | 262 | |
263 | serviceLogInfo("############################"); |
||
264 | serviceLogInfo("############################"); |
||
265 | serviceLogInfo("#Students found: " + alunosFound); |
||
266 | serviceLogInfo("#Students New: " + studentsNew); |
||
267 | serviceLogInfo("#Students Merged: " + studentsMerged); |
||
268 | serviceLogInfo("#Students Zero Units: " + studentsZeroUnits); |
||
269 | serviceLogInfo("#Units not found: " + unitsNotFound); |
||
1145 | jmachado | 270 | serviceLogInfo("#Units not found in real course (turma ok): " + unitsNotFoundTurma); |
996 | jmachado | 271 | serviceLogInfo("#Units added to Students: " + unitsAddedToStudents); |
995 | jmachado | 272 | serviceLogInfo("#Units removed to Students: " + unitsRemovedToStudents); |
273 | serviceLogInfo("#Units not Removed because localy added: " + unitsLocalAddedNotRemoved); |
||
996 | jmachado | 274 | serviceLogInfo("#Units not Added because localy removed: " + unitsLocallyRemovedNotAdded); |
1279 | jmachado | 275 | serviceLogInfo("#Alunos com Unidades repetidas: " + unitsRepeated); |
1396 | jmachado | 276 | serviceLogWarn("#ERASMUS Sum Subscriptions Replaced: " + alunosErasmusCadeirasEcontradas); |
277 | if(turmasVindasANullDoSIGES > 0) |
||
278 | { |
||
279 | serviceLogError("######!!!!!Turmas a NULL NO SIGES " + turmasVindasANullDoSIGES + " - POSSIVEL CAMPO DE TURMA diferente de TURMA_T na tabela T_INSCR, procure no LOG pela frase: (turmasVindasANullDoSIGES) "); |
||
280 | } |
||
1400 | jmachado | 281 | if(turmasVindasANullDoSIGESEncontradasNoutroCampo > 0) |
282 | { |
||
283 | serviceLogInfo("######!!!!!Foram no entanto encontradas noutro campo P L TP O C S E: " + turmasVindasANullDoSIGESEncontradasNoutroCampo + " turmas ver mais info no LOG"); |
||
284 | } |
||
1396 | jmachado | 285 | if(alunosSemTurmaParaAUnidades > 0) |
286 | { |
||
287 | serviceLogError("######!!!!!Alunos com Unidade mas sem Turma: " + alunosSemTurmaParaAUnidades + " -> verificar situação junto da administração de software do PAE - procure no LOG pela frase:(alunosSemTurmaParaAUnidades)"); |
||
288 | } |
||
1341 | jmachado | 289 | if(unidadesProcuradasNumCursoAleatorio > 0) |
290 | serviceLogInfo("######!!!!!Unidades atribuidas com curso aleatoriamente escolhido derivado a duvidas: " + unidadesProcuradasNumCursoAleatorio + " (procurar por \"tem mais de um curso vamos procurar num qualquer\")"); |
||
1229 | jmachado | 291 | if(turmaMoreThanOneRegularCourse > 0) |
1312 | jmachado | 292 | { |
293 | serviceLogWarn("#########!!!!!!!ATENÇÃO TURMAS COM MAIS DE UM CURSO: " + turmaMoreThanOneRegularCourse); |
||
294 | serviceLogWarn(turmasMoreThanOneCourse.toString()); |
||
295 | } |
||
296 | if(turmasWrongSubscriptions > 0) |
||
297 | { |
||
298 | serviceLogWarn("Inscrições em TURMAS sem correspondencia nas disciplinas foram removidas: " + turmasWrongSubscriptions); |
||
299 | } |
||
300 | else |
||
301 | { |
||
302 | serviceLogInfo("CHECK OK - Todas as TURMAS com correspondencia nas disciplinas: "); |
||
303 | } |
||
304 | if(estudantesComCadeirasSemTurma > 0) |
||
305 | { |
||
306 | serviceLogWarn("########!!!!!!!Estudantes com cadeiras sem TURMA no BACO: " + estudantesComCadeirasSemTurma); |
||
307 | } |
||
308 | else |
||
309 | { |
||
310 | serviceLogInfo("CHECK TURMAS REVERSE OK - Todas as disciplinas subsescritas com turmas verificadas"); |
||
311 | } |
||
312 | if(estudantesDesaparecidosDoSigesNesteAno > 0) |
||
313 | { |
||
314 | serviceLogWarn("########!!!!!!!Estudantes que desapareceram do Siges neste ano e tinham cadeiras no BACO: " + estudantesDesaparecidosDoSigesNesteAno); |
||
315 | } |
||
316 | else |
||
317 | { |
||
318 | serviceLogInfo("CHECK DESAPARECIDOS OK - Não existem estudantes desaparecidos"); |
||
319 | } |
||
320 | if(turmasComCodigoNullRemovidas > 0) |
||
321 | { |
||
322 | serviceLogWarn("########Turmas com codigo vazio removidas:" + turmasComCodigoNullRemovidas); |
||
323 | } |
||
324 | else |
||
325 | { |
||
326 | serviceLogInfo("CHECK OK zero Turmas com codigo vazio"); |
||
327 | } |
||
328 | if(unidadesSoComAlunosExtra > 0) |
||
329 | { |
||
330 | //Acontece com cadeiras criadas especialmente para alunos de erasmus |
||
331 | serviceLogInfo("########Unidades sem Curso Real não criadas:" + unidadesSoComAlunosExtra); |
||
332 | serviceLogInfo("procure no log por: \"Problema Encontrado Turma não tem Curso Real\""); |
||
333 | } |
||
1025 | jmachado | 334 | |
1312 | jmachado | 335 | |
1025 | jmachado | 336 | logger.info("############################"); |
337 | logger.info("############################"); |
||
338 | logger.info("#Students found: " + alunosFound); |
||
339 | logger.info("#Students New: " + studentsNew); |
||
340 | logger.info("#Students Merged: " + studentsMerged); |
||
341 | logger.info("#Students Zero Units: " + studentsZeroUnits); |
||
342 | logger.info("#Units not found: " + unitsNotFound); |
||
1145 | jmachado | 343 | logger.info("#Units not found in real course (turma ok): " + unitsNotFoundTurma); |
1025 | jmachado | 344 | logger.info("#Units added to Students: " + unitsAddedToStudents); |
345 | logger.info("#Units removed to Students: " + unitsRemovedToStudents); |
||
346 | logger.info("#Units not Removed because localy added: " + unitsLocalAddedNotRemoved); |
||
347 | logger.info("#Units not Added because localy removed: " + unitsLocallyRemovedNotAdded); |
||
1279 | jmachado | 348 | logger.info("#Alunos com Unidades repetidas: " + unitsRepeated); |
1218 | jmachado | 349 | logger.info("#ERASMUS Sum Subscriptions Replaced: " + alunosErasmusCadeirasEcontradas); |
1396 | jmachado | 350 | if(turmasVindasANullDoSIGES > 0) |
351 | { |
||
352 | logger.error("######!!!!!Turmas a NULL NO SIGES " + turmasVindasANullDoSIGES + " - POSSIVEL CAMPO DE TURMA diferente de TURMA_T na tabela T_INSCR procure no LOG pela frase: (turmasVindasANullDoSIGES) "); |
||
353 | } |
||
1400 | jmachado | 354 | if(turmasVindasANullDoSIGESEncontradasNoutroCampo > 0) |
355 | { |
||
356 | logger.info("######!!!!!Foram no entanto encontradas noutro campo P L TP O C S E: " + turmasVindasANullDoSIGESEncontradasNoutroCampo + " turmas ver mais info no LOG"); |
||
357 | } |
||
1396 | jmachado | 358 | if(alunosSemTurmaParaAUnidades > 0) |
359 | { |
||
360 | logger.error("######!!!!!Alunos com Unidade mas sem Turma: " + alunosSemTurmaParaAUnidades + " -> verificar situação junto da administração de software do PAE - procure no LOG pela frase:(alunosSemTurmaParaAUnidades)"); |
||
361 | } |
||
1341 | jmachado | 362 | if(unidadesProcuradasNumCursoAleatorio > 0) |
363 | logger.warn("######!!!!!Unidades atribuidas com curso aleatoriamente escolhido derivado a duvidas: " + unidadesProcuradasNumCursoAleatorio + " (procurar por \"tem mais de um curso vamos procurar num qualquer\")"); |
||
364 | |||
1229 | jmachado | 365 | if(turmaMoreThanOneRegularCourse > 0) |
1312 | jmachado | 366 | { |
367 | logger.warn("#########!!!!!!!ATENÇÃO TURMAS COM MAIS DE UM CURSO: " + turmaMoreThanOneRegularCourse); |
||
368 | logger.warn(turmasMoreThanOneCourse.toString()); |
||
369 | } |
||
370 | if(turmasWrongSubscriptions > 0) |
||
371 | { |
||
372 | logger.warn("Inscrições em TURMAS sem correspondencia nas disciplinas: " + turmasWrongSubscriptions); |
||
373 | } |
||
374 | else |
||
375 | { |
||
376 | logger.info("CHECK TURMAS OK - Todas as TURMAS com correspondencia nas disciplinas subscritas"); |
||
377 | } |
||
378 | if(estudantesComCadeirasSemTurma > 0) |
||
379 | { |
||
380 | logger.warn("########!!!!!!!Estudantes com cadeiras sem TURMA no BACO: " + estudantesComCadeirasSemTurma); |
||
381 | } |
||
382 | else |
||
383 | { |
||
384 | logger.info("CHECK TURMAS REVERSE OK - Todas as disciplinas subsescritas com turmas verificadas"); |
||
385 | } |
||
386 | if(estudantesDesaparecidosDoSigesNesteAno > 0) |
||
387 | { |
||
388 | logger.warn("########!!!!!!!Estudantes que desapareceram do Siges neste ano e tinham cadeiras no BACO: " + estudantesDesaparecidosDoSigesNesteAno); |
||
389 | } |
||
390 | else |
||
391 | { |
||
392 | logger.info("CHECK DESAPARECIDOS OK - Não existem estudantes desaparecidos"); |
||
393 | } |
||
394 | if(turmasComCodigoNullRemovidas > 0) |
||
395 | { |
||
396 | logger.warn("########Turmas com codigo vazio removidas:" + turmasComCodigoNullRemovidas); |
||
397 | } |
||
398 | else |
||
399 | { |
||
400 | logger.info("CHECK OK zero Turmas com codigo vazio"); |
||
401 | } |
||
402 | if(unidadesSoComAlunosExtra > 0) |
||
403 | { |
||
404 | logger.warn("########Unidades sem Curso Real não criadas:" + unidadesSoComAlunosExtra); |
||
405 | logger.warn("procure no log por: \"Problema Encontrado Turma não tem Curso Real\""); |
||
406 | } |
||
1229 | jmachado | 407 | |
1312 | jmachado | 408 | |
995 | jmachado | 409 | if(studentsChangeBI>0) |
410 | { |
||
411 | serviceLogInfo("#>>>>>AVISO AVISO<<<<<<<<<: "); |
||
412 | serviceLogInfo("#>>>>>AVISO AVISO<<<<<<<<<: "); |
||
413 | serviceLogInfo("#>>>>>NUMEROS DE ALUNOS MUDARAM DE BI<<<<<<<<<: CONSULTAR LOG"); |
||
414 | serviceLogInfo("#CODIGO SIGES COM BIs DIFERENTES:" + studentsChangeBI); |
||
1025 | jmachado | 415 | logger.info("#>>>>>AVISO AVISO<<<<<<<<<: "); |
416 | logger.info("#>>>>>AVISO AVISO<<<<<<<<<: "); |
||
417 | logger.info("#>>>>>NUMEROS DE ALUNOS MUDARAM DE BI<<<<<<<<<: CONSULTAR LOG"); |
||
418 | logger.info("#CODIGO SIGES COM BIs DIFERENTES:" + studentsChangeBI); |
||
165 | jmachado | 419 | } |
1025 | jmachado | 420 | |
995 | jmachado | 421 | setProgress(100); |
165 | jmachado | 422 | return logMessages; |
129 | susana | 423 | } |
116 | jmachado | 424 | |
1312 | jmachado | 425 | private void eliminarTurmasInvalidas(1.5.0/docs/api/java/lang/String.html">String year,DefaultLogMessages logMessages) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException { |
1076 | jmachado | 426 | |
1312 | jmachado | 427 | 1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement ps = AbstractDao.getCurrentSession().connection().prepareStatement( |
428 | "select courseunitturma.id as id, courseunit.code as code, courseunit.name as name, courseunit.coursename as coursename from courseunitturma " + |
||
429 | "join courseunit on courseunit.id = courseunitturma.courseunit " + |
||
430 | "where courseunit.importYear = \"" + year + "\" and (courseunitturma.turma is null or courseunitturma.turma = \"\")"); |
||
431 | 1.5.0/docs/api/java/sql/ResultSet.html">ResultSet rs = ps.executeQuery(); |
||
432 | while(rs.next()) |
||
433 | { |
||
434 | CourseUnitTurma cut = DaoFactory.getCourseUnitTurmaDaoImpl().load(rs.getLong("id")); |
||
1076 | jmachado | 435 | |
1312 | jmachado | 436 | /****logging*****/ |
437 | turmasComCodigoNullRemovidas++; |
||
438 | 1.5.0/docs/api/java/lang/String.html">String msg = "Removing courseunit turma:" + cut.getId() + " from unit:" + rs.getString("code") + ":" + rs.getString("name") + "(" + rs.getString("coursename") + ")" + " has null turma"; |
||
439 | logger.warn(msg); |
||
440 | logMessages.addMessage(new DefaultLogMessage("import.warning",LogMessageTypeEnum.WARNING,msg)); |
||
441 | serviceLogWarn(msg); |
||
442 | /****logging*****/ |
||
443 | |||
444 | if(cut.getStudents().size() > 0) |
||
445 | { |
||
446 | Iterator<StudentImpl> sd = cut.getStudents().iterator(); |
||
447 | while(sd.hasNext()) |
||
448 | { |
||
449 | StudentImpl s = sd.next(); |
||
450 | |||
451 | /****logging*****/ |
||
452 | msg = "Removing student " + s.getSigesCode() + " from turma:" + cut.getId() + " from unit:" + rs.getString("code") + ":" + rs.getString("name") + "(" + rs.getString("coursename") + ")" + " has null turma"; |
||
453 | logger.warn(msg); |
||
454 | logMessages.addMessage(new DefaultLogMessage("import.warning",LogMessageTypeEnum.WARNING,msg)); |
||
455 | serviceLogWarn(msg); |
||
456 | /****logging*****/ |
||
457 | |||
458 | s.getTurmas().remove(cut); |
||
459 | sd.remove(); |
||
460 | } |
||
461 | } |
||
462 | cut.getCourseUnit().getTurmas().remove(cut); |
||
463 | cut.setCourseUnit(null); |
||
464 | } |
||
465 | rs.close(); |
||
466 | ps.close(); |
||
467 | } |
||
468 | |||
469 | |||
1553 | jmachado | 470 | private Student loadStudent(Aluno alunoSiges,HashMap<Integer,Nacionalidade> nacionalidades) |
1312 | jmachado | 471 | { |
472 | Student s = null; |
||
473 | User u = DaoFactory.getUserDaoImpl().loadByUsernameOrSigesCode(alunoSiges.getCodigo().intValue()); |
||
474 | |||
475 | boolean newUser = false; |
||
476 | studentComUnidadesRepetidas = false; |
||
477 | if(u != null && !(u instanceof Student)) |
||
478 | { |
||
479 | /*****logging*******/ |
||
480 | 1.5.0/docs/api/java/lang/String.html">String msgS = "Student " + u.getUsername() + " already exist in system but is not a Student is a standard USER, will merge both users"; |
||
481 | studentsMerged++; |
||
482 | serviceLogWarn(msgS); |
||
483 | logger.warn(msgS); |
||
484 | /*****logging*******/ |
||
485 | |||
486 | DaoFactory.getUserDaoImpl().delete(u); |
||
487 | |||
488 | /*****logging*******/ |
||
489 | msgS = "Student " + u.getUsername() + "1"; |
||
490 | logger.warn(msgS); |
||
491 | serviceLogWarn(msgS); |
||
492 | /*****logging*******/ |
||
493 | |||
494 | |||
495 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
496 | AbstractDao.getCurrentSession().beginTransaction(); |
||
497 | |||
498 | /*****logging*******/ |
||
499 | msgS = "Student " + u.getUsername() + "2"; |
||
500 | logger.warn(msgS); |
||
501 | serviceLogWarn(msgS); |
||
502 | /*****logging*******/ |
||
503 | |||
504 | s = DomainObjectFactory.createStudentImpl(); |
||
505 | } |
||
506 | else if(u != null) |
||
507 | { |
||
508 | s = DaoFactory.getStudentDaoImpl().load(u.getId()); |
||
509 | } |
||
510 | |||
511 | if (s == null) |
||
512 | { |
||
513 | s = DomainObjectFactory.createStudentImpl(); |
||
514 | } |
||
515 | return s; |
||
516 | } |
||
129 | susana | 517 | /** |
1312 | jmachado | 518 | * Obter os alunos que tem cadeiras na lista de subscribed units que depois não têm uma associação com turma |
519 | * associada na CourseUnitTurma |
||
520 | * Este metodo usa dois selects |
||
521 | * O interior vai ler todas as possibilidades de unidade, estudante olhando para a tabela das turmas |
||
522 | * O exterior seleciona todas as ocorrencias da subscribedUnits e verifica com um left join quais |
||
523 | * não verificam correspondencia no select interior |
||
524 | * Assim ficamos a saber os alunos que estão subscritos numa unidade mas que não estão subscritos |
||
525 | * numa Turma com essa mesma unidade |
||
526 | * @param codigos |
||
527 | * @return |
||
528 | * @throws SQLException |
||
529 | */ |
||
530 | private List<Integer> obterAlunosInconsitentesComCadeirasSemTurma(List<Integer> codigos,1.5.0/docs/api/java/lang/String.html">String year,int institutionCode) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException { |
||
531 | /**EXTRA PARA DETECTAR ALUNOS COM CADEIRAS SEM TURMA***/ |
||
532 | |||
533 | 1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement ps= AbstractDao.getCurrentSession().connection().prepareStatement( |
||
534 | "select distinct (user.sigesCode)\n" + |
||
535 | "from subscribedunits \n" + |
||
536 | "join courseunit on subscribedunits.courseUnitId = courseunit.id\n" + |
||
1692 | jmachado | 537 | "join course on courseunit.course = course.id\n" + |
538 | "join course_department on course.area = course_department.sigla\n" + |
||
539 | "join course_school on course_department.school_id = course_school.id\n" + |
||
1312 | jmachado | 540 | "join user on user.id = subscribedunits.studentid\n" + |
541 | "left join (\n" + |
||
542 | "select subscribedturmaunits.studentId,courseunitturma.courseUnit,courseunitturma.turma from subscribedturmaunits \n" + |
||
543 | "join courseunitturma on courseunitturma.id = subscribedturmaunits.courseunitturmaid\n" + |
||
544 | "join courseunit on courseunit.id = courseunitturma.courseUnit\n" + |
||
545 | "where courseunit.importYear=\"" + year + "\") as turmas\n" + |
||
546 | "on turmas.studentId = subscribedunits.studentId and turmas.courseUnit = subscribedunits.courseunitid\n" + |
||
1692 | jmachado | 547 | "where courseunit.importYear=\"" + year + "\" and course_school.institutionalCode = \"" + institutionCode + "\" and turmas.studentId is null "); |
1312 | jmachado | 548 | 1.5.0/docs/api/java/sql/ResultSet.html">ResultSet rs = ps.executeQuery(); |
549 | List<Integer> longs = new ArrayList<Integer>(); |
||
1396 | jmachado | 550 | //alunosSemTurmaParaAUnidades = longs.size(); |
1312 | jmachado | 551 | while(rs.next()) |
552 | { |
||
553 | longs.add(rs.getInt("sigesCode")); |
||
1400 | jmachado | 554 | } |
555 | alunosSemTurmaParaAUnidades = longs.size(); |
||
1312 | jmachado | 556 | rs.close(); |
557 | ps.close(); |
||
558 | |||
559 | if(longs.size() > 0) |
||
560 | { |
||
1396 | jmachado | 561 | 1.5.0/docs/api/java/lang/String.html">String msgS = "(alunosSemTurmaParaAUnidades) ATENÇÃO_ Existem estudantes no BACO com unidades sem turma respectiva ano: " + year + " institution:" + institutionCode + " possiveis adicionados manualmente, confirmar"; |
1312 | jmachado | 562 | serviceLogWarn(msgS); |
563 | logger.warn(msgS); |
||
564 | msgS = ""; |
||
565 | for (1.5.0/docs/api/java/lang/Integer.html">Integer c : longs) |
||
566 | { |
||
567 | msgS+=c + ", "; |
||
568 | } |
||
569 | serviceLogWarn(msgS); |
||
570 | logger.warn(msgS); |
||
571 | } |
||
572 | else |
||
573 | { |
||
574 | 1.5.0/docs/api/java/lang/String.html">String msgS = "OK check - Estudantes no BACO todos com respectiva turma ano: " + year + " institution:" + institutionCode + " possiveis adicionados manualmente, confirmar"; |
||
575 | serviceLogInfo(msgS); |
||
576 | logger.info(msgS); |
||
577 | } |
||
578 | return longs; |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * Este métido vai consistir os alunos que não eram tratados porque não vinham do SIGES logo não constavam do |
||
583 | * ciclo |
||
584 | * @param year |
||
585 | * @param institutionCode |
||
586 | * @param codigos |
||
587 | */ |
||
588 | private void removerUnidadesDosDesaparecidosDoSiges(1.5.0/docs/api/java/lang/String.html">String year, int institutionCode, List<Integer> codigos) { |
||
589 | 1.5.0/docs/api/java/lang/String.html">String msgS; |
||
590 | List<Integer> codesInBaco = DaoFactory.getStudentDaoImpl().findAllSigesCodesYear(year,institutionCode); |
||
591 | codesInBaco.removeAll(codigos); |
||
592 | |||
593 | if(codesInBaco.size() > 0) |
||
594 | { |
||
595 | msgS = "Existem estudantes no BACO que não estao no SIGES no ano: " + year + " institution:" + institutionCode + " possiveis adicionados manualmente, confirmar"; |
||
596 | serviceLogWarn(msgS); |
||
597 | logger.warn(msgS); |
||
598 | msgS = ""; |
||
599 | for (1.5.0/docs/api/java/lang/Integer.html">Integer c : codesInBaco) |
||
600 | { |
||
601 | msgS+=c + ", "; |
||
602 | } |
||
603 | serviceLogWarn(msgS); |
||
604 | logger.warn(msgS); |
||
605 | for (1.5.0/docs/api/java/lang/Integer.html">Integer c : codesInBaco) |
||
606 | { |
||
607 | estudantesDesaparecidosDoSigesNesteAno++; |
||
608 | Student s = DaoFactory.getStudentDaoImpl().loadBySigesCode(c); |
||
609 | StudentImpl studentImpl = (StudentImpl) DaoFactory.getStudentDaoImpl().narrow(s); |
||
1396 | jmachado | 610 | removerUnidadesQueDesapareceramNoSiges(year, new HashSet<CourseUnit>(), studentImpl,institutionCode); |
611 | consistirTurmasAluno(studentImpl, year, new HashMap<CourseUnit, String>(),institutionCode); |
||
1312 | jmachado | 612 | } |
613 | } |
||
614 | else |
||
615 | { |
||
616 | msgS = "OK check - Não existem alunos desaparecidos no SIGES ano: " + year + " institution:" + institutionCode + " possiveis adicionados manualmente, confirmar"; |
||
617 | serviceLogInfo(msgS); |
||
618 | logger.info(msgS); |
||
619 | } |
||
620 | } |
||
621 | |||
622 | /** |
||
623 | * |
||
624 | * QUERY DAS INCONSISTENCIAS PARA REMOVER ALUNOS DAS TURMAS |
||
625 | * Estes casos são aqueles em que temos alunos em turmas de disciplinas |
||
626 | * sem que os alunos estejam subscritos na tabela de subscrições antiga |
||
627 | * Estes casos sao para remover |
||
628 | * |
||
629 | * Este caso aconteceu quando se deu o caso do Bug do session.refresh |
||
630 | * que estragava o aluno e ia gravando alunos novos sempre com cadeiras penduradas |
||
631 | * |
||
632 | * |
||
633 | * @param year |
||
634 | * @param institutionCode |
||
635 | * @param logMessages |
||
636 | * @throws SQLException |
||
637 | */ |
||
638 | private void removeUnitsFromTurmaSubscriptionsThatAreNotInCourseUnitSubscriptions(1.5.0/docs/api/java/lang/String.html">String year,int institutionCode,DefaultLogMessages logMessages) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException { |
||
639 | |||
640 | 1.5.0/docs/api/java/lang/String.html">String query = "select {0} " + |
||
641 | "from subscribedturmaunits " + |
||
642 | "join courseunitturma on courseunitturma.id = subscribedturmaunits.courseUnitTurmaId " + |
||
643 | "join courseunit on courseunitturma.courseUnit = courseunit.id " + |
||
1692 | jmachado | 644 | "join course on courseunit.course = course.id\n" + |
645 | "join course_department on course.area = course_department.sigla\n" + |
||
646 | "join course_school on course_department.school_id = course_school.id\n" + |
||
1312 | jmachado | 647 | "join user on user.id = subscribedturmaunits.studentId " + |
648 | "left join subscribedunits on " + |
||
649 | "subscribedturmaunits.studentId = subscribedunits.studentId " + |
||
650 | "and subscribedunits.courseUnitId = courseunit.id " + |
||
1692 | jmachado | 651 | "where courseunit.importYear = \"" + year + "\" and course_school.institutionalCode = " + institutionCode + " and subscribedunits.studentId is null"; |
1312 | jmachado | 652 | |
653 | 1.5.0/docs/api/java/lang/String.html">String fields = "courseunit.code as unidSigesCode," + |
||
654 | "user.name as name, " + |
||
655 | "user.sigesCode as sigesCode, " + |
||
656 | "subscribedturmaunits.studentId as studentId, " + |
||
657 | "courseunit.id as unitId ," + |
||
658 | "courseunit.name as unitname ," + |
||
659 | "courseunitturma.id as turmaId ," + |
||
660 | "courseunitturma.turma as turma"; |
||
661 | |||
662 | |||
663 | 1.5.0/docs/api/java/sql/PreparedStatement.html">PreparedStatement ps = AbstractDao.getCurrentSession().connection().prepareStatement( |
||
664 | 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(query,"count(*) as total")); |
||
665 | 1.5.0/docs/api/java/sql/ResultSet.html">ResultSet rs = ps.executeQuery(); |
||
666 | rs.next(); |
||
667 | int size = rs.getInt("total"); |
||
668 | rs.close(); |
||
669 | ps.close(); |
||
670 | |||
671 | if(size > 0) |
||
672 | { |
||
673 | /**********logging*********/ |
||
674 | turmasWrongSubscriptions=size; |
||
675 | 1.5.0/docs/api/java/lang/String.html">String msg = "Found " + size + " subscritions in turmas wich are not in subscribedUnits will remove them"; |
||
676 | logger.warn(msg); |
||
677 | serviceLogInfo(msg); |
||
678 | /**********logging*********/ |
||
679 | |||
680 | ps = AbstractDao.getCurrentSession().connection().prepareStatement( |
||
681 | 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(query,fields)); |
||
682 | rs = ps.executeQuery(); |
||
683 | int i = 0; |
||
684 | while(rs.next()) |
||
685 | { |
||
686 | 1.5.0/docs/api/java/lang/String.html">String unidSigesCode = rs.getString("unidSigesCode"); |
||
687 | 1.5.0/docs/api/java/lang/String.html">String studentName = rs.getString("name"); |
||
688 | long sigesCode = rs.getInt("sigesCode"); |
||
689 | long studentId = rs.getLong("studentId"); |
||
690 | long unitId = rs.getLong("unitId"); |
||
691 | 1.5.0/docs/api/java/lang/String.html">String unitname = rs.getString("unitname"); |
||
692 | long turmaId = rs.getLong("turmaId"); |
||
693 | 1.5.0/docs/api/java/lang/String.html">String turma = rs.getString("turma"); |
||
694 | CourseUnitTurma cut = DaoFactory.getCourseUnitTurmaDaoImpl().load(turmaId); |
||
695 | Student s = DaoFactory.getStudentDaoImpl().load(studentId); |
||
696 | cut.getStudents().remove(s); |
||
697 | s.getTurmas().remove(cut); |
||
698 | /**********logging*********/ |
||
699 | msg = "Inconsistencia encontrada na turma " + turma + " para o aluno " + studentName + " siges: " + sigesCode + " id:" + studentId + " na unidade siges:" + unidSigesCode + " unitid:" + unitId + " " + unitname + " O aluno nao tinha esta unidade e tinha uma turma para ela "; |
||
700 | logger.warn(msg); |
||
701 | serviceLogWarn(msg); |
||
702 | logMessages.addMessage(new DefaultLogMessage("import.students.consisting.turmas", LogMessageTypeEnum.WARNING,msg)); |
||
703 | /**********logging*********/ |
||
704 | } |
||
705 | rs.close(); |
||
706 | ps.close(); |
||
707 | } |
||
708 | else |
||
709 | { |
||
710 | 1.5.0/docs/api/java/lang/String.html">String msgS = "OK check - Todos os alunos com cadeiras em turmas tem a cadeira subscrita ano: " + year + " institution:" + institutionCode + " possiveis adicionados manualmente, confirmar"; |
||
711 | serviceLogInfo(msgS); |
||
712 | logger.info(msgS); |
||
713 | } |
||
714 | } |
||
715 | |||
716 | |||
717 | /** |
||
995 | jmachado | 718 | * Envio de Notificação aos operadores do CI |
719 | * @param subject |
||
720 | * @param cause |
||
721 | */ |
||
722 | private void sendNotificationAdmin(1.5.0/docs/api/java/lang/String.html">String subject, 1.5.0/docs/api/java/lang/String.html">String cause) |
||
723 | { |
||
724 | List<String> emails = ConfigProperties.getListValues("admin.email"); |
||
725 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
726 | { |
||
727 | serviceLogWarn(">>>>>>>>ENVIANDO NOTIFICACAO A ADMINISTRACAO: " + email); |
||
728 | logger.warn(">>>>>>>>ENVIANDO NOTIFICACAO A ADMINISTRACAO: " + email); |
||
729 | } |
||
730 | List<String> arguments = new ArrayList<String>(); |
||
731 | arguments.add(cause.replace("\n","<br/>")); |
||
732 | Email email = new Email(subject,emails,Globals.SYSTEM_EMAIL_BOX,"messageToAdmin_pt.txt",arguments); |
||
1029 | jmachado | 733 | email.setHtml(true); |
995 | jmachado | 734 | try { |
735 | new SendEmailService().sendEmail(email); |
||
736 | } catch (ServiceException e) { |
||
737 | e.printStackTrace(); |
||
738 | } |
||
739 | } |
||
740 | |||
1312 | jmachado | 741 | public 1.5.0/docs/api/java/lang/Integer.html">Integer getRealCourse(1.5.0/docs/api/java/lang/String.html">String turma,1.5.0/docs/api/java/lang/String.html">String year, int institutionCode,1.5.0/docs/api/java/lang/String.html">String semestre, DefaultLogMessages messages) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException { |
1298 | jmachado | 742 | |
1312 | jmachado | 743 | HashMap<String,List<Integer>> pairs = getCourseTurmaPairs(year,institutionCode,semestre,messages); |
1298 | jmachado | 744 | List<Integer> cursos = pairs.get(turma); |
1140 | jmachado | 745 | if(cursos.size() > 1) |
746 | { |
||
747 | 1.5.0/docs/api/java/lang/String.html">String msgAdmin = ""; |
||
748 | 1.5.0/docs/api/java/lang/String.html">String msg = "####Atenção existe um caso de dúvida nas inscrições : " + year + "-" + semestre + " turma " + turma; |
||
749 | msgAdmin += msg + "\n"; |
||
750 | logger.warn(msg); |
||
751 | serviceLogWarn(msg); |
||
752 | msg = "####A turma " + turma + " tem " + cursos.size() + " cursos associados: "; |
||
753 | logger.warn(msg); |
||
754 | serviceLogWarn(msg); |
||
755 | msgAdmin += msg + "\n"; |
||
1298 | jmachado | 756 | for(1.5.0/docs/api/java/lang/Integer.html">Integer curso: cursos) |
1140 | jmachado | 757 | { |
758 | msg = "######->turma:" + turma + " -> curso siges: " + curso.longValue(); |
||
759 | msgAdmin += msg + "\n"; |
||
760 | logger.warn(msg); |
||
761 | serviceLogWarn(msg); |
||
762 | } |
||
1341 | jmachado | 763 | sendNotificationAdmin("Atenção existe um caso de dúvida nas inscrições vamos devolver código invalido de curso para o sistema atribuir o primeiro onde a unidade se encontre",msgAdmin); |
764 | return -1; |
||
1140 | jmachado | 765 | } |
1341 | jmachado | 766 | else if(cursos.size() == 1) |
1312 | jmachado | 767 | { |
1140 | jmachado | 768 | return cursos.get(0); |
1312 | jmachado | 769 | } |
1140 | jmachado | 770 | else |
771 | { |
||
1312 | jmachado | 772 | 1.5.0/docs/api/java/lang/String.html">String msg = "####Atenção existe uma turma que nao tem curso associado : " + year + "-" + semestre + " turma " + turma; |
773 | sendNotificationAdmin("Atenção existe uma turma que nao tem curso associado",msg); |
||
1140 | jmachado | 774 | logger.error(msg); |
775 | serviceLogError(msg); |
||
776 | return null; |
||
777 | } |
||
778 | } |
||
1224 | jmachado | 779 | |
1296 | jmachado | 780 | protected static boolean isCursoFicticio(int cursoCode) |
1224 | jmachado | 781 | { |
1312 | jmachado | 782 | if(cursosFicticios == null) |
783 | cursosFicticios = DaoFactory.getConfigurationDaoImpl().getCursosFicticios(); |
||
1224 | jmachado | 784 | for(1.5.0/docs/api/java/lang/Integer.html">Integer cursoFicticio: cursosFicticios) |
785 | { |
||
786 | if(cursoFicticio.intValue() == cursoCode) |
||
787 | { |
||
788 | return true; |
||
789 | } |
||
790 | } |
||
791 | return false; |
||
792 | } |
||
793 | |||
1298 | jmachado | 794 | HashMap<String,HashMap<String,List<Integer>>> semestreTurmaCursosPairs = new HashMap<String, HashMap<String, List<Integer>>>(); |
795 | |||
1312 | jmachado | 796 | private HashMap<String,List<Integer>> getCourseTurmaPairs(1.5.0/docs/api/java/lang/String.html">String year,int institutionCode,1.5.0/docs/api/java/lang/String.html">String semestre, DefaultLogMessages messages) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException { |
1298 | jmachado | 797 | HashMap<String,List<Integer>> turmaCourses = semestreTurmaCursosPairs.get(year + ";" + semestre); |
1140 | jmachado | 798 | if(turmaCourses == null) |
799 | { |
||
800 | 1.5.0/docs/api/java/lang/String.html">String msg = "Starting structure pairs turma curso para : " + year + "-" + semestre; |
||
801 | logger.info(msg); |
||
802 | serviceLogInfo(msg); |
||
1298 | jmachado | 803 | /* ArrayOfTurmaCurso arrayOfTurmaCurso = service.getSiGesWEBSoap().loadParesTurmaCurso( |
1140 | jmachado | 804 | new BigDecimal(DaoFactory.getConfigurationDaoImpl().getSigesInstitutionCode()) |
1298 | jmachado | 805 | , year,semestre);*/ |
1312 | jmachado | 806 | List<pt.estgp.estgweb.services.sigesimports.oracle.domain.TurmaCurso> turmaCursos = TurmaDao.getInstance().loadTurmasCurso(institutionCode, year, semestre); |
1298 | jmachado | 807 | turmaCourses = new HashMap<String, List<Integer>>(); |
808 | for(pt.estgp.estgweb.services.sigesimports.oracle.domain.TurmaCurso turmaCursoPair: turmaCursos) |
||
1140 | jmachado | 809 | { |
1298 | jmachado | 810 | List<Integer> cursos = turmaCourses.get(turmaCursoPair.getCdTurma()); |
1140 | jmachado | 811 | if(cursos == null) |
812 | { |
||
1298 | jmachado | 813 | cursos = new ArrayList<Integer>(); |
1140 | jmachado | 814 | turmaCourses.put(turmaCursoPair.getCdTurma(),cursos); |
815 | } |
||
1224 | jmachado | 816 | if(turmaCursoPair.getCodigoCurso().intValue() >= 0) |
1142 | jmachado | 817 | { |
1225 | jmachado | 818 | boolean cursoFicticio = isCursoFicticio(turmaCursoPair.getCodigoCurso().intValue()); |
819 | if(!cursoFicticio) |
||
1224 | jmachado | 820 | { |
821 | cursos.add(turmaCursoPair.getCodigoCurso()); |
||
1229 | jmachado | 822 | |
1224 | jmachado | 823 | msg = "Adding:" + turmaCursoPair.getCdTurma() + "->" + turmaCursoPair.getCodigoCurso(); |
824 | logger.info(msg); |
||
825 | serviceLogInfo(msg); |
||
1229 | jmachado | 826 | if(cursos.size()>1) |
827 | { |
||
828 | turmaMoreThanOneRegularCourse++; |
||
1312 | jmachado | 829 | turmasMoreThanOneCourse.add(turmaCursoPair.getCdTurma()); |
1229 | jmachado | 830 | msg = "Warning: turma " + turmaCursoPair.getCdTurma() + " has more than one regular course associated "; |
831 | logger.warn(msg); |
||
832 | serviceLogWarn(msg); |
||
1312 | jmachado | 833 | //Nao vamos reportar aviso neste caso |
834 | //messages.addMessage(new DefaultLogMessage("", LogMessageTypeEnum.WARNING,msg)); |
||
1229 | jmachado | 835 | } |
1224 | jmachado | 836 | } |
837 | else |
||
838 | { |
||
1225 | jmachado | 839 | msg = "Not adding:" + turmaCursoPair.getCdTurma() + "->" + turmaCursoPair.getCodigoCurso() + " -> Codigo de Curso Ficticio ->não vai ser considerado"; |
1224 | jmachado | 840 | logger.info(msg); |
841 | serviceLogInfo(msg); |
||
842 | } |
||
1142 | jmachado | 843 | } |
844 | else |
||
845 | { |
||
846 | msg = "Excluding:" + turmaCursoPair.getCdTurma() + "->" + turmaCursoPair.getCodigoCurso(); |
||
847 | logger.warn(msg); |
||
848 | serviceLogInfo(msg); |
||
849 | } |
||
1140 | jmachado | 850 | } |
851 | semestreTurmaCursosPairs.put(year + ";" + semestre,turmaCourses); |
||
852 | /***END INICIALIZACAO***/ |
||
853 | } |
||
854 | /**Inicialização da Estrutura de Suporte aos Cursos/Turma*/ |
||
855 | return turmaCourses; |
||
856 | } |
||
995 | jmachado | 857 | |
1048 | jmachado | 858 | |
995 | jmachado | 859 | /** |
129 | susana | 860 | * Nao esta testado |
861 | * jm |
||
165 | jmachado | 862 | * |
995 | jmachado | 863 | * @param alunoSiges Aluno |
163 | jmachado | 864 | * @param student Student |
1553 | jmachado | 865 | * @param nacionalidades |
129 | susana | 866 | */ |
1553 | jmachado | 867 | private void persist(Aluno alunoSiges, Student student, boolean newUser, 1.5.0/docs/api/java/lang/String.html">String year, int institutionCode, 1.5.0/docs/api/java/lang/String.html">String activeImportYear, DefaultLogMessages logMessages, AlunoDao service, HashMap<Integer, Nacionalidade> nacionalidades) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException { |
1312 | jmachado | 868 | |
869 | |||
1553 | jmachado | 870 | updateStudentFields(alunoSiges, student, newUser,nacionalidades); |
1312 | jmachado | 871 | |
872 | updateSituacaoPropinas(alunoSiges, student, activeImportYear); |
||
873 | |||
874 | /*Desta forma as relacoes antigas sao ignoradas cria-se uma lista nova e atribui-se ao Teacher, o Hibernate faz resto e apaga as chaves estrangeiras antigas */ |
||
875 | if (alunoSiges.getDisciplinasInscrito() == null || alunoSiges.getDisciplinasInscrito().size() == 0) |
||
445 | jmachado | 876 | { |
1312 | jmachado | 877 | studentsZeroUnits++; |
878 | serviceLogWarn("ATENTION STUDENT WITH ZERO UNITS: codigo " + alunoSiges.getCodigo()); |
||
879 | logger.warn("ATENTION STUDENT WITH ZERO UNITS: codigo " + alunoSiges.getCodigo()); |
||
880 | StudentImpl studentImpl = (StudentImpl) DaoFactory.getStudentDaoImpl().narrow(student); |
||
1396 | jmachado | 881 | removerUnidadesQueDesapareceramNoSiges(year, new HashSet<CourseUnit>(), studentImpl,institutionCode); |
882 | consistirTurmasAluno(studentImpl, year, new HashMap<CourseUnit, String>(),institutionCode); |
||
445 | jmachado | 883 | } |
1312 | jmachado | 884 | else |
995 | jmachado | 885 | { |
1312 | jmachado | 886 | //1 - PROCEDIMENTO CADEIRAS SAO CARREGADAS DO BACO DA LISTA QUE VEM DO SIGES -> units CADEIRAS SIGES PERS BACO |
887 | //2 - Sao retiradas da lista units as que o aluno tem mas que foram removidas localmente CADEIRAS SIGES PERS BACO - REMOVIDAS LOCALMENTE = CADEIRAS SIGES PER BACO LIMPAS |
||
888 | //3 - Sao adicionadas ao aluno as que o aluno ainda nao tiver da lista units CADEIRAS SIGES LIMPAS ---> COPY ---> ALUNO CADEIRAS |
||
889 | //4 - Por fim Sao removidas da lista final as unidades que não vêm do SIGES e que não foram adicionadas localmente CADEIRAS ALUNO - CADEIRAS SIGES = CADEIRAS EXCEDENTES |
||
890 | //5 - Consistir Turmas do Aluno com novas cadeiras - Turmas do aluno sem cadeira correspondente sao apagadas, novas adicionadas |
||
116 | jmachado | 891 | |
1312 | jmachado | 892 | //Mapa de unidades carregadas a partir do Siges para o aluno associadas à turma que vinha do siges |
893 | //Para todas as cadeiras correspondentes 'as do SIGES no baco existira uma entrada com a turma nesta tabela |
||
894 | Map<CourseUnit,String> map_CourseUnit_x_Turma = new HashMap<CourseUnit, String>(); |
||
995 | jmachado | 895 | |
1312 | jmachado | 896 | //PASSO 1 |
897 | //turmas separadas : depende da escolha de turmas separadas para o curso |
||
898 | //caso aconteca a unidade será discriminada pelo código de turma como unica o mesmo é feito na importacao de cursos |
||
899 | Set<CourseUnit> unitsFromSigesPersistentInBaco = obterCadeirasBacoCorrespondentes(alunoSiges, student, year, institutionCode, logMessages, map_CourseUnit_x_Turma); |
||
995 | jmachado | 900 | |
1312 | jmachado | 901 | //PASSO 2 - Sao retiradas da lista unitsFromSigesPersistentInBaco as que o aluno tem mas que foram removidas localmente |
902 | //turmas separadas : Nao afetado pelas turmas separadas usa apenas os codigos do baco nas verificacoes para remocoes |
||
903 | StudentImpl studentImpl = removerRemovidasLocalmente(student, unitsFromSigesPersistentInBaco); |
||
904 | student = studentImpl;//just to be allays consistent |
||
995 | jmachado | 905 | |
1312 | jmachado | 906 | //PASSO 3 - Sao adicionadas ao aluno as unidades que o aluno ainda nao tiver da lista unitsFromSigesPersistentInBaco |
907 | //turmas separadas : Seguro a verificação de existencia é feita pelo id da unidade curricular no baco nas verificacoes para remocoes |
||
908 | adicionarCadeirasNovasAoAluno(studentImpl, unitsFromSigesPersistentInBaco); |
||
995 | jmachado | 909 | |
1312 | jmachado | 910 | //PASSO 4 - Remover unidades deste ano que nao vem do SIGES e que nao foram adicionadas localmente |
911 | //turmas separadas : Seguro a verificação de existencia é feita pelo id da unidade curricular no baco nas verificacoes para remocoes |
||
1396 | jmachado | 912 | removerUnidadesQueDesapareceramNoSiges(year, unitsFromSigesPersistentInBaco, studentImpl,institutionCode); |
995 | jmachado | 913 | |
1312 | jmachado | 914 | //PASSO 5 - Consistir Turmas do Aluno com novas cadeiras - Turmas do aluno sem cadeira correspondente sao apagadas, novas sao adicionadas |
915 | //Este metodo vai necessitar de obter as turmas das unidades que vieram do SIGES atraves do mapa map_CourseUnit_x_Turma |
||
916 | //de forma a garantir que as mesmas estão consistentes em |
||
917 | //em termos de relacoes com turmas na classe CourseUnitTurma |
||
918 | //deste modo se alguma unidade foi adicionada localmente poderá nao ser removida no PASSO 4 e nao havera correspondente |
||
919 | //para a turma nesta tabela map_CourseUnit_x_Turma logo essas turmas nessas unidades nao serao mechidas, um aviso e emitido |
||
1396 | jmachado | 920 | consistirTurmasAluno(studentImpl, year, map_CourseUnit_x_Turma,institutionCode); |
1312 | jmachado | 921 | } |
922 | } |
||
995 | jmachado | 923 | |
1396 | jmachado | 924 | private void consistirTurmasAluno(StudentImpl student, 1.5.0/docs/api/java/lang/String.html">String year, Map<CourseUnit, String> map_CourseUnit_x_Turma, int institutionCode) { |
1312 | jmachado | 925 | //PASSO 1 Para cada cadeira onde o aluno se encontra inscrito |
926 | // obter a turma onde o aluno esta' colocado, se nao existir criar e afectar a turma |
||
927 | //PASSO 2 Colocar o aluno nessa turma se ele ainda lá nao estiver |
||
928 | //PASSO 3 Para todas as turmas do aluno de cadeiras do ano corrente |
||
929 | // se essa turma nao estiver na lista de Turmas afectadas |
||
930 | // remover a turma do aluno |
||
931 | // remove ao mesmo tempo da lista da turma da unidade |
||
932 | //PASSO 1 |
||
933 | Map<CourseUnitTurma,Boolean> turmasAfectadas = new HashMap<CourseUnitTurma,Boolean>(); |
||
934 | for(CourseUnit cu: student.getSubscribedUnits()) |
||
935 | { |
||
1692 | jmachado | 936 | if(cu.getImportYear().equals(year) && cu.getCourse().getDepartment().getCourseSchool().getInstitutionalCode().equals(""+institutionCode)) |
1312 | jmachado | 937 | { |
938 | if(cu.getTurmas() == null) |
||
939 | { |
||
940 | cu.setTurmas(new HashSet<CourseUnitTurma>()); |
||
941 | } |
||
995 | jmachado | 942 | |
1312 | jmachado | 943 | 1.5.0/docs/api/java/lang/String.html">String codigoTurma = map_CourseUnit_x_Turma.get(cu); |
944 | if(student.isLocalUnit(cu) && codigoTurma == null) |
||
945 | { |
||
946 | //nao tem correspondencia no mapa de turmas uma vez que nao foi carregada no siges |
||
947 | //mas foi mantida porque foi adicionada manualmente |
||
948 | //deste modo usaremos a turma antiga |
||
949 | //e nao afetaremos uma turma nao afetada, esta nao sera verificada |
||
1396 | jmachado | 950 | 1.5.0/docs/api/java/lang/String.html">String msg = "Atenção turma não encontrada para uma unidade do aluno, A unidade não foi importada do SIGES logo não há turma mas nao sera verificada porque e' uma local unit:" + cu.getCode() + " aluno:" + student.getSigesCode(); |
1312 | jmachado | 951 | serviceLogInfo(msg); |
952 | logger.info(msg); |
||
953 | } |
||
954 | else if(codigoTurma == null) |
||
955 | { |
||
956 | //Este caso nao deverá acontecer porque no PASSO 4 da persistencia apenas nao se removem as adicionadas localmente |
||
1396 | jmachado | 957 | 1.5.0/docs/api/java/lang/String.html">String msg = "Atenção turma não encontrada para uma unidade do aluno. A Unidade não foi importada do SIGES ou vinha com turma NULL, logo nao se sabe a turma do aluno para escolher, e não e' uma unidade LOCALMENTE ADICIONADA logo devia vir do SIGES ou ter sido removida - unit:" + cu.getCode() + " aluno:" + student.getSigesCode(); |
1312 | jmachado | 958 | serviceLogError(msg); |
959 | logger.error(msg); |
||
960 | } |
||
961 | else |
||
962 | { |
||
963 | CourseUnitTurma courseUnitTurma = findOrCreateCourseUnitTurma(codigoTurma, cu); |
||
964 | turmasAfectadas.put(courseUnitTurma,true); |
||
965 | } |
||
966 | } |
||
995 | jmachado | 967 | } |
1312 | jmachado | 968 | //PASSO 2 |
969 | for(CourseUnitTurma turmaAfectada: turmasAfectadas.keySet()) |
||
1048 | jmachado | 970 | { |
1312 | jmachado | 971 | if(turmaAfectada.getStudents() == null || !turmaAfectada.getStudents().contains(student)) |
972 | { |
||
973 | if(turmaAfectada.getStudents() == null) |
||
974 | turmaAfectada.setStudents(new HashSet<StudentImpl>()); |
||
975 | turmaAfectada.getStudents().add(student); |
||
976 | //student.getTurmas().add((CourseUnitTurmaImpl) turmaAfectada); |
||
977 | } |
||
1048 | jmachado | 978 | } |
1312 | jmachado | 979 | |
980 | //PASSO 3 |
||
981 | if(student.getTurmas() != null) |
||
1048 | jmachado | 982 | { |
1312 | jmachado | 983 | Iterator<CourseUnitTurmaImpl> iter = student.getTurmas().iterator(); |
984 | while(iter.hasNext()) |
||
1048 | jmachado | 985 | { |
1312 | jmachado | 986 | CourseUnitTurmaImpl turma = iter.next(); |
1692 | jmachado | 987 | if(turma.getCourseUnit().getImportYear().equals(year) && turma.getCourseUnit().getCourse().getDepartment().getCourseSchool().getInstitutionalCode().equals(institutionCode+"")) |
1048 | jmachado | 988 | { |
1312 | jmachado | 989 | if(student.isLocalUnit(turma.getCourseUnit()) && turmasAfectadas.get(turma) == null) |
1048 | jmachado | 990 | { |
1312 | jmachado | 991 | 1.5.0/docs/api/java/lang/String.html">String msg = "Atenção turma com código " + turma.getTurma() + " nao sera removida porque e' a turma da local unit:" + turma.getCourseUnit().getCode() + " aluno:" + student.getSigesCode(); |
992 | serviceLogInfo(msg); |
||
993 | logger.info(msg); |
||
1048 | jmachado | 994 | } |
1312 | jmachado | 995 | else if(turmasAfectadas.get(turma) == null) |
996 | { |
||
1341 | jmachado | 997 | |
1312 | jmachado | 998 | //Este caso nao devera acontecer mas fica aqui a seguranca |
1341 | jmachado | 999 | 1.5.0/docs/api/java/lang/String.html">String msg = "Atenção turma com código " + turma.getTurma() + " nao existe nas afetadas e vai ser removida ao aluno e nao e' local unit:" + turma.getCourseUnit().getCode() + " aluno:" + student.getSigesCode(); |
1312 | jmachado | 1000 | serviceLogError(msg); |
1001 | logger.error(msg); |
||
1002 | iter.remove(); |
||
1003 | turma.getStudents().remove(student); |
||
1004 | } |
||
1048 | jmachado | 1005 | } |
1006 | } |
||
1312 | jmachado | 1007 | } |
1008 | } |
||
1009 | |||
1010 | /** |
||
1011 | * |
||
1012 | * @param cdturma |
||
1013 | * @param cu |
||
1014 | * @return |
||
1015 | */ |
||
1016 | private CourseUnitTurma findOrCreateCourseUnitTurma(1.5.0/docs/api/java/lang/String.html">String cdturma, CourseUnit cu) { |
||
1017 | CourseUnitTurma courseUnitTurma = null; |
||
1018 | try{ |
||
1019 | for(CourseUnitTurma turma: cu.getTurmas()) |
||
1020 | { |
||
1021 | if(turma.getTurma() != null && turma.getTurma().trim().equals(cdturma.trim())) |
||
1048 | jmachado | 1022 | { |
1312 | jmachado | 1023 | courseUnitTurma = turma; |
1024 | break; |
||
1048 | jmachado | 1025 | } |
1026 | } |
||
1312 | jmachado | 1027 | if(courseUnitTurma == null) |
995 | jmachado | 1028 | { |
1312 | jmachado | 1029 | courseUnitTurma = DomainObjectFactory.createCourseUnitTurmaImpl(); |
1030 | courseUnitTurma.setTurma(cdturma); |
||
1031 | DaoFactory.getCourseUnitTurmaDaoImpl().save(courseUnitTurma); |
||
1032 | courseUnitTurma.setCourseUnit(cu); |
||
1033 | cu.getTurmas().add(courseUnitTurma); |
||
995 | jmachado | 1034 | } |
1312 | jmachado | 1035 | }catch(1.5.0/docs/api/java/lang/Exception.html">Exception e) |
129 | susana | 1036 | { |
1312 | jmachado | 1037 | e.toString(); |
1038 | e.printStackTrace(); |
||
1039 | } |
||
1040 | return courseUnitTurma; |
||
1041 | } |
||
996 | jmachado | 1042 | |
1312 | jmachado | 1043 | /** |
1044 | * |
||
1045 | * @param student |
||
1046 | * @param year |
||
1047 | * @param unitsFromSigesPersistentInBaco |
||
1048 | * @param student |
||
1049 | */ |
||
1396 | jmachado | 1050 | private void removerUnidadesQueDesapareceramNoSiges(1.5.0/docs/api/java/lang/String.html">String year, Set<CourseUnit> unitsFromSigesPersistentInBaco, StudentImpl student,int institutionCode) { |
1312 | jmachado | 1051 | Iterator<CourseUnit> iterNowUnits = student.getSubscribedUnits().iterator(); |
1052 | while(iterNowUnits.hasNext()) |
||
1053 | { |
||
1054 | CourseUnit cUNow = iterNowUnits.next(); |
||
1692 | jmachado | 1055 | if(cUNow.getImportYear().equals(year) && cUNow.getCourse().getDepartment().getCourseSchool().getInstitutionalCode().equals(""+institutionCode)) |
1312 | jmachado | 1056 | //Apenas tentamos apagar as unidades do ano corrente. |
1057 | //Este servico trabalha com unidades importadas do ano que e passado como argumento |
||
1058 | //Se importamos unidades desse ano, as dos outros anos nao vem na lista, logo |
||
1059 | //iriamos constatar que nenhuma estava no SIGES o que nao e verdade. |
||
1060 | //Assim so apagamos unidades do ano que estamos a importar e que nao venham |
||
1061 | //na importacao desse ano |
||
1062 | { |
||
996 | jmachado | 1063 | |
1312 | jmachado | 1064 | boolean added = false; |
1065 | for(CourseUnit c: unitsFromSigesPersistentInBaco) |
||
1140 | jmachado | 1066 | { |
1312 | jmachado | 1067 | if(cUNow.getId() == c.getId()) |
1218 | jmachado | 1068 | { |
1312 | jmachado | 1069 | added = true; |
1070 | break; |
||
1071 | } |
||
1072 | } |
||
1073 | if(!added) |
||
1074 | { |
||
1075 | |||
1076 | if(!student.isLocalUnit(cUNow)) |
||
1077 | { |
||
1078 | 1.5.0/docs/api/java/lang/String.html">String msg = "Removendo unidade: " + ((CourseUnitImpl)cUNow).getSigesUniqueIdentifiers() + " - do aluno: " + student.getSigesCode() + " - Associacao desapareceu do SIGES"; |
||
1218 | jmachado | 1079 | serviceLogInfo(msg); |
1080 | logger.info(msg); |
||
1312 | jmachado | 1081 | iterNowUnits.remove(); |
1082 | unitsRemovedToStudents++; |
||
1218 | jmachado | 1083 | } |
1224 | jmachado | 1084 | else |
1085 | { |
||
1312 | jmachado | 1086 | 1.5.0/docs/api/java/lang/String.html">String msg = "NAO REMOVIDA - Unidade: " + ((CourseUnitImpl)cUNow).getSigesUniqueIdentifiers() + " - do aluno: " + student.getSigesCode() + " - Associacao desapareceu do SIGES mas foi adicionada localmente"; |
1224 | jmachado | 1087 | serviceLogInfo(msg); |
1088 | logger.info(msg); |
||
1312 | jmachado | 1089 | unitsLocalAddedNotRemoved++; |
1224 | jmachado | 1090 | } |
1312 | jmachado | 1091 | } |
1092 | } |
||
1093 | } |
||
1094 | } |
||
1095 | |||
1096 | private void adicionarCadeirasNovasAoAluno(Student student, Set<CourseUnit> unitsFromSigesPersistentInBacoLimpas) { |
||
1097 | if(student.getSubscribedUnits() != null) |
||
1098 | { |
||
1099 | for(CourseUnit c: unitsFromSigesPersistentInBacoLimpas) |
||
1100 | { |
||
1101 | boolean isIn = false; |
||
1102 | for(CourseUnit tc : student.getSubscribedUnits()) |
||
1103 | { |
||
1104 | if(tc.getId() == c.getId()) |
||
1105 | { |
||
1106 | isIn = true; |
||
1107 | break; |
||
1108 | } |
||
1109 | } |
||
1110 | if(!isIn) |
||
1111 | { |
||
1112 | 1.5.0/docs/api/java/lang/String.html">String msg = "Adicionando unidade: " + ((CourseUnitImpl)c).getSigesUniqueIdentifiers() + " - ao aluno: " + student.getSigesCode() + " - Associacao nova no SIGES"; |
||
1140 | jmachado | 1113 | serviceLogInfo(msg); |
1114 | logger.info(msg); |
||
1312 | jmachado | 1115 | unitsAddedToStudents++; |
1116 | student.getSubscribedUnits().add(c); |
||
1140 | jmachado | 1117 | } |
1312 | jmachado | 1118 | } |
1119 | } |
||
1120 | else |
||
1121 | student.setSubscribedUnits(unitsFromSigesPersistentInBacoLimpas); |
||
1122 | } |
||
1140 | jmachado | 1123 | |
1312 | jmachado | 1124 | private StudentImpl removerRemovidasLocalmente(Student student, Set<CourseUnit> unitsFromSigesPersistentInBaco) { |
1125 | Iterator<CourseUnit> iter = unitsFromSigesPersistentInBaco.iterator(); |
||
1126 | StudentImpl studentImpl = (StudentImpl) DaoFactory.getStudentDaoImpl().narrow(student); |
||
1127 | while (iter.hasNext()) |
||
1128 | { |
||
1129 | CourseUnit courseUnit = iter.next(); |
||
1130 | //In case of a comming proxy |
||
1131 | |||
1132 | if(studentImpl.isLocalRemovedUnit(courseUnit)) |
||
1133 | { |
||
1134 | unitsLocallyRemovedNotAdded++; |
||
1135 | 1.5.0/docs/api/java/lang/String.html">String msg = "Removendo unidade: " + ((CourseUnitImpl)courseUnit).getSigesUniqueIdentifiers() + " - do aluno: " + student.getSigesCode() + " - Associacao existe no SIGES mas foi removido LOCALMENTE"; |
||
1136 | serviceLogInfo(msg); |
||
1137 | logger.info(msg); |
||
1138 | iter.remove(); |
||
1139 | } |
||
1140 | } |
||
1141 | return studentImpl; |
||
1142 | } |
||
1143 | |||
1144 | private Set<CourseUnit> obterCadeirasBacoCorrespondentes(Aluno alunoSiges, Student student, 1.5.0/docs/api/java/lang/String.html">String year, int institutionCode, DefaultLogMessages logMessages, Map<CourseUnit, String> map_CourseUnit_x_Turma) throws 1.5.0/docs/api/java/sql/SQLException.html">SQLException { |
||
1145 | Set<CourseUnit> unitsFromSigesPersistentInBaco = new HashSet<CourseUnit>(); |
||
1146 | for (Disciplina disciplina : alunoSiges.getDisciplinasInscrito()) |
||
1147 | { |
||
1400 | jmachado | 1148 | if(disciplina.getCdTurma() == null) |
1149 | { |
||
1150 | turmasVindasANullDoSIGES++; |
||
1151 | 1.5.0/docs/api/java/lang/String.html">String msg = "(turmasVindasANullDoSIGES) ATENÇÃO ERRO: Existe uma turma a null numa inscrição vinda do SIGES, procurar razão: unidade:" + disciplina.getCodigo() + " estudante:" + student.getSigesCode() + " possivelmente campo de turma em uso é errado, Vamos tentar usar o campo de outra TURMA P, L, TP, P, O, C, E, S"; |
||
1152 | serviceLogWarn(msg); |
||
1153 | logger.warn(msg); |
||
1154 | if(disciplina.getOutraTurma() != null) |
||
1155 | { |
||
1156 | turmasVindasANullDoSIGESEncontradasNoutroCampo++; |
||
1157 | disciplina.setCdTurma(disciplina.getOutraTurma()); |
||
1158 | msg = "Encontrada Outra Turma: Atenção vai ser usada a turma " + disciplina.getOutraTurmaCode(); |
||
1159 | serviceLogWarn(msg); |
||
1160 | logger.warn(msg); |
||
1161 | } |
||
1162 | } |
||
1163 | |||
1312 | jmachado | 1164 | boolean cursoFicticio = isCursoFicticio(disciplina.getCodigoCurso().intValue()); |
1165 | 1.5.0/docs/api/java/lang/Integer.html">Integer codigoDoCurso = disciplina.getCodigoCurso().intValue(); |
||
1166 | |||
1167 | if( (disciplina.getCdTipoDisciplina() != null |
||
1168 | && |
||
1169 | disciplina.getCdTipoDisciplina().intValue() == ImportCourseService.SIGES_CODIGO_TIPO_DISCIPLINA_EXTRA_CURRICULAR) |
||
1170 | || |
||
1171 | cursoFicticio) |
||
1172 | { |
||
1173 | if(cursoFicticio) |
||
1277 | jmachado | 1174 | { |
1312 | jmachado | 1175 | alunosErasmusCadeirasEcontradas++; |
1176 | 1.5.0/docs/api/java/lang/String.html">String msg = "Disciplina para Aluno " + student.getSigesCode() + " de Curso Ficticio " +disciplina.getCodigoCurso().intValue() + " encontrada vamos trocar para código de curso real"; |
||
1177 | serviceLogInfo(msg); |
||
1178 | logger.info(msg); |
||
1277 | jmachado | 1179 | } |
1312 | jmachado | 1180 | else |
225 | jmachado | 1181 | { |
1312 | jmachado | 1182 | 1.5.0/docs/api/java/lang/String.html">String msg = "Disciplina para Aluno " + student.getSigesCode() + " ExtraCurricular " +disciplina.getCodigoCurso().intValue() + " encontrada vamos trocar para código de curso real"; |
1183 | serviceLogInfo(msg); |
||
1184 | logger.info(msg); |
||
1185 | } |
||
1186 | codigoDoCurso = getRealCourse(disciplina.getCdTurma(),year,institutionCode,disciplina.getCdDuracao(),logMessages); |
||
1341 | jmachado | 1187 | |
1312 | jmachado | 1188 | if(codigoDoCurso != null) |
1138 | jmachado | 1189 | { |
1341 | jmachado | 1190 | if(codigoDoCurso < 0) |
1191 | { |
||
1192 | 1.5.0/docs/api/java/lang/String.html">String msg = "Codigo de curso (" + disciplina.getCodigoCurso() + ") da disciplina " + disciplina.getCodigo() + " tipo: " + disciplina.getCdTipoDisciplina() + " turma: " + disciplina.getCdTurma() + " tem mais de um curso vamos procurar num qualquer curso onde exista "; |
||
1193 | serviceLogInfo(msg); |
||
1194 | logger.info(msg); |
||
1195 | } |
||
1196 | else |
||
1197 | { |
||
1198 | 1.5.0/docs/api/java/lang/String.html">String msg = "Codigo de curso (" + disciplina.getCodigoCurso() + ") da disciplina " + disciplina.getCodigo() + " tipo: " + disciplina.getCdTipoDisciplina() + " turma: " + disciplina.getCdTurma() + " Modificado para o real: " + codigoDoCurso; |
||
1199 | serviceLogInfo(msg); |
||
1200 | logger.info(msg); |
||
1201 | } |
||
225 | jmachado | 1202 | } |
129 | susana | 1203 | else |
1298 | jmachado | 1204 | { |
1312 | jmachado | 1205 | 1.5.0/docs/api/java/lang/String.html">String msg = "Problema Encontrado Turma não tem Curso Real --> Codigo de curso (" + disciplina.getCodigoCurso() + ") da disciplina " + disciplina.getCodigo() + " tipo: " + disciplina.getCdTipoDisciplina() + " turma: " + disciplina.getCdTurma(); |
1206 | serviceLogWarn(msg); |
||
1207 | logger.warn(msg); |
||
1208 | msg = "A unidade " + disciplina.getCodigo() + " não será adicionada ao aluno " + alunoSiges.getCodigo() + " porque nao foi encontrada, possivelmente apenas existe para alunos com inscrição NORMAL"; |
||
1209 | serviceLogWarn(msg); |
||
1210 | logger.warn(msg); |
||
1211 | unidadesSoComAlunosExtra++; |
||
1212 | continue; |
||
1298 | jmachado | 1213 | } |
129 | susana | 1214 | } |
996 | jmachado | 1215 | |
1312 | jmachado | 1216 | |
1217 | //Politica de separação de turmas em unidades independentes neste curso |
||
1218 | boolean separateTurmas = ImportCourseService.loadCourseYearTurmasPolicy(codigoDoCurso, year, logMessages, this); |
||
1219 | List<CourseUnit> courseUnits; |
||
1341 | jmachado | 1220 | |
1221 | /*BLOCO DE LOAD DAS UNIDADES*/ |
||
1222 | if(codigoDoCurso <= 0) //O curso encontrado foi mais que um vamos fazer o melhor esforço e atribuir um que dê isto apenas deverá acontecer com erasmus e em turmas com mais que um curso |
||
1223 | { |
||
1224 | unidadesProcuradasNumCursoAleatorio++; |
||
1225 | if(separateTurmas) |
||
1226 | courseUnits = DaoFactory.getCourseUnitDaoImpl().loadBySigesCodeUniqueWithTurmaIgnoreCourse("" + disciplina.getCodigo(), disciplina.getCdDuracao(), disciplina.getCdLectivo(), disciplina.getCdTurma()); |
||
1227 | else |
||
1228 | courseUnits = DaoFactory.getCourseUnitDaoImpl().loadBySigesCodeUniqueIgnoreCourse("" + disciplina.getCodigo(),disciplina.getCdDuracao(),disciplina.getCdLectivo()); |
||
1229 | if(courseUnits.size() > 0) |
||
1230 | { |
||
1231 | //Neste caso adicionamos apenas a primeira |
||
1232 | CourseUnit cu = courseUnits.get(0); |
||
1233 | courseUnits = new ArrayList<CourseUnit>(); |
||
1234 | courseUnits.add(cu); |
||
1235 | } |
||
1236 | } |
||
1312 | jmachado | 1237 | else |
1341 | jmachado | 1238 | { |
1239 | if(separateTurmas) |
||
1240 | courseUnits = DaoFactory.getCourseUnitDaoImpl().loadBySigesCodeUniqueWithTurma("" + disciplina.getCodigo(), "" + codigoDoCurso, disciplina.getCdDuracao(), disciplina.getCdLectivo(), disciplina.getCdTurma()); |
||
1241 | else |
||
1242 | courseUnits = DaoFactory.getCourseUnitDaoImpl().loadBySigesCodeUnique("" + disciplina.getCodigo(),"" + codigoDoCurso,disciplina.getCdDuracao(),disciplina.getCdLectivo()); |
||
1243 | } |
||
1244 | /*BLOCO DE LOAD DAS UNIDADES*/ |
||
1312 | jmachado | 1245 | |
1246 | |||
1341 | jmachado | 1247 | |
1312 | jmachado | 1248 | if(courseUnits != null && courseUnits.size() > 1 ) |
223 | jmachado | 1249 | { |
1312 | jmachado | 1250 | studentComUnidadesRepetidas=true; |
1251 | logMessages.addMessage(new DefaultLogMessage("import.warning","Unidade Repetida: (" + disciplina.getCodigo() + ") curso: " + disciplina.getCodigoCurso() + " " + disciplina.getCdDuracao() + " " + year, "see log for details", LogMessageTypeEnum.WARNING)); |
||
1252 | logger.fatal(logMessages.getLastMessage()); |
||
1253 | serviceLogWarn(logMessages.getLastMessage()); |
||
223 | jmachado | 1254 | } |
1312 | jmachado | 1255 | //CourseUnit courseUnit = null; |
1256 | //Special procedure for Aluno to check if turma not exist will find without turma code to keep old years compatibility |
||
1257 | /*if(courseUnit == null) |
||
255 | jmachado | 1258 | { |
1312 | jmachado | 1259 | unitsNotFoundTurma++; |
1260 | courseUnit = tryFindCourseUnitWithOutTurma(logMessages,disciplina.getCdDuracao(),""+disciplina.getCodigo().intValue() |
||
1261 | ,"" + codigoDoCurso.intValue(),disciplina.getCdLectivo(),disciplina.getCdTurma()); |
||
1262 | }*/ |
||
1263 | if(courseUnits == null || courseUnits.size() == 0) |
||
1264 | { |
||
1265 | unitsNotFound++; |
||
1266 | 1.5.0/docs/api/java/lang/String.html">String msg = "Unit not found (student " + student.getSigesCode() + "): semestre:" + disciplina.getCdDuracao() + " codigo:" + disciplina.getCodigo() + " course:" + codigoDoCurso + " year:" + disciplina.getCdLectivo() + " turma: " + disciplina.getCdTurma(); |
||
1267 | serviceLogWarn(msg); |
||
1268 | logger.warn(msg); |
||
1269 | } |
||
1270 | else |
||
1271 | { |
||
1272 | for(CourseUnit found: courseUnits) |
||
255 | jmachado | 1273 | { |
1400 | jmachado | 1274 | 1.5.0/docs/api/java/lang/String.html">String turma = disciplina.getCdTurma(); |
1275 | map_CourseUnit_x_Turma.put(found, turma); |
||
255 | jmachado | 1276 | } |
1312 | jmachado | 1277 | |
1278 | unitsFromSigesPersistentInBaco.addAll(courseUnits); |
||
255 | jmachado | 1279 | } |
1312 | jmachado | 1280 | } |
1281 | return unitsFromSigesPersistentInBaco; |
||
1282 | } |
||
566 | jmachado | 1283 | |
1312 | jmachado | 1284 | |
1285 | |||
1286 | |||
1287 | private void updateSituacaoPropinas(Aluno alunoSiges, Student student, 1.5.0/docs/api/java/lang/String.html">String activeImportYear) { |
||
1288 | if(alunoSiges.getHistoricos() == null || alunoSiges.getHistoricos().size() == 0) |
||
1289 | { |
||
1290 | student.setPropinasEmDia(false); |
||
1291 | serviceLogWarn("ATENTION Estudante sem historico de Matriculas para aferir propinas: codigo " + alunoSiges.getCodigo()); |
||
1292 | logger.warn("ATENTION Estudante sem historico de Matriculas para aferir propinas: codigo " + alunoSiges.getCodigo()); |
||
1293 | } |
||
1294 | else |
||
1295 | { |
||
1296 | student.setPropinasEmDia(false); |
||
1297 | student.setPropinasEmDiaYear(activeImportYear); |
||
1298 | |||
1299 | for(AlunoHistorico hist: alunoSiges.getHistoricos()) |
||
566 | jmachado | 1300 | { |
1312 | jmachado | 1301 | if(hist.getCodigoLectivo()!=null && hist.getCodigoLectivo().equals(activeImportYear)) |
566 | jmachado | 1302 | { |
1312 | jmachado | 1303 | if(hist.getPropinaEmDia().equalsIgnoreCase("s")) |
566 | jmachado | 1304 | { |
1312 | jmachado | 1305 | student.setPropinasEmDia(true); |
1306 | student.setPropinasEmDiaYear(activeImportYear); |
||
566 | jmachado | 1307 | } |
1312 | jmachado | 1308 | break; |
566 | jmachado | 1309 | } |
1310 | } |
||
1312 | jmachado | 1311 | if(!student.isPropinasEmDia()) |
1312 | { |
||
1313 | serviceLogInfo("ATENTION Estudante sem propina em dia: codigo " + alunoSiges.getCodigo()); |
||
1314 | logger.info("ATENTION Estudante sem propina em dia: codigo " + alunoSiges.getCodigo()); |
||
1315 | } |
||
129 | susana | 1316 | } |
116 | jmachado | 1317 | } |
1318 | |||
1553 | jmachado | 1319 | |
1320 | |||
1321 | private void updateStudentFields(Aluno alunoSiges, Student student, boolean newUser, HashMap<Integer, Nacionalidade> nacionalidades) { |
||
1312 | jmachado | 1322 | if(newUser) |
1323 | { |
||
1324 | studentsNew++; |
||
1553 | jmachado | 1325 | cloneFields(alunoSiges, student, nacionalidades); |
1312 | jmachado | 1326 | 1.5.0/docs/api/java/lang/String.html">String msg = "NOVO ALUNO ENCONTRADO: siges:" + student.getSigesCode() + " bi:" + student.getBi() + " nome:" + student.getName(); |
1327 | serviceLogInfo(msg); |
||
1328 | logger.info(msg); |
||
1329 | } |
||
1330 | //CASO EM QUE O ALUNO NO SIGES FOI ATRIBUIDO A OUTRO ESTUDANTE PARA PREENCHER BURACO NA NUMERACAO |
||
1331 | else if(alunoSiges.getNumeroBi() == null || student.getBi() == null || ! alunoSiges.getNumeroBi().equals(student.getBi())) |
||
1332 | { |
||
1333 | studentsChangeBI++; |
||
1334 | |||
1335 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder builder = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
1336 | |||
1337 | builder.append("ATENCAO NUMERO DE ALUNO " + alunoSiges.getCodigo() + " MUDOU DE DONO Confirme dados\n"); |
||
1338 | builder.append("ALTERANDO DADOS DO ALUNO " + alunoSiges.getCodigo() + "\n"); |
||
1339 | builder.append("-----ANTES: " + "\n"); |
||
1340 | builder.append("-----BI: " + student.getBi() + "\n"); |
||
1341 | builder.append("-----Nome: " + student.getName() + "\n"); |
||
1342 | builder.append("-----Username: " + student.getUserNameNetpa() + "\n"); |
||
1343 | builder.append("-----Address: " + student.getAddress() + "\n"); |
||
1344 | builder.append("-----Zip: " + student.getZip() + "\n"); |
||
1345 | builder.append("-----Email: " + student.getEmail() + "\n"); |
||
1346 | builder.append("-----Phone: " + student.getPhonenumber() + "\n"); |
||
1347 | |||
1553 | jmachado | 1348 | cloneFields(alunoSiges, student, nacionalidades); |
1312 | jmachado | 1349 | |
1350 | //todo verificar isto |
||
1351 | //student.setAutoBlockMode(false); |
||
1352 | //student.setManualBlock(true); |
||
1353 | |||
1354 | builder.append("DEPOIS: " + "\n"); |
||
1355 | builder.append("BI: " + student.getBi() + "\n"); |
||
1356 | builder.append("Nome: " + student.getName() + "\n"); |
||
1357 | builder.append("Username: " + student.getUserNameNetpa() + "\n"); |
||
1358 | builder.append("Address: " + student.getAddress() + "\n"); |
||
1359 | builder.append("Zip: " + student.getZip() + "\n"); |
||
1360 | builder.append("Email: " + student.getEmail() + "\n"); |
||
1361 | builder.append("Phone: " + student.getPhonenumber() + "\n"); |
||
1362 | |||
1363 | serviceLogWarn(builder.toString()); |
||
1364 | |||
1365 | sendNotificationAdmin("CODIGO SIGES " + alunoSiges.getCodigo() + " MUDOU DE DONO - FOI BLOQUEADO ",builder.toString()); |
||
1366 | |||
1367 | |||
1368 | } |
||
1423 | jmachado | 1369 | |
1553 | jmachado | 1370 | actualizaNacionalidade(alunoSiges, student, nacionalidades); |
1371 | |||
1423 | jmachado | 1372 | if(alunoSiges.getTiposAlunosRepresentados() != null) |
1373 | { |
||
1374 | for(Aluno.TipoAluno tipo:alunoSiges.getTiposAlunosRepresentados()) |
||
1375 | { |
||
1376 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_NORMAL)) |
||
1377 | student.setTipoAlunoNormal(true); |
||
1378 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_ERASMUS)) |
||
1379 | student.setTipoAlunoErasmus(true); |
||
1380 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_TRABALHADOR_ESTUDANTE)) |
||
1381 | student.setTipoAlunoTrabalhadorEstudante(true); |
||
1382 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_BOLSEIRO)) |
||
1383 | student.setTipoAlunoBolseiro(true); |
||
1384 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_BOMBEIRO)) |
||
1385 | student.setTipoAlunoBombeiro(true); |
||
1386 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_DEFICIENTE)) |
||
1387 | student.setTipoAlunoDeficiente(true); |
||
1388 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_DIRIGENTE_ASSOCIATIVO)) |
||
1389 | student.setTipoAlunoDirigenteAssociativo(true); |
||
1390 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_MILITAR)) |
||
1391 | student.setTipoAlunoMilitar(true); |
||
1392 | if(tipo.getCodigoTipoAluno().equals(Globals.SIGES_TIPO_ALUNO_VASCODAGAMA)) |
||
1393 | student.setTipoAlunoVascodagama(true); |
||
1394 | } |
||
1395 | } |
||
1312 | jmachado | 1396 | } |
1397 | |||
1553 | jmachado | 1398 | private void actualizaNacionalidade(Aluno alunoSiges, Student student, HashMap<Integer, Nacionalidade> nacionalidades) { |
1399 | //NEW CLONINNG NACIONALIDADE |
||
1400 | try{ |
||
1401 | if(alunoSiges.getCodigoNacionalidade() != null) |
||
1402 | { |
||
1403 | Nacionalidade nac = nacionalidades.get(alunoSiges.getCodigoNacionalidade()); |
||
1404 | if(nac != null) |
||
1405 | { |
||
1406 | student.setCountry(nac.getPais()); |
||
1407 | student.setNacionalidade(nac.getNacionalidade()); |
||
1408 | } |
||
1409 | } |
||
1410 | } |
||
1411 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable t) |
||
1412 | { |
||
1413 | logger.error("NACIONALIDADE INVALIDA NO DOCENTE: " + alunoSiges.getCodigo()); |
||
1414 | } |
||
1415 | } |
||
1416 | |||
1312 | jmachado | 1417 | /*private CourseUnit tryFindCourseUnitWithOutTurma(DefaultLogMessages logMessages, String cdDuracao, String codigo,String codigoCurso,String cdLectivo,String cdTurma) |
1138 | jmachado | 1418 | { |
1419 | CourseUnit courseUnit = null; |
||
1140 | jmachado | 1420 | String msg = "Unit not found with turma code : semestre:" + cdDuracao + " codigo:" + codigo + " course:" + codigoCurso + " year:" + cdLectivo + " turma: " + cdTurma; |
1138 | jmachado | 1421 | logMessages.addMessage(new DefaultLogMessage("", LogMessageTypeEnum.WARNING,msg)); |
1422 | serviceLogWarn(msg); |
||
1423 | logger.warn(msg); |
||
1424 | msg = "Trying without Turma code..."; |
||
1425 | serviceLogWarn(msg); |
||
1426 | logger.warn(msg); |
||
1140 | jmachado | 1427 | List<CourseUnit> cus = DaoFactory.getCourseUnitDaoImpl().loadBySigesCode("" + codigo,"" + codigoCurso,cdDuracao,cdLectivo); |
1138 | jmachado | 1428 | if(cus != null && cus.size() == 1) |
1429 | { |
||
1430 | courseUnit = cus.get(0); |
||
1431 | msg = "Found ok..."; |
||
1432 | serviceLogInfo(msg); |
||
1433 | logger.info(msg); |
||
1434 | } |
||
1435 | else if(cus !=null && cus.size() > 1) |
||
1436 | { |
||
1437 | courseUnit = cus.get(0); |
||
1438 | msg = "Found More than one, unexpected situation..." + cus.get(0).getId() + " - " + cus.get(1).getId(); |
||
1439 | logMessages.addMessage(new DefaultLogMessage("", LogMessageTypeEnum.WARNING,msg)); |
||
1440 | serviceLogWarn(msg); |
||
1441 | logger.warn(msg); |
||
1442 | } |
||
1443 | else |
||
1444 | { |
||
1445 | msg = "Not Found ..."; |
||
1446 | serviceLogInfo(msg); |
||
1447 | logger.info(msg); |
||
1448 | } |
||
1449 | return courseUnit; |
||
1450 | |||
1312 | jmachado | 1451 | }*/ |
1452 | |||
1553 | jmachado | 1453 | private void cloneFields(Aluno alunoSiges, Student student, HashMap<Integer, Nacionalidade> nacionalidades) { |
995 | jmachado | 1454 | student.setName(alunoSiges.getNome()); |
1455 | student.setEmail(alunoSiges.getEmail()); |
||
1456 | student.setSigesCode(alunoSiges.getCodigo().intValue()); |
||
1457 | student.setAddress(alunoSiges.getMorada()); |
||
1458 | student.setPhonenumber(StringsUtils.cleanKeepNumbers(alunoSiges.getTelemovel())); |
||
1459 | student.setZip("" + alunoSiges.getCodigoPostal().intValue()); |
||
1460 | student.setBi(alunoSiges.getNumeroBi()); |
||
1461 | student.setSex(alunoSiges.getSexo()); |
||
1462 | student.setUserNameNetpa(alunoSiges.getUsernameNetpa()); |
||
1298 | jmachado | 1463 | student.setBirthDate(alunoSiges.getDataNascimento()); |
995 | jmachado | 1464 | student.setUsername("a" + alunoSiges.getCodigo().intValue()); |
1553 | jmachado | 1465 | actualizaNacionalidade(alunoSiges, student, nacionalidades); |
995 | jmachado | 1466 | } |
1467 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
1070 | jmachado | 1468 | protected ILogMessages runJobServiceTask() throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
995 | jmachado | 1469 | |
1070 | jmachado | 1470 | 1.5.0/docs/api/java/lang/String.html">String importYear = getParametersMap().get(JOB_importYear_KEY).getObject(); |
1312 | jmachado | 1471 | 1.5.0/docs/api/java/lang/String.html">String institutionCode = getParametersMap().get(JOB_institution_KEY).getObject(); |
1472 | ILogMessages messages = run(importYear,1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(institutionCode)); |
||
1070 | jmachado | 1473 | return messages; |
995 | jmachado | 1474 | |
1475 | } |
||
1476 | |||
129 | susana | 1477 | /** |
1478 | * Testar por aqui poi requer Super Role e assim e' autmatico |
||
165 | jmachado | 1479 | * |
129 | susana | 1480 | * @param args of main |
165 | jmachado | 1481 | * @throws ServiceException on error |
1482 | */ |
||
116 | jmachado | 1483 | |
165 | jmachado | 1484 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException |
129 | susana | 1485 | { |
995 | jmachado | 1486 | 1.5.0/docs/api/java/lang/String.html">String year = DaoFactory.getConfigurationDaoImpl().getImportsDefaultImportYearCreateTransaction(); |
941 | jmachado | 1487 | 1.5.0/docs/api/java/lang/System.html">System.out.println("YEAR:" + year); |
491 | jmachado | 1488 | if(args != null && args.length > 0) |
1489 | year = args[0]; |
||
1341 | jmachado | 1490 | 1.5.0/docs/api/java/lang/String.html">String institutionCode = "3"; |
1312 | jmachado | 1491 | if(args != null && args.length > 1) |
1492 | institutionCode = args[1]; |
||
995 | jmachado | 1493 | AbstractDao.getCurrentSession().beginTransaction(); |
1312 | jmachado | 1494 | new ImportStudentsService().run(year,1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(institutionCode)); |
995 | jmachado | 1495 | AbstractDao.getCurrentSession().getTransaction().commit(); |
129 | susana | 1496 | } |
1497 | } |
||
116 | jmachado | 1498 | |
129 | susana | 1499 | |
1500 | |||
1501 | |||
1502 | |||
1503 |