Rev 1778 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1076 | jmachado | 1 | package pt.estgp.estgweb.web.controllers.configuration; |
2 | |||
3 | import com.owlike.genson.Genson; |
||
4 | import jomm.dao.impl.AbstractDao; |
||
5 | import org.apache.log4j.Logger; |
||
6 | import pt.estgp.estgweb.domain.JobServiceTask; |
||
7 | import pt.estgp.estgweb.domain.JobServiceTaskImpl; |
||
1085 | jmachado | 8 | import pt.estgp.estgweb.domain.JobServiceTaskScheduler; |
1076 | jmachado | 9 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
10 | import pt.estgp.estgweb.web.UserSessionProxy; |
||
11 | import pt.estgp.estgweb.web.utils.RequestUtils; |
||
12 | import pt.utl.ist.berserk.logic.filterManager.exceptions.*; |
||
13 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
||
14 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
||
15 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException; |
||
16 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.ServiceManagerException; |
||
17 | |||
18 | import javax.servlet.ServletException; |
||
19 | import javax.servlet.http.HttpServlet; |
||
20 | import javax.servlet.http.HttpServletRequest; |
||
21 | import javax.servlet.http.HttpServletResponse; |
||
22 | import java.io.IOException; |
||
23 | import java.lang.reflect.InvocationTargetException; |
||
1085 | jmachado | 24 | import java.util.List; |
1076 | jmachado | 25 | |
26 | /** |
||
27 | * Created by jorgemachado on 23/11/15. |
||
28 | */ |
||
29 | public class SchedullerTasksJson extends HttpServlet |
||
30 | { |
||
31 | 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(SchedullerTasksJson.class); |
||
32 | |||
33 | |||
34 | public void doGet(HttpServletRequest request, HttpServletResponse response) |
||
35 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException |
||
36 | { |
||
37 | try { |
||
38 | process(request,response); |
||
39 | } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) { |
||
40 | response.sendError(500); |
||
41 | logger.error(e,e); |
||
42 | } |
||
43 | } |
||
44 | |||
45 | public void doPost(HttpServletRequest request, HttpServletResponse response) |
||
46 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException |
||
47 | { |
||
48 | try { |
||
49 | process(request,response); |
||
50 | } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) { |
||
51 | response.sendError(500); |
||
52 | logger.error(e, e); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | private void process(HttpServletRequest request, HttpServletResponse response) |
||
57 | throws ServletException, 1.5.0/docs/api/java/io/IOException.html">IOException, 1.5.0/docs/api/java/lang/NoSuchMethodException.html">NoSuchMethodException, 1.5.0/docs/api/java/lang/reflect/InvocationTargetException.html">InvocationTargetException, 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException { |
||
58 | 1.5.0/docs/api/java/lang/String.html">String service = request.getParameter("service"); |
||
59 | |||
60 | this.getClass().getMethod(service,HttpServletRequest.class,HttpServletResponse.class) |
||
61 | .invoke(this,request,response); |
||
62 | } |
||
63 | |||
64 | public void loadLog(HttpServletRequest request,HttpServletResponse response) throws 1.5.0/docs/api/java/io/IOException.html">IOException, IncompatibleFilterException, InvalidFilterException, ClassNotIFilterException, FilterRetrieveException, ServiceManagerException, InvalidFilterExpressionException { |
||
65 | |||
66 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("ci")) |
||
67 | { |
||
68 | response.sendError(403); |
||
69 | return; |
||
70 | } |
||
71 | |||
72 | 1.5.0/docs/api/java/lang/String.html">String id = request.getParameter("id"); |
||
73 | IServiceManager sm = ServiceManager.getInstance(); |
||
74 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
75 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{1.5.0/docs/api/java/lang/Long.html">Long.parseLong(id)}; |
||
76 | |||
77 | try |
||
78 | { |
||
79 | JobServiceTaskImpl j = (JobServiceTaskImpl) sm.execute(RequestUtils.getRequester(request, response), "LoadJobServiceTask", args, names); |
||
80 | |||
81 | Genson genson = new Genson.Builder() |
||
82 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
1778 | jmachado | 83 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
84 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
85 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
86 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
87 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
1780 | jmachado | 88 | .exclude("parameter") //metodo getParameter tem de ser evitado porque recebe parametros nao é um getter |
1076 | jmachado | 89 | .include("serviceStartDateFormated", JobServiceTask.class) |
90 | .include("serviceLastUpdateDateFormated", JobServiceTask.class) |
||
91 | .include("serviceFinishDateFormated", JobServiceTask.class) |
||
92 | .include("status", JobServiceTask.class) |
||
93 | .include("progress",JobServiceTask.class) |
||
94 | .create(); |
||
95 | |||
96 | 1.5.0/docs/api/java/lang/String.html">String json = genson.serialize(j); |
||
97 | response.setContentType("application/json"); |
||
98 | response.setCharacterEncoding("ISO-8859-1"); |
||
99 | response.setContentLength(json.length()); |
||
100 | response.getOutputStream().print(json); |
||
101 | |||
102 | } |
||
103 | catch (FilterChainFailedException e) |
||
104 | { |
||
105 | logger.error(e,e); |
||
106 | response.sendError(500); |
||
107 | } |
||
108 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
109 | { |
||
110 | logger.error(e,e); |
||
111 | response.sendError(500); |
||
112 | } |
||
113 | } |
||
1085 | jmachado | 114 | |
115 | |||
116 | |||
117 | public void loadTasks(HttpServletRequest request,HttpServletResponse response) throws 1.5.0/docs/api/java/io/IOException.html">IOException, IncompatibleFilterException, InvalidFilterException, ClassNotIFilterException, FilterRetrieveException, ServiceManagerException, InvalidFilterExpressionException { |
||
118 | |||
119 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isAdmin() && !UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole("ci")) |
||
120 | { |
||
121 | response.sendError(403); |
||
122 | return; |
||
123 | } |
||
124 | |||
125 | |||
126 | IServiceManager sm = ServiceManager.getInstance(); |
||
127 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
128 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{}; |
||
129 | |||
130 | try |
||
131 | { |
||
132 | List<JobServiceTaskScheduler> tasks = (List<JobServiceTaskScheduler>) sm.execute(RequestUtils.getRequester(request, response), "LoadJobServiceTaskSchedullers", args, names); |
||
133 | |||
134 | |||
135 | Genson genson = new Genson.Builder() |
||
136 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
1778 | jmachado | 137 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
138 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
139 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
140 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
141 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
1780 | jmachado | 142 | .exclude("parameter") //metodo getParameter tem de ser evitado porque recebe parametros nao é um getter |
1085 | jmachado | 143 | .include("serviceStartDateFormated", JobServiceTask.class) |
144 | .include("serviceLastUpdateDateFormated", JobServiceTask.class) |
||
145 | .include("serviceFinishDateFormated", JobServiceTask.class) |
||
146 | .include("status", JobServiceTask.class) |
||
147 | .include("progress",JobServiceTask.class) |
||
148 | .include("lastJobServiceTask",JobServiceTaskScheduler.class) |
||
149 | .create(); |
||
150 | |||
151 | 1.5.0/docs/api/java/lang/String.html">String json = genson.serialize(tasks); |
||
152 | |||
153 | response.setContentType("application/json"); |
||
154 | response.setCharacterEncoding("ISO-8859-1"); |
||
155 | response.setContentLength(json.length()); |
||
156 | response.getOutputStream().print(json); |
||
157 | |||
158 | } |
||
159 | catch (FilterChainFailedException e) |
||
160 | { |
||
161 | logger.error(e,e); |
||
162 | response.sendError(500); |
||
163 | } |
||
164 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
165 | { |
||
166 | logger.error(e,e); |
||
167 | response.sendError(500); |
||
168 | } |
||
169 | } |
||
1076 | jmachado | 170 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args2) throws IncompatibleFilterException, InvalidFilterException, ClassNotIFilterException, FilterRetrieveException, ServiceManagerException, InvalidFilterExpressionException { |
171 | 1.5.0/docs/api/java/lang/String.html">String id = "44365"; |
||
172 | IServiceManager sm = ServiceManager.getInstance(); |
||
173 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
174 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{1.5.0/docs/api/java/lang/Long.html">Long.parseLong(id)}; |
||
175 | |||
176 | try |
||
177 | { |
||
178 | AbstractDao.getCurrentSession().beginTransaction(); |
||
1780 | jmachado | 179 | JobServiceTaskImpl j = (JobServiceTaskImpl) DaoFactory.getJobServiceTaskDaoImpl().get(new 1.5.0/docs/api/java/lang/Long.html">Long(1)); |
1076 | jmachado | 180 | |
181 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
182 | |||
183 | Genson genson = new Genson.Builder() |
||
184 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
1778 | jmachado | 185 | .include(1.5.0/docs/api/java/lang/Boolean.html">Boolean.class) |
186 | .include(1.5.0/docs/api/java/lang/Integer.html">Integer.class) |
||
187 | .include(1.5.0/docs/api/java/lang/Long.html">Long.class) |
||
188 | .include(1.5.0/docs/api/java/lang/Double.html">Double.class) |
||
189 | .include(1.5.0/docs/api/java/lang/Float.html">Float.class) |
||
1780 | jmachado | 190 | .exclude("parameter") //metodo getParameter tem de ser evitado porque recebe parametros nao é um getter |
1076 | jmachado | 191 | .include("serviceStartDate", JobServiceTask.class) |
192 | .include("serviceLastUpdateDate", JobServiceTask.class) |
||
193 | .include("serviceFinishDate", JobServiceTask.class) |
||
194 | .include("status", JobServiceTask.class) |
||
195 | .include("progress",JobServiceTask.class) |
||
196 | .create(); |
||
197 | |||
198 | 1.5.0/docs/api/java/lang/String.html">String json = genson.serialize(j); |
||
199 | |||
1780 | jmachado | 200 | 1.5.0/docs/api/java/lang/System.html">System.out.println(json); |
1076 | jmachado | 201 | } |
202 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
203 | { |
||
204 | logger.error(e,e); |
||
205 | |||
206 | } |
||
207 | } |
||
208 | } |