Rev 1704 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1704 | Rev 1730 | ||
---|---|---|---|
1 | package pt.estgp.estgweb.web.controllers.widgetmodel; |
1 | package pt.estgp.estgweb.web.controllers.widgetmodel; |
2 | 2 | ||
3 | import jomm.dao.impl.AbstractDao; |
3 | import jomm.dao.impl.AbstractDao; |
4 | import org.apache.struts.action.ActionForm; |
4 | import org.apache.struts.action.ActionForm; |
5 | import org.json.JSONArray; |
5 | import org.json.JSONArray; |
6 | import org.json.JSONException; |
6 | import org.json.JSONException; |
7 | import org.json.JSONObject; |
7 | import org.json.JSONObject; |
8 | import pt.estgp.estgweb.domain.SigesUser; |
8 | import pt.estgp.estgweb.domain.SigesUser; |
9 | import pt.estgp.estgweb.domain.Student; |
9 | import pt.estgp.estgweb.domain.Student; |
10 | import pt.estgp.estgweb.domain.Teacher; |
10 | import pt.estgp.estgweb.domain.Teacher; |
11 | import pt.estgp.estgweb.domain.User; |
11 | import pt.estgp.estgweb.domain.User; |
12 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
12 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
13 | import pt.estgp.estgweb.domain.views.UserView; |
13 | import pt.estgp.estgweb.domain.views.UserView; |
- | 14 | import pt.estgp.estgweb.filters.exceptions.NotFoundException; |
|
14 | import pt.estgp.estgweb.web.controllers.utils.AbstractWidgetAjaxController; |
15 | import pt.estgp.estgweb.web.controllers.utils.AbstractWidgetAjaxController; |
15 | import pt.estgp.estgweb.web.form.widgetmodel.WidgetModelForm; |
16 | import pt.estgp.estgweb.web.form.widgetmodel.WidgetModelForm; |
16 | import pt.estgp.estgweb.web.utils.RequestUtils; |
17 | import pt.estgp.estgweb.web.utils.RequestUtils; |
17 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
18 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
18 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
19 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
19 | 20 | ||
20 | import javax.servlet.http.HttpServletRequest; |
21 | import javax.servlet.http.HttpServletRequest; |
21 | import javax.servlet.http.HttpServletResponse; |
22 | import javax.servlet.http.HttpServletResponse; |
22 | import java.util.List; |
23 | import java.util.List; |
23 | 24 | ||
24 | /** |
25 | /** |
25 | * Created by jorgemachado on 06/01/17. |
26 | * Created by jorgemachado on 06/01/17. |
26 | */ |
27 | */ |
27 | public class ModelWidgetController extends AbstractWidgetAjaxController |
28 | public class ModelWidgetController extends AbstractWidgetAjaxController |
28 | { |
29 | { |
29 | 30 | ||
30 | public JSONObject findUser(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws JSONException { |
31 | public JSONObject findUser(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws JSONException { |
31 | 32 | ||
32 | WidgetModelForm frm = (WidgetModelForm) form; |
33 | WidgetModelForm frm = (WidgetModelForm) form; |
33 | 1.5.0/docs/api/java/lang/String.html">String query = frm.getQ(); |
34 | 1.5.0/docs/api/java/lang/String.html">String query = frm.getQ(); |
34 | 35 | ||
35 | JSONObject result = new JSONObject(); |
36 | JSONObject result = new JSONObject(); |
36 | JSONArray usersArray = new JSONArray(); |
37 | JSONArray usersArray = new JSONArray(); |
37 | result.put("results",usersArray); |
38 | result.put("results",usersArray); |
38 | 39 | ||
39 | if(query==null || query.trim().length() == 0) |
40 | if(query==null || query.trim().length() == 0) |
40 | return result; |
41 | return result; |
41 | 42 | ||
42 | AbstractDao.getCurrentSession().beginTransaction(); |
43 | AbstractDao.getCurrentSession().beginTransaction(); |
43 | 44 | ||
44 | //result.put("results",usersArray); |
45 | //result.put("results",usersArray); |
45 | List<User> users = DaoFactory.getUserDaoImpl().findUsers(query); |
46 | List<User> users = DaoFactory.getUserDaoImpl().findUsers(query); |
46 | getUsersInJson(usersArray, users); |
47 | getUsersInJson(usersArray, users); |
47 | AbstractDao.getCurrentSession().getTransaction().commit(); |
48 | AbstractDao.getCurrentSession().getTransaction().commit(); |
48 | return result; |
49 | return result; |
49 | } |
50 | } |
50 | 51 | ||
51 | 52 | ||
52 | 53 | ||
53 | 54 | ||
54 | public JSONObject getUserForUsername(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws JSONException { |
55 | public JSONObject getUserForUsername(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws JSONException, NotFoundException { |
55 | 56 | ||
56 | WidgetModelForm frm = (WidgetModelForm) form; |
57 | WidgetModelForm frm = (WidgetModelForm) form; |
57 | 1.5.0/docs/api/java/lang/String.html">String username = frm.getQ(); |
58 | 1.5.0/docs/api/java/lang/String.html">String username = frm.getQ(); |
58 | 59 | ||
59 | JSONObject result; |
60 | JSONObject result; |
60 | 61 | ||
61 | AbstractDao.getCurrentSession().beginTransaction(); |
62 | AbstractDao.getCurrentSession().beginTransaction(); |
62 | 63 | ||
63 | // |
64 | // |
64 | User user = DaoFactory.getUserDaoImpl().loadByUsername(username); |
65 | User user = DaoFactory.getUserDaoImpl().loadByUsername(username); |
- | 66 | if(user != null) |
|
65 | result = getJsonUser(user); |
67 | result = getJsonUser(user); |
- | 68 | else |
|
- | 69 | throw new NotFoundException("Username: " + username + " not found"); |
|
66 | AbstractDao.getCurrentSession().getTransaction().commit(); |
70 | AbstractDao.getCurrentSession().getTransaction().commit(); |
67 | return result; |
71 | return result; |
68 | } |
72 | } |
69 | 73 | ||
70 | 74 | ||
71 | 75 | ||
72 | 76 | ||
73 | public JSONObject findUserRoles(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws JSONException { |
77 | public JSONObject findUserRoles(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws JSONException { |
74 | 78 | ||
75 | WidgetModelForm frm = (WidgetModelForm) form; |
79 | WidgetModelForm frm = (WidgetModelForm) form; |
76 | 1.5.0/docs/api/java/lang/String.html">String query = frm.getQ(); |
80 | 1.5.0/docs/api/java/lang/String.html">String query = frm.getQ(); |
77 | 81 | ||
78 | JSONObject result = new JSONObject(); |
82 | JSONObject result = new JSONObject(); |
79 | JSONArray usersArray = new JSONArray(); |
83 | JSONArray usersArray = new JSONArray(); |
80 | result.put("results",usersArray); |
84 | result.put("results",usersArray); |
81 | 85 | ||
82 | if(query==null || query.trim().length() == 0) |
86 | if(query==null || query.trim().length() == 0) |
83 | return result; |
87 | return result; |
84 | 88 | ||
85 | AbstractDao.getCurrentSession().beginTransaction(); |
89 | AbstractDao.getCurrentSession().beginTransaction(); |
86 | 90 | ||
87 | result.put("results",usersArray); |
91 | result.put("results",usersArray); |
88 | List<User> users = DaoFactory.getUserDaoImpl().loadRoleUsers(query); |
92 | List<User> users = DaoFactory.getUserDaoImpl().loadRoleUsers(query); |
89 | getUsersInJson(usersArray, users); |
93 | getUsersInJson(usersArray, users); |
90 | AbstractDao.getCurrentSession().getTransaction().commit(); |
94 | AbstractDao.getCurrentSession().getTransaction().commit(); |
91 | return result; |
95 | return result; |
92 | } |
96 | } |
93 | 97 | ||
94 | private void getUsersInJson(JSONArray usersArray, List<User> users) throws JSONException { |
98 | private void getUsersInJson(JSONArray usersArray, List<User> users) throws JSONException { |
95 | for(User u: users) |
99 | for(User u: users) |
96 | { |
100 | { |
97 | JSONObject user = getJsonUser(u); |
101 | JSONObject user = getJsonUser(u); |
98 | usersArray.put(user); |
102 | usersArray.put(user); |
99 | } |
103 | } |
100 | } |
104 | } |
101 | 105 | ||
102 | public static JSONObject getJsonUser(User u) throws JSONException { |
106 | public static JSONObject getJsonUser(User u) throws JSONException { |
103 | JSONObject user = new JSONObject(); |
107 | JSONObject user = new JSONObject(); |
104 | user.put("id",u.getId()); |
108 | user.put("id",u.getId()); |
105 | user.put("username",u.getUsername()); |
109 | user.put("username",u.getUsername()); |
106 | user.put("name",u.getName()); |
110 | user.put("name",u.getName()); |
107 | if(u instanceof SigesUser) |
111 | if(u instanceof SigesUser) |
108 | { |
112 | { |
109 | user.put("sigesCode",((SigesUser)u).getSigesCode()); |
113 | user.put("sigesCode",((SigesUser)u).getSigesCode()); |
110 | } |
114 | } |
111 | if(u instanceof Teacher) |
115 | if(u instanceof Teacher) |
112 | { |
116 | { |
113 | user.put("type","teacher"); |
117 | user.put("type","teacher"); |
114 | } |
118 | } |
115 | if(u instanceof Student) |
119 | if(u instanceof Student) |
116 | { |
120 | { |
117 | user.put("type","student"); |
121 | user.put("type","student"); |
118 | } |
122 | } |
119 | return user; |
123 | return user; |
120 | } |
124 | } |
121 | 125 | ||
122 | 126 | ||
123 | /** |
127 | /** |
124 | * q json object: |
128 | * q json object: |
125 | * { |
129 | * { |
126 | * userId:Long, |
130 | * userId:Long, |
127 | * role:String, |
131 | * role:String, |
128 | * } |
132 | * } |
129 | * Adds a role to a user |
133 | * Adds a role to a user |
130 | * |
134 | * |
131 | * @param form |
135 | * @param form |
132 | * @param request |
136 | * @param request |
133 | * @param response |
137 | * @param response |
134 | * @return Users in Json |
138 | * @return Users in Json |
135 | * @throws JSONException |
139 | * @throws JSONException |
136 | */ |
140 | */ |
137 | public JSONObject addRole2User(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
141 | public JSONObject addRole2User(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
138 | 142 | ||
139 | WidgetModelForm frm = (WidgetModelForm) form; |
143 | WidgetModelForm frm = (WidgetModelForm) form; |
140 | 1.5.0/docs/api/java/lang/String.html">String query = frm.getQ(); |
144 | 1.5.0/docs/api/java/lang/String.html">String query = frm.getQ(); |
141 | JSONObject roleUser = new JSONObject(query); |
145 | JSONObject roleUser = new JSONObject(query); |
142 | 1.5.0/docs/api/java/lang/Long.html">Long userId = roleUser.getLong("userId"); |
146 | 1.5.0/docs/api/java/lang/Long.html">Long userId = roleUser.getLong("userId"); |
143 | 1.5.0/docs/api/java/lang/String.html">String role = roleUser.getString("role"); |
147 | 1.5.0/docs/api/java/lang/String.html">String role = roleUser.getString("role"); |
144 | 148 | ||
145 | IServiceManager sm = ServiceManager.getInstance(); |
149 | IServiceManager sm = ServiceManager.getInstance(); |
146 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"userId","role_2_addRemove"}; //colocacao do nome de parametro role_2_add obrigatoria para validacao no filtro do serviço |
150 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"userId","role_2_addRemove"}; //colocacao do nome de parametro role_2_add obrigatoria para validacao no filtro do serviço |
147 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{userId,role}; |
151 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{userId,role}; |
148 | sm.execute(RequestUtils.getRequester(request, response), "AddRole2User", args, names); |
152 | sm.execute(RequestUtils.getRequester(request, response), "AddRole2User", args, names); |
149 | 153 | ||
150 | frm.setQ(role); |
154 | frm.setQ(role); |
151 | addMessageAsString(request,"Utilizador adicionado com sucesso ao papel institucional"); |
155 | addMessageAsString(request,"Utilizador adicionado com sucesso ao papel institucional"); |
152 | return findUserRoles(frm,request,response); |
156 | return findUserRoles(frm,request,response); |
153 | } |
157 | } |
154 | 158 | ||
155 | /** |
159 | /** |
156 | * q json object: |
160 | * q json object: |
157 | * { |
161 | * { |
158 | * userId:Long, |
162 | * userId:Long, |
159 | * role:String, |
163 | * role:String, |
160 | * } |
164 | * } |
161 | * Adds a role to a user |
165 | * Adds a role to a user |
162 | * |
166 | * |
163 | * @param form |
167 | * @param form |
164 | * @param request |
168 | * @param request |
165 | * @param response |
169 | * @param response |
166 | * @return Users in Json |
170 | * @return Users in Json |
167 | * @throws JSONException |
171 | * @throws JSONException |
168 | */ |
172 | */ |
169 | public JSONObject removeRole2User(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
173 | public JSONObject removeRole2User(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
170 | 174 | ||
171 | WidgetModelForm frm = (WidgetModelForm) form; |
175 | WidgetModelForm frm = (WidgetModelForm) form; |
172 | 1.5.0/docs/api/java/lang/String.html">String query = frm.getQ(); |
176 | 1.5.0/docs/api/java/lang/String.html">String query = frm.getQ(); |
173 | JSONObject roleUser = new JSONObject(query); |
177 | JSONObject roleUser = new JSONObject(query); |
174 | 1.5.0/docs/api/java/lang/Long.html">Long userId = roleUser.getLong("userId"); |
178 | 1.5.0/docs/api/java/lang/Long.html">Long userId = roleUser.getLong("userId"); |
175 | 1.5.0/docs/api/java/lang/String.html">String role = roleUser.getString("role"); |
179 | 1.5.0/docs/api/java/lang/String.html">String role = roleUser.getString("role"); |
176 | 180 | ||
177 | IServiceManager sm = ServiceManager.getInstance(); |
181 | IServiceManager sm = ServiceManager.getInstance(); |
178 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"userId","role_2_addRemove"}; //colocacao do nome de parametro role_2_add obrigatoria para validacao no filtro do serviço |
182 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"userId","role_2_addRemove"}; //colocacao do nome de parametro role_2_add obrigatoria para validacao no filtro do serviço |
179 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{userId,role}; |
183 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{userId,role}; |
180 | sm.execute(RequestUtils.getRequester(request, response), "RemoveRole2User", args, names); |
184 | sm.execute(RequestUtils.getRequester(request, response), "RemoveRole2User", args, names); |
181 | 185 | ||
182 | frm.setQ(role); |
186 | frm.setQ(role); |
183 | addMessageAsString(request,"Utilizador removido com sucesso do papel institucional"); |
187 | addMessageAsString(request,"Utilizador removido com sucesso do papel institucional"); |
184 | return findUserRoles(frm,request,response); |
188 | return findUserRoles(frm,request,response); |
185 | } |
189 | } |
186 | 190 | ||
187 | 191 | ||
188 | 192 | ||
189 | 193 | ||
190 | /** |
194 | /** |
191 | * For Json Services |
195 | * For Json Services |
192 | * @param form |
196 | * @param form |
193 | * @param request |
197 | * @param request |
194 | * @param response |
198 | * @param response |
195 | * @return |
199 | * @return |
196 | * @throws Throwable |
200 | * @throws Throwable |
197 | */ |
201 | */ |
198 | public boolean wsLoginMobileChallenge(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
202 | public boolean wsLoginMobileChallenge(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
199 | 203 | ||
200 | 1.5.0/docs/api/java/lang/String.html">String username = request.getParameter("username"); |
204 | 1.5.0/docs/api/java/lang/String.html">String username = request.getParameter("username"); |
201 | 1.5.0/docs/api/java/lang/String.html">String chaveAppsMoveis = request.getParameter("chaveAppsMoveis"); |
205 | 1.5.0/docs/api/java/lang/String.html">String chaveAppsMoveis = request.getParameter("chaveAppsMoveis"); |
202 | IServiceManager sm = ServiceManager.getInstance(); |
206 | IServiceManager sm = ServiceManager.getInstance(); |
203 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
207 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
204 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{username,chaveAppsMoveis}; |
208 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{username,chaveAppsMoveis}; |
205 | UserView u = (UserView) sm.execute(RequestUtils.getRequester(request, response), "WSAPILoginChallenge", args, names); |
209 | UserView u = (UserView) sm.execute(RequestUtils.getRequester(request, response), "WSAPILoginChallenge", args, names); |
206 | return u != null; |
210 | return u != null; |
207 | } |
211 | } |
208 | 212 | ||
209 | /** |
213 | /** |
210 | * * For Json Services |
214 | * * For Json Services |
211 | * @param form |
215 | * @param form |
212 | * @param request |
216 | * @param request |
213 | * @param response |
217 | * @param response |
214 | * @return |
218 | * @return |
215 | * @throws Throwable |
219 | * @throws Throwable |
216 | */ |
220 | */ |
217 | public JSONObject wsListStudents(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
221 | public JSONObject wsListStudents(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
218 | 222 | ||
219 | IServiceManager sm = ServiceManager.getInstance(); |
223 | IServiceManager sm = ServiceManager.getInstance(); |
220 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
224 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
221 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{}; |
225 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{}; |
222 | JSONObject result = (JSONObject) sm.execute(RequestUtils.getRequester(request, response), "WSAPIListStudents", args, names); |
226 | JSONObject result = (JSONObject) sm.execute(RequestUtils.getRequester(request, response), "WSAPIListStudents", args, names); |
223 | return result; |
227 | return result; |
224 | } |
228 | } |
225 | 229 | ||
226 | /** |
230 | /** |
227 | * * For Json Services |
231 | * * For Json Services |
228 | * @param form |
232 | * @param form |
229 | * @param request |
233 | * @param request |
230 | * @param response |
234 | * @param response |
231 | * @return |
235 | * @return |
232 | * @throws Throwable |
236 | * @throws Throwable |
233 | */ |
237 | */ |
234 | public JSONObject wsListTeachers(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
238 | public JSONObject wsListTeachers(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
235 | 239 | ||
236 | IServiceManager sm = ServiceManager.getInstance(); |
240 | IServiceManager sm = ServiceManager.getInstance(); |
237 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
241 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
238 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{}; |
242 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{}; |
239 | JSONObject result = (JSONObject) sm.execute(RequestUtils.getRequester(request, response), "WSAPIListTeachers", args, names); |
243 | JSONObject result = (JSONObject) sm.execute(RequestUtils.getRequester(request, response), "WSAPIListTeachers", args, names); |
240 | return result; |
244 | return result; |
241 | } |
245 | } |
242 | 246 | ||
243 | /** |
247 | /** |
244 | * * For Json Services |
248 | * * For Json Services |
245 | * @param form |
249 | * @param form |
246 | * @param request |
250 | * @param request |
247 | * @param response |
251 | * @param response |
248 | * @return |
252 | * @return |
249 | * @throws Throwable |
253 | * @throws Throwable |
250 | */ |
254 | */ |
251 | public JSONObject wsListServices(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
255 | public JSONObject wsListServices(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
252 | 256 | ||
253 | JSONObject result = new JSONObject(); |
257 | JSONObject result = new JSONObject(); |
254 | JSONObject wsServices = new JSONObject(); |
258 | JSONObject wsServices = new JSONObject(); |
255 | result.put("ws-services",wsServices); |
259 | result.put("ws-services",wsServices); |
256 | wsServices.put("info-Developers","Precisa de uma chave de API fornecida pelos administradores de sistema, com a chave poderá autênticar-se com o serviço ws-authenticate cada vez que a sua APP comunicar"); |
260 | wsServices.put("info-Developers","Precisa de uma chave de API fornecida pelos administradores de sistema, com a chave poderá autênticar-se com o serviço ws-authenticate cada vez que a sua APP comunicar"); |
257 | wsServices.put("info-Users","O utilizador final necessita de ser encaminhado via WEB para gerar a sua chaveAppsMoveis entrando no PAE/BACO no seguinte URL /startGenerateChaveApps.do"); |
261 | wsServices.put("info-Users","O utilizador final necessita de ser encaminhado via WEB para gerar a sua chaveAppsMoveis entrando no PAE/BACO no seguinte URL /startGenerateChaveApps.do"); |
258 | 262 | ||
259 | JSONObject wsAuthenticate = new JSONObject(); |
263 | JSONObject wsAuthenticate = new JSONObject(); |
260 | wsAuthenticate.put("service","/wsjson/api/app/ws-authenticate"); |
264 | wsAuthenticate.put("service","/wsjson/api/app/ws-authenticate"); |
261 | wsAuthenticate.put("parameter1","apikey"); |
265 | wsAuthenticate.put("parameter1","apikey"); |
262 | wsAuthenticate.put("return1","certificate: este serviço devolve a chave de comunicação seguinte que deverá ser usada como certificado"); |
266 | wsAuthenticate.put("return1","certificate: este serviço devolve a chave de comunicação seguinte que deverá ser usada como certificado"); |
263 | wsAuthenticate.put("return2","certificateExpire: este serviço devolve a data em que o seu certificado de API expira"); |
267 | wsAuthenticate.put("return2","certificateExpire: este serviço devolve a data em que o seu certificado de API expira"); |
264 | 268 | ||
265 | JSONObject wsLoginChallenge = new JSONObject(); |
269 | JSONObject wsLoginChallenge = new JSONObject(); |
266 | wsLoginChallenge.put("service","/wsjson/api/app/secure/ws-login-challenge"); |
270 | wsLoginChallenge.put("service","/wsjson/api/app/secure/ws-login-challenge"); |
267 | wsLoginChallenge.put("parameter1","certificate"); |
271 | wsLoginChallenge.put("parameter1","certificate"); |
268 | wsLoginChallenge.put("parameter2","username"); |
272 | wsLoginChallenge.put("parameter2","username"); |
269 | wsLoginChallenge.put("parameter3","chaveAppsMoveis"); |
273 | wsLoginChallenge.put("parameter3","chaveAppsMoveis"); |
270 | wsLoginChallenge.put("descricao","usa o certificado para garantir autenticidade da APP e verifica se o utilizador e a chave fornecida pelo mesmo estão correctas"); |
274 | wsLoginChallenge.put("descricao","usa o certificado para garantir autenticidade da APP e verifica se o utilizador e a chave fornecida pelo mesmo estão correctas"); |
271 | wsLoginChallenge.put("return1","se estiver correcto devolve -> service-simple-response\",\"ok\");"); |
275 | wsLoginChallenge.put("return1","se estiver correcto devolve -> service-simple-response\",\"ok\");"); |
272 | wsLoginChallenge.put("return2","se estiver incorreto devolve -> service-simple-response\",\"fail\");"); |
276 | wsLoginChallenge.put("return2","se estiver incorreto devolve -> service-simple-response\",\"fail\");"); |
273 | 277 | ||
274 | JSONObject wsLoginListStudents = new JSONObject(); |
278 | JSONObject wsLoginListStudents = new JSONObject(); |
275 | wsLoginListStudents.put("service","/wsjson/api/app/secure/ws-student-list"); |
279 | wsLoginListStudents.put("service","/wsjson/api/app/secure/ws-student-list"); |
276 | wsLoginListStudents.put("parameter1","certificate"); |
280 | wsLoginListStudents.put("parameter1","certificate"); |
277 | wsLoginListStudents.put("descricao","usa o certificado para garantir autenticidade da APP e devolve a lista total de estudantes do sistema no parametro response"); |
281 | wsLoginListStudents.put("descricao","usa o certificado para garantir autenticidade da APP e devolve a lista total de estudantes do sistema no parametro response"); |
278 | wsLoginListStudents.put("return1","lista total de estudantes do sistema no parametro response"); |
282 | wsLoginListStudents.put("return1","lista total de estudantes do sistema no parametro response"); |
279 | 283 | ||
280 | 284 | ||
281 | JSONObject wsLoginListTeachers = new JSONObject(); |
285 | JSONObject wsLoginListTeachers = new JSONObject(); |
282 | wsLoginListTeachers.put("service","/wsjson/api/app/secure/ws-teacher-list"); |
286 | wsLoginListTeachers.put("service","/wsjson/api/app/secure/ws-teacher-list"); |
283 | wsLoginListTeachers.put("parameter","certificate"); |
287 | wsLoginListTeachers.put("parameter","certificate"); |
284 | wsLoginListTeachers.put("descricao","usa o certificado para garantir autenticidade da APP e devolve a lista total de professores do sistema no parametro response"); |
288 | wsLoginListTeachers.put("descricao","usa o certificado para garantir autenticidade da APP e devolve a lista total de professores do sistema no parametro response"); |
285 | wsLoginListTeachers.put("return1","devolve a lista total de professores do sistema no parametro response"); |
289 | wsLoginListTeachers.put("return1","devolve a lista total de professores do sistema no parametro response"); |
286 | 290 | ||
287 | JSONArray services = new JSONArray(); |
291 | JSONArray services = new JSONArray(); |
288 | services.put(wsAuthenticate); |
292 | services.put(wsAuthenticate); |
289 | services.put(wsLoginChallenge); |
293 | services.put(wsLoginChallenge); |
290 | services.put(wsLoginListStudents); |
294 | services.put(wsLoginListStudents); |
291 | services.put(wsLoginListTeachers); |
295 | services.put(wsLoginListTeachers); |
292 | wsServices.put("services",services); |
296 | wsServices.put("services",services); |
293 | 297 | ||
294 | return result; |
298 | return result; |
295 | } |
299 | } |
296 | } |
300 | } |
297 | 301 |