Example usage for org.hibernate.criterion Projections property

List of usage examples for org.hibernate.criterion Projections property

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections property.

Prototype

public static PropertyProjection property(String propertyName) 

Source Link

Document

A property value projection

Usage

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

/**
 * This function is a convince function to get staff Ids for team. It is
 * dependent on <b>private List<Integer> getStaffPersonIdsForTeam(Integer
 * teamId)</b>/*  w w  w. j a  v a2  s .  c  o m*/
 * 
 * @param teamId
 * @return
 */
@SuppressWarnings("unchecked")
private List<String> getStaffIdForTeam(Integer teamId) {
    if (teamId != null && teamId > 0) {
        List<Integer> teamPersonIds = this.getStaffPersonIdsForTeam(teamId);

        if (teamPersonIds != null && teamPersonIds.size() > 0) {

            Criteria criteria = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                    .createCriteria(TAStaffDO.class, "staff");

            criteria.add(Restrictions.in("staff.person.personId", teamPersonIds));

            criteria.setProjection(Projections.property("staff.staffId"));

            return criteria.list();
        } else
            return null;
    } else
        return null;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

/**
 * This function returns a list of team lead ids based on the road operation
 * id./*from  w  w  w. j a  v a  2 s  .co  m*/
 * 
 * @param roadOp
 * @return
 */
@SuppressWarnings({ "unused", "unchecked" })
private List<String> getTeamLeadIdsForRoadOp(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.teamLead.staffId"));

    return criteria.list();
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

@SuppressWarnings("unchecked")
@Override/*from   w w  w  .  j av  a 2  s  . com*/
public RoadOperationsStatisticsReportBO performanceSaisticsReport(
        PerformanceStatisticsReportCriteriaBO reportCriteria, String userName, String userRegion,
        ReportDisplayInformationDAOImpl reportDisplayInformation) {
    /* Specify search criteria for report */
    Criteria criteria = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(RoadOperationDO.class, "roadOp");

    /* List of all aliases used */
    criteria.createAlias("roadOp.category", "category");

    /* _______________________ */

    /* Apply filters to search results */
    Criterion mainCriteron = Restrictions.or(
            Restrictions.between("roadOp.scheduledStartDtime",
                    DateUtils.searchDateFormater(reportCriteria.getStartDate(), DateUtils.SEARCHDATETYPE.START),
                    DateUtils.searchDateFormater(reportCriteria.getEndDate(), DateUtils.SEARCHDATETYPE.END)),
            Restrictions.between("roadOp.scheduledEndDtime",
                    DateUtils.searchDateFormater(reportCriteria.getStartDate(), DateUtils.SEARCHDATETYPE.START),
                    DateUtils.searchDateFormater(reportCriteria.getEndDate(), DateUtils.SEARCHDATETYPE.END)));

    if (StringUtil.isSet(reportCriteria.getTAOfficeRegion())) {
        mainCriteron = Restrictions.and(mainCriteron,
                Restrictions.eq("roadOp.officeLocCode", reportCriteria.getTAOfficeRegion().trim()));
    }

    if (StringUtil.isSet(reportCriteria.getOperationCategory())) {
        mainCriteron = Restrictions.and(mainCriteron,
                Restrictions.eq("category.categoryId", reportCriteria.getOperationCategory().trim()));
    }

    if (reportCriteria.getTeamLeadId() != null && !reportCriteria.getTeamLeadId().isEmpty()) {
        List<Integer> roadOpIds = this.getListOfRoadOpIdsBasedOnTeamLead(reportCriteria.getTeamLeadId());

        if (roadOpIds != null)
            mainCriteron = Restrictions.and(mainCriteron, Restrictions.in("roadOp.roadOperationId", roadOpIds));
    }

    if (StringUtil.isSet(reportCriteria.getTeamLeadTRN())) {
        List<Integer> roadOpIds = this.getListOfRoadOpIdsBasedOnTeamLeadTRN(reportCriteria.getTeamLeadTRN());

        if (roadOpIds != null)
            mainCriteron = Restrictions.and(mainCriteron, Restrictions.in("roadOp.roadOperationId", roadOpIds));
    }

    if (StringUtil.isSet(reportCriteria.getRoadOperationName())) {
        mainCriteron = Restrictions.and(mainCriteron,
                Restrictions
                        .like("roadOp.operationName", reportCriteria.getRoadOperationName(), MatchMode.ANYWHERE)
                        .ignoreCase());
    }

    if (reportCriteria.getRoadOperationId() != null && reportCriteria.getRoadOperationId() > 0) {
        mainCriteron = Restrictions.and(mainCriteron,
                Restrictions.eq("roadOp.roadOperationId", reportCriteria.getRoadOperationId()));
    }

    if (StringUtil.isSet(reportCriteria.getTAStaffId()) || StringUtil.isSet(reportCriteria.getTAStaffTRN())) {
        Criteria criteriaTA = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                .createCriteria(TAStaffDO.class, "ta");

        criteriaTA.createAlias("ta.person", "taPerson");

        if (StringUtil.isSet(reportCriteria.getTAStaffId()))
            criteriaTA.add(Restrictions.eq("ta.staffId", reportCriteria.getTAStaffId().trim()));

        if (StringUtil.isSet(reportCriteria.getTAStaffTRN()))
            criteriaTA.add(Restrictions.eq("taPerson.trnNbr", reportCriteria.getTAStaffTRN().trim()));

        TAStaffDO taStaff = null;

        List<TAStaffDO> staffList = criteriaTA.list();

        if (!staffList.isEmpty())
            taStaff = staffList.get(0);

        if (taStaff != null) {

            /* Get a list of all assigned persons for a road operation. */
            Criteria criteriaAssignedPersons = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                    .createCriteria(AssignedPersonDO.class, "assignedP");

            criteriaAssignedPersons.add(Restrictions.sqlRestriction("{alias}.person_id = ?",
                    taStaff.getPerson().getPersonId(), Hibernate.INTEGER));

            List<Integer> roadOpsWithTAStaff = new ArrayList<Integer>();

            for (AssignedPersonDO assignee : (List<AssignedPersonDO>) criteriaAssignedPersons.list()) {
                roadOpsWithTAStaff
                        .add(assignee.getAssignedPersonKey().getTeam().getRoadOperation().getRoadOperationId());
            }

            mainCriteron = Restrictions.and(mainCriteron,
                    Restrictions.in("roadOp.roadOperationId", roadOpsWithTAStaff));
        } else {
            return null;
        }
    }

    /* ______________________________ */

    /*** Check which road operations employ the strategies selected ****/
    if (reportCriteria.getStrategyIds() != null && !reportCriteria.getStrategyIds().isEmpty()) {
        //
        Criteria criteriaStrategies = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                .createCriteria(OperationStrategyDO.class, "opStrat");

        // criteriaStrategies.createAlias("opStrat.operationStrategyKey.roadOperation",
        // "roadOp");
        // criteriaStrategies.createAlias("opStrat.operationStrategyKey.strategy",
        // "strat");

        criteriaStrategies.setProjection(Projections
                .distinct(Projections.property("opStrat.operationStrategyKey.roadOperation.roadOperationId")));

        criteriaStrategies.add(Restrictions.in("opStrat.operationStrategyKey.strategy.strategyId",
                reportCriteria.getStrategyIds()));

        List<Integer> roadOpWithStratsList = criteriaStrategies.list();

        if (roadOpWithStratsList != null && !roadOpWithStratsList.isEmpty()) {
            mainCriteron = Restrictions.and(mainCriteron,
                    Restrictions.in("roadOp.roadOperationId", roadOpWithStratsList));
        } else {
            return null;
        }
    }
    /* ______________________________________________________________ */

    /*
     * Create Return objects which are going to be filled during report
     * processing.
     */

    String stringStartDate = "";
    String stringEndDate = "";
    try {
        stringStartDate = DateUtils.getFormattedUtilDate(reportCriteria.getStartDate());
        stringEndDate = DateUtils.getFormattedUtilDate(reportCriteria.getEndDate());
    } catch (Exception exe) {

    }

    /* Get report criteria names and descriptions */
    reportCriteria
            .setTAOfficeDescription(this.getTAOfficeRegionDescription(reportCriteria.getTAOfficeRegion()));
    reportCriteria.setOperationCategoryDescription(
            this.getOperationCategoryDesc(reportCriteria.getOperationCategory()));

    if (StringUtil.isSet(reportCriteria.getTAStaffId()))
        reportCriteria.setTAStaffName(this.getTAStaffName(reportCriteria.getTAStaffId()));
    else if (StringUtil.isSet(reportCriteria.getTAStaffTRN()))
        reportCriteria.setTAStaffName(this.getPersonName(reportCriteria.getTAStaffTRN()));

    if (StringUtil.isSet(reportCriteria.getTeamLeadId()))
        reportCriteria.setTeamLeadName(this.getTAStaffName(reportCriteria.getTeamLeadId()));
    else if (StringUtil.isSet(reportCriteria.getTeamLeadTRN()))
        reportCriteria.setTeamLeadName(this.getPersonName(reportCriteria.getTeamLeadTRN()));

    if (reportCriteria.getStrategyIds() != null && !reportCriteria.getStrategyIds().isEmpty()) {
        StringBuilder strategyDescriptions = new StringBuilder("");

        for (Integer strategyId : reportCriteria.getStrategyIds()) {
            StrategyDO strategyDO = this.hibernateTemplate.get(StrategyDO.class, strategyId);

            if (strategyDO != null) {
                if (!strategyDescriptions.toString().isEmpty())
                    strategyDescriptions.append(", ");

                strategyDescriptions.append(strategyDO.getDescription());
            }
        }

        reportCriteria.setStrategyDescriptions(strategyDescriptions.toString());
    }

    RoadOperationsStatisticsReportBO roadOpReportStatsOuput = new RoadOperationsStatisticsReportBO(userName,
            userRegion, reportDisplayInformation.applicationName,
            reportDisplayInformation.getPerformanceStatisticsReportTitle() + stringStartDate + " TO "
                    + stringEndDate,
            reportCriteria.getStartDate(), reportCriteria.getEndDate(),
            reportCriteria.getSearchCriteriaString(), this.getTAOfficeRegionDescription(userRegion));

    List<RegionStatisticsBO> regionStats = new ArrayList<RegionStatisticsBO>();

    RegionStatisticsBO currentRegionStats = null;
    OperationSummaryReportCriteriaBO reportCriteriaForRoadOps = null;

    roadOpReportStatsOuput.setRegionStatistics(regionStats);

    /* ____________________________________ */

    /* Loop through list of road operations and get statistics for persons. */
    criteria.add(mainCriteron);
    criteria.addOrder(Order.asc("roadOp.officeLocCode"));
    criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

    List criteriaList = criteria.list();

    Iterator iterator = criteriaList.iterator();

    while (iterator.hasNext()) {
        Map map = (Map) iterator.next();

        final RoadOperationDO roadOpDO = (RoadOperationDO) map.get("roadOp");
        // TAStaffDO teamLead = (TAStaffDO)map.get("teamLead");

        if (currentRegionStats == null) {

            /* Create List of RoadOperationSummaryBO */
            reportCriteriaForRoadOps = new OperationSummaryReportCriteriaBO(reportCriteria.getStartDate(),
                    reportCriteria.getEndDate(), new ArrayList<String>() {
                        {
                            add(roadOpDO.getOfficeLocCode());

                        }
                    }, this.getTeamLeadIdsForRoadOp(roadOpDO.getRoadOperationId()),
                    roadOpDO.getCategory().getCategoryId(), roadOpDO.getRoadOperationId());

            currentRegionStats = new RegionStatisticsBO(roadOpDO.getOfficeLocCode(),
                    this.getTAOfficeRegionDescription(roadOpDO.getOfficeLocCode()));

            currentRegionStats.setRoadOpSummary(this.operationSummaryReport(reportCriteriaForRoadOps, userName,
                    userRegion, reportDisplayInformation).getResults());

            List<RoadOperationSummaryResultsBO> roadOpSummary = this.operationSummaryReport(
                    reportCriteriaForRoadOps, userName, userRegion, reportDisplayInformation).getResults();

            currentRegionStats.setRoadOpSummary(roadOpSummary);

            currentRegionStats.setRoadOperationStatistics(new ArrayList<RoadOperationStatisticsBO>());

            roadOpReportStatsOuput.getRegionStatistics().add(currentRegionStats);

        } else if (!currentRegionStats.getOfficeLocCode().equalsIgnoreCase(roadOpDO.getOfficeLocCode())) {

            reportCriteriaForRoadOps = new OperationSummaryReportCriteriaBO(reportCriteria.getStartDate(),
                    reportCriteria.getEndDate(), new ArrayList<String>() {
                        {
                            add(roadOpDO.getOfficeLocCode());

                        }
                    }, null, roadOpDO.getCategory().getCategoryId(), null);

            currentRegionStats = new RegionStatisticsBO(roadOpDO.getOfficeLocCode(),
                    this.getTAOfficeRegionDescription(roadOpDO.getOfficeLocCode()));
            ;

            currentRegionStats.setRoadOpSummary(this.operationSummaryReport(reportCriteriaForRoadOps, userName,
                    userRegion, reportDisplayInformation).getResults());

            List<RoadOperationSummaryResultsBO> roadOpSummary = this.operationSummaryReport(
                    reportCriteriaForRoadOps, userName, userRegion, reportDisplayInformation).getResults();

            currentRegionStats.setRoadOpSummary(roadOpSummary);

            currentRegionStats.setRoadOperationStatistics(new ArrayList<RoadOperationStatisticsBO>());

            roadOpReportStatsOuput.getRegionStatistics().add(currentRegionStats);
        }

        RoadOperationStatisticsBO roadOpStats = new RoadOperationStatisticsBO(
                getListOfTeamLeadNamesBasedOnRoadOpId(roadOpDO.getRoadOperationId()),
                roadOpDO.getOperationName());

        roadOpStats.setITAExaminerSummary(new ArrayList<ITAExaminerStatisticsBO>());
        roadOpStats.setJPSummary(new ArrayList<JPStatisticsBO>());
        roadOpStats.setPoliceOfficerSummary(new ArrayList<PoliceOfficerStatisticsBO>());
        roadOpStats.setTAOfficerSummary(new ArrayList<TAOfficerStatisticsBO>());
        /* Get a list of all assigned persons for a road operation. */
        Criteria criteriaAssignedPersons = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                .createCriteria(AssignedPersonDO.class, "assignedP");

        // criteriaAssignedPersons.add(Restrictions.sqlRestriction("{alias}.road_operation_id = ?",
        // roadOpDO.getRoadOperationId(), Hibernate.INTEGER));

        List<Integer> teamIds = this.getTeamIdsForRoadOp(roadOpDO.getRoadOperationId());

        if (teamIds != null && teamIds.size() > 0)
            criteriaAssignedPersons.add(Restrictions.in("assignedPersonKey.team.teamId", teamIds));

        if (StringUtil.isSet(reportCriteria.getTAStaffId())) {
            TAStaffDO taStaff = (TAStaffDO) this.hibernateTemplate.getSessionFactory().getCurrentSession()
                    .get(TAStaffDO.class, reportCriteria.getTAStaffId().trim());

            if (taStaff != null) {

                criteriaAssignedPersons.add(Restrictions.sqlRestriction("{alias}.person_id = ?",
                        taStaff.getPerson().getPersonId(), Hibernate.INTEGER));
            } else {
                return null;
            }
        }

        for (AssignedPersonDO assignedPerson : (List<AssignedPersonDO>) criteriaAssignedPersons.list()) {
            /* Looping through a list of persons based on road operation id. */

            PersonDO person = assignedPerson.getAssignedPersonKey().getPerson();
            CDPersonTypeDO personType = assignedPerson.getAssignedPersonKey().getPersonType();

            if (personType.getPersonTypeId().toLowerCase().equalsIgnoreCase(Constants.PersonType.JP)) {
                /* Get Statistics for JP Person */
                Criteria criteriaJP = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                        .createCriteria(JPDO.class);
                criteriaJP.add(Restrictions.eq("person.personId", person.getPersonId()));

                JPDO jp = (JPDO) criteriaJP.uniqueResult();

                JPStatisticsBO jpStatsBO = new JPStatisticsBO(
                        NameUtil.getName(person.getFirstName(), person.getLastName())/* fullName */,
                        jp.getRegNumber()/* regNumber */,
                        this.summonsCount(roadOpDO.getRoadOperationId(), person.getPersonId(),
                                Constants.PersonType.JP)/* countSummonsSigned */,
                        assignedPerson.getAttended()/* attended */);

                roadOpStats.getJPSummary().add(jpStatsBO);

            } else if (personType.getPersonTypeId().equalsIgnoreCase(Constants.PersonType.TA_STAFF)) {
                /* Get Statistics for TA Staff. */
                Criteria criteriaTA = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                        .createCriteria(TAStaffDO.class);
                criteriaTA.add(Restrictions.eq("person.personId", person.getPersonId()));
                //System.out.println("Person ID is " + person.getPersonId());
                TAStaffDO ta = (TAStaffDO) criteriaTA.uniqueResult();

                TAOfficerStatisticsBO taStatsBO = new TAOfficerStatisticsBO(
                        NameUtil.getName(person.getFirstName(), person.getLastName())/* fullName */,
                        ta.getStaffTypeCode()/* staffType */,
                        this.complianceCount(roadOpDO.getRoadOperationId(), person.getPersonId(),
                                personType.getPersonTypeId())/* countCompliancyChecks */,
                        this.roadCheckTypeCount(roadOpDO.getRoadOperationId(),
                                Constants.RoadCheckType.MOTOR_VEHICLE, person.getPersonId(),
                                personType.getPersonTypeId())/* countMVChecks */,
                        this.roadCheckTypeCount(roadOpDO.getRoadOperationId(),
                                Constants.RoadCheckType.DRIVERS_LICENCE, person.getPersonId(),
                                personType.getPersonTypeId())/* countDLChecks */,
                        this.roadCheckTypeCount(roadOpDO.getRoadOperationId(), Constants.RoadCheckType.BADGE,
                                person.getPersonId(), personType.getPersonTypeId())/* countBadgeChecks */,
                        this.roadCheckTypeCount(roadOpDO.getRoadOperationId(), Constants.RoadCheckType.CITATION,
                                person.getPersonId(), personType.getPersonTypeId())/* countCitationChecks */,
                        this.roadCheckTypeCount(roadOpDO.getRoadOperationId(),
                                Constants.RoadCheckType.ROAD_LICENCE, person.getPersonId(),
                                personType.getPersonTypeId())/* countRLChecks */,
                        this.roadCheckTypeCount(roadOpDO.getRoadOperationId(), Constants.RoadCheckType.OTHER,
                                person.getPersonId(), personType.getPersonTypeId())/* countOtherChecks */,
                        this.warningNoticeCount(roadOpDO.getRoadOperationId(), person.getPersonId(),
                                personType.getPersonTypeId())/* countWarningNoticesIssued */,
                        this.summonsCount(roadOpDO.getRoadOperationId(), person.getPersonId(),
                                personType.getPersonTypeId())/* countSummonsIssued */,
                        this.roadCheckOutcomeCount(roadOpDO.getRoadOperationId(),
                                Constants.OutcomeType.VEHICLE_SEIZURE, person.getPersonId(),
                                personType.getPersonTypeId())/* countVehiclesSeized */,
                        assignedPerson.getAttended()/* attended */,
                        this.roadCheckOutcomeCount(roadOpDO.getRoadOperationId(),
                                Constants.OutcomeType.REMOVE_PLATES, person.getPersonId(),
                                personType.getPersonTypeId())/* countPlatesRemoved */,
                        this.roadCheckOutcomeCount(roadOpDO.getRoadOperationId(),
                                Constants.OutcomeType.WARNED_FOR_PROSECUTION, person.getPersonId(),
                                personType.getPersonTypeId())/* warningsForProcecution */,
                        this.roadCheckOutcomeCount(roadOpDO.getRoadOperationId(),
                                Constants.OutcomeType.ALL_IN_ORDER, person.getPersonId(),
                                personType.getPersonTypeId())/* allInOrders */,
                        ta.getStaffId()/* staff id */);

                roadOpStats.getTAOfficerSummary().add(taStatsBO);
            } else if (personType.getPersonTypeId().equalsIgnoreCase(Constants.PersonType.ITA_EXAMINER)) {
                /* Get Statistics for ITA Examiner */
                Criteria criteriaITA = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                        .createCriteria(ITAExaminerDO.class);
                criteriaITA.add(Restrictions.eq("person.personId", person.getPersonId()));

                ITAExaminerDO ita = (ITAExaminerDO) criteriaITA.uniqueResult();

                ITAExaminerStatisticsBO itaStats = new ITAExaminerStatisticsBO(
                        NameUtil.getName(person.getFirstName(), person.getLastName()),
                        assignedPerson.getAttended(), ita.getExaminerId());

                roadOpStats.getITAExaminerSummary().add(itaStats);
            } else if (personType.getPersonTypeId().equalsIgnoreCase(Constants.PersonType.POLICE_OFFCER)) {
                /* Get Statistics for Police Officer */
                Criteria criteriaITA = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                        .createCriteria(PoliceOfficerDO.class);
                criteriaITA.add(Restrictions.eq("person.personId", person.getPersonId()));

                PoliceOfficerDO police = (PoliceOfficerDO) criteriaITA.uniqueResult();

                PoliceOfficerStatisticsBO policeStats = new PoliceOfficerStatisticsBO(
                        NameUtil.getName(person.getFirstName(), person.getLastName()),
                        assignedPerson.getAttended(), police.getPolOfficerCompNo());

                roadOpStats.getPoliceOfficerSummary().add(policeStats);
            }

        }
        /* ____________________________________ */

        currentRegionStats.getRoadOperationStatistics().add(roadOpStats);
    }
    /* ________________________________ */

    roadOpReportStatsOuput.setRegionStatistics(regionStats);
    return roadOpReportStatsOuput;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

/**
 * This is a convenience function which gets a list of road operation ids
 * which the ta staff was involved in./*  ww w .j av  a 2 s.c  o  m*/
 * 
 * @param taStaffId
 * @return
 */
private List<Integer> getListOfRoadOpIdsBasedOnTeamLead(String taStaffId) {
    if (StringUtil.isSet(taStaffId)) {
        Criteria criteria = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                .createCriteria(TeamDO.class, "team");

        criteria.add(Restrictions.eq("team.teamLead.staffId", taStaffId.trim()).ignoreCase());

        criteria.setProjection(Projections.property("team.roadOperation.roadOperationId"));

        return criteria.list();
    } else
        return null;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

private List<Integer> getListOfRoadOpIdsBasedOnTeamLeadTRN(String taStaffTRN) {
    if (StringUtil.isSet(taStaffTRN)) {
        Criteria criteriaTRN = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                .createCriteria(TAStaffDO.class, "staff");

        criteriaTRN.add(Restrictions.eq("staff.person.trnNbr", taStaffTRN.trim()).ignoreCase());

        criteriaTRN.setProjection(Projections.property("staff.staffId"));

        String staffId = (String) criteriaTRN.uniqueResult();

        if (StringUtil.isSet(staffId)) {
            Criteria criteria = this.hibernateTemplate.getSessionFactory().getCurrentSession()
                    .createCriteria(TeamDO.class, "team");

            criteria.add(Restrictions.eq("team.teamLead.staffId", staffId.trim()).ignoreCase());

            criteria.setProjection(Projections.property("team.roadOperation.roadOperationId"));

            return criteria.list();
        } else/*  w ww . j a v a2s. com*/
            return null;
    } else
        return null;
}

From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java

/**
 * This is a helper function which checks the starting trial date of court
 * cases and returns all court case id as a list of integers based on the
 * start and end date ranges.// w  w  w .  j  ava 2 s  . co  m
 * 
 * @param startTrialDate
 * @param endTrialDate
 * @return
 */
@SuppressWarnings("unchecked")
private List<Integer> getCourtCasesIdsForTrialDateRange(Date startTrialDate, Date endTrialDate) {
    List<Integer> courtCaseIds = new ArrayList<Integer>();

    Criteria criteria = this.hibernateTemplate.getSessionFactory().getCurrentSession()
            .createCriteria(CourtAppearanceDO.class, "capp");

    criteria.setProjection(Projections.distinct(Projections.property("courtCase.courtCaseId")));

    criteria.add(Restrictions.between("CourtDTime",
            DateUtils.searchDateFormater(startTrialDate, DateUtils.SEARCHDATETYPE.START),
            DateUtils.searchDateFormater(endTrialDate, DateUtils.SEARCHDATETYPE.END)));

    courtCaseIds = criteria.list();

    return courtCaseIds;
}

From source file:gov.nih.nci.caarray.util.CaArrayAuditLogProcessorTest.java

License:BSD License

@Test
public void testProcessDetailGroupCreate() {
    Transaction tx = this.hibernateHelper.beginTransaction();
    this.hibernateHelper.getCurrentSession().createQuery("delete from " + AuditLogDetail.class.getName())
            .executeUpdate();//  w w  w . ja  v a2 s .c om

    setupUsersAndGroups();

    this.hibernateHelper.getCurrentSession().save(this.u1);
    this.hibernateHelper.getCurrentSession().save(this.u2);
    this.hibernateHelper.getCurrentSession().save(this.g1);
    tx.commit();

    tx = this.hibernateHelper.beginTransaction();
    final Criteria c = this.hibernateHelper.getCurrentSession().createCriteria(AuditLogDetail.class)
            .setProjection(Projections.property("message"));

    final List<String> l = c.list();
    assertEquals(2L, l.size());
    assertTrue(l.contains("Group group1 created"));
    assertTrue(l.contains("User user1 added to group group1"));
    tx.commit();

}

From source file:gov.nih.nci.caarray.util.CaArrayAuditLogProcessorTest.java

License:BSD License

@SuppressWarnings("unchecked")
private List<String> getLogMessages() {
    Criteria c = hibernateHelper.getCurrentSession().createCriteria(AuditLogDetail.class);
    c.setProjection(Projections.property("message"));
    return c.list();

}

From source file:gov.nih.nci.caintegrator.data.CaIntegrator2DaoImpl.java

License:BSD License

/**
 * {@inheritDoc}/*from   ww w  .j a v  a 2s  . c  o  m*/
 */
@Override
@SuppressWarnings(UNCHECKED) // Hibernate operations are untyped
public List<Gene> findGenesByLocation(String chromosome, Integer startPosition, Integer endPosition,
        GenomeBuildVersionEnum genomeBuildVersion) {
    String locStartPosition = "location.startPosition";
    String locEndPosition = "location.endPosition";
    Criteria geneLocationCriteria = getCurrentSession().createCriteria(GeneChromosomalLocation.class);
    // (gene.startPos <= startPosition && gene.endPos >= startPosition)
    //  || (gene.startPos >= lowerInput  && gene.startPos <= higherInput)
    Junction overallOrStatement = Restrictions.disjunction();
    overallOrStatement.add(Restrictions.conjunction().add(Restrictions.le(locStartPosition, startPosition))
            .add(Restrictions.ge(locEndPosition, startPosition)));
    overallOrStatement.add(Restrictions.conjunction().add(Restrictions.ge(locStartPosition, startPosition))
            .add(Restrictions.le(locStartPosition, endPosition)));
    geneLocationCriteria.add(overallOrStatement);
    geneLocationCriteria.add(getChromosomeRestriction(chromosome));
    geneLocationCriteria.createCriteria("geneLocationConfiguration")
            .add(Restrictions.eq("genomeBuildVersion", genomeBuildVersion));
    geneLocationCriteria.setProjection(Projections.property("geneSymbol"));
    List<String> geneSymbols = geneLocationCriteria.list();
    return geneSymbols.isEmpty() ? new ArrayList<Gene>()
            : getCurrentSession().createCriteria(Gene.class)
                    .setProjection(Projections.distinct(Projections.property(SYMBOL_ATTRIBUTE)))
                    .add(Restrictions.in(SYMBOL_ATTRIBUTE, geneSymbols)).addOrder(Order.asc(SYMBOL_ATTRIBUTE))
                    .list();
}

From source file:gov.nih.nci.caintegrator.data.CaIntegrator2DaoImpl.java

License:BSD License

/**
 * {@inheritDoc}/*from  w ww . j  a  v a  2s.  c o m*/
 */
@Override
@SuppressWarnings(UNCHECKED)
public <T> List<T> retrieveUniqueValuesForStudyAnnotation(Study study, AnnotationDefinition definition,
        EntityTypeEnum entityType, Class<T> objectClass) {
    AnnotationTypeEnum annotationType = definition.getDataType();
    if (annotationType == null) {
        throw new IllegalArgumentException("Data Type for the Annotation Definition is unknown.");
    }
    Criteria abstractAnnotationValueCriteria = getCurrentSession()
            .createCriteria(AbstractAnnotationValue.class);
    abstractAnnotationValueCriteria.add(Restrictions.eq(ANNOTATION_DEFINITION_ASSOCIATION, definition));
    addValuesToStudyCriteria(study, entityType, abstractAnnotationValueCriteria);

    String uniqueAttribute = "stringValue";
    switch (annotationType) {
    case STRING:
        uniqueAttribute = "stringValue";
        break;
    case NUMERIC:
        uniqueAttribute = "numericValue";
        break;
    case DATE:
        uniqueAttribute = "dateValue";
        break;
    default:
        throw new IllegalStateException("Unknown Annotation Type Type.");
    }
    abstractAnnotationValueCriteria.setProjection(Projections.distinct(Projections.property(uniqueAttribute)));
    return abstractAnnotationValueCriteria.list();

}