List of usage examples for org.hibernate.criterion Projections property
public static PropertyProjection property(String propertyName)
From source file:fr.insalyon.creatis.vip.application.server.dao.hibernate.SimulationStatsData.java
License:Open Source License
@Override public List<String> getApplications(List<String> workflowsId) throws WorkflowsDBDAOException { List<String> result = new ArrayList<String>(); try {//from w w w . j a va 2 s. c om Session session = sessionFactory.openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(Workflow.class); criteria.add(Restrictions.in("id", workflowsId)); ProjectionList p = Projections.projectionList(); p.add(Projections.groupProperty("application")); p.add(Projections.property("application")); p.add(Projections.alias(Projections.count("status"), "nbWfls")); criteria.setProjection(p); criteria.setProjection(p); criteria.addOrder(Order.desc("nbWfls")); List l = criteria.list(); session.getTransaction().commit(); session.close(); Iterator it = l.iterator(); while (it.hasNext()) { Object ob[] = (Object[]) it.next(); if (ob[0] != null && ob[1] != null) { result.add(String.valueOf(ob[0]) + "##" + String.valueOf(ob[2])); } } return result; } catch (HibernateException ex) { throw new WorkflowsDBDAOException(ex); } //System.out.println("getApplications, first result is " + result.get(0).toString()); }
From source file:fr.insalyon.creatis.vip.application.server.dao.hibernate.SimulationStatsData.java
License:Open Source License
@Override public List<String> getClasses(List<String> workflowsId) throws WorkflowsDBDAOException { List<String> result = new ArrayList<String>(); try {/* w w w .j a v a2 s . com*/ Session session = sessionFactory.openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(Workflow.class); criteria.add(Restrictions.in("id", workflowsId)); criteria.setProjection(Projections.distinct(Projections.property("applicationClass"))); result = (List<String>) criteria.list(); session.getTransaction().commit(); session.close(); return result; } catch (HibernateException ex) { throw new WorkflowsDBDAOException(ex); } }
From source file:fr.mcc.ginco.dao.hibernate.AssociativeRelationshipDAO.java
License:CeCILL license
@Override public List<String> getAssociatedConcepts(ThesaurusConcept concept) { DetachedCriteria d1 = DetachedCriteria.forClass(AssociativeRelationship.class, "ar1"); d1.setProjection(Projections.projectionList().add(Projections.property("ar1.identifier.concept2"))); d1.add(Restrictions.eq("identifier.concept1", concept.getIdentifier())); DetachedCriteria d2 = DetachedCriteria.forClass(AssociativeRelationship.class, "ar2"); d2.setProjection(Projections.projectionList().add(Projections.property("ar2.identifier.concept1"))); d2.add(Restrictions.eq("identifier.concept2", concept.getIdentifier())); Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc") .add(Restrictions.or(Subqueries.propertyIn("tc.identifier", d1), Subqueries.propertyIn("tc.identifier", d2))) .setProjection(Projections.property("tc.identifier")); return criteria.list(); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusArrayConceptDAO.java
License:CeCILL license
@Override public List<String> getAssociatedConcepts(String arrayId) { Criteria criteria = getCurrentSession().createCriteria(ThesaurusArrayConcept.class, "tac") .add(Restrictions.eq("tac.identifier.thesaurusArrayId", arrayId)) .setProjection(Projections.property("tac.identifier.conceptId")); return criteria.list(); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java
License:CeCILL license
@Override public Long countConceptsAlignedToIntThes(String idThesaurus) throws BusinessException { DetachedCriteria alignmentCriteria = DetachedCriteria.forClass(Alignment.class, "al") .add(Restrictions.isNotNull("al.internalTargetThesaurus")).setProjection( Projections.projectionList().add(Projections.property("al.sourceConcept.identifier"))); DetachedCriteria conceptCriteria = DetachedCriteria.forClass(ThesaurusConcept.class, "stc") .add(Restrictions.eq("stc.thesaurus.identifier", idThesaurus)) .setProjection(Projections.projectionList().add(Projections.property("stc.identifier"))); Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc") .add(Restrictions.and(Subqueries.propertyIn("tc.identifier", alignmentCriteria), Subqueries.propertyIn("tc.identifier", conceptCriteria))) .setProjection(Projections.rowCount()); return (Long) criteria.list().get(0); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java
License:CeCILL license
@Override public Long countConceptsAlignedToExtThes(String idThesaurus) throws BusinessException { DetachedCriteria alignmentCriteria = DetachedCriteria.forClass(Alignment.class, "al") .add(Restrictions.isNotNull("al.externalTargetThesaurus")).setProjection( Projections.projectionList().add(Projections.property("al.sourceConcept.identifier"))); DetachedCriteria conceptCriteria = DetachedCriteria.forClass(ThesaurusConcept.class, "stc") .add(Restrictions.eq("stc.thesaurus.identifier", idThesaurus)) .setProjection(Projections.projectionList().add(Projections.property("stc.identifier"))); Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc") .add(Restrictions.and(Subqueries.propertyIn("tc.identifier", alignmentCriteria), Subqueries.propertyIn("tc.identifier", conceptCriteria))) .setProjection(Projections.rowCount()); return (Long) criteria.list().get(0); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java
License:CeCILL license
@Override public Long countConceptsAlignedToMyThes(String idThesaurus) throws BusinessException { DetachedCriteria alignmentCriteria = DetachedCriteria.forClass(Alignment.class, "al") .add(Restrictions.eq("al.internalTargetThesaurus.identifier", idThesaurus)).setProjection( Projections.projectionList().add(Projections.property("al.sourceConcept.identifier"))); Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc") .add(Subqueries.propertyIn("tc.identifier", alignmentCriteria)) .setProjection(Projections.rowCount()); return (Long) criteria.list().get(0); }
From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java
@Override public RoadOperationSummaryBO operationSummaryReport(OperationSummaryReportCriteriaBO reportCriteria, String userName, String userRegion, ReportDisplayInformationDAOImpl reportDisplayInformation) { Criteria criteriaRoadOp = this.hibernateTemplate.getSessionFactory().getCurrentSession() .createCriteria(RoadOperationDO.class, "ro"); criteriaRoadOp.createAlias("ro.category", "cat"); Criterion subCriteron = null;/*from w w w .j av a2 s .com*/ Criterion mainCriteron = null; if (reportCriteria.getOperationStartDate() != null && reportCriteria.getOperationEndDate() != null) { mainCriteron = Restrictions.or( Restrictions.between("ro.scheduledStartDtime", DateUtils.searchDateFormater(reportCriteria.getOperationStartDate(), DateUtils.SEARCHDATETYPE.START), DateUtils.searchDateFormater(reportCriteria.getOperationEndDate(), DateUtils.SEARCHDATETYPE.END)), Restrictions.between("ro.scheduledEndDtime", DateUtils.searchDateFormater(reportCriteria.getOperationStartDate(), DateUtils.SEARCHDATETYPE.START), DateUtils.searchDateFormater(reportCriteria.getOperationEndDate(), DateUtils.SEARCHDATETYPE.END))); } if (reportCriteria.getTAOfficeRegions() != null && reportCriteria.getTAOfficeRegions().size() > 0) { subCriteron = Restrictions.in("ro.officeLocCode", reportCriteria.getTAOfficeRegions()); } if (reportCriteria.getTeamLeadStaffIds() != null && reportCriteria.getTeamLeadStaffIds().size() > 0) { /* Get List of all road operations with staff as team lead. */ Criteria teamLeadsByStaffIdCrit = this.getSession().createCriteria(TeamDO.class, "team"); teamLeadsByStaffIdCrit .add(Restrictions.in("team.teamLead.staffId", reportCriteria.getTeamLeadStaffIds())); teamLeadsByStaffIdCrit.setProjection(Projections.property("team.roadOperation.roadOperationId")); List<Integer> teamLeadsByStaffId = teamLeadsByStaffIdCrit.list(); if (teamLeadsByStaffId != null && teamLeadsByStaffId.size() > 0) { if (subCriteron == null) { subCriteron = Restrictions.in("ro.roadOperationId", teamLeadsByStaffId); } else { subCriteron = Restrictions.and(subCriteron, Restrictions.in("ro.roadOperationId", teamLeadsByStaffId)); } } } if (reportCriteria.getTeamLeadTRNs() != null && reportCriteria.getTeamLeadTRNs().size() > 0) { /* Get List of all road operations with staff as team lead. */ Criteria teamLeadsByTRNCrit = this.getSession().createCriteria(TeamDO.class, "team"); teamLeadsByTRNCrit.createAlias("team.teamLead", "teamLead"); teamLeadsByTRNCrit.createAlias("teamLead.person", "person"); teamLeadsByTRNCrit.add(Restrictions.in("person.trnNbr", reportCriteria.getTeamLeadTRNs())); teamLeadsByTRNCrit.setProjection(Projections.property("team.roadOperation.roadOperationId")); List<Integer> teamLeadsByTRN = teamLeadsByTRNCrit.list(); if (teamLeadsByTRN != null && teamLeadsByTRN.size() > 0) { if (subCriteron == null) { subCriteron = Restrictions.in("ro.roadOperationId", teamLeadsByTRNCrit.list()); } else { subCriteron = Restrictions.and(subCriteron, Restrictions.in("ro.roadOperationId", teamLeadsByTRNCrit.list())); } } } if (reportCriteria.getOperationCategory() != null && !reportCriteria.getOperationCategory().isEmpty()) { if (subCriteron == null) { subCriteron = Restrictions .eq("ro.category.categoryId", reportCriteria.getOperationCategory().trim()).ignoreCase(); } else { subCriteron = Restrictions.and(subCriteron, Restrictions .eq("ro.category.categoryId", reportCriteria.getOperationCategory().trim()).ignoreCase()); } } if (StringUtil.isSet(reportCriteria.getRoadOperationName())) { if (subCriteron == null) { subCriteron = Restrictions .like("ro.operationName", reportCriteria.getRoadOperationName().trim(), MatchMode.ANYWHERE) .ignoreCase(); } else { subCriteron = Restrictions.and(subCriteron, Restrictions .like("ro.operationName", reportCriteria.getRoadOperationName().trim(), MatchMode.ANYWHERE) .ignoreCase()); } } if (reportCriteria.getRoadOperationId() != null && reportCriteria.getRoadOperationId() > 0) { if (subCriteron == null) { subCriteron = Restrictions.eq("ro.roadOperationId", reportCriteria.getRoadOperationId()); } else { subCriteron = Restrictions.and(subCriteron, Restrictions.eq("ro.roadOperationId", reportCriteria.getRoadOperationId())); } } if (reportCriteria.getRoadOperationIds() != null && !reportCriteria.getRoadOperationIds().isEmpty()) { if (subCriteron == null) { subCriteron = Restrictions.in("ro.roadOperationId", reportCriteria.getRoadOperationIds()); } else { subCriteron = Restrictions.and(subCriteron, Restrictions.in("ro.roadOperationId", reportCriteria.getRoadOperationIds())); } } if (subCriteron == null && mainCriteron != null) criteriaRoadOp.add(mainCriteron); else if (mainCriteron == null && subCriteron != null) criteriaRoadOp.add(subCriteron); else if (mainCriteron != null && subCriteron != null) criteriaRoadOp.add(Restrictions.and(mainCriteron, subCriteron)); else return null; /* Get report criteria names and descriptions */ reportCriteria.setTAOfficeDescription(this.getTAOfficeRegionDescription(userRegion)); if (reportCriteria.getTeamLeadStaffIds() != null && reportCriteria.getTeamLeadStaffIds().size() > 0) reportCriteria.setTAStaffFullName(this.getTAStaffNames(reportCriteria.getTeamLeadStaffIds())); else if (reportCriteria.getTeamLeadTRNs() != null && reportCriteria.getTeamLeadTRNs().size() > 0) reportCriteria.setTAStaffFullName(this.getPersonNamesWithTRN(reportCriteria.getTeamLeadTRNs())); reportCriteria.setOperationCategoryDescription( this.getOperationCategoryDesc(reportCriteria.getOperationCategory())); criteriaRoadOp.addOrder(Order.asc("ro.officeLocCode")); criteriaRoadOp.addOrder(Order.asc("cat.description")); criteriaRoadOp.addOrder(Order.asc("ro.actualStartDtime")); criteriaRoadOp.addOrder(Order.asc("ro.actualEndDtime")); criteriaRoadOp.addOrder(Order.asc("ro.operationName")); List<RoadOperationSummaryResultsBO> results = new ArrayList<RoadOperationSummaryResultsBO>(); String stringStartDate = ""; String stringEndDate = ""; try { stringStartDate = DateUtils.getFormattedUtilDate(reportCriteria.getOperationStartDate()); stringEndDate = DateUtils.getFormattedUtilDate(reportCriteria.getOperationEndDate()); } catch (Exception exe) { } for (RoadOperationDO roadOp : (List<RoadOperationDO>) criteriaRoadOp.list()) { // Get counts that are needed to fill roadOpSummaryReportList Integer absentMembersCount = this.absentPersonCount(roadOp.getRoadOperationId()); Integer teamMemberCount = this.teamMemberPersonCount(roadOp.getRoadOperationId()); Integer summonsCount = this.summonsCount(roadOp.getRoadOperationId()); Integer warningNoProsecutionCount = this.warningNoProsecutionCount(roadOp.getRoadOperationId()); Integer warningNoticeCount = this.warningNoticeCount(roadOp.getRoadOperationId()); Integer vehicleSeizedCount = this.roadCheckOutcomeCount(roadOp.getRoadOperationId(), Constants.OutcomeType.VEHICLE_SEIZURE); Integer complianceCount = this.complianceCount(roadOp.getRoadOperationId()); Integer motorVehicleCheckCount = this.roadCheckTypeCount(roadOp.getRoadOperationId(), Constants.RoadCheckType.MOTOR_VEHICLE); Integer dlCheckCount = this.roadCheckTypeCount(roadOp.getRoadOperationId(), Constants.RoadCheckType.DRIVERS_LICENCE); Integer badgeCheckCount = this.roadCheckTypeCount(roadOp.getRoadOperationId(), Constants.RoadCheckType.BADGE); Integer citationCheckCount = this.roadCheckTypeCount(roadOp.getRoadOperationId(), Constants.RoadCheckType.CITATION); Integer roadLicenceCheckCount = this.roadCheckTypeCount(roadOp.getRoadOperationId(), Constants.RoadCheckType.ROAD_LICENCE); Integer otherCheckCount = this.roadCheckTypeCount(roadOp.getRoadOperationId(), Constants.RoadCheckType.OTHER); Integer countJPs = this.getCountOfPersonType(roadOp.getRoadOperationId(), Constants.PersonType.JP); Integer countPoliceOfficers = this.getCountOfPersonType(roadOp.getRoadOperationId(), Constants.PersonType.POLICE_OFFCER); Integer countTAInspectors = this.getCountOfPersonType(roadOp.getRoadOperationId(), Constants.PersonType.TA_STAFF); Integer countITAExaminers = this.getCountOfPersonType(roadOp.getRoadOperationId(), Constants.PersonType.ITA_EXAMINER); /***** * UR-057 Got absent count for each person type */ Integer absentITACount = absentPersonTypeCount(roadOp.getRoadOperationId(), Constants.PersonType.ITA_EXAMINER); Integer absentTACount = absentPersonTypeCount(roadOp.getRoadOperationId(), Constants.PersonType.TA_STAFF); Integer absentPoliceCount = absentPersonTypeCount(roadOp.getRoadOperationId(), Constants.PersonType.POLICE_OFFCER); Integer absentJPCount = absentPersonTypeCount(roadOp.getRoadOperationId(), Constants.PersonType.JP); /* __________________________________________________________________________ */ /* * Get Duration of an road operation using actual start and end * time. */ long operationDuration = 0; if (roadOp.getActualStartDtime() != null && roadOp.getActualEndDtime() != null) operationDuration = DateUtils.getDateDiff(roadOp.getActualStartDtime(), roadOp.getActualEndDtime(), TimeUnit.MINUTES); /* ___________________________________________________________________ */ RoadOperationSummaryResultsBO result = new RoadOperationSummaryResultsBO( roadOp.getAuditEntry().getCreateDTime()/* operationCreateDate */, roadOp.getScheduledEndDtime()/* scheduledEndDateTime */, roadOp.getScheduledStartDtime()/* scheduledStartDateTime */, roadOp.getActualStartDtime()/* actualStartDateTime */, roadOp.getActualEndDtime()/* actualEndDateTime */, roadOp.getStatus().getDescription()/* operationStatus */, roadOp.getCategory().getDescription()/* operationCategory */, roadOp.getOperationName()/* operationName */, summonsCount/* countSummonsIssued */, warningNoticeCount/* countWaningNoticesIssued */, vehicleSeizedCount/* countVehiclesSeized */, complianceCount/* countCompliancyActivitiesCommited */, motorVehicleCheckCount/* countMotorVehiclesChecked */, dlCheckCount/* countDrivesLicenceChecked */, badgeCheckCount/* countBadgesChecked */, citationCheckCount/* countCitationChecks */, roadLicenceCheckCount/* countRoadLicencesChecked */, otherCheckCount/* countOtherChecks */, (int) operationDuration/* durationOfOperationInMinutes */, absentMembersCount/* countAbsentMembers */, roadOp.getRoadOperationId()/* operationId */, this.roadCheckOutcomeCount(roadOp.getRoadOperationId(), Constants.OutcomeType.REMOVE_PLATES)/* countPlatesRemoved */, this.roadCheckOutcomeCount(roadOp.getRoadOperationId(), Constants.OutcomeType.WARNED_FOR_PROSECUTION)/* warningsForProcecution */, this.roadCheckOutcomeCount(roadOp.getRoadOperationId(), Constants.OutcomeType.ALL_IN_ORDER)/* * Integer * allInOrders */, teamMemberCount /* count team members */, this.getRoadOpTeamSummaryResults(roadOp.getRoadOperationId()) /* team Summaries */, roadOp.getOfficeLocCode()/*TAOfficeRegion*/, this.getTAOfficeRegionDescription(roadOp.getOfficeLocCode())/*TAOfficeRegion*/); result.setCountWarningNoProsecutions(warningNoProsecutionCount); result.setCountITAExaminers(countITAExaminers); result.setCountPoliceOfficers(countPoliceOfficers); result.setCountJPs(countJPs); result.setCountTAInspectors(countTAInspectors); /***** * UR-057 - Set absentee values for each assigned person group */ result.setCountAbsentITAExaminers(absentITACount); result.setCountAbsentJPs(absentJPCount); result.setCountAbsentPoliceOfficers(absentPoliceCount); result.setCountAbsentTAInspectors(absentTACount); results.add(result); } return new RoadOperationSummaryBO(userName, userRegion, reportDisplayInformation.applicationName, reportDisplayInformation.roadOperationSummaryTitle + stringStartDate + " TO " + stringEndDate, reportCriteria.getOperationStartDate(), reportCriteria.getOperationEndDate(), reportCriteria.getSearchCriteriaString(), this.getTAOfficeRegionDescription(userRegion), results); }
From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java
/** * This function is a convenience method which returns all the team ids for * an road operation/*from ww w . ja v a 2 s.c om*/ * * @param roadOpId * @return */ @SuppressWarnings("unchecked") private List<Integer> getTeamIdsForRoadOp(Integer roadOpId) { Criteria criteria = this.hibernateTemplate.getSessionFactory().getCurrentSession() .createCriteria(TeamDO.class, "team"); criteria.add(Restrictions.eq("team.roadOperation.roadOperationId", roadOpId)); criteria.setProjection(Projections.property("team.teamId")); return criteria.list(); }
From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java
private List<Integer> getStaffPersonIdsForTeam(Integer teamId) { if (teamId != null && teamId > 0) { Criteria criteriaAssignedPersons = this.hibernateTemplate.getSessionFactory().getCurrentSession() .createCriteria(AssignedPersonDO.class, "a"); criteriaAssignedPersons.add(Restrictions.eq("a.assignedPersonKey.team.teamId", teamId)); criteriaAssignedPersons.add(/*from w w w. j av a 2s. com*/ Restrictions.eq("a.assignedPersonKey.personType.personTypeId", Constants.PersonType.TA_STAFF)); criteriaAssignedPersons.setProjection(Projections.property("a.assignedPersonKey.person.personId")); return criteriaAssignedPersons.list(); } else return null; }