Rev 1310 | Rev 1353 | 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; |
1312 | jmachado | 30 | import pt.estgp.estgweb.utils.ConfigProperties; |
995 | jmachado | 31 | import pt.estgp.estgweb.utils.Dom4jUtil; |
32 | import pt.estgp.estgweb.web.FtpServer; |
||
33 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
34 | |||
35 | import javax.xml.transform.TransformerException; |
||
36 | import javax.xml.transform.dom.DOMSource; |
||
37 | import java.io.File; |
||
38 | import java.io.FileInputStream; |
||
39 | import java.io.FileOutputStream; |
||
40 | import java.io.IOException; |
||
1267 | jmachado | 41 | import java.sql.Connection; |
995 | jmachado | 42 | import java.util.ArrayList; |
43 | import java.util.HashMap; |
||
44 | import java.util.List; |
||
45 | import java.util.Map; |
||
46 | |||
47 | /** |
||
48 | * @author Jorge Machado |
||
49 | * @date 11/May/2008 |
||
50 | * @time 12:51:32 |
||
51 | * @see pt.estgp.estgweb |
||
52 | */ |
||
53 | public class ImportSumariesJson extends ServiceJob implements IService |
||
54 | { |
||
55 | |||
56 | 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); |
||
57 | |||
1030 | jmachado | 58 | private static final int MAX_COMMIT = 10; |
995 | jmachado | 59 | |
60 | |||
1312 | jmachado | 61 | 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 | 62 | { |
1312 | jmachado | 63 | return run(year,institutionCode,semestre,true,true); |
995 | jmachado | 64 | } |
65 | |||
1312 | jmachado | 66 | 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 | 67 | { |
68 | 1.5.0/docs/api/java/lang/String.html">String msgS = "STARTING SUMARIES IMPORT SERVICE FOR year: " + year + " semestre: " + semestre + " sendIONLINE: " + sendIONLINE + " sendEMAIL: " + sendEMAIL; |
||
69 | serviceLogInfo(msgS); |
||
70 | logger.info(msgS); |
||
71 | |||
72 | DefaultLogMessages logMessages = new DefaultLogMessages(); |
||
1312 | jmachado | 73 | logMessages.addMessage(new DefaultLogMessage("import.summaries", LogMessageTypeEnum.INFO, "instituicao " + institutionCode)); |
995 | jmachado | 74 | serviceLogInfo(logMessages.getLastMessage()); |
75 | |||
76 | |||
77 | int countUnits = 0; |
||
78 | int countUnitsOk = 0; |
||
79 | int countUnitsZeroSummaries = 0; |
||
1081 | jmachado | 80 | int countUnitsZeroValidSummaries = 0; |
995 | jmachado | 81 | |
82 | List<String> unitsZeroSummaries = new ArrayList<String>(); |
||
83 | List<String> unitsFailed = new ArrayList<String>(); |
||
84 | try |
||
85 | { |
||
86 | |||
1298 | jmachado | 87 | /* SiGesWEB service; |
1017 | jmachado | 88 | String WSDL = DaoFactory.getConfigurationDaoImpl().getSigesWebServicesWsdl(); |
995 | jmachado | 89 | try |
90 | { |
||
1017 | jmachado | 91 | serviceLogInfo("STARTING WEB SERVICE AT " + WSDL); |
92 | service = new SiGesWEB(new URL(WSDL), new QName(Globals.SIGES_WEBSERVICE_TARGET_NAMESPACE, "SiGesWEB")); |
||
995 | jmachado | 93 | } |
94 | catch (Throwable e) |
||
95 | { |
||
96 | logMessages.addMessage(new DefaultLogMessage("import.error",e.toString(),"erro na configuracao do WEB Service", LogMessageTypeEnum.INFO)); |
||
97 | serviceLogInfo(logMessages.getLastMessage()); |
||
98 | logger.fatal(e, e); |
||
99 | serviceLogError(e.toString(), e); |
||
100 | return logMessages; |
||
1298 | jmachado | 101 | }*/ |
995 | jmachado | 102 | |
103 | int i = 0; |
||
104 | //List<Long> cUs = DaoFactory.getCourseUnitDaoImpl().loadIds(year,DatesUtils.getSemestre()); |
||
105 | List<Long> cUs = DaoFactory.getCourseUnitDaoImpl().loadIds(year,semestre); |
||
106 | 1.5.0/docs/api/java/lang/String.html">String nowCode = ""; |
||
1267 | jmachado | 107 | 1.5.0/docs/api/java/sql/Connection.html">Connection conn = ConnectionManager.openConnection(); |
108 | boolean connError = false; |
||
995 | jmachado | 109 | for(1.5.0/docs/api/java/lang/Long.html">Long cId: cUs) |
110 | { |
||
1267 | jmachado | 111 | if(connError) |
112 | break; |
||
1144 | jmachado | 113 | nowCode = "" + cId; |
995 | jmachado | 114 | countUnits++; |
115 | try |
||
116 | { |
||
117 | if (i++ > MAX_COMMIT) |
||
118 | { |
||
119 | i = 0; |
||
996 | jmachado | 120 | setProgress((int) (((float)countUnits)/((float)cUs.size())*100.0f)); |
1312 | jmachado | 121 | conn.close(); |
1076 | jmachado | 122 | commitPartially(); |
1312 | jmachado | 123 | conn = ConnectionManager.openConnection(); |
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()); |
1312 | jmachado | 141 | arrayOfAulas = AulaDao.getInstance().loadAulas(institutionCode,year,c.getCode(),semestre,c.getCourse().getCode(),conn); |
1267 | jmachado | 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 | |
1312 | jmachado | 365 | if(ConfigProperties.getBooleanProperty("test.control.var")) |
366 | { |
||
367 | 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"; |
||
368 | logger.warn(warn); |
||
369 | return; |
||
370 | } |
||
995 | jmachado | 371 | FtpServer server = null; |
372 | if(client == null) |
||
373 | { |
||
374 | server = FtpServer.getNewServer(Globals.FTP_IONLINE_URL,Globals.FTP_IONLINE_USER,Globals.FTP_IONLINE_PASS); |
||
375 | client = server.getClient(); |
||
1005 | jmachado | 376 | if(client == null) |
377 | { |
||
378 | logger.warn("###################"); |
||
1009 | jmachado | 379 | logger.warn("################### > CANT CONNECT FTP - could be FTPTimeout: " + Globals.FTP_TIMEOUT_SECONDS); |
380 | errors.add("################### > CANT CONNECT FTP to send summaries " + ((CourseUnitImpl)cu).getSummariosPathIntranet()); |
||
1005 | jmachado | 381 | return; |
382 | } |
||
383 | |||
995 | jmachado | 384 | } |
385 | client.setFileType(FTP.BINARY_FILE_TYPE); |
||
386 | |||
387 | |||
388 | 1.5.0/docs/api/java/lang/String.html">String pastaFichaCurricular = ((CourseUnitImpl)cu).getSummariosPathIntranet(); |
||
389 | if(!client.changeWorkingDirectory(pastaFichaCurricular)) |
||
390 | { |
||
391 | logger.error("FTP CANT CHANGE TO PATH: " + pastaFichaCurricular); |
||
392 | } |
||
393 | else |
||
394 | { |
||
1009 | jmachado | 395 | if(!client.storeFile(((CourseUnitImpl)cu).getSummariosFileNameIntranet(),new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(pdfPath))) |
396 | { |
||
1010 | jmachado | 397 | 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; |
398 | logger.error(msgS); |
||
399 | serviceLogError(msgS); |
||
1009 | jmachado | 400 | } |
995 | jmachado | 401 | if(server != null) |
402 | { |
||
403 | client.quit(); |
||
404 | client.disconnect(); |
||
405 | } |
||
406 | } |
||
407 | // |
||
408 | } |
||
409 | /** |
||
410 | * Testar por aqui poi requer Super Role e assim e' autmatico |
||
411 | * |
||
412 | * |
||
413 | * @param args of main |
||
414 | * @throws pt.estgp.estgweb.services.expceptions.ServiceException on error |
||
415 | */ |
||
416 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException, JSONException { |
||
417 | |||
997 | jmachado | 418 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Syntax:"); |
419 | 1.5.0/docs/api/java/lang/System.html">System.out.println("year, semestre, sendIonline, sendEmail"); |
||
420 | 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"); |
||
421 | |||
995 | jmachado | 422 | 1.5.0/docs/api/java/lang/String.html">String year = DaoFactory.getConfigurationDaoImpl().getImportsDefaultImportYearCreateTransaction(); |
423 | 1.5.0/docs/api/java/lang/String.html">String semestre = null; |
||
1133 | jmachado | 424 | boolean sendIonline = false; |
425 | boolean sendEmail = false; |
||
1312 | jmachado | 426 | int institutionCode = 1; |
995 | jmachado | 427 | if(args != null && args.length > 0) |
428 | year = args[0]; |
||
997 | jmachado | 429 | |
995 | jmachado | 430 | if(args != null && args.length > 1) |
431 | semestre = args[1]; |
||
997 | jmachado | 432 | |
995 | jmachado | 433 | if(args != null && args.length > 2) |
434 | sendIonline = 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(args[2]); |
||
997 | jmachado | 435 | |
995 | jmachado | 436 | if(args != null && args.length > 3) |
437 | sendEmail = 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(args[3]); |
||
997 | jmachado | 438 | |
1312 | jmachado | 439 | if(args != null && args.length > 4) |
440 | institutionCode = 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(args[4]); |
||
441 | |||
995 | jmachado | 442 | AbstractDao.getCurrentSession().beginTransaction(); |
443 | if(semestre != null) |
||
1312 | jmachado | 444 | new ImportSumariesJson().run(year,institutionCode,semestre,sendIonline,sendEmail); |
995 | jmachado | 445 | else |
446 | { |
||
1312 | jmachado | 447 | new ImportSumariesJson().run(year,institutionCode,"S1",sendIonline,sendEmail); |
448 | new ImportSumariesJson().run(year,institutionCode,"S2",sendIonline,sendEmail); |
||
449 | new ImportSumariesJson().run(year,institutionCode,"A",sendIonline,sendEmail); |
||
995 | jmachado | 450 | } |
451 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
452 | } |
||
453 | |||
454 | |||
455 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
1070 | jmachado | 456 | protected ILogMessages runJobServiceTask() throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
995 | jmachado | 457 | |
1070 | jmachado | 458 | 1.5.0/docs/api/java/lang/String.html">String importYear = getParametersMap().get(JOB_importYear_KEY).getObject(); |
459 | 1.5.0/docs/api/java/lang/String.html">String semestre = getParametersMap().get(JOB_semestre_KEY).getObject(); |
||
460 | 1.5.0/docs/api/java/lang/String.html">String sendIonlineStr = getParametersMap().get(JOB_sendIonline_KEY).getObject(); |
||
461 | 1.5.0/docs/api/java/lang/String.html">String sendEmailStr = getParametersMap().get(JOB_sendEmail_KEY).getObject(); |
||
1312 | jmachado | 462 | 1.5.0/docs/api/java/lang/String.html">String institutionCode = getParametersMap().get(JOB_institution_KEY).getObject(); |
1070 | jmachado | 463 | boolean sendIonline = sendIonlineStr != null && 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(sendIonlineStr); |
464 | boolean sendEmail = sendEmailStr != null && 1.5.0/docs/api/java/lang/Boolean.html">Boolean.parseBoolean(sendEmailStr); |
||
1312 | jmachado | 465 | return run(importYear,1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(institutionCode),semestre,sendIonline,sendEmail); |
995 | jmachado | 466 | } |
467 | |||
468 | } |