Rev 1801 | Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
203 | jmachado | 1 | package pt.estgp.estgweb.services.courseunits; |
2 | |||
915 | jmachado | 3 | import jomm.dao.impl.AbstractDao; |
749 | jmachado | 4 | import jomm.utils.PdfUtils; |
915 | jmachado | 5 | import org.apache.commons.net.ftp.FTP; |
6 | import org.apache.commons.net.ftp.FTPClient; |
||
749 | jmachado | 7 | import org.apache.fop.apps.FOPException; |
8 | import org.apache.log4j.Logger; |
||
9 | import org.dom4j.*; |
||
915 | jmachado | 10 | import org.hibernate.Query; |
749 | jmachado | 11 | import pt.estgp.estgweb.Globals; |
204 | jmachado | 12 | import pt.estgp.estgweb.domain.*; |
203 | jmachado | 13 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
915 | jmachado | 14 | import pt.estgp.estgweb.domain.dao.impl.CourseUnitDaoImpl; |
749 | jmachado | 15 | import pt.estgp.estgweb.domain.views.CourseUnitProgramView; |
16 | import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
||
1798 | jmachado | 17 | import pt.estgp.estgweb.services.data.IRepositoryFile; |
749 | jmachado | 18 | import pt.estgp.estgweb.services.data.RepositoryService; |
19 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
||
20 | import pt.estgp.estgweb.utils.DatesUtils; |
||
21 | import pt.estgp.estgweb.utils.Dom4jUtil; |
||
751 | jmachado | 22 | import pt.estgp.estgweb.utils.StringsUtils; |
915 | jmachado | 23 | import pt.estgp.estgweb.web.FtpServer; |
749 | jmachado | 24 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
203 | jmachado | 25 | |
749 | jmachado | 26 | import javax.xml.transform.TransformerException; |
27 | import javax.xml.transform.dom.DOMSource; |
||
1798 | jmachado | 28 | import java.io.*; |
749 | jmachado | 29 | import java.text.SimpleDateFormat; |
915 | jmachado | 30 | import java.util.*; |
203 | jmachado | 31 | |
32 | /* |
||
33 | * @author Goncalo Luiz gedl [AT] rnl [DOT] ist [DOT] utl [DOT] pt |
||
34 | * |
||
35 | * |
||
36 | * Created at 17/Out/2003 , 23:45:24 |
||
37 | * |
||
38 | */ |
||
749 | jmachado | 39 | |
203 | jmachado | 40 | /** |
41 | * @author Jorge Machado |
||
42 | * |
||
43 | * |
||
44 | * Created at 17/Out/2003 , 23:45:24 |
||
45 | * |
||
46 | */ |
||
749 | jmachado | 47 | public class SaveCourseUnitProgram implements IService |
203 | jmachado | 48 | { |
49 | |||
204 | jmachado | 50 | RepositoryService repositoryService = new RepositoryService(); |
209 | jmachado | 51 | LoadCourseUnitAnnouncements loadCourseUnitAnnouncements = new LoadCourseUnitAnnouncements(); |
204 | jmachado | 52 | |
749 | jmachado | 53 | 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(SaveCourseUnitProgram.class); |
203 | jmachado | 54 | |
757 | jmachado | 55 | |
1350 | jmachado | 56 | public void validate(1.5.0/docs/api/java/lang/Long.html">Long courseUnitId, UserSession usession, CourseUnitImpl clearedCourseUnit) throws ServiceException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, 1.5.0/docs/api/java/io/IOException.html">IOException, FOPException { |
206 | jmachado | 57 | |
1350 | jmachado | 58 | if(clearedCourseUnit.isClear((UserSessionImpl) usession,CourseUnitImpl.CourseUnitClearancesOperation.PROGRAM_CAN_VALIDATE.name())) |
59 | { |
||
60 | clearedCourseUnit.setValidProgram(true); |
||
61 | } |
||
62 | |||
63 | } |
||
64 | |||
65 | public void invalidate(1.5.0/docs/api/java/lang/Long.html">Long courseUnitId, UserSession usession, CourseUnitImpl clearedCourseUnit) throws ServiceException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, 1.5.0/docs/api/java/io/IOException.html">IOException, FOPException { |
||
66 | |||
67 | if(clearedCourseUnit.isClear((UserSessionImpl) usession,CourseUnitImpl.CourseUnitClearancesOperation.PROGRAM_CAN_VALIDATE.name())) |
||
68 | { |
||
69 | clearedCourseUnit.setValidProgram(false); |
||
70 | } |
||
71 | |||
72 | } |
||
73 | |||
74 | public CourseUnitProgramView run(CourseUnitProgramView cupv, 1.5.0/docs/api/java/lang/Long.html">Long coursUnitId, UserSession usession, CourseUnitImpl clearedCourseUnit) throws ServiceException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, 1.5.0/docs/api/java/io/IOException.html">IOException, FOPException { |
||
75 | |||
76 | //CourseUnit cProxy = DaoFactory.getCourseUnitDaoImpl().get(coursUnitId); |
||
77 | |||
78 | |||
79 | //Ja vem do filtro isto feito |
||
80 | // clearedCourseUnit.initClearances((UserSessionImpl) usession,true); |
||
81 | |||
82 | CourseUnitProgram program = clearedCourseUnit.getCourseUnitProgram(); |
||
749 | jmachado | 83 | if(program == null) |
84 | { |
||
85 | program = new CourseUnitProgramImpl(); |
||
86 | DaoFactory.getCourseUnitProgramDaoImpl().save(program); |
||
87 | program.setCourseUnitProgramPart2(new CourseUnitProgramPart2Impl()); |
||
88 | DaoFactory.getCourseUnitProgramPart2DaoImpl().save(program.getCourseUnitProgramPart2()); |
||
1350 | jmachado | 89 | clearedCourseUnit.setCourseUnitProgram(program); |
749 | jmachado | 90 | } |
91 | // |
||
1350 | jmachado | 92 | //if(usession.getUser().isSuperuserOrAdmin()) |
93 | |||
94 | if(clearedCourseUnit.isClear((UserSessionImpl) usession,CourseUnitImpl.CourseUnitClearancesOperation.PROGRAM_TEACHER_PART.name())) |
||
1782 | jmachado | 95 | //if(usession.getUser() instanceof Teacher && (((Teacher)(usession.getUser())).checkIsTeacherOfCourseUnit(c.getId(),true))) |
749 | jmachado | 96 | { |
97 | cupv.persistViewInObjectTeacher(program); |
||
98 | } |
||
1350 | jmachado | 99 | if(clearedCourseUnit.isClear((UserSessionImpl) usession,CourseUnitImpl.CourseUnitClearancesOperation.PROGRAM_COORDINATOR_PART.name())) |
749 | jmachado | 100 | { |
101 | cupv.persistViewInObjectCoordinator(program); |
||
1350 | jmachado | 102 | setResponsableTeacher(cupv, clearedCourseUnit); |
749 | jmachado | 103 | } |
1350 | jmachado | 104 | |
749 | jmachado | 105 | List<String> errors = new ArrayList<String>(); |
1350 | jmachado | 106 | createPdf(clearedCourseUnit,errors,usession); |
751 | jmachado | 107 | |
108 | if(usession.getUser() instanceof Teacher) |
||
1350 | jmachado | 109 | DirectedCoordinatedUnitsService.sendNotificationsEditedInterestedPeople(clearedCourseUnit,usession); |
751 | jmachado | 110 | else |
111 | { |
||
112 | logger.info("Nao vai informar docentes"); |
||
113 | } |
||
114 | |||
749 | jmachado | 115 | return cupv; |
116 | } |
||
358 | jmachado | 117 | |
847 | jmachado | 118 | private void setResponsableTeacher(CourseUnitProgramView cupv, CourseUnit c) { |
119 | if(cupv.getResponsableId() > 0) |
||
120 | { |
||
121 | Teacher t = DaoFactory.getTeacherDaoImpl().load(cupv.getResponsableId()); |
||
122 | c.setResponsableTeacher(t); |
||
123 | } |
||
124 | } |
||
206 | jmachado | 125 | |
749 | jmachado | 126 | |
1300 | jmachado | 127 | |
749 | jmachado | 128 | public void createPdf(CourseUnit cu, List<String> errors) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException { |
751 | jmachado | 129 | createPdf(cu,errors,null); |
130 | } |
||
915 | jmachado | 131 | |
751 | jmachado | 132 | public void createPdf(CourseUnit cu, List<String> errors,UserSession u) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException { |
1300 | jmachado | 133 | createPdf(cu,errors,null,null); |
134 | } |
||
749 | jmachado | 135 | |
1300 | jmachado | 136 | public void createPdf(CourseUnit cu, List<String> errors,UserSession u,List<String> warns) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException { |
915 | jmachado | 137 | |
1300 | jmachado | 138 | |
915 | jmachado | 139 | 1.5.0/docs/api/java/lang/String.html">String path = generatePdfFile(cu, errors, u); |
140 | |||
141 | |||
142 | |||
143 | RepositoryService repositoryService = new RepositoryService(); |
||
144 | User owner; |
||
145 | if(cu.getTeachers() != null && cu.getTeachers().size() > 0) |
||
146 | owner = cu.getTeachers().iterator().next(); |
||
147 | else |
||
148 | owner = DaoFactory.getUserDaoImpl().load(new 1.5.0/docs/api/java/lang/Long.html">Long(1)); |
||
149 | if(owner.getUsername() == null) |
||
150 | { |
||
151 | errors.add("Docente: " + owner.getName() + " ( " + owner.getId() + " ) don't have username check that situation"); |
||
152 | // owner.setUsername("UKNOWN"); |
||
153 | } |
||
154 | if(cu.getProgramStreamId() == null) |
||
155 | { |
||
1703 | jmachado | 156 | 1.5.0/docs/api/java/lang/String.html">String identifier = repositoryService.storeRepositoryFile(new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(path), "application/pdf", "pdf",((int) new 1.5.0/docs/api/java/io/File.html">File(path).length()), cu.getCode() + ".pdf", "courseunit.program.description" + cu.getName(), ResourceAccessControlEnum.publicDomain, null, owner); |
915 | jmachado | 157 | cu.setProgramStreamId(identifier); |
158 | } |
||
159 | else |
||
160 | { |
||
161 | repositoryService.updateRepositoryFile(cu.getProgramStreamId(), new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(path), "application/pdf", "pdf", ((int)new 1.5.0/docs/api/java/io/File.html">File(path).length()),cu.getCode() + ".pdf", "courseunit.program.description " + cu.getName(), ResourceAccessControlEnum.publicDomain); |
||
162 | } |
||
163 | cu.setObjectives(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getObjectivos()); |
||
164 | //Obrigar a ser falso |
||
165 | |||
166 | //NOVO |
||
167 | RepositoryFileImpl repoFile = repositoryService.loadView(cu.getProgramStreamId()); |
||
1300 | jmachado | 168 | sendPdfFtpIonline(cu,errors,u,path,repoFile.getLastVersion().getSaveDate(),null,warns); |
915 | jmachado | 169 | } |
170 | |||
171 | |||
1801 | jmachado | 172 | public boolean sendCurrentPdf2IonlineDontGeneratePdf(CourseUnit cu, List<String> errors,UserSession u,FTPClient client,List<String> warns) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException { |
1798 | jmachado | 173 | |
1801 | jmachado | 174 | if(cu.getProgramStreamId() != null && cu.getProgramStreamId().length()> 0) |
175 | { |
||
176 | try |
||
177 | { |
||
178 | IRepositoryFile repoFileLastVersion = repositoryService.load(cu.getProgramStreamId(), null); |
||
1798 | jmachado | 179 | |
1801 | jmachado | 180 | sendPdfFtpIonline(cu, errors, u, repoFileLastVersion.getInput(), repoFileLastVersion.getSaveDate(), client, warns); |
181 | return true; |
||
182 | } |
||
183 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
184 | { |
||
185 | logger.error("Loading repository file: " + cu.getProgramStreamId() + " " + e.toString(),e); |
||
186 | } |
||
187 | } |
||
188 | return false; |
||
1798 | jmachado | 189 | } |
190 | |||
191 | |||
1300 | jmachado | 192 | public boolean sendPdfFtpIonline(CourseUnit cu, List<String> errors, UserSession u, FTPClient client, List<String> warns) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException |
915 | jmachado | 193 | { |
194 | RepositoryService repositoryService = new RepositoryService(); |
||
195 | if(cu.getProgramStreamId() != null && cu.getProgramStreamId().length()> 0) |
||
196 | { |
||
1800 | jmachado | 197 | try |
198 | { |
||
199 | RepositoryFileImpl repoFile = repositoryService.loadView(cu.getProgramStreamId()); |
||
200 | 1.5.0/docs/api/java/lang/String.html">String path = generatePdfFile(cu, errors, u); |
||
201 | sendPdfFtpIonline(cu,errors,u,path,repoFile.getLastVersion().getSaveDate(),client,warns); |
||
202 | return true; |
||
203 | } |
||
204 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
205 | { |
||
206 | logger.error("Loading repository file: " + cu.getProgramStreamId() + " " + e.toString(),e); |
||
207 | } |
||
915 | jmachado | 208 | } |
209 | return false; |
||
210 | } |
||
211 | |||
212 | 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat sdf = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat("yyyy_MM_dd.HH_mm_ss"); |
||
213 | |||
1798 | jmachado | 214 | private void sendPdfFtpIonline(CourseUnit cu, List<String> errors, UserSession u,5+0%2Fdocs%2Fapi+InputStream">InputStream pdfPath,5+0%2Fdocs%2Fapi+Date">Date versionDate,FTPClient client,List<String> warnings) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException { |
1300 | jmachado | 215 | |
1312 | jmachado | 216 | if(Globals.TEST_ENVIRONEMENT) |
1300 | jmachado | 217 | { |
218 | 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"; |
||
219 | if(warnings != null) |
||
220 | warnings.add(warn); |
||
221 | logger.warn(warn); |
||
222 | return; |
||
223 | } |
||
915 | jmachado | 224 | FtpServer server = null; |
225 | if(client == null) |
||
226 | { |
||
227 | server = FtpServer.getNewServer(Globals.FTP_IONLINE_URL,Globals.FTP_IONLINE_USER,Globals.FTP_IONLINE_PASS); |
||
228 | client = server.getClient(); |
||
1005 | jmachado | 229 | if(client == null) |
230 | { |
||
231 | logger.warn("###################"); |
||
1009 | jmachado | 232 | logger.warn("################### > CANT CONNECT FTP - could be FTPTimeout: " + Globals.FTP_TIMEOUT_SECONDS); |
1007 | jmachado | 233 | errors.add("################### > CANT CONNECT FTP to send program " + ((CourseUnitImpl)cu).getSigesUniqueIdentifiers()); |
1005 | jmachado | 234 | return; |
235 | } |
||
915 | jmachado | 236 | } |
237 | client.setFileType(FTP.BINARY_FILE_TYPE); |
||
238 | |||
239 | 1.5.0/docs/api/java/lang/String.html">String pastaFichaCurricular = Globals.FTP_IONLINE_START_PATH + cu.getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_FichaCurricular; |
||
240 | if(!client.changeWorkingDirectory(pastaFichaCurricular)) |
||
241 | { |
||
242 | logger.error("FTP CANT CHANGE TO PATH: " + pastaFichaCurricular); |
||
243 | } |
||
244 | else |
||
245 | { |
||
1798 | jmachado | 246 | if(!client.storeFile(cu.getCode() + "_" + cu.getNormalizedName() + "_v" + sdf.format(versionDate) + ".pdf",pdfPath)) |
1009 | jmachado | 247 | { |
248 | errors.add("CANT store file in given time, probably timeout at " + Globals.FTP_DATA_STORE_TIMEOUT_SECONDS); |
||
249 | } |
||
915 | jmachado | 250 | |
251 | if(server != null) |
||
252 | { |
||
253 | client.quit(); |
||
254 | client.disconnect(); |
||
255 | } |
||
256 | } |
||
257 | // |
||
258 | } |
||
259 | |||
1798 | jmachado | 260 | private void sendPdfFtpIonline(CourseUnit cu, List<String> errors, UserSession u,1.5.0/docs/api/java/lang/String.html">String pdfPath,5+0%2Fdocs%2Fapi+Date">Date versionDate,FTPClient client,List<String> warnings) throws 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException { |
261 | |||
262 | sendPdfFtpIonline(cu,errors,u,new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(pdfPath),versionDate,client,warnings); |
||
263 | // |
||
264 | } |
||
265 | |||
915 | jmachado | 266 | private 1.5.0/docs/api/java/lang/String.html">String generatePdfFile(CourseUnit cu, List<String> errors, UserSession u) throws 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, 1.5.0/docs/api/java/io/IOException.html">IOException, FOPException { |
937 | jmachado | 267 | |
939 | jmachado | 268 | CourseUnitProgramImpl cProgram = (CourseUnitProgramImpl) DaoFactory.getCourseUnitProgramDaoImpl().narrow(cu.getCourseUnitProgram()); |
937 | jmachado | 269 | cProgram.consistNullValues(); |
938 | jmachado | 270 | |
749 | jmachado | 271 | 5+0%2Fdocs%2Fapi+Document">Document responseDoc = DocumentHelper.createDocument(); |
272 | Namespace namespace = new Namespace("uc", "http://baco.estgp.pt/schemas/courseunits/program/"); |
||
273 | responseDoc.setXMLEncoding("ISO-8859-1"); |
||
274 | |||
275 | 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat sdf = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat("dd-MM-yyyy"); |
||
276 | 5+0%2Fdocs%2Fapi+Element">Element curriculum = responseDoc.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("UnidadeCurricular", namespace)); |
||
277 | curriculum.addAttribute(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("data",namespace),sdf.format(new java.util.5+0%2Fdocs%2Fapi+Date">Date())); |
||
278 | |||
279 | 5+0%2Fdocs%2Fapi+Element">Element curso = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("curso",namespace)); |
||
280 | if(cu.getCourseName() == null) |
||
204 | jmachado | 281 | { |
749 | jmachado | 282 | if(cu.getCourse() == null) |
204 | jmachado | 283 | { |
749 | jmachado | 284 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Unidade nao tem curso"); |
285 | curso.setText("Desactualizado"); |
||
204 | jmachado | 286 | } |
749 | jmachado | 287 | else |
288 | { |
||
289 | 1.5.0/docs/api/java/lang/System.html">System.out.println("Unidade nao tem nome no curso a actualizar com " + cu.getCourse().getName()); |
||
290 | curso.setText(cu.getCourse().getName()); |
||
291 | cu.setCourseName(cu.getCourse().getName()); |
||
292 | } |
||
204 | jmachado | 293 | } |
749 | jmachado | 294 | else |
295 | curso.setText(cu.getCourseName()); |
||
209 | jmachado | 296 | |
749 | jmachado | 297 | 5+0%2Fdocs%2Fapi+Element">Element anoLectivo = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("anoLectivo",namespace)); |
298 | anoLectivo.setText(DatesUtils.getImportYearPrograms(cu.getImportYear())); |
||
299 | |||
300 | 5+0%2Fdocs%2Fapi+Element">Element unidadeCurricular = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("unidadeCurricular",namespace)); |
||
301 | unidadeCurricular.setText(cu.getName()); |
||
302 | |||
303 | if(cu.getResponsableTeacher() != null) |
||
209 | jmachado | 304 | { |
749 | jmachado | 305 | 5+0%2Fdocs%2Fapi+Element">Element responsavel = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("responsavel",namespace)); |
358 | jmachado | 306 | |
754 | jmachado | 307 | if(cu.getResponsableTeacher().getName()==null) |
308 | { |
||
309 | errors.add("Erro a carregar docente responsavel da unidade " + cu.getCode()); |
||
310 | responsavel.setText("erro"); |
||
311 | } |
||
312 | else |
||
313 | responsavel.setText(StringsUtils.getNormalizedName(cu.getResponsableTeacher().getName())); |
||
314 | |||
749 | jmachado | 315 | 5+0%2Fdocs%2Fapi+Element">Element responsavelEmail = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("responsavelEmail",namespace)); |
750 | jmachado | 316 | if(cu.getResponsableTeacher().getEmail()==null) |
317 | { |
||
318 | logger.warn("Teacher don't has email: " + cu.getResponsableTeacher().getSigesCode() + " - " + cu.getResponsableTeacher().getName()); |
||
319 | try { |
||
320 | 1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(3000); |
||
321 | } catch (1.5.0/docs/api/java/lang/InterruptedException.html">InterruptedException e) { |
||
322 | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
||
323 | } |
||
324 | responsavelEmail.setText(""); |
||
325 | } |
||
326 | else |
||
327 | responsavelEmail.setText(cu.getResponsableTeacher().getEmail()); |
||
209 | jmachado | 328 | } |
749 | jmachado | 329 | |
330 | |||
331 | 5+0%2Fdocs%2Fapi+Element">Element apresentacaoObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("objetivosDaAprendizagem",namespace)); |
||
332 | apresentacaoObjectivos.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getObjectivos()); |
||
333 | |||
334 | |||
335 | int docenteNumber = 1; |
||
336 | for(Teacher t : cu.getTeachers()) |
||
337 | { |
||
338 | 5+0%2Fdocs%2Fapi+Element">Element codigoSIGESDocente1 = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("codigoSIGESDocente" + docenteNumber,namespace)); |
||
339 | codigoSIGESDocente1.setText(t.getSigesCode()+""); |
||
340 | 5+0%2Fdocs%2Fapi+Element">Element outroDocente1 = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("outroDocente" + docenteNumber,namespace)); |
||
753 | jmachado | 341 | if(t.getName()==null) |
752 | jmachado | 342 | { |
343 | errors.add("Erro a carregar docente da unidade " + cu.getCode()); |
||
344 | outroDocente1.setText("erro"); |
||
345 | } |
||
346 | else |
||
347 | outroDocente1.setText(StringsUtils.getNormalizedName(t.getName())); |
||
749 | jmachado | 348 | 5+0%2Fdocs%2Fapi+Element">Element docenteEmail1 = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("docenteEmail" + docenteNumber,namespace)); |
750 | jmachado | 349 | |
350 | if(t.getEmail()==null) |
||
351 | { |
||
352 | logger.warn("Teacher don't has email: " + t.getSigesCode() + " - " + t.getName()); |
||
353 | try { |
||
354 | 1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(3000); |
||
355 | } catch (1.5.0/docs/api/java/lang/InterruptedException.html">InterruptedException e) { |
||
356 | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
||
357 | } |
||
358 | docenteEmail1.setText(""); |
||
359 | } |
||
360 | else |
||
361 | docenteEmail1.setText(t.getEmail()); |
||
751 | jmachado | 362 | |
363 | docenteNumber++; |
||
749 | jmachado | 364 | } |
365 | |||
366 | |||
367 | 5+0%2Fdocs%2Fapi+Element">Element conteudosProgramaticos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("conteudosProgramaticos",namespace)); |
||
368 | conteudosProgramaticos.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getConteudos()); |
||
369 | |||
370 | 5+0%2Fdocs%2Fapi+Element">Element demonstracaoCoerenciaConteudosObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("demonstracaoCoerenciaConteudosObjectivos",namespace)); |
||
371 | demonstracaoCoerenciaConteudosObjectivos.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getDemonstracaoCoerenciaConteudos()); |
||
372 | |||
373 | 5+0%2Fdocs%2Fapi+Element">Element metodologiasEnsino = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("metodologiasEnsino",namespace)); |
||
374 | metodologiasEnsino.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getMetodologiasEnsino()); |
||
375 | |||
376 | 5+0%2Fdocs%2Fapi+Element">Element alunosOrdinariosPorFrequencia = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("alunosOrdinariosPorFrequencia",namespace)); |
||
377 | alunosOrdinariosPorFrequencia.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getAvaliacaoOrdinariosFrequencia()); |
||
378 | |||
379 | 5+0%2Fdocs%2Fapi+Element">Element alunosOrdinariosPorExame = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("alunosOrdinariosPorExame",namespace)); |
||
380 | alunosOrdinariosPorExame.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getAvaliacaoOrdinariosExame()); |
||
381 | |||
382 | 5+0%2Fdocs%2Fapi+Element">Element alunosMobilidadeAlunosComEstatutoEspecialPorFrequencia = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("alunosMobilidadeAlunosComEstatutoEspecialPorFrequencia",namespace)); |
||
383 | alunosMobilidadeAlunosComEstatutoEspecialPorFrequencia.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getAvaliacaoEspeciaisFrequencia()); |
||
384 | |||
385 | 5+0%2Fdocs%2Fapi+Element">Element alunosMobilidadeAlunosComEstatutoEspecialPorExame = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("alunosMobilidadeAlunosComEstatutoEspecialPorExame",namespace)); |
||
386 | alunosMobilidadeAlunosComEstatutoEspecialPorExame.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getAvaliacaoEspeciaissExame()); |
||
387 | |||
388 | |||
389 | 5+0%2Fdocs%2Fapi+Element">Element demonstracaoDaCoerenciaMetodologiasObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("demonstracaoDaCoerenciaMetodologiasObjectivos",namespace)); |
||
390 | demonstracaoDaCoerenciaMetodologiasObjectivos.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getDemonstracaoObjectivosMetodologia()); |
||
391 | |||
392 | |||
393 | 5+0%2Fdocs%2Fapi+Element">Element bibliografiaPrincipal = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("bibliografiaPrincipal",namespace)); |
||
394 | bibliografiaPrincipal.setText(cu.getCourseUnitProgram().getBibliografia()); |
||
395 | |||
396 | 5+0%2Fdocs%2Fapi+Element">Element bibliografiaComplementar = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("bibliografiaComplementar",namespace)); |
||
397 | bibliografiaComplementar.setText(cu.getCourseUnitProgram().getBibliografiaComplementar()); |
||
398 | |||
399 | 5+0%2Fdocs%2Fapi+Element">Element adaptacaoMetodologiasObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("adaptacaoMetodologiasObjectivos",namespace)); |
||
400 | adaptacaoMetodologiasObjectivos.setText(cu.getCourseUnitProgram().getAdaptacaoObjectivosMetodologia()); |
||
401 | |||
402 | 5+0%2Fdocs%2Fapi+Element">Element verificacaoCargaECTS = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("verificacaoCargaECTS",namespace)); |
||
403 | verificacaoCargaECTS.setText(cu.getCourseUnitProgram().getDemonstracaoCargaEcts()); |
||
404 | |||
405 | 5+0%2Fdocs%2Fapi+Element">Element avaliacaoFuncaoObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("avaliacaoFuncaoObjectivos",namespace)); |
||
406 | avaliacaoFuncaoObjectivos.setText(cu.getCourseUnitProgram().getGarantiaAvaliacaoFuncaObjectivos()); |
||
407 | |||
408 | 5+0%2Fdocs%2Fapi+Element">Element metodologiasFacilitamParticipacaoCientificas = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("metodologiasFacilitamParticipacaoCientificas",namespace)); |
||
409 | metodologiasFacilitamParticipacaoCientificas.setText(cu.getCourseUnitProgram().getMetodologiasActividadeCientifica()); |
||
410 | |||
411 | 5+0%2Fdocs%2Fapi+Element">Element ects = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("ects",namespace)); |
||
412 | ects.setText(cu.getCourseUnitProgram().getEcts()); |
||
413 | |||
414 | |||
415 | 5+0%2Fdocs%2Fapi+Element">Element preRequisitos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("preRequisitos",namespace)); |
||
416 | preRequisitos.setText(cu.getCourseUnitProgram().getPrerequisitos()); |
||
417 | |||
418 | 5+0%2Fdocs%2Fapi+Element">Element obrigatoria = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("obrigatoria",namespace)); |
||
419 | obrigatoria.setText(cu.getCourseUnitProgram().getObrigatoria()); |
||
420 | |||
421 | 5+0%2Fdocs%2Fapi+Element">Element lingua1 = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("lingua1",namespace)); |
||
422 | lingua1.setText(cu.getCourseUnitProgram().getLingua1()); |
||
423 | |||
424 | 5+0%2Fdocs%2Fapi+Element">Element lingua2 = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("lingua2",namespace)); |
||
763 | jmachado | 425 | lingua2.setText(cu.getCourseUnitProgram().getLingua2()); |
749 | jmachado | 426 | |
427 | 5+0%2Fdocs%2Fapi+Element">Element cargaHorariaT = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaT",namespace)); |
||
428 | cargaHorariaT.setText(cu.getCourseUnitProgram().getCargaHorariaT()); |
||
429 | 5+0%2Fdocs%2Fapi+Element">Element cargaHorariaTP = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaTP",namespace)); |
||
430 | cargaHorariaTP.setText(cu.getCourseUnitProgram().getCargaHorariaTP()); |
||
431 | 5+0%2Fdocs%2Fapi+Element">Element cargaHorariaPL = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaPL",namespace)); |
||
432 | cargaHorariaPL.setText(cu.getCourseUnitProgram().getCargaHorariaPL()); |
||
433 | 5+0%2Fdocs%2Fapi+Element">Element cargaHorariaS = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaS",namespace)); |
||
434 | cargaHorariaS.setText(cu.getCourseUnitProgram().getCargaHorariaS()); |
||
435 | 5+0%2Fdocs%2Fapi+Element">Element cargaHorariaTC = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaTC",namespace)); |
||
436 | cargaHorariaTC.setText(cu.getCourseUnitProgram().getCargaHorariaTC()); |
||
437 | 5+0%2Fdocs%2Fapi+Element">Element cargaHorariaO = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaO",namespace)); |
||
438 | cargaHorariaO.setText(cu.getCourseUnitProgram().getCargaHorariaO()); |
||
439 | 5+0%2Fdocs%2Fapi+Element">Element cargaHorariaOT = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaOT",namespace)); |
||
440 | cargaHorariaOT.setText(cu.getCourseUnitProgram().getCargaHorariaOT()); |
||
441 | |||
442 | 5+0%2Fdocs%2Fapi+Element">Element cargaHorariaTotal = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaTotal",namespace)); |
||
443 | cargaHorariaTotal.setText(cu.getCourseUnitProgram().getCargaHorariaTotal()); |
||
444 | |||
445 | |||
446 | // Dom4jUtil.writeSout(responseDoc); |
||
447 | |||
780 | jmachado | 448 | |
916 | jmachado | 449 | 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 + cu.getCode() + "-" + cu.getNormalizedName() + ".pdf"; |
450 | 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream out = new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(path); |
||
749 | jmachado | 451 | Map<String,Object> params = new HashMap<String,Object>(); |
452 | params.put("site", Globals.SITE_URL); |
||
751 | jmachado | 453 | if(cu.isValidProgram()) |
454 | params.put("validadoCC", "true"); |
||
455 | else |
||
456 | params.put("validadoCC", "false"); |
||
457 | if(u != null && u.getUser() != null) |
||
458 | params.put("revisor", u.getUser().getName()); |
||
459 | |||
780 | jmachado | 460 | |
778 | jmachado | 461 | org.w3c.dom.5+0%2Fdocs%2Fapi+Document">Document dd = Dom4jUtil.toW3c(responseDoc); |
780 | jmachado | 462 | |
916 | jmachado | 463 | PdfUtils.createPdfFromXml(new 1.5.0/docs/api/javax/xml/transform/dom/DOMSource.html">DOMSource(dd), "pt/estgp/estgweb/services/courseunits/courseunitprogram.fo.xsl", out, params); |
464 | out.flush(); |
||
465 | out.close(); |
||
915 | jmachado | 466 | return path; |
467 | } |
||
749 | jmachado | 468 | |
780 | jmachado | 469 | |
1803 | jmachado | 470 | public void storeAllPrograms(boolean generate) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
915 | jmachado | 471 | CourseUnitDaoImpl dao = DaoFactory.getCourseUnitDaoImpl(); |
472 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("select c from c in class " + CourseUnit.class.getName() + " where c.importYear = ?"); |
||
995 | jmachado | 473 | q.setString(0,DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear()); |
915 | jmachado | 474 | Iterator<CourseUnit> cuIter = q.iterate(); |
475 | FtpServer server = FtpServer.getNewServer(Globals.FTP_IONLINE_URL,Globals.FTP_IONLINE_USER,Globals.FTP_IONLINE_PASS); |
||
476 | FTPClient client = server.getClient(); |
||
1005 | jmachado | 477 | if(client == null) |
478 | { |
||
479 | logger.warn("###################"); |
||
480 | logger.warn("################### > CANT CONNECT FTP"); |
||
481 | return; |
||
482 | } |
||
915 | jmachado | 483 | while (cuIter.hasNext()) { |
484 | CourseUnit next = cuIter.next(); |
||
485 | |||
486 | try { |
||
487 | List<String> errors = new ArrayList<String>(); |
||
488 | 1.5.0/docs/api/java/lang/System.html">System.out.print("Sending " + next.getCourse().getName() + " - " + next.getSemestre() + " - " + next.getNormalizedName()); |
||
1803 | jmachado | 489 | boolean result = generate ? |
490 | sendPdfFtpIonline(next, errors,null,client,null) : sendCurrentPdf2IonlineDontGeneratePdf(next, errors, null, client, null); |
||
491 | |||
492 | if(result) |
||
915 | jmachado | 493 | 1.5.0/docs/api/java/lang/System.html">System.out.print(" ... OK"); |
494 | else |
||
495 | 1.5.0/docs/api/java/lang/System.html">System.out.print(" ... FAIL probably no StreamID"); |
||
496 | 1.5.0/docs/api/java/lang/System.html">System.out.print("\n"); |
||
497 | if(errors.size()>0) |
||
498 | for(1.5.0/docs/api/java/lang/String.html">String error:errors) |
||
499 | logger.warn(error); |
||
500 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
||
501 | logger.error(e,e); |
||
502 | } catch (1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException e) { |
||
503 | logger.error(e, e); |
||
504 | } catch (FOPException e) { |
||
505 | e.printStackTrace(); |
||
1798 | jmachado | 506 | }catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) { |
507 | e.printStackTrace(); |
||
915 | jmachado | 508 | } |
509 | |||
510 | AbstractDao.getCurrentSession().evict(next); |
||
1803 | jmachado | 511 | logger.info(next.getName() + " done"); |
749 | jmachado | 512 | } |
1803 | jmachado | 513 | logger.info("Service Done"); |
915 | jmachado | 514 | client.quit(); |
515 | client.disconnect(); |
||
1803 | jmachado | 516 | logger.info("Disconnecting FTP Client"); |
915 | jmachado | 517 | |
518 | } |
||
519 | |||
520 | |||
521 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
||
937 | jmachado | 522 | |
915 | jmachado | 523 | AbstractDao.getCurrentSession().beginTransaction(); |
1803 | jmachado | 524 | new SaveCourseUnitProgram().storeAllPrograms(false); |
525 | logger.info("Flushing Database"); |
||
915 | jmachado | 526 | AbstractDao.getCurrentSession().flush(); |
527 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
749 | jmachado | 528 | } |
529 | |||
203 | jmachado | 530 | } |