Rev 1862 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1862 | Rev 1873 | ||
---|---|---|---|
Line 7... | Line 7... | ||
7 | import jomm.utils.BytesUtils; |
7 | import jomm.utils.BytesUtils; |
8 | import jomm.utils.FilesUtils; |
8 | import jomm.utils.FilesUtils; |
9 | import jomm.utils.StreamsUtils; |
9 | import jomm.utils.StreamsUtils; |
10 | import org.apache.log4j.Logger; |
10 | import org.apache.log4j.Logger; |
11 | import org.dom4j.Document; |
11 | import org.dom4j.Document; |
- | 12 | import org.hibernate.Query; |
|
12 | import org.json.JSONArray; |
13 | import org.json.JSONArray; |
13 | import org.json.JSONException; |
14 | import org.json.JSONException; |
14 | import org.json.JSONObject; |
15 | import org.json.JSONObject; |
15 | import pt.estgp.estgweb.utils.Globals; |
- | |
16 | import pt.estgp.estgweb.domain.*; |
16 | import pt.estgp.estgweb.domain.*; |
17 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
17 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
18 | import pt.estgp.estgweb.domain.views.CourseView; |
18 | import pt.estgp.estgweb.domain.views.CourseView; |
19 | import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
19 | import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
20 | import pt.estgp.estgweb.filters.exceptions.AccessDeniedException; |
20 | import pt.estgp.estgweb.filters.exceptions.AccessDeniedException; |
Line 25... | Line 25... | ||
25 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
25 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
26 | import pt.estgp.estgweb.services.users.ReplaceRoleResult; |
26 | import pt.estgp.estgweb.services.users.ReplaceRoleResult; |
27 | import pt.estgp.estgweb.services.users.UserRoleConfigService; |
27 | import pt.estgp.estgweb.services.users.UserRoleConfigService; |
28 | import pt.estgp.estgweb.utils.ConfigProperties; |
28 | import pt.estgp.estgweb.utils.ConfigProperties; |
29 | import pt.estgp.estgweb.utils.Dom4jUtil; |
29 | import pt.estgp.estgweb.utils.Dom4jUtil; |
- | 30 | import pt.estgp.estgweb.utils.Globals; |
|
30 | import pt.estgp.estgweb.utils.StringsUtils; |
31 | import pt.estgp.estgweb.utils.StringsUtils; |
31 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
32 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
32 | 33 | ||
33 | import javax.xml.bind.JAXBContext; |
34 | import javax.xml.bind.JAXBContext; |
34 | import javax.xml.bind.JAXBException; |
35 | import javax.xml.bind.JAXBException; |
Line 179... | Line 180... | ||
179 | } |
180 | } |
180 | else |
181 | else |
181 | { |
182 | { |
182 | c = DaoFactory.getCourseDaoImpl().findCourseByCodeAndYear(courseView.getCode(),courseView.getImportYear()); |
183 | c = DaoFactory.getCourseDaoImpl().findCourseByCodeAndYear(courseView.getCode(),courseView.getImportYear()); |
183 | if(c != null) |
184 | if(c != null) |
184 | throw new AlreadyExistsException(AlreadyExistsException.ALREADY_EXISTS_COURSE); |
185 | throw new AlreadyExistsException(AlreadyExistsException.ALREADY_EXISTS_COURSE); |
185 | c = DomainObjectFactory.createCourseImpl(); |
186 | c = DomainObjectFactory.createCourseImpl(); |
186 | DaoFactory.getCourseDaoImpl().save(c); |
187 | DaoFactory.getCourseDaoImpl().save(c); |
187 | } |
188 | } |
188 | 189 | ||
189 | 1.5.0/docs/api/java/lang/String.html">String htmlTrasformationResult = null; |
190 | 1.5.0/docs/api/java/lang/String.html">String htmlTrasformationResult = null; |
Line 697... | Line 698... | ||
697 | generateXmlJaxbStudiesPlanVersionFromRepositoryOldPlanStream(userSession, course, false, null); |
698 | generateXmlJaxbStudiesPlanVersionFromRepositoryOldPlanStream(userSession, course, false, null); |
698 | } catch (JAXBException e) { |
699 | } catch (JAXBException e) { |
699 | logger.error(e,e); |
700 | logger.error(e,e); |
700 | return "<error>" + e.toString() + ". see log for details</error>"; |
701 | return "<error>" + e.toString() + ". see log for details</error>"; |
701 | } |
702 | } |
702 | } |
703 | } |
703 | 704 | ||
704 | if(course.getStudiesPlans() != null && course.getStudiesPlans().size() > 0) |
705 | if(course.getStudiesPlans() != null && course.getStudiesPlans().size() > 0) |
705 | { |
706 | { |
706 | return course.getStudiesPlans().iterator().next().getXml(); |
707 | return course.getStudiesPlans().iterator().next().getXml(); |
707 | } |
708 | } |
708 | return "<error>Does not exixt</error>"; |
709 | return "<error>Does not exixt</error>"; |
Line 1176... | Line 1177... | ||
1176 | { |
1177 | { |
1177 | Course c = DaoFactory.getCourseDaoImpl().load(courseId); |
1178 | Course c = DaoFactory.getCourseDaoImpl().load(courseId); |
1178 | 1.5.0/docs/api/java/lang/String.html">String normalizedName = StringsUtils.getNormalizedNameSafeforCode(c.getName()); |
1179 | 1.5.0/docs/api/java/lang/String.html">String normalizedName = StringsUtils.getNormalizedNameSafeforCode(c.getName()); |
1179 | if(normalizedName == null) |
1180 | 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 | 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 | - | ||
1193 | ReplaceRoleResult result; |
- | |
1194 | if(c.getValidationRole() == null || c.getValidationRole().trim().length() == 0) |
- | |
1195 | { |
- | |
1196 | result = new UserRoleConfigService().addUpdateRole(newUserRoleConfig,userSession,false); |
- | |
1197 | } |
- | |
1198 | else |
- | |
1199 | { |
- | |
1200 | 1.5.0/docs/api/java/lang/String.html">String oldValidationRole = c.getValidationRole(); |
- | |
1201 | result = new UserRoleConfigService().updateOldRoleWithView(oldValidationRole, newUserRoleConfig, userSession,false); |
- | |
1202 | } |
- | |
1203 | - | ||
1204 | 1182 | ||
1205 | if(result.roleKeyAlreadyExist) |
1183 | 1.5.0/docs/api/java/lang/String.html">String roleValidation = "courseValidateProgram" + normalizedName; |
1206 | { |
- | |
1207 | logger.error("Tentado CRIAR um Role que já existe e não é Administrador nem Super user"); |
1184 | 1.5.0/docs/api/java/lang/String.html">String oldValidationRole = c.getValidationRole(); |
1208 | throw new AccessDeniedException("Tentado CRIAR um Role que já existe e não é Administrador nem Super user"); |
1185 | 1.5.0/docs/api/java/lang/String.html">String nomeRole = "Comissão de Curso de " + c.getName(); |
1209 | } |
1186 | try{ |
- | 1187 | ReplaceRoleResult result = new UserRoleConfigService().createNewNormalizedRoleService(oldValidationRole,nomeRole,roleValidation,userSession); |
|
1210 | c.setValidationRole(roleValidation); |
1188 | c.setValidationRole(roleValidation); |
1211 | return result; |
1189 | return result; |
1212 | } catch (AccessDeniedException e) { |
1190 | }catch(AccessDeniedException e) |
1213 | logger.error("Tentado alterar um Role e não é Administrador nem Super user"); |
1191 | { |
1214 | throw e; |
1192 | throw e; |
1215 | } |
1193 | } |
1216 | } |
1194 | } |
1217 | 1195 | ||
1218 | 1196 | ||
Line 1227... | Line 1205... | ||
1227 | } |
1205 | } |
1228 | 1206 | ||
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 |
1207 | 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 |
1230 | { |
1208 | { |
1231 | CourseDepartmentImpl courseDepartment = CourseDepartmentImpl.loadFromJson(json); |
1209 | CourseDepartmentImpl courseDepartment = CourseDepartmentImpl.loadFromJson(json); |
1232 | CourseDepartmentImpl courseDepartmentPersistent = (CourseDepartmentImpl) DaoFactory.getCourseDepartmentDaoImpl().load(courseDepartment.getSigla()); |
- | |
- | 1210 | ||
- | 1211 | ||
- | 1212 | ||
1233 | if(!courseDepartment.getSiglaNova().equals(courseDepartment.getSigla())) |
1213 | if(!courseDepartment.getSiglaNova().equals(courseDepartment.getSigla())) |
- | 1214 | { |
|
1234 | courseDepartmentPersistent.setSigla(courseDepartment.getSiglaNova()); |
1215 | //courseDepartmentPersistent.setSigla(courseDepartment.getSiglaNova()); |
- | 1216 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("update " + CourseDepartment.class.getName() + " d " + |
|
- | 1217 | " set d.sigla = :siglaNova where d.sigla = :sigla"); |
|
- | 1218 | q.setString("siglaNova",courseDepartment.getSiglaNova()); |
|
- | 1219 | q.setString("sigla",courseDepartment.getSigla()); |
|
- | 1220 | q.executeUpdate(); |
|
- | 1221 | //courseDepartmentPersistent = (CourseDepartmentImpl) DaoFactory.getCourseDepartmentDaoImpl().load(courseDepartment.getSiglaNova()); |
|
- | 1222 | } |
|
- | 1223 | CourseDepartmentImpl courseDepartmentPersistent = (CourseDepartmentImpl) DaoFactory.getCourseDepartmentDaoImpl().load(courseDepartment.getSiglaNova()); |
|
1235 | //courseDepartmentPersistent.setSigla(courseDepartment.getSigla()); |
1224 | //courseDepartmentPersistent.setSigla(courseDepartment.getSigla()); |
1236 | courseDepartmentPersistent.setActive(courseDepartment.isActive()); |
1225 | courseDepartmentPersistent.setActive(courseDepartment.isActive()); |
1237 | courseDepartmentPersistent.setName(courseDepartment.getName()); |
1226 | courseDepartmentPersistent.setName(courseDepartment.getName()); |
1238 | courseDepartmentPersistent.setNameEs(courseDepartment.getNameEs()); |
1227 | courseDepartmentPersistent.setNameEs(courseDepartment.getNameEs()); |
1239 | courseDepartmentPersistent.setNameEn(courseDepartment.getNameEs()); |
1228 | courseDepartmentPersistent.setNameEn(courseDepartment.getNameEs()); |
Line 1271... | Line 1260... | ||
1271 | DaoFactory.getCourseDepartmentDaoImpl().save(courseDepartmentPersistent); |
1260 | DaoFactory.getCourseDepartmentDaoImpl().save(courseDepartmentPersistent); |
1272 | return courseDepartmentPersistent; |
1261 | return courseDepartmentPersistent; |
1273 | 1262 | ||
1274 | } |
1263 | } |
1275 | 1264 | ||
- | 1265 | /** |
|
- | 1266 | * Cria um conjunto de roles novos para um determinado departamento |
|
- | 1267 | * chama o serviço tier1 UserRoleConfigService.createNewNormalizedRoleService |
|
- | 1268 | * @param session |
|
- | 1269 | * @return |
|
- | 1270 | * @throws IOException |
|
- | 1271 | * @throws AccessDeniedException |
|
- | 1272 | */ |
|
- | 1273 | public CourseDepartmentImpl newDepartmentRolesFromJson(1.5.0/docs/api/java/lang/String.html">String json,UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException, AccessDeniedException { |
|
- | 1274 | CourseDepartmentImpl courseDepartment = CourseDepartmentImpl.loadFromJson(json); |
|
- | 1275 | CourseDepartmentImpl courseDepartmentPersistent = (CourseDepartmentImpl) DaoFactory.getCourseDepartmentDaoImpl().findBySigla(courseDepartment.getSigla()); |
|
- | 1276 | ||
- | 1277 | UserRoleConfigService userRoleConfigService = new UserRoleConfigService(); |
|
- | 1278 | 1.5.0/docs/api/java/lang/String.html">String normalizedName = StringsUtils.getNormalizedNameSafeforCode(courseDepartmentPersistent.getName()); |
|
- | 1279 | if(normalizedName == null) |
|
- | 1280 | throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("Erro o Departamento " + courseDepartmentPersistent.getSigla() +" + nao tem nome"); |
|
- | 1281 | ||
- | 1282 | ||
- | 1283 | 1.5.0/docs/api/java/lang/String.html">String nomeRole = "Departamento Direcção - " + courseDepartmentPersistent.getName(); |
|
- | 1284 | 1.5.0/docs/api/java/lang/String.html">String oldRole = courseDepartmentPersistent.getBoardRole(); |
|
- | 1285 | 1.5.0/docs/api/java/lang/String.html">String newRoleStr = "department.board." + normalizedName; |
|
- | 1286 | try |
|
- | 1287 | { |
|
- | 1288 | userRoleConfigService.createNewNormalizedRoleService(oldRole,nomeRole,newRoleStr, session); |
|
- | 1289 | courseDepartmentPersistent.setBoardRole(newRoleStr); |
|
- | 1290 | } catch (AccessDeniedException e) { |
|
- | 1291 | logger.error(e,e); |
|
- | 1292 | throw e; |
|
- | 1293 | } |
|
- | 1294 | ||
- | 1295 | ||
- | 1296 | nomeRole = "Departamento Diretor - " + courseDepartmentPersistent.getName(); |
|
- | 1297 | oldRole = courseDepartmentPersistent.getDirectorRole(); |
|
- | 1298 | newRoleStr = "department.diretor." + normalizedName; |
|
- | 1299 | ||
- | 1300 | try { |
|
- | 1301 | userRoleConfigService.createNewNormalizedRoleService(oldRole,nomeRole,newRoleStr, session); |
|
- | 1302 | courseDepartmentPersistent.setDirectorRole(newRoleStr); |
|
- | 1303 | } catch (AccessDeniedException e) { |
|
- | 1304 | logger.error(e,e); |
|
- | 1305 | throw e; |
|
- | 1306 | } |
|
- | 1307 | ||
- | 1308 | return courseDepartmentPersistent; |
|
- | 1309 | } |
|
- | 1310 | ||
- | 1311 | ||
- | 1312 | ||
1276 | 1313 | ||
1277 | 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 |
1314 | 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 |
1278 | { |
1315 | { |
1279 | CourseSchoolImpl courseSchool = CourseSchoolImpl.loadFromJson(json); |
1316 | CourseSchoolImpl courseSchool = CourseSchoolImpl.loadFromJson(json); |
1280 | CourseSchoolImpl courseSchoolPersistent = (CourseSchoolImpl) DaoFactory.getCourseSchoolDaoImpl().load(courseSchool.getId()); |
1317 | CourseSchoolImpl courseSchoolPersistent = (CourseSchoolImpl) DaoFactory.getCourseSchoolDaoImpl().load(courseSchool.getId()); |
Line 1305... | Line 1342... | ||
1305 | 1342 | ||
1306 | return courseSchoolPersistent; |
1343 | return courseSchoolPersistent; |
1307 | 1344 | ||
1308 | } |
1345 | } |
1309 | 1346 | ||
- | 1347 | ||
1310 | public CourseSchoolImpl newSchoolFromJson(UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1348 | public CourseSchoolImpl newSchoolFromJson(UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
1311 | { |
1349 | { |
1312 | CourseSchoolImpl courseSchoolPersistent = DomainObjectFactory.createCourseSchoolImpl(); |
1350 | CourseSchoolImpl courseSchoolPersistent = DomainObjectFactory.createCourseSchoolImpl(); |
1313 | 1351 | ||
1314 | courseSchoolPersistent.setActive(false); |
1352 | courseSchoolPersistent.setActive(false); |
Line 1339... | Line 1377... | ||
1339 | marshaller.marshal(c,xml); |
1377 | marshaller.marshal(c,xml); |
1340 | System.out.println(xml); |
1378 | System.out.println(xml); |
1341 | }*/ |
1379 | }*/ |
1342 | 1380 | ||
1343 | 1381 | ||
1344 | } |
1382 | } |
1345 | 1383 |