List of usage examples for java.sql Date compareTo
public int compareTo(Date anotherDate)
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void processEdit(final HttpServletRequest req, final HttpServletResponse resp) { long recordId = Long.parseLong(req.getParameter("record-id")); long schemeId = Long.parseLong(req.getParameter("schemeId")); String userName = req.getParameter("user"); Date startDate = Date.valueOf(req.getParameter("start-date")); Date endDate = Date.valueOf(req.getParameter("end-date")); Date endDateExcluded = DateUtil.addDays(endDate, 1); Long userId = getUserId(userName); if (userId == null) { renderAlert("User does not exist", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;//from w w w .ja v a 2 s . c o m } if (startDate.compareTo(endDate) > 0) { renderAlert("Start date must not be after end date", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } Set<String> schemeNamesWithOverlappingTimeRange = getSchemeNamesWithOverlappingTimeRange(userId, startDate, endDateExcluded, recordId); if (!schemeNamesWithOverlappingTimeRange.isEmpty()) { renderAlert( "The user is assigned overlapping with the specified date range to the" + " following scheme(s): " + schemeNamesWithOverlappingTimeRange.toString(), "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } update(recordId, schemeId, userId, startDate, endDateExcluded); try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { renderAlertOnPrb("Updating user successful", "info", prb, resp.getLocale()); prb.replace("#scheme-user-table", render(req, resp.getLocale(), "scheme-user-table")); } }
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void processSave(final HttpServletRequest req, final HttpServletResponse resp) { long schemeId = Long.parseLong(req.getParameter("schemeId")); String userName = req.getParameter("user"); Date startDate = Date.valueOf(req.getParameter("start-date")); Date endDate = Date.valueOf(req.getParameter("end-date")); Date endDateExcluded = DateUtil.addDays(endDate, 1); Long userId = getUserId(userName); if (userId == null) { renderAlert("User does not exist", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;//from ww w . j a v a 2 s.c o m } if (startDate.compareTo(endDate) > 0) { renderAlert("Start date must not be after end date", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } Set<String> schemeNamesWithOverlappingTimeRange = getSchemeNamesWithOverlappingTimeRange(userId, startDate, endDateExcluded, null); if (!schemeNamesWithOverlappingTimeRange.isEmpty()) { renderAlert( "The user is assigned overlapping with the specified date range to the" + " following scheme(s): " + schemeNamesWithOverlappingTimeRange.toString(), "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } save(schemeId, userName, startDate, endDateExcluded); Long userCount = schemeUserCount(String.valueOf(schemeId)); try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { renderAlertOnPrb("Assiging user successful", "info", prb, resp.getLocale()); prb.replace("#scheme-user-table", render(req, resp.getLocale(), "scheme-user-table")); prb.replace("#delete-schema-validation-dialog", (writer) -> { DeleteSchemaValidationComponent.INSTANCE.render(writer, resp.getLocale(), userCount); }); } }
From source file:org.kuali.coeus.common.budget.impl.period.BudgetPeriodRule.java
private boolean isValidNewBudgetPeriod(Budget budget, BudgetPeriod newBudgetPeriod, String errorPathPrefix) { MessageMap errorMap = GlobalVariables.getMessageMap(); boolean validNewBudgetPeriod = true; List<BudgetPeriod> budgetPeriods = budget.getBudgetPeriods(); Date previousPeriodStartDate = null; Date previousPeriodEndDate = null; Date periodStartDate = null;/*from ww w . java 2 s. co m*/ Date periodEndDate = null; Date newPeriodStartDate = null; Date newPeriodEndDate = null; int index = 0; /* check new budget period */ newPeriodStartDate = newBudgetPeriod.getStartDate(); newPeriodEndDate = newBudgetPeriod.getEndDate(); errorMap.addToErrorPath(errorPathPrefix); if (newPeriodStartDate == null) { saveErrors("ERROR_PERIOD_START_REQUIRED", errorMap); validNewBudgetPeriod = false; } if (newPeriodEndDate == null) { saveErrors("ERROR_PERIOD_END_REQUIRED", errorMap); validNewBudgetPeriod = false; } errorMap.removeFromErrorPath(errorPathPrefix); if (CollectionUtils.isEmpty(budgetPeriods)) { newBudgetPeriod.setBudgetPeriod(1); } /* if dates are valid, check further where we can insert this new date */ if (validNewBudgetPeriod) { int totalBudgetPeriods = budgetPeriods.size() - 1; errorMap.addToErrorPath(errorPathPrefix); for (BudgetPeriod budgetPeriod : budgetPeriods) { Date validDateBefore; periodStartDate = budgetPeriod.getStartDate(); periodEndDate = budgetPeriod.getEndDate(); String dateCompareValue = null; /* check first record */ if (previousPeriodStartDate == null) { validDateBefore = budget.getStartDate(); } else { validDateBefore = previousPeriodEndDate; } /* check if entered new period already exists in budget periods list */ int periodNum = index; String[] newPeriodDateParams = { periodNum + "", periodNum + 1 + "" }; String invalidErrorMessage = null; if (index == 0 || index == totalBudgetPeriods) { invalidErrorMessage = "ERROR_NEW_PERIOD_INVALID"; } else { invalidErrorMessage = "ERROR_NEW_PERIOD_VALID"; } if ((newPeriodStartDate.compareTo(periodStartDate) == 0) || (newPeriodEndDate.compareTo(periodEndDate) == 0)) { saveErrors(invalidErrorMessage, errorMap, newPeriodDateParams); validNewBudgetPeriod = false; break; } else if (newPeriodStartDate.before(periodStartDate) || (index == totalBudgetPeriods && newPeriodStartDate.after(periodEndDate))) { /* check if new period start date is before current period start date */ boolean lastRecord = false; if (index == totalBudgetPeriods) { lastRecord = true; if (newPeriodStartDate.after(periodEndDate)) { periodNum = index + 1; } } /* check new budget period */ if (newPeriodStartDate.before(budget.getStartDate())) { dateCompareValue = "ERROR_PERIOD_START_BEFORE_PROJECT_START"; } else if (newPeriodStartDate.after(budget.getEndDate())) { dateCompareValue = "ERROR_NEW_PERIOD_START_AFTER_PROJECT_END"; } else if (newPeriodEndDate.after(budget.getEndDate())) { dateCompareValue = "ERROR_NEW_PERIOD_END_DATE"; } else if (newPeriodStartDate.before(validDateBefore)) { dateCompareValue = invalidErrorMessage; } else if ((index < totalBudgetPeriods) && newPeriodEndDate.after(periodStartDate)) { if (!lastRecord) { dateCompareValue = invalidErrorMessage; } else { dateCompareValue = "ERROR_NEW_PERIOD_PROJECT_END"; } } if (dateCompareValue != null) { saveErrors(dateCompareValue, errorMap, newPeriodDateParams); validNewBudgetPeriod = false; } else { newBudgetPeriod.setBudgetPeriod(periodNum + 1); } break; } else if (newPeriodStartDate.compareTo(periodEndDate) <= 0) { dateCompareValue = "ERROR_NEW_PERIOD_START_BEFORE_PREVIOUS_END"; saveErrors(dateCompareValue, errorMap, newPeriodDateParams); validNewBudgetPeriod = false; break; } previousPeriodStartDate = budgetPeriod.getStartDate(); previousPeriodEndDate = budgetPeriod.getEndDate(); index++; } errorMap.removeFromErrorPath(errorPathPrefix); } return validNewBudgetPeriod; }
From source file:org.kuali.coeus.common.budget.impl.rate.BudgetRatesServiceImpl.java
protected Date getRateEffectiveStartDate(Budget budget, AbstractInstituteRate rate, Date personEffectiveDate) { Date effectiveDate = budget.getStartDate(); if (rate.getRateClass().getRateClassTypeCode().equalsIgnoreCase(Constants.RATE_CLASS_TYPE_FOR_INFLATION) && personEffectiveDate != null && personEffectiveDate.compareTo(effectiveDate) < 0) { effectiveDate = personEffectiveDate; }//from www . jav a 2s .c o m return effectiveDate; }
From source file:org.kuali.coeus.common.budget.impl.summary.BudgetSummaryServiceImpl.java
@Override public List<BudgetPeriod> generateBudgetPeriods(Budget budget) { List<BudgetPeriod> budgetPeriods = new ArrayList<BudgetPeriod>(); Date projectStartDate = budget.getStartDate(); Date projectEndDate = budget.getEndDate(); boolean budgetPeriodExists = true; Calendar cl = Calendar.getInstance(); Date periodStartDate = projectStartDate; int budgetPeriodNum = 1; while (budgetPeriodExists) { cl.setTime(periodStartDate);/*from ww w. ja v a2s. co m*/ cl.add(Calendar.YEAR, 1); Date nextPeriodStartDate = new Date(cl.getTime().getTime()); cl.add(Calendar.DATE, -1); Date periodEndDate = new Date(cl.getTime().getTime()); /* check period end date gt project end date */ switch (periodEndDate.compareTo(projectEndDate)) { case 1: periodEndDate = projectEndDate; case 0: budgetPeriodExists = false; break; } BudgetPeriod budgetPeriod = budget.getNewBudgetPeriod(); budgetPeriod.setBudgetPeriod(budgetPeriodNum); budgetPeriod.setStartDate(periodStartDate); budgetPeriod.setEndDate(periodEndDate); budgetPeriod.setBudget(budget); budgetPeriods.add(budgetPeriod); periodStartDate = nextPeriodStartDate; budgetPeriodNum++; } return budgetPeriods; }
From source file:org.kuali.coeus.common.budget.impl.summary.BudgetSummaryServiceImpl.java
/** * //from w w w . j a v a 2 s . co m * This method is to be shared by adjusting dates for budgetperiod.lineitem and lineitem.personnellineitem * refer to jira-1376 for rules */ protected List<Date> getNewStartEndDates(Date parentStartDate, Date oldStartDate, Date parentEndDate, Date oldEndDate, List<Date> startEndDates) { Date startDate = startEndDates.get(0); Date endDate = startEndDates.get(1); Date newStartDate = startDate; Date newEndDate = endDate; if (startDate.compareTo(oldStartDate) == 0 && endDate.compareTo(oldEndDate) == 0) { // if initiall, both are matching, then keep matching. newStartDate = parentStartDate; newEndDate = parentEndDate; } else { // duration has priority over child start date relative to parent start date if (parentStartDate.compareTo(oldStartDate) != 0) { // keep the gap between child start date and parent start date newStartDate = add(newStartDate, getDateTimeService().dateDiff(oldStartDate, parentStartDate, false)); if (newStartDate.after(parentEndDate)) { newStartDate = parentStartDate; } else { if (newStartDate.after(parentStartDate)) { // keep the duration, but the item start date relative to period start date is not maintained. int parentDuration = getDateTimeService().dateDiff(parentStartDate, parentEndDate, false); int duration = getDateTimeService().dateDiff(startDate, endDate, false); int daysTOEndDate = getDateTimeService().dateDiff(newStartDate, parentEndDate, false); if (daysTOEndDate < duration) { if (parentDuration > duration) { newEndDate = parentEndDate; newStartDate = add(newEndDate, duration * (-1)); } else { // can't keep duration because parent duration is smaller than child initial duration newStartDate = parentStartDate; } } } } newEndDate = add(newStartDate, getDateTimeService().dateDiff(startDate, endDate, false)); if (newEndDate.after(parentEndDate)) { newEndDate = parentEndDate; } } else { // end date changed if (parentEndDate.compareTo(oldStartDate) != 0 && parentEndDate.before(endDate)) { if (parentEndDate.after(startDate) && parentEndDate.before(endDate)) { newEndDate = parentEndDate; // try to keep duration newStartDate = add(newEndDate, getDateTimeService().dateDiff(endDate, startDate, false)); if (newStartDate.before(parentStartDate)) { newStartDate = parentStartDate; } } else { if (parentEndDate.before(startDate)) { newStartDate = parentStartDate; newEndDate = add(newStartDate, getDateTimeService().dateDiff(startDate, endDate, false)); if (newEndDate.after(parentEndDate)) { newEndDate = parentEndDate; } } } } } } startEndDates.clear(); startEndDates.add(0, newStartDate); startEndDates.add(1, newEndDate); return startEndDates; }
From source file:org.kuali.coeus.common.budget.impl.summary.BudgetSummaryServiceImpl.java
@Override public boolean isLeapDaysInPeriod(Date sDate, Date eDate) { Date leapDate;//from www . j a v a 2 s . c om int sYear = getYear(sDate); int eYear = getYear(eDate); if (isLeapYear(sDate)) { Calendar c1 = Calendar.getInstance(); c1.clear(); c1.set(sYear, 1, 29); leapDate = new java.sql.Date(c1.getTime().getTime()); // start date is before 2/29 & enddate >= 2/29 if (sDate.before(leapDate)) { if (eDate.compareTo(leapDate) >= 0) { return true; } } else if (sDate.equals(leapDate)) { return true; } } else if (isLeapYear(eDate)) { Calendar c1 = Calendar.getInstance(); c1.set(eYear, 1, 29); leapDate = new java.sql.Date(c1.getTime().getTime()); if (eDate.compareTo(leapDate) >= 0) { return true; } } else { sYear++; while (eYear > sYear) { if (isLeapYear(sYear)) { return true; } sYear++; } } return false; }
From source file:org.kuali.coeus.propdev.impl.budget.hierarchy.ProposalBudgetHierarchyServiceImpl.java
protected int getCorrespondingParentPeriod(List<BudgetPeriod> oldBudgetPeriods, Budget childBudget) { int correspondingStart = -1; // using start date of first period as start date and end date of last period // as end because budget start and end are not particularly reliable Date childStart = childBudget.getBudgetPeriod(0).getStartDate(); Date parentStart = oldBudgetPeriods.get(0).getStartDate(); Date parentEnd = oldBudgetPeriods.get(oldBudgetPeriods.size() - 1).getEndDate(); // check that child budget starts somewhere during parent budget if (childStart.compareTo(parentStart) >= 0 && childStart.compareTo(parentEnd) < 0) { // check that child budget starts on one of the budget period starts List<BudgetPeriod> parentPeriods = oldBudgetPeriods; for (int i = 0; i < parentPeriods.size(); i++) { if (childStart.equals(parentPeriods.get(i).getStartDate())) { correspondingStart = i;/* w ww.j ava 2 s. com*/ break; } } } return correspondingStart; }
From source file:org.kuali.kfs.module.endow.document.KEMIDMaintainableImpl.java
/** * Prepares the payout instructions tab for display. * /* w ww . jav a 2 s . c o m*/ * @param document * @param section * @param field * * KRAD Conversion: MaintainableImpl performs customization of the fields in the rows of the sections. */ private void preparePayoutInstructionsTab(MaintenanceDocument document, Section section) { KEMService kemService = SpringContext.getBean(KEMService.class); DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); for (Row row : section.getRows()) { for (Field field : row.getFields()) { if (field.getCONTAINER().equalsIgnoreCase(field.getFieldType())) { for (Row containerRow : field.getContainerRows()) { for (Field containerRowfield : containerRow.getFields()) { // the payout start date is no longer editable if the payout start date is less than the // current process // or // system date String indexedPropertyNamePrefix = EndowPropertyConstants.KEMID_PAY_INSTRUCTIONS_TAB + "\\[\\d+\\]\\" + "."; String indexedStartDate = indexedPropertyNamePrefix + EndowPropertyConstants.KEMID_PAY_INC_START_DATE; if (containerRowfield.getPropertyName().matches(indexedStartDate)) { String payoutStartDateString = containerRowfield.getPropertyValue(); if (payoutStartDateString != null && !KFSConstants.EMPTY_STRING.equalsIgnoreCase(payoutStartDateString)) { String currentProcessDateString = kemService.getCurrentSystemProcessDate(); try { Date currentProcessDate = dateTimeService .convertToSqlDate(currentProcessDateString); Date payoutStartDate = dateTimeService .convertToSqlDate(payoutStartDateString); if (payoutStartDate.compareTo(currentProcessDate) < 0) { containerRowfield.setReadOnly(true); } } catch (ParseException ex) { // do nothing } } } // a record is no longer editable if the payout termination date is less than the current // process or // system // date String indexedEndDate = indexedPropertyNamePrefix + EndowPropertyConstants.KEMID_PAY_INC_END_DATE; if (containerRowfield.getPropertyName().matches(indexedEndDate)) { String payoutEndDateString = containerRowfield.getPropertyValue(); if (payoutEndDateString != null && !KFSConstants.EMPTY_STRING.equalsIgnoreCase(payoutEndDateString)) { String currentProcessDateString = kemService.getCurrentSystemProcessDate(); try { Date currentProcessDate = dateTimeService .convertToSqlDate(currentProcessDateString); Date payoutEndDate = dateTimeService.convertToSqlDate(payoutEndDateString); if (payoutEndDate.compareTo(currentProcessDate) < 0) { containerRow.setHidden(true); } } catch (ParseException ex) { // do nothing } } } } } } } } }
From source file:org.kuali.kfs.module.endow.document.KEMIDMaintainableImpl.java
/** * Prepares the special instructions tab. * // www . ja va2s . c o m * @param document * @param section * @param field */ private void prepareSpecialInstructionsTab(MaintenanceDocument document, Section section) { KEMService kemService = SpringContext.getBean(KEMService.class); DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); for (Row row : section.getRows()) { for (Field field : row.getFields()) { if (field.getCONTAINER().equalsIgnoreCase(field.getFieldType())) { for (Row containerRow : field.getContainerRows()) { for (Field containerRowfield : containerRow.getFields()) { // a record is no longer editable if the instruction end date is less than the current // process or // system // date String specialInstructionEndDateField = KFSConstants.ADD_PREFIX + "." + EndowPropertyConstants.KEMID_SPECIAL_INSTRUCTIONS_TAB + "." + EndowPropertyConstants.KEMID_SPEC_INSTR_END_DATE; if (specialInstructionEndDateField.equalsIgnoreCase(specialInstructionEndDateField)) { String instructionEndDateString = containerRowfield.getPropertyValue(); if (instructionEndDateString != null && !KFSConstants.EMPTY_STRING.equalsIgnoreCase(instructionEndDateString)) { String currentProcessDateString = kemService.getCurrentSystemProcessDate(); try { Date currentProcessDate = dateTimeService .convertToSqlDate(currentProcessDateString); Date specialInstructionEndDate = dateTimeService .convertToSqlDate(instructionEndDateString); if (specialInstructionEndDate.compareTo(currentProcessDate) < 0) { for (Field rowfield : row.getFields()) { rowfield.setReadOnly(true); } } } catch (ParseException ex) { // do nothing } } } } } } } } }