Rev 1248 | Rev 1268 | 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); |
||
249 | FilesUtils.delete(path); |
||
250 | } |
||
251 | if(sendEMAIL) |
||
252 | { |
||
253 | sendEmail(null, courseUnitSummaries,true); |
||
254 | } |
||
255 | } |
||
256 | else |
||
257 | { |
||
1144 | jmachado | 258 | //NAO METE OK MAS METE ZERO |
995 | jmachado | 259 | countUnitsZeroSummaries++; |
260 | unitsZeroSummaries.add(c.getCode()); |
||
261 | logger.error("Summaries come null in unit:" + c.getCode()); |
||
262 | serviceLogError("Summaries come null in unit:" + c.getCode()); |
||
263 | } |
||
264 | } |
||
265 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
266 | { |
||
1144 | jmachado | 267 | //NAO METE OK |
995 | jmachado | 268 | unitsFailed.add(nowCode); |
269 | logger.error(e,e); |
||
270 | serviceLogError(e.toString(),e); |
||
271 | } |
||
272 | } |
||
1267 | jmachado | 273 | conn.close(); |
995 | jmachado | 274 | |
275 | setProgress(100); |
||
276 | serviceLogError("Finish commiting"); |
||
277 | |||
278 | } |
||
279 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
280 | { |
||
281 | logger.error(e, e); |
||
282 | logMessages.addMessage(new DefaultLogMessage("import.error", e.toString(), "see log for details", LogMessageTypeEnum.ERROR)); |
||
283 | serviceLogError(logMessages.getLastMessage(),e); |
||
284 | throw new ServiceException(e.toString(), e); |
||
285 | } |
||
286 | |||
287 | logMessages.addMessage(new DefaultLogMessage("import.summaries.terminating", LogMessageTypeEnum.INFO)); |
||
288 | logger.info("terminating summaries import"); |
||
289 | serviceLogInfo(logMessages.getLastMessage()); |
||
290 | |||
1144 | jmachado | 291 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder failedUnitsExc = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
292 | for(1.5.0/docs/api/java/lang/String.html">String cId: unitsFailed) |
||
293 | failedUnitsExc.append(cId).append(";"); |
||
1145 | jmachado | 294 | |
995 | jmachado | 295 | serviceLogInfo("#######################################"); |
296 | serviceLogInfo("#######################################"); |
||
297 | serviceLogInfo("UNITS PROCESSED: " + countUnits); |
||
1144 | jmachado | 298 | serviceLogInfo("UNITS FAILED: " + (countUnits - countUnitsZeroSummaries - countUnitsOk - countUnitsZeroValidSummaries)); |
299 | serviceLogInfo("UNITS FAILED EXCEPTION PARSING XML WEB SERVICE: " + unitsFailed.size()); |
||
995 | jmachado | 300 | serviceLogInfo("UNITS IMPORT OK: " + countUnitsOk); |
301 | serviceLogInfo("UNITS ZERO SUMARIES: " + countUnitsZeroSummaries); |
||
1081 | jmachado | 302 | serviceLogInfo("UNITS ZERO VALID SUMARIES: " + countUnitsZeroValidSummaries); |
995 | jmachado | 303 | serviceLogInfo("#######################################"); |
1144 | jmachado | 304 | serviceLogWarn("####FAILED Exception (Check exceptions in log): Units Baco Id Code : " + failedUnitsExc.toString()); |
1025 | jmachado | 305 | |
306 | logger.info("#######################################"); |
||
307 | logger.info("#######################################"); |
||
308 | logger.info("UNITS PROCESSED: " + countUnits); |
||
1144 | jmachado | 309 | logger.info("UNITS FAILED: " + (countUnits - countUnitsZeroSummaries - countUnitsOk - countUnitsZeroValidSummaries)); |
310 | logger.info("UNITS FAILED EXCEPTION PARSING XML WEB SERVICE: " + unitsFailed.size()); |
||
1025 | jmachado | 311 | logger.info("UNITS IMPORT OK: " + countUnitsOk); |
312 | logger.info("UNITS ZERO SUMARIES: " + countUnitsZeroSummaries); |
||
1081 | jmachado | 313 | logger.info("UNITS ZERO VALID SUMARIES: " + countUnitsZeroValidSummaries); |
1025 | jmachado | 314 | logger.info("#######################################"); |
1144 | jmachado | 315 | logger.warn("####FAILED Exception (Check exceptions in log): Units Baco Id Code : " + failedUnitsExc.toString()); |
316 | |||
317 | |||
995 | jmachado | 318 | return logMessages; |
319 | } |
||
320 | |||
321 | |||
322 | public static SendEmailService sendEmailService = new SendEmailService(); |
||
323 | |||
324 | private void sendEmail(UserSession userSession,List<CourseUnitSummary> summaries,boolean sendEmail) |
||
325 | { |
||
326 | if(Globals.EMAIL_SUMMARIES && summaries.size() > 0 && sendEmail) |
||
327 | { |
||
328 | // for(CourseUnitSummary summary: summaries) |
||
329 | // { |
||
330 | |||
331 | List<String> emails = DaoFactory.getCourseUnitSummaryDaoImpl().getStudentsEmails(summaries.get(0).getId()); |
||
332 | if(emails == null) |
||
333 | logger.warn("No students emails in unit: code:" + summaries.get(0).getCourseUnit().getCode() + " " + summaries.get(0).getCourseUnit().getName()); |
||
334 | EMAILJob emailJob = new EMAILJob(sendEmailService.getSummariesEmail(emails, summaries, summaries.get(0).getCourseUnit(), LangEnum.PORTUGUESE)); |
||
335 | JobScheduleService.getInstance().scheduleNow(emailJob,"New Summary EMAIL from: " + summaries.get(0).getCourseUnit().getName() + " aula: " +summaries.get(summaries.size()-1).getNumeroAula() ,userSession); |
||
336 | // } |
||
337 | } |
||
338 | } |
||
339 | |||
340 | |||
341 | |||
342 | |||
343 | |||
344 | |||
345 | 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 { |
||
346 | 5+0%2Fdocs%2Fapi+Document">Document dom = new CreateCourseUnitXML().run(c,null); |
||
347 | org.w3c.dom.5+0%2Fdocs%2Fapi+Document">Document dd = Dom4jUtil.toW3c(dom); |
||
348 | 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"; |
||
349 | 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream out = new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(path); |
||
350 | Map<String,Object> params = new HashMap<String,Object>(); |
||
351 | params.put("site", Globals.SITE_URL); |
||
352 | 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); |
||
353 | out.flush(); |
||
354 | out.close(); |
||
355 | return path; |
||
356 | } |
||
357 | |||
1006 | jmachado | 358 | 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 | 359 | |
360 | FtpServer server = null; |
||
361 | if(client == null) |
||
362 | { |
||
363 | server = FtpServer.getNewServer(Globals.FTP_IONLINE_URL,Globals.FTP_IONLINE_USER,Globals.FTP_IONLINE_PASS); |
||
364 | client = server.getClient(); |
||
1005 | jmachado | 365 | if(client == null) |
366 | { |
||
367 | logger.warn("###################"); |
||
1009 | jmachado | 368 | logger.warn("################### > CANT CONNECT FTP - could be FTPTimeout: " + Globals.FTP_TIMEOUT_SECONDS); |
369 | errors.add("################### > CANT CONNECT FTP to send summaries " + ((CourseUnitImpl)cu).getSummariosPathIntranet()); |
||
1005 | jmachado | 370 | return; |
371 | } |
||
372 | |||
995 | jmachado | 373 | } |
374 | client.setFileType(FTP.BINARY_FILE_TYPE); |
||
375 | |||
376 | |||
377 | 1.5.0/docs/api/java/lang/String.html">String pastaFichaCurricular = ((CourseUnitImpl)cu).getSummariosPathIntranet(); |
||
378 | if(!client.changeWorkingDirectory(pastaFichaCurricular)) |
||
379 | { |
||
380 | logger.error("FTP CANT CHANGE TO PATH: " + pastaFichaCurricular); |
||
381 | } |
||
382 | else |
||
383 | { |
||
1009 | jmachado | 384 | if(!client.storeFile(((CourseUnitImpl)cu).getSummariosFileNameIntranet(),new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(pdfPath))) |
385 | { |
||
1010 | jmachado | 386 | 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; |
387 | logger.error(msgS); |
||
388 | serviceLogError(msgS); |
||
1009 | jmachado | 389 | } |
995 | jmachado | 390 | if(server != null) |
391 | { |
||
392 | client.quit(); |
||
393 | client.disconnect(); |
||
394 | } |
||
395 | } |
||
396 | // |
||
397 | } |
||
398 | /** |
||
399 | * Testar por aqui poi requer Super Role e assim e' autmatico |
||
400 | * |
||
401 | * |
||
402 | * @param args of main |
||
403 | * @throws pt.estgp.estgweb.services.expceptions.ServiceException on error |
||
404 | */ |
||
405 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException, JSONException { |
||
406 | |||
997 | jmachado | 407 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Syntax:"); |
408 | 1.5.0/docs/api/java/lang/System.html">System.out.println("year, semestre, sendIonline, sendEmail"); |
||
409 | 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"); |
||
410 | |||
995 | jmachado | 411 | 1.5.0/docs/api/java/lang/String.html">String year = DaoFactory.getConfigurationDaoImpl().getImportsDefaultImportYearCreateTransaction(); |
412 | 1.5.0/docs/api/java/lang/String.html">String semestre = null; |
||
1133 | jmachado | 413 | boolean sendIonline = false; |
414 | boolean sendEmail = false; |
||
995 | jmachado | 415 | if(args != null && args.length > 0) |
416 | year = args[0]; |
||
997 | jmachado | 417 | |
995 | jmachado | 418 | if(args != null && args.length > 1) |
419 | semestre = args[1]; |
||
997 | jmachado | 420 | |
995 | jmachado | 421 | if(args != null && args.length > 2) |
422 | sendIonline = 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(args[2]); |
||
997 | jmachado | 423 | |
995 | jmachado | 424 | if(args != null && args.length > 3) |
425 | sendEmail = 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(args[3]); |
||
997 | jmachado | 426 | |
995 | jmachado | 427 | AbstractDao.getCurrentSession().beginTransaction(); |
428 | if(semestre != null) |
||
429 | new ImportSumariesJson().run(year,semestre,sendIonline,sendEmail); |
||
430 | else |
||
431 | { |
||
432 | new ImportSumariesJson().run(year,"S1",sendIonline,sendEmail); |
||
433 | new ImportSumariesJson().run(year,"S2",sendIonline,sendEmail); |
||
434 | new ImportSumariesJson().run(year,"A",sendIonline,sendEmail); |
||
435 | } |
||
436 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
437 | } |
||
438 | |||
439 | |||
440 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
1070 | jmachado | 441 | protected ILogMessages runJobServiceTask() throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
995 | jmachado | 442 | |
1070 | jmachado | 443 | 1.5.0/docs/api/java/lang/String.html">String importYear = getParametersMap().get(JOB_importYear_KEY).getObject(); |
444 | 1.5.0/docs/api/java/lang/String.html">String semestre = getParametersMap().get(JOB_semestre_KEY).getObject(); |
||
445 | 1.5.0/docs/api/java/lang/String.html">String sendIonlineStr = getParametersMap().get(JOB_sendIonline_KEY).getObject(); |
||
446 | 1.5.0/docs/api/java/lang/String.html">String sendEmailStr = getParametersMap().get(JOB_sendEmail_KEY).getObject(); |
||
447 | boolean sendIonline = sendIonlineStr != null && 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(sendIonlineStr); |
||
448 | boolean sendEmail = sendEmailStr != null && 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(sendEmailStr); |
||
449 | return run(importYear,semestre,sendIonline,sendEmail); |
||
995 | jmachado | 450 | } |
451 | |||
452 | } |