Rev 1506 | Rev 1514 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1506 | Rev 1507 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.estgweb.services.courses; |
1 | package pt.estgp.estgweb.services.courses; |
2 | 2 | ||
3 | import com.owlike.genson.Genson; |
3 | import com.owlike.genson.Genson; |
4 | import com.owlike.genson.TransformationException; |
4 | import com.owlike.genson.TransformationException; |
5 | import com.owlike.genson.reflect.VisibilityFilter; |
5 | import com.owlike.genson.reflect.VisibilityFilter; |
- | 6 | import jomm.dao.impl.AbstractDao; |
|
6 | import jomm.utils.FilesUtils; |
7 | import jomm.utils.FilesUtils; |
7 | import jomm.utils.StreamsUtils; |
8 | import jomm.utils.StreamsUtils; |
8 | import org.apache.log4j.Logger; |
9 | import org.apache.log4j.Logger; |
9 | import org.dom4j.Document; |
10 | import org.dom4j.Document; |
10 | import org.json.JSONArray; |
11 | import org.json.JSONArray; |
Line 417... | Line 418... | ||
417 | 418 | ||
418 | 419 | ||
419 | private static Genson getGensonPlanoEstudos(){ |
420 | private static Genson getGensonPlanoEstudos(){ |
420 | Genson genson = new Genson.Builder() |
421 | Genson genson = new Genson.Builder() |
421 | .exclude("class") |
422 | .exclude("class") |
422 | .exclude("siges") |
423 | .exclude("siges", Curso.class) |
423 | .exclude("nome") |
424 | .exclude("nome",Curso.class) |
424 | .exclude("dep") |
425 | .exclude("dep") |
- | 426 | .exclude("removed",UnidadeType.class) |
|
425 | .create(); |
427 | .create(); |
426 | return genson; |
428 | return genson; |
427 | } |
429 | } |
428 | 430 | ||
429 | 431 | ||
Line 915... | Line 917... | ||
915 | target = plan; |
917 | target = plan; |
916 | } |
918 | } |
917 | target.setXml(source.getXml()); |
919 | target.setXml(source.getXml()); |
918 | target.setJson(source.getJson()); |
920 | target.setJson(source.getJson()); |
919 | } |
921 | } |
- | 922 | ||
920 | public Curso loadCursoPlanoFromXml(1.5.0/docs/api/java/lang/String.html">String xml) |
923 | public Curso loadCursoPlanoFromXml(1.5.0/docs/api/java/lang/String.html">String xml) |
921 | { |
924 | { |
922 | try { |
925 | try { |
923 | if(xml != null) |
926 | if(xml != null) |
924 | { |
927 | { |
Line 956... | Line 959... | ||
956 | if(courseStudiesPlanPersistente.getId() == coursePlanId) |
959 | if(courseStudiesPlanPersistente.getId() == coursePlanId) |
957 | { |
960 | { |
958 | courseStudiesPlanPersistente.setVersion(courseStudiesPlanEditado.getVersion()); |
961 | courseStudiesPlanPersistente.setVersion(courseStudiesPlanEditado.getVersion()); |
959 | courseStudiesPlanPersistente.setVersionDescription(courseStudiesPlanEditado.getVersionDescription()); |
962 | courseStudiesPlanPersistente.setVersionDescription(courseStudiesPlanEditado.getVersionDescription()); |
960 | 963 | ||
- | 964 | //REMOVED UNIDADES TO REMOVE |
|
- | 965 | for(Curso.Semestre semestre:planoEditado.getSemestre()) |
|
- | 966 | { |
|
- | 967 | Iterator<UnidadeType> uIter = semestre.getUnidade().iterator(); |
|
- | 968 | while(uIter.hasNext()) |
|
- | 969 | { |
|
- | 970 | UnidadeType unidade = uIter.next(); |
|
- | 971 | if(unidade.getRemoved() != null && unidade.getRemoved().equals("true")) |
|
- | 972 | uIter.remove(); |
|
- | 973 | } |
|
- | 974 | for(Curso.Semestre.Perfil perfil: semestre.getPerfil()) |
|
- | 975 | { |
|
- | 976 | Iterator<UnidadeType> uIter2 = perfil.getUnidade().iterator(); |
|
- | 977 | while(uIter2.hasNext()) |
|
- | 978 | { |
|
- | 979 | UnidadeType unidade = uIter2.next(); |
|
- | 980 | if(unidade.getRemoved() != null && unidade.getRemoved().equals("true")) |
|
- | 981 | uIter2.remove(); |
|
- | 982 | } |
|
- | 983 | } |
|
- | 984 | } |
|
961 | //Garante-se mas depois não vai para o JSON |
985 | //Garante-se mas depois não vai para o JSON |
962 | planoEditado.setSiges(course.getCode());//GARANTIR QUE O CODIGO SIGEST ESTA CORRECTO |
986 | planoEditado.setSiges(course.getCode());//GARANTIR QUE O CODIGO SIGEST ESTA CORRECTO |
963 | planoEditado.setNome(course.getName()); |
987 | planoEditado.setNome(course.getName()); |
964 | planoEditado.setDep(course.getArea()); |
988 | planoEditado.setDep(course.getArea()); |
965 | //planoEditado.setDepDesc(""); |
989 | //planoEditado.setDepDesc(""); |
Line 990... | Line 1014... | ||
990 | logger.error(e,e); |
1014 | logger.error(e,e); |
991 | return null; |
1015 | return null; |
992 | } |
1016 | } |
993 | } |
1017 | } |
994 | 1018 | ||
- | 1019 | public void generateFreshJsonPlanosEstudosFromXml(UserSession session) |
|
- | 1020 | { |
|
- | 1021 | List<CourseStudiesPlan> coursePlans = DaoFactory.getCourseStudiesPlanDaoImpl().findAll(); |
|
- | 1022 | for(CourseStudiesPlan courseStudiesPlanPersistente: coursePlans) |
|
- | 1023 | { |
|
- | 1024 | try |
|
- | 1025 | { |
|
- | 1026 | logger.info("Generating JSON for " + courseStudiesPlanPersistente.getCourse().getName() + " version: " + courseStudiesPlanPersistente.getVersion()); |
|
- | 1027 | Curso cursoPlano = loadCursoPlanoFromXml(courseStudiesPlanPersistente.getXml()); |
|
- | 1028 | 1.5.0/docs/api/java/lang/String.html">String json = getGensonPlanoEstudos().serialize(cursoPlano); |
|
- | 1029 | //SETTING JSON in COURSE STUDIES PLAN |
|
- | 1030 | courseStudiesPlanPersistente.setJson(json); |
|
- | 1031 | } |
|
- | 1032 | catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
|
- | 1033 | { |
|
- | 1034 | logger.error(e,e); |
|
- | 1035 | } |
|
- | 1036 | } |
|
- | 1037 | } |
|
- | 1038 | ||
995 | 1039 | ||
996 | 1040 | ||
997 | public List<CourseDepartment> loadDepartments() |
1041 | public List<CourseDepartment> loadDepartments() |
998 | { |
1042 | { |
999 | List<CourseDepartment> departments = DaoFactory.getCourseDepartmentDaoImpl().findAll(); |
1043 | List<CourseDepartment> departments = DaoFactory.getCourseDepartmentDaoImpl().findAll(); |
1000 | for(CourseDepartment dep: departments) |
1044 | for(CourseDepartment dep: departments) |
1001 | dep.getName(); |
1045 | dep.getName(); |
1002 | return departments; |
1046 | return departments; |
- | 1047 | ||
- | 1048 | } |
|
- | 1049 | ||
- | 1050 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) |
|
- | 1051 | { |
|
- | 1052 | AbstractDao.getCurrentSession().beginTransaction(); |
|
- | 1053 | new CoursesService().generateFreshJsonPlanosEstudosFromXml(null); |
|
- | 1054 | AbstractDao.getCurrentSession().getTransaction().commit(); |
|
1003 | } |
1055 | } |
1004 | 1056 | ||
1005 | 1057 | ||
1006 | } |
1058 | } |