Rev 1328 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1327 | jmachado | 1 | package pt.estgp.estgweb.services.questionarios.pedagogico; |
2 | |||
3 | import org.json.JSONArray; |
||
4 | import pt.estgp.estgweb.domain.*; |
||
5 | import pt.estgp.estgweb.services.jobs.JobDeamon; |
||
6 | import pt.estgp.estgweb.services.jobs.ServiceJob; |
||
7 | import pt.estgp.estgweb.services.logresults.ILogMessages; |
||
8 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages; |
||
9 | import pt.estgp.estgweb.web.exceptions.NotAuthorizedException; |
||
10 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
11 | |||
12 | import java.util.HashSet; |
||
13 | import java.util.Set; |
||
14 | |||
15 | /** |
||
16 | * Created by jorgemachado on 22/03/16. |
||
17 | */ |
||
18 | public class UpdateCoursesAndUnitsJobService extends ServiceJob implements IService |
||
19 | { |
||
20 | |||
21 | //todo falta validar as clearances |
||
22 | //todo falta meter a tarefa no Questionario |
||
23 | public QuestionarioImpl runJobSelectCourses(long questionarioId,1.5.0/docs/api/java/lang/String.html">String[] coursesList,UserSession session,QuestionarioImpl questionarioCleared) throws NotAuthorizedException { |
||
24 | |||
25 | if(!questionarioCleared.isClear((UserSessionImpl) session,QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SCHEDULLE_SELECT_COURSES.name())) |
||
26 | { |
||
27 | throw new NotAuthorizedException("Nao tem autorização para agendar atribuições de cursos"); |
||
28 | } |
||
29 | JSONArray jsonArray = new JSONArray(); |
||
30 | for(1.5.0/docs/api/java/lang/String.html">String sele: coursesList) |
||
31 | { |
||
32 | jsonArray.put(new 1.5.0/docs/api/java/lang/Long.html">Long(sele)); |
||
33 | } |
||
34 | |||
35 | Set<JobServiceTaskParameter> paramsJob = new HashSet<JobServiceTaskParameter>(); |
||
36 | |||
37 | JobServiceTaskParameterImpl paramJobL = DomainObjectFactory.createJobServiceTaskParameterImpl(); |
||
38 | paramJobL.setName(ServiceJob.JOB_questionario_courseList_KEY); |
||
39 | paramJobL.setDescription("lista de cursos a associar"); |
||
40 | paramJobL.setObject(jsonArray.toString()); |
||
41 | paramsJob.add(paramJobL); |
||
42 | |||
43 | |||
44 | JobServiceTaskParameterImpl paramJob = DomainObjectFactory.createJobServiceTaskParameterImpl(); |
||
45 | paramJob.setName(ServiceJob.JOB_questionario_id_KEY); |
||
46 | paramJob.setDescription("ID do questionário"); |
||
47 | paramJob.setObject("" + questionarioId); |
||
48 | paramsJob.add(paramJob); |
||
49 | |||
50 | JobServiceTask job = JobDeamon.createServiceJob(UpdateCoursesAndUnitsJobService.class, session.getUser(), paramsJob, |
||
51 | "Service: Atribuição de Cursos e Unidades a um questionário Pedagógico"); |
||
52 | questionarioCleared.setCourseSelectionTaskId(job.getId()); |
||
53 | return questionarioCleared; |
||
54 | } |
||
55 | |||
56 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
57 | protected ILogMessages runJobServiceTask() throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
||
58 | 1.5.0/docs/api/java/lang/System.html">System.out.println("RUNNING DEMO"); |
||
59 | return new DefaultLogMessages(); |
||
60 | } |
||
61 | } |