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

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

Introduction

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

Prototype

public static Date addDays(Date date, int amount) 

Source Link

Document

Adds a number of days to a date returning a new object.

Usage

From source file:org.kuali.kfs.module.cam.document.service.RetirementInfoServiceTest.java

private AssetRetirementGlobalDetail createRetirementDetail(String docNumber, int daysToAdd, String docStatus) {
    AssetRetirementGlobalDetail globalDetail = new AssetRetirementGlobalDetail();
    globalDetail.setDocumentNumber(docNumber);
    AssetRetirementGlobal retirementGlobal = new AssetRetirementGlobal() {
        @Override//w ww .  j  a  v  a  2s  . co  m
        public void refreshReferenceObject(String referenceObjectName) {
        }

    };
    retirementGlobal.setRetirementDate(
            new java.sql.Date(DateUtils.addDays(dateTimeService.getCurrentDate(), daysToAdd).getTime()));
    FinancialSystemDocumentHeader header = new FinancialSystemDocumentHeader();
    header.setFinancialDocumentStatusCode(docStatus);
    retirementGlobal.setDocumentHeader(header);
    globalDetail.setAssetRetirementGlobal(retirementGlobal);
    return globalDetail;
}

From source file:org.kuali.kfs.module.tem.batch.service.impl.PerDiemLoadServiceImpl.java

/**
 * @see org.kuali.kfs.module.tem.batch.service.PerDiemLoadService#loadPerDiem(java.lang.String,
 *      org.kuali.kfs.sys.batch.BatchInputFileType)
 */// w w w .  j av a  2 s. co  m
@Override
@Transactional
public boolean loadPerDiem(String dataFileName, BatchInputFileType inputFileType) {
    String fileExtension = "." + inputFileType.getFileExtension();
    String doneFileName = this.getCompanionFileName(dataFileName, fileExtension, TemConstants.DONE_FILE_SUFFIX);
    File doneFile = this.getFileByAbsolutePath(doneFileName);

    try {
        FileInputStream fileContents = new FileInputStream(dataFileName);
        LOG.info("Processing Per Diem file [" + dataFileName + "]");

        byte[] fileByteContent = IOUtils.toByteArray(fileContents);
        List<PerDiemForLoad> perDiemList = (List<PerDiemForLoad>) batchInputFileService.parse(inputFileType,
                fileByteContent);
        IOUtils.closeQuietly(fileContents);

        List<PerDiemForLoad> perDiemLoadList = this.validatePerDiem(perDiemList, dataFileName);

        persistedRegions = businessObjectService.findAll(TemRegion.class);
        Map<String, TemRegion> newRegions = this.extractTemCountries(perDiemLoadList, true);
        for (TemRegion region : newRegions.values()) {
            businessObjectService.save(region);
        }

        persistedPrimaryDestinations = businessObjectService.findAll(PrimaryDestination.class);
        Map<String, PrimaryDestination> newPrimaryDestinations = this
                .extractPrimaryDestinations(perDiemLoadList, true);
        for (PrimaryDestination primaryDestination : newPrimaryDestinations.values()) {
            businessObjectService.save(primaryDestination);
        }

        persistedPrimaryDestinations = businessObjectService.findAll(PrimaryDestination.class);
        Map<String, PrimaryDestination> allPrimaryDestinations = new HashMap<String, PrimaryDestination>();
        for (PrimaryDestination pd : persistedPrimaryDestinations) {
            allPrimaryDestinations
                    .put(pd.getRegionCode() + ":" + pd.getCounty() + ":" + pd.getPrimaryDestinationName(), pd);
        }

        for (PerDiem perDiem : perDiemLoadList) {
            if (perDiem.getPrimaryDestination().getId() == null) {

                StringBuilder keyBuilder = new StringBuilder();
                keyBuilder.append(perDiem.getPrimaryDestination().getRegionCode());
                keyBuilder.append(":");
                keyBuilder.append(perDiem.getPrimaryDestination().getCounty());
                keyBuilder.append(":");
                keyBuilder.append(perDiem.getPrimaryDestination().getPrimaryDestinationName());

                PrimaryDestination pd = allPrimaryDestinations.get(keyBuilder.toString());
                if (pd == null) {
                    continue;

                } else if (pd.equals(perDiem.getPrimaryDestination())) {
                    perDiem.setPrimaryDestinationId(pd.getId());
                }
            } else {
                perDiem.setPrimaryDestinationId(perDiem.getPrimaryDestination().getId());
            }
            List<PerDiem> oldPerDiems = perDiemService.retrievePreviousPerDiem(perDiem);
            for (PerDiem oldPerDiem : oldPerDiems) {

                if (KfsDateUtils.isSameDay(oldPerDiem.getEffectiveToDate(), futureDate)) {
                    oldPerDiem.setEffectiveToDate(
                            new java.sql.Date(DateUtils.addDays(perDiem.getEffectiveFromDate(), 0).getTime()));
                    businessObjectService.save(oldPerDiem);
                }
            }
            // businessObjectService.save(perDiem);
        }
        businessObjectService.save(perDiemLoadList);

    } catch (Exception ex) {
        LOG.error("Failed to process the file : " + dataFileName, ex);
        this.moveErrorFile(dataFileName, this.getPerDiemFileErrorDirectory());

        throw new RuntimeException("Failed to process the file : " + dataFileName, ex);
    } finally {
        boolean doneFileDeleted = doneFile.delete();
    }

    return true;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelAuthorizationServiceImpl.java

private Date getTripBeginDate(Timestamp tripBeginDate) {
    Date tripBegin = null;//from  w ww .  j  a  v a  2s. c o m
    Integer days = getDuplicateTripDateRangeDays();
    try {
        tripBegin = dateTimeService
                .convertToSqlDate(dateTimeService.toDateString(DateUtils.addDays(tripBeginDate, (days * -1))));

    } catch (ParseException pe) {
        LOG.error("Exception while parsing trip begin date" + pe);
    }

    return tripBegin;

}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelAuthorizationServiceImpl.java

private Date getTripEndDate(Timestamp tripEndDate) {
    Date tripEnd = null;/*from  w ww  . jav a  2  s .  c om*/
    Integer days = getDuplicateTripDateRangeDays();
    try {
        tripEnd = dateTimeService
                .convertToSqlDate(dateTimeService.toDateString((DateUtils.addDays(tripEndDate, days))));

    } catch (ParseException pe) {
        LOG.error("Exception while parsing trip end date" + pe);
    }

    return tripEnd;

}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelDocumentServiceImpl.java

private Timestamp getTripBeginDate(Timestamp tripBeginDate) {
    Timestamp tripBegin = null;//from   w w w .j  a v a 2s .  c  o  m
    Integer days = getDuplicateTripDateRangeDays();
    try {
        tripBegin = dateTimeService.convertToSqlTimestamp(
                dateTimeService.toDateString(DateUtils.addDays(tripBeginDate, (days * -1))));

    } catch (java.text.ParseException pe) {
        LOG.error("Exception while parsing trip begin date" + pe);
    }

    return tripBegin;

}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelDocumentServiceImpl.java

private Timestamp getTripEndDate(Timestamp tripEndDate) {
    Timestamp tripEnd = null;//from ww w  .  ja v  a2s.  c o m
    Integer days = getDuplicateTripDateRangeDays();
    try {
        tripEnd = dateTimeService
                .convertToSqlTimestamp(dateTimeService.toDateString((DateUtils.addDays(tripEndDate, days))));

    } catch (java.text.ParseException pe) {
        LOG.error("Exception while parsing trip end date" + pe);
    }

    return tripEnd;

}

From source file:org.kuali.kfs.sys.batch.PurgeSessionDocumentsStep.java

/**
 * @see org.kuali.kfs.sys.batch.Step#execute(java.lang.String, java.util.Date)
 *//* w w  w. ja v  a2s .  com*/
public boolean execute(String jobName, Date jobRunDate) {
    try {
        LOG.info("executing PurgeSessionDocumentsStep");
        String maxAgeInDaysStr = parameterService.getParameterValueAsString(PurgeSessionDocumentsStep.class,
                KFSConstants.SystemGroupParameterNames.NUMBER_OF_DAYS_SINCE_LAST_UPDATE);
        int maxAgeInDays = Integer.parseInt(maxAgeInDaysStr);

        Timestamp expirationDate = new Timestamp(
                DateUtils.addDays(getDateTimeService().getCurrentDate(), -maxAgeInDays).getTime());

        sessionDocumentService.purgeAllSessionDocuments(expirationDate);
        return true;
    } catch (Exception e) {
        LOG.error("error occured trying to purge session document from DB: ", e);
    }
    return false;
}

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

/**
 * Helper method to calculate advanced submission days.
 * @param startDate// www.  j  a v a2  s . c  o m
 * @param days
 * @return
 */
protected java.sql.Date calculateAdvancedSubmissionDays(Date startDate, Integer days) {
    Date deadlineDate = DateUtils.addDays(startDate, -days);
    return new java.sql.Date(deadlineDate.getTime());
}

From source file:org.kuali.kra.committee.web.CommitteeScheduleAddSeleniumTest.java

/**
 * Test the never recurrence./*from ww  w  .  java 2 s.  co m*/
 * 
 * @throws Exception
 */
@Test
public void testCommitteeScheduleNeverRecurrance() throws Exception {
    helper.createCommittee();
    helper.clickCommitteeSchedulePage();

    Date scheduleStartDate = new Date();
    Date deadlineDate = DateUtils.addDays(scheduleStartDate, -1);

    helper.set(HELPER_SCHEDULE_START_DATE_ID, fullFormatter.format(scheduleStartDate));
    helper.set(HELPER_TIME_ID, TIME);
    helper.set(HELPER_PLACE_ID, PLACE);

    helper.click(ADD_EVENT_BUTTON);

    helper.assertNoPageErrors();

    helper.assertTableRowCount(TABLE_ID, 4);

    helper.assertElementContains(String.format(LIST_SCHEDULE_DATE_ID, 0),
            fullFormatter.format(scheduleStartDate));
    helper.assertTableCellValueContains(TABLE_ID, 2, 1, dayFormatter.format(scheduleStartDate).toUpperCase());
    helper.assertElementContains(String.format(LIST_PROTOCOL_SUB_DEADLINE_ID, 0),
            fullFormatter.format(deadlineDate));
}

From source file:org.kuali.kra.committee.web.CommitteeScheduleAddSeleniumTest.java

/**
 * Test the daily recurrence option for "every x day".
 * //  w  ww. j a  va  2 s . c  o  m
 * @throws Exception
 */
@Test
public void testCommitteeScheduleDailyRecurranceOptionEveryXDay() throws Exception {
    helper.createCommittee();
    helper.clickCommitteeSchedulePage();

    Date scheduleStartDate = new Date();
    Date scheduleEndDate = DateUtils.addDays(scheduleStartDate, 3);

    helper.set(HELPER_SCHEDULE_START_DATE_ID, fullFormatter.format(scheduleStartDate));
    helper.set(HELPER_TIME_ID, TIME);
    helper.set(HELPER_PLACE_ID, PLACE);
    helper.set(HELPER_RECURRENCE_TYPE_ID, RECURRENCE_TYPE_DAILY);
    helper.set(HELPER_DAILY_SCHEDULE_DAY_OPTION_ID, SCHEDULE_OPTION_XDAY);
    helper.set(HELPER_DAILY_SCHEDULE_SCHEDULE_END_DATE_ID, fullFormatter.format(scheduleEndDate));

    helper.click(ADD_EVENT_BUTTON);

    helper.assertNoPageErrors();

    Date firstScheduleDate = DateUtils.addDays(scheduleStartDate, 0);
    Date firstDeadlineDate = DateUtils.addDays(firstScheduleDate, -1);
    Date secondScheduleDate = DateUtils.addDays(scheduleStartDate, 1);
    Date secondDeadlineDate = DateUtils.addDays(secondScheduleDate, -1);
    Date thirdScheduleDate = DateUtils.addDays(scheduleStartDate, 2);
    Date thirdDeadlineDate = DateUtils.addDays(thirdScheduleDate, -1);
    Date fourthScheduleDate = DateUtils.addDays(scheduleStartDate, 3);
    Date fourthDeadlineDate = DateUtils.addDays(fourthScheduleDate, -1);

    helper.assertTableRowCount(TABLE_ID, 7);

    helper.assertElementContains(String.format(LIST_SCHEDULE_DATE_ID, 0),
            fullFormatter.format(firstScheduleDate));
    helper.assertTableCellValueContains(TABLE_ID, 2, 1, dayFormatter.format(firstScheduleDate).toUpperCase());
    helper.assertElementContains(String.format(LIST_PROTOCOL_SUB_DEADLINE_ID, 0),
            fullFormatter.format(firstDeadlineDate));

    helper.assertElementContains(String.format(LIST_SCHEDULE_DATE_ID, 1),
            fullFormatter.format(secondScheduleDate));
    helper.assertTableCellValueContains(TABLE_ID, 3, 1, dayFormatter.format(secondScheduleDate).toUpperCase());
    helper.assertElementContains(String.format(LIST_PROTOCOL_SUB_DEADLINE_ID, 1),
            fullFormatter.format(secondDeadlineDate));

    helper.assertElementContains(String.format(LIST_SCHEDULE_DATE_ID, 2),
            fullFormatter.format(thirdScheduleDate));
    helper.assertTableCellValueContains(TABLE_ID, 4, 1, dayFormatter.format(thirdScheduleDate).toUpperCase());
    helper.assertElementContains(String.format(LIST_PROTOCOL_SUB_DEADLINE_ID, 2),
            fullFormatter.format(thirdDeadlineDate));

    helper.assertElementContains(String.format(LIST_SCHEDULE_DATE_ID, 3),
            fullFormatter.format(fourthScheduleDate));
    helper.assertTableCellValueContains(TABLE_ID, 5, 1, dayFormatter.format(fourthScheduleDate).toUpperCase());
    helper.assertElementContains(String.format(LIST_PROTOCOL_SUB_DEADLINE_ID, 3),
            fullFormatter.format(fourthDeadlineDate));
}