Subversion Repositories bacoAlunos

Rev

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