List of usage examples for org.hibernate.criterion DetachedCriteria forEntityName
@SuppressWarnings("UnusedDeclaration") public static DetachedCriteria forEntityName(String entityName)
From source file:ro.cs.om.model.dao.impl.DaoRoleImpl.java
License:Open Source License
/** * Returns a default Role for a Module identified by it's name. * //from w w w .j av a 2s .c om * @author dan.damian */ public RoleWeb getDefaultRoleByModule(Integer moduleId, String name) { logger.debug("getDefaultRoleByModule START moduleId: ".concat(String.valueOf(moduleId)).concat(", name: ") .concat(name)); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleWebEntity); dc.add(Restrictions.eq("status", (int) IConstant.ROLE_STATUS_DEFAULT)); dc.add(Restrictions.eq("moduleId", moduleId)); dc.add(Restrictions.eq("name", name)); List<RoleWeb> roles = getHibernateTemplate().findByCriteria(dc); logger.debug("getDefaultRole END ".concat(String.valueOf(roles.size()))); if (roles.size() > 0) { return roles.get(0); } else { return null; } }
From source file:ro.cs.om.model.dao.impl.DaoRoleImpl.java
License:Open Source License
/** * Get roles by organisation and module/* w ww.jav a 2 s .c om*/ * @author Adelina * @param organisationId * @param moduleId * @return List<RoleWeb> */ @SuppressWarnings("unchecked") public List<RoleWeb> getRolesByModuleAndOrg(Integer organisationId, Integer moduleId) { logger.debug("getRolesByModuleAndOrg DAO IMPL - START - "); logger.debug("organisationId = " + organisationId); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleWebEntity); dc.add(Restrictions.eq("organisationId", organisationId)); dc.add(Restrictions.eq("moduleId", moduleId)); List roles = getHibernateTemplate().findByCriteria(dc); logger.debug("getRolesByModuleAndOrg DAO IMPL - END - ".concat(String.valueOf(roles.size()))); return roles; }
From source file:ro.cs.om.model.dao.impl.DaoRoleImpl.java
License:Open Source License
/** * /*from w w w .ja va 2s . co m*/ * Return the role with the given name in the organisation if present * @author mitziuro * @param organisationId * @param name * @return */ public Role getRoleByNameAndOrg(Integer organisationId, String name) { logger.debug("getRoleByNameAndOrg DAO IMPL - START - "); logger.debug("name = ".concat(name)); logger.debug("organisationId = ".concat(String.valueOf(organisationId))); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleForListingEntity); dc.add(Restrictions.eq("name", name)); dc.add(Restrictions.eq("organisation.organisationId", organisationId)); List<Role> roles = getHibernateTemplate().findByCriteria(dc); /*String hquery = "from Role where name='".concat(name).concat("'").concat(" and organisationId=").concat(String.valueOf(organisationId)); List<Role> roles = getHibernateTemplate().find(IModelConstant.roleForListingEntity, hquery);*/ if (roles.size() > 0) { return (Role) roles.get(0); } return null; }
From source file:ro.cs.om.model.dao.impl.DaoRoleImpl.java
License:Open Source License
/** * Return the roles with the given names in the organisation if present * /* w w w .j a v a 2 s. c o m*/ * @author Adelina * * @param organisationId * @param count * @param name * @return List<Role> */ public List<Role> getRolesByNamesAndOrg(Integer organisationId, int count, String... name) { logger.debug("getRoleByNameAndOrg DAO IMPL - START - "); for (int i = 0; i < count; i++) { logger.debug("name = ".concat(name[i])); } logger.debug("organisationId = ".concat(String.valueOf(organisationId))); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleForListingEntity); Disjunction disjunction = Restrictions.disjunction(); for (int i = 0; i < count; i++) { disjunction.add(Restrictions.eq("name", name[i])); } dc.add(disjunction); dc.add(Restrictions.eq("organisation.organisationId", organisationId)); List<Role> roles = getHibernateTemplate().findByCriteria(dc); return roles; }
From source file:ro.cs.om.model.dao.impl.DaoRoleImpl.java
License:Open Source License
/** * Get roles by organisation and module/*from ww w . j av a2s .c o m*/ * @author coni * @param organisationId * @param moduleId * @return List<Role> */ public List<Role> getRolesByModuleAndOrganisation(Integer organisationId, Integer moduleId, Person person) { logger.debug("getRolesByModuleAndOrganisation DAO IMPL - START - "); logger.debug("organisationId = " + organisationId); logger.debug("moduleId = " + moduleId); Set<Role> roles = person.getRoles(); Integer[] roleIds = new Integer[roles.size()]; int i = 0; for (Role role : roles) { roleIds[i] = role.getRoleId(); i++; } DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleForListingEntity); dc.add(Restrictions.eq("organisation.organisationId", organisationId)); dc.add(Restrictions.eq("module.moduleId", moduleId)); dc.add(Restrictions.not(Restrictions.in("roleId", roleIds))); List<Role> res = getHibernateTemplate().findByCriteria(dc); logger.debug("getRolesByModuleAndOrganisation DAO IMPL - END - ".concat(String.valueOf(roles.size()))); return res; }
From source file:ro.cs.om.model.dao.impl.DaoRoleImpl.java
License:Open Source License
/** * Gets the default roles (those that have status = 2) * /*from w w w . j ava 2 s . co m*/ * @author Adelina * * @return List<Role> */ @SuppressWarnings("unchecked") public List<Role> getDefaultRoles(Integer moduleId) { logger.debug("getDefaultRoles DAO IMPL - START - "); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleForListingEntity); dc.add(Restrictions.eq("status", (int) IConstant.ROLE_STATUS_DEFAULT)); dc.add(Restrictions.eq("module.moduleId", moduleId)); List roles = getHibernateTemplate().findByCriteria(dc); logger.debug("getDefaultRoles DAO IMPL - END - ".concat(String.valueOf(roles.size()))); return roles; }
From source file:ro.cs.om.model.dao.impl.DaoRoleImpl.java
License:Open Source License
/** * //from www . j a v a2s .c o m * Add the default roles for a given module, to an organization, * when that organization updates the modules * * @author Adelina * * @param moduleId * @param organisationId */ @SuppressWarnings("unchecked") public void addDefaultRolesToOrganisation(Integer moduleId, Integer organisationId) { logger.debug("getDefaultRolesToOrganisation - START - "); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleForListingEntity); dc.add(Restrictions.ne("status", (int) IConstant.ROLE_STATUS_DEFAULT)); dc.add(Restrictions.eq("organisation.organisationId", organisationId)); dc.add(Restrictions.eq("module.moduleId", moduleId)); List<Role> roles = getHibernateTemplate().findByCriteria(dc); if (roles != null && roles.size() == 0) { addDefaultRoles(organisationId, moduleId); } logger.debug("getDefaultRolesToOrganisation- ".concat(String.valueOf(roles.size()))); }
From source file:ro.cs.om.model.dao.impl.DaoRoleImpl.java
License:Open Source License
/** * Gets the list of persons that has a specific permission * // w w w . j av a 2s . c o m * @author Adelina * * @param permissionName * @return */ public Set<Person> getPersonsByRole(String permissionName, Integer organizationId) { logger.debug("getPersonsByRole - START"); Set<Person> persons = new HashSet<Person>(); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleAllEntity); dc.add(Restrictions.eq("name", IConstant.TS_USER_ALL)); dc.add(Restrictions.eq("module.moduleId", IConstant.TS_MODULE_ID)); dc.add(Restrictions.eq("organisation.organisationId", organizationId)); Permission permission = permissionDao.getByName(permissionName); logger.debug("permission = " + permission); if (permission == null) { return new HashSet<Person>(); } dc.createCriteria("permissions").add(Restrictions.eq("permissionId", permission.getPermissionId())); List<Role> roles = getHibernateTemplate().findByCriteria(dc); logger.debug("roles = " + roles); if (roles != null && roles.size() > 0) { for (Role role : roles) { logger.debug("role = " + role); Set<Person> rolesPersons = role.getPersons(); logger.debug("rolesPersons = " + rolesPersons); if (rolesPersons != null && rolesPersons.size() > 0) { for (Person person : rolesPersons) { persons.add(person); } } } } else { logger.debug("getPersonBYRole - END"); return new HashSet<Person>(); } logger.debug("getPersonBYRole - END"); return persons; }
From source file:ro.cs.om.model.dao.impl.DaoUserGroupImpl.java
License:Open Source License
public List<UserGroup> getUserGroupBeanFromSearch(SearchUserGroupBean searchUserGroupBean, boolean isDeleteAction) { logger.debug("DaoUserGroupImpl - getUserGroupBeanFromSearch - START - name: " .concat(String.valueOf(searchUserGroupBean.getName())) .concat(" - organisationId: ".concat(String.valueOf(searchUserGroupBean.getOrganisationId())))); /*Once a Projection is being set to a Detached Criteria object, it cannot be removed anymore, so two identical DetachedCriteria objects must be created: /*from ww w .j ava2 s .c om*/ -dcCount ( on which the projection is being set )used to retrieve the number of distinct results which is set when the request didn't come from the pagination area and needed further more to set the current page after a delete action; -dc used to retrieve the result set after the current page has been set in case of a delete action */ // set search criterion DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.userGroupForListingEntity); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.userGroupForListingEntity); if (searchUserGroupBean.getName() != null && !"".equals(searchUserGroupBean.getName())) { dc.add(Restrictions.ilike("name", "%".concat(searchUserGroupBean.getName()).concat("%"))); dcCount.add(Restrictions.ilike("name", "%".concat(searchUserGroupBean.getName()).concat("%"))); } if (searchUserGroupBean.getOrganisationId() != -1) { dc.add(Restrictions.eq("organisation.organisationId", searchUserGroupBean.getOrganisationId())); dcCount.add(Restrictions.eq("organisation.organisationId", searchUserGroupBean.getOrganisationId())); } //the organization default user group mustn't be displayed dc.add(Restrictions.eq("status", IConstant.NOM_USER_GROUP_NORMAL)); dcCount.add(Restrictions.eq("status", IConstant.NOM_USER_GROUP_NORMAL)); // check if I have to order the results if (searchUserGroupBean.getSortParam() != null && !"".equals(searchUserGroupBean.getSortParam())) { // if I have to, check if I have to order them ascending or descending if (searchUserGroupBean.getSortDirection() == -1) { // ascending dc.addOrder(Order.asc(searchUserGroupBean.getSortParam())); } else { // descending dc.addOrder(Order.desc(searchUserGroupBean.getSortParam())); } } // if the request didn't come from the pagination area, // it means that I have to set the number of results and pages if (isDeleteAction || searchUserGroupBean.getNbrOfResults() == -1) { boolean isSearch = false; if (searchUserGroupBean.getNbrOfResults() == -1) { isSearch = true; } // set the count(*) restriction dcCount.setProjection(Projections.countDistinct("userGroupId")); //findByCriteria must be called with firstResult and maxResults parameters; the default findByCriteria(DetachedCriteria criteria) implementation //sets firstResult and maxResults to -1, which kills the countDistinct Projection int nbrOfResults = ((Integer) getHibernateTemplate().findByCriteria(dcCount, 0, 0).get(0)).intValue(); logger.debug("search results: ".concat(String.valueOf(nbrOfResults))); searchUserGroupBean.setNbrOfResults(nbrOfResults); // get the number of pages if (nbrOfResults % searchUserGroupBean.getResultsPerPage() == 0) { searchUserGroupBean.setNbrOfPages(nbrOfResults / searchUserGroupBean.getResultsPerPage()); } else { searchUserGroupBean.setNbrOfPages(nbrOfResults / searchUserGroupBean.getResultsPerPage() + 1); } // after an user group is deleted, the same page has to be displayed; //only when all the user groups from last page are deleted, the previous page will be shown if (isDeleteAction && (searchUserGroupBean.getCurrentPage() > searchUserGroupBean.getNbrOfPages())) { searchUserGroupBean.setCurrentPage(searchUserGroupBean.getNbrOfPages()); } else if (isSearch) { searchUserGroupBean.setCurrentPage(1); } } List<UserGroup> res = (List<UserGroup>) getHibernateTemplate().findByCriteria(dc, (searchUserGroupBean.getCurrentPage() - 1) * searchUserGroupBean.getResultsPerPage(), searchUserGroupBean.getResultsPerPage()); logger.debug("DaoUserGroupImpl - getUserGroupBeanFromSearch - END"); return res; }
From source file:ro.cs.om.model.dao.impl.DaoUserGroupImpl.java
License:Open Source License
public UserGroup getDefaultUserGrup(int organizationId) { logger.debug("DaoUserGroupImpl - getDefaultUserGrup - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.userGroupSimpleEntity); //user group status must be default dc.add(Restrictions.eq("status", IConstant.NOM_USER_GROUP_DEFAULT)); dc.add(Restrictions.eq("organisation.organisationId", organizationId)); UserGroup defaultUserGroup = null;/* w ww . jav a 2s .co m*/ List userGroups = getHibernateTemplate().findByCriteria(dc); if (userGroups != null && userGroups.size() > 0) { defaultUserGroup = (UserGroup) userGroups.get(0); } logger.debug("DaoUserGroupImpl - getDefaultUserGrup - END"); return defaultUserGroup; }