Rev 1789 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
214 | jmachado | 1 | package pt.estgp.estgweb.services.courses; |
2 | |||
1496 | jmachado | 3 | import com.owlike.genson.Genson; |
1784 | jmachado | 4 | import com.owlike.genson.GensonBuilder; |
1496 | jmachado | 5 | import com.owlike.genson.reflect.VisibilityFilter; |
1790 | jmachado | 6 | import jomm.dao.impl.AbstractDao; |
1670 | jmachado | 7 | import jomm.utils.BytesUtils; |
417 | jmachado | 8 | import jomm.utils.FilesUtils; |
1496 | jmachado | 9 | import jomm.utils.StreamsUtils; |
417 | jmachado | 10 | import org.apache.log4j.Logger; |
11 | import org.dom4j.Document; |
||
1496 | jmachado | 12 | import org.json.JSONArray; |
13 | import org.json.JSONException; |
||
14 | import org.json.JSONObject; |
||
417 | jmachado | 15 | import pt.estgp.estgweb.Globals; |
1496 | jmachado | 16 | import pt.estgp.estgweb.domain.*; |
417 | jmachado | 17 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
18 | import pt.estgp.estgweb.domain.views.CourseView; |
||
19 | import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
||
1699 | jmachado | 20 | import pt.estgp.estgweb.filters.exceptions.AccessDeniedException; |
1789 | jmachado | 21 | import pt.estgp.estgweb.services.courses.xsd.*; |
417 | jmachado | 22 | import pt.estgp.estgweb.services.data.IRepositoryFile; |
214 | jmachado | 23 | import pt.estgp.estgweb.services.data.RepositoryService; |
444 | jmachado | 24 | import pt.estgp.estgweb.services.expceptions.AlreadyExistsException; |
995 | jmachado | 25 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
1789 | jmachado | 26 | import pt.estgp.estgweb.services.users.ReplaceRoleResult; |
1667 | jmachado | 27 | import pt.estgp.estgweb.services.users.UserRoleConfigService; |
1496 | jmachado | 28 | import pt.estgp.estgweb.utils.ConfigProperties; |
248 | jmachado | 29 | import pt.estgp.estgweb.utils.Dom4jUtil; |
1667 | jmachado | 30 | import pt.estgp.estgweb.utils.StringsUtils; |
417 | jmachado | 31 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
214 | jmachado | 32 | |
1496 | jmachado | 33 | import javax.xml.bind.JAXBContext; |
34 | import javax.xml.bind.JAXBException; |
||
35 | import javax.xml.bind.Marshaller; |
||
36 | import javax.xml.bind.Unmarshaller; |
||
1505 | jmachado | 37 | import java.io.*; |
1496 | jmachado | 38 | import java.net.URL; |
39 | import java.util.*; |
||
214 | jmachado | 40 | |
41 | /* |
||
42 | * @author Goncalo Luiz gedl [AT] rnl [DOT] ist [DOT] utl [DOT] pt |
||
43 | * |
||
44 | * |
||
45 | * Created at 17/Out/2003 , 23:45:24 |
||
46 | * |
||
47 | */ |
||
48 | /** |
||
49 | * @author Jorge Machado |
||
50 | * |
||
51 | * |
||
52 | * Created at 17/Out/2003 , 23:45:24 |
||
53 | * |
||
54 | */ |
||
55 | public class CoursesService implements IService |
||
56 | { |
||
57 | 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(CoursesService.class); |
||
58 | |||
59 | RepositoryService repositoryService = new RepositoryService(); |
||
60 | |||
61 | |||
1789 | jmachado | 62 | |
1505 | jmachado | 63 | /** |
64 | * Servico e subservico para termos acesso as variaveis de controlo |
||
65 | * @param id |
||
66 | * @param initUnits |
||
67 | * @return |
||
68 | * @throws ServiceException |
||
69 | */ |
||
70 | public CourseView loadCourse(long id, boolean initUnits) |
||
71 | throws ServiceException |
||
214 | jmachado | 72 | { |
1505 | jmachado | 73 | return loadCourse(id,initUnits,false); |
74 | } |
||
75 | public CourseView loadCourseAndStudiesPlans(long id, boolean initUnits) |
||
76 | throws ServiceException |
||
77 | { |
||
78 | return loadCourse(id,initUnits,true); |
||
79 | } |
||
80 | |||
81 | |||
82 | private CourseView loadCourse(long id, boolean initUnits,boolean loadStudiesPlans) throws ServiceException |
||
83 | { |
||
214 | jmachado | 84 | Course c = DaoFactory.getCourseDaoImpl().get(id); |
85 | |||
86 | if(c != null) |
||
87 | { |
||
1505 | jmachado | 88 | return getCourseView(initUnits, c,loadStudiesPlans); |
214 | jmachado | 89 | } |
90 | return null; |
||
91 | } |
||
92 | |||
1505 | jmachado | 93 | /** |
94 | * Servico e subservico para termos acesso as variaveis de controlo |
||
95 | * @param code |
||
96 | * @param initUnits |
||
97 | * @return |
||
98 | * @throws ServiceException |
||
99 | */ |
||
100 | |||
101 | public CourseView loadCourseByCode(1.5.0/docs/api/java/lang/String.html">String code, boolean initUnits) throws ServiceException |
||
345 | jmachado | 102 | { |
1505 | jmachado | 103 | return loadCourseByCode(code,initUnits,false); |
345 | jmachado | 104 | } |
1505 | jmachado | 105 | public CourseView loadCourseByCodeAndStudiesPlans(1.5.0/docs/api/java/lang/String.html">String code, boolean initUnits) throws ServiceException |
106 | { |
||
107 | return loadCourseByCode(code,initUnits,true); |
||
108 | } |
||
345 | jmachado | 109 | |
1505 | jmachado | 110 | |
111 | private CourseView loadCourseByCode(1.5.0/docs/api/java/lang/String.html">String code, boolean initUnits,boolean loadStudiesPlans) throws ServiceException |
||
214 | jmachado | 112 | { |
444 | jmachado | 113 | try{ |
114 | Course c = DaoFactory.getCourseDaoImpl().findCourseByCode(code); |
||
115 | if(c != null) |
||
214 | jmachado | 116 | { |
1505 | jmachado | 117 | return getCourseView(initUnits, c, loadStudiesPlans); |
214 | jmachado | 118 | } |
119 | } |
||
444 | jmachado | 120 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
121 | { |
||
122 | logger.error(e + " loading code:" + code,e); |
||
123 | throw new ServiceException("loading code: " + code + " - " + e.toString(),e); |
||
124 | } |
||
214 | jmachado | 125 | return null; |
126 | } |
||
127 | |||
1505 | jmachado | 128 | /** |
129 | * Carrega efetivamente o curso nos servicos load e load by code |
||
130 | * @param initUnits |
||
131 | * @param c |
||
132 | * @return |
||
133 | */ |
||
134 | |||
135 | private CourseView getCourseView(boolean initUnits, Course c,boolean loadStudiesPlans) { |
||
136 | CourseView cV = new CourseView(c,initUnits); |
||
137 | /* |
||
138 | * todo Parte antig antigo XML do plano de estudos para remover futuramente*/ |
||
139 | if(c.getStudiesPlan() != null) |
||
140 | { |
||
141 | RepositoryFileImpl repositoryFile = repositoryService.loadView(c.getStudiesPlan()); |
||
142 | cV.setStudiesPlan(repositoryFile); |
||
143 | } |
||
144 | if(loadStudiesPlans && c.getStudiesPlans() != null && c.getStudiesPlans().size() > 0) |
||
145 | { |
||
146 | for(CourseStudiesPlan sp : c.getStudiesPlans()) |
||
147 | { |
||
148 | sp.getVersion(); |
||
149 | cV.getCourseStudiesPlans().add(sp); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | return cV; |
||
154 | } |
||
155 | |||
156 | public List<String> loadImportYears(UserSession userSession) throws ServiceException |
||
157 | { |
||
158 | List<String> importYears = DaoFactory.getCourseDaoImpl().loadImportYears(); |
||
159 | List<String> imStrings = new ArrayList<String>(); |
||
160 | for(1.5.0/docs/api/java/lang/String.html">String importYear: importYears) |
||
161 | { |
||
162 | imStrings.add(importYear); |
||
163 | } |
||
164 | return imStrings; |
||
165 | } |
||
166 | |||
167 | |||
168 | |||
214 | jmachado | 169 | public CourseView submitCourse(CourseView courseView, |
170 | 5+0%2Fdocs%2Fapi+InputStream">InputStream stream, |
||
171 | 1.5.0/docs/api/java/lang/String.html">String name, |
||
172 | int size, |
||
173 | 1.5.0/docs/api/java/lang/String.html">String contentType, |
||
1776 | jmachado | 174 | UserSession userSession) throws ServiceException, JAXBException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
214 | jmachado | 175 | Course c; |
176 | if(courseView.getId() > 0) |
||
444 | jmachado | 177 | { |
214 | jmachado | 178 | c = DaoFactory.getCourseDaoImpl().get(courseView.getId()); |
444 | jmachado | 179 | } |
214 | jmachado | 180 | else |
181 | { |
||
444 | jmachado | 182 | c = DaoFactory.getCourseDaoImpl().findCourseByCodeAndYear(courseView.getCode(),courseView.getImportYear()); |
183 | if(c != null) |
||
184 | throw new AlreadyExistsException(AlreadyExistsException.ALREADY_EXISTS_COURSE); |
||
214 | jmachado | 185 | c = DomainObjectFactory.createCourseImpl(); |
186 | DaoFactory.getCourseDaoImpl().save(c); |
||
187 | } |
||
188 | |||
248 | jmachado | 189 | 1.5.0/docs/api/java/lang/String.html">String htmlTrasformationResult = null; |
190 | |||
1505 | jmachado | 191 | //Stream que pode vir do upload da UIde Admin de Cursos |
1496 | jmachado | 192 | htmlTrasformationResult = uploadStudiesPlan(stream, name, size, contentType, userSession, c,false,null); |
193 | courseView.persistViewInObject(c); |
||
194 | CourseView cv = loadCourse(c.getId(),false); |
||
195 | cv.setHtmlResult(htmlTrasformationResult); |
||
196 | |||
197 | /** |
||
198 | * New## generating course json |
||
199 | */ |
||
200 | generateCourseJson(c); |
||
201 | |||
202 | return cv; |
||
203 | } |
||
204 | |||
1776 | jmachado | 205 | private 1.5.0/docs/api/java/lang/String.html">String uploadStudiesPlan(5+0%2Fdocs%2Fapi+InputStream">InputStream stream, 1.5.0/docs/api/java/lang/String.html">String name, int size, 1.5.0/docs/api/java/lang/String.html">String contentType, UserSession userSession, Course c,boolean forceUrlFichas, 1.5.0/docs/api/java/lang/String.html">String systemUrl) throws JAXBException { |
1496 | jmachado | 206 | 1.5.0/docs/api/java/lang/String.html">String htmlTrasformationResult = null; |
1505 | jmachado | 207 | //APENAS NO CASO DO AMDIN FAZER UPLOAD DE UM XML |
214 | jmachado | 208 | if(stream != null && size > 0) |
209 | { |
||
268 | jmachado | 210 | 1.5.0/docs/api/java/lang/String.html">String extension = FilesUtils.getExtension(name); |
211 | if(c.getStudiesPlan() == null) |
||
212 | { |
||
1703 | jmachado | 213 | 1.5.0/docs/api/java/lang/String.html">String identifier = repositoryService.storeRepositoryFile(stream, contentType, extension, size, name, "course.studies.plan " + c.getName(), ResourceAccessControlEnum.publicDomain, null, userSession); |
268 | jmachado | 214 | c.setStudiesPlan(identifier); |
215 | } |
||
216 | else |
||
217 | { |
||
218 | repositoryService.updateRepositoryFile(c.getStudiesPlan(), stream, contentType, extension, size, name, "course.studies.plan " + c.getName(), ResourceAccessControlEnum.publicDomain); |
||
219 | } |
||
1496 | jmachado | 220 | htmlTrasformationResult = generateHtmlCache(userSession, c); |
221 | //####New#### Generating XML with JaxB |
||
1505 | jmachado | 222 | //ISTO SO É CHAMADO NO CASO DE SE FAZER UPLOAD DE UM NOVO PLANO PELO MECANISMO ANTIGO |
223 | generateXmlJaxbStudiesPlanVersionFromRepositoryOldPlanStream(userSession, c, forceUrlFichas, systemUrl); |
||
1496 | jmachado | 224 | } |
225 | return htmlTrasformationResult; |
||
226 | } |
||
227 | |||
1505 | jmachado | 228 | |
229 | |||
1776 | jmachado | 230 | private void generateCourseJson(Course cAux) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
1496 | jmachado | 231 | CourseImpl c = (CourseImpl) DaoFactory.getCourseDaoImpl().narrow(cAux); |
232 | |||
233 | if(c.getValidationRole() != null && c.getValidationRole().trim().length() > 0) |
||
234 | { |
||
235 | List<Teacher> courseComissionProxys = DaoFactory.getUserDaoImpl().loadRoleTeachers(c.getValidationRole()); |
||
236 | List<Teacher> courseComission = new ArrayList<Teacher>(); |
||
237 | for(Teacher t: courseComissionProxys) |
||
248 | jmachado | 238 | { |
1496 | jmachado | 239 | courseComission.add(DaoFactory.getTeacherDaoImpl().narrow(t)); |
248 | jmachado | 240 | } |
1496 | jmachado | 241 | c.setCourseComission(courseComission); |
242 | } |
||
243 | //Getting Coordinator from proxy |
||
244 | Teacher t = c.getCoordinator(); |
||
1500 | jmachado | 245 | if(t != null) |
246 | t.getName(); |
||
247 | else |
||
248 | { |
||
249 | logger.warn("Course does not have coordinator"); |
||
250 | } |
||
1496 | jmachado | 251 | |
252 | 1.5.0/docs/api/java/lang/String.html">String jsonCourse = getGensonCourse().serialize(c); |
||
253 | c.setJson(jsonCourse); |
||
254 | } |
||
255 | |||
256 | private 1.5.0/docs/api/java/lang/String.html">String generateHtmlCache(UserSession userSession, Course c) { |
||
257 | 1.5.0/docs/api/java/lang/String.html">String htmlTrasformationResult = null; |
||
258 | 5+0%2Fdocs%2Fapi+InputStream">InputStream stream;IRepositoryFile repositoryFile = repositoryService.load(c.getStudiesPlan(),userSession); |
||
259 | stream = repositoryFile.getInput(); |
||
260 | try |
||
261 | { |
||
262 | 5+0%2Fdocs%2Fapi+Document">Document dom = Dom4jUtil.parse(stream); |
||
263 | Map<String,Object> parameters = new HashMap<String,Object>(); |
||
264 | parameters.put("COURSE_SIGES_CODE",c.getCode()); |
||
265 | 1.5.0/docs/api/java/lang/String.html">String html = Dom4jUtil.styleDocument(dom, Globals.TEMPLATE_COURSE_XSL_PATH,parameters); |
||
266 | c.setCacheWebDocument(html); |
||
267 | } |
||
268 | catch (1.5.0/docs/api/java/lang/Exception.html">Exception e) |
||
269 | { |
||
270 | 1.5.0/docs/api/java/io/StringWriter.html">StringWriter writer = new 1.5.0/docs/api/java/io/StringWriter.html">StringWriter(); |
||
271 | 1.5.0/docs/api/java/io/PrintWriter.html">PrintWriter printWriter = new 1.5.0/docs/api/java/io/PrintWriter.html">PrintWriter(writer); |
||
272 | e.printStackTrace(printWriter); |
||
273 | htmlTrasformationResult = "<div class=\"error\"><pre>" + e.toString() + "\n" + printWriter.toString() + "</pre></div>"; |
||
274 | printWriter.close(); |
||
275 | } |
||
276 | try |
||
277 | { |
||
278 | stream.close(); |
||
279 | } |
||
280 | catch (1.5.0/docs/api/java/io/IOException.html">IOException e) |
||
281 | { |
||
282 | logger.error(e,e); |
||
283 | } |
||
284 | return htmlTrasformationResult; |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * ##NEW METHOD### |
||
289 | * Gera o XML normalizado para o JAXB a partir do XML importado do XML do plano XML quese usou no upload |
||
290 | * para garantir que está bem formado |
||
291 | * @param userSession |
||
292 | * @param c |
||
293 | * @return |
||
294 | * @throws JAXBException if XML is not weel formed |
||
295 | */ |
||
1776 | jmachado | 296 | private void generateXmlJaxbStudiesPlanVersionFromRepositoryOldPlanStream(UserSession userSession, Course c, boolean forceFichaCurricularUrlSet, 1.5.0/docs/api/java/lang/String.html">String systemUrlForUnitPrograms) throws JAXBException |
1496 | jmachado | 297 | { |
298 | CourseStudiesPlan courseStudiesPlan; |
||
1500 | jmachado | 299 | if(c.getStudiesPlan() == null || c.getStudiesPlan().trim().length() == 0) |
300 | { |
||
1505 | jmachado | 301 | //ESTE É O STREAM DO PLANO DE UPLOAD |
1500 | jmachado | 302 | logger.warn("Course does not have studies plan XML file stream to use in update"); |
303 | return; |
||
304 | } |
||
1496 | jmachado | 305 | |
306 | if(c.getStudiesPlans() == null || c.getStudiesPlans().size() == 0) |
||
307 | { |
||
308 | logger.info("Generating first study plan"); |
||
309 | courseStudiesPlan = DomainObjectFactory.createCourseStudiesPlanImpl(); |
||
310 | courseStudiesPlan.setVersion(1); |
||
311 | courseStudiesPlan.setVersionDescription("Auto gerado durante a importação de um XML com o plano de estudos a " + new 5+0%2Fdocs%2Fapi+Date">Date().toString()); |
||
312 | courseStudiesPlan.setCourse(c); |
||
313 | if(c.getStudiesPlans() == null) |
||
314 | c.setStudiesPlans(new HashSet<CourseStudiesPlan>()); |
||
315 | c.getStudiesPlans().add(courseStudiesPlan); |
||
316 | DaoFactory.getCourseStudiesPlanDaoImpl().save(courseStudiesPlan); |
||
317 | } |
||
318 | else |
||
319 | { |
||
320 | courseStudiesPlan = c.getStudiesPlans().iterator().next(); |
||
321 | logger.info("Updating Study Plan version " + courseStudiesPlan.getVersion()); |
||
322 | } |
||
323 | |||
324 | 5+0%2Fdocs%2Fapi+InputStream">InputStream stream; |
||
325 | IRepositoryFile repositoryFile = repositoryService.load(c.getStudiesPlan(),userSession); |
||
1502 | jmachado | 326 | long lastVersion = repositoryService.loadView(c.getStudiesPlan()).getLastVersion().getId(); |
1514 | jmachado | 327 | //stream = repositoryFile.getInput(); |
1503 | jmachado | 328 | //TODO TIRAR |
329 | //JUST FOR DEBUG |
||
1514 | jmachado | 330 | /* try { |
1503 | jmachado | 331 | System.out.println(StreamsUtils.readString(stream)); |
332 | stream.close(); |
||
333 | } catch (IOException e) { |
||
334 | e.printStackTrace(); |
||
1514 | jmachado | 335 | }*/ |
1503 | jmachado | 336 | repositoryFile = repositoryService.load(c.getStudiesPlan(),userSession); |
337 | stream = repositoryFile.getInput(); |
||
1496 | jmachado | 338 | |
339 | try { |
||
340 | JAXBContext jc = JAXBContext.newInstance(Curso.class); |
||
341 | Unmarshaller unmarshaller = jc.createUnmarshaller(); |
||
1503 | jmachado | 342 | //Just in case lets update SigesCode |
1496 | jmachado | 343 | Curso curso = (Curso) unmarshaller.unmarshal(stream); |
1503 | jmachado | 344 | curso.setSiges(c.getCode()); |
1505 | jmachado | 345 | curso.setNome(c.getName()); |
346 | curso.setDep(c.getArea()); |
||
1496 | jmachado | 347 | |
1505 | jmachado | 348 | //##NOVO PARA GERAR LINK SE NAO EXISTIR |
349 | generateAutoUrlFichasCurriculares(curso,systemUrlForUnitPrograms,forceFichaCurricularUrlSet); |
||
350 | |||
1496 | jmachado | 351 | Marshaller marshaller = jc.createMarshaller(); |
352 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); |
||
353 | 1.5.0/docs/api/java/io/StringWriter.html">StringWriter sw = new 1.5.0/docs/api/java/io/StringWriter.html">StringWriter(); |
||
354 | marshaller.marshal(curso, sw); |
||
355 | //SETTING XML in COURSE STUDIES PLAN |
||
356 | courseStudiesPlan.setXml(sw.toString()); |
||
1505 | jmachado | 357 | |
358 | |||
1789 | jmachado | 359 | 1.5.0/docs/api/java/lang/String.html">String json = CursoImpl.getGensonPlanoEstudosParaApiJsonWS().serialize(curso); |
1496 | jmachado | 360 | //SETTING JSON in COURSE STUDIES PLAN |
361 | courseStudiesPlan.setJson(json); |
||
362 | |||
363 | } catch (JAXBException e) { |
||
364 | logger.error(e,e); |
||
1502 | jmachado | 365 | 1.5.0/docs/api/java/lang/System.html">System.out.print("check XML for possible errors for repositoryStream:" + c.getStudiesPlan() + " file version: " + lastVersion); |
1496 | jmachado | 366 | throw e; |
367 | } |
||
368 | try |
||
369 | { |
||
370 | stream.close(); |
||
371 | } |
||
372 | catch (1.5.0/docs/api/java/io/IOException.html">IOException e) |
||
373 | { |
||
374 | logger.error(e,e); |
||
375 | } |
||
376 | } |
||
377 | |||
1505 | jmachado | 378 | |
1506 | jmachado | 379 | /** |
380 | * Apenas é chamado quando se tenta injectar um programa a partir de um upload que foi feito |
||
381 | * pelo user ou pela sincronização remota |
||
382 | * @param curso |
||
383 | * @param systemUrl |
||
384 | * @param force |
||
385 | */ |
||
1496 | jmachado | 386 | private void generateAutoUrlFichasCurriculares(Curso curso,1.5.0/docs/api/java/lang/String.html">String systemUrl,boolean force) |
387 | { |
||
388 | for(Curso.Semestre s :curso.getSemestre()) |
||
389 | { |
||
390 | for(Curso.Semestre.Perfil p :s.getPerfil()) |
||
248 | jmachado | 391 | { |
1496 | jmachado | 392 | for(UnidadeType unidadeType : p.getUnidade()) |
393 | { |
||
394 | generateAutoUrlUnidade(unidadeType,systemUrl,curso,s,force); |
||
395 | } |
||
248 | jmachado | 396 | } |
1496 | jmachado | 397 | for(UnidadeType unidadeType : s.getUnidade()) |
214 | jmachado | 398 | { |
1496 | jmachado | 399 | generateAutoUrlUnidade(unidadeType,systemUrl,curso,s,force); |
214 | jmachado | 400 | } |
401 | } |
||
402 | } |
||
403 | |||
1496 | jmachado | 404 | private void generateAutoUrlUnidade(UnidadeType unidadeType,1.5.0/docs/api/java/lang/String.html">String systemUrl,Curso curso,Curso.Semestre semestre,boolean force) |
405 | { |
||
406 | if(force || unidadeType.getUrlFichaCurricular() == null || unidadeType.getUrlFichaCurricular().trim().length()==0) |
||
407 | { |
||
408 | logger.info("GENERATING FICHA CURRICULAR URL For " + unidadeType.getNome()); |
||
409 | 1.5.0/docs/api/java/lang/String.html">String url = systemUrl != null ? systemUrl : ""; |
||
1504 | jmachado | 410 | if(!url.endsWith("/")) |
1496 | jmachado | 411 | url = url + "/"; |
1504 | jmachado | 412 | |
1505 | jmachado | 413 | //Nao fornece o ano pois o servico irá assumir o ultimo |
1504 | jmachado | 414 | unidadeType.setUrlFichaCurricular(url + "startLoadCourseUnitProgramSiges.do?unitCode=" + unidadeType.getSiges() + "&courseCode=" + curso.getSiges() + "&semestre=" + semestre.getId()); |
415 | unidadeType.setUrlUnidadeCurricular(url + "startLoadCourseUnitSiges.do?unitCode=" + unidadeType.getSiges() + "&courseCode=" + curso.getSiges() + "&semestre=" + semestre.getId()); |
||
1496 | jmachado | 416 | } |
417 | } |
||
418 | |||
419 | |||
420 | private static Genson getGensonCourse(){ |
||
1784 | jmachado | 421 | Genson genson = new GensonBuilder() |
1496 | jmachado | 422 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
1776 | jmachado | 423 | .useFields(false) |
424 | .useMethods(true) |
||
1496 | jmachado | 425 | .setMethodFilter(VisibilityFilter.PACKAGE_PUBLIC) |
426 | .exclude("admin") |
||
427 | .exclude("autoBlock") |
||
428 | .exclude("autoBlockMode") |
||
429 | .exclude("manualBlock") |
||
430 | .exclude("newUser") |
||
431 | .exclude("student") |
||
432 | .exclude("superuser") |
||
433 | .exclude("superuserOrAdmin") |
||
434 | .exclude("teacher") |
||
435 | .exclude("unitCheck") |
||
436 | .exclude("id") |
||
437 | |||
438 | /* .exclude(Course.class) |
||
439 | .exclude(CourseImpl.class) |
||
440 | .exclude(GenericUser.class) |
||
441 | .exclude(User.class) |
||
442 | .exclude(UserImpl.class) |
||
443 | .exclude(Teacher.class) |
||
444 | .exclude(TeacherImpl.class) |
||
445 | .exclude(SigesUser.class) |
||
446 | .exclude(SigesUserImpl.class) |
||
447 | .exclude(GenericUser.class) |
||
448 | .exclude(GenericUserImpl.class) |
||
449 | */ |
||
450 | .exclude("id", Course.class) |
||
1505 | jmachado | 451 | .exclude("status", Course.class) |
1521 | jmachado | 452 | .exclude("showStudiesPlan", Course.class) |
1496 | jmachado | 453 | .include("degreeForJsonApi", CourseImpl.class) |
1543 | jmachado | 454 | .include("degreeForJsonApiEn", CourseImpl.class) |
455 | .include("degreeForJsonApiEs", CourseImpl.class) |
||
456 | .include("degreeForJsonApiFr", CourseImpl.class) |
||
1496 | jmachado | 457 | .include("schoolForJsonApi", CourseImpl.class) |
458 | .include("statusForJsonApi", CourseImpl.class) |
||
459 | |||
1789 | jmachado | 460 | |
1496 | jmachado | 461 | .include("name", Course.class) |
1505 | jmachado | 462 | .include("nameEn", Course.class) |
463 | .include("nameEs", Course.class) |
||
464 | .include("nameFr", Course.class) |
||
465 | .include("department", Course.class) |
||
466 | .exclude("active", CourseDepartment.class) |
||
467 | .include("sigla", CourseDepartment.class) |
||
468 | .include("name", CourseDepartment.class) |
||
469 | .include("nameEn", CourseDepartment.class) |
||
470 | .include("nameEs", CourseDepartment.class) |
||
471 | .include("nameFr", CourseDepartment.class) |
||
1496 | jmachado | 472 | .include("code", Course.class) |
1500 | jmachado | 473 | .include("validationRole", Course.class) |
474 | |||
1496 | jmachado | 475 | .include("courseComission", CourseImpl.class) |
476 | |||
477 | .include("name", GenericUser.class) |
||
478 | .include("email", GenericUser.class) |
||
479 | .include("sigesCode", SigesUser.class) |
||
480 | .include("coordinator", Course.class) |
||
481 | .create(); |
||
482 | |||
483 | return genson; |
||
484 | } |
||
485 | |||
486 | |||
487 | |||
214 | jmachado | 488 | public List<CourseView> loadCourses() throws ServiceException |
489 | { |
||
490 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAllOrderByName(); |
||
491 | List<CourseView> courseViews = new ArrayList<CourseView>(); |
||
492 | for(Course c: courses) |
||
493 | { |
||
494 | CourseView courseView = new CourseView(c); |
||
495 | courseViews.add(courseView); |
||
496 | } |
||
497 | return courseViews; |
||
498 | } |
||
499 | |||
376 | jmachado | 500 | public List<CourseView> loadCoursesImportYearArea(1.5.0/docs/api/java/lang/String.html">String importYear, 1.5.0/docs/api/java/lang/String.html">String area) throws ServiceException |
501 | { |
||
1312 | jmachado | 502 | return loadCoursesImportYearAreaInstitution(importYear, area,null); |
503 | } |
||
504 | |||
505 | public List<CourseView> loadCoursesImportYearAreaInstitution(1.5.0/docs/api/java/lang/String.html">String importYear, 1.5.0/docs/api/java/lang/String.html">String area,1.5.0/docs/api/java/lang/String.html">String institutionCode) throws ServiceException |
||
506 | { |
||
507 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAllOrderByName(importYear,area,null,institutionCode); |
||
376 | jmachado | 508 | List<CourseView> courseViews = new ArrayList<CourseView>(); |
509 | for(Course c: courses) |
||
510 | { |
||
511 | CourseView courseView = new CourseView(c); |
||
512 | courseViews.add(courseView); |
||
513 | } |
||
514 | return courseViews; |
||
515 | } |
||
516 | |||
249 | jmachado | 517 | public List<CourseView> loadCoursesImportYear() throws ServiceException |
518 | { |
||
995 | jmachado | 519 | 1.5.0/docs/api/java/lang/String.html">String importYearIntranet = DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear(); |
249 | jmachado | 520 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAllOrderByName(importYearIntranet); |
521 | List<CourseView> courseViews = new ArrayList<CourseView>(); |
||
522 | for(Course c: courses) |
||
523 | { |
||
524 | CourseView courseView = new CourseView(c); |
||
525 | courseViews.add(courseView); |
||
526 | } |
||
527 | return courseViews; |
||
528 | } |
||
417 | jmachado | 529 | public List<CourseView> loadCoursesImportYearByType(1.5.0/docs/api/java/lang/String.html">String type) throws ServiceException |
530 | { |
||
995 | jmachado | 531 | 1.5.0/docs/api/java/lang/String.html">String importYearIntranet = DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear(); |
695 | jmachado | 532 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAllOrderByNameEvenWithoutCourseUnit(importYearIntranet,null,type); |
417 | jmachado | 533 | List<CourseView> courseViews = new ArrayList<CourseView>(); |
534 | for(Course c: courses) |
||
535 | { |
||
536 | CourseView courseView = new CourseView(c); |
||
537 | courseViews.add(courseView); |
||
538 | } |
||
539 | return courseViews; |
||
540 | } |
||
214 | jmachado | 541 | |
790 | jmachado | 542 | public List<CourseView> loadActiveCoursesByType(1.5.0/docs/api/java/lang/String.html">String type) throws ServiceException |
543 | { |
||
995 | jmachado | 544 | 1.5.0/docs/api/java/lang/String.html">String importYearIntranet = DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear(); |
790 | jmachado | 545 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAllActiveOrderByNameEvenWithoutCourseUnit(importYearIntranet,null,type); |
546 | List<CourseView> courseViews = new ArrayList<CourseView>(); |
||
547 | for(Course c: courses) |
||
548 | { |
||
549 | CourseView courseView = new CourseView(c); |
||
550 | courseViews.add(courseView); |
||
551 | } |
||
552 | return courseViews; |
||
553 | } |
||
249 | jmachado | 554 | |
1500 | jmachado | 555 | |
556 | |||
557 | /** JSON API **/ |
||
558 | /** |
||
559 | * @SERVICE@ |
||
560 | * |
||
561 | * @param school |
||
562 | * @param type |
||
563 | * @return |
||
564 | * @throws JSONException |
||
565 | */ |
||
1496 | jmachado | 566 | public JSONObject getActiveCoursesForJsonApi(1.5.0/docs/api/java/lang/String.html">String school,1.5.0/docs/api/java/lang/String.html">String type) throws JSONException { |
567 | 1.5.0/docs/api/java/lang/String.html">String institutionalCode = null; |
||
568 | 1.5.0/docs/api/java/lang/String.html">String degree = null; |
||
569 | if(school != null && school.length() > 0) |
||
570 | institutionalCode = ConfigProperties.getProperty("institution.code.prefix.inverse." + school); |
||
249 | jmachado | 571 | |
1496 | jmachado | 572 | if(type != null && type.length() > 0) |
573 | degree = ConfigProperties.getProperty("course.inverse." + type); |
||
790 | jmachado | 574 | |
1521 | jmachado | 575 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAllShowStudiesPlanCoursesOrderByNameEvenWithoutCourseUnit(institutionalCode, degree); |
1496 | jmachado | 576 | JSONObject coursesResponse = new JSONObject(); |
577 | |||
578 | JSONArray coursesArray = new JSONArray(); |
||
579 | for(Course cAux: courses) |
||
580 | { |
||
581 | CourseImpl c = (CourseImpl) DaoFactory.getCourseDaoImpl().narrow(cAux); |
||
582 | JSONObject courseJson = new JSONObject(); |
||
583 | courseJson.put("name",c.getName()); |
||
584 | courseJson.put("code",c.getCode()); |
||
585 | courseJson.put("schoolForJsonApi",c.getSchoolForJsonApi()); |
||
586 | courseJson.put("degreeForJsonApi",c.getDegreeForJsonApi()); |
||
1543 | jmachado | 587 | courseJson.put("degreeForJsonApiEn",c.getDegreeForJsonApiEn()); |
588 | courseJson.put("degreeForJsonApiEs",c.getDegreeForJsonApiEs()); |
||
589 | courseJson.put("degreeForJsonApiFr",c.getDegreeForJsonApiFr()); |
||
1496 | jmachado | 590 | courseJson.put("statusForJsonApi",c.getStatusForJsonApi()); |
591 | courseJson.put("getDetailedInfoUrl","/wsjson/api?service=getCourse&code=" + c.getCode()); |
||
592 | coursesArray.put(courseJson); |
||
593 | |||
594 | } |
||
595 | coursesResponse.put("status","ok"); |
||
596 | coursesResponse.put("courses",coursesArray); |
||
597 | |||
598 | return coursesResponse; |
||
599 | } |
||
600 | |||
1500 | jmachado | 601 | /** |
602 | * |
||
1505 | jmachado | 603 | * * Serviço invocado para obter o JSON de um curso |
604 | * O JSON tem dois campos o courseInfo e o plano de estudos colocados separadamente |
||
1500 | jmachado | 605 | * |
1505 | jmachado | 606 | * Atenção o plano de estudos usado é o ultimo considerando o seu ID |
607 | * Nota: O plano de Estudos é uma classe persistente que tem apenas versão e descrição |
||
608 | * deverá ter como campo o XML e o JSON já gerados do plano de estudos que comporta |
||
609 | * |
||
1789 | jmachado | 610 | * //TODO REVER |
1500 | jmachado | 611 | * @param code |
612 | * @return |
||
613 | * @throws JSONException |
||
614 | * @throws IOException |
||
615 | * @throws JAXBException |
||
616 | */ |
||
1776 | jmachado | 617 | public JSONObject getCourseDetailForJsonApi(1.5.0/docs/api/java/lang/String.html">String code) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException, JAXBException { |
1496 | jmachado | 618 | |
619 | Course course = DaoFactory.getCourseDaoImpl().findCourseByCode(code); |
||
620 | |||
621 | |||
622 | JSONObject coursesResponse = new JSONObject(); |
||
623 | |||
1740 | jmachado | 624 | generateCourseJson(course); |
1498 | jmachado | 625 | |
1779 | jmachado | 626 | //if(course.toJson() == null) |
1740 | jmachado | 627 | //{ |
628 | // logger.info("status JSON NOT EXIST FOR STUDIES PLAN IN THIS COURSE, will generate"); |
||
629 | // new CoursesService().generateCourseJson(course); |
||
630 | //} |
||
631 | |||
1496 | jmachado | 632 | if(course.getJson() != null) |
633 | { |
||
634 | JSONObject courseObj = new JSONObject(course.getJson()); |
||
635 | coursesResponse.put("courseInfo",courseObj); |
||
1505 | jmachado | 636 | //Este caso apenas se dá se o plano nunca tiver sido editado ou sincronizado |
637 | //Nesse caso o sistema irá tentar obtê-lo da stream do repositorio |
||
1500 | jmachado | 638 | if(course.getStudiesPlans() == null || course.getStudiesPlans().size() == 0) |
1498 | jmachado | 639 | { |
1505 | jmachado | 640 | logger.info("status JSON NOT EXIST FOR STUDIES PLAN IN THIS COURSE, will try generate from studies plan OLD Stream"); |
1498 | jmachado | 641 | UserSession userSession = DomainObjectFactory.createUserSessionImpl(); |
642 | userSession.setUser(DaoFactory.getUserDaoImpl().load(new 1.5.0/docs/api/java/lang/Long.html">Long(1))); |
||
1505 | jmachado | 643 | new CoursesService().generateXmlJaxbStudiesPlanVersionFromRepositoryOldPlanStream(userSession, course, false, null); |
1498 | jmachado | 644 | } |
645 | |||
1505 | jmachado | 646 | if(course.getStudiesPlans() != null ) |
1496 | jmachado | 647 | { |
648 | CourseStudiesPlan studiesPlan = course.getStudiesPlans().iterator().next(); |
||
1505 | jmachado | 649 | JSONObject studiesPlanObj; |
650 | if(studiesPlan.getJson() != null) |
||
651 | { |
||
1789 | jmachado | 652 | CursoImpl c = CursoImpl.loadFromJson(studiesPlan.getJson()); |
653 | autoFillTotalHorasContacto(c); |
||
654 | studiesPlanObj = c.toJsonObjectJsonApiWS(); |
||
1505 | jmachado | 655 | studiesPlanObj.put("version",studiesPlan.getVersion()); |
656 | coursesResponse.put("courseStudiesPlan",studiesPlanObj); |
||
657 | } |
||
658 | else |
||
659 | { |
||
660 | studiesPlanObj = new JSONObject(); |
||
661 | studiesPlanObj.put("fault","Zero contents for this version"); |
||
662 | studiesPlanObj.put("version",studiesPlan.getVersion()); |
||
663 | coursesResponse.put("courseStudiesPlan",studiesPlanObj); |
||
664 | } |
||
1496 | jmachado | 665 | coursesResponse.put("courseStudiesPlan",studiesPlanObj); |
1505 | jmachado | 666 | |
1496 | jmachado | 667 | } |
668 | else |
||
669 | { |
||
670 | coursesResponse.put("status","JSON NOT EXIST FOR STUDIES PLAN IN THIS COURSE"); |
||
671 | } |
||
672 | } |
||
673 | else |
||
674 | { |
||
1505 | jmachado | 675 | coursesResponse.put("status","JSON NOT EXIST FOR COURSE, PLEASE OPEN AND SAVE COURSE IN ADMINISTRATION"); |
1496 | jmachado | 676 | } |
677 | return coursesResponse; |
||
678 | } |
||
679 | |||
1500 | jmachado | 680 | /** |
681 | * @SERVICE@ |
||
682 | * |
||
683 | * @param code |
||
684 | * @return |
||
685 | * @throws JSONException |
||
686 | */ |
||
1502 | jmachado | 687 | public 1.5.0/docs/api/java/lang/String.html">String getCourseStudiesPlanXml(1.5.0/docs/api/java/lang/String.html">String code,1.5.0/docs/api/java/lang/String.html">String renew) throws JSONException { |
1496 | jmachado | 688 | |
689 | Course course = DaoFactory.getCourseDaoImpl().findCourseByCode(code); |
||
1501 | jmachado | 690 | |
1502 | jmachado | 691 | if(renew != null || course.getStudiesPlans() == null || course.getStudiesPlans().size() == 0) |
1501 | jmachado | 692 | { |
693 | logger.info("status JSON NOT EXIST FOR STUDIES PLAN IN THIS COURSE, will generate"); |
||
694 | UserSession userSession = DomainObjectFactory.createUserSessionImpl(); |
||
695 | userSession.setUser(DaoFactory.getUserDaoImpl().load(new 1.5.0/docs/api/java/lang/Long.html">Long(1))); |
||
696 | try { |
||
1505 | jmachado | 697 | generateXmlJaxbStudiesPlanVersionFromRepositoryOldPlanStream(userSession, course, false, null); |
1501 | jmachado | 698 | } catch (JAXBException e) { |
699 | logger.error(e,e); |
||
700 | return "<error>" + e.toString() + ". see log for details</error>"; |
||
701 | } |
||
702 | } |
||
703 | |||
1496 | jmachado | 704 | if(course.getStudiesPlans() != null && course.getStudiesPlans().size() > 0) |
705 | { |
||
706 | return course.getStudiesPlans().iterator().next().getXml(); |
||
707 | } |
||
708 | return "<error>Does not exixt</error>"; |
||
709 | |||
710 | } |
||
711 | |||
712 | |||
1500 | jmachado | 713 | /** |
714 | * @SERVICE@ |
||
715 | * |
||
716 | * @param systemUrl |
||
717 | * @param setActive |
||
718 | * @return |
||
719 | * @throws IOException |
||
720 | * @throws JSONException |
||
721 | * @throws JAXBException |
||
722 | */ |
||
1496 | jmachado | 723 | |
1776 | jmachado | 724 | public 1.5.0/docs/api/java/lang/String.html">String sincronizeCoursesStudiesPlans(1.5.0/docs/api/java/lang/String.html">String systemUrl,boolean setActive,UserSession sess) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, JAXBException { |
1496 | jmachado | 725 | |
1497 | jmachado | 726 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder log = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
727 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(systemUrl + "/wsjson/api?service=listCourses"); |
||
1496 | jmachado | 728 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream(); |
729 | 1.5.0/docs/api/java/lang/String.html">String str = StreamsUtils.readString(is); |
||
730 | JSONObject obj = new JSONObject(str); |
||
731 | JSONArray courses = obj.getJSONArray("courses"); |
||
732 | for(int i = 0; i < courses.length();i++) |
||
733 | { |
||
1502 | jmachado | 734 | 1.5.0/docs/api/java/lang/String.html">String code = ""; |
735 | try{ |
||
736 | JSONObject course = courses.getJSONObject(i); |
||
737 | code = course.getString("code"); |
||
738 | Course c = DaoFactory.getCourseDaoImpl().findCourseByCode(code); |
||
739 | if(c == null) |
||
740 | { |
||
741 | 1.5.0/docs/api/java/lang/String.html">String msg = "SKIPING - Course " + code + " " + course.getString("name") + " does not exist in this system"; |
||
742 | log.append("<info>" + msg+"</info>"); |
||
743 | logger.info(msg); |
||
744 | } |
||
745 | else |
||
746 | { |
||
747 | 1.5.0/docs/api/java/lang/String.html">String msg = "UPDATING - Course " + code + " " + course.getString("name") + " exist in this system"; |
||
748 | log.append("<info>" + msg+"</info>"); |
||
749 | logger.info(msg); |
||
1500 | jmachado | 750 | |
1505 | jmachado | 751 | //#############UPDATING Course Comission Members |
1516 | jmachado | 752 | updateCourseComissionMembersAndCourseInfo(systemUrl, code, c); |
1505 | jmachado | 753 | |
1502 | jmachado | 754 | //#############UPDATING STUDIES PLAN |
755 | updateStudiesPlanFromRemoteSystem(systemUrl, setActive, log, course, code, c); |
||
1500 | jmachado | 756 | |
1505 | jmachado | 757 | |
1502 | jmachado | 758 | } |
1500 | jmachado | 759 | } |
1502 | jmachado | 760 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
761 | { |
||
762 | logger.error("UPDATE COURSE: " + i + " code: " + code + " FAILED"); |
||
763 | logger.error(e,e); |
||
764 | } |
||
1500 | jmachado | 765 | } |
766 | return log.toString(); |
||
767 | |||
768 | } |
||
769 | |||
1776 | jmachado | 770 | private void updateStudiesPlanFromRemoteSystem(1.5.0/docs/api/java/lang/String.html">String systemUrl, boolean setActive, 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder log, JSONObject course, 1.5.0/docs/api/java/lang/String.html">String code, Course c) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException, JAXBException { |
1505 | jmachado | 771 | 1.5.0/docs/api/java/lang/String.html">String msg; |
772 | 5+0%2Fdocs%2Fapi+InputStream">InputStream stream = new 1.5.0/docs/api/java/net/URL.html">URL(systemUrl + "/wsjson/api?service=getStudiesPlanXml&code=" + code + "&renew=true").openStream(); |
||
773 | 1.5.0/docs/api/java/lang/String.html">String studiesPlan = StreamsUtils.readString(stream); |
||
774 | int len = studiesPlan.length(); |
||
775 | if(studiesPlan == null || studiesPlan.trim().length() == 0 || studiesPlan.contains("<error>")) |
||
776 | { |
||
777 | msg = "Course " + code + " " + course.getString("name") + " dont has studies plan"; |
||
778 | log.append("<warn>" + msg+"</warn>"); |
||
779 | logger.warn(msg); |
||
780 | } |
||
781 | else |
||
782 | { |
||
783 | msg = "Found studies plan for " + code + " " + course.getString("name") + " will update "; |
||
784 | log.append("<info>" + msg+"</info>"); |
||
785 | logger.info(msg); |
||
786 | if(setActive) |
||
787 | { |
||
788 | msg = "Setting course to active"; |
||
789 | log.append("<info>" + msg+"</info>"); |
||
790 | logger.info(msg); |
||
791 | c.setStatus(true); |
||
792 | } |
||
793 | //System.out.println(studiesPlan); |
||
794 | msg = "GENERATING COURSE JSON ...."; |
||
795 | log.append("<info>" + msg+"</info>"); |
||
796 | logger.info(msg); |
||
797 | new CoursesService().generateCourseJson(c); |
||
798 | |||
799 | msg="GENERATING COURSE STUDIES PLAN JSON ...."; |
||
800 | log.append("<info>" + msg+"</info>"); |
||
801 | logger.info(msg); |
||
802 | stream.close(); |
||
803 | stream = new 1.5.0/docs/api/java/net/URL.html">URL(systemUrl + "/wsjson/api?service=getStudiesPlanXml&code=" + code).openStream(); |
||
804 | UserSession userSession = DomainObjectFactory.createUserSessionImpl(); |
||
805 | userSession.setUser(DaoFactory.getUserDaoImpl().load(new 1.5.0/docs/api/java/lang/Long.html">Long(1))); |
||
806 | new CoursesService().uploadStudiesPlan(stream, "curso_" + code + ".xml", len,"appication/xml", userSession,c,true,systemUrl); |
||
807 | } |
||
808 | } |
||
809 | |||
810 | |||
1500 | jmachado | 811 | /** |
812 | * Update courseComission Members |
||
813 | * @param systemUrl |
||
814 | * @param code |
||
815 | * @param c |
||
816 | * @throws IOException |
||
817 | * @throws JSONException |
||
818 | */ |
||
1516 | jmachado | 819 | private void updateCourseComissionMembersAndCourseInfo(1.5.0/docs/api/java/lang/String.html">String systemUrl, 1.5.0/docs/api/java/lang/String.html">String code, Course c) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException |
820 | { |
||
821 | |||
1500 | jmachado | 822 | 1.5.0/docs/api/java/net/URL.html">URL urlCourseDetails = new 1.5.0/docs/api/java/net/URL.html">URL(systemUrl + "/wsjson/api?service=getCourse&code=" + code); |
823 | 5+0%2Fdocs%2Fapi+InputStream">InputStream isCourseDetails = urlCourseDetails.openStream(); |
||
824 | 1.5.0/docs/api/java/lang/String.html">String strCourseDetails = StreamsUtils.readString(isCourseDetails); |
||
825 | JSONObject objCourseDetails = new JSONObject(strCourseDetails); |
||
1516 | jmachado | 826 | |
827 | //DEPARTMENT |
||
828 | JSONObject department = objCourseDetails.getJSONObject("courseInfo").getJSONObject("department"); |
||
829 | if(department != null) |
||
830 | { |
||
831 | 1.5.0/docs/api/java/lang/String.html">String sigla = department.getString("sigla"); |
||
832 | if(sigla != null) |
||
833 | { |
||
834 | CourseDepartment department1 = DaoFactory.getCourseDepartmentDaoImpl().findBySigla(sigla); |
||
835 | if(department1 != null) |
||
836 | { |
||
837 | c.setDepartment(department1); |
||
838 | } |
||
839 | } |
||
840 | } |
||
841 | |||
842 | |||
1500 | jmachado | 843 | 1.5.0/docs/api/java/lang/String.html">String validationRole = objCourseDetails.getJSONObject("courseInfo").getString("validationRole"); |
844 | |||
1516 | jmachado | 845 | |
846 | |||
847 | |||
1500 | jmachado | 848 | if(validationRole == null) |
849 | { |
||
850 | logger.info("validationRole is not defined"); |
||
851 | } |
||
852 | else |
||
853 | { |
||
854 | logger.info("found validationRole: " + validationRole); |
||
855 | c.setValidationRole(validationRole); |
||
856 | |||
857 | JSONObject coordinator = objCourseDetails.getJSONObject("courseInfo").getJSONObject("coordinator"); |
||
858 | JSONArray courseComission = objCourseDetails.getJSONObject("courseInfo").getJSONArray("courseComission"); |
||
859 | |||
860 | Teacher coordinatorPersistent = findPersonFromCourseDetails(coordinator); |
||
861 | if(coordinatorPersistent == null) |
||
862 | { |
||
863 | logger.warn("Coordinator does not exist in this system "); |
||
864 | } |
||
865 | else |
||
866 | { |
||
867 | c.setCoordinator(coordinatorPersistent); |
||
868 | } |
||
1516 | jmachado | 869 | |
870 | List<User> users = DaoFactory.getUserDaoImpl().loadRoleUsers(validationRole); |
||
871 | logger.info("Encontrados " + users.size() + " docentes com o papel de comissao " + validationRole + " vai remover"); |
||
872 | for(User u: users) |
||
873 | { |
||
874 | logger.info("Removendo role a " + u.getName()); |
||
875 | u.removeRole(validationRole); |
||
876 | } |
||
877 | |||
1500 | jmachado | 878 | for(int j = 0 ; j < courseComission.length(); j++) |
879 | { |
||
880 | JSONObject memberComission = courseComission.getJSONObject(j); |
||
881 | Teacher memberPersistent = findPersonFromCourseDetails(memberComission); |
||
882 | if(memberPersistent == null) |
||
1496 | jmachado | 883 | { |
1500 | jmachado | 884 | logger.info("Member does not exist in this system "); |
1496 | jmachado | 885 | } |
886 | else |
||
887 | { |
||
1500 | jmachado | 888 | logger.info("Adding role of course comission member"); |
889 | if(!memberPersistent.hasRole(validationRole)) |
||
1497 | jmachado | 890 | { |
1500 | jmachado | 891 | memberPersistent.addRole(validationRole); |
1497 | jmachado | 892 | } |
1500 | jmachado | 893 | } |
1496 | jmachado | 894 | } |
895 | } |
||
1500 | jmachado | 896 | } |
1497 | jmachado | 897 | |
1500 | jmachado | 898 | private Teacher findPersonFromCourseDetails(JSONObject coordinator) { |
899 | int code; |
||
900 | try { |
||
901 | if(coordinator.has("sigesCode")) |
||
902 | { |
||
903 | code = coordinator.getInt("sigesCode"); |
||
904 | } |
||
905 | else |
||
906 | { |
||
907 | logger.warn("there is no sigesCode for this person " + coordinator.toString()); |
||
908 | return null; |
||
909 | } |
||
910 | } catch (JSONException e){ |
||
911 | return null; |
||
912 | } catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e){ |
||
913 | return null; |
||
914 | } |
||
915 | return DaoFactory.getTeacherDaoImpl().loadBySigesCode(code); |
||
1496 | jmachado | 916 | } |
917 | |||
1505 | jmachado | 918 | |
919 | |||
920 | /* |
||
921 | * Studies Plans Administration Services |
||
922 | * |
||
923 | */ |
||
924 | public void addNewStudiesPlan(long courseId,CourseStudiesPlan studiesPlan,UserSession session) |
||
925 | { |
||
926 | Course c = DaoFactory.getCourseDaoImpl().load(courseId); |
||
927 | studiesPlan.setCourse(c); |
||
928 | c.getStudiesPlans().add(studiesPlan); |
||
929 | DaoFactory.getCourseStudiesPlanDaoImpl().save(studiesPlan); |
||
930 | } |
||
931 | |||
1516 | jmachado | 932 | public CourseStudiesPlanImpl cloneVersionFrom(long sourcePlanId, long targetPlanId, long courseId, UserSession session) |
1505 | jmachado | 933 | { |
934 | Course course = DaoFactory.getCourseDaoImpl().load(courseId); |
||
935 | CourseStudiesPlan source = null; |
||
936 | CourseStudiesPlan target = null; |
||
937 | for(CourseStudiesPlan plan: course.getStudiesPlans()) |
||
1500 | jmachado | 938 | { |
1505 | jmachado | 939 | if(plan.getId() == sourcePlanId) |
940 | source = plan; |
||
941 | else if(plan.getId() == targetPlanId) |
||
942 | target = plan; |
||
1500 | jmachado | 943 | } |
1505 | jmachado | 944 | target.setXml(source.getXml()); |
945 | target.setJson(source.getJson()); |
||
1516 | jmachado | 946 | return (CourseStudiesPlanImpl) DaoFactory.getCourseStudiesPlanDaoImpl().narrow(target); |
1505 | jmachado | 947 | } |
1507 | jmachado | 948 | |
1505 | jmachado | 949 | public Curso loadCursoPlanoFromXml(1.5.0/docs/api/java/lang/String.html">String xml) |
950 | { |
||
951 | try { |
||
952 | if(xml != null) |
||
1500 | jmachado | 953 | { |
1505 | jmachado | 954 | JAXBContext jc = JAXBContext.newInstance(Curso.class); |
955 | Unmarshaller unmarshaller = jc.createUnmarshaller(); |
||
956 | Curso curso = (Curso) unmarshaller.unmarshal(new 1.5.0/docs/api/java/io/StringReader.html">StringReader(xml)); |
||
957 | return curso; |
||
1500 | jmachado | 958 | } |
1505 | jmachado | 959 | return null; |
960 | } catch (JAXBException e) { |
||
961 | logger.error(e,e); |
||
962 | return null; |
||
963 | } |
||
964 | } |
||
1496 | jmachado | 965 | |
1505 | jmachado | 966 | /** |
967 | * Persist the edited studies plan |
||
968 | * Updates studiesPlanVersion |
||
969 | * Updates studiesPlanVersionDescription |
||
970 | * Updates PlanoEstudos XML and JSON |
||
1789 | jmachado | 971 | * TODO REVER |
1505 | jmachado | 972 | * @param courseId |
973 | * @param coursePlanId |
||
974 | * @param planoEditado |
||
975 | * @param courseStudiesPlanEditado |
||
976 | * @return |
||
977 | */ |
||
978 | public Course savePlanoEstudosEditado(long courseId, long coursePlanId, Curso planoEditado, CourseStudiesPlan courseStudiesPlanEditado,UserSession session) |
||
979 | { |
||
980 | try { |
||
981 | Course course = DaoFactory.getCourseDaoImpl().load(courseId); |
||
982 | |||
983 | for(CourseStudiesPlan courseStudiesPlanPersistente: course.getStudiesPlans()) |
||
984 | { |
||
985 | if(courseStudiesPlanPersistente.getId() == coursePlanId) |
||
986 | { |
||
987 | courseStudiesPlanPersistente.setVersion(courseStudiesPlanEditado.getVersion()); |
||
988 | courseStudiesPlanPersistente.setVersionDescription(courseStudiesPlanEditado.getVersionDescription()); |
||
989 | |||
1507 | jmachado | 990 | //REMOVED UNIDADES TO REMOVE |
991 | for(Curso.Semestre semestre:planoEditado.getSemestre()) |
||
992 | { |
||
993 | Iterator<UnidadeType> uIter = semestre.getUnidade().iterator(); |
||
994 | while(uIter.hasNext()) |
||
995 | { |
||
996 | UnidadeType unidade = uIter.next(); |
||
997 | if(unidade.getRemoved() != null && unidade.getRemoved().equals("true")) |
||
998 | uIter.remove(); |
||
999 | } |
||
1000 | for(Curso.Semestre.Perfil perfil: semestre.getPerfil()) |
||
1001 | { |
||
1002 | Iterator<UnidadeType> uIter2 = perfil.getUnidade().iterator(); |
||
1003 | while(uIter2.hasNext()) |
||
1004 | { |
||
1005 | UnidadeType unidade = uIter2.next(); |
||
1006 | if(unidade.getRemoved() != null && unidade.getRemoved().equals("true")) |
||
1007 | uIter2.remove(); |
||
1008 | } |
||
1009 | } |
||
1010 | } |
||
1505 | jmachado | 1011 | //Garante-se mas depois não vai para o JSON |
1012 | planoEditado.setSiges(course.getCode());//GARANTIR QUE O CODIGO SIGEST ESTA CORRECTO |
||
1013 | planoEditado.setNome(course.getName()); |
||
1014 | planoEditado.setDep(course.getArea()); |
||
1789 | jmachado | 1015 | |
1016 | /** |
||
1017 | * Calcula automaticamente as horas de contacto totais |
||
1018 | */ |
||
1019 | autoFillTotalHorasContacto(planoEditado); |
||
1020 | |||
1505 | jmachado | 1021 | //planoEditado.setDepDesc(""); |
1022 | //planoEditado.setDepDescEn(""); |
||
1023 | //planoEditado.setDepDescEs(""); |
||
1024 | //planoEditado.setDepDescFr(""); |
||
1025 | JAXBContext jc = JAXBContext.newInstance(Curso.class); |
||
1026 | Marshaller marshaller = jc.createMarshaller(); |
||
1027 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); |
||
1028 | 1.5.0/docs/api/java/io/StringWriter.html">StringWriter xml = new 1.5.0/docs/api/java/io/StringWriter.html">StringWriter(); |
||
1029 | marshaller.marshal(planoEditado,xml); |
||
1030 | |||
1031 | courseStudiesPlanPersistente.setXml(xml.toString()); |
||
1789 | jmachado | 1032 | 1.5.0/docs/api/java/lang/String.html">String json = CursoImpl.getGensonPlanoEstudosParaApiJsonWS().serialize(planoEditado); |
1505 | jmachado | 1033 | //SETTING JSON in COURSE STUDIES PLAN |
1034 | courseStudiesPlanPersistente.setJson(json); |
||
1035 | break; |
||
1036 | } |
||
1037 | } |
||
1038 | return course; |
||
1039 | } catch (JAXBException e) { |
||
1040 | logger.error(e,e); |
||
1041 | return null; |
||
1500 | jmachado | 1042 | } |
1043 | } |
||
1496 | jmachado | 1044 | |
1789 | jmachado | 1045 | private void autoFillTotalHorasContacto(Curso planoEditado) { |
1046 | if(planoEditado.getSemestre() != null) |
||
1047 | { |
||
1048 | for(Curso.Semestre s : planoEditado.getSemestre()) |
||
1049 | { |
||
1050 | if(s.getUnidade() != null) |
||
1051 | { |
||
1052 | for(UnidadeType u : s.getUnidade()) |
||
1053 | { |
||
1054 | u.setTotalHorasContacto(UnidadeImpl.calculateTotalHorasContacto(u.getHorasContacto())); |
||
1055 | } |
||
1056 | } |
||
1057 | if(s.getPerfil() != null) |
||
1058 | { |
||
1059 | for(Curso.Semestre.Perfil p : s.getPerfil()) |
||
1060 | { |
||
1061 | if(p.getUnidade() != null) |
||
1062 | { |
||
1063 | for(UnidadeType u : p.getUnidade()) |
||
1064 | { |
||
1065 | u.setTotalHorasContacto(UnidadeImpl.calculateTotalHorasContacto(u.getHorasContacto())); |
||
1066 | } |
||
1067 | } |
||
1068 | } |
||
1069 | } |
||
1070 | } |
||
1071 | } |
||
1072 | } |
||
1073 | |||
1507 | jmachado | 1074 | public void generateFreshJsonPlanosEstudosFromXml(UserSession session) |
1075 | { |
||
1076 | List<CourseStudiesPlan> coursePlans = DaoFactory.getCourseStudiesPlanDaoImpl().findAll(); |
||
1077 | for(CourseStudiesPlan courseStudiesPlanPersistente: coursePlans) |
||
1078 | { |
||
1079 | try |
||
1080 | { |
||
1081 | logger.info("Generating JSON for " + courseStudiesPlanPersistente.getCourse().getName() + " version: " + courseStudiesPlanPersistente.getVersion()); |
||
1082 | Curso cursoPlano = loadCursoPlanoFromXml(courseStudiesPlanPersistente.getXml()); |
||
1518 | jmachado | 1083 | if(cursoPlano != null) |
1084 | { |
||
1085 | for(Curso.Semestre s : cursoPlano.getSemestre()) |
||
1086 | { |
||
1087 | SemestreImpl.setDescriptionsDefaults(s); |
||
1088 | } |
||
1089 | //send to XML again |
||
1090 | JAXBContext jc = JAXBContext.newInstance(Curso.class); |
||
1091 | Marshaller marshaller = jc.createMarshaller(); |
||
1092 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); |
||
1093 | 1.5.0/docs/api/java/io/StringWriter.html">StringWriter xml = new 1.5.0/docs/api/java/io/StringWriter.html">StringWriter(); |
||
1094 | marshaller.marshal(cursoPlano,xml); |
||
1095 | courseStudiesPlanPersistente.setXml(xml.toString()); |
||
1789 | jmachado | 1096 | 1.5.0/docs/api/java/lang/String.html">String json = CursoImpl.getGensonPlanoEstudosParaApiJsonWS().serialize(cursoPlano); |
1518 | jmachado | 1097 | //SETTING JSON in COURSE STUDIES PLAN |
1098 | courseStudiesPlanPersistente.setJson(json); |
||
1099 | } |
||
1100 | |||
1507 | jmachado | 1101 | } |
1102 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
1103 | { |
||
1104 | logger.error(e,e); |
||
1105 | } |
||
1106 | } |
||
1514 | jmachado | 1107 | |
1108 | logger.info("GENERATING JSON FOR CLASS COURSE"); |
||
1109 | for(Course course: DaoFactory.getCourseDaoImpl().findAll()) |
||
1110 | { |
||
1111 | try { |
||
1112 | logger.info("generating json for course: " + course.getName() + " (" + course.getCode() + ")"); |
||
1113 | generateCourseJson(course); |
||
1114 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
||
1115 | logger.error(e,e); |
||
1116 | } |
||
1117 | } |
||
1507 | jmachado | 1118 | } |
1500 | jmachado | 1119 | |
1505 | jmachado | 1120 | |
1507 | jmachado | 1121 | |
1505 | jmachado | 1122 | public List<CourseDepartment> loadDepartments() |
1123 | { |
||
1124 | List<CourseDepartment> departments = DaoFactory.getCourseDepartmentDaoImpl().findAll(); |
||
1125 | for(CourseDepartment dep: departments) |
||
1126 | dep.getName(); |
||
1127 | return departments; |
||
1507 | jmachado | 1128 | |
1505 | jmachado | 1129 | } |
1130 | |||
1516 | jmachado | 1131 | |
1132 | public Teacher addTeacherCommission(1.5.0/docs/api/java/lang/String.html">String teacherId,1.5.0/docs/api/java/lang/String.html">String courseId, UserSession session) |
||
1133 | { |
||
1134 | Course course = DaoFactory.getCourseDaoImpl().load(new 1.5.0/docs/api/java/lang/Long.html">Long(courseId)); |
||
1135 | Teacher t = DaoFactory.getTeacherDaoImpl().load(new 1.5.0/docs/api/java/lang/Long.html">Long(teacherId)); |
||
1136 | t.addRole(course.getValidationRole()); |
||
1137 | return t; |
||
1138 | } |
||
1139 | |||
1140 | public Teacher removeTeacherCommission(1.5.0/docs/api/java/lang/String.html">String teacherId,1.5.0/docs/api/java/lang/String.html">String courseId, UserSession session) |
||
1141 | { |
||
1142 | Course course = DaoFactory.getCourseDaoImpl().load(new 1.5.0/docs/api/java/lang/Long.html">Long(courseId)); |
||
1143 | Teacher t = DaoFactory.getTeacherDaoImpl().load(new 1.5.0/docs/api/java/lang/Long.html">Long(teacherId)); |
||
1144 | t.removeRole(course.getValidationRole()); |
||
1145 | return t; |
||
1146 | } |
||
1147 | |||
1790 | jmachado | 1148 | |
1507 | jmachado | 1149 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) |
1150 | { |
||
1151 | AbstractDao.getCurrentSession().beginTransaction(); |
||
1152 | new CoursesService().generateFreshJsonPlanosEstudosFromXml(null); |
||
1153 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
1790 | jmachado | 1154 | } |
1505 | jmachado | 1155 | |
1535 | jmachado | 1156 | public StudiesPlanImporter importStudiesPlanVersionFromFile(5+0%2Fdocs%2Fapi+InputStream">InputStream stream, 1.5.0/docs/api/java/lang/Long.html">Long studiesPlanId, UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1534 | jmachado | 1157 | { |
1158 | StudiesPlanImporter importer = new StudiesPlanImporter(); |
||
1159 | importer.parseFile(stream); |
||
1160 | 1.5.0/docs/api/java/lang/System.html">System.out.println(importer.getLog()); |
||
1535 | jmachado | 1161 | CourseStudiesPlan plan = DaoFactory.getCourseStudiesPlanDaoImpl().load(studiesPlanId); |
1162 | plan.setImportLog(importer.getLog()); |
||
1534 | jmachado | 1163 | return importer; |
1164 | } |
||
1541 | jmachado | 1165 | public StudiesPlanImporter mergeStudiesPlanVersionFromFile(5+0%2Fdocs%2Fapi+InputStream">InputStream stream, 1.5.0/docs/api/java/lang/Long.html">Long studiesPlanId, UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1166 | { |
||
1167 | StudiesPlanImporter importer = new StudiesPlanImporter(); |
||
1168 | importer.parseFile(stream); |
||
1169 | 1.5.0/docs/api/java/lang/System.html">System.out.println(importer.getLog()); |
||
1170 | CourseStudiesPlan plan = DaoFactory.getCourseStudiesPlanDaoImpl().load(studiesPlanId); |
||
1171 | plan.setImportLog(plan.getImportLog() + "\n\n############\n\n##MERGING\n\n" + importer.getLog()); |
||
1172 | return importer; |
||
1173 | } |
||
1507 | jmachado | 1174 | |
1789 | jmachado | 1175 | public ReplaceRoleResult createRoleCourseComission(long courseId,UserSession userSession) throws AccessDeniedException |
1667 | jmachado | 1176 | { |
1177 | Course c = DaoFactory.getCourseDaoImpl().load(courseId); |
||
1699 | jmachado | 1178 | 1.5.0/docs/api/java/lang/String.html">String normalizedName = StringsUtils.getNormalizedNameSafeforCode(c.getName()); |
1179 | if(normalizedName == null) |
||
1180 | throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("Erro o curso " + c.getId() +" + nao tem nome"); |
||
1181 | 1.5.0/docs/api/java/lang/String.html">String roleValidation = "courseValidateProgram" + normalizedName; |
||
1182 | UserRoleConfigImpl newUserRoleConfig = DomainObjectFactory.createUserRoleConfigImpl(); |
||
1183 | newUserRoleConfig.setRole(roleValidation); |
||
1184 | newUserRoleConfig.setValid(true); |
||
1185 | newUserRoleConfig.setValue("Comissão de Curso de " + c.getName()); |
||
1186 | newUserRoleConfig.setValuePt("Comissão de Curso de " + c.getName()); |
||
1187 | newUserRoleConfig.setValueEn(""); |
||
1188 | newUserRoleConfig.setValueEs(""); |
||
1189 | newUserRoleConfig.setValueFr(""); |
||
1190 | |||
1191 | try { |
||
1192 | |||
1789 | jmachado | 1193 | ReplaceRoleResult result; |
1699 | jmachado | 1194 | if(c.getValidationRole() == null || c.getValidationRole().trim().length() == 0) |
1195 | { |
||
1196 | result = new UserRoleConfigService().addUpdateRole(newUserRoleConfig,userSession); |
||
1197 | } |
||
1198 | else |
||
1199 | { |
||
1200 | 1.5.0/docs/api/java/lang/String.html">String oldValidationRole = c.getValidationRole(); |
||
1703 | jmachado | 1201 | result = new UserRoleConfigService().updateOldRoleWithView(oldValidationRole, newUserRoleConfig, userSession); |
1699 | jmachado | 1202 | } |
1203 | |||
1204 | |||
1205 | if(result.roleKeyAlreadyExist) |
||
1206 | { |
||
1207 | logger.error("Tentado CRIAR um Role que já existe e não é Administrador nem Super user"); |
||
1208 | throw new AccessDeniedException("Tentado CRIAR um Role que já existe e não é Administrador nem Super user"); |
||
1209 | } |
||
1667 | jmachado | 1210 | c.setValidationRole(roleValidation); |
1700 | jmachado | 1211 | return result; |
1699 | jmachado | 1212 | } catch (AccessDeniedException e) { |
1213 | logger.error("Tentado alterar um Role e não é Administrador nem Super user"); |
||
1214 | throw e; |
||
1667 | jmachado | 1215 | } |
1216 | } |
||
1534 | jmachado | 1217 | |
1699 | jmachado | 1218 | |
1219 | |||
1667 | jmachado | 1220 | public Teacher changeCoordinator(long teacherId,long courseId,UserSession userSession) |
1221 | { |
||
1222 | Course c = DaoFactory.getCourseDaoImpl().load(courseId); |
||
1223 | Teacher t = DaoFactory.getTeacherDaoImpl().load(teacherId); |
||
1224 | c.setCoordinator(t); |
||
1225 | t = DaoFactory.getTeacherDaoImpl().narrow(t); |
||
1226 | return t; |
||
1227 | } |
||
1228 | |||
1776 | jmachado | 1229 | public CourseDepartmentImpl updateDepartmentFromJson(1.5.0/docs/api/java/lang/String.html">String json,UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1670 | jmachado | 1230 | { |
1231 | CourseDepartmentImpl courseDepartment = CourseDepartmentImpl.loadFromJson(json); |
||
1232 | CourseDepartmentImpl courseDepartmentPersistent = (CourseDepartmentImpl) DaoFactory.getCourseDepartmentDaoImpl().load(courseDepartment.getSigla()); |
||
1233 | courseDepartmentPersistent.setSigla(courseDepartment.getSigla()); |
||
1234 | courseDepartmentPersistent.setActive(courseDepartment.isActive()); |
||
1235 | courseDepartmentPersistent.setName(courseDepartment.getName()); |
||
1236 | courseDepartmentPersistent.setNameEs(courseDepartment.getNameEs()); |
||
1237 | courseDepartmentPersistent.setNameEn(courseDepartment.getNameEs()); |
||
1238 | courseDepartmentPersistent.setNameFr(courseDepartment.getNameFr()); |
||
1692 | jmachado | 1239 | //courseDepartmentPersistent.setInstitutionalCode(courseDepartment.getInstitutionalCode()); |
1670 | jmachado | 1240 | courseDepartmentPersistent.setBoardRole(courseDepartment.getBoardRole()); |
1241 | courseDepartmentPersistent.setDirectorRole(courseDepartment.getDirectorRole()); |
||
1242 | if(courseDepartment.getCourseSchool() != null && courseDepartment.getCourseSchool().getId() > 0) |
||
1243 | { |
||
1244 | CourseSchoolImpl courseSchool = (CourseSchoolImpl) DaoFactory.getCourseSchoolDaoImpl().load(courseDepartment.getCourseSchool().getId()); |
||
1245 | courseDepartmentPersistent.setCourseSchool(courseSchool); |
||
1246 | } |
||
1247 | else |
||
1248 | courseDepartmentPersistent.setCourseSchool(null); |
||
1249 | return courseDepartmentPersistent; |
||
1667 | jmachado | 1250 | |
1670 | jmachado | 1251 | } |
1252 | |||
1776 | jmachado | 1253 | public CourseDepartmentImpl removeDepartmentFromJson(1.5.0/docs/api/java/lang/String.html">String json,UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1670 | jmachado | 1254 | { |
1255 | CourseDepartmentImpl courseDepartment = CourseDepartmentImpl.loadFromJson(json); |
||
1256 | CourseDepartmentImpl courseDepartmentPersistent = (CourseDepartmentImpl) DaoFactory.getCourseDepartmentDaoImpl().load(courseDepartment.getSigla()); |
||
1257 | DaoFactory.getCourseDepartmentDaoImpl().delete(courseDepartmentPersistent); |
||
1258 | return courseDepartmentPersistent; |
||
1259 | |||
1260 | } |
||
1261 | |||
1776 | jmachado | 1262 | public CourseDepartmentImpl newDepartmentFromJson(UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1670 | jmachado | 1263 | { |
1264 | CourseDepartmentImpl courseDepartmentPersistent = DomainObjectFactory.createCourseDepartmentImpl(); |
||
1265 | |||
1266 | courseDepartmentPersistent.setSigla(BytesUtils.generateKey().substring(0,10)); |
||
1267 | courseDepartmentPersistent.setActive(false); |
||
1268 | DaoFactory.getCourseDepartmentDaoImpl().save(courseDepartmentPersistent); |
||
1269 | return courseDepartmentPersistent; |
||
1270 | |||
1271 | } |
||
1272 | |||
1273 | |||
1776 | jmachado | 1274 | public CourseSchoolImpl updateSchoolFromJson(1.5.0/docs/api/java/lang/String.html">String json,UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1670 | jmachado | 1275 | { |
1276 | CourseSchoolImpl courseSchool = CourseSchoolImpl.loadFromJson(json); |
||
1277 | CourseSchoolImpl courseSchoolPersistent = (CourseSchoolImpl) DaoFactory.getCourseSchoolDaoImpl().load(courseSchool.getId()); |
||
1278 | |||
1279 | courseSchoolPersistent.setActive(courseSchool.isActive()); |
||
1280 | courseSchoolPersistent.setName(courseSchool.getName()); |
||
1281 | courseSchoolPersistent.setNameEs(courseSchool.getNameEs()); |
||
1282 | courseSchoolPersistent.setNameEn(courseSchool.getNameEs()); |
||
1283 | courseSchoolPersistent.setNameFr(courseSchool.getNameFr()); |
||
1284 | courseSchoolPersistent.setInstitutionalCode(courseSchool.getInstitutionalCode()); |
||
1730 | jmachado | 1285 | courseSchoolPersistent.setInitials(courseSchool.getInitials()); |
1670 | jmachado | 1286 | |
1287 | courseSchoolPersistent.setSchoolDirectorRole(courseSchool.getSchoolDirectorRole()); |
||
1288 | courseSchoolPersistent.setSchoolBoardRole(courseSchool.getSchoolBoardRole()); |
||
1289 | courseSchoolPersistent.setSchoolSecretariadoRole(courseSchool.getSchoolSecretariadoRole()); |
||
1290 | |||
1291 | courseSchoolPersistent.setCtcPresidentRole(courseSchool.getCtcPresidentRole()); |
||
1292 | courseSchoolPersistent.setCtcMemberRole(courseSchool.getCtcMemberRole()); |
||
1293 | courseSchoolPersistent.setCtcSecretariadoRole(courseSchool.getCtcSecretariadoRole()); |
||
1294 | |||
1295 | courseSchoolPersistent.setPedagogicoPresidentRole(courseSchool.getPedagogicoPresidentRole()); |
||
1296 | courseSchoolPersistent.setPedagogicoMemberRole(courseSchool.getPedagogicoMemberRole()); |
||
1297 | courseSchoolPersistent.setPedagogicoSecretariadoRole(courseSchool.getPedagogicoSecretariadoRole()); |
||
1298 | |||
1728 | jmachado | 1299 | courseSchoolPersistent.setFuncionarioRole(courseSchool.getFuncionarioRole()); |
1300 | courseSchoolPersistent.setTeacherRole(courseSchool.getTeacherRole()); |
||
1301 | courseSchoolPersistent.setStudentRole(courseSchool.getStudentRole()); |
||
1302 | |||
1670 | jmachado | 1303 | return courseSchoolPersistent; |
1304 | |||
1305 | } |
||
1306 | |||
1776 | jmachado | 1307 | public CourseSchoolImpl newSchoolFromJson(UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1670 | jmachado | 1308 | { |
1309 | CourseSchoolImpl courseSchoolPersistent = DomainObjectFactory.createCourseSchoolImpl(); |
||
1310 | |||
1311 | courseSchoolPersistent.setActive(false); |
||
1312 | DaoFactory.getCourseSchoolDaoImpl().save(courseSchoolPersistent); |
||
1313 | return courseSchoolPersistent; |
||
1314 | |||
1315 | } |
||
1316 | |||
1776 | jmachado | 1317 | public CourseSchoolImpl removeSchoolFromJson(1.5.0/docs/api/java/lang/String.html">String json,UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1670 | jmachado | 1318 | { |
1319 | CourseSchoolImpl courseSchool = CourseSchoolImpl.loadFromJson(json); |
||
1320 | CourseSchoolImpl courseSchoolPersistent = (CourseSchoolImpl) DaoFactory.getCourseSchoolDaoImpl().load(courseSchool.getId()); |
||
1321 | DaoFactory.getCourseSchoolDaoImpl().delete(courseSchoolPersistent); |
||
1322 | return courseSchoolPersistent; |
||
1323 | |||
1324 | } |
||
1325 | |||
1790 | jmachado | 1326 | /* |
1789 | jmachado | 1327 | public static void main(String[] args) throws JAXBException, IOException { |
1670 | jmachado | 1328 | |
1789 | jmachado | 1329 | String json = "{\"anoPlanoSiges\":null,\"codigoPlanoSiges\":null,\"dep\":null,\"descPlanoSiges\":null,\"nome\":null,\"semestre\":[{\"id\":\"S1\",\"notas\":null,\"perfil\":[],\"semestreDesc\":\"Semestre 1\",\"semestreDescEn\":\"Semester 1\",\"semestreDescEs\":\"Semestre 1\",\"semestreDescFr\":\"Semestre 1\",\"semestreId\":null,\"unidade\":[{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Português — Língua e Literatura\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"150\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:12\",\"horasContacto\":{\"tP\":\"60\",\"oT\":\"15\"},\"eCTS\":\"6\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Geografia\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"125\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:16\",\"horasContacto\":{\"tP\":\"45\",\"oT\":\"15\"},\"eCTS\":\"5\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"História\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"125\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:20\",\"horasContacto\":{\"tP\":\"45\",\"oT\":\"15\"},\"eCTS\":\"5\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Linguística e Análise do Discurso\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"150\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:24\",\"horasContacto\":{\"tP\":\"60\",\"oT\":\"15\"},\"eCTS\":\"6\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Matemática no 1.o Ciclo do Ensino Básico\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"125\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:28\",\"horasContacto\":{\"tP\":\"45\",\"oT\":\"15\"},\"eCTS\":\"5\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Educação para a Saúde\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"75\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:32\",\"horasContacto\":{\"tP\":\"30\",\"oT\":\"7\"},\"eCTS\":\"3\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Música, Emoção e Criatividade\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"75\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:36\",\"horasContacto\":{\"tP\":\"30\",\"oT\":\"7\"},\"eCTS\":\"3\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Educação para a Cidadania\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"75\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:40\",\"horasContacto\":{\"tP\":\"30\",\"oT\":\"7\"},\"eCTS\":\"3\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Descobrir a Matemática\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"75\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:44\",\"horasContacto\":{\"tP\":\"30\",\"oT\":\"7\"},\"eCTS\":\"3\"}],\"type\":\"semestre\",\"$$hashKey\":\"object:6\"},{\"id\":\"S2\",\"notas\":null,\"perfil\":[],\"semestreDesc\":\"Semestre 1\",\"semestreDescEn\":\"Semester 1\",\"semestreDescEs\":\"Semestre 1\",\"semestreDescFr\":\"Semestre 1\",\"semestreId\":null,\"unidade\":[{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Didática do Português no 1º Ciclo do Ensino Básico\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"150\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:54\",\"eCTS\":\"6\",\"horasContacto\":{\"tP\":\"60\",\"oT\":\"15\"}},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Didática do Estudo do Meio no 1º Ciclo do Ensino Básico\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"150\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:58\",\"eCTS\":\"6\",\"horasContacto\":{\"tP\":\"60\",\"oT\":\"15\"}},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Didática da Matemática no 1º Ciclo do Ensino Básico\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"150\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:62\",\"eCTS\":\"6\",\"horasContacto\":{\"tP\":\"60\",\"oT\":\"15\"}},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Didática das Expressões no 1º Ciclo do Ensino Básico\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"150\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:66\",\"eCTS\":\"6\",\"horasContacto\":{\"tP\":\"60\",\"oT\":\"15\"}},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Psicologia da Educação\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"75\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:70\",\"eCTS\":\"3\",\"horasContacto\":{\"tP\":\"30\",\"oT\":\"7\"}},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Investigação em Educação\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"75\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:74\",\"eCTS\":\"3\",\"horasContacto\":{\"tP\":\"30\",\"oT\":\"7\"}}],\"type\":\"semestre\",\"$$hashKey\":\"object:48\"},{\"id\":\"S3\",\"notas\":null,\"perfil\":[],\"semestreDesc\":\"Semestre 1\",\"semestreDescEn\":\"Semester 1\",\"semestreDescEs\":\"Semestre 1\",\"semestreDescFr\":\"Semestre 1\",\"semestreId\":null,\"unidade\":[{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Prática de Ensino Supervisionada no 1º Ciclo do Ensino Básico\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"500\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:90\",\"eCTS\":\"20\",\"horasContacto\":{\"s\":\"30\",\"e\":\"270\",\"oT\":\"45\"}},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Seminário de Investigação I\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"50\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:98\",\"eCTS\":\"2\",\"horasContacto\":{\"s\":\"20\",\"oT\":\"10\"}},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Didática da História e Geografia de Portugal no 2º Ciclo do Ensino Básico\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"100\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:94\",\"eCTS\":\"4\",\"horasContacto\":{\"tP\":\"35\",\"oT\":\"15\"}},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"Didática do Português no 2º Ciclo do Ensino Básico\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":\"100\",\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:102\",\"eCTS\":\"4\",\"horasContacto\":{\"oT\":\"15\",\"tP\":\"35\"}}],\"type\":\"semestre\",\"$$hashKey\":\"object:78\"},{\"id\":\"S4\",\"notas\":null,\"perfil\":[],\"semestreDesc\":\"Semestre 1\",\"semestreDescEn\":\"Semester 1\",\"semestreDescEs\":\"Semestre 1\",\"semestreDescFr\":\"Semestre 1\",\"semestreId\":null,\"unidade\":[{\"dep\":\"\",\"ects\":\"\",\"nome\":\"\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":0,\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:106\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":0,\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:110\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":0,\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:114\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":0,\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:118\"},{\"dep\":\"\",\"ects\":\"\",\"nome\":\"\",\"nomeEn\":null,\"nomeEs\":null,\"nomeFr\":null,\"obs\":\"\",\"removed\":null,\"siges\":null,\"totalHoras\":0,\"urlFichaCurricular\":\"\",\"urlUnidadeCurricular\":\"\",\"type\":\"unidade\",\"$$hashKey\":\"object:122\"}],\"type\":\"semestre\",\"$$hashKey\":\"object:84\"}],\"siges\":null}"; |
1330 | CursoImpl c = CursoImpl.loadFromJson(json); |
||
1331 | |||
1332 | JAXBContext jc = JAXBContext.newInstance(Curso.class); |
||
1333 | Marshaller marshaller = jc.createMarshaller(); |
||
1334 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); |
||
1335 | StringWriter xml = new StringWriter(); |
||
1336 | marshaller.marshal(c,xml); |
||
1337 | System.out.println(xml); |
||
1790 | jmachado | 1338 | }*/ |
1789 | jmachado | 1339 | |
1340 | |||
214 | jmachado | 1341 | } |