Example usage for org.apache.commons.lang.time DateUtils isSameDay

List of usage examples for org.apache.commons.lang.time DateUtils isSameDay

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils isSameDay.

Prototype

public static boolean isSameDay(Calendar cal1, Calendar cal2) 

Source Link

Document

Checks if two calendar objects are on the same day ignoring time.

28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.

Usage

From source file:org.kuali.kra.common.committee.service.impl.CommitteeScheduleServiceImplBase.java

/**
 * Helper method to test if date is available (non conflicting).
 * @param committeeSchedules/*  w  w  w . j  a  v  a2  s  . c  o  m*/
 * @param date
 * @return
 */
protected Boolean isDateAvailable(List<CS> committeeSchedules, java.sql.Date date) {
    boolean retVal = true;
    for (CS committeeSchedule : committeeSchedules) {
        Date scheduledDate = committeeSchedule.getScheduledDate();
        if ((scheduledDate != null) && DateUtils.isSameDay(scheduledDate, date)) {
            retVal = false;
            break;
        }
    }
    return retVal;
}

From source file:org.linagora.linshare.core.batches.impl.UploadRequestBatchImpl.java

@Override
public void updateStatus() {
    SystemAccount systemAccount = accountRepository.getBatchSystemAccount();
    logger.info("Update upload request status");
    List<MailContainerWithRecipient> notifications = Lists.newArrayList();
    for (UploadRequest r : uploadRequestRepository.findByStatus(UploadRequestStatus.STATUS_CREATED)) {
        if (r.getActivationDate().before(new Date())) {
            try {
                r.updateStatus(UploadRequestStatus.STATUS_ENABLED);
                r = uploadRequestService.updateRequest(systemAccount, systemAccount, r);
                for (UploadRequestUrl u : r.getUploadRequestURLs()) {
                    notifications.add(mailBuildingService.buildActivateUploadRequest((User) r.getOwner(), u));
                }/*w  ww  .j  a  v a2 s.com*/
            } catch (BusinessException e) {
                logger.error("Fail to update upload request status of the request : " + r.getUuid());
            }
        }
    }
    for (UploadRequest r : uploadRequestRepository.findByStatus(UploadRequestStatus.STATUS_ENABLED)) {
        if (DateUtils.isSameDay(r.getNotificationDate(), new Date())
                && !DateUtils.isSameDay(r.getNotificationDate(), r.getExpiryDate())) {
            logger.debug("date de notification == today..." + r.getExpiryDate() + " == " + new Date());
            try {
                for (UploadRequestUrl u : r.getUploadRequestURLs()) {
                    EmailContext ctx = new UploadRequestWarnBeforeExpiryEmailContext((User) r.getOwner(), r, u,
                            false);
                    notifications.add(mailBuildingService.build(ctx));
                }
                EmailContext ctx = new UploadRequestWarnBeforeExpiryEmailContext((User) r.getOwner(), r, null,
                        true);
                notifications.add(mailBuildingService.build(ctx));
            } catch (BusinessException e) {
                logger.error("Fail to update upload request status of the request : " + r.getUuid());
            }
        }
        if (r.getExpiryDate().before(new Date())) {
            try {
                r.updateStatus(UploadRequestStatus.STATUS_CLOSED);
                r = uploadRequestService.updateRequest(systemAccount, systemAccount, r);
                for (UploadRequestUrl u : r.getUploadRequestURLs()) {
                    EmailContext ctx = new UploadRequestWarnExpiryEmailContext((User) r.getOwner(), r, u,
                            false);
                    notifications.add(mailBuildingService.build(ctx));
                }
                EmailContext ctx = new UploadRequestWarnExpiryEmailContext((User) r.getOwner(), r, null, true);
                notifications.add(mailBuildingService.build(ctx));
            } catch (BusinessException e) {
                logger.error("Fail to update upload request status of the request : " + r.getUuid());
            }
        }
    }
    try {
        notifierService.sendNotification(notifications);
    } catch (BusinessException e) {
        logger.error("Unable to send upload request status notifications");
    }
}

From source file:org.linagora.linshare.core.service.impl.UploadRequestServiceImpl.java

private List<UploadRequest> createRequestGrouped(Account actor, User owner, UploadRequest req,
        List<Contact> contacts, String subject, String body, UploadRequestGroup group)
        throws BusinessException {
    UploadRequestHistory hist = new UploadRequestHistory(req, UploadRequestHistoryEventType.EVENT_CREATED);
    req.getUploadRequestHistory().add(hist);
    req = uploadRequestBusinessService.create(req);
    List<MailContainerWithRecipient> mails = Lists.newArrayList();
    for (Contact c : contacts) {
        UploadRequestUrl requestUrl = uploadRequestUrlService.create(req, c);
        if (!DateUtils.isSameDay(req.getActivationDate(), req.getCreationDate())) {
            mails.add(mailBuildingService.buildCreateUploadRequest((User) req.getOwner(), requestUrl));
        }//from  w  ww.  j  a v a 2 s .  co  m
    }
    notifierService.sendNotification(mails);
    mails.clear();
    req = uploadRequestBusinessService.findByUuid(req.getUuid());
    if (req.getActivationDate().before(new Date())) {
        try {
            req.updateStatus(UploadRequestStatus.STATUS_ENABLED);
            updateRequest(actor, owner, req);
            for (UploadRequestUrl u : req.getUploadRequestURLs()) {
                if (u.getContact().equals(contacts.get(0))) {
                    mails.add(mailBuildingService.buildActivateUploadRequest((User) req.getOwner(), u));
                }
            }
            notifierService.sendNotification(mails);
        } catch (BusinessException e) {
            logger.error("Fail to update upload request status of the request : " + req.getUuid());
        }
    }
    return Lists.newArrayList(req);
}

From source file:org.ojbc.adapters.analyticaldatastore.CamelContextTest.java

@Test
public void testPretrialServiceEnrollmentReportService() throws Exception {
    Exchange pretrialEnrollmentReportExchange = createSenderExchange(
            "src/test/resources/xmlInstances/pretrialServicesEnrollmentReport/pretrial_services_enrollment_report.xml");

    //Send the one-way exchange.  Using template.send will send an one way message
    Exchange returnExchange = template.send("direct:processPretrialServiceReport",
            pretrialEnrollmentReportExchange);

    //Use getException to see if we received an exception
    if (returnExchange.getException() != null) {
        throw new Exception(returnExchange.getException());
    }/*from w  ww  . java 2 s.  c o  m*/

    //Sleep while a response is generated
    Thread.sleep(3000);

    PretrialServiceParticipation pretrialServiceParticipation = analyticalDatastoreDAOImpl
            .searchForPretrialServiceParticipationByUniqueID("ID43597|Incident4557");

    assertNotNull(pretrialServiceParticipation);
    assertEquals("Incident4557", pretrialServiceParticipation.getArrestIncidentCaseNumber());
    assertTrue(
            DateUtils.isSameDay(AbstractReportRepositoryProcessor.DATE_TIME_FORMAT.parse("2001-12-17T09:30:47"),
                    pretrialServiceParticipation.getIntakeDate()));
    assertEquals("ORI", pretrialServiceParticipation.getArrestingAgencyORI());
    assertEquals(Integer.valueOf(1), pretrialServiceParticipation.getCountyID());
    assertEquals("ID43597|Incident4557", pretrialServiceParticipation.getPretrialServiceUniqueID());

    List<AssessedNeed> associatedNeeds = analyticalDatastoreDAOImpl
            .getAssociatedNeeds(pretrialServiceParticipation.getPretrialServiceParticipationID());
    assertEquals(3, associatedNeeds.size());

    Person person = analyticalDatastoreDAOImpl.getPerson(pretrialServiceParticipation.getPersonID());
    assertNotNull(person);
    log.info("Person: " + person.toString());
    assertEquals(
            "Person[personID=5,personSexID=1,personRaceID=5,personSexDescription=M,"
                    + "personRaceDescription=W,personBirthDate=2001-12-17,",
            StringUtils.substringBefore(person.toString(), "personUniqueIdentifier"));

    List<PretrialService> pretrialServices = analyticalDatastoreDAOImpl
            .getAssociatedPretrialServices(pretrialServiceParticipation.getPretrialServiceParticipationID());
    assertEquals(3, pretrialServices.size());

    template.send("direct:processPretrialServiceReport", pretrialEnrollmentReportExchange);

    PretrialServiceParticipation participationUpdated = analyticalDatastoreDAOImpl
            .searchForPretrialServiceParticipationByUniqueID("ID43597|Incident4557");
    assertNotNull(participationUpdated);

    //Assert it has the same PK
    assertEquals(pretrialServiceParticipation.getPretrialServiceParticipationID().intValue(),
            participationUpdated.getPretrialServiceParticipationID().intValue());
}

From source file:org.ojbc.intermediaries.sn.dao.TestSubscriptionSearchQueryDAO.java

@Test
@DirtiesContext/*from   w  ww.ja  va 2 s.  c  o  m*/
public void testUnsubscribeCivilSubscription() throws Exception {

    Statement statement = dataSource.getConnection().createStatement();
    ResultSet rs = statement
            .executeQuery("select * from identification_transaction where subscription_id = '62724'");
    assertTrue(rs.next());
    Date availableForSubscriptionStartDate = rs.getDate("AVAILABLE_FOR_SUBSCRIPTION_START_DATE");
    log.info("availableForSubscriptionStartDate before unsubscribe: " + availableForSubscriptionStartDate);
    assertTrue(DateUtils.isSameDay(availableForSubscriptionStartDate,
            XmlUtils.parseXmlDate("2015-10-16").toDate()));

    subscriptionSearchQueryDAO.unsubscribe("62724", "{http://ojbc.org/wsn/topics}:person/arrest", null, null,
            null);

    ResultSet rsAfter = statement
            .executeQuery("select * from identification_transaction where subscription_id = '62724'");
    assertTrue(rsAfter.next());
    Date availableForSubscriptionStartDateAfter = rsAfter.getDate("AVAILABLE_FOR_SUBSCRIPTION_START_DATE");
    log.info("availableForSubscriptionStartDate after unsubscribe: " + availableForSubscriptionStartDateAfter);
    assertTrue(DateUtils.isSameDay(availableForSubscriptionStartDateAfter, Calendar.getInstance().getTime()));
}

From source file:org.ojbc.intermediaries.sn.dao.TestSubscriptionSearchQueryDAO.java

@Test
@DirtiesContext//from  w w  w.  j  a  va 2s . c  o m
public void testSubscribe_noExistingCivilSubscriptions() throws Exception {

    Statement s = dataSource.getConnection().createStatement();
    ResultSet rs = s.executeQuery(
            "select * from identification_transaction where TRANSACTION_NUMBER = '000001820140729014008339997'");
    assertTrue(rs.next());
    Date availableForSubscriptionStartDate = rs.getDate("AVAILABLE_FOR_SUBSCRIPTION_START_DATE");
    log.info("availableForSubscriptionStartDate before subscribe: " + availableForSubscriptionStartDate);
    assertTrue(DateUtils.isSameDay(availableForSubscriptionStartDate, Calendar.getInstance().getTime()));

    Map<String, String> subjectIds = new HashMap<String, String>();
    subjectIds.put(SubscriptionNotificationConstants.SID, "A023460");
    subjectIds.put(SubscriptionNotificationConstants.SUBSCRIPTION_QUALIFIER, "ABCDE");

    ResultSet rsCountBefore = s.executeQuery("select count(*) as count from subscription");
    assertTrue(rsCountBefore.next());
    int recordCount = rsCountBefore.getInt("count");

    LocalDate currentDate = new LocalDate();
    subscriptionSearchQueryDAO
            .subscribe(null, "{http://ojbc.org/wsn/topics}:person/arrest", "2015-11-03", "2016-11-02",
                    subjectIds, new HashSet<String>(Arrays.asList("none@none.com")), "offenderName",
                    "systemName", "ABCDE", "I", "SYSTEM", currentDate, "000001820140729014008339997")
            .intValue();

    ResultSet rsCountAfter = s.executeQuery("select count(*) as count from subscription");
    assertTrue(rsCountAfter.next());

    int postRecordCount = rsCountAfter.getInt("count");
    assertEquals(1, postRecordCount - recordCount);
    rs.close();

    ResultSet rsAvalibaleDateAfterSubscribe = s.executeQuery(
            "select * from identification_transaction where TRANSACTION_NUMBER = '000001820140729014008339997'");
    assertTrue(rsAvalibaleDateAfterSubscribe.next());
    Date availableForSubscriptionStartDateAfter = rsAvalibaleDateAfterSubscribe
            .getDate("AVAILABLE_FOR_SUBSCRIPTION_START_DATE");
    log.info("availableForSubscriptionStartDate after subscribe: " + availableForSubscriptionStartDateAfter);
    assertTrue(DateUtils.isSameDay(availableForSubscriptionStartDateAfter,
            XmlUtils.parseXmlDate("2016-11-03").toDate()));
}

From source file:org.olat.commons.calendar.ui.CalendarDetailsController.java

private String formatDate() {
    Locale locale = getLocale();/*w  w w  .  ja v  a 2s .  co  m*/
    Calendar cal = CalendarUtils.createCalendarInstance(locale);
    Date begin = calEvent.getBegin();
    Date end = calEvent.getEnd();
    cal.setTime(begin);

    StringBuilder sb = new StringBuilder();
    sb.append(StringHelper.formatLocaleDateFull(begin.getTime(), locale));
    if (!calEvent.isAllDayEvent()) {
        sb.append("<br />").append(StringHelper.formatLocaleTime(begin.getTime(), locale));
        sb.append(" - ");
        if (!DateUtils.isSameDay(begin, end)) {
            sb.append(StringHelper.formatLocaleDateFull(end.getTime(), locale)).append(", ");
        }
        sb.append(StringHelper.formatLocaleTime(end.getTime(), locale));
    }
    return sb.toString();
}

From source file:org.olat.commons.calendar.ui.components.WeeklyCalendarComponentRenderer.java

private void renderEventTooltip(final KalendarEventRenderWrapper eventWrapper, final String escapedSubject,
        final boolean hideSubject, final StringOutput sb, final URLBuilder ubu, final Locale locale) {
    final KalendarEvent event = eventWrapper.getEvent();
    // Tooltip content
    sb.append("<div class=\"o_cal_wv_event_tooltip");
    if (event.isAllDayEvent()) {
        // add marker css class used in js code to identify all day events
        sb.append(" o_cal_allday");
    }//from   www  . j a va  2  s. co m
    sb.append("\">");
    // time
    sb.append("<div class=\"o_cal_time\">\n");
    final Translator translator = Util.createPackageTranslator(CalendarManager.class, locale);
    final Calendar cal = CalendarUtils.createCalendarInstance(locale);
    final Date begin = event.getBegin();
    final Date end = event.getEnd();
    cal.setTime(begin);
    sb.append(StringHelper.formatLocaleDateFull(begin.getTime(), locale));
    if (!event.isAllDayEvent()) {
        sb.append("<br />").append(StringHelper.formatLocaleTime(begin.getTime(), locale));
        sb.append(" - ");
        if (!DateUtils.isSameDay(begin, end)) {
            sb.append(StringHelper.formatLocaleDateFull(end.getTime(), locale)).append(", ");
        }
        sb.append(StringHelper.formatLocaleTime(end.getTime(), locale));
    }
    sb.append("</div>\n");
    if (!hideSubject) {
        sb.append("<div class=\"o_cal_wv_event_tooltip_content\">");
        sb.append(escapedSubject);
    }

    // location
    if (StringHelper.containsNonWhitespace(event.getLocation())) {
        sb.append("<div class=\"o_cal_location\">\n");
        if (!hideSubject) {
            sb.append("<b>").append(translator.translate("cal.form.location")).append("</b>:");
            sb.append(event.getLocation());
        }
        sb.append("</div>\n");
    }
    // links
    if (!hideSubject) {
        renderEventLinks(event, sb);
    }

    if (eventWrapper.getCalendarAccess() == KalendarRenderWrapper.ACCESS_READ_WRITE) {
        // edit link
        sb.append("<div class=\"o_cal_tooltip_buttons\"><a class=\"b_button b_xsmall\" href=\"");
        ubu.buildURI(sb, new String[] { WeeklyCalendarComponent.ID_CMD, WeeklyCalendarComponent.ID_PARAM },
                new String[] { WeeklyCalendarComponent.CMD_EDIT,
                        event.getCalendar().getCalendarID() + WeeklyCalendarComponent.ID_PARAM_SEPARATOR
                                + event.getID() + WeeklyCalendarComponent.ID_PARAM_SEPARATOR
                                + event.getBegin().getTime() },
                isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
        sb.append("\" ");
        if (isIframePostEnabled) {
            ubu.appendTarget(sb);
        }
        sb.append("><span>");
        sb.append(translator.translate("edit"));
        sb.append("</span></a></div>");
    }

    // tooltip_content
    if (!hideSubject) {
        sb.append("</div>");
    }
    // event_tooltip
    sb.append("</div>");
}

From source file:org.olat.user.propertyhandlers.FutureDatePropertyHandler.java

/**
 * checks whether the given date is in the future.
 * if the two dates are on the same date, false is returned!
 * /*  www.  j  a v a 2s . c o  m*/
 * @param dateToCheck
 * @return true if the given date is in the future
 */
private static boolean isDateInTheFuture(Date dateToCheck) {
    Date now = new Date();
    return (!DateUtils.isSameDay(now, dateToCheck)) && dateToCheck.after(now);
}

From source file:org.olat.user.propertyhandlers.PastDatePropertyHandler.java

/**
 * checks whether the given date is in the past. if the two dates are on
 * the same date, false is returned!//  w  ww .j  av a 2 s  . c o  m
 * 
 * @param dateToCheck
 * @return true if the given date is in the past
 */
private boolean isDateInThePast(Date dateToCheck) {
    Date now = new Date();
    return (!DateUtils.isSameDay(now, dateToCheck)) && dateToCheck.before(now);
}