List of usage examples for org.hibernate Criteria createAlias
public Criteria createAlias(String associationPath, String alias) throws HibernateException;
From source file:com.dell.asm.asmcore.asmmanager.db.TemplateDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<TemplateEntity> getAllTemplates(List<SortParamParser.SortInfo> sortInfos, List<FilterParamParser.FilterInfo> filterInfos, PaginationInfo paginationInfo) { Session session = null;// w w w .j a v a2 s .c o m Transaction tx = null; List<TemplateEntity> entityList = new ArrayList<>(); try { int offset = paginationInfo.getOffset(); int pageSize = paginationInfo.getLimit(); session = _dao._database.getNewSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(TemplateEntity.class); BaseDAO.addSortCriteria(criteria, sortInfos); List<FilterParamParser.FilterInfo> notFound = BaseDAO.addFilterCriteria(criteria, filterInfos, TemplateEntity.class); if (notFound != null && notFound.size() > 0) { criteria.createAlias("templateEntity", "templateEntityAlias"); for (FilterParamParser.FilterInfo filterInfo : notFound) { criteria.add(Restrictions.eq("templateEntityAlias.deviceKey", filterInfo.getColumnName())); if (filterInfo.getColumnValue().size() == 1) { criteria.add(Restrictions.eq("templateEntityAlias.deviceValue", filterInfo.getColumnValue().get(0))); } else if (filterInfo.getColumnValue().size() > 1) { criteria.add( Restrictions.in("templateEntityAlias.deviceValue", filterInfo.getColumnValue())); } } } //criteria.setFirstResult((pageNumber - 1) * pageSize); criteria.setFirstResult(offset); criteria.setMaxResults(pageSize); criteria.setFetchMode("policyRefEntities", FetchMode.SELECT); entityList = criteria.list(); // Collection<PolicyRefEntity> dummy; // for (TemplateEntity parm : entityList) { // dummy = parm.getPolicyRefEntities(); // dummy.isEmpty(); // } // workaround for dupliacate templates //entityList.addAll(buildUniqueList(criteria.list())); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get all templates: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get all templates: " + ex); } throw new AsmManagerInternalErrorException("Get All templates", "TemplateDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get all devices: " + ex); } } logger.warn("Template DAO get all templates size: " + entityList.size()); return entityList; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationDao.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Override//ww w . ja va 2s . c o m public List<Integer> getTopXVulnerableAppsFromList(int numApps, List<Integer> teamIdList, List<Integer> applicationIdList, List<Integer> tagIdList, List<Integer> vulnTagIdList) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Application.class); criteria.createAlias("vulnerabilities", "vulnerability"); criteria.add(Restrictions.eq("active", true)); criteria.add(Restrictions.eq("vulnerability.active", true)); criteria.add(Restrictions.eq("vulnerability.hidden", false)); criteria.add(Restrictions.eq("vulnerability.isFalsePositive", false)); if (vulnTagIdList.size() > 0) { criteria.createAlias("vulnerability.tags", "tags"); criteria.add(Restrictions.in("tags.id", vulnTagIdList)); } if (teamIdList.isEmpty() || applicationIdList.isEmpty()) { if (!applicationIdList.isEmpty()) { criteria.add(Restrictions.in("id", applicationIdList)); } if (!teamIdList.isEmpty()) { criteria.add(Restrictions.in("organization.id", teamIdList)); } } else { criteria.add(Restrictions.or(Restrictions.in("id", applicationIdList), Restrictions.in("organization.id", teamIdList))); } if (!tagIdList.isEmpty()) { criteria.createAlias("tags", "tag"); criteria.add(Restrictions.in("tag.id", tagIdList)); } criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("id")) .add(Projections.alias(Projections.countDistinct("vulnerability.id"), "vulnCount"))); criteria.addOrder(Order.desc("vulnCount")); List<Integer> list = list(); List results = criteria.list(); int i = 0; for (Object result : results) { if (i++ >= numApps) { break; } Object[] resultArray = (Object[]) result; list.add((Integer) resultArray[0]); } if (list.isEmpty()) list = Arrays.asList(-1); return list; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationDao.java
License:Mozilla Public License
@Override public List<Map<String, Object>> retrieveAppsInfoMap(List<Integer> applicationIdList, List<Integer> vulnTagIds) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Application.class); criteria.createAlias("vulnerabilities", "vulnerability"); criteria.createAlias("organization", "team"); criteria.add(Restrictions.eq("active", true)); criteria.add(Restrictions.eq("vulnerability.active", true)); criteria.add(Restrictions.eq("vulnerability.isFalsePositive", false)); criteria.createAlias("vulnerability.genericSeverity", "severity"); if (applicationIdList.size() > 0) { criteria.add(Restrictions.in("id", applicationIdList)); }/* w w w . j a v a2 s .c o m*/ if (vulnTagIds.size() > 0) { criteria.createAlias("vulnerability.tags", "tags"); criteria.add(Restrictions.in("tags.id", vulnTagIds)); } criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("id"), "appId") .add(Projections.groupProperty("name"), "appName") .add(Projections.groupProperty("team.id"), "teamId") .add(Projections.groupProperty("team.name"), "teamName") .add(Projections.groupProperty("severity.intValue"), "severityIntValue") .add(Projections.groupProperty("severity.name"), "severityNameValue") .add(Projections.alias(Projections.countDistinct("vulnerability.id"), "vulnCount"))); criteria.addOrder(Order.desc("vulnCount")); criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List results = criteria.list(); return results; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateApplicationVersionDao.java
License:Mozilla Public License
@Override public Map<String, Object> getAllVersionsByAppId(List<Integer> appIds) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Application.class); criteria.add(Restrictions.eq("active", true)); criteria.createAlias("versions", "version"); if (appIds != null) criteria.add(Restrictions.in("id", appIds)); List<Application> applications = (List<Application>) criteria.list(); Map<String, Object> map = CollectionUtils.map(); for (Application application : applications) { map.put(application.getOrganization().getName() + " / " + application.getName(), application.getVersions()); }/*from w w w . j av a 2 s . co m*/ return map; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateFindingDao.java
License:Mozilla Public License
@SuppressWarnings("unchecked") public Criteria getScanIdAndPageCriteria(Integer scanId, int page) { List<Integer> mappedFindingIds = (List<Integer>) sessionFactory.getCurrentSession() .createQuery("select finding.id from ScanRepeatFindingMap map " + "where map.scan.id = :scanId") .setInteger("scanId", scanId).list(); Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Finding.class) .add(Restrictions.eq("active", true)); if (mappedFindingIds != null && !mappedFindingIds.isEmpty()) { criteria.add(// w w w.j a va2 s. c om Restrictions.or(Restrictions.eq("scan.id", scanId), Restrictions.in("id", mappedFindingIds))); } else { criteria.add(Restrictions.eq("scan.id", scanId)); } return criteria.createAlias("channelSeverity", "severity").createAlias("channelVulnerability", "vuln") .createAlias("surfaceLocation", "surface").setFirstResult((page - 1) * Finding.NUMBER_ITEM_PER_PAGE) .setMaxResults(Finding.NUMBER_ITEM_PER_PAGE).addOrder(Order.desc("severity.numericValue")) .addOrder(Order.asc("vuln.name")).addOrder(Order.asc("surface.path")); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateFindingDao.java
License:Mozilla Public License
@Override @SuppressWarnings("unchecked") public List<Finding> retrieveUnmappedFindingsByPage(int page, Integer appId) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Finding.class) .add(Restrictions.eq("active", true)).add(Restrictions.isNull("vulnerability")); if (appId != null) { criteria.createAlias("scan", "scanAlias").createAlias("scanAlias.application", "appAlias") .add(Restrictions.eq("appAlias.id", appId)); }/*w w w . j a va 2 s . co m*/ return criteria.createAlias("channelSeverity", "severity").createAlias("channelVulnerability", "vuln") .createAlias("surfaceLocation", "surface").setFirstResult((page - 1) * Finding.NUMBER_ITEM_PER_PAGE) .setMaxResults(Finding.NUMBER_ITEM_PER_PAGE).addOrder(Order.desc("severity.numericValue")) .addOrder(Order.asc("vuln.name")).addOrder(Order.asc("surface.path")).list(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateScanDao.java
License:Mozilla Public License
@Nonnull private Criteria addFiltering(Criteria criteria, Set<Integer> teamIds, Set<Integer> appIds) { boolean useAppIds = appIds != null, useTeamIds = teamIds != null; if (teamIds != null && teamIds.isEmpty()) { teamIds = set(0);//from w w w . j a v a 2 s.c om } if (appIds != null && appIds.isEmpty()) { appIds = set(0); } if (!useAppIds && !useTeamIds) { return criteria; } if (useAppIds && useTeamIds) { criteria.createAlias("app.organization", "team").add(eq("team.active", true)) .add(or(Restrictions.in("app.id", appIds), Restrictions.in("team.id", teamIds))); } else if (useAppIds) { criteria.add(Restrictions.in("app.id", appIds)); } else { criteria.createAlias("app.organization", "team").add(Restrictions.in("team.id", teamIds)) .add(eq("team.active", true)); } return criteria; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateVulnerabilityCommentDao.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2 s . c om*/ public List<VulnerabilityComment> retrieveRecent(int number, Set<Integer> authenticatedAppIds, Set<Integer> authenticatedTeamIds) { if ((authenticatedAppIds == null || authenticatedAppIds.isEmpty()) && (authenticatedTeamIds == null || authenticatedTeamIds.isEmpty())) { return list(); } Criteria baseCriteria = getVulnCriteria(number).createAlias("vulnerability.application", "app") .createAlias("vulnerability", "vuln").add(Restrictions.eq("app.active", true)) .add(Restrictions.eq("vuln.active", true)); boolean useAppIds = authenticatedAppIds != null && !authenticatedAppIds.isEmpty(), useTeamIds = authenticatedTeamIds != null && !authenticatedTeamIds.isEmpty(); if (useAppIds && useTeamIds) { baseCriteria.createAlias("app.organization", "team") .add(Restrictions.or(Restrictions.in("app.id", authenticatedAppIds), Restrictions.in("team.id", authenticatedTeamIds))); } else if (useAppIds) { baseCriteria.add(Restrictions.in("app.id", authenticatedAppIds)); } else if (useTeamIds) { baseCriteria.createAlias("app.organization", "team") .add(Restrictions.in("team.id", authenticatedTeamIds)); } return baseCriteria.list(); }
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 {//w ww .j av a 2 s . c om 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.HibernateVulnerabilityFilterDao.java
License:Mozilla Public License
@Override public VulnerabilityFilter find(GenericVulnerability sourceGenericVulnerability, int orgId, int appId) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(VulnerabilityFilter.class) .createAlias("sourceGenericVulnerability", "genericAlias") .add(eq("genericAlias.id", sourceGenericVulnerability.getId())); if (orgId != -1) { criteria.createAlias("organization", "organizationAlias").add(eq("organizationAlias.id", orgId)); } else if (appId != -1) { criteria.createAlias("application", "applicationAlias").add(eq("applicationAlias.id", appId)); } else {/*www. j a v a 2 s. c o m*/ criteria.add(eq("global", true)); } List list = criteria.list(); if (list.size() > 0) { return (VulnerabilityFilter) list.get(0); } else { return null; } }