Rev 1312 | Rev 1558 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
995 | jmachado | 1 | package pt.estgp.estgweb.services.sigesimports; |
2 | |||
3 | import jomm.dao.impl.AbstractDao; |
||
4 | import jomm.utils.FilesUtils; |
||
5 | import jomm.utils.PdfUtils; |
||
6 | import org.apache.commons.net.ftp.FTP; |
||
7 | import org.apache.commons.net.ftp.FTPClient; |
||
8 | import org.apache.fop.apps.FOPException; |
||
9 | import org.apache.log4j.Logger; |
||
10 | import org.dom4j.Document; |
||
11 | import org.json.JSONArray; |
||
12 | import org.json.JSONException; |
||
13 | import org.json.JSONObject; |
||
14 | import pt.estgp.estgweb.Globals; |
||
15 | import pt.estgp.estgweb.domain.*; |
||
16 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
17 | import pt.estgp.estgweb.domain.enums.LangEnum; |
||
1353 | jmachado | 18 | import pt.estgp.estgweb.domain.views.CourseUnitSummaryView; |
19 | import pt.estgp.estgweb.domain.views.CourseUnitView; |
||
995 | jmachado | 20 | import pt.estgp.estgweb.services.courseunits.CreateCourseUnitXML; |
21 | import pt.estgp.estgweb.services.email.EMAILJob; |
||
22 | import pt.estgp.estgweb.services.email.SendEmailService; |
||
23 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
||
24 | import pt.estgp.estgweb.services.jobs.JobScheduleService; |
||
25 | import pt.estgp.estgweb.services.jobs.ServiceJob; |
||
26 | import pt.estgp.estgweb.services.logresults.ILogMessages; |
||
27 | import pt.estgp.estgweb.services.logresults.LogMessageTypeEnum; |
||
28 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessage; |
||
29 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages; |
||
1235 | jmachado | 30 | import pt.estgp.estgweb.services.sigesimports.oracle.dao.AulaDao; |
1267 | jmachado | 31 | import pt.estgp.estgweb.services.sigesimports.oracle.dao.connection.ConnectionManager; |
1312 | jmachado | 32 | import pt.estgp.estgweb.utils.ConfigProperties; |
995 | jmachado | 33 | import pt.estgp.estgweb.utils.Dom4jUtil; |
34 | import pt.estgp.estgweb.web.FtpServer; |
||
35 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
36 | |||
37 | import javax.xml.transform.TransformerException; |
||
38 | import javax.xml.transform.dom.DOMSource; |
||
39 | import java.io.File; |
||
40 | import java.io.FileInputStream; |
||
41 | import java.io.FileOutputStream; |
||
42 | import java.io.IOException; |
||
1267 | jmachado | 43 | import java.sql.Connection; |
1353 | jmachado | 44 | import java.util.*; |
995 | jmachado | 45 | |
46 | /** |
||
47 | * @author Jorge Machado |
||
48 | * @date 11/May/2008 |
||
49 | * @time 12:51:32 |
||
50 | * @see pt.estgp.estgweb |
||
1353 | jmachado | 51 | * |
52 | * |
||
53 | * @NOTAS IMPORTANTES DESTE SERVIÇO |
||
54 | * |
||
55 | * @DEPENDS TODO DEPENDENCIAS FORTES |
||
56 | * Este serviço gera toda a informação acerca de sumários e sumários em FALTA |
||
57 | * Existe uma forte depêndencia da CourseUniView que recebe daqui a lógica de decisão daquilo que são ou não sumários |
||
58 | * atrasados |
||
995 | jmachado | 59 | */ |
60 | public class ImportSumariesJson extends ServiceJob implements IService |
||
61 | { |
||
62 | |||
63 | 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(ImportSumariesJson.class); |
||
64 | |||
1030 | jmachado | 65 | private static final int MAX_COMMIT = 10; |
995 | jmachado | 66 | |
67 | |||
1312 | jmachado | 68 | public ILogMessages run(1.5.0/docs/api/java/lang/String.html">String year,int institutionCode,1.5.0/docs/api/java/lang/String.html">String semestre) throws ServiceException |
995 | jmachado | 69 | { |
1312 | jmachado | 70 | return run(year,institutionCode,semestre,true,true); |
995 | jmachado | 71 | } |
72 | |||
1312 | jmachado | 73 | public ILogMessages run(1.5.0/docs/api/java/lang/String.html">String year,int institutionCode,1.5.0/docs/api/java/lang/String.html">String semestre,boolean sendIONLINE,boolean sendEMAIL) throws ServiceException |
995 | jmachado | 74 | { |
75 | 1.5.0/docs/api/java/lang/String.html">String msgS = "STARTING SUMARIES IMPORT SERVICE FOR year: " + year + " semestre: " + semestre + " sendIONLINE: " + sendIONLINE + " sendEMAIL: " + sendEMAIL; |
||
76 | serviceLogInfo(msgS); |
||
77 | logger.info(msgS); |
||
78 | |||
79 | DefaultLogMessages logMessages = new DefaultLogMessages(); |
||
1312 | jmachado | 80 | logMessages.addMessage(new DefaultLogMessage("import.summaries", LogMessageTypeEnum.INFO, "instituicao " + institutionCode)); |
995 | jmachado | 81 | serviceLogInfo(logMessages.getLastMessage()); |
82 | |||
83 | |||
84 | int countUnits = 0; |
||
85 | int countUnitsOk = 0; |
||
86 | int countUnitsZeroSummaries = 0; |
||
1081 | jmachado | 87 | int countUnitsZeroValidSummaries = 0; |
995 | jmachado | 88 | |
89 | List<String> unitsZeroSummaries = new ArrayList<String>(); |
||
90 | List<String> unitsFailed = new ArrayList<String>(); |
||
91 | try |
||
92 | { |
||
93 | |||
1298 | jmachado | 94 | /* SiGesWEB service; |
1017 | jmachado | 95 | String WSDL = DaoFactory.getConfigurationDaoImpl().getSigesWebServicesWsdl(); |
995 | jmachado | 96 | try |
97 | { |
||
1017 | jmachado | 98 | serviceLogInfo("STARTING WEB SERVICE AT " + WSDL); |
99 | service = new SiGesWEB(new URL(WSDL), new QName(Globals.SIGES_WEBSERVICE_TARGET_NAMESPACE, "SiGesWEB")); |
||
995 | jmachado | 100 | } |
101 | catch (Throwable e) |
||
102 | { |
||
103 | logMessages.addMessage(new DefaultLogMessage("import.error",e.toString(),"erro na configuracao do WEB Service", LogMessageTypeEnum.INFO)); |
||
104 | serviceLogInfo(logMessages.getLastMessage()); |
||
105 | logger.fatal(e, e); |
||
106 | serviceLogError(e.toString(), e); |
||
107 | return logMessages; |
||
1298 | jmachado | 108 | }*/ |
995 | jmachado | 109 | |
110 | int i = 0; |
||
111 | //List<Long> cUs = DaoFactory.getCourseUnitDaoImpl().loadIds(year,DatesUtils.getSemestre()); |
||
112 | List<Long> cUs = DaoFactory.getCourseUnitDaoImpl().loadIds(year,semestre); |
||
113 | 1.5.0/docs/api/java/lang/String.html">String nowCode = ""; |
||
1267 | jmachado | 114 | 1.5.0/docs/api/java/sql/Connection.html">Connection conn = ConnectionManager.openConnection(); |
115 | boolean connError = false; |
||
995 | jmachado | 116 | for(1.5.0/docs/api/java/lang/Long.html">Long cId: cUs) |
117 | { |
||
1267 | jmachado | 118 | if(connError) |
119 | break; |
||
1144 | jmachado | 120 | nowCode = "" + cId; |
995 | jmachado | 121 | countUnits++; |
122 | try |
||
123 | { |
||
124 | if (i++ > MAX_COMMIT) |
||
125 | { |
||
126 | i = 0; |
||
996 | jmachado | 127 | setProgress((int) (((float)countUnits)/((float)cUs.size())*100.0f)); |
1312 | jmachado | 128 | conn.close(); |
1076 | jmachado | 129 | commitPartially(); |
1312 | jmachado | 130 | conn = ConnectionManager.openConnection(); |
995 | jmachado | 131 | } |
132 | CourseUnit c = DaoFactory.getCourseUnitDaoImpl().load(cId); |
||
133 | nowCode = c.getCode(); |
||
134 | logMessages.addMessage(new DefaultLogMessage("import.info","Importing Summaries to CourseUnit: " + c.getCode() + ": course: " + c.getCourse().getCode(),"", LogMessageTypeEnum.INFO)); |
||
135 | logger.info("Importing Summaries to CourseUnit: " + c.getName() + " (" + c.getCode() + ") course " + c.getCourse().getName() + " (" + c.getCourse().getCode() + ")"); |
||
136 | serviceLogInfo(logMessages.getLastMessage()); |
||
137 | |||
138 | int tries = 3; |
||
1235 | jmachado | 139 | //ArrayOfAula arrayOfAulas = null; |
140 | ArrayList<pt.estgp.estgweb.services.sigesimports.oracle.domain.Aula> arrayOfAulas = null; |
||
995 | jmachado | 141 | while(tries > 0) |
142 | { |
||
143 | //comentario de teste |
||
144 | try |
||
145 | { |
||
1267 | jmachado | 146 | |
1235 | jmachado | 147 | //arrayOfAulas = service.getSiGesWEBSoap().getAulas(new BigDecimal(DaoFactory.getConfigurationDaoImpl().getSigesInstitutionCode()), year,c.getCode(),semestre,c.getCourse().getCode()); |
1312 | jmachado | 148 | arrayOfAulas = AulaDao.getInstance().loadAulas(institutionCode,year,c.getCode(),semestre,c.getCourse().getCode(),conn); |
1267 | jmachado | 149 | |
995 | jmachado | 150 | break; |
151 | } |
||
152 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable t) |
||
153 | { |
||
154 | if(tries-- == 0) |
||
155 | { |
||
156 | logger.error("Giving up of courseUnit:" + cId + " ( " + c.getName() + " ) ",t); |
||
157 | serviceLogError("Giving up of courseUnit:" + cId + " ( " + c.getName() + " ) ",t); |
||
1267 | jmachado | 158 | connError = true; |
995 | jmachado | 159 | break; |
160 | } |
||
161 | |||
1144 | jmachado | 162 | |
1267 | jmachado | 163 | logger.error("WebService Fail, trying " + tries + " times sleeping a while",t); |
1144 | jmachado | 164 | serviceLogError("WebService Fail, trying " + tries + " times sleeping a while " + t.toString()); |
165 | serviceLogError("WebService Fail, trying " + tries + " times sleeping a while " + t.getCause()); |
||
995 | jmachado | 166 | 1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(5000); |
167 | } |
||
168 | } |
||
169 | |||
1235 | jmachado | 170 | if(arrayOfAulas != null && arrayOfAulas.size() > 0) |
995 | jmachado | 171 | { |
172 | List<CourseUnitSummary> courseUnitSummaries = new ArrayList<CourseUnitSummary>(); |
||
173 | |||
174 | //HashMap<String, CourseUnitSummary> map = new HashMap<String, CourseUnitSummary>(); |
||
175 | /*if(c.getSummaries() != null && c.getSummaries().size() > 0) |
||
176 | for(CourseUnitSummary s: c.getSummaries()) |
||
177 | map.put(s.getCodigoAula() + ":" + s.getCodigoSumario(),s); |
||
178 | else |
||
179 | c.setSummaries(new HashSet<CourseUnitSummary>());*/ |
||
180 | JSONObject summariesJson = new JSONObject(); |
||
181 | JSONArray summaries = new JSONArray(); |
||
182 | summariesJson.put("summary",summaries); |
||
1081 | jmachado | 183 | int summariesValid = 0; |
1235 | jmachado | 184 | for(pt.estgp.estgweb.services.sigesimports.oracle.domain.Aula aula: arrayOfAulas) |
995 | jmachado | 185 | { |
186 | |||
1235 | jmachado | 187 | //todo cdTurma Rollback aqui não retirar o sumário |
188 | //Mas pensar em separar os sumários na página, podemos |
||
189 | //separar tendo em conta quem entra, se for aluno só vê os |
||
190 | //seus sumários, se for prof vê os sumários das suas turmas |
||
191 | |||
1248 | jmachado | 192 | /* |
1235 | jmachado | 193 | if(c.getCdTurma() != null && aula.getAula_codigoTurma()!=null |
1133 | jmachado | 194 | && c.getCdTurma().trim().length() > 0 |
1235 | jmachado | 195 | && aula.getAula_codigoTurma().trim().length() > 0 |
196 | && !aula.getAula_codigoTurma().equals(c.getCdTurma())) |
||
1133 | jmachado | 197 | { |
198 | //Código de Turma diferente |
||
1235 | jmachado | 199 | System.out.println("Ignoring summary code: " + aula.getAula_codigoTurma() + " for unit " + c.getName() + "/" + c.getCode() + " T:" + c.getCdTurma()); |
1133 | jmachado | 200 | continue; |
1248 | jmachado | 201 | }*/ |
1133 | jmachado | 202 | |
995 | jmachado | 203 | //CourseUnitSummary s = map.get(aula.getSumNumeroAula() + ":" + aula.getCodigoSumario()); |
204 | //if(s == null) |
||
205 | //{ |
||
206 | CourseUnitSummaryImpl s = DomainObjectFactory.createCourseUnitSummaryImpl(); |
||
207 | s.setCourseUnit(c); |
||
208 | //c.getSummaries().add(s); |
||
209 | //DaoFactory.getCourseUnitSummaryDaoImpl().save(s); |
||
210 | //summaries.add(); |
||
211 | //} |
||
1235 | jmachado | 212 | s.setCdTipoOcupacao(aula.getTipoOcupacao().intValue()); |
213 | s.setNrAula(aula.getNumeroAula().intValue()); |
||
995 | jmachado | 214 | s.setCodigoSumario(""+aula.getCodigoSumario().intValue()); |
1235 | jmachado | 215 | s.setCodigoAula("" + aula.getSum_numeroAula().intValue()); |
216 | s.setNumeroAula(aula.getSum_numeroAula().intValue()); |
||
217 | s.setDataAula(aula.getData()); |
||
218 | s.setTipoAula(aula.getSum_tipoAula()); |
||
219 | s.setCodigoSalaAula("" + aula.getAula_codigoSalaAula().intValue()); |
||
220 | s.setAlunosPresentes(aula.getSum_numeroPresencas().intValue()); |
||
221 | s.setTitulo(aula.getSum_titulo()); |
||
222 | s.setCodigoDocente(aula.getAula_codigoDocente()+ ""); |
||
223 | s.setDescricao(aula.getSum_descricao()); |
||
224 | s.setcEstado(""+aula.getSum_cdEstado().intValue()); |
||
995 | jmachado | 225 | s.setNumeroHoras("" + aula.getNumeroCelulas().intValue()); |
226 | summaries.put(s.getJson()); |
||
227 | courseUnitSummaries.add(s); |
||
1081 | jmachado | 228 | if(s.getNumeroAula() > 0) |
229 | summariesValid++; |
||
995 | jmachado | 230 | } |
231 | if(courseUnitSummaries.size() == 0) |
||
232 | { |
||
233 | countUnitsZeroSummaries++; |
||
234 | unitsZeroSummaries.add(c.getCode()); |
||
1081 | jmachado | 235 | logger.info("ZERO SUMARIES unit:" + c.getCode() + " course: " + c.getCourseCode()); |
236 | serviceLogInfo("ZERO SUMARIES unit:" + c.getCode() + " course: " + c.getCourseCode()); |
||
995 | jmachado | 237 | } |
1081 | jmachado | 238 | else if(summariesValid == 0) |
239 | { |
||
1144 | jmachado | 240 | //NAO METE OK NEM ZERO |
1081 | jmachado | 241 | countUnitsZeroValidSummaries++; |
242 | unitsZeroSummaries.add(c.getCode()); |
||
243 | logger.info("ZERO VALID SUMARIES unit:" + c.getCode() + " course: " + c.getCourseCode()); |
||
244 | serviceLogInfo("ZERO VALID SUMARIES unit:" + c.getCode() + " course: " + c.getCourseCode()); |
||
245 | } |
||
995 | jmachado | 246 | else |
247 | { |
||
248 | countUnitsOk++; |
||
249 | } |
||
250 | c.setSummariesJson(summariesJson.toString()); |
||
251 | |||
252 | if(sendIONLINE) |
||
253 | { |
||
254 | 1.5.0/docs/api/java/lang/String.html">String path = generatePdf(c); |
||
255 | sendPdfFtpIonline(c,new ArrayList<String>(),null,path,null); |
||
1268 | jmachado | 256 | try{ |
257 | FilesUtils.delete(path); |
||
258 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
259 | { |
||
260 | logger.error("trying to delete " + path,e); |
||
261 | } |
||
995 | jmachado | 262 | } |
263 | if(sendEMAIL) |
||
264 | { |
||
265 | sendEmail(null, courseUnitSummaries,true); |
||
266 | } |
||
267 | } |
||
268 | else |
||
269 | { |
||
1144 | jmachado | 270 | //NAO METE OK MAS METE ZERO |
995 | jmachado | 271 | countUnitsZeroSummaries++; |
272 | unitsZeroSummaries.add(c.getCode()); |
||
273 | logger.error("Summaries come null in unit:" + c.getCode()); |
||
274 | serviceLogError("Summaries come null in unit:" + c.getCode()); |
||
275 | } |
||
276 | } |
||
277 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
278 | { |
||
1144 | jmachado | 279 | //NAO METE OK |
995 | jmachado | 280 | unitsFailed.add(nowCode); |
281 | logger.error(e,e); |
||
282 | serviceLogError(e.toString(),e); |
||
283 | } |
||
284 | } |
||
1267 | jmachado | 285 | conn.close(); |
995 | jmachado | 286 | |
287 | setProgress(100); |
||
288 | serviceLogError("Finish commiting"); |
||
289 | |||
290 | } |
||
291 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
292 | { |
||
293 | logger.error(e, e); |
||
294 | logMessages.addMessage(new DefaultLogMessage("import.error", e.toString(), "see log for details", LogMessageTypeEnum.ERROR)); |
||
295 | serviceLogError(logMessages.getLastMessage(),e); |
||
296 | throw new ServiceException(e.toString(), e); |
||
297 | } |
||
298 | |||
299 | logMessages.addMessage(new DefaultLogMessage("import.summaries.terminating", LogMessageTypeEnum.INFO)); |
||
300 | logger.info("terminating summaries import"); |
||
301 | serviceLogInfo(logMessages.getLastMessage()); |
||
302 | |||
1144 | jmachado | 303 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder failedUnitsExc = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
304 | for(1.5.0/docs/api/java/lang/String.html">String cId: unitsFailed) |
||
305 | failedUnitsExc.append(cId).append(";"); |
||
1145 | jmachado | 306 | |
995 | jmachado | 307 | serviceLogInfo("#######################################"); |
308 | serviceLogInfo("#######################################"); |
||
309 | serviceLogInfo("UNITS PROCESSED: " + countUnits); |
||
1144 | jmachado | 310 | serviceLogInfo("UNITS FAILED: " + (countUnits - countUnitsZeroSummaries - countUnitsOk - countUnitsZeroValidSummaries)); |
311 | serviceLogInfo("UNITS FAILED EXCEPTION PARSING XML WEB SERVICE: " + unitsFailed.size()); |
||
995 | jmachado | 312 | serviceLogInfo("UNITS IMPORT OK: " + countUnitsOk); |
313 | serviceLogInfo("UNITS ZERO SUMARIES: " + countUnitsZeroSummaries); |
||
1081 | jmachado | 314 | serviceLogInfo("UNITS ZERO VALID SUMARIES: " + countUnitsZeroValidSummaries); |
995 | jmachado | 315 | serviceLogInfo("#######################################"); |
1144 | jmachado | 316 | serviceLogWarn("####FAILED Exception (Check exceptions in log): Units Baco Id Code : " + failedUnitsExc.toString()); |
1025 | jmachado | 317 | |
318 | logger.info("#######################################"); |
||
319 | logger.info("#######################################"); |
||
320 | logger.info("UNITS PROCESSED: " + countUnits); |
||
1144 | jmachado | 321 | logger.info("UNITS FAILED: " + (countUnits - countUnitsZeroSummaries - countUnitsOk - countUnitsZeroValidSummaries)); |
322 | logger.info("UNITS FAILED EXCEPTION PARSING XML WEB SERVICE: " + unitsFailed.size()); |
||
1025 | jmachado | 323 | logger.info("UNITS IMPORT OK: " + countUnitsOk); |
324 | logger.info("UNITS ZERO SUMARIES: " + countUnitsZeroSummaries); |
||
1081 | jmachado | 325 | logger.info("UNITS ZERO VALID SUMARIES: " + countUnitsZeroValidSummaries); |
1025 | jmachado | 326 | logger.info("#######################################"); |
1144 | jmachado | 327 | logger.warn("####FAILED Exception (Check exceptions in log): Units Baco Id Code : " + failedUnitsExc.toString()); |
328 | |||
329 | |||
995 | jmachado | 330 | return logMessages; |
331 | } |
||
332 | |||
333 | |||
334 | public static SendEmailService sendEmailService = new SendEmailService(); |
||
335 | |||
336 | private void sendEmail(UserSession userSession,List<CourseUnitSummary> summaries,boolean sendEmail) |
||
337 | { |
||
338 | if(Globals.EMAIL_SUMMARIES && summaries.size() > 0 && sendEmail) |
||
339 | { |
||
340 | // for(CourseUnitSummary summary: summaries) |
||
341 | // { |
||
342 | |||
343 | List<String> emails = DaoFactory.getCourseUnitSummaryDaoImpl().getStudentsEmails(summaries.get(0).getId()); |
||
344 | if(emails == null) |
||
345 | logger.warn("No students emails in unit: code:" + summaries.get(0).getCourseUnit().getCode() + " " + summaries.get(0).getCourseUnit().getName()); |
||
346 | EMAILJob emailJob = new EMAILJob(sendEmailService.getSummariesEmail(emails, summaries, summaries.get(0).getCourseUnit(), LangEnum.PORTUGUESE)); |
||
347 | JobScheduleService.getInstance().scheduleNow(emailJob,"New Summary EMAIL from: " + summaries.get(0).getCourseUnit().getName() + " aula: " +summaries.get(summaries.size()-1).getNumeroAula() ,userSession); |
||
348 | // } |
||
349 | } |
||
350 | } |
||
351 | |||
352 | |||
353 | |||
354 | |||
355 | |||
356 | |||
357 | public static 1.5.0/docs/api/java/lang/String.html">String generatePdf(CourseUnit c) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException { |
||
358 | 5+0%2Fdocs%2Fapi+Document">Document dom = new CreateCourseUnitXML().run(c,null); |
||
359 | org.w3c.dom.5+0%2Fdocs%2Fapi+Document">Document dd = Dom4jUtil.toW3c(dom); |
||
360 | 1.5.0/docs/api/java/lang/String.html">String path = Globals.TMP_DIR + 1.5.0/docs/api/java/io/File.html">File.separator + c.getCode() + "-" + c.getNormalizedName() + "-sumarios.pdf"; |
||
361 | 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream out = new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(path); |
||
362 | Map<String,Object> params = new HashMap<String,Object>(); |
||
363 | params.put("site", Globals.SITE_URL); |
||
364 | PdfUtils.createPdfFromXml(new 1.5.0/docs/api/javax/xml/transform/dom/DOMSource.html">DOMSource(dd), "pt/estgp/estgweb/services/courseunits/courseunitsummaries.fo.xsl", out, params); |
||
365 | out.flush(); |
||
366 | out.close(); |
||
367 | return path; |
||
368 | } |
||
369 | |||
1006 | jmachado | 370 | private void sendPdfFtpIonline(CourseUnit cu, List<String> errors, UserSession u,1.5.0/docs/api/java/lang/String.html">String pdfPath,FTPClient client) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException { |
995 | jmachado | 371 | |
1312 | jmachado | 372 | if(ConfigProperties.getBooleanProperty("test.control.var")) |
373 | { |
||
374 | 1.5.0/docs/api/java/lang/String.html">String warn = "System in TEST Environement - will NOT send file to ionline test.control.var.DontSendIonlineFiles = true"; |
||
375 | logger.warn(warn); |
||
376 | return; |
||
377 | } |
||
995 | jmachado | 378 | FtpServer server = null; |
379 | if(client == null) |
||
380 | { |
||
381 | server = FtpServer.getNewServer(Globals.FTP_IONLINE_URL,Globals.FTP_IONLINE_USER,Globals.FTP_IONLINE_PASS); |
||
382 | client = server.getClient(); |
||
1005 | jmachado | 383 | if(client == null) |
384 | { |
||
385 | logger.warn("###################"); |
||
1009 | jmachado | 386 | logger.warn("################### > CANT CONNECT FTP - could be FTPTimeout: " + Globals.FTP_TIMEOUT_SECONDS); |
387 | errors.add("################### > CANT CONNECT FTP to send summaries " + ((CourseUnitImpl)cu).getSummariosPathIntranet()); |
||
1005 | jmachado | 388 | return; |
389 | } |
||
390 | |||
995 | jmachado | 391 | } |
392 | client.setFileType(FTP.BINARY_FILE_TYPE); |
||
393 | |||
394 | |||
395 | 1.5.0/docs/api/java/lang/String.html">String pastaFichaCurricular = ((CourseUnitImpl)cu).getSummariosPathIntranet(); |
||
396 | if(!client.changeWorkingDirectory(pastaFichaCurricular)) |
||
397 | { |
||
398 | logger.error("FTP CANT CHANGE TO PATH: " + pastaFichaCurricular); |
||
399 | } |
||
400 | else |
||
401 | { |
||
1009 | jmachado | 402 | if(!client.storeFile(((CourseUnitImpl)cu).getSummariosFileNameIntranet(),new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(pdfPath))) |
403 | { |
||
1010 | jmachado | 404 | 1.5.0/docs/api/java/lang/String.html">String msgS = "CANT store file in given time, probably timeout at " + Globals.FTP_DATA_STORE_TIMEOUT_SECONDS; |
405 | logger.error(msgS); |
||
406 | serviceLogError(msgS); |
||
1009 | jmachado | 407 | } |
995 | jmachado | 408 | if(server != null) |
409 | { |
||
410 | client.quit(); |
||
411 | client.disconnect(); |
||
412 | } |
||
413 | } |
||
414 | // |
||
415 | } |
||
416 | /** |
||
417 | * Testar por aqui poi requer Super Role e assim e' autmatico |
||
418 | * |
||
419 | * |
||
420 | * @param args of main |
||
421 | * @throws pt.estgp.estgweb.services.expceptions.ServiceException on error |
||
422 | */ |
||
423 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException, JSONException { |
||
424 | |||
997 | jmachado | 425 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Syntax:"); |
426 | 1.5.0/docs/api/java/lang/System.html">System.out.println("year, semestre, sendIonline, sendEmail"); |
||
427 | 1.5.0/docs/api/java/lang/System.html">System.out.println("If no arguments wil user actual year import config in all semestres and true in email and ionline"); |
||
428 | |||
1353 | jmachado | 429 | 1.5.0/docs/api/java/lang/String.html">String year = "201516";DaoFactory.getConfigurationDaoImpl().getImportsDefaultImportYearCreateTransaction(); |
995 | jmachado | 430 | 1.5.0/docs/api/java/lang/String.html">String semestre = null; |
1133 | jmachado | 431 | boolean sendIonline = false; |
432 | boolean sendEmail = false; |
||
1312 | jmachado | 433 | int institutionCode = 1; |
995 | jmachado | 434 | if(args != null && args.length > 0) |
435 | year = args[0]; |
||
997 | jmachado | 436 | |
995 | jmachado | 437 | if(args != null && args.length > 1) |
438 | semestre = args[1]; |
||
997 | jmachado | 439 | |
995 | jmachado | 440 | if(args != null && args.length > 2) |
441 | sendIonline = 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(args[2]); |
||
997 | jmachado | 442 | |
995 | jmachado | 443 | if(args != null && args.length > 3) |
444 | sendEmail = 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(args[3]); |
||
997 | jmachado | 445 | |
1312 | jmachado | 446 | if(args != null && args.length > 4) |
447 | institutionCode = 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(args[4]); |
||
448 | |||
995 | jmachado | 449 | AbstractDao.getCurrentSession().beginTransaction(); |
450 | if(semestre != null) |
||
1312 | jmachado | 451 | new ImportSumariesJson().run(year,institutionCode,semestre,sendIonline,sendEmail); |
995 | jmachado | 452 | else |
453 | { |
||
1312 | jmachado | 454 | new ImportSumariesJson().run(year,institutionCode,"S1",sendIonline,sendEmail); |
455 | new ImportSumariesJson().run(year,institutionCode,"S2",sendIonline,sendEmail); |
||
456 | new ImportSumariesJson().run(year,institutionCode,"A",sendIonline,sendEmail); |
||
995 | jmachado | 457 | } |
458 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
459 | } |
||
460 | |||
461 | |||
462 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
1070 | jmachado | 463 | protected ILogMessages runJobServiceTask() throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
995 | jmachado | 464 | |
1070 | jmachado | 465 | 1.5.0/docs/api/java/lang/String.html">String importYear = getParametersMap().get(JOB_importYear_KEY).getObject(); |
466 | 1.5.0/docs/api/java/lang/String.html">String semestre = getParametersMap().get(JOB_semestre_KEY).getObject(); |
||
467 | 1.5.0/docs/api/java/lang/String.html">String sendIonlineStr = getParametersMap().get(JOB_sendIonline_KEY).getObject(); |
||
468 | 1.5.0/docs/api/java/lang/String.html">String sendEmailStr = getParametersMap().get(JOB_sendEmail_KEY).getObject(); |
||
1312 | jmachado | 469 | 1.5.0/docs/api/java/lang/String.html">String institutionCode = getParametersMap().get(JOB_institution_KEY).getObject(); |
1070 | jmachado | 470 | boolean sendIonline = sendIonlineStr != null && 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(sendIonlineStr); |
471 | boolean sendEmail = sendEmailStr != null && 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(sendEmailStr); |
||
1312 | jmachado | 472 | return run(importYear,1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(institutionCode),semestre,sendIonline,sendEmail); |
995 | jmachado | 473 | } |
474 | |||
1353 | jmachado | 475 | |
476 | /** |
||
477 | * METODO DE HELP PARA A VISTA DA UNIDADE CURRICULAR |
||
478 | */ |
||
479 | |||
480 | public static void setSummariesFromJson(CourseUnitView cuview) { |
||
481 | |||
482 | int lateSummaries = 0; |
||
483 | int prelancadosSummaries = 0; |
||
484 | List<CourseUnitSummaryView> summariesFromJson = new ArrayList<CourseUnitSummaryView>(); |
||
485 | 1.5.0/docs/api/java/lang/String.html">String summariesJson = cuview.getSummariesJson(); |
||
486 | ArrayList<String> lateSummariesDates = new ArrayList<String>(); |
||
487 | ArrayList<String> prelancadosSummariesDates = new ArrayList<String>(); |
||
488 | |||
489 | if(summariesJson != null && summariesJson.length() > 0) |
||
490 | { |
||
491 | try { |
||
492 | JSONObject jsonObject = new JSONObject(summariesJson); |
||
493 | JSONArray summaries = jsonObject.getJSONArray("summary"); |
||
494 | for(int i = 0; i < summaries.length();i++) |
||
495 | { |
||
496 | JSONObject summary = summaries.getJSONObject(i); |
||
497 | CourseUnitSummaryImpl sum = DomainObjectFactory.createCourseUnitSummaryImpl(); |
||
498 | |||
499 | if(sum.updateWithJson(summary)){ |
||
500 | CourseUnitSummaryView view = new CourseUnitSummaryView(sum); |
||
501 | summariesFromJson.add(view); |
||
502 | } |
||
503 | else |
||
504 | // so verifica atrasados para unidades do ano corrente a titulo informativo |
||
505 | { |
||
506 | CourseUnitSummaryView view = new CourseUnitSummaryView(sum); |
||
507 | if(view.getNumber() < 0 && view.getOriginalDate().getTime() + 48*60*60*1000 < 1.5.0/docs/api/java/lang/System.html">System.currentTimeMillis()) |
||
508 | { |
||
509 | |||
510 | //System.out.println(view.getNumber() + " " + view.getDate() + " " + view.getOriginalDate()); |
||
511 | lateSummaries++; |
||
512 | lateSummariesDates.add(view.getDate()); |
||
513 | } |
||
514 | else if(sum.getcEstado().equals(""+Globals.SIGES_SUMARIO_PRELANCADO_CODIGO)) |
||
515 | { |
||
516 | prelancadosSummaries++; |
||
517 | prelancadosSummariesDates.add(view.getDate()); |
||
518 | } |
||
519 | } |
||
520 | } |
||
521 | } catch (JSONException e) { |
||
522 | logger.error(e,e); |
||
523 | } |
||
524 | 1.5.0/docs/api/java/util/Collections.html">Collections.sort(summariesFromJson, new Comparator<CourseUnitSummaryView>() { |
||
525 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
526 | public int compare(CourseUnitSummaryView courseUnitSummaryView, CourseUnitSummaryView courseUnitSummaryView2) { |
||
527 | |||
528 | if (courseUnitSummaryView.getNumber() > courseUnitSummaryView2.getNumber()) |
||
529 | return -1; |
||
530 | else if (courseUnitSummaryView.getNumber() < courseUnitSummaryView2.getNumber()) |
||
531 | return 1; |
||
532 | return 0; |
||
533 | } |
||
534 | }); |
||
535 | cuview.setSummariesFromJson(summariesFromJson); |
||
536 | cuview.setLateSummaries(lateSummaries); |
||
537 | cuview.setLateSummariesDates(lateSummariesDates); |
||
538 | cuview.setPrelancadosSummaries(prelancadosSummaries); |
||
539 | cuview.setPrelancadosSummariesDates(prelancadosSummariesDates); |
||
540 | } |
||
541 | } |
||
995 | jmachado | 542 | } |