List of usage examples for org.hibernate Criteria setProjection
public Criteria setProjection(Projection projection);
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationDao.java
License:Mozilla Public License
@Override public Long countApps(Integer orgId, String searchString, Set<Integer> appIds, Set<Integer> teamIds) { Criteria criteria = getSearchAppCriteria(orgId, searchString); addFiltering(criteria, teamIds, appIds); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationDao.java
License:Mozilla Public License
@Override public Long countVulns(Integer orgId, Set<Integer> appIds, Set<Integer> teamIds) { Criteria criteria = getSearchAppCriteria(orgId, null); addFiltering(criteria, teamIds, appIds); return (Long) criteria.setProjection(Projections.sum("totalVulnCount")).uniqueResult(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateEventDao.java
License:Mozilla Public License
private List<Event> retrieveGrouped(List<String> eventActions, User user, Date startTime, Date stopTime, Set<Integer> appIds, Set<Integer> teamIds, Set<Integer> vulnIds, Set<Integer> defectIds) { Criteria criteria = getEventCriteria(eventActions, user, startTime, stopTime, appIds, teamIds, vulnIds, defectIds);// ww w . ja v a 2s . c o m criteria.setProjection(Projections.projectionList().add(Projections.count("id").as("groupCount")) .add(Projections.groupProperty("eventAction").as("eventAction")) .add(Projections.groupProperty("scan").as("scan")) .add(Projections.groupProperty("deletedScanId").as("deletedScanId")) .add(Projections.min("date"), "date").add(Projections.groupProperty("application"), "application") .add(Projections.groupProperty("user"), "user")); criteria.setResultTransformer(Transformers.aliasToBean(Event.class)); List<Event> events = criteria.list(); for (Event event : events) { EventAction eventAction = event.getEventActionEnum(); EventAction groupedEventAction = eventAction.getGroupedEventAction(); String groupedEventActionString = groupedEventAction.name(); event.setEventAction(groupedEventActionString); } return events; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateScheduledJobDao.java
License:Mozilla Public License
@Override public boolean checkSameDate(@Nonnull S scheduledJob) { if (scheduledJob.getDay() == null && scheduledJob.getFrequency() == null) { throw new IllegalArgumentException("Got scheduled job without day or frequency."); }//from w ww. j a va 2s .com Criteria criteria = getSession().createCriteria(getClassReference()); if (scheduledJob.getDay() != null) { criteria.add(Restrictions.eq("day", scheduledJob.getDay())); } else if (scheduledJob.getFrequency() != null) { criteria.add(Restrictions.eq("frequency", scheduledJob.getFrequency())); } criteria.add(Restrictions.eq("hour", scheduledJob.getHour())); criteria.add(Restrictions.eq("minute", scheduledJob.getMinute())); criteria.add(Restrictions.eq("period", scheduledJob.getPeriod())); criteria.setProjection(Projections.rowCount()); Long count = (Long) criteria.uniqueResult(); return (count > 0); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilityDao.java
License:Mozilla Public License
@Override public long getVulnCountWithFilters(Integer appId, String description, String severity, String path, String param, Integer cweInteger, boolean open, boolean falsePositive, boolean hidden) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Vulnerability.class); if (hidden) { criteria.add(Restrictions.eq("hidden", true)); } else {/*from w w w . j a v a 2 s. com*/ criteria.add(Restrictions.eq("hidden", false)); if (!open && falsePositive) { criteria.add(Restrictions.eq("isFalsePositive", true)); } else { criteria.add(Restrictions.eq("active", open)).add(Restrictions.eq("hidden", false)) .add(Restrictions.eq("isFalsePositive", falsePositive)); } } criteria.createAlias("genericVulnerability", "vuln").add(Restrictions.eq("application.id", appId)); // Add Filtering restrictions if (description != null) { criteria.add(Restrictions.like("vuln.name", "%" + description + "%").ignoreCase()); } if (severity != null) { criteria.createAlias("genericSeverity", "severity") .add(Restrictions.like("severity.name", "%" + severity + "%").ignoreCase()); } if (path != null) { criteria.createAlias("surfaceLocation", "surface") .add(Restrictions.like("surface.path", "%" + path + "%").ignoreCase()); } if (cweInteger != null) { criteria.add(Restrictions.eq("vuln.id", cweInteger)); } if (param != null) { criteria.createAlias("surfaceLocation", "surface") .add(Restrictions.like("surface.parameter", "%" + param + "%").ignoreCase()); } return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilitySearchDao.java
License:Mozilla Public License
@Override public long performLookupCount(VulnerabilitySearchParameters parameters) { assert parameters != null; Criteria criteria = performLookupSetup(parameters); Number numVulns = (Number) criteria.setProjection(Projections.rowCount()).uniqueResult(); return numVulns.longValue(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilitySearchDao.java
License:Mozilla Public License
@Override public List<VulnerabilityTreeElement> getTree(VulnerabilitySearchParameters parameters) { assert parameters != null; Criteria criteria = VulnerabilitySearchCriteriaConstructor .getCriteriaWithRestrictions(sessionFactory.getCurrentSession(), parameters); criteria.setProjection(Projections.projectionList().add(Projections.countDistinct("id"), "numResults") .add(Projections.groupProperty("severity.intValue")) .add(Projections.groupProperty("genericVulnAlias.id"), "genericVulnerabilityId") .add(Projections.groupProperty("genericVulnAlias.name"), "genericVulnerabilityName") .add(Projections.groupProperty("genericVulnAlias.cweId"), "genericVulnerabilityDisplayId") .add(Projections.groupProperty("severity.intValue"), "severityIntValue")) .addOrder(Order.desc("severityIntValue")).addOrder(Order.desc("numResults")); criteria.setResultTransformer(Transformers.aliasToBean(VulnerabilityTreeElement.class)); return (List<VulnerabilityTreeElement>) criteria.list(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilitySearchDao.java
License:Mozilla Public License
@Override public List<Map> getScanComparison(VulnerabilitySearchParameters parameters, boolean isFalsePositive) { assert parameters != null; List<Integer> idList = getVulnIdList(parameters); if (idList.isEmpty()) return list(); Session session = sessionFactory.getCurrentSession(); List<Map> fullList = list(); // TODO refactor this to reduce duplication or remove the need for it int current = 0; while (current < idList.size()) { int start = current, end = current + 500; if (end > idList.size()) { end = idList.size();/*from w w w . ja va 2 s . co m*/ } List<Integer> thisPage = idList.subList(start, end); Criteria criteria = session.createCriteria(Vulnerability.class); criteria.createAlias("findings", "finding"); criteria.createAlias("finding.scan", "scan"); criteria.createAlias("scan.applicationChannel", "applicationChannel"); criteria.createAlias("applicationChannel.channelType", "channelType"); criteria.add(Restrictions.in("id", thisPage)); ProjectionList projectionList = Projections.projectionList() .add(Projections.groupProperty("channelType.name"), "channelName") .add(Projections.alias(Projections.countDistinct("id"), "foundCount")); if (!isFalsePositive) { projectionList.add(Projections.groupProperty("foundHAMEndpoint"), "foundHAMEndpoint"); } criteria.setProjection(projectionList); criteria.addOrder(Order.desc("foundCount")); criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List results = (List<Map>) criteria.list(); fullList.addAll(results); current += 500; } return fullList; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilitySearchDao.java
License:Mozilla Public License
private List<Integer> getVulnIdList(VulnerabilitySearchParameters parameters) { Criteria criteria = VulnerabilitySearchCriteriaConstructor .getCriteriaWithRestrictions(sessionFactory.getCurrentSession(), parameters); criteria.setProjection(Projections.projectionList().add(Projections.property("id"))); List<Integer> idList = (List<Integer>) criteria.list(); return idList; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.VulnerabilitySearchCriteriaConstructor.java
License:Mozilla Public License
private void addAppTags() { List<Integer> appIds; List<Integer> tagIds = list(); if (parameters.getTags() != null) { for (Tag tag : parameters.getTags()) { if (tag.getId() != null) { tagIds.add(tag.getId()); }//from ww w.j a v a 2 s. co m } } if (tagIds.isEmpty()) { LOG.debug("No tag IDs found in parameters."); } else { Criteria subCriteria = session.createCriteria(Tag.class); subCriteria.createAlias("applications", "applicationsAlias"); subCriteria.add(Restrictions.in("id", tagIds)); subCriteria.setProjection(Projections.property("applicationsAlias.id")); appIds = (List<Integer>) subCriteria.list(); if (appIds.isEmpty()) appIds.add(0); criteria.add(Restrictions.in("application.id", appIds)); LOG.debug("Added applications with IDs " + appIds); } }