Rev 1327 | Rev 1329 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1327 | Rev 1328 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.estgweb.services.questionarios.pedagogico; |
1 | package pt.estgp.estgweb.services.questionarios.pedagogico; |
2 | 2 | ||
- | 3 | import org.apache.log4j.Logger; |
|
3 | import org.json.JSONArray; |
4 | import org.json.JSONArray; |
- | 5 | import org.json.JSONException; |
|
4 | import pt.estgp.estgweb.domain.*; |
6 | import pt.estgp.estgweb.domain.*; |
- | 7 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
|
5 | import pt.estgp.estgweb.services.jobs.JobDeamon; |
8 | import pt.estgp.estgweb.services.jobs.JobDeamon; |
6 | import pt.estgp.estgweb.services.jobs.ServiceJob; |
9 | import pt.estgp.estgweb.services.jobs.ServiceJob; |
7 | import pt.estgp.estgweb.services.logresults.ILogMessages; |
10 | import pt.estgp.estgweb.services.logresults.ILogMessages; |
8 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages; |
11 | import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages; |
9 | import pt.estgp.estgweb.web.exceptions.NotAuthorizedException; |
12 | import pt.estgp.estgweb.web.exceptions.NotAuthorizedException; |
10 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
13 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
11 | 14 | ||
12 | import java.util.HashSet; |
15 | import java.util.HashSet; |
13 | import java.util.Set; |
16 | import java.util.Set; |
14 | 17 | ||
- | 18 | ||
15 | /** |
19 | /** |
16 | * Created by jorgemachado on 22/03/16. |
20 | * Created by jorgemachado on 22/03/16. |
17 | */ |
21 | */ |
18 | public class UpdateCoursesAndUnitsJobService extends ServiceJob implements IService |
22 | public class UpdateCoursesAndUnitsJobService extends ServiceJob implements IService |
19 | { |
23 | { |
20 | 24 | ||
- | 25 | public 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(UpdateCoursesAndUnitsJobService.class); |
|
- | 26 | ||
- | 27 | public 1.5.0/docs/api/java/lang/String.html">String[] deserializeCoursesList(QuestionarioImpl questionario) |
|
- | 28 | { |
|
- | 29 | JobServiceTaskImpl job = questionario.getCourseSelectionTaskId() > 0 ? |
|
- | 30 | (JobServiceTaskImpl) DaoFactory.getJobServiceTaskDaoImpl().load(questionario.getCourseSelectionTaskId()) : |
|
- | 31 | null; |
|
- | 32 | if(job == null) |
|
- | 33 | return new 1.5.0/docs/api/java/lang/String.html">String[0]; |
|
- | 34 | ||
- | 35 | 1.5.0/docs/api/java/lang/String.html">String courses = job.getParameter(ServiceJob.JOB_questionario_courseList_KEY).getObject(); |
|
- | 36 | ||
- | 37 | try { |
|
- | 38 | ||
- | 39 | JSONArray jsonArray = new JSONArray(courses); |
|
- | 40 | 1.5.0/docs/api/java/lang/String.html">String[] coursesList = new 1.5.0/docs/api/java/lang/String.html">String[jsonArray.length()]; |
|
- | 41 | for(int i=0;i <jsonArray.length();i++) |
|
- | 42 | { |
|
- | 43 | coursesList[i] = ""+ jsonArray.get(i); |
|
- | 44 | } |
|
- | 45 | return coursesList; |
|
- | 46 | } catch (JSONException e) { |
|
- | 47 | logger.error(e,e); |
|
- | 48 | } |
|
- | 49 | return new 1.5.0/docs/api/java/lang/String.html">String[0]; |
|
- | 50 | } |
|
21 | //todo falta validar as clearances |
51 | //todo falta validar as clearances |
22 | //todo falta meter a tarefa no Questionario |
52 | //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 { |
53 | public QuestionarioImpl runJobSelectCourses(long questionarioId,1.5.0/docs/api/java/lang/String.html">String[] coursesList,UserSession session,QuestionarioImpl questionarioCleared) throws NotAuthorizedException { |
24 | 54 | ||
25 | if(!questionarioCleared.isClear((UserSessionImpl) session,QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SCHEDULLE_SELECT_COURSES.name())) |
55 | if(!questionarioCleared.isClear((UserSessionImpl) session,QuestionarioImpl.QuestionarioClearancesOperation.QUESTIONARIO_SCHEDULLE_SELECT_COURSES.name())) |
Line 54... | Line 84... | ||
54 | } |
84 | } |
55 | 85 | ||
56 | @1.5.0/docs/api/java/lang/Override.html">Override |
86 | @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 { |
87 | 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"); |
88 | 1.5.0/docs/api/java/lang/System.html">System.out.println("RUNNING DEMO"); |
- | 89 | long total = 60000; |
|
- | 90 | long start = 1.5.0/docs/api/java/lang/System.html">System.currentTimeMillis(); |
|
- | 91 | //Thread.sleep(20000); |
|
- | 92 | while(true) |
|
- | 93 | { |
|
- | 94 | 1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(5000); |
|
- | 95 | long elapsed = 1.5.0/docs/api/java/lang/System.html">System.currentTimeMillis() - start; |
|
- | 96 | setProgress((int) (((float)elapsed)/((float)total)*100.0f)); |
|
- | 97 | commitPartially(); |
|
- | 98 | if(1.5.0/docs/api/java/lang/System.html">System.currentTimeMillis() - start > total) |
|
- | 99 | break; |
|
- | 100 | } |
|
- | 101 | setProgress(100); |
|
- | 102 | ||
59 | return new DefaultLogMessages(); |
103 | return new DefaultLogMessages(); |
60 | } |
104 | } |
61 | } |
105 | } |