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