List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
From source file:org.webcurator.domain.TargetInstanceDAOImpl.java
License:Apache License
/** * Detect and update TargetGroups that must be made inactive due to their * end date having been passed.//w w w .ja v a 2 s . c om */ public void endDateGroups() { Date startTime = new Date(); log.info("Starting Job to check end dates on groups"); getHibernateTemplate().execute(new HibernateCallback() { @SuppressWarnings("unchecked") public Object doInHibernate(Session aSession) throws HibernateException, SQLException { List<TargetGroup> groupsToEnd = aSession.createCriteria(TargetGroup.class) .add(Restrictions.ne("state", TargetGroup.STATE_INACTIVE)) .add(Restrictions.lt("toDate", new Date())).list(); for (TargetGroup group : groupsToEnd) { deleteScheduledInstances(group); group.changeState(TargetGroup.STATE_INACTIVE); } return null; } }); log.info("Completed Job to check end dates on group: took " + (new Date().getTime() - startTime.getTime()) + "ms"); }
From source file:org.webical.dao.hibernateImpl.EventDaoWebDavHibernateBufferedImpl.java
License:Open Source License
@Transaction(readOnly = false) @SuppressWarnings("unchecked") public List<Event> getEventsForPeriod(Calendar calendar, Date dtStart, Date dtEnd) throws DaoException { if (calendar == null || dtStart == null || dtEnd == null) return null; List<Event> eventList = new ArrayList<Event>(); refreshCalendarEventsAfterRefreshTime(calendar); try {//from w w w . ja v a 2 s . c o m Criteria criteria = getSession().createCriteria(Event.class); criteria.add(Restrictions.eq(Calendar.CALENDAR_PROPERTY_NAME, calendar)); criteria.add(Restrictions.lt("dtStart", new Date(dtEnd.getTime() + CalendarUtils.secondInMs))); criteria.add(Restrictions.gt("dtEnd", new Date(dtStart.getTime() - CalendarUtils.secondInMs))); if (log.isDebugEnabled()) log.debug(criteria.toString() + " " + calendar.getName()); List<Event> events = criteria.list(); eventList.addAll(this.getRecurringEvents(calendar, events, dtStart, dtEnd)); if (log.isDebugEnabled()) { log.debug("Events: " + eventList.size() + " for period: " + dtStart + " to " + dtEnd); } return eventList; } catch (Exception e) { log.error(e, e); throw new DaoException("Could not get Events", e); } }
From source file:org.xerela.provider.devices.internal.OsVersionResolutionScheme.java
License:Mozilla Public License
private PageData search(String osType, String operator, String version, PageData pageData, String sortColumn, boolean descending) { AdapterMetadata adapterMetadata = DeviceProviderActivator.getAdapterService().getAdapterMetadata(osType); if (adapterMetadata != null) { Session session = DeviceProviderActivator.getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(ZDeviceLite.class).setFirstResult(pageData.getOffset()) .setMaxResults(pageData.getPageSize()); criteria.add(Restrictions.eq(ATTR_ADAPTER_ID, osType)); if (version != null && version.trim().length() > 0) { String canonicalVersion = ServerDeviceElf.computeCononicalVersion(version, adapterMetadata.getSoftwareVersionRegEx()); if (">".equals(operator)) //$NON-NLS-1$ {/*from w w w . j a v a 2 s . c o m*/ criteria.add(Restrictions.gt(ATTR_CANONICAL_OS_VERSION, canonicalVersion)); } else if ("<".equals(operator)) //$NON-NLS-1$ { criteria.add(Restrictions.lt(ATTR_CANONICAL_OS_VERSION, canonicalVersion)); } else if ("=".equals(operator)) //$NON-NLS-1$ { criteria.add(Restrictions.eq(ATTR_CANONICAL_OS_VERSION, canonicalVersion)); } else if ("<=".equals(operator)) //$NON-NLS-1$ { criteria.add(Restrictions.le(ATTR_CANONICAL_OS_VERSION, canonicalVersion)); } else if (">=".equals(operator)) //$NON-NLS-1$ { criteria.add(Restrictions.ge(ATTR_CANONICAL_OS_VERSION, canonicalVersion)); } else { throw new RuntimeException( String.format("Invalid operator '%s'supplied to search method.", operator)); //$NON-NLS-1$ } } return populatePageData(pageData, criteria, sortColumn, descending); } return new PageData(); }
From source file:org.yes.cart.service.dto.impl.DtoPromotionServiceImpl.java
License:Apache License
@Override public List<PromotionDTO> findBy(final String shopCode, final String currency, final String filter, final int page, final int pageSize) throws UnmappedInterfaceException, UnableToCreateInstanceException { final List<PromotionDTO> dtos = new ArrayList<>(); if (StringUtils.hasLength(shopCode) && StringUtils.hasLength(currency)) { // only allow lists for shop+currency selection final List<Criterion> criteria = new ArrayList<Criterion>(); criteria.add(Restrictions.eq("shopCode", shopCode)); criteria.add(Restrictions.eq("currency", currency)); if (StringUtils.hasLength(filter)) { final Pair<Date, Date> dateSearch = ComplexSearchUtils.checkDateRangeSearch(filter); if (dateSearch != null) { if (dateSearch.getFirst() != null) { criteria.add(Restrictions.le("enabledFrom", dateSearch.getFirst())); }// ww w . j a v a 2 s.c o m if (dateSearch.getSecond() != null) { criteria.add(Restrictions.ge("enabledTo", dateSearch.getSecond())); } } else { final Pair<String, String> enabled = ComplexSearchUtils.checkSpecialSearch(filter, ENABLED); boolean enabledOnly = enabled != null && "+".equals(enabled.getFirst()); boolean disabledOnly = enabled != null && "-".equals(enabled.getFirst()); if (enabledOnly) { final Date now = new Date(); criteria.add(Restrictions.eq("enabled", Boolean.TRUE)); criteria.add(Restrictions.or(Restrictions.isNull("enabledFrom"), Restrictions.le("enabledFrom", now))); criteria.add(Restrictions.or(Restrictions.isNull("enabledTo"), Restrictions.gt("enabledTo", now))); } if (disabledOnly) { final Date now = new Date(); criteria.add(Restrictions.or(Restrictions.eq("enabled", Boolean.FALSE), Restrictions.gt("enabledFrom", now), Restrictions.lt("enabledTo", now))); } if (enabled == null || !enabled.getFirst().equals(enabled.getSecond())) { final Pair<String, String> tagOrCodeOrConditionOrAction = ComplexSearchUtils .checkSpecialSearch(enabled != null ? enabled.getSecond() : filter, TAG_OR_CODE_OR_CONDITION_OR_ACTION); if (tagOrCodeOrConditionOrAction != null) { if ("#".equals(tagOrCodeOrConditionOrAction.getFirst())) { criteria.add(Restrictions.or( Restrictions.ilike("code", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.ANYWHERE), Restrictions.ilike("tag", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.ANYWHERE))); } else if ("!".equals(tagOrCodeOrConditionOrAction.getFirst())) { criteria.add(Restrictions.or( Restrictions.ilike("promoType", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.EXACT), Restrictions.ilike("promoAction", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.EXACT))); } else if ("?".equals(tagOrCodeOrConditionOrAction.getFirst())) { criteria.add(Restrictions.or( Restrictions.ilike("eligibilityCondition", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.ANYWHERE), Restrictions.ilike("promoActionContext", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.ANYWHERE))); } } else { criteria.add(Restrictions.or(Restrictions.ilike("code", filter, MatchMode.ANYWHERE), Restrictions.ilike("name", filter, MatchMode.ANYWHERE), Restrictions.ilike("description", filter, MatchMode.ANYWHERE))); } } } } final List<Promotion> entities = getService().getGenericDao().findByCriteria(page * pageSize, pageSize, criteria.toArray(new Criterion[criteria.size()]), PROMO_ORDER); fillDTOs(entities, dtos); } return dtos; }
From source file:org.yes.cart.service.dto.impl.DtoPromotionServiceImpl.java
License:Apache License
@Override public List<PromotionDTO> findBy(final String shopCode, final String currency, final String filter, final List<String> types, final List<String> actions, final int page, final int pageSize) throws UnmappedInterfaceException, UnableToCreateInstanceException { final List<PromotionDTO> dtos = new ArrayList<>(); if (StringUtils.hasLength(shopCode) && StringUtils.hasLength(currency)) { // only allow lists for shop+currency selection final List<Criterion> criteria = new ArrayList<Criterion>(); criteria.add(Restrictions.eq("shopCode", shopCode)); criteria.add(Restrictions.eq("currency", currency)); if (StringUtils.hasLength(filter)) { final Pair<Date, Date> dateSearch = ComplexSearchUtils.checkDateRangeSearch(filter); if (dateSearch != null) { if (dateSearch.getFirst() != null) { criteria.add(Restrictions.le("enabledFrom", dateSearch.getFirst())); }//from w w w.j ava 2 s . com if (dateSearch.getSecond() != null) { criteria.add(Restrictions.ge("enabledTo", dateSearch.getSecond())); } } else { final Pair<String, String> enabled = ComplexSearchUtils.checkSpecialSearch(filter, ENABLED); boolean enabledOnly = enabled != null && "+".equals(enabled.getFirst()); boolean disabledOnly = enabled != null && "-".equals(enabled.getFirst()); if (enabledOnly) { final Date now = new Date(); criteria.add(Restrictions.eq("enabled", Boolean.TRUE)); criteria.add(Restrictions.or(Restrictions.isNull("enabledFrom"), Restrictions.le("enabledFrom", now))); criteria.add(Restrictions.or(Restrictions.isNull("enabledTo"), Restrictions.gt("enabledTo", now))); } if (disabledOnly) { final Date now = new Date(); criteria.add(Restrictions.or(Restrictions.eq("enabled", Boolean.FALSE), Restrictions.gt("enabledFrom", now), Restrictions.lt("enabledTo", now))); } if (enabled == null || !enabled.getFirst().equals(enabled.getSecond())) { final Pair<String, String> tagOrCodeOrConditionOrAction = ComplexSearchUtils .checkSpecialSearch(enabled != null ? enabled.getSecond() : filter, TAG_OR_CODE_OR_CONDITION_OR_ACTION); if (tagOrCodeOrConditionOrAction != null) { if ("#".equals(tagOrCodeOrConditionOrAction.getFirst())) { criteria.add(Restrictions.or( Restrictions.ilike("code", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.ANYWHERE), Restrictions.ilike("tag", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.ANYWHERE))); } else if ("?".equals(tagOrCodeOrConditionOrAction.getFirst())) { criteria.add(Restrictions.or( Restrictions.ilike("eligibilityCondition", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.ANYWHERE), Restrictions.ilike("promoActionContext", tagOrCodeOrConditionOrAction.getSecond(), MatchMode.ANYWHERE))); } } else { criteria.add(Restrictions.or(Restrictions.ilike("code", filter, MatchMode.ANYWHERE), Restrictions.ilike("name", filter, MatchMode.ANYWHERE), Restrictions.ilike("description", filter, MatchMode.ANYWHERE))); } } } } if (CollectionUtils.isNotEmpty(types)) { criteria.add(Restrictions.in("promoType", types)); } if (CollectionUtils.isNotEmpty(actions)) { criteria.add(Restrictions.in("promoAction", actions)); } final List<Promotion> entities = getService().getGenericDao().findByCriteria(page * pageSize, pageSize, criteria.toArray(new Criterion[criteria.size()]), PROMO_ORDER); fillDTOs(entities, dtos); } return dtos; }
From source file:pe.gob.onpe.rae.dao.hibernate.ExpedientePadronDAOH.java
@Override public List<ExpedientePadron> getByCompaginado(ExpedienteImpresion expImpresion) { Criteria criteria = this.getSession().createCriteria(ExpedientePadron.class); criteria.add(Restrictions.eq("expediente", expImpresion.getExpediente())); criteria.add(Restrictions.not(Restrictions.in("estado", new Integer[] { Parametros.ESTADO_ELECTOR_ELIMINADO, Parametros.ESTADO_ELECTOR_RECHAZADO }))); criteria.add(Restrictions.eq("indicador", expImpresion.getIndicador())); criteria.add(Restrictions.gt("ordenRegistro", expImpresion.getRegistroInicial() - 1)); criteria.add(Restrictions.lt("ordenRegistro", expImpresion.getResgitroFinal() + 1)); criteria.addOrder(Order.asc("ordenRegistro")); return (List<ExpedientePadron>) criteria.list(); }
From source file:pl.umk.mat.zawodyweb.www.ranking.RankingACM.java
License:Open Source License
private RankingTable getRankingACM(int contest_id, Timestamp checkDate, boolean admin, Integer series_id) { Session hibernateSession = HibernateUtil.getSessionFactory().getCurrentSession(); Timestamp checkTimestamp;//from w w w . j ava2 s .c o m Timestamp visibleTimestamp; UsersDAO usersDAO = DAOFactory.DEFAULT.buildUsersDAO(); SeriesDAO seriesDAO = DAOFactory.DEFAULT.buildSeriesDAO(); ProblemsDAO problemsDAO = DAOFactory.DEFAULT.buildProblemsDAO(); Map<Integer, UserACM> mapUserACM = new HashMap<>(); boolean allTests; boolean frozenRanking = false; boolean frozenSeria; long lCheckDate = checkDate.getTime(); for (Series series : seriesDAO.findByContestsid(contest_id)) { if ((series_id == null && series.getVisibleinranking() == false) || (series_id != null && series_id.equals(series.getId()) == false)) { continue; } if (series.getStartdate().getTime() > lCheckDate) { continue; } frozenSeria = false; checkTimestamp = checkDate; allTests = admin; if (!admin && series.getFreezedate() != null) { if (lCheckDate > series.getFreezedate().getTime() && (series.getUnfreezedate() == null || lCheckDate < series.getUnfreezedate().getTime())) { checkTimestamp = new Timestamp(series.getFreezedate().getTime()); if (series.getUnfreezedate() != null) { frozenRanking = true; } frozenSeria = true; } } if (checkTimestamp.before(series.getStartdate())) { visibleTimestamp = new Timestamp(0); } else { visibleTimestamp = new Timestamp(series.getStartdate().getTime()); } if (series.getUnfreezedate() != null) { if (checkDate.after(series.getUnfreezedate())) { allTests = true; } } for (Problems problems : problemsDAO.findBySeriesid(series.getId())) { if (problems.getVisibleinranking() == false) { continue; } // select sum(maxpoints) from tests where problemsid='7' and visibility=1 Number maxPoints; Number testCount; if (allTests) { Object[] o = (Object[]) hibernateSession.createCriteria(Tests.class) .setProjection(Projections.projectionList().add(Projections.sum("maxpoints")) .add(Projections.rowCount())) .add(Restrictions.eq("problems.id", problems.getId())).uniqueResult(); maxPoints = (Number) o[0]; testCount = (Number) o[1]; } else { Object[] o = (Object[]) hibernateSession.createCriteria(Tests.class) .setProjection(Projections.projectionList().add(Projections.sum("maxpoints")) .add(Projections.rowCount())) .add(Restrictions.and(Restrictions.eq("problems.id", problems.getId()), Restrictions.eq("visibility", 1))) .uniqueResult(); maxPoints = (Number) o[0]; testCount = (Number) o[1]; } if (maxPoints == null) { maxPoints = 0; // To nie powinno si nigdy zdarzy ;).. chyba, e nie ma testu przy zadaniu? } if (testCount == null) { testCount = 0; // To nie powinno si zdarzy nigdy. } Query query; if (allTests == true) { query = hibernateSession.createSQLQuery("" + "select usersid, min(sdate) sdate " // zapytanie zewntrzne znajduj minimaln dat wysania poprawnego rozwizania dla kadego usera + "from submits " + "where id in (" + " select submits.id " // zapytanie wewntrzne znajduje wszystkie id, ktre zdobyy maksa punktw + " from submits,results,tests " + " where submits.problemsid = :problemsId " + " and submits.id=results.submitsid " + " and tests.id = results.testsid " + " and results.status = :statusAcc " + " and submits.state = :stateDone " + " and sdate <= :currentTimestamp " + " and sdate >= :visibleTimestamp " + " and visibleInRanking=true" //+ " and tests.visibility=1 " + " group by submits.id,usersid,sdate " + " having sum(points) = :maxPoints " + " and count(points) = :testCount " + " ) " + "group by usersid") .setInteger("problemsId", problems.getId()) .setInteger("statusAcc", ResultsStatusEnum.ACC.getCode()) .setInteger("stateDone", SubmitsStateEnum.DONE.getCode()) .setInteger("maxPoints", maxPoints.intValue()) .setInteger("testCount", testCount.intValue()) .setTimestamp("currentTimestamp", checkTimestamp) .setTimestamp("visibleTimestamp", visibleTimestamp); } else { query = hibernateSession.createSQLQuery("" + "select usersid, min(sdate) sdate " + "from submits " + "where id in (" + " select submits.id " + " from submits,results,tests " + " where submits.problemsid = :problemsId " + " and submits.id=results.submitsid " + " and tests.id = results.testsid " + " and results.status = :statusAcc " + " and submits.state = :stateDone " + " and sdate <= :currentTimestamp " + " and sdate >= :visibleTimestamp " + " and visibleInRanking=true" + " and tests.visibility=1 " // FIXME: should be ok + " group by submits.id,usersid,sdate " + " having sum(points) = :maxPoints " + " and count(points) = :testCount " + " ) " + "group by usersid") .setInteger("problemsId", problems.getId()) .setInteger("statusAcc", ResultsStatusEnum.ACC.getCode()) .setInteger("stateDone", SubmitsStateEnum.DONE.getCode()) .setInteger("maxPoints", maxPoints.intValue()) .setInteger("testCount", testCount.intValue()) .setTimestamp("currentTimestamp", checkTimestamp) .setTimestamp("visibleTimestamp", visibleTimestamp); } for (Object list : query.list()) { // tu jest zwrcona lista "zaakceptowanych" w danym momencie rozwiza zadania Object[] o = (Object[]) list; Number bombs = (Number) hibernateSession.createCriteria(Submits.class) .setProjection(Projections.rowCount()) .add(Restrictions.eq("problems.id", (Number) problems.getId())) .add(Restrictions.eq("users.id", (Number) o[0])) .add(Restrictions.lt("sdate", (Timestamp) o[1])).uniqueResult(); if (bombs == null) { bombs = 0; } UserACM user = mapUserACM.get((Integer) o[0]); if (user == null) { Integer user_id = (Integer) o[0]; Users users = usersDAO.getById(user_id); user = new UserACM(user_id, users); mapUserACM.put((Integer) o[0], user); } user.add(maxPoints.intValue(), new SolutionACM(problems.getAbbrev(), ((Timestamp) o[1]).getTime(), (maxPoints.equals(0) ? 0 : ((Timestamp) o[1]).getTime() - series.getStartdate().getTime()) / 1000, series.getPenaltytime() * bombs.intValue(), bombs.intValue(), problems.getName(), frozenSeria)); } } } /* * Tworzenie rankingu z danych */ List<UserACM> cre = new ArrayList<>(); cre.addAll(mapUserACM.values()); Collections.sort(cre); /* * nazwy kolumn */ List<String> columnsCaptions = new ArrayList<>(); columnsCaptions.add(messages.getString("points")); columnsCaptions.add(messages.getString("time")); columnsCaptions.add(messages.getString("solutions")); /* * nazwy klas css-owych dla kolumn */ List<String> columnsCSS = new ArrayList<>(); columnsCSS.add("small"); // points columnsCSS.add("nowrap small"); // time columnsCSS.add("big left"); // solutions /* * tabelka z rankingiem */ List<RankingEntry> vectorRankingEntry = new ArrayList<>(); int place = 0; long totalTime = -1; int points = Integer.MAX_VALUE; for (UserACM user : cre) { if (points > user.points || (points == user.points && totalTime < user.totalTime)) { ++place; points = user.points; totalTime = user.totalTime; } List<String> v = new ArrayList<>(); v.add(Integer.toString(user.points)); v.add(parseTime(user.totalTime)); v.add(user.getSolutionsForRanking()); vectorRankingEntry .add(new RankingEntry(place, user.firstname, user.lastname, user.login, user.loginOnly, v)); } return new RankingTable(columnsCaptions, columnsCSS, vectorRankingEntry, frozenRanking); }
From source file:py.una.pol.karaku.dao.helper.LtExpressionHelper.java
License:Open Source License
@Override public Criterion getCriterion(@Nonnull Criteria criteria, @Nonnull Lt lt, @Nonnull Map<String, String> aliases) { String aliasWithProperty = configureAlias(criteria, lt.getPath(), aliases); return Restrictions.lt(aliasWithProperty, lt.getValue()); }
From source file:py.una.pol.karaku.dao.where.Lt.java
License:Open Source License
@Override public Criterion getCriterion() { return Restrictions.lt(this.path, this.value); }
From source file:ro.cs.ts.model.dao.impl.DaoRecordImpl.java
License:Open Source License
/** * Checks if exists a record for a person, for a specific project, activity, with the same work hours or overtime hours range * /*w w w .ja v a2 s . c o m*/ * @author Adelina * * @param recordId * @param teamMemberDetailId * @param activityId * @param startTime * @param endTime * @param time * @param overTimeStartTime * @param overTimeEndTime * @param overtimeTime * @param personDetailId * @return */ public Record hasIdenticalRecordForPerson(Integer recordId, Integer teamMemberDetailId, Integer activityId, Date startTime, Date endTime, String time, Date overTimeStartTime, Date overTimeEndTime, String overtimeTime, Integer personDetailId) { logger.debug("hasIdenticalRecordForPerson - START"); // if we have a startTime and an endTime if (startTime != null && endTime != null) { logger.debug("startTime = " + startTime); logger.debug("endTime = " + endTime); boolean existRecord = false; // else, find if there is another record with the same conditions DetachedCriteria dc1 = DetachedCriteria.forEntityName(IModelConstant.recordEntity); if (teamMemberDetailId != null) { dc1.add(Restrictions.eq("teamMemberDetailId", teamMemberDetailId)); } else if (personDetailId != null) { dc1.add(Restrictions.eq("personDetailId", personDetailId)); } dc1.add(Restrictions.ne("status", IConstant.NOM_RECORD_STATUS_DELETED)); dc1.add(Restrictions.eq("activityId", activityId)); if (recordId != null && recordId > 0) { dc1.add(Restrictions.ne("recordId", recordId)); } dc1.add(Restrictions.or( Restrictions.or( Restrictions.or( Restrictions.and(Restrictions.ge("startTime", startTime), Restrictions.le("endTime", endTime)), Restrictions.and(Restrictions.lt("startTime", startTime), Restrictions.gt("endTime", startTime))), Restrictions.or( Restrictions.and(Restrictions.lt("startTime", endTime), Restrictions.gt("endTime", endTime)), Restrictions.and(Restrictions.le("startTime", startTime), Restrictions.gt("endTime", endTime)))), Restrictions.or( Restrictions.or( Restrictions.and(Restrictions.ge("overTimeStartTime", startTime), Restrictions.le("overTimeEndTime", endTime)), Restrictions.and(Restrictions.lt("overTimeStartTime", startTime), Restrictions.gt("overTimeEndTime", startTime))), Restrictions.or( Restrictions.and(Restrictions.lt("overTimeStartTime", endTime), Restrictions.gt("overTimeEndTime", endTime)), Restrictions.and(Restrictions.le("overTimeStartTime", startTime), Restrictions.gt("overTimeEndTime", endTime)))))); List<Record> tempRecords = (List<Record>) getHibernateTemplate().findByCriteria(dc1); Record record = null; if (tempRecords != null && tempRecords.size() > 0) { logger.debug("tempRecords size = " + tempRecords.size() + ", " + tempRecords); for (Record rec : tempRecords) { logger.debug("record = " + rec); if (rec.getStartTime() != null && rec.getEndTime() != null) { boolean hasOverlap = ControllerUtils.getInstance().hasOverlap(startTime, endTime, time, rec.getStartTime(), rec.getEndTime(), rec.getTime()); logger.debug("hasOverlap = " + hasOverlap); if (hasOverlap) { existRecord = true; record = rec; break; } } if (rec.getOverTimeStartTime() != null && rec.getOverTimeEndTime() != null) { if (ControllerUtils.getInstance().hasOverlap(startTime, endTime, time, rec.getOverTimeStartTime(), rec.getOverTimeEndTime(), rec.getOverTimeTime())) { existRecord = true; record = rec; break; } } } } // if we have also an overtimeStartTime and an overtimeEndTime if (overTimeStartTime != null && overTimeEndTime != null) { logger.debug("overTimeStartTime = " + overTimeStartTime); logger.debug("overTimeEndTime = " + overTimeEndTime); // if the range for the work hours is the same or is an interval from the overtime hours // we can't add or update the record if (((startTime.after(overTimeStartTime) || startTime.equals(overTimeStartTime)) && (endTime.before(overTimeEndTime) || endTime.equals(overTimeEndTime))) || (startTime.before(overTimeStartTime) && endTime.after(overTimeStartTime)) || (startTime.before(overTimeEndTime) && endTime.after(overTimeEndTime)) || ((startTime.before(overTimeStartTime) || startTime.equals(overTimeStartTime)) && (endTime.after(overTimeEndTime) || endTime.equals(overTimeEndTime)))) { logger.debug("hasIdenticalRecordForPerson - END"); if (ControllerUtils.getInstance().hasOverlap(startTime, endTime, time, overTimeStartTime, overTimeEndTime, overtimeTime)) { return new Record(); } else { return null; } } else { if (existRecord == true) { logger.debug("hasIdenticalRecordForPerson - END, tempRecords = " + tempRecords + ", size = " + tempRecords.size()); return record; } } } else { if (existRecord == true) { logger.debug("hasIdenticalRecordForPerson - END, tempRecords = " + tempRecords + ", size = " + tempRecords.size()); return record; } } } // also, for the overtime if (overTimeStartTime != null && overTimeEndTime != null) { logger.debug("overTimeStartTime = " + overTimeStartTime); logger.debug("overTimeEndTime = " + overTimeEndTime); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.recordEntity); if (teamMemberDetailId != null) { dc.add(Restrictions.eq("teamMemberDetailId", teamMemberDetailId)); } else if (personDetailId != null) { dc.add(Restrictions.eq("personDetailId", personDetailId)); } dc.add(Restrictions.ne("status", IConstant.NOM_RECORD_STATUS_DELETED)); dc.add(Restrictions.eq("activityId", activityId)); if (recordId != null && recordId > 0) { dc.add(Restrictions.ne("recordId", recordId)); } dc.add(Restrictions.or( Restrictions.or( Restrictions.or( Restrictions.and(Restrictions.ge("startTime", overTimeStartTime), Restrictions.le("endTime", overTimeEndTime)), Restrictions.and(Restrictions.lt("startTime", overTimeStartTime), Restrictions.gt("endTime", overTimeStartTime))), Restrictions.or( Restrictions.and(Restrictions.lt("startTime", overTimeEndTime), Restrictions.gt("endTime", overTimeEndTime)), Restrictions.and(Restrictions.le("startTime", overTimeStartTime), Restrictions.gt("endTime", overTimeEndTime)))), Restrictions.or( Restrictions.or( Restrictions.and(Restrictions.ge("overTimeStartTime", overTimeStartTime), Restrictions.le("overTimeEndTime", overTimeEndTime)), Restrictions.and(Restrictions.lt("overTimeStartTime", overTimeStartTime), Restrictions.gt("overTimeEndTime", overTimeStartTime))), Restrictions.or( Restrictions.and(Restrictions.lt("overTimeStartTime", overTimeEndTime), Restrictions.gt("overTimeEndTime", overTimeEndTime)), Restrictions.and(Restrictions.le("overTimeStartTime", overTimeStartTime), Restrictions.gt("overTimeEndTime", overTimeEndTime)))))); List<Record> records = (List<Record>) getHibernateTemplate().findByCriteria(dc); logger.debug("hasIdenticalRecordForPerson - END, records = " + records + ", size = " + records.size()); if (records != null && records.size() > 0) { for (Record rec : records) { logger.debug("rec = " + rec); if (rec.getStartTime() != null && rec.getEndTime() != null) { if (ControllerUtils.getInstance().hasOverlap(overTimeStartTime, overTimeEndTime, overtimeTime, rec.getStartTime(), rec.getEndTime(), rec.getTime())) { return rec; } } else if (rec.getOverTimeStartTime() != null && rec.getOverTimeEndTime() != null) { if (ControllerUtils.getInstance().hasOverlap(overTimeStartTime, overTimeEndTime, overtimeTime, rec.getOverTimeStartTime(), rec.getOverTimeEndTime(), rec.getOverTimeTime())) { return rec; } } } return null; } } return null; }