Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1616 | jmachado | 1 | package pt.estgp.estgweb.web.controllers.widgetmodel; |
2 | |||
1830 | jmachado | 3 | import jomm.utils.StreamsUtils; |
1616 | jmachado | 4 | import org.apache.struts.action.ActionForm; |
5 | import org.json.JSONArray; |
||
6 | import org.json.JSONObject; |
||
1830 | jmachado | 7 | import pt.estgp.estgweb.utils.Globals; |
1616 | jmachado | 8 | import pt.estgp.estgweb.web.controllers.utils.AbstractWidgetAjaxController; |
1617 | jmachado | 9 | import pt.estgp.estgweb.web.utils.RequestUtils; |
10 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
||
11 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
||
1616 | jmachado | 12 | |
13 | import javax.servlet.http.HttpServletRequest; |
||
14 | import javax.servlet.http.HttpServletResponse; |
||
1830 | jmachado | 15 | import java.io.InputStream; |
16 | import java.net.URL; |
||
1616 | jmachado | 17 | |
18 | /** |
||
19 | * Created by jorgemachado on 06/01/17. |
||
20 | */ |
||
1830 | jmachado | 21 | public class CoursesServicesWidgetController extends AbstractWidgetAjaxController |
1616 | jmachado | 22 | { |
23 | |||
24 | |||
25 | |||
26 | |||
27 | |||
28 | |||
1617 | jmachado | 29 | |
1704 | jmachado | 30 | |
31 | |||
1830 | jmachado | 32 | /****************************************************************************/ |
33 | /* SERVICOS WS-API |
||
34 | /****************************************************************************/ |
||
1704 | jmachado | 35 | |
1617 | jmachado | 36 | |
37 | /** |
||
38 | * |
||
39 | * @param form |
||
40 | * @param request |
||
41 | * @param response |
||
1830 | jmachado | 42 | * @return |
43 | * @throws Throwable |
||
1617 | jmachado | 44 | */ |
45 | |||
1830 | jmachado | 46 | public JSONObject findPedagogicReport4Period(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
1617 | jmachado | 47 | |
1830 | jmachado | 48 | 1.5.0/docs/api/java/lang/String.html">String year = request.getParameter("year"); |
49 | 1.5.0/docs/api/java/lang/String.html">String code = request.getParameter("code"); |
||
50 | 1.5.0/docs/api/java/lang/String.html">String period = request.getParameter("period"); |
||
1617 | jmachado | 51 | |
1830 | jmachado | 52 | if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_REPORT_RESULTS.indexOf("localhost")>=0) |
53 | { |
||
54 | IServiceManager sm = ServiceManager.getInstance(); |
||
55 | 1.5.0/docs/api/java/lang/String.html">String json = (1.5.0/docs/api/java/lang/String.html">String) sm.execute(RequestUtils.getRequester(request, response), "QuestionariosReportLoadReportUnidadesSalasJson", new 5+0%2Fdocs%2Fapi+Object">Object[]{code, year, period}); |
||
56 | return new JSONObject(json); |
||
57 | } |
||
58 | else |
||
59 | { |
||
60 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_REPORT_RESULTS + "?code=" + code + "&year=" + year + "&period=" + period); |
||
61 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream(); |
||
62 | |||
63 | 1.5.0/docs/api/java/lang/String.html">String json = StreamsUtils.readString(is); |
||
64 | is.close(); |
||
65 | JSONObject jsonObject = new JSONObject(json); |
||
66 | return jsonObject; |
||
67 | } |
||
1617 | jmachado | 68 | } |
69 | |||
1830 | jmachado | 70 | public JSONObject getCourseUnitsEvaluations(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
1617 | jmachado | 71 | |
1830 | jmachado | 72 | 1.5.0/docs/api/java/lang/String.html">String year = request.getParameter("year"); |
73 | 1.5.0/docs/api/java/lang/String.html">String code = request.getParameter("code"); |
||
1617 | jmachado | 74 | |
75 | |||
1830 | jmachado | 76 | IServiceManager sm = ServiceManager.getInstance(); |
77 | 1.5.0/docs/api/java/lang/String.html">String json = (1.5.0/docs/api/java/lang/String.html">String) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseEvaluationSections", new 5+0%2Fdocs%2Fapi+Object">Object[]{code, year}); |
||
78 | return new JSONObject(json); |
||
1617 | jmachado | 79 | } |
1704 | jmachado | 80 | |
81 | |||
82 | |||
1830 | jmachado | 83 | public JSONObject getCourseUnitDtpStats(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
1704 | jmachado | 84 | |
1830 | jmachado | 85 | 1.5.0/docs/api/java/lang/String.html">String year = request.getParameter("year"); |
86 | 1.5.0/docs/api/java/lang/String.html">String code = request.getParameter("code"); |
||
1704 | jmachado | 87 | |
88 | |||
89 | IServiceManager sm = ServiceManager.getInstance(); |
||
1830 | jmachado | 90 | 1.5.0/docs/api/java/lang/String.html">String json = (1.5.0/docs/api/java/lang/String.html">String) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnitDtpStats", new 5+0%2Fdocs%2Fapi+Object">Object[]{code, year}); |
91 | return new JSONObject(json); |
||
1704 | jmachado | 92 | } |
93 | |||
94 | |||
95 | |||
96 | /** |
||
97 | * * For Json Services |
||
98 | * @param form |
||
99 | * @param request |
||
100 | * @param response |
||
101 | * @return |
||
102 | * @throws Throwable |
||
103 | */ |
||
104 | public JSONObject wsListServices(ActionForm form,HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
||
105 | |||
106 | JSONObject result = new JSONObject(); |
||
107 | JSONObject wsServices = new JSONObject(); |
||
1830 | jmachado | 108 | result.put("ws-course-services",wsServices); |
1704 | jmachado | 109 | |
110 | |||
1830 | jmachado | 111 | JSONObject service1 = new JSONObject(); |
112 | service1.put("service","/wsjson/api/app/ws-units-report-list"); |
||
113 | service1.put("name","getCourseUnitsEvaluations"); |
||
114 | service1.put("parameter1","code = siges code"); |
||
115 | service1.put("parameter3","year = \"201617,201718,...\""); |
||
116 | service1.put("return","uma tabela em JSON com toda a com um array objetos do tipo CourseUnitSection"); |
||
1704 | jmachado | 117 | |
1830 | jmachado | 118 | JSONObject service2 = new JSONObject(); |
119 | service2.put("service","/wsjson/api/app/ws-course-pedagogic-results-list"); |
||
120 | service2.put("name","getPedagogicReport4Period"); |
||
121 | service2.put("parameter1","code = siges code"); |
||
122 | service2.put("parameter2","period = \"S1,S2\""); |
||
123 | service2.put("parameter3","year = \"201617,201718,...\""); |
||
124 | service2.put("return","uma tabela em JSON com toda a informação de reusltados do pedagogico nesse ano"); |
||
1704 | jmachado | 125 | |
1830 | jmachado | 126 | JSONObject service3 = new JSONObject(); |
127 | service3.put("service","/wsjson/api/app/ws-units-dtp-stats"); |
||
128 | service3.put("name","getCourseUnitDtpStats"); |
||
129 | service3.put("parameter1","code = siges code"); |
||
130 | service3.put("parameter2","period = \"S1,S2\""); |
||
131 | service3.put("parameter3","year = \"201617,201718,...\""); |
||
132 | service3.put("return","uma tabela em JSON com toda a informação de estatistica do preenchimento das pastas DTP"); |
||
1704 | jmachado | 133 | |
134 | |||
135 | JSONArray services = new JSONArray(); |
||
1830 | jmachado | 136 | services.put(service1); |
137 | services.put(service2); |
||
138 | services.put(service3); |
||
1704 | jmachado | 139 | wsServices.put("services",services); |
140 | |||
141 | return result; |
||
142 | } |
||
1830 | jmachado | 143 | |
144 | /* |
||
145 | |||
146 | public static void main(String[] args) throws Throwable |
||
147 | { |
||
148 | URL url = new URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION + "?code=9119&year=201516&period=S2"); |
||
149 | InputStream is = url.openStream(); |
||
150 | |||
151 | String json = StreamsUtils.readString(is); |
||
152 | is.close(); |
||
153 | JSONObject jsonObject = new JSONObject(json); |
||
154 | System.out.println(jsonObject.toString()); |
||
155 | |||
156 | IServiceManager sm = ServiceManager.getInstance(); |
||
157 | json = (String) sm.execute("123", "LoadCourseReportsSections", new Object[]{"9119","201516"}); |
||
158 | System.out.println(json); |
||
159 | } |
||
160 | */ |
||
1616 | jmachado | 161 | } |