List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:ca.myewb.controllers.common.EventList.java
License:Open Source License
public int visibleEventCount(String filter, Date endAfter) throws HibernateException { Criteria criteria = hibernateSession.createCriteria(EventModel.class); if (!currentUser.isAdmin()) { criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true))); }/*w w w .ja v a 2 s . c om*/ addBooleanFilters(endAfter, criteria); addFilter(filter, criteria); criteria.addOrder(Order.asc("startDate")); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return getUniqueEventCount(criteria); }
From source file:ca.myewb.controllers.common.EventList.java
License:Open Source License
public int visiblePreviousEventCount(String filter, Date fromDate) throws HibernateException { Criteria criteria = hibernateSession.createCriteria(EventModel.class); if (!currentUser.isAdmin()) { criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true))); }/* w w w . j av a2 s . com*/ criteria.add(Restrictions.lt("startDate", fromDate)); addFilter(filter, criteria); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return getUniqueEventCount(criteria); }
From source file:ca.myewb.controllers.common.WhiteboardList.java
License:Open Source License
public List<WhiteboardModel> listPaginatedVisibleWhiteboards(int startPage, int eventsPerPage) throws HibernateException { Criteria criteria = hibernateSession.createCriteria(WhiteboardModel.class); if (!currentUser.isAdmin() || !currentUser.getAdminToggle()) { criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true))); }//from ww w . j a v a 2s . c o m criteria.add(Restrictions.ne("numEdits", 0)); criteria.add(Restrictions.gt("lastEditDate", currentUser.getLastLogin())); criteria.addOrder(Order.desc("lastEditDate")); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); addPagination(startPage, eventsPerPage, criteria); return getUniqueWhiteboardList(criteria); }
From source file:ca.myewb.controllers.common.WhiteboardList.java
License:Open Source License
public int visibleWhiteboardCount() throws HibernateException { Criteria criteria = hibernateSession.createCriteria(WhiteboardModel.class); if (!currentUser.isAdmin() || !currentUser.getAdminToggle()) { criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true))); }//from w w w . j a v a 2s . c o m criteria.add(Restrictions.ne("numEdits", 0)); criteria.add(Restrictions.gt("lastEditDate", currentUser.getLastLogin())); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return getUniqueWhiteboardCount(criteria); }
From source file:ca.myewb.controllers.mailing.AvailableLists.java
License:Open Source License
public void handle(Context ctx) throws Exception { List<GroupModel> currentLists = currentUser.getGroups(); GroupChapterModel chapter = currentUser.getChapter(); Criteria crit = null; Hashtable<String, List<GroupModel>> hash = new Hashtable<String, List<GroupModel>>(); List<String> names = new Vector<String>(); //chapter lists crit = hibernateSession.createCriteria(GroupChapterModel.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq("visible", new Boolean(true))); crit.addOrder(Order.asc("name")); List<GroupModel> chapterLists = (new SafeHibList<GroupModel>(crit)).list(); chapterLists.removeAll(currentLists); //general public lists crit = hibernateSession.createCriteria(GroupModel.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq("admin", new Boolean(false))); crit.add(Restrictions.eq("visible", new Boolean(true))); crit.add(Restrictions.isNull("parent")); crit.add(Restrictions.eq("public", new Boolean(true))); List<GroupModel> generalPublicLists = (new SafeHibList<GroupModel>(crit)).list(); generalPublicLists.removeAll(currentLists); generalPublicLists.removeAll(chapterLists); log.debug("Populating available lists:"); if (currentUser.getUsername().equals("guest")) { generalPublicLists.add(0, Helpers.getGroup("Org")); log.debug("Global list, for the guest"); }//from www. j a v a2 s. c o m if (!generalPublicLists.isEmpty()) { hash.put("General Public Lists", generalPublicLists); names.add("General Public Lists"); log.debug("General public lists"); } if (currentUser.isMember("Exec")) { // admin level lists List<GroupModel> adminLists = Helpers.getNationalRepLists(true, true); adminLists.add(0, Helpers.getGroup("ProChaptersExec")); adminLists.add(0, Helpers.getGroup("UniChaptersExec")); adminLists.add(0, Helpers.getGroup("Exec")); adminLists.removeAll(currentLists); if (!adminLists.isEmpty()) { hash.put("Exec and Natl Rep Lists", adminLists); names.add("Exec and Natl Rep Lists"); } } if (currentUser.isAdmin()) { { //general private lists crit = hibernateSession.createCriteria(GroupModel.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq("admin", new Boolean(false))); crit.add(Restrictions.eq("visible", new Boolean(true))); crit.add(Restrictions.isNull("parent")); crit.add(Restrictions.eq("public", new Boolean(false))); List<GroupModel> generalPrivateLists = (new SafeHibList<GroupModel>(crit)).list(); generalPrivateLists.removeAll(currentLists); if (!generalPrivateLists.isEmpty()) { hash.put("General Private Lists", generalPrivateLists); names.add("General Private Lists"); log.debug("General private lists"); } else { log.debug("General private lists was empty"); } } { //all chapter public lists crit = hibernateSession.createCriteria(GroupModel.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq("admin", new Boolean(false))); crit.add(Restrictions.eq("visible", new Boolean(true))); crit.add(Restrictions.isNotNull("parent")); crit.add(Restrictions.eq("public", new Boolean(true))); crit.addOrder(Order.asc("parent")); List<GroupModel> chapterPublicLists = (new SafeHibList<GroupModel>(crit)).list(); chapterPublicLists.removeAll(currentLists); if (!chapterPublicLists.isEmpty()) { hash.put("Chapter Public Lists (any chapter)", chapterPublicLists); names.add("Chapter Public Lists (any chapter)"); log.debug("Chapter public lists for admin"); } else { log.debug("Chapter public lists for admin; empty"); } } { //all chapter private lists crit = hibernateSession.createCriteria(GroupModel.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq("admin", new Boolean(false))); crit.add(Restrictions.eq("visible", new Boolean(true))); crit.add(Restrictions.isNotNull("parent")); crit.add(Restrictions.eq("public", new Boolean(false))); crit.addOrder(Order.asc("parent")); List<GroupModel> chapterPrivateLists = (new SafeHibList<GroupModel>(crit)).list(); chapterPrivateLists.removeAll(currentLists); if (!chapterPrivateLists.isEmpty()) { hash.put("Chapter Private Lists (any chapter)", chapterPrivateLists); names.add("Chapter Private Lists (any chapter)"); log.debug("Chapter private lists, admin"); } else { log.debug("Chapter private lists, admin, empty"); } } } else { if (chapter != null) { //chapter public lists crit = hibernateSession.createCriteria(GroupModel.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq("admin", new Boolean(false))); crit.add(Restrictions.eq("visible", new Boolean(true))); crit.add(Restrictions.eq("parent", chapter)); crit.add(Restrictions.eq("public", new Boolean(true))); List<GroupModel> chapterPublicLists = (new SafeHibList<GroupModel>(crit)).list(); chapterPublicLists.removeAll(currentLists); if (!chapterPublicLists.isEmpty()) { hash.put("Chapter Public Lists", chapterPublicLists); names.add("Chapter Public Lists"); log.debug("Chapter public lists"); } else { log.debug("Chapter public lists was empty"); } if (currentUser.isLeader(chapter, false)) { //own chapter's private lists crit = hibernateSession.createCriteria(GroupModel.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq("admin", new Boolean(false))); crit.add(Restrictions.eq("visible", new Boolean(true))); crit.add(Restrictions.eq("parent", chapter)); crit.add(Restrictions.eq("public", new Boolean(false))); List<GroupModel> chapterPrivateLists = (new SafeHibList<GroupModel>(crit)).list(); chapterPrivateLists.removeAll(currentLists); if (!chapterPrivateLists.isEmpty()) { hash.put("Chapter Private Lists", chapterPrivateLists); names.add("Chapter Private Lists"); log.debug("Chapter private lists"); } else { log.debug("Chapter private lists was empty"); } } } } if (!chapterLists.isEmpty()) { hash.put("Chapter Lists", chapterLists); names.add("Chapter Lists"); log.debug("Chapter lists"); } // Stick it all in the context ctx.put("names", names); ctx.put("names2", names); ctx.put("hash", hash); }
From source file:ca.myewb.frame.Cron.java
License:Open Source License
private static void doTwoWeekWarnings(Logger log, Session session) throws Exception { // 2-week warning log.info("----- 14-day warning"); Calendar calendar = Calendar.getInstance(); Criteria crit = session.createCriteria(UserModel.class); crit.add(Restrictions.isNotNull("email")); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); calendar.add(Calendar.DAY_OF_YEAR, 14); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); crit.add(Restrictions.eq("expiry", calendar.getTime())); Iterator it = crit.list().iterator(); while (it.hasNext()) { UserModel u = (UserModel) it.next(); log.info(u.getFirstname() + " " + u.getLastname() + ": " + u.getEmail()); VelocityContext mailCtx = new VelocityContext(); mailCtx.put("helpers", new Helpers()); mailCtx.put("name", u.getFirstname()); mailCtx.put("numdays", "14 days"); mailCtx.put("expiry", formatter.format(calendar.getTime())); Template template = Velocity.getTemplate("emails/expirywarning.vm"); StringWriter writer = new StringWriter(); template.merge(mailCtx, writer); EmailModel.sendEmail(u.getEmail(), writer.toString()); }//from w w w .ja v a2s. c o m }
From source file:ca.myewb.frame.Cron.java
License:Open Source License
private static void doOneWeekWarnings(Logger log, Session session) throws Exception { // 1-week warning log.info("----- 7-day warning"); Calendar calendar = Calendar.getInstance(); Criteria crit = session.createCriteria(UserModel.class); crit.add(Restrictions.isNotNull("email")); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); calendar.add(Calendar.DAY_OF_YEAR, 7); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); crit.add(Restrictions.eq("expiry", calendar.getTime())); Iterator it = crit.list().iterator(); while (it.hasNext()) { UserModel u = (UserModel) it.next(); log.info(u.getFirstname() + " " + u.getLastname() + ": " + u.getEmail()); VelocityContext mailCtx = new VelocityContext(); mailCtx.put("helpers", new Helpers()); mailCtx.put("name", u.getFirstname()); mailCtx.put("numdays", "7 days"); mailCtx.put("expiry", formatter.format(calendar.getTime())); Template template = Velocity.getTemplate("emails/expirywarning.vm"); StringWriter writer = new StringWriter(); template.merge(mailCtx, writer); EmailModel.sendEmail(u.getEmail(), writer.toString()); }/*from w w w . ja v a 2 s. c o m*/ }
From source file:ca.myewb.frame.Cron.java
License:Open Source License
private static void doOneDayWarnings(Logger log, Session session) throws Exception { // 1-day warning log.info("----- 1-day warning"); Calendar calendar = Calendar.getInstance(); Criteria crit = session.createCriteria(UserModel.class); crit.add(Restrictions.isNotNull("email")); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); calendar.add(Calendar.DAY_OF_YEAR, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); crit.add(Restrictions.eq("expiry", calendar.getTime())); Iterator it = crit.list().iterator(); while (it.hasNext()) { UserModel u = (UserModel) it.next(); log.info(u.getFirstname() + " " + u.getLastname() + ": " + u.getEmail()); VelocityContext mailCtx = new VelocityContext(); mailCtx.put("helpers", new Helpers()); mailCtx.put("name", u.getFirstname()); mailCtx.put("numdays", "1 day"); mailCtx.put("expiry", formatter.format(calendar.getTime())); Template template = Velocity.getTemplate("emails/expirywarning.vm"); StringWriter writer = new StringWriter(); template.merge(mailCtx, writer); EmailModel.sendEmail(u.getEmail(), writer.toString()); }/*from ww w . j a v a 2 s . c om*/ }
From source file:ca.myewb.frame.Cron.java
License:Open Source License
private static void doMembershipExpiry(Logger log, Session session) throws Exception { // expiry//from w ww.j av a2 s . c om log.info("----- Expiry"); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Criteria crit = session.createCriteria(UserModel.class); crit.add(Restrictions.isNotNull("email")); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.le("expiry", calendar.getTime())); Iterator it = crit.list().iterator(); while (it.hasNext()) { UserModel u = (UserModel) it.next(); log.info(u.getFirstname() + " " + u.getLastname() + ": " + u.getEmail()); u.expire(); VelocityContext mailCtx = new VelocityContext(); mailCtx.put("helpers", new Helpers()); mailCtx.put("name", u.getFirstname()); Template template = Velocity.getTemplate("emails/expiry.vm"); StringWriter writer = new StringWriter(); template.merge(mailCtx, writer); EmailModel.sendEmail(u.getEmail(), writer.toString()); } }
From source file:ca.myewb.frame.Helpers.java
License:Open Source License
public static List<GroupModel> getNationalRepLists(boolean includeUni, boolean includePro) { Criteria crit = HibernateUtil.currentSession().createCriteria(GroupModel.class); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); ArrayList<Object> types = new ArrayList<Object>(); types.add('b'); if (includePro) { types.add('p'); }//from w ww .jav a 2 s .co m if (includeUni) { types.add('s'); } crit.add(Restrictions.in("nationalRepType", types)); return (new SafeHibList<GroupModel>(crit)).list(); }