Rev 1586 | Rev 1830 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1579 | jmachado | 1 | package pt.estgp.estgweb.services.questionarios; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | import pt.estgp.estgweb.domain.*; |
||
5 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
6 | import pt.estgp.estgweb.services.jobs.JobDeamon; |
||
7 | import pt.estgp.estgweb.services.jobs.ServiceJob; |
||
8 | import pt.estgp.estgweb.utils.ConfigProperties; |
||
9 | import pt.estgp.estgweb.web.exceptions.NotAuthorizedException; |
||
10 | import pt.estgp.estgweb.web.form.questionarios.widgets.ReportAdminAlunosWidgetForm; |
||
11 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
12 | |||
13 | import java.util.ArrayList; |
||
14 | import java.util.HashSet; |
||
15 | import java.util.List; |
||
16 | import java.util.Set; |
||
17 | |||
18 | /** |
||
19 | * Created by jorgemachado on 21/03/16. |
||
20 | */ |
||
21 | public class QuestionariosReportsService implements IService |
||
22 | { |
||
23 | |||
24 | 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(QuestionariosReportsService.class); |
||
25 | |||
26 | |||
27 | public void saveReportGroup(1.5.0/docs/api/java/lang/String.html">String title,1.5.0/docs/api/java/lang/String.html">String classType, UserSession userSession) throws 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException, 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException, 1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException |
||
28 | { |
||
29 | QuestionarioReportFileGroup reportFileGroup = (QuestionarioReportFileGroup) 1.5.0/docs/api/java/lang/Class.html">Class.forName(classType).newInstance(); |
||
30 | reportFileGroup.setTitle(title); |
||
31 | 1.5.0/docs/api/java/lang/String.html">String processorClassForGroup = ConfigProperties.getProperty("questionarios.processor." + classType); |
||
32 | reportFileGroup.setReportProcessorClass(processorClassForGroup); |
||
1586 | jmachado | 33 | DaoFactory.getQuestionarioReportFileGroupDaoImpl().save(reportFileGroup); |
1579 | jmachado | 34 | } |
35 | |||
1586 | jmachado | 36 | public void updateReportGroup(long reportGroupId, 1.5.0/docs/api/java/lang/String.html">String title, boolean active, UserSession userSession) throws 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException, 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException, 1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException |
1580 | jmachado | 37 | { |
38 | QuestionarioReportFileGroupImpl reportGroup = (QuestionarioReportFileGroupImpl) DaoFactory.getQuestionarioReportFileGroupDaoImpl().load(reportGroupId); |
||
39 | reportGroup.setTitle(title); |
||
1586 | jmachado | 40 | reportGroup.setActive(active); |
1580 | jmachado | 41 | } |
1579 | jmachado | 42 | |
1586 | jmachado | 43 | public void updateReportFile(long reportFileId, boolean active, UserSession userSession) throws 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException, 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException, 1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException |
44 | { |
||
45 | QuestionarioReportFile reportFile = DaoFactory.getQuestionarioReportFileDaoImpl() |
||
46 | .load(reportFileId); |
||
47 | reportFile.setActive(active); |
||
48 | } |
||
1580 | jmachado | 49 | |
1586 | jmachado | 50 | public QuestionarioReportFileGroupImpl runJobGenerate(long reportGroupId,1.5.0/docs/api/java/lang/String.html">String title,boolean active, UserSession session) throws NotAuthorizedException, 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException { |
51 | |||
1579 | jmachado | 52 | QuestionarioReportFileGroupImpl reportGroup = (QuestionarioReportFileGroupImpl) DaoFactory.getQuestionarioReportFileGroupDaoImpl().load(reportGroupId); |
1580 | jmachado | 53 | reportGroup.setTitle(title); |
1586 | jmachado | 54 | reportGroup.setActive(active); |
1629 | jmachado | 55 | |
56 | if(reportGroup.getReportGenerationTaskId() > 0) |
||
57 | { |
||
58 | JobServiceTask serviceTask = DaoFactory.getJobServiceTaskDaoImpl().load(reportGroup.getReportGenerationTaskId()); |
||
59 | if(!serviceTask.isExecuted()) |
||
60 | { |
||
61 | //test 5 minutes |
||
62 | logger.info("Tarefa já em execução"); |
||
63 | if(1.5.0/docs/api/java/lang/System.html">System.currentTimeMillis() - serviceTask.getUpdateDate().getTime() < (60000*5)) |
||
64 | return reportGroup; |
||
65 | } |
||
66 | } |
||
1579 | jmachado | 67 | Set<JobServiceTaskParameter> paramsJob = new HashSet<JobServiceTaskParameter>(); |
68 | |||
69 | JobServiceTaskParameterImpl paramJob = DomainObjectFactory.createJobServiceTaskParameterImpl(); |
||
70 | paramJob.setName(ServiceJob.JOB_questionario_report_id_KEY); |
||
71 | paramJob.setDescription("ID do Report Group"); |
||
72 | paramJob.setObject("" + reportGroupId); |
||
73 | paramsJob.add(paramJob); |
||
74 | |||
75 | 1.5.0/docs/api/java/lang/Class.html">Class reportGeneratorServiceClass = 1.5.0/docs/api/java/lang/Class.html">Class.forName(reportGroup.getReportProcessorClass()); |
||
76 | |||
77 | JobServiceTask job = JobDeamon.createServiceJob(reportGeneratorServiceClass, session.getUser(), paramsJob, |
||
78 | "Service: Geração de Reports para o group " + reportGroupId + " - " + reportGroup.getTitle()); |
||
79 | reportGroup.setReportGenerationTaskId(job.getId()); |
||
80 | |||
81 | return reportGroup; |
||
82 | } |
||
83 | |||
84 | |||
85 | /*************WIDGET ALUNOS REPORTS***************/ |
||
86 | |||
87 | public void saveReportGroupAlunosParameters(ReportAdminAlunosWidgetForm form, UserSession userSession) throws 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException, 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException, 1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException |
||
88 | { |
||
89 | QuestionarioReportFileGroupAnoImpl reportGroup = (QuestionarioReportFileGroupAnoImpl) DaoFactory.getQuestionarioReportFileGroupAnoDaoImpl().load(form.getQuestionarioReportGroupId()); |
||
90 | List<String> periodos = new ArrayList<String>(); |
||
91 | List<String> degrees = new ArrayList<String>(); |
||
92 | reportGroup.setImportYear(form.getAno()); |
||
93 | |||
94 | if(form.isAnuais()) |
||
95 | periodos.add("A"); |
||
96 | if(form.isSemestre1()) |
||
97 | periodos.add("S1"); |
||
98 | if(form.isSemestre2()) |
||
99 | periodos.add("S2"); |
||
100 | if(form.isTrimestre1()) |
||
101 | periodos.add("T1"); |
||
102 | if(form.isTrimestre2()) |
||
103 | periodos.add("T2"); |
||
104 | if(form.isTrimestre3()) |
||
105 | periodos.add("T3"); |
||
106 | if(form.isTrimestre4()) |
||
107 | periodos.add("T4"); |
||
108 | |||
109 | if(form.isLicenciaturas()) |
||
110 | degrees.add("L"); |
||
111 | if(form.isMestrados()) |
||
112 | degrees.add("M"); |
||
113 | if(form.isTesps()) |
||
114 | degrees.add("T"); |
||
115 | if(form.isCets()) |
||
116 | degrees.add("E"); |
||
117 | |||
118 | |||
119 | reportGroup.setPeriodosList(periodos); |
||
120 | reportGroup.setDegreesList(degrees); |
||
121 | |||
122 | |||
123 | } |
||
124 | |||
125 | |||
126 | |||
127 | |||
128 | } |