Rev 1306 | Rev 1312 | 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; |
||
18 | import pt.estgp.estgweb.services.courseunits.CreateCourseUnitXML; |
||
19 | import pt.estgp.estgweb.services.email.EMAILJob; |
||
20 | import pt.estgp.estgweb.services.email.SendEmailService; |
||
21 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
||
22 | import pt.estgp.estgweb.services.jobs.JobScheduleService; |
||
23 | import pt.estgp.estgweb.services.jobs.ServiceJob; |
||
24 | import pt.estgp.estgweb.services.logresults.ILogMessages; |
||
25 | import pt.estgp.estgweb.services.logresults.LogMessageTypeEnum; |
||
26 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessage; |
||
27 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages; |
||
1235 | jmachado | 28 | import pt.estgp.estgweb.services.sigesimports.oracle.dao.AulaDao; |
1267 | jmachado | 29 | import pt.estgp.estgweb.services.sigesimports.oracle.dao.connection.ConnectionManager; |
995 | jmachado | 30 | import pt.estgp.estgweb.utils.Dom4jUtil; |
31 | import pt.estgp.estgweb.web.FtpServer; |
||
32 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
33 | |||
34 | import javax.xml.transform.TransformerException; |
||
35 | import javax.xml.transform.dom.DOMSource; |
||
36 | import java.io.File; |
||
37 | import java.io.FileInputStream; |
||
38 | import java.io.FileOutputStream; |
||
39 | import java.io.IOException; |
||
1267 | jmachado | 40 | import java.sql.Connection; |
995 | jmachado | 41 | import java.util.ArrayList; |
42 | import java.util.HashMap; |
||
43 | import java.util.List; |
||
44 | import java.util.Map; |
||
45 | |||
46 | /** |
||
47 | * @author Jorge Machado |
||
48 | * @date 11/May/2008 |
||
49 | * @time 12:51:32 |
||
50 | * @see pt.estgp.estgweb |
||
51 | */ |
||
52 | public class ImportSumariesJson extends ServiceJob implements IService |
||
53 | { |
||
54 | |||
55 | 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); |
||
56 | |||
1030 | jmachado | 57 | private static final int MAX_COMMIT = 10; |
995 | jmachado | 58 | |
59 | |||
60 | public ILogMessages run(1.5.0/docs/api/java/lang/String.html">String year,1.5.0/docs/api/java/lang/String.html">String semestre) throws ServiceException |
||
61 | { |
||
62 | return run(year,semestre,true,true); |
||
63 | } |
||
64 | |||
65 | public ILogMessages run(1.5.0/docs/api/java/lang/String.html">String year,1.5.0/docs/api/java/lang/String.html">String semestre,boolean sendIONLINE,boolean sendEMAIL) throws ServiceException |
||
66 | { |
||
67 | 1.5.0/docs/api/java/lang/String.html">String msgS = "STARTING SUMARIES IMPORT SERVICE FOR year: " + year + " semestre: " + semestre + " sendIONLINE: " + sendIONLINE + " sendEMAIL: " + sendEMAIL; |
||
68 | serviceLogInfo(msgS); |
||
69 | logger.info(msgS); |
||
70 | |||
71 | DefaultLogMessages logMessages = new DefaultLogMessages(); |
||
1017 | jmachado | 72 | logMessages.addMessage(new DefaultLogMessage("import.summaries", LogMessageTypeEnum.INFO, "instituicao " + DaoFactory.getConfigurationDaoImpl().getSigesInstitutionCode())); |
995 | jmachado | 73 | serviceLogInfo(logMessages.getLastMessage()); |
74 | |||
75 | |||
76 | int countUnits = 0; |
||
77 | int countUnitsOk = 0; |
||
78 | int countUnitsZeroSummaries = 0; |
||
1081 | jmachado | 79 | int countUnitsZeroValidSummaries = 0; |
995 | jmachado | 80 | |
81 | List<String> unitsZeroSummaries = new ArrayList<String>(); |
||
82 | List<String> unitsFailed = new ArrayList<String>(); |
||
83 | try |
||
84 | { |
||
85 | |||
1298 | jmachado | 86 | /* SiGesWEB service; |
1017 | jmachado | 87 | String WSDL = DaoFactory.getConfigurationDaoImpl().getSigesWebServicesWsdl(); |
995 | jmachado | 88 | try |
89 | { |
||
1017 | jmachado | 90 | serviceLogInfo("STARTING WEB SERVICE AT " + WSDL); |
91 | service = new SiGesWEB(new URL(WSDL), new QName(Globals.SIGES_WEBSERVICE_TARGET_NAMESPACE, "SiGesWEB")); |
||
995 | jmachado | 92 | } |
93 | catch (Throwable e) |
||
94 | { |
||
95 | logMessages.addMessage(new DefaultLogMessage("import.error",e.toString(),"erro na configuracao do WEB Service", LogMessageTypeEnum.INFO)); |
||
96 | serviceLogInfo(logMessages.getLastMessage()); |
||
97 | logger.fatal(e, e); |
||
98 | serviceLogError(e.toString(), e); |
||
99 | return logMessages; |
||
1298 | jmachado | 100 | }*/ |
995 | jmachado | 101 | |
102 | int i = 0; |
||
103 | //List<Long> cUs = DaoFactory.getCourseUnitDaoImpl().loadIds(year,DatesUtils.getSemestre()); |
||
104 | List<Long> cUs = DaoFactory.getCourseUnitDaoImpl().loadIds(year,semestre); |
||
105 | 1.5.0/docs/api/java/lang/String.html">String nowCode = ""; |
||
1267 | jmachado | 106 | 1.5.0/docs/api/java/sql/Connection.html">Connection conn = ConnectionManager.openConnection(); |
107 | boolean connError = false; |
||
995 | jmachado | 108 | for(1.5.0/docs/api/java/lang/Long.html">Long cId: cUs) |
109 | { |
||
1267 | jmachado | 110 | if(connError) |
111 | break; |
||
1144 | jmachado | 112 | nowCode = "" + cId; |
995 | jmachado | 113 | countUnits++; |
114 | try |
||
115 | { |
||
116 | if (i++ > MAX_COMMIT) |
||
117 | { |
||
118 | i = 0; |
||
996 | jmachado | 119 | setProgress((int) (((float)countUnits)/((float)cUs.size())*100.0f)); |
1076 | jmachado | 120 | commitPartially(); |
995 | jmachado | 121 | } |
122 | CourseUnit c = DaoFactory.getCourseUnitDaoImpl().load(cId); |
||
123 | nowCode = c.getCode(); |
||
124 | logMessages.addMessage(new DefaultLogMessage("import.info","Importing Summaries to CourseUnit: " + c.getCode() + ": course: " + c.getCourse().getCode(),"", LogMessageTypeEnum.INFO)); |
||
125 | logger.info("Importing Summaries to CourseUnit: " + c.getName() + " (" + c.getCode() + ") course " + c.getCourse().getName() + " (" + c.getCourse().getCode() + ")"); |
||
126 | serviceLogInfo(logMessages.getLastMessage()); |
||
127 | |||
128 | int tries = 3; |
||
1235 | jmachado | 129 | //ArrayOfAula arrayOfAulas = null; |
130 | ArrayList<pt.estgp.estgweb.services.sigesimports.oracle.domain.Aula> arrayOfAulas = null; |
||
995 | jmachado | 131 | while(tries > 0) |
132 | { |
||
133 | //comentario de teste |
||
134 | try |
||
135 | { |
||
1267 | jmachado | 136 | |
1235 | jmachado | 137 | //arrayOfAulas = service.getSiGesWEBSoap().getAulas(new BigDecimal(DaoFactory.getConfigurationDaoImpl().getSigesInstitutionCode()), year,c.getCode(),semestre,c.getCourse().getCode()); |
1267 | jmachado | 138 | arrayOfAulas = AulaDao.getInstance().loadAulas(DaoFactory.getConfigurationDaoImpl().getSigesInstitutionCode(),year,c.getCode(),semestre,c.getCourse().getCode(),conn); |
139 | |||
995 | jmachado | 140 | break; |
141 | } |
||
142 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable t) |
||
143 | { |
||
144 | if(tries-- == 0) |
||
145 | { |
||
146 | logger.error("Giving up of courseUnit:" + cId + " ( " + c.getName() + " ) ",t); |
||
147 | serviceLogError("Giving up of courseUnit:" + cId + " ( " + c.getName() + " ) ",t); |
||
1267 | jmachado | 148 | connError = true; |
995 | jmachado | 149 | break; |
150 | } |
||
151 | |||
1144 | jmachado | 152 | |
1267 | jmachado | 153 | logger.error("WebService Fail, trying " + tries + " times sleeping a while",t); |
1144 | jmachado | 154 | serviceLogError("WebService Fail, trying " + tries + " times sleeping a while " + t.toString()); |
155 | serviceLogError("WebService Fail, trying " + tries + " times sleeping a while " + t.getCause()); |
||
995 | jmachado | 156 | 1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(5000); |
157 | } |
||
158 | } |
||
159 | |||
1235 | jmachado | 160 | if(arrayOfAulas != null && arrayOfAulas.size() > 0) |
995 | jmachado | 161 | { |
162 | List<CourseUnitSummary> courseUnitSummaries = new ArrayList<CourseUnitSummary>(); |
||
163 | |||
164 | //HashMap<String, CourseUnitSummary> map = new HashMap<String, CourseUnitSummary>(); |
||
165 | /*if(c.getSummaries() != null && c.getSummaries().size() > 0) |
||
166 | for(CourseUnitSummary s: c.getSummaries()) |
||
167 | map.put(s.getCodigoAula() + ":" + s.getCodigoSumario(),s); |
||
168 | else |
||
169 | c.setSummaries(new HashSet<CourseUnitSummary>());*/ |
||
170 | JSONObject summariesJson = new JSONObject(); |
||
171 | JSONArray summaries = new JSONArray(); |
||
172 | summariesJson.put("summary",summaries); |
||
1081 | jmachado | 173 | int summariesValid = 0; |
1235 | jmachado | 174 | for(pt.estgp.estgweb.services.sigesimports.oracle.domain.Aula aula: arrayOfAulas) |
995 | jmachado | 175 | { |
176 | |||
1235 | jmachado | 177 | //todo cdTurma Rollback aqui não retirar o sumário |
178 | //Mas pensar em separar os sumários na página, podemos |
||
179 | //separar tendo em conta quem entra, se for aluno só vê os |
||
180 | //seus sumários, se for prof vê os sumários das suas turmas |
||
181 | |||
1248 | jmachado | 182 | /* |
1235 | jmachado | 183 | if(c.getCdTurma() != null && aula.getAula_codigoTurma()!=null |
1133 | jmachado | 184 | && c.getCdTurma().trim().length() > 0 |
1235 | jmachado | 185 | && aula.getAula_codigoTurma().trim().length() > 0 |
186 | && !aula.getAula_codigoTurma().equals(c.getCdTurma())) |
||
1133 | jmachado | 187 | { |
188 | //Código de Turma diferente |
||
1235 | jmachado | 189 | System.out.println("Ignoring summary code: " + aula.getAula_codigoTurma() + " for unit " + c.getName() + "/" + c.getCode() + " T:" + c.getCdTurma()); |
1133 | jmachado | 190 | continue; |
1248 | jmachado | 191 | }*/ |
1133 | jmachado | 192 | |
995 | jmachado | 193 | //CourseUnitSummary s = map.get(aula.getSumNumeroAula() + ":" + aula.getCodigoSumario()); |
194 | //if(s == null) |
||
195 | //{ |
||
196 | CourseUnitSummaryImpl s = DomainObjectFactory.createCourseUnitSummaryImpl(); |
||
197 | s.setCourseUnit(c); |
||
198 | //c.getSummaries().add(s); |
||
199 | //DaoFactory.getCourseUnitSummaryDaoImpl().save(s); |
||
200 | //summaries.add(); |
||
201 | //} |
||
1235 | jmachado | 202 | s.setCdTipoOcupacao(aula.getTipoOcupacao().intValue()); |
203 | s.setNrAula(aula.getNumeroAula().intValue()); |
||
995 | jmachado | 204 | s.setCodigoSumario(""+aula.getCodigoSumario().intValue()); |
1235 | jmachado | 205 | s.setCodigoAula("" + aula.getSum_numeroAula().intValue()); |
206 | s.setNumeroAula(aula.getSum_numeroAula().intValue()); |
||
207 | s.setDataAula(aula.getData()); |
||
208 | s.setTipoAula(aula.getSum_tipoAula()); |
||
209 | s.setCodigoSalaAula("" + aula.getAula_codigoSalaAula().intValue()); |
||
210 | s.setAlunosPresentes(aula.getSum_numeroPresencas().intValue()); |
||
211 | s.setTitulo(aula.getSum_titulo()); |
||
212 | s.setCodigoDocente(aula.getAula_codigoDocente()+ ""); |
||
213 | s.setDescricao(aula.getSum_descricao()); |
||
214 | s.setcEstado(""+aula.getSum_cdEstado().intValue()); |
||
995 | jmachado | 215 | s.setNumeroHoras("" + aula.getNumeroCelulas().intValue()); |
216 | summaries.put(s.getJson()); |
||
217 | courseUnitSummaries.add(s); |
||
1081 | jmachado | 218 | if(s.getNumeroAula() > 0) |
219 | summariesValid++; |
||
995 | jmachado | 220 | } |
221 | if(courseUnitSummaries.size() == 0) |
||
222 | { |
||
223 | countUnitsZeroSummaries++; |
||
224 | unitsZeroSummaries.add(c.getCode()); |
||
1081 | jmachado | 225 | logger.info("ZERO SUMARIES unit:" + c.getCode() + " course: " + c.getCourseCode()); |
226 | serviceLogInfo("ZERO SUMARIES unit:" + c.getCode() + " course: " + c.getCourseCode()); |
||
995 | jmachado | 227 | } |
1081 | jmachado | 228 | else if(summariesValid == 0) |
229 | { |
||
1144 | jmachado | 230 | //NAO METE OK NEM ZERO |
1081 | jmachado | 231 | countUnitsZeroValidSummaries++; |
232 | unitsZeroSummaries.add(c.getCode()); |
||
233 | logger.info("ZERO VALID SUMARIES unit:" + c.getCode() + " course: " + c.getCourseCode()); |
||
234 | serviceLogInfo("ZERO VALID SUMARIES unit:" + c.getCode() + " course: " + c.getCourseCode()); |
||
235 | } |
||
995 | jmachado | 236 | else |
237 | { |
||
238 | countUnitsOk++; |
||
239 | } |
||
240 | c.setSummariesJson(summariesJson.toString()); |
||
241 | |||
242 | if(sendIONLINE) |
||
243 | { |
||
244 | 1.5.0/docs/api/java/lang/String.html">String path = generatePdf(c); |
||
245 | sendPdfFtpIonline(c,new ArrayList<String>(),null,path,null); |
||
1268 | jmachado | 246 | try{ |
247 | FilesUtils.delete(path); |
||
248 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
249 | { |
||
250 | logger.error("trying to delete " + path,e); |
||
251 | } |
||
995 | jmachado | 252 | } |
253 | if(sendEMAIL) |
||
254 | { |
||
255 | sendEmail(null, courseUnitSummaries,true); |
||
256 | } |
||
257 | } |
||
258 | else |
||
259 | { |
||
1144 | jmachado | 260 | //NAO METE OK MAS METE ZERO |
995 | jmachado | 261 | countUnitsZeroSummaries++; |
262 | unitsZeroSummaries.add(c.getCode()); |
||
263 | logger.error("Summaries come null in unit:" + c.getCode()); |
||
264 | serviceLogError("Summaries come null in unit:" + c.getCode()); |
||
265 | } |
||
266 | } |
||
267 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
268 | { |
||
1144 | jmachado | 269 | //NAO METE OK |
995 | jmachado | 270 | unitsFailed.add(nowCode); |
271 | logger.error(e,e); |
||
272 | serviceLogError(e.toString(),e); |
||
273 | } |
||
274 | } |
||
1267 | jmachado | 275 | conn.close(); |
995 | jmachado | 276 | |
277 | setProgress(100); |
||
278 | serviceLogError("Finish commiting"); |
||
279 | |||
280 | } |
||
281 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
282 | { |
||
283 | logger.error(e, e); |
||
284 | logMessages.addMessage(new DefaultLogMessage("import.error", e.toString(), "see log for details", LogMessageTypeEnum.ERROR)); |
||
285 | serviceLogError(logMessages.getLastMessage(),e); |
||
286 | throw new ServiceException(e.toString(), e); |
||
287 | } |
||
288 | |||
289 | logMessages.addMessage(new DefaultLogMessage("import.summaries.terminating", LogMessageTypeEnum.INFO)); |
||
290 | logger.info("terminating summaries import"); |
||
291 | serviceLogInfo(logMessages.getLastMessage()); |
||
292 | |||
1144 | jmachado | 293 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder failedUnitsExc = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
294 | for(1.5.0/docs/api/java/lang/String.html">String cId: unitsFailed) |
||
295 | failedUnitsExc.append(cId).append(";"); |
||
1145 | jmachado | 296 | |
995 | jmachado | 297 | serviceLogInfo("#######################################"); |
298 | serviceLogInfo("#######################################"); |
||
299 | serviceLogInfo("UNITS PROCESSED: " + countUnits); |
||
1144 | jmachado | 300 | serviceLogInfo("UNITS FAILED: " + (countUnits - countUnitsZeroSummaries - countUnitsOk - countUnitsZeroValidSummaries)); |
301 | serviceLogInfo("UNITS FAILED EXCEPTION PARSING XML WEB SERVICE: " + unitsFailed.size()); |
||
995 | jmachado | 302 | serviceLogInfo("UNITS IMPORT OK: " + countUnitsOk); |
303 | serviceLogInfo("UNITS ZERO SUMARIES: " + countUnitsZeroSummaries); |
||
1081 | jmachado | 304 | serviceLogInfo("UNITS ZERO VALID SUMARIES: " + countUnitsZeroValidSummaries); |
995 | jmachado | 305 | serviceLogInfo("#######################################"); |
1144 | jmachado | 306 | serviceLogWarn("####FAILED Exception (Check exceptions in log): Units Baco Id Code : " + failedUnitsExc.toString()); |
1025 | jmachado | 307 | |
308 | logger.info("#######################################"); |
||
309 | logger.info("#######################################"); |
||
310 | logger.info("UNITS PROCESSED: " + countUnits); |
||
1144 | jmachado | 311 | logger.info("UNITS FAILED: " + (countUnits - countUnitsZeroSummaries - countUnitsOk - countUnitsZeroValidSummaries)); |
312 | logger.info("UNITS FAILED EXCEPTION PARSING XML WEB SERVICE: " + unitsFailed.size()); |
||
1025 | jmachado | 313 | logger.info("UNITS IMPORT OK: " + countUnitsOk); |
314 | logger.info("UNITS ZERO SUMARIES: " + countUnitsZeroSummaries); |
||
1081 | jmachado | 315 | logger.info("UNITS ZERO VALID SUMARIES: " + countUnitsZeroValidSummaries); |
1025 | jmachado | 316 | logger.info("#######################################"); |
1144 | jmachado | 317 | logger.warn("####FAILED Exception (Check exceptions in log): Units Baco Id Code : " + failedUnitsExc.toString()); |
318 | |||
319 | |||
995 | jmachado | 320 | return logMessages; |
321 | } |
||
322 | |||
323 | |||
324 | public static SendEmailService sendEmailService = new SendEmailService(); |
||
325 | |||
326 | private void sendEmail(UserSession userSession,List<CourseUnitSummary> summaries,boolean sendEmail) |
||
327 | { |
||
328 | if(Globals.EMAIL_SUMMARIES && summaries.size() > 0 && sendEmail) |
||
329 | { |
||
330 | // for(CourseUnitSummary summary: summaries) |
||
331 | // { |
||
332 | |||
333 | List<String> emails = DaoFactory.getCourseUnitSummaryDaoImpl().getStudentsEmails(summaries.get(0).getId()); |
||
334 | if(emails == null) |
||
335 | logger.warn("No students emails in unit: code:" + summaries.get(0).getCourseUnit().getCode() + " " + summaries.get(0).getCourseUnit().getName()); |
||
336 | EMAILJob emailJob = new EMAILJob(sendEmailService.getSummariesEmail(emails, summaries, summaries.get(0).getCourseUnit(), LangEnum.PORTUGUESE)); |
||
337 | JobScheduleService.getInstance().scheduleNow(emailJob,"New Summary EMAIL from: " + summaries.get(0).getCourseUnit().getName() + " aula: " +summaries.get(summaries.size()-1).getNumeroAula() ,userSession); |
||
338 | // } |
||
339 | } |
||
340 | } |
||
341 | |||
342 | |||
343 | |||
344 | |||
345 | |||
346 | |||
347 | 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 { |
||
348 | 5+0%2Fdocs%2Fapi+Document">Document dom = new CreateCourseUnitXML().run(c,null); |
||
349 | org.w3c.dom.5+0%2Fdocs%2Fapi+Document">Document dd = Dom4jUtil.toW3c(dom); |
||
350 | 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"; |
||
351 | 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream out = new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(path); |
||
352 | Map<String,Object> params = new HashMap<String,Object>(); |
||
353 | params.put("site", Globals.SITE_URL); |
||
354 | 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); |
||
355 | out.flush(); |
||
356 | out.close(); |
||
357 | return path; |
||
358 | } |
||
359 | |||
1006 | jmachado | 360 | 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 | 361 | |
362 | FtpServer server = null; |
||
363 | if(client == null) |
||
364 | { |
||
365 | server = FtpServer.getNewServer(Globals.FTP_IONLINE_URL,Globals.FTP_IONLINE_USER,Globals.FTP_IONLINE_PASS); |
||
366 | client = server.getClient(); |
||
1005 | jmachado | 367 | if(client == null) |
368 | { |
||
369 | logger.warn("###################"); |
||
1009 | jmachado | 370 | logger.warn("################### > CANT CONNECT FTP - could be FTPTimeout: " + Globals.FTP_TIMEOUT_SECONDS); |
371 | errors.add("################### > CANT CONNECT FTP to send summaries " + ((CourseUnitImpl)cu).getSummariosPathIntranet()); |
||
1005 | jmachado | 372 | return; |
373 | } |
||
374 | |||
995 | jmachado | 375 | } |
376 | client.setFileType(FTP.BINARY_FILE_TYPE); |
||
377 | |||
378 | |||
379 | 1.5.0/docs/api/java/lang/String.html">String pastaFichaCurricular = ((CourseUnitImpl)cu).getSummariosPathIntranet(); |
||
380 | if(!client.changeWorkingDirectory(pastaFichaCurricular)) |
||
381 | { |
||
382 | logger.error("FTP CANT CHANGE TO PATH: " + pastaFichaCurricular); |
||
383 | } |
||
384 | else |
||
385 | { |
||
1009 | jmachado | 386 | if(!client.storeFile(((CourseUnitImpl)cu).getSummariosFileNameIntranet(),new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(pdfPath))) |
387 | { |
||
1010 | jmachado | 388 | 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; |
389 | logger.error(msgS); |
||
390 | serviceLogError(msgS); |
||
1009 | jmachado | 391 | } |
995 | jmachado | 392 | if(server != null) |
393 | { |
||
394 | client.quit(); |
||
395 | client.disconnect(); |
||
396 | } |
||
397 | } |
||
398 | // |
||
399 | } |
||
400 | /** |
||
401 | * Testar por aqui poi requer Super Role e assim e' autmatico |
||
402 | * |
||
403 | * |
||
404 | * @param args of main |
||
405 | * @throws pt.estgp.estgweb.services.expceptions.ServiceException on error |
||
406 | */ |
||
407 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException, JSONException { |
||
408 | |||
997 | jmachado | 409 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Syntax:"); |
410 | 1.5.0/docs/api/java/lang/System.html">System.out.println("year, semestre, sendIonline, sendEmail"); |
||
411 | 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"); |
||
412 | |||
995 | jmachado | 413 | 1.5.0/docs/api/java/lang/String.html">String year = DaoFactory.getConfigurationDaoImpl().getImportsDefaultImportYearCreateTransaction(); |
414 | 1.5.0/docs/api/java/lang/String.html">String semestre = null; |
||
1133 | jmachado | 415 | boolean sendIonline = false; |
416 | boolean sendEmail = false; |
||
995 | jmachado | 417 | if(args != null && args.length > 0) |
418 | year = args[0]; |
||
997 | jmachado | 419 | |
995 | jmachado | 420 | if(args != null && args.length > 1) |
421 | semestre = args[1]; |
||
997 | jmachado | 422 | |
995 | jmachado | 423 | if(args != null && args.length > 2) |
424 | sendIonline = 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(args[2]); |
||
997 | jmachado | 425 | |
995 | jmachado | 426 | if(args != null && args.length > 3) |
427 | sendEmail = 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(args[3]); |
||
997 | jmachado | 428 | |
995 | jmachado | 429 | AbstractDao.getCurrentSession().beginTransaction(); |
430 | if(semestre != null) |
||
431 | new ImportSumariesJson().run(year,semestre,sendIonline,sendEmail); |
||
432 | else |
||
433 | { |
||
434 | new ImportSumariesJson().run(year,"S1",sendIonline,sendEmail); |
||
435 | new ImportSumariesJson().run(year,"S2",sendIonline,sendEmail); |
||
436 | new ImportSumariesJson().run(year,"A",sendIonline,sendEmail); |
||
437 | } |
||
438 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
439 | } |
||
440 | |||
441 | |||
442 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
1070 | jmachado | 443 | protected ILogMessages runJobServiceTask() throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
995 | jmachado | 444 | |
1070 | jmachado | 445 | 1.5.0/docs/api/java/lang/String.html">String importYear = getParametersMap().get(JOB_importYear_KEY).getObject(); |
446 | 1.5.0/docs/api/java/lang/String.html">String semestre = getParametersMap().get(JOB_semestre_KEY).getObject(); |
||
447 | 1.5.0/docs/api/java/lang/String.html">String sendIonlineStr = getParametersMap().get(JOB_sendIonline_KEY).getObject(); |
||
448 | 1.5.0/docs/api/java/lang/String.html">String sendEmailStr = getParametersMap().get(JOB_sendEmail_KEY).getObject(); |
||
449 | boolean sendIonline = sendIonlineStr != null && 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(sendIonlineStr); |
||
450 | boolean sendEmail = sendEmailStr != null && 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(sendEmailStr); |
||
451 | return run(importYear,semestre,sendIonline,sendEmail); |
||
995 | jmachado | 452 | } |
453 | |||
454 | } |