Example usage for org.hibernate.criterion Restrictions gt

List of usage examples for org.hibernate.criterion Restrictions gt

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions gt.

Prototype

public static SimpleExpression gt(String propertyName, Object value) 

Source Link

Document

Apply a "greater than" constraint to the named property

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.intf.BookingsService.java

License:Open Source License

@Override
public CreateBookingResponse createBooking(CreateBooking createBooking) {
    /* --------------------------------------------------------------------
     * -- Read request parameters.                                       --
     * -------------------------------------------------------------------- */
    CreateBookingType request = createBooking.getCreateBooking();
    String debug = "Received " + this.getClass().getSimpleName() + "#createBooking with params: ";

    UserIDType uid = request.getUserID();
    debug += " user ID=" + uid.getUserID() + ", user namespace=" + uid.getUserNamespace() + ", user name="
            + uid.getUserName() + " user QName=" + uid.getUserQName();

    BookingType booking = request.getBooking();
    int pid = booking.getPermissionID().getPermissionID();
    debug += ", permission=" + pid;

    Calendar start = booking.getStartTime();
    Calendar end = booking.getEndTime();
    this.dstHack(start);
    this.dstHack(end);

    debug += ", start=" + start.getTime() + ", end=" + end.getTime();

    debug += ", send notification=" + request.getSendNotification() + ", notification time zone="
            + request.getNotificationTimezone() + '.';
    this.logger.debug(debug);

    /* --------------------------------------------------------------------
     * -- Generate default response parameters.                          --
     * -------------------------------------------------------------------- */
    CreateBookingResponse response = new CreateBookingResponse();
    BookingResponseType status = new BookingResponseType();
    status.setSuccess(false);/*w  w  w  . ja v  a 2 s.co m*/
    response.setCreateBookingResponse(status);

    Session ses = DataAccessActivator.getNewSession();
    try {
        /* ----------------------------------------------------------------
         * -- Load the user.                                             --
         * ---------------------------------------------------------------- */
        User user = this.getUserFromUserID(uid, ses);
        if (user == null) {
            this.logger.info("Unable to create a booking because the user has not been found. Supplied "
                    + "credentials ID=" + uid.getUserID() + ", namespace=" + uid.getUserNamespace() + ", "
                    + "name=" + uid.getUserName() + '.');
            status.setFailureReason("User not found.");
            return response;
        }

        /* ----------------------------------------------------------------
         * -- Load the permission.                                       --
         * ---------------------------------------------------------------- */
        ResourcePermission perm = new ResourcePermissionDao(ses).get(Long.valueOf(pid));
        if (perm == null) {
            this.logger.info("Unable to create a booking because the permission has not been found. Supplied "
                    + "permission ID=" + pid + '.');
            status.setFailureReason("Permission not found.");
            return response;
        }

        if (!this.checkPermission(user, perm)) {
            this.logger.info("Unable to create a booking because the user " + user.getNamespace() + ':'
                    + user.getName() + " does not have permission " + pid + '.');
            status.setFailureReason("Does not have permission.");
            return response;
        }

        /* ----------------------------------------------------------------
         * -- Check permission constraints.                              --
         * ---------------------------------------------------------------- */
        Date startDate = start.getTime();
        Date endDate = end.getTime();

        if (!perm.getUserClass().isBookable()) {
            this.logger.info("Unable to create a booking because the permission " + pid + " is not bookable.");
            status.setFailureReason("Permission not bookable.");
            return response;
        }

        if (startDate.before(perm.getStartTime()) || endDate.after(perm.getExpiryTime())) {
            this.logger
                    .info("Unable to create a booking because the booking time is outside the permission time. "
                            + "Permission start: " + perm.getStartTime() + ", expiry: " + perm.getExpiryTime()
                            + ", booking start: " + startDate + ", booking end: " + endDate + '.');
            status.setFailureReason("Booking time out of permission range.");
            return response;
        }

        /* Time horizon is a moving offset when bookings can be made. */
        Calendar horizon = Calendar.getInstance();
        horizon.add(Calendar.SECOND, perm.getUserClass().getTimeHorizon());
        if (horizon.after(start)) {
            this.logger.info("Unable to create a booking because the booking start time (" + startDate
                    + ") is before the time horizon (" + horizon.getTime() + ").");
            status.setFailureReason("Before time horizon.");
            return response;
        }

        /* Maximum concurrent bookings. */
        int numBookings = (Integer) ses.createCriteria(Bookings.class)
                .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.eq("user", user))
                .add(Restrictions.eq("resourcePermission", perm)).setProjection(Projections.rowCount())
                .uniqueResult();
        if (numBookings >= perm.getMaximumBookings()) {
            this.logger.info("Unable to create a booking because the user " + user.getNamespace() + ':'
                    + user.getName() + " already has the maxiumum numnber of bookings (" + numBookings + ").");
            status.setFailureReason("User has maximum number of bookings.");
            return response;
        }

        /* User bookings at the same time. */
        numBookings = (Integer) ses.createCriteria(Bookings.class).setProjection(Projections.rowCount())
                .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.eq("user", user))
                .add(Restrictions.disjunction()
                        .add(Restrictions.and(Restrictions.gt("startTime", startDate),
                                Restrictions.lt("startTime", endDate)))
                        .add(Restrictions.and(Restrictions.gt("endTime", startDate),
                                Restrictions.le("endTime", endDate)))
                        .add(Restrictions.and(Restrictions.le("startTime", startDate),
                                Restrictions.gt("endTime", endDate))))
                .uniqueResult();
        if (numBookings > 0) {
            this.logger.info("Unable to create a booking because the user " + user.getNamespace() + ':'
                    + user.getName() + " has concurrent bookings.");
            status.setFailureReason("User has concurrent bookings.");
            return response;
        }

        /* ----------------------------------------------------------------
         * -- Create booking.                                            --
         * ---------------------------------------------------------------- */
        BookingCreation bc = this.engine.createBooking(user, perm, new TimePeriod(start, end), ses);
        if (bc.wasCreated()) {
            status.setSuccess(true);
            BookingIDType bid = new BookingIDType();
            bid.setBookingID(bc.getBooking().getId().intValue());
            status.setBookingID(bid);

            new BookingNotification(bc.getBooking()).notifyCreation();
        } else {
            status.setSuccess(false);
            status.setFailureReason("Resource not free.");

            BookingListType bestFits = new BookingListType();
            status.setBestFits(bestFits);
            for (TimePeriod tp : bc.getBestFits()) {
                numBookings = (Integer) ses.createCriteria(Bookings.class).setProjection(Projections.rowCount())
                        .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.eq("user", user))
                        .add(Restrictions.disjunction()
                                .add(Restrictions.and(Restrictions.gt("startTime", tp.getStartTime().getTime()),
                                        Restrictions.lt("startTime", tp.getEndTime().getTime())))
                                .add(Restrictions.and(Restrictions.gt("endTime", tp.getStartTime().getTime()),
                                        Restrictions.le("endTime", tp.getEndTime().getTime())))
                                .add(Restrictions.and(Restrictions.le("startTime", tp.getStartTime().getTime()),
                                        Restrictions.gt("endTime", tp.getEndTime().getTime()))))
                        .uniqueResult();
                if (numBookings > 0) {
                    this.logger.debug("Excluding best fit option for user " + user.qName() + " because it is "
                            + "concurrent with an existing.");
                    continue;
                }
                BookingType fit = new BookingType();
                fit.setPermissionID(booking.getPermissionID());
                fit.setStartTime(tp.getStartTime());
                fit.setEndTime(tp.getEndTime());
                bestFits.addBookings(fit);
            }
        }
    } finally {
        ses.close();
    }

    return response;
}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.pojo.impl.BookingsServiceImpl.java

License:Open Source License

@Override
public BookingOperation createBooking(Calendar start, Calendar end, User user, ResourcePermission perm,
        Session db) {/*from   w  w w .  j av a 2s. co  m*/
    BookingOperation response = new BookingOperation();
    response.setSuccess(false);

    /* ----------------------------------------------------------------
     * -- Check permission constraints.                              --
     * ---------------------------------------------------------------- */
    Date startDate = start.getTime();
    Date endDate = end.getTime();

    if (!perm.getUserClass().isBookable()) {
        this.logger.info(
                "Unable to create a booking because the permission " + perm.getId() + " is not bookable.");
        response.setFailureReason("Permission not bookable.");
        return response;
    }

    if (startDate.before(perm.getStartTime()) || endDate.after(perm.getExpiryTime())) {
        this.logger.info("Unable to create a booking because the booking time is outside the permission time. "
                + "Permission start: " + perm.getStartTime() + ", expiry: " + perm.getExpiryTime()
                + ", booking start: " + startDate + ", booking end: " + endDate + '.');
        response.setFailureReason("Booking time out of permission range.");
        return response;
    }

    /* Time horizon is a moving offset when bookings can be made. */
    Calendar horizon = Calendar.getInstance();
    horizon.add(Calendar.SECOND, perm.getUserClass().getTimeHorizon());
    if (horizon.after(start)) {
        this.logger.info("Unable to create a booking because the booking start time (" + startDate
                + ") is before the time horizon (" + horizon.getTime() + ").");
        response.setFailureReason("Before time horizon.");
        return response;
    }

    /* Maximum concurrent bookings. */
    int numBookings = (Integer) db.createCriteria(Bookings.class).add(Restrictions.eq("active", Boolean.TRUE))
            .add(Restrictions.eq("user", user)).add(Restrictions.eq("resourcePermission", perm))
            .setProjection(Projections.rowCount()).uniqueResult();
    if (numBookings >= perm.getMaximumBookings()) {
        this.logger.info("Unable to create a booking because the user " + user.getNamespace() + ':'
                + user.getName() + " already has the maxiumum numnber of bookings (" + numBookings + ").");
        response.setFailureReason("User has maximum number of bookings.");
        return response;
    }

    /* User bookings at the same time. */
    numBookings = (Integer) db.createCriteria(Bookings.class).setProjection(Projections.rowCount())
            .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.eq("user", user))
            .add(Restrictions.disjunction()
                    .add(Restrictions.and(Restrictions.gt("startTime", startDate),
                            Restrictions.lt("startTime", endDate)))
                    .add(Restrictions.and(Restrictions.gt("endTime", startDate),
                            Restrictions.le("endTime", endDate)))
                    .add(Restrictions.and(Restrictions.le("startTime", startDate),
                            Restrictions.gt("endTime", endDate))))
            .uniqueResult();

    if (numBookings > 0) {
        this.logger.info("Unable to create a booking because the user " + user.getNamespace() + ':'
                + user.getName() + " has concurrent bookings.");
        response.setFailureReason("User has concurrent bookings.");
        return response;
    }

    /* ----------------------------------------------------------------
     * -- Create booking.                                            --
     * ---------------------------------------------------------------- */
    if (ResourcePermission.CONSUMER_PERMISSION.equals(perm.getType())) {
        CreateBookingRequest request = new CreateBookingRequest();
        if (request.createBooking(user, perm.getRemotePermission(), start, end, db)) {
            response.setSuccess(request.wasSuccessful());
            response.setFailureReason(request.getReason());
            if (request.wasSuccessful()) {
                /* Provider created booking so we now need to create it 
                 * locally. */
                this.logger.debug("Successfullly created booking at provider with identifier "
                        + request.getBookingID() + '.');
                Bookings bk = new Bookings();
                bk.setActive(true);
                bk.setStartTime(startDate);
                bk.setEndTime(endDate);
                bk.setDuration((int) (end.getTimeInMillis() - start.getTimeInMillis()) / 1000);
                bk.setResourcePermission(perm);
                bk.setResourceType(ResourcePermission.CONSUMER_PERMISSION);
                bk.setProviderId(request.getBookingID());
                bk.setUser(user);
                bk.setUserNamespace(user.getNamespace());
                bk.setUserName(user.getName());
                response.setBooking(new BookingsDao(db).persist(bk));

                /* Notification emails are only sent to home users. */
                new BookingNotification(bk).notifyCreation();
            } else {
                this.logger.info("Provider failed to create booking with reason " + request.getReason());

                /* Provider returned that it couldn't create booking. */
                for (BookingTime bt : request.getBestFits()) {
                    response.addBestFit(bt.getStart(), bt.getEnd());
                }
            }
        } else {
            /* Provider call failed. */
            this.logger
                    .info("Provider call to create booking failed with reason " + request.getFailureReason());
            response.setSuccess(false);
            response.setFailureReason("Provider request failed (" + request.getFailureReason() + ")");
        }
    } else {
        BookingCreation bc = this.engine.createBooking(user, perm, new TimePeriod(start, end), db);
        if (bc.wasCreated()) {
            response.setSuccess(true);
            response.setBooking(bc.getBooking());

            /* Notification emails are only sent to home users. */
            if (perm.getRemotePermission() == null)
                new BookingNotification(bc.getBooking()).notifyCreation();
        } else {
            response.setSuccess(false);
            response.setFailureReason("Resource not free.");

            for (TimePeriod tp : bc.getBestFits()) {
                numBookings = (Integer) db.createCriteria(Bookings.class).setProjection(Projections.rowCount())
                        .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.eq("user", user))
                        .add(Restrictions.disjunction()
                                .add(Restrictions.and(Restrictions.gt("startTime", tp.getStartTime().getTime()),
                                        Restrictions.lt("startTime", tp.getEndTime().getTime())))
                                .add(Restrictions.and(Restrictions.gt("endTime", tp.getStartTime().getTime()),
                                        Restrictions.le("endTime", tp.getEndTime().getTime())))
                                .add(Restrictions.and(Restrictions.le("startTime", tp.getStartTime().getTime()),
                                        Restrictions.gt("endTime", tp.getEndTime().getTime()))))
                        .uniqueResult();
                if (numBookings > 0) {
                    this.logger.debug("Excluding best fit option for user " + user.qName() + " because it is "
                            + "concurrent with an existing.");
                    continue;
                }

                response.addBestFit(tp.getStartTime(), tp.getEndTime());
            }
        }
    }

    return response;
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RequestablePermissionPeriodDao.java

License:Open Source License

/**
 * Gets the list of active requestable periods.
 * // w  w w  .j  a v a 2s.c o m
 * @return list of requestable periods
 */
@SuppressWarnings("unchecked")
public List<RequestablePermissionPeriod> getActivePeriods() {
    return this.session.createCriteria(RequestablePermissionPeriod.class)
            .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.gt("end", new Date()))
            .addOrder(Order.desc("type")).addOrder(Order.desc("rigType")).addOrder(Order.desc("rig"))
            .addOrder(Order.desc("requestCapabilities")).addOrder(Order.asc("start")).list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigLogDao.java

License:Open Source License

/**
 * Finds all the stored logs for the specified period for a specific
 * rig. The logs are ordered by their time stamp with the earliest log 
 * first.//  w  w  w. j ava2 s . c o  m
 * 
 * @param rig rig to find the logs for
 * @param begin beginning of a period
 * @param end end of a period
 * @return list of logs
 */
@SuppressWarnings("unchecked")
public List<RigLog> findLogs(Rig rig, Date begin, Date end) {
    Criteria cri = this.session.createCriteria(RigLog.class);
    cri.add(Restrictions.eq("rig", rig));
    cri.add(Restrictions.gt("timeStamp", begin));
    cri.add(Restrictions.lt("timeStamp", end));
    cri.addOrder(Order.asc("timeStamp"));
    return cri.list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigLogDao.java

License:Open Source License

/**
 * Finds all the stored logs for the specified period for a specific
 * rig, filtered for a specific state. The logs are ordered by their
 * time stamp with the earliest log first.
 * /*from   w ww  .jav a  2  s . co  m*/
 * @param rig rig to find the logs for
 * @param begin beginning of a period
 * @param end end of a period
 * @return list of logs
 */
@SuppressWarnings("unchecked")
public List<RigLog> findLogsOfState(Rig rig, String state, Date begin, Date end) {
    Criteria cri = this.session.createCriteria(RigLog.class);
    cri.add(Restrictions.eq("rig", rig));
    cri.add(Restrictions.gt("timeStamp", begin));
    cri.add(Restrictions.lt("timeStamp", end));
    cri.add(Restrictions.eq("newState", state));
    cri.addOrder(Order.asc("timeStamp"));
    return cri.list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigOfflineScheduleDao.java

License:Open Source License

/**
 * Returns true if the rig is currently in a scheduled off-line period.
 * /*from   w  w w . j  a v  a 2  s.com*/
 * @param rig rig to check
 * @return true if off-line
 */
public boolean isOffline(Rig rig) {
    Date now = new Date();
    return (Integer) this.session.createCriteria(this.clazz).add(Restrictions.eq("rig", rig))
            .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.lt("startTime", now))
            .add(Restrictions.gt("endTime", now)).setProjection(Projections.rowCount()).uniqueResult() > 0;
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.RigOfflineScheduleDao.java

License:Open Source License

/**
 * Returns a list of offline periods for the rig.
 * /*from   www . j  av a  2s  .  c  om*/
 * @param rig rig
 * @return list of offline periods
 */
@SuppressWarnings("unchecked")
public List<RigOfflineSchedule> getOfflinePeriods(Rig rig) {
    return this.session.createCriteria(this.clazz).add(Restrictions.eq("rig", rig))
            .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.gt("endTime", new Date())).list();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.pages.KeysPage.java

License:Open Source License

/**
 * Returns the list of keys for a user class. If the parameter 'historical'
 * is part of the request parameters and has a value of 'true', non-usable
 * keys are returned otherwise usable keys are returned. Usable keys are 
 * those that are 'active', have remaining uses and have not elapsed
 * their expiry time. //from w w w  .  j a v  a  2  s.  c o  m
 * 
 * @param request request
 * @return list of permission keys
 * @throws JSONException 
 */
@SuppressWarnings("unchecked")
public JSONArray getList(HttpServletRequest request) throws JSONException {
    JSONArray arr = new JSONArray();

    String className = request.getParameter("name");
    if (className == null) {
        this.logger.warn("Unable to provide access key list because the user class name was not provided.");
        return arr;
    }

    Criteria qu = this.db.createCriteria(UserClassKey.class).add(Restrictions.eq("userTargeted", Boolean.FALSE))
            .addOrder(Order.asc("id"));

    if ("true".equals(request.getAttribute("historical"))) {
        qu.add(Restrictions.disjunction().add(Restrictions.eq("active", Boolean.FALSE))
                .add(Restrictions.eq("remaining", 0)))
                .add(Restrictions.or(Restrictions.isNull("expiry"), Restrictions.lt("expiry", new Date())));
    } else {
        qu.add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.gt("remaining", 0))
                .add(Restrictions.or(Restrictions.isNull("expiry"), Restrictions.gt("expiry", new Date())));
    }

    qu = qu.createCriteria("userClass").add(Restrictions.eq("name", className));

    for (UserClassKey key : (List<UserClassKey>) qu.list()) {
        JSONObject keyObj = new JSONObject();
        keyObj.put("key", key.getRedeemKey());
        keyObj.put("active", key.isActive());
        keyObj.put("remaining", key.getRemaining());
        arr.put(keyObj);
    }

    return arr;
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.RigManagement.java

License:Open Source License

@Override
public PutRigOfflineResponse putRigOffline(PutRigOffline putRigOffline) {
    PutRigOfflineType param = putRigOffline.getPutRigOffline();
    this.logger.debug("Received RigManagement#putRigOffline with params: requestor ID=" + param.getRequestorID()
            + "requestor namespace=" + param.getRequestorNameSpace() + ", requestor name"
            + param.getRequestorName() + ", rig name=" + param.getRig().getName() + ", offline start="
            + param.getStart().getTime() + ", offline end=" + param.getEnd().getTime() + ", reason="
            + param.getReason() + '.');

    PutRigOfflineResponse response = new PutRigOfflineResponse();
    OperationResponseType result = new OperationResponseType();
    response.setPutRigOfflineResponse(result);

    RigDao dao = new RigDao();
    try {/*from  ww w. j  av a2 s .  c  om*/
        if (!this.isAuthorised(param, dao.getSession())) {
            this.logger.warn("Unable to put a rig offline because the user is not authorised to perform this "
                    + "operation (not a ADMIN).");
            result.setFailureCode(1);
            result.setFailureReason("Not authorised.");
            return response;
        }

        Rig rig = dao.findByName(param.getRig().getName());
        if (rig == null) {
            this.logger.warn("Unable to put a rig offline because the rig with name " + param.getRig().getName()
                    + " was not found.");
            result.setFailureCode(2);
            result.setFailureReason("Rig not found.");
            return response;
        }

        if (param.getStart().after(param.getEnd())) {
            this.logger
                    .warn("Unable to put a rig offline because the offline start " + param.getStart().getTime()
                            + " is after the offline end " + param.getEnd().getTime() + ".");
            result.setFailureCode(3);
            result.setFailureReason("Start after end.");
            return response;
        }

        Date startDate = param.getStart().getTime();
        Date endDate = param.getEnd().getTime();

        if ((Integer) dao.getSession().createCriteria(RigOfflineSchedule.class)
                .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.eq("rig", rig))
                .add(Restrictions.disjunction()
                        .add(Restrictions.and(Restrictions.gt("startTime", startDate),
                                Restrictions.lt("endTime", endDate)))
                        .add(Restrictions.and(Restrictions.lt("startTime", startDate),
                                Restrictions.gt("endTime", endDate)))
                        .add(Restrictions.and(Restrictions.lt("startTime", startDate),
                                Restrictions.gt("endTime", endDate)))
                        .add(Restrictions.and(Restrictions.lt("startTime", startDate),
                                Restrictions.gt("endTime", endDate))))
                .setProjection(Projections.rowCount()).uniqueResult() > 0) {
            this.logger.warn("Unable to put a rig offline because there is a concurrent rig offline period.");
            result.setFailureCode(4);
            result.setFailureReason("Concurrent offline period.");
            return response;
        }

        result.setSuccessful(true);

        RigOfflineSchedule offline = new RigOfflineSchedule();
        offline.setActive(true);
        offline.setRig(rig);
        offline.setStartTime(startDate);
        offline.setEndTime(endDate);
        offline.setReason(param.getReason());
        new RigOfflineScheduleDao(dao.getSession()).persist(offline);

        /* Notify the booking engine. */
        BookingEngineService service = RigManagementActivator.getBookingService();
        if (service != null)
            service.putRigOffline(offline, dao.getSession());

        /* If the period is currently active, clear the rig maintenance state. */
        Date now = new Date();
        if (rig.isActive() && rig.isOnline() && offline.getStartTime().before(now)
                && offline.getEndTime().after(now)) {
            this.logger.info("Setting maintenance state on rig " + rig.getName() + '.');
            if (this.notTest)
                new RigMaintenance().putMaintenance(rig, true, dao.getSession());

            rig.setOnline(false);
            rig.setOfflineReason("In maintenance.");
            new RigLogDao(dao.getSession()).addOfflineLog(rig, "In maintenance.");
            dao.flush();
        }
    } finally {
        dao.closeSession();
    }

    return response;
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

private List<Long> applyConsentStatusFilters(DataExtractionVO allTheData, Search search,
        List<Long> idsToInclude) {

    //for(Long l : idsToInclude) {
    //   log.info("including: " + l);
    //}//  w  ww.  j  a  v a2s  .  co  m
    boolean hasConsentFilters = false;
    if (search.getQueryFilters().isEmpty()) {
        return idsToInclude;
    } else {
        for (QueryFilter filter : search.getQueryFilters()) {
            if (filter.getConsentStatusField() != null) {
                hasConsentFilters = true;
            }
        }
    }
    Criteria filter = getSession().createCriteria(Consent.class, "c");
    filter.add(Restrictions.eq("c.study.id", search.getStudy().getId()));
    filter.createAlias("c.linkSubjectStudy", "lss");
    if (!idsToInclude.isEmpty()) {
        filter.add(Restrictions.in("lss.id", idsToInclude));
    }
    filter.createAlias("c.studyComponentStatus", "cscs");
    filter.createAlias("c.studyComp", "csc");

    if (!hasConsentFilters) {

        for (QueryFilter qf : search.getQueryFilters()) {
            if (qf.getConsentStatusField() != null) {
                switch (qf.getOperator()) {
                case EQUAL:
                    filter.add(Restrictions.eq(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case BETWEEN:
                    filter.add(Restrictions.between(getConsentFilterFieldName(qf), qf.getValue(),
                            qf.getSecondValue()));
                    break;
                case GREATER_THAN:
                    filter.add(Restrictions.gt(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case GREATER_THAN_OR_EQUAL:
                    filter.add(Restrictions.ge(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case IS_EMPTY:
                    filter.add(Restrictions.isEmpty(getConsentFilterFieldName(qf)));
                    break;
                case IS_NOT_EMPTY:
                    filter.add(Restrictions.isNotEmpty(getConsentFilterFieldName(qf)));
                    break;
                case LESS_THAN:
                    filter.add(Restrictions.lt(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case LESS_THAN_OR_EQUAL:
                    filter.add(Restrictions.le(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                case LIKE:
                    filter.add(Restrictions.like(getConsentFilterFieldName(qf), qf.getValue(),
                            MatchMode.ANYWHERE));
                    break;
                case NOT_EQUAL:
                    filter.add(Restrictions.ne(getConsentFilterFieldName(qf), qf.getValue()));
                    break;
                default:
                    break;
                }
            }
        }
    }
    filter.setProjection(
            Projections.distinct(Projections.projectionList().add(Projections.property("lss.id"))));

    List<Long> consentStatusIDs = filter.list();

    Collection<Consent> csData = Collections.EMPTY_LIST;

    if (!consentStatusIDs.isEmpty()) {
        Criteria consentData = getSession().createCriteria(Consent.class, "c");
        consentData.add(Restrictions.eq("c.study.id", search.getStudy().getId()));
        consentData.createAlias("c.linkSubjectStudy", "lss");
        consentData.add(Restrictions.in("lss.id", consentStatusIDs));
        csData = consentData.list();
    }

    HashMap<String, ExtractionVO> hashOfConsentStatusData = allTheData.getConsentStatusData();

    ExtractionVO valuesForThisLss = new ExtractionVO();
    HashMap<String, String> map = null;
    LinkSubjectStudy previousLss = null;
    int count = 0;
    //will try to order our results and can therefore just compare to last LSS and either add to or create new Extraction VO
    for (Consent data : csData) {
        if (previousLss == null) {
            map = new HashMap<String, String>();
            previousLss = data.getLinkSubjectStudy();
            count = 0;
        } else if (data.getLinkSubjectStudy().getId().equals(previousLss.getId())) {
            //then just put the data in
            count++;
        } else { //if its a new LSS finalize previous map, etc
            valuesForThisLss.setKeyValues(map);
            valuesForThisLss.setSubjectUid(previousLss.getSubjectUID());
            hashOfConsentStatusData.put(previousLss.getSubjectUID(), valuesForThisLss);
            previousLss = data.getLinkSubjectStudy();
            map = new HashMap<String, String>();//reset
            valuesForThisLss = new ExtractionVO();
            count = 0;
        }
        if (data.getStudyComp().getName() != null) {
            map.put(count + "_Study Component Name", data.getStudyComp().getName());
        }
        if (data.getStudyComponentStatus() != null) {
            map.put(count + "_Study Component Status", data.getStudyComponentStatus().getName());
        }
        if (data.getConsentDate() != null) {
            map.put(count + "_Consent Date", data.getConsentDate().toString());
        }
        if (data.getConsentedBy() != null) {
            map.put(count + "_Consented By", data.getConsentedBy());
        }
    }

    //finalize the last entered key value sets/extraction VOs
    if (map != null && previousLss != null) {
        valuesForThisLss.setKeyValues(map);
        valuesForThisLss.setSubjectUid(previousLss.getSubjectUID());
        hashOfConsentStatusData.put(previousLss.getSubjectUID(), valuesForThisLss);
    }

    //can probably now go ahead and add these to the dataVO...even though inevitable further filters may further axe this list or parts of it.
    allTheData.setConsentStatusData(hashOfConsentStatusData);
    if (hasConsentFilters) {
        return consentStatusIDs;
    } else {
        return idsToInclude;
    }
}