public static ScrCity getScrCityById(String sessionID, int id, String entidad) throws AttributesException, SessionException, ValidationException { Validator.validate_String_NotNull_LengthMayorZero( sessionID, ValidationException.ATTRIBUTE_SESSION); ScrCity result = null; Transaction tran = null; try { Session session = HibernateUtil.currentSession(entidad); tran = session.beginTransaction(); // Recuperamos la sesión CacheFactory.getCacheInterface().getCacheEntry(sessionID); result = (ScrCity) session.load(ScrCity.class, new Integer(id)); HibernateUtil.commitTransaction(tran); return result; } catch (SessionException sE) { HibernateUtil.rollbackTransaction(tran); throw sE; } catch (Exception e) { HibernateUtil.rollbackTransaction(tran); log.error("Impossible to load ScrCity for session [" + sessionID + "]", e); throw new AttributesException(AttributesException.ERROR_CANNOT_FIND_CITIES); } finally { HibernateUtil.closeSession(entidad); } }
public static ValidationResults getProvForCities( String sessionID, int firstRow, int maxResults, String where, String additionalFieldName, String docColName, String entidad) throws AttributesException, SessionException, ValidationException { Validator.validate_String_NotNull_LengthMayorZero( sessionID, ValidationException.ATTRIBUTE_SESSION); Validator.validate_String_NotNull_LengthMayorZero( sessionID, ValidationException.ATTRIBUTE_SESSION); ValidationResults result = new ValidationResults(); Transaction tran = null; try { Session session = HibernateUtil.currentSession(entidad); tran = session.beginTransaction(); // Recuperamos la sesión CacheFactory.getCacheInterface().getCacheEntry(sessionID); // Calculamos el tamaño de los resultados StringBuffer querySize = new StringBuffer(); querySize.append("select count(*) from "); querySize.append(HIBERNATE_ScrProv); querySize.append(" as scr"); if (where != null && where.length() > 0) { querySize.append(" as scr where "); } Criteria criteriaResults = session.createCriteria(ScrProv.class); result = getValidationResults( session, criteriaResults, querySize.toString(), where, 1, firstRow, maxResults, "name"); result.setAdditionalFieldName(additionalFieldName); result.setDocColName(docColName); // result.setResults(provincies); HibernateUtil.commitTransaction(tran); return result; } catch (Exception e) { log.error( "Impossible to load provinces for getProvForCities for session [" + sessionID + "]", e); throw new AttributesException(AttributesException.ERROR_CANNOT_FIND_PROV); } finally { HibernateUtil.closeSession(entidad); } }
/** * Metodo que obtiene el id del grupo mediante su guid * * @param guid * @param entidad * @return id * @throws SecurityException */ public Integer getIdGroup(String guid, String entidad) throws SecurityException { Transaction tran = null; Integer result = null; try { Session session = HibernateUtil.currentSession(entidad); // tran = session.beginTransaction(); // Obtener el grupo ldap de la tabla de grupos List list = ISicresQueries.getUserLdapPgrp(session, guid); if (list != null && !list.isEmpty()) { Iuserldapgrphdr udeptGrpHdr = (Iuserldapgrphdr) list.get(0); if (log.isDebugEnabled()) { log.debug(" Iuserldapgrphdr [" + udeptGrpHdr + "] con el log [" + log + "]"); } result = Integer.valueOf(udeptGrpHdr.getId()); } // HibernateUtil.commitTransaction(tran); } catch (Exception e) { // HibernateUtil.rollbackTransaction(tran); log.error("Impossible to verify user with guid[" + guid + "]", e); throw new SecurityException(SecurityException.ERROR_USER_NOTFOUND); } /* * finally { HibernateUtil.closeSession(); } */ return result; }
private List getUserDeptList(Integer userId, String entidad, List deptListLDAP) throws SecurityException { String sqlUsrOfic = "id in (select idofic from scr_usrofic where iduser = "******")"); Criteria criteriaResults = session.createCriteria(ScrOfic.class); criteriaResults.add(Expression.sql(query.toString())); List list = criteriaResults.list(); if (deptListLDAP != null) { deptList.addAll(deptListLDAP); } if (list != null && list.size() > 0) { Iterator it = list.iterator(); while (it.hasNext()) { ScrOfic ofic = (ScrOfic) it.next(); if (!deptList.contains(new Integer(ofic.getDeptid()))) deptList.add(new Integer(ofic.getDeptid())); } } return deptList; } catch (Exception e) { log.error("Impossible to load other offices for user [" + userId + "]", e); throw new SecurityException(SecurityException.ERROR_USER_NOTFOUND); } }
public Integer userVerification(LDAPAuthenticationUser attributesUser, String entidad) throws SecurityException { Integer userId = null; try { Session session = HibernateUtil.currentSession(entidad); // tran = session.beginTransaction(); // consulta si existe el usuario en ldap List list = ISicresQueries.getUserLdapUser(session, attributesUser.getGuidStringFormat()); // si no existe el usuario lo inserta en el modelo de isicres if (list == null || list.isEmpty()) { userId = new Integer( DBEntityDAOFactory.getCurrentDBEntityDAO() .getNextIdForUser( attributesUser.getGuidStringFormat(), attributesUser.getFullName(), entidad)); if (log.isDebugEnabled()) { log.debug("new userId [" + userId + "] con el log [" + log + "]"); } list = ISicresQueries.getUserUserType(session, userId.intValue(), 5); Iuserusertype userType = null; if (list == null || list.isEmpty()) { userType = new Iuserusertype(); userType.setUserid(userId.intValue()); // producto sicres valor 5 // seteamos usuario estandar (operador de registro) // IDocKeys // IUSER_USER_TYPE_NULL (0) // IUSERUSERTYPE_USER_TYPE_OPERATOR = 1; // IUSERUSERTYPE_USER_TYPE_BOOK_ADMIN = 2; // IUSERUSERTYPE_USER_TYPE_ADMIN = 3; userType.setProdid(5); userType.setType(1); session.save(userType); // IUSER_PROD_ID_IUSER (2) (q tipo de producto es este? para q es?) userType = new Iuserusertype(); userType.setUserid(userId.intValue()); userType.setProdid(2); userType.setType(0); session.save(userType); session.flush(); } } else { // el usuario ya existe en el sistema de sicres Iuserldapuserhdr ldapUser = (Iuserldapuserhdr) list.get(0); if (log.isDebugEnabled()) { log.debug("exist userId Iuserldapuserhdr [" + ldapUser + "] con el log [" + log + "]"); } // obtenemos el perfil del usuario userId = new Integer(ldapUser.getId()); list = ISicresQueries.getUserUserType(session, ldapUser.getId(), 5); // Si no existen valores en iuserusertype, se lanzará una excepción de seguridad if (list == null || list.size() == 0) { throw new SecurityException(SecurityException.ERROR_IUSERUSERTYPE_NOT_FOUND); } Iuserusertype userType = (Iuserusertype) list.get(0); if (log.isDebugEnabled()) { log.debug("exist userId Iuserusertype [" + userType + "] con el log [" + log + "]"); } // DBEntityDAOFactory.getCurrentDBEntityDAO().updateRole(userType.getUserid(), // userType.getProdid(), 1, entidad); DBEntityDAOFactory.getCurrentDBEntityDAO() .updateRole(userType.getUserid(), userType.getProdid(), userType.getType(), entidad); DBEntityDAOFactory.getCurrentDBEntityDAO() .updateLdapFullName(ldapUser.getId(), attributesUser.getFullName(), entidad); } // HibernateUtil.commitTransaction(tran); } catch (HibernateException e) { // HibernateUtil.rollbackTransaction(tran); log.error("Impossible to verify user [" + attributesUser + "] on LDAP", e); throw new SecurityException(SecurityException.ERROR_SQL); } catch (SecurityException e) { throw e; } catch (Exception e) { // HibernateUtil.rollbackTransaction(tran); log.error("Impossible to verify user [" + attributesUser + "] on LDAP", e); throw new SecurityException(SecurityException.ERROR_SQL); } /* * finally { HibernateUtil.closeSession(); } */ return userId; }