Subversion Repositories bacoAlunos

Rev

Rev 1782 | Rev 1800 | 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
 
1798 jmachado 172
    public void sendPdfIonlineOnly(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 {
173
 
174
 
175
        IRepositoryFile repoFileLastVersion = repositoryService.load(cu.getProgramStreamId(), null);
176
 
177
        FTPClient nullClient = null;
178
        sendPdfFtpIonline(cu, errors, u, repoFileLastVersion.getInput(), repoFileLastVersion.getSaveDate(), nullClient, warns);
179
    }
180
 
181
 
1300 jmachado 182
    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 183
    {
184
        RepositoryService repositoryService = new RepositoryService();
185
        if(cu.getProgramStreamId() != null && cu.getProgramStreamId().length()> 0)
186
        {
187
            RepositoryFileImpl repoFile = repositoryService.loadView(cu.getProgramStreamId());
188
            1.5.0/docs/api/java/lang/String.html">String path = generatePdfFile(cu, errors, u);
1300 jmachado 189
            sendPdfFtpIonline(cu,errors,u,path,repoFile.getLastVersion().getSaveDate(),client,warns);
915 jmachado 190
            return true;
191
        }
192
        return false;
193
    }
194
 
195
    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");
196
 
1798 jmachado 197
    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 198
 
1312 jmachado 199
        if(Globals.TEST_ENVIRONEMENT)
1300 jmachado 200
        {
201
            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";
202
            if(warnings != null)
203
                warnings.add(warn);
204
            logger.warn(warn);
205
            return;
206
        }
915 jmachado 207
        FtpServer server = null;
208
        if(client == null)
209
        {
210
            server = FtpServer.getNewServer(Globals.FTP_IONLINE_URL,Globals.FTP_IONLINE_USER,Globals.FTP_IONLINE_PASS);
211
            client = server.getClient();
1005 jmachado 212
            if(client == null)
213
            {
214
                logger.warn("###################");
1009 jmachado 215
                logger.warn("################### > CANT CONNECT FTP - could be FTPTimeout: " + Globals.FTP_TIMEOUT_SECONDS);
1007 jmachado 216
                errors.add("################### > CANT CONNECT FTP to send program " + ((CourseUnitImpl)cu).getSigesUniqueIdentifiers());
1005 jmachado 217
                return;
218
            }
915 jmachado 219
        }
220
        client.setFileType(FTP.BINARY_FILE_TYPE);
221
 
222
        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;
223
        if(!client.changeWorkingDirectory(pastaFichaCurricular))
224
        {
225
            logger.error("FTP CANT CHANGE TO PATH: " + pastaFichaCurricular);
226
        }
227
        else
228
        {
1798 jmachado 229
            if(!client.storeFile(cu.getCode() + "_" + cu.getNormalizedName() + "_v" + sdf.format(versionDate) + ".pdf",pdfPath))
1009 jmachado 230
            {
231
                errors.add("CANT store file in given time, probably timeout at " + Globals.FTP_DATA_STORE_TIMEOUT_SECONDS);
232
            }
915 jmachado 233
 
234
            if(server != null)
235
            {
236
                client.quit();
237
                client.disconnect();
238
            }
239
        }
240
        //
241
    }
242
 
1798 jmachado 243
    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 {
244
 
245
        sendPdfFtpIonline(cu,errors,u,new 1.5.0/docs/api/java/io/FileInputStream.html">FileInputStream(pdfPath),versionDate,client,warnings);
246
        //
247
    }
248
 
915 jmachado 249
    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 250
 
939 jmachado 251
        CourseUnitProgramImpl cProgram = (CourseUnitProgramImpl) DaoFactory.getCourseUnitProgramDaoImpl().narrow(cu.getCourseUnitProgram());
937 jmachado 252
        cProgram.consistNullValues();
938 jmachado 253
 
749 jmachado 254
        5+0%2Fdocs%2Fapi+Document">Document responseDoc = DocumentHelper.createDocument();
255
        Namespace namespace = new Namespace("uc", "http://baco.estgp.pt/schemas/courseunits/program/");
256
        responseDoc.setXMLEncoding("ISO-8859-1");
257
 
258
        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");
259
        5+0%2Fdocs%2Fapi+Element">Element curriculum = responseDoc.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("UnidadeCurricular", namespace));
260
        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()));
261
 
262
        5+0%2Fdocs%2Fapi+Element">Element curso = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("curso",namespace));
263
        if(cu.getCourseName() == null)
204 jmachado 264
        {
749 jmachado 265
            if(cu.getCourse() == null)
204 jmachado 266
            {
749 jmachado 267
                1.5.0/docs/api/java/lang/System.html">System.out.println("Unidade nao tem curso");
268
                curso.setText("Desactualizado");
204 jmachado 269
            }
749 jmachado 270
            else
271
            {
272
                1.5.0/docs/api/java/lang/System.html">System.out.println("Unidade nao tem nome no curso a actualizar com " + cu.getCourse().getName());
273
                curso.setText(cu.getCourse().getName());
274
                cu.setCourseName(cu.getCourse().getName());
275
            }
204 jmachado 276
        }
749 jmachado 277
        else
278
            curso.setText(cu.getCourseName());
209 jmachado 279
 
749 jmachado 280
        5+0%2Fdocs%2Fapi+Element">Element anoLectivo = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("anoLectivo",namespace));
281
        anoLectivo.setText(DatesUtils.getImportYearPrograms(cu.getImportYear()));
282
 
283
        5+0%2Fdocs%2Fapi+Element">Element unidadeCurricular = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("unidadeCurricular",namespace));
284
        unidadeCurricular.setText(cu.getName());
285
 
286
        if(cu.getResponsableTeacher() != null)
209 jmachado 287
        {
749 jmachado 288
            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 289
 
754 jmachado 290
            if(cu.getResponsableTeacher().getName()==null)
291
            {
292
                errors.add("Erro a carregar docente responsavel da unidade " + cu.getCode());
293
                responsavel.setText("erro");
294
            }
295
            else
296
                responsavel.setText(StringsUtils.getNormalizedName(cu.getResponsableTeacher().getName()));
297
 
749 jmachado 298
            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 299
            if(cu.getResponsableTeacher().getEmail()==null)
300
            {
301
                logger.warn("Teacher don't has email: " + cu.getResponsableTeacher().getSigesCode() + " - " + cu.getResponsableTeacher().getName());
302
                try {
303
                    1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(3000);
304
                } catch (1.5.0/docs/api/java/lang/InterruptedException.html">InterruptedException e) {
305
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
306
                }
307
                responsavelEmail.setText("");
308
            }
309
            else
310
                responsavelEmail.setText(cu.getResponsableTeacher().getEmail());
209 jmachado 311
        }
749 jmachado 312
 
313
 
314
        5+0%2Fdocs%2Fapi+Element">Element apresentacaoObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("objetivosDaAprendizagem",namespace));
315
        apresentacaoObjectivos.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getObjectivos());
316
 
317
 
318
        int docenteNumber = 1;
319
        for(Teacher t : cu.getTeachers())
320
        {
321
            5+0%2Fdocs%2Fapi+Element">Element codigoSIGESDocente1 = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("codigoSIGESDocente" + docenteNumber,namespace));
322
            codigoSIGESDocente1.setText(t.getSigesCode()+"");
323
            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 324
            if(t.getName()==null)
752 jmachado 325
            {
326
                errors.add("Erro a carregar docente da unidade " + cu.getCode());
327
                outroDocente1.setText("erro");
328
            }
329
            else
330
                outroDocente1.setText(StringsUtils.getNormalizedName(t.getName()));
749 jmachado 331
            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 332
 
333
            if(t.getEmail()==null)
334
            {
335
                logger.warn("Teacher don't has email: " + t.getSigesCode() + " - " + t.getName());
336
                try {
337
                    1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(3000);
338
                } catch (1.5.0/docs/api/java/lang/InterruptedException.html">InterruptedException e) {
339
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
340
                }
341
                docenteEmail1.setText("");
342
            }
343
            else
344
                docenteEmail1.setText(t.getEmail());
751 jmachado 345
 
346
            docenteNumber++;
749 jmachado 347
        }
348
 
349
 
350
        5+0%2Fdocs%2Fapi+Element">Element conteudosProgramaticos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("conteudosProgramaticos",namespace));
351
        conteudosProgramaticos.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getConteudos());
352
 
353
        5+0%2Fdocs%2Fapi+Element">Element demonstracaoCoerenciaConteudosObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("demonstracaoCoerenciaConteudosObjectivos",namespace));
354
        demonstracaoCoerenciaConteudosObjectivos.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getDemonstracaoCoerenciaConteudos());
355
 
356
        5+0%2Fdocs%2Fapi+Element">Element metodologiasEnsino = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("metodologiasEnsino",namespace));
357
        metodologiasEnsino.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getMetodologiasEnsino());
358
 
359
        5+0%2Fdocs%2Fapi+Element">Element alunosOrdinariosPorFrequencia = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("alunosOrdinariosPorFrequencia",namespace));
360
        alunosOrdinariosPorFrequencia.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getAvaliacaoOrdinariosFrequencia());
361
 
362
        5+0%2Fdocs%2Fapi+Element">Element alunosOrdinariosPorExame = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("alunosOrdinariosPorExame",namespace));
363
        alunosOrdinariosPorExame.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getAvaliacaoOrdinariosExame());
364
 
365
        5+0%2Fdocs%2Fapi+Element">Element alunosMobilidadeAlunosComEstatutoEspecialPorFrequencia = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("alunosMobilidadeAlunosComEstatutoEspecialPorFrequencia",namespace));
366
        alunosMobilidadeAlunosComEstatutoEspecialPorFrequencia.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getAvaliacaoEspeciaisFrequencia());
367
 
368
        5+0%2Fdocs%2Fapi+Element">Element alunosMobilidadeAlunosComEstatutoEspecialPorExame = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("alunosMobilidadeAlunosComEstatutoEspecialPorExame",namespace));
369
        alunosMobilidadeAlunosComEstatutoEspecialPorExame.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getAvaliacaoEspeciaissExame());
370
 
371
 
372
        5+0%2Fdocs%2Fapi+Element">Element demonstracaoDaCoerenciaMetodologiasObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("demonstracaoDaCoerenciaMetodologiasObjectivos",namespace));
373
        demonstracaoDaCoerenciaMetodologiasObjectivos.setText(cu.getCourseUnitProgram().getCourseUnitProgramPart2().getDemonstracaoObjectivosMetodologia());
374
 
375
 
376
        5+0%2Fdocs%2Fapi+Element">Element bibliografiaPrincipal = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("bibliografiaPrincipal",namespace));
377
        bibliografiaPrincipal.setText(cu.getCourseUnitProgram().getBibliografia());
378
 
379
        5+0%2Fdocs%2Fapi+Element">Element bibliografiaComplementar = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("bibliografiaComplementar",namespace));
380
        bibliografiaComplementar.setText(cu.getCourseUnitProgram().getBibliografiaComplementar());
381
 
382
        5+0%2Fdocs%2Fapi+Element">Element adaptacaoMetodologiasObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("adaptacaoMetodologiasObjectivos",namespace));
383
        adaptacaoMetodologiasObjectivos.setText(cu.getCourseUnitProgram().getAdaptacaoObjectivosMetodologia());
384
 
385
        5+0%2Fdocs%2Fapi+Element">Element verificacaoCargaECTS = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("verificacaoCargaECTS",namespace));
386
        verificacaoCargaECTS.setText(cu.getCourseUnitProgram().getDemonstracaoCargaEcts());
387
 
388
        5+0%2Fdocs%2Fapi+Element">Element avaliacaoFuncaoObjectivos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("avaliacaoFuncaoObjectivos",namespace));
389
        avaliacaoFuncaoObjectivos.setText(cu.getCourseUnitProgram().getGarantiaAvaliacaoFuncaObjectivos());
390
 
391
        5+0%2Fdocs%2Fapi+Element">Element metodologiasFacilitamParticipacaoCientificas = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("metodologiasFacilitamParticipacaoCientificas",namespace));
392
        metodologiasFacilitamParticipacaoCientificas.setText(cu.getCourseUnitProgram().getMetodologiasActividadeCientifica());
393
 
394
        5+0%2Fdocs%2Fapi+Element">Element ects = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("ects",namespace));
395
        ects.setText(cu.getCourseUnitProgram().getEcts());
396
 
397
 
398
        5+0%2Fdocs%2Fapi+Element">Element preRequisitos = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("preRequisitos",namespace));
399
        preRequisitos.setText(cu.getCourseUnitProgram().getPrerequisitos());
400
 
401
        5+0%2Fdocs%2Fapi+Element">Element obrigatoria = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("obrigatoria",namespace));
402
        obrigatoria.setText(cu.getCourseUnitProgram().getObrigatoria());
403
 
404
        5+0%2Fdocs%2Fapi+Element">Element lingua1 = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("lingua1",namespace));
405
        lingua1.setText(cu.getCourseUnitProgram().getLingua1());
406
 
407
        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 408
        lingua2.setText(cu.getCourseUnitProgram().getLingua2());
749 jmachado 409
 
410
        5+0%2Fdocs%2Fapi+Element">Element cargaHorariaT = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaT",namespace));
411
        cargaHorariaT.setText(cu.getCourseUnitProgram().getCargaHorariaT());
412
        5+0%2Fdocs%2Fapi+Element">Element cargaHorariaTP = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaTP",namespace));
413
        cargaHorariaTP.setText(cu.getCourseUnitProgram().getCargaHorariaTP());
414
        5+0%2Fdocs%2Fapi+Element">Element cargaHorariaPL = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaPL",namespace));
415
        cargaHorariaPL.setText(cu.getCourseUnitProgram().getCargaHorariaPL());
416
        5+0%2Fdocs%2Fapi+Element">Element cargaHorariaS = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaS",namespace));
417
        cargaHorariaS.setText(cu.getCourseUnitProgram().getCargaHorariaS());
418
        5+0%2Fdocs%2Fapi+Element">Element cargaHorariaTC = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaTC",namespace));
419
        cargaHorariaTC.setText(cu.getCourseUnitProgram().getCargaHorariaTC());
420
        5+0%2Fdocs%2Fapi+Element">Element cargaHorariaO = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaO",namespace));
421
        cargaHorariaO.setText(cu.getCourseUnitProgram().getCargaHorariaO());
422
        5+0%2Fdocs%2Fapi+Element">Element cargaHorariaOT = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaOT",namespace));
423
        cargaHorariaOT.setText(cu.getCourseUnitProgram().getCargaHorariaOT());
424
 
425
        5+0%2Fdocs%2Fapi+Element">Element cargaHorariaTotal = curriculum.addElement(new 1.5.0/docs/api/javax/xml/namespace/QName.html">QName("cargaHorariaTotal",namespace));
426
        cargaHorariaTotal.setText(cu.getCourseUnitProgram().getCargaHorariaTotal());
427
 
428
 
429
//        Dom4jUtil.writeSout(responseDoc);
430
 
780 jmachado 431
 
916 jmachado 432
        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";
433
        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 434
        Map<String,Object> params = new HashMap<String,Object>();
435
        params.put("site", Globals.SITE_URL);
751 jmachado 436
        if(cu.isValidProgram())
437
            params.put("validadoCC", "true");
438
        else
439
            params.put("validadoCC", "false");
440
        if(u != null && u.getUser() != null)
441
            params.put("revisor", u.getUser().getName());
442
 
780 jmachado 443
 
778 jmachado 444
        org.w3c.dom.5+0%2Fdocs%2Fapi+Document">Document dd = Dom4jUtil.toW3c(responseDoc);
780 jmachado 445
 
916 jmachado 446
        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);
447
        out.flush();
448
        out.close();
915 jmachado 449
        return path;
450
    }
749 jmachado 451
 
780 jmachado 452
 
915 jmachado 453
    public void storeAllPrograms() throws 1.5.0/docs/api/java/io/IOException.html">IOException {
454
        CourseUnitDaoImpl dao = DaoFactory.getCourseUnitDaoImpl();
455
        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 456
        q.setString(0,DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear());
915 jmachado 457
        Iterator<CourseUnit> cuIter = q.iterate();
458
        FtpServer server = FtpServer.getNewServer(Globals.FTP_IONLINE_URL,Globals.FTP_IONLINE_USER,Globals.FTP_IONLINE_PASS);
459
        FTPClient client = server.getClient();
1005 jmachado 460
        if(client == null)
461
        {
462
            logger.warn("###################");
463
            logger.warn("################### > CANT CONNECT FTP");
464
            return;
465
        }
915 jmachado 466
        while (cuIter.hasNext()) {
467
            CourseUnit next = cuIter.next();
468
 
469
            try {
470
                List<String> errors = new ArrayList<String>();
471
                1.5.0/docs/api/java/lang/System.html">System.out.print("Sending " + next.getCourse().getName() + " - " + next.getSemestre() + " - " + next.getNormalizedName());
1300 jmachado 472
                if(sendPdfFtpIonline(next,errors,null,client,null))
915 jmachado 473
                    1.5.0/docs/api/java/lang/System.html">System.out.print(" ... OK");
474
                else
475
                    1.5.0/docs/api/java/lang/System.html">System.out.print(" ... FAIL probably no StreamID");
476
                1.5.0/docs/api/java/lang/System.html">System.out.print("\n");
477
                if(errors.size()>0)
478
                    for(1.5.0/docs/api/java/lang/String.html">String error:errors)
479
                        logger.warn(error);
480
            } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) {
481
                logger.error(e,e);
482
            } catch (1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException e) {
483
                logger.error(e, e);
484
            } catch (FOPException e) {
485
                e.printStackTrace();
1798 jmachado 486
            }catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
487
                e.printStackTrace();
915 jmachado 488
            }
489
 
490
            AbstractDao.getCurrentSession().evict(next);
749 jmachado 491
        }
915 jmachado 492
        client.quit();
493
        client.disconnect();
494
 
495
    }
496
 
497
 
498
        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 499
 
915 jmachado 500
            AbstractDao.getCurrentSession().beginTransaction();
501
            new SaveCourseUnitProgram().storeAllPrograms();
502
            AbstractDao.getCurrentSession().flush();
503
            AbstractDao.getCurrentSession().getTransaction().commit();
749 jmachado 504
        }
505
 
203 jmachado 506
}