List of usage examples for org.joda.time Interval contains
public boolean contains(long millisInstant)
From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarAction.java
License:Educational Community License
protected void setMessages(LeaveCalendarForm leaveCalendarForm, List<LeaveBlock> leaveBlocks) { String principalId = HrContext.getTargetPrincipalId(); CalendarEntry calendarEntry = leaveCalendarForm.getCalendarEntry(); PrincipalHRAttributes principalHRAttributes = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(principalId, calendarEntry.getEndPeriodFullDateTime().toLocalDate()); Map<String, Set<String>> allMessages = LeaveCalendarValidationUtil .getWarningMessagesForLeaveBlocks(leaveBlocks); // add warning message for accrual categories that have exceeded max balance. // Could set a flag on the transferable rows here so that LeaveCalendarSubmit.do knows // which row(s) to transfer when user submits the calendar for approval. List<BalanceTransfer> losses = new ArrayList<BalanceTransfer>(); Interval calendarInterval = new Interval(calendarEntry.getBeginPeriodDate().getTime(), calendarEntry.getEndPeriodDate().getTime()); Map<String, Set<LeaveBlock>> maxBalInfractions = new HashMap<String, Set<LeaveBlock>>(); Date effectiveDate = LocalDate.now().toDate(); if (!calendarInterval.contains(effectiveDate.getTime())) { effectiveDate = calendarEntry.getEndPeriodDate(); }/* w ww . jav a 2 s . co m*/ if (principalHRAttributes != null) { maxBalInfractions = LmServiceLocator.getAccrualCategoryMaxBalanceService() .getMaxBalanceViolations(calendarEntry, principalId); LeaveSummary summary = leaveCalendarForm.getLeaveSummary(); for (Entry<String, Set<LeaveBlock>> entry : maxBalInfractions.entrySet()) { for (LeaveBlock lb : entry.getValue()) { AccrualCategory accrualCat = HrServiceLocator.getAccrualCategoryService() .getAccrualCategory(lb.getAccrualCategory(), lb.getLeaveLocalDate()); AccrualCategoryRule aRule = HrServiceLocator.getAccrualCategoryRuleService() .getAccrualCategoryRule(lb.getAccrualCategoryRuleId()); if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.LOSE)) { DateTime aDate = null; if (StringUtils.equals(aRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.YEAR_END)) { aDate = HrServiceLocator.getLeavePlanService().getRolloverDayOfLeavePlan( principalHRAttributes.getLeavePlan(), lb.getLeaveLocalDate()); } else { Calendar cal = HrServiceLocator.getCalendarService().getCalendarByPrincipalIdAndDate( principalId, new LocalDate(lb.getLeaveDate()), true); CalendarEntry leaveEntry = HrServiceLocator.getCalendarEntryService() .getCurrentCalendarEntryByCalendarId(cal.getHrCalendarId(), new DateTime(lb.getLeaveDate())); aDate = new DateTime(leaveEntry.getEndPeriodDate()); } aDate = aDate.minusDays(1); if (calendarInterval.contains(aDate.getMillis()) && aDate.toDate().compareTo(calendarEntry.getEndPeriodDate()) <= 0) { //may want to calculate summary for all rows, displayable or not, and determine displayability via tags. AccrualCategory accrualCategory = HrServiceLocator.getAccrualCategoryService() .getAccrualCategory(aRule.getLmAccrualCategoryId()); BigDecimal accruedBalance = LmServiceLocator.getAccrualService() .getAccruedBalanceForPrincipal(principalId, accrualCategory, lb.getLeaveLocalDate()); BalanceTransfer loseTransfer = LmServiceLocator.getBalanceTransferService() .initializeTransfer(principalId, lb.getAccrualCategoryRuleId(), accruedBalance, lb.getLeaveLocalDate()); boolean valid = BalanceTransferValidationUtils.validateTransfer(loseTransfer); if (valid) { losses.add(loseTransfer); } } } else if (StringUtils.equals(HrConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND, aRule.getMaxBalanceActionFrequency())) { if (calendarInterval.contains(lb.getLeaveDate().getTime())) { // accrual categories within the leave plan that are hidden from the leave summary will not appear. List<LeaveSummaryRow> summaryRows = summary.getLeaveSummaryRows(); List<LeaveSummaryRow> updatedSummaryRows = new ArrayList<LeaveSummaryRow>( summaryRows.size()); //AccrualCategoryRule currentRule = HrServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRuleForDate(accrualCat, effectiveDate, principalCalendar.getServiceDate()); for (LeaveSummaryRow summaryRow : summaryRows) { if (StringUtils.equals(summaryRow.getAccrualCategory(), accrualCat.getAccrualCategory())) { if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.PAYOUT)) { summaryRow.setPayoutable(true); } else { if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.TRANSFER)) { summaryRow.setTransferable(true); } } summaryRow.setInfractingLeaveBlockId(lb.getLmLeaveBlockId()); } updatedSummaryRows.add(summaryRow); } summary.setLeaveSummaryRows(updatedSummaryRows); } } if (calendarInterval.contains(lb.getLeaveDate().getTime())) { // accrual categories within the leave plan that are hidden from the leave summary WILL appear. String message = "You have exceeded the maximum balance limit for '" + accrualCat.getAccrualCategory() + "' as of " + lb.getLeaveDate() + ". " + "Depending upon the accrual category rules, leave over this limit may be forfeited."; // leave blocks are sorted in getMaxBalanceViolations() method, so we just take the one with the earliest leave date for an accrual category. if (!StringUtils.contains(allMessages.get("warningMessages").toString(), "You have exceeded the maximum balance limit for '" + accrualCat.getAccrualCategory())) { allMessages.get("warningMessages").add(message); } } } } leaveCalendarForm.setLeaveSummary(summary); } leaveCalendarForm.setForfeitures(losses); Map<String, Set<String>> transactionalMessages = LeaveCalendarValidationUtil.validatePendingTransactions( principalId, calendarEntry.getBeginPeriodFullDateTime().toLocalDate(), calendarEntry.getEndPeriodFullDateTime().toLocalDate()); allMessages.get("infoMessages").addAll(transactionalMessages.get("infoMessages")); allMessages.get("warningMessages").addAll(transactionalMessages.get("warningMessages")); allMessages.get("actionMessages").addAll(transactionalMessages.get("actionMessages")); // add warning messages based on max carry over balances for each accrual category if (principalHRAttributes != null) { List<AccrualCategory> accrualCategories = HrServiceLocator.getAccrualCategoryService() .getActiveLeaveAccrualCategoriesForLeavePlan(principalHRAttributes.getLeavePlan(), calendarEntry.getEndPeriodFullDateTime().toLocalDate()); for (AccrualCategory accrualCategory : accrualCategories) { if (LmServiceLocator.getAccrualCategoryMaxCarryOverService().exceedsAccrualCategoryMaxCarryOver( accrualCategory.getAccrualCategory(), principalId, calendarEntry, calendarEntry.getEndPeriodFullDateTime().toLocalDate())) { String message = "Your pending leave balance is greater than the annual max carry over for accrual category '" + accrualCategory.getAccrualCategory() + "' and upon approval, the excess balance will be lost."; if (!allMessages.get("warningMessages").contains(message)) { allMessages.get("warningMessages").add(message); } } } // KPME-1279 check for Absent Earn code to add warning. List<EarnCode> earnCodes = HrServiceLocator.getEarnCodeService().getEarnCodesForPrincipal(principalId, calendarEntry.getEndPeriodFullDateTime().toLocalDate(), true); if (earnCodes != null && !earnCodes.isEmpty()) { for (EarnCode earnCodeObj : earnCodes) { if (earnCodeObj != null) { if ("Y".equalsIgnoreCase(earnCodeObj.getAffectPay()) && "N".equalsIgnoreCase(earnCodeObj.getEligibleForAccrual())) { String message = "Absent time cannot be used until other accrual balances are zero or below a specified accrual balance."; if (!allMessages.get("warningMessages").contains(message)) { allMessages.get("warningMessages").add(message); break; } } } } } } leaveCalendarForm.setWarningMessages(new ArrayList<String>(allMessages.get("warningMessages"))); leaveCalendarForm.setInfoMessages(new ArrayList<String>(allMessages.get("infoMessages"))); leaveCalendarForm.setActionMessages(new ArrayList<String>(allMessages.get("actionMessages"))); }
From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarSubmitAction.java
License:Educational Community License
public ActionForward approveLeaveCalendar(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String documentId = request.getParameter("documentId"); String action = request.getParameter("action"); LeaveCalendarDocument document = LmServiceLocator.getLeaveCalendarService() .getLeaveCalendarDocument(documentId); // Switched to grab the target (chain, resolution: target -> backdoor -> actual) user. // Approvals still using backdoor > actual if (StringUtils.equals(action, HrConstants.DOCUMENT_ACTIONS.ROUTE)) { if (DocumentStatus.INITIATED.getCode().equals(document.getDocumentHeader().getDocumentStatus()) || DocumentStatus.SAVED.getCode().equals(document.getDocumentHeader().getDocumentStatus())) { Map<String, Set<LeaveBlock>> eligibilities = LmServiceLocator.getAccrualCategoryMaxBalanceService() .getMaxBalanceViolations(document.getCalendarEntry(), document.getPrincipalId()); ActionRedirect transferRedirect = new ActionRedirect(); ActionRedirect payoutRedirect = new ActionRedirect(); List<LeaveBlock> eligibleTransfers = new ArrayList<LeaveBlock>(); List<LeaveBlock> eligiblePayouts = new ArrayList<LeaveBlock>(); Interval interval = new Interval(document.getCalendarEntry().getBeginPeriodDate().getTime(), document.getCalendarEntry().getEndPeriodDate().getTime()); for (Entry<String, Set<LeaveBlock>> entry : eligibilities.entrySet()) { for (LeaveBlock lb : entry.getValue()) { if (interval.contains(lb.getLeaveDate().getTime())) { //maxBalanceViolations should, if a violation exists, return a leave block with leave date either current date, or the end period date - 1 days. PrincipalHRAttributes pha = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(document.getPrincipalId(), lb.getLeaveLocalDate()); AccrualCategoryRule aRule = HrServiceLocator.getAccrualCategoryRuleService() .getAccrualCategoryRule(lb.getAccrualCategoryRuleId()); if (ObjectUtils.isNotNull(aRule) && !StringUtils.equals(aRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND)) { if (StringUtils.equals(aRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE) || (StringUtils.equals(aRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.YEAR_END) && HrServiceLocator.getLeavePlanService() .isLastCalendarPeriodOfLeavePlan( document.getCalendarEntry(), pha.getLeavePlan(), lb.getLeaveLocalDate()))) if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.PAYOUT)) { eligiblePayouts.add(lb); } else if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.TRANSFER) || StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.LOSE)) { eligibleTransfers.add(lb); }// ww w . j a va 2s. co m } } } } if (!eligibleTransfers.isEmpty()) { transferRedirect.setPath("/BalanceTransfer.do?" + request.getQueryString()); request.getSession().setAttribute("eligibilities", eligibleTransfers); return transferRedirect; } if (!eligiblePayouts.isEmpty()) { payoutRedirect.setPath("/LeavePayout.do?" + request.getQueryString()); request.getSession().setAttribute("eligibilities", eligiblePayouts); return payoutRedirect; } LmServiceLocator.getLeaveCalendarService().routeLeaveCalendar(HrContext.getTargetPrincipalId(), document); } } else if (StringUtils.equals(action, HrConstants.DOCUMENT_ACTIONS.APPROVE)) { if (LmServiceLocator.getLeaveCalendarService().isReadyToApprove(document)) { if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) { LmServiceLocator.getLeaveCalendarService().approveLeaveCalendar(HrContext.getPrincipalId(), document); } } else { //ERROR!!!! } } else if (StringUtils.equals(action, HrConstants.DOCUMENT_ACTIONS.DISAPPROVE)) { if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) { LmServiceLocator.getLeaveCalendarService().disapproveLeaveCalendar(HrContext.getPrincipalId(), document); } } ActionRedirect rd = new ActionRedirect(mapping.findForward("leaveCalendarRedirect")); TkServiceLocator.getTkSearchableAttributeService().updateSearchableAttribute(document, document.getAsOfDate()); rd.addParameter("documentId", documentId); return rd; }
From source file:org.kuali.kpme.tklm.time.detail.web.TimeDetailAction.java
License:Educational Community License
protected void setMessages(TimeDetailActionForm timeDetailActionForm) { String principalId = HrContext.getTargetPrincipalId(); TimesheetDocument timesheetDocument = timeDetailActionForm.getTimesheetDocument(); CalendarEntry calendarEntry = timeDetailActionForm.getCalendarEntry(); List<LeaveBlock> balanceTransferLeaveBlocks = LmServiceLocator.getLeaveBlockService() .getLeaveBlocksWithType(timesheetDocument.getPrincipalId(), calendarEntry.getBeginPeriodFullDateTime().toLocalDate(), calendarEntry.getEndPeriodFullDateTime().toLocalDate(), LMConstants.LEAVE_BLOCK_TYPE.BALANCE_TRANSFER); Map<String, Set<String>> allMessages = LeaveCalendarValidationUtil .getWarningMessagesForLeaveBlocks(balanceTransferLeaveBlocks); // add warning messages based on max carry over balances for each accrual category for non-exempt leave users List<BalanceTransfer> losses = new ArrayList<BalanceTransfer>(); if (LmServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(principalId, HrConstants.FLSA_STATUS_NON_EXEMPT, true)) { PrincipalHRAttributes principalCalendar = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(principalId, calendarEntry.getEndPeriodFullDateTime().toLocalDate()); Interval calendarInterval = new Interval(calendarEntry.getBeginPeriodDate().getTime(), calendarEntry.getEndPeriodDate().getTime()); Map<String, Set<LeaveBlock>> maxBalInfractions = new HashMap<String, Set<LeaveBlock>>(); if (principalCalendar != null) { maxBalInfractions = LmServiceLocator.getAccrualCategoryMaxBalanceService() .getMaxBalanceViolations(calendarEntry, principalId); for (Entry<String, Set<LeaveBlock>> entry : maxBalInfractions.entrySet()) { for (LeaveBlock lb : entry.getValue()) { if (calendarInterval.contains(lb.getLeaveDate().getTime())) { AccrualCategory accrualCat = HrServiceLocator.getAccrualCategoryService() .getAccrualCategory(lb.getAccrualCategory(), lb.getLeaveLocalDate()); AccrualCategoryRule aRule = HrServiceLocator.getAccrualCategoryRuleService() .getAccrualCategoryRule(lb.getAccrualCategoryRuleId()); if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.LOSE)) { DateTime aDate = null; if (StringUtils.equals(aRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.YEAR_END)) { aDate = HrServiceLocator.getLeavePlanService().getRolloverDayOfLeavePlan( principalCalendar.getLeavePlan(), lb.getLeaveLocalDate()); } else { Calendar cal = HrServiceLocator.getCalendarService() .getCalendarByPrincipalIdAndDate(principalId, new LocalDate(lb.getLeaveDate()), true); CalendarEntry leaveEntry = HrServiceLocator.getCalendarEntryService() .getCurrentCalendarEntryByCalendarId(cal.getHrCalendarId(), new DateTime(lb.getLeaveDate())); aDate = new DateTime(leaveEntry.getEndPeriodDate()); }//from ww w .ja va 2s. c om aDate = aDate.minusDays(1); if (calendarInterval.contains(aDate.getMillis()) && aDate.toDate().compareTo(calendarEntry.getEndPeriodDate()) <= 0) { //may want to calculate summary for all rows, displayable or not, and determine displayability via tags. AccrualCategory accrualCategory = HrServiceLocator.getAccrualCategoryService() .getAccrualCategory(aRule.getLmAccrualCategoryId()); BigDecimal accruedBalance = LmServiceLocator.getAccrualService() .getAccruedBalanceForPrincipal(principalId, accrualCategory, lb.getLeaveLocalDate()); BalanceTransfer loseTransfer = LmServiceLocator.getBalanceTransferService() .initializeTransfer(principalId, lb.getAccrualCategoryRuleId(), accruedBalance, lb.getLeaveLocalDate()); boolean valid = BalanceTransferValidationUtils.validateTransfer(loseTransfer); if (valid) { losses.add(loseTransfer); } } } // accrual categories within the leave plan that are hidden from the leave summary WILL appear. String message = "You have exceeded the maximum balance limit for '" + accrualCat.getAccrualCategory() + "' as of " + lb.getLeaveDate() + ". " + "Depending upon the accrual category rules, leave over this limit may be forfeited."; // leave blocks are sorted in getMaxBalanceViolations() method, so we just take the one with the earliest leave date for an accrual category. if (!StringUtils.contains(allMessages.get("warningMessages").toString(), "You have exceeded the maximum balance limit for '" + accrualCat.getAccrualCategory())) { allMessages.get("warningMessages").add(message); } } } } } timeDetailActionForm.setForfeitures(losses); Map<String, Set<String>> transactionalMessages = LeaveCalendarValidationUtil .validatePendingTransactions(HrContext.getTargetPrincipalId(), calendarEntry.getBeginPeriodFullDateTime().toLocalDate(), calendarEntry.getEndPeriodFullDateTime().toLocalDate()); allMessages.get("infoMessages").addAll(transactionalMessages.get("infoMessages")); allMessages.get("warningMessages").addAll(transactionalMessages.get("warningMessages")); allMessages.get("actionMessages").addAll(transactionalMessages.get("actionMessages")); if (principalCalendar != null) { Calendar calendar = HrServiceLocator.getCalendarService().getCalendarByPrincipalIdAndDate( principalId, calendarEntry.getEndPeriodFullDateTime().toLocalDate(), true); if (calendar != null) { List<CalendarEntry> leaveCalendarEntries = HrServiceLocator.getCalendarEntryService() .getCalendarEntriesEndingBetweenBeginAndEndDate(calendar.getHrCalendarId(), calendarEntry.getBeginPeriodFullDateTime(), calendarEntry.getEndPeriodFullDateTime()); List<AccrualCategory> accrualCategories = HrServiceLocator.getAccrualCategoryService() .getActiveLeaveAccrualCategoriesForLeavePlan(principalCalendar.getLeavePlan(), calendarEntry.getEndPeriodFullDateTime().toLocalDate()); for (AccrualCategory accrualCategory : accrualCategories) { if (LmServiceLocator.getAccrualCategoryMaxCarryOverService() .exceedsAccrualCategoryMaxCarryOver(accrualCategory.getAccrualCategory(), principalId, leaveCalendarEntries, calendarEntry.getEndPeriodFullDateTime().toLocalDate())) { String message = "Your pending leave balance is greater than the annual max carry over for accrual category '" + accrualCategory.getAccrualCategory() + "' and upon approval, the excess balance will be lost."; if (!allMessages.get("warningMessages").contains(message)) { allMessages.get("warningMessages").add(message); } } } } } } List<String> infoMessages = timeDetailActionForm.getInfoMessages(); infoMessages.addAll(allMessages.get("infoMessages")); List<String> warningMessages = timeDetailActionForm.getWarningMessages(); warningMessages.addAll(allMessages.get("warningMessages")); List<String> actionMessages = timeDetailActionForm.getActionMessages(); actionMessages.addAll(allMessages.get("actionMessages")); timeDetailActionForm.setInfoMessages(infoMessages); timeDetailActionForm.setWarningMessages(warningMessages); timeDetailActionForm.setActionMessages(actionMessages); }
From source file:org.kuali.kpme.tklm.time.missedpunch.MissedPunchAssignmentKeyValuesFinder.java
License:Educational Community License
@Override public List<KeyValue> getKeyValues(ViewModel model) { List<KeyValue> labels = new ArrayList<KeyValue>(); if (model instanceof MissedPunchForm) { MissedPunchForm missedPunchForm = (MissedPunchForm) model; MissedPunchDocument missedPunchDocument = (MissedPunchDocument) missedPunchForm.getDocument(); MissedPunchBo mp = missedPunchDocument == null ? missedPunchForm.getMissedPunch() : missedPunchDocument.getMissedPunch(); LocalDate mpDate = mp.getLocalDate(); if (mpDate == null) { mpDate = mp.getActionLocalDate(); if (mpDate == null) { mpDate = LocalDate.now(); }/* w w w .j a va2s.c om*/ } String timesheetDocumentId = missedPunchDocument != null ? missedPunchDocument.getMissedPunch().getTimesheetDocumentId() : missedPunchForm.getMissedPunch().getTimesheetDocumentId(); if (StringUtils.isNotBlank(timesheetDocumentId)) { TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService() .getTimesheetDocument(timesheetDocumentId); Map<LocalDate, List<Assignment>> assignmentMap = timesheetDocument.getAssignmentMap(); List<Assignment> assignments = assignmentMap.get(mpDate); Interval calEntryInterval = new Interval( timesheetDocument.getCalendarEntry().getBeginPeriodFullDateTime(), timesheetDocument.getCalendarEntry().getEndPeriodFullDateTime()); if (CollectionUtils.isEmpty(assignments) && !calEntryInterval.contains(mpDate.toDateTimeAtStartOfDay())) { assignments = KpmeUtils.getUniqueAssignments(HrServiceLocator.getAssignmentService() .getAssignmentHistoryBetweenDays(timesheetDocument.getPrincipalId(), mpDate, mpDate)); } if (CollectionUtils.isEmpty(assignments)) { assignments = Collections.emptyList(); } // if (assignments.size() > 1) { // labels.add(new ConcreteKeyValue("", "")); // } if (missedPunchForm.getIpAddress() != null) { String ipAddress = TKUtils.getIPAddressFromRequest(missedPunchForm.getIpAddress()); //Map<String, String> assignmentDescMap = timesheetDocument.getAssignmentDescriptions(true, mpDate); String targetPrincipalId = HrContext.getTargetPrincipalId(); String principalId = HrContext.getPrincipalId(); if (targetPrincipalId.equals(principalId)) { DateTime currentDateTime = new DateTime(); for (Assignment assignment : assignments) { //Assignment assignment = timesheetDocument.getAssignment(AssignmentDescriptionKey.get(entry.getKey()), LocalDate.now()); String allowActionFromInvalidLocation = ConfigContext.getCurrentContextConfig() .getProperty(LMConstants.ALLOW_CLOCKINGEMPLOYYE_FROM_INVALIDLOCATION); if (StringUtils.equals(allowActionFromInvalidLocation, "false")) { boolean isInvalid = TkServiceLocator.getClockLocationRuleService() .isInvalidIPClockLocation(assignment.getGroupKeyCode(), assignment.getDept(), assignment.getWorkArea(), assignment.getPrincipalId(), assignment.getJobNumber(), ipAddress, currentDateTime.toLocalDate()); if (!isInvalid) { labels.add(new ConcreteKeyValue(assignment.getAssignmentKey(), assignment.getAssignmentDescription())); } } } } else { for (Assignment assignment : assignments) { labels.add(new ConcreteKeyValue(assignment.getAssignmentKey(), assignment.getAssignmentDescription())); } } } else { if (CollectionUtils.isNotEmpty(assignments)) { for (Assignment assignment : assignments) { labels.add(new ConcreteKeyValue(assignment.getAssignmentKey(), assignment.getAssignmentDescription())); } } } } } if (labels.size() > 1) { List<KeyValue> newLables = new ArrayList<KeyValue>(); newLables.add(new ConcreteKeyValue("", "")); newLables.addAll(labels); labels = newLables; } if (labels.size() == 0) { labels.add(new ConcreteKeyValue("", "--- No asssignments for date ---")); } return labels; }
From source file:org.kuali.kpme.tklm.time.timeblock.service.TimeBlockServiceImpl.java
License:Educational Community License
public List<TimeBlock> buildTimeBlocksSpanDates(Assignment assignment, String earnCode, TimesheetDocument timesheetDocument, DateTime beginDateTime, DateTime endDateTime, BigDecimal hours, BigDecimal amount, Boolean getClockLogCreated, Boolean getLunchDeleted, String spanningWeeks, String userPrincipalId) { DateTimeZone zone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); DateTime beginDt = beginDateTime.withZone(zone); DateTime endDt = beginDt.toLocalDate().toDateTime(endDateTime.withZone(zone).toLocalTime(), zone); if (endDt.isBefore(beginDt)) endDt = endDt.plusDays(1);//from w w w . jav a2s . c o m List<Interval> dayInt = TKUtils.getDaySpanForCalendarEntry(timesheetDocument.getCalendarEntry()); TimeBlock firstTimeBlock = new TimeBlock(); List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>(); DateTime endOfFirstDay = null; // KPME-2568 long diffInMillis = 0; // KPME-2568 for (Interval dayIn : dayInt) { if (dayIn.contains(beginDt)) { if (dayIn.contains(endDt) || dayIn.getEnd().equals(endDt)) { // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list if (StringUtils.isEmpty(spanningWeeks) && (dayIn.getStart().getDayOfWeek() == DateTimeConstants.SATURDAY || dayIn.getStart().getDayOfWeek() == DateTimeConstants.SUNDAY)) { // Get difference in millis for the next time block - KPME-2568 endOfFirstDay = endDt.withZone(zone); diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis(); } else { firstTimeBlock = createTimeBlock(timesheetDocument, beginDateTime, endDt, assignment, earnCode, hours, amount, false, getLunchDeleted, userPrincipalId); lstTimeBlocks.add(firstTimeBlock); } } else { //TODO move this to prerule validation //throw validation error if this case met error } } } DateTime endTime = endDateTime.withZone(zone); if (firstTimeBlock.getEndDateTime() != null) { // KPME-2568 endOfFirstDay = firstTimeBlock.getEndDateTime().withZone(zone); diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis(); } DateTime currTime = beginDt.plusDays(1); while (currTime.isBefore(endTime) || currTime.isEqual(endTime)) { // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list if (StringUtils.isEmpty(spanningWeeks) && (currTime.getDayOfWeek() == DateTimeConstants.SATURDAY || currTime.getDayOfWeek() == DateTimeConstants.SUNDAY)) { // do nothing } else { TimeBlock tb = createTimeBlock(timesheetDocument, currTime, currTime.plus(diffInMillis), assignment, earnCode, hours, amount, false, getLunchDeleted, userPrincipalId); lstTimeBlocks.add(tb); } currTime = currTime.plusDays(1); } return lstTimeBlocks; }
From source file:org.kuali.kpme.tklm.time.timeblock.service.TimeBlockServiceImpl.java
License:Educational Community License
public List<TimeBlock> buildTimeBlocks(Assignment assignment, String earnCode, TimesheetDocument timesheetDocument, DateTime beginDateTime, DateTime endDateTime, BigDecimal hours, BigDecimal amount, Boolean getClockLogCreated, Boolean getLunchDeleted, String userPrincipalId) { //Create 1 or many timeblocks if the span of timeblocks exceed more than one //day that is determined by pay period day(24 hrs + period begin date) Interval firstDay = null;//from w w w . j a va2 s . co m List<Interval> dayIntervals = TKUtils.getDaySpanForCalendarEntry(timesheetDocument.getCalendarEntry()); List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>(); DateTime currentDateTime = beginDateTime; for (Interval dayInt : dayIntervals) { // the time period spans more than one day if (firstDay != null) { if (!dayInt.contains(endDateTime)) { currentDateTime = dayInt.getStart(); } else if ((dayInt.getStartMillis() - endDateTime.getMillis()) != 0) { TimeBlock tb = createTimeBlock(timesheetDocument, dayInt.getStart(), endDateTime, assignment, earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId); lstTimeBlocks.add(tb); break; } } if (dayInt.contains(currentDateTime)) { firstDay = dayInt; // KPME-361 // added a condition to handle the time block which ends at 12a, e.g. a 10p-12a timeblock // this is the same fix as TkTimeBlockAggregate if (dayInt.contains(endDateTime) || (endDateTime.getMillis() == dayInt.getEnd().getMillis())) { //create one timeblock if contained in one day interval TimeBlock tb = createTimeBlock(timesheetDocument, currentDateTime, endDateTime, assignment, earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId); tb.setBeginDateTime(currentDateTime); tb.setEndDateTime(endDateTime); lstTimeBlocks.add(tb); break; } else { // create a timeblock that wraps the 24 hr day TimeBlock tb = createTimeBlock(timesheetDocument, currentDateTime, dayInt.getEnd(), assignment, earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId); tb.setBeginDateTime(currentDateTime); tb.setEndDateTime(firstDay.getEnd()); lstTimeBlocks.add(tb); } } } return lstTimeBlocks; }
From source file:org.kuali.kpme.tklm.time.timesheet.web.TimesheetSubmitAction.java
License:Educational Community License
public ActionForward approveTimesheet(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TimesheetSubmitActionForm tsaf = (TimesheetSubmitActionForm) form; TimesheetDocument document = TkServiceLocator.getTimesheetService() .getTimesheetDocument(tsaf.getDocumentId()); // Switched to grab the target (chain, resolution: target -> backdoor -> actual) user. // Approvals still using backdoor > actual if (StringUtils.equals(tsaf.getAction(), HrConstants.DOCUMENT_ACTIONS.ROUTE)) { if (DocumentStatus.INITIATED.getCode().equals(document.getDocumentHeader().getDocumentStatus()) || DocumentStatus.SAVED.getCode().equals(document.getDocumentHeader().getDocumentStatus())) { boolean nonExemptLE = LmServiceLocator.getLeaveApprovalService() .isActiveAssignmentFoundOnJobFlsaStatus(document.getPrincipalId(), HrConstants.FLSA_STATUS_NON_EXEMPT, true); if (nonExemptLE) { Map<String, Set<LeaveBlock>> eligibilities = LmServiceLocator .getAccrualCategoryMaxBalanceService() .getMaxBalanceViolations(document.getCalendarEntry(), document.getPrincipalId()); PrincipalHRAttributes pha = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(document.getPrincipalId(), document.getCalendarEntry().getEndPeriodFullDateTime().toLocalDate()); Calendar cal = pha.getLeaveCalObj(); if (cal == null) { //non exempt leave eligible employee without a leave calendar? LOG.error("Principal is without a leave calendar"); GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "principal.without.leavecal"); return mapping.findForward("basic"); // throw new RuntimeException("Principal is without a leave calendar"); }//w w w . ja v a2 s.co m List<LeaveBlock> eligibleTransfers = new ArrayList<LeaveBlock>(); List<LeaveBlock> eligiblePayouts = new ArrayList<LeaveBlock>(); Interval interval = new Interval(document.getCalendarEntry().getBeginPeriodDate().getTime(), document.getCalendarEntry().getEndPeriodDate().getTime()); for (Entry<String, Set<LeaveBlock>> entry : eligibilities.entrySet()) { for (LeaveBlock lb : entry.getValue()) { if (interval.contains(lb.getLeaveDate().getTime())) { //maxBalanceViolations should, if a violation exists, return a leave block with leave date either current date, or the end period date - 1 days. AccrualCategoryRule aRule = HrServiceLocator.getAccrualCategoryRuleService() .getAccrualCategoryRule(lb.getAccrualCategoryRuleId()); if (ObjectUtils.isNotNull(aRule) && !StringUtils.equals(aRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND)) { if (StringUtils.equals(aRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.YEAR_END)) { DateTime rollOverDate = HrServiceLocator.getLeavePlanService() .getRolloverDayOfLeavePlan(pha.getLeavePlan(), document.getCalendarEntry().getBeginPeriodFullDateTime() .toLocalDate()); //the final calendar period of the leave plan should end within this time sheet if (interval.contains(rollOverDate.minusDays(1).getMillis())) { //only leave blocks belonging to the calendar entry being submitted may reach this point //if the infraction occurs before the relative end date of the leave plan year, then action will be executed. if (lb.getLeaveDate().before(rollOverDate.toDate())) { if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.PAYOUT)) { eligiblePayouts.add(lb); } else if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.TRANSFER) || StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.LOSE)) { eligibleTransfers.add(lb); } } } } if (StringUtils.equals(aRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.LEAVE_APPROVE)) { //a leave period should end within the time period. CalendarEntry leaveEntry = HrServiceLocator.getCalendarEntryService() .getCurrentCalendarEntryByCalendarId(cal.getHrCalendarId(), lb.getLeaveLocalDate().toDateTimeAtStartOfDay()); if (ObjectUtils.isNotNull(leaveEntry)) { //only leave blocks belonging to the calendar entry being submitted may reach this point. //if the infraction occurs before the end of the leave calendar entry, then action will be executed. if (interval.contains(DateUtils .addDays(leaveEntry.getEndPeriodDate(), -1).getTime())) { if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.PAYOUT)) { eligiblePayouts.add(lb); } else if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.TRANSFER) || StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.LOSE)) { eligibleTransfers.add(lb); } } } } } } } } ActionRedirect transferRedirect = new ActionRedirect(); ActionRedirect payoutRedirect = new ActionRedirect(); if (!eligibleTransfers.isEmpty()) { transferRedirect.setPath("/BalanceTransfer.do?" + request.getQueryString()); request.getSession().setAttribute("eligibilities", eligibleTransfers); return transferRedirect; } if (!eligiblePayouts.isEmpty()) { payoutRedirect.setPath("/LeavePayout.do?" + request.getQueryString()); request.getSession().setAttribute("eligibilities", eligiblePayouts); return payoutRedirect; } } TkServiceLocator.getTimesheetService().routeTimesheet(HrContext.getTargetPrincipalId(), document); } } else if (StringUtils.equals(tsaf.getAction(), HrConstants.DOCUMENT_ACTIONS.APPROVE)) { if (TkServiceLocator.getTimesheetService().isReadyToApprove(document)) { if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) { TkServiceLocator.getTimesheetService().approveTimesheet(HrContext.getPrincipalId(), document); } } else { //ERROR!!! } } else if (StringUtils.equals(tsaf.getAction(), HrConstants.DOCUMENT_ACTIONS.DISAPPROVE)) { if (document.getDocumentHeader().getDocumentStatus().equals(DocumentStatus.ENROUTE.getCode())) { TkServiceLocator.getTimesheetService().disapproveTimesheet(HrContext.getPrincipalId(), document); } } TkServiceLocator.getTkSearchableAttributeService().updateSearchableAttribute(document, document.getAsOfDate()); ActionRedirect rd = new ActionRedirect(mapping.findForward("timesheetRedirect")); rd.addParameter("documentId", tsaf.getDocumentId()); return rd; }
From source file:org.kuali.kpme.tklm.time.timesummary.service.TimeSummaryServiceImpl.java
License:Educational Community License
private List<LeaveSummaryRow> getMaxedLeaveRows(CalendarEntry calendarEntry, String principalId) throws Exception { List<LeaveSummaryRow> maxedLeaveRows = new ArrayList<LeaveSummaryRow>(); if (LmServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(principalId, HrConstants.FLSA_STATUS_NON_EXEMPT, true)) { Map<String, Set<LeaveBlock>> eligibilities = LmServiceLocator.getAccrualCategoryMaxBalanceService() .getMaxBalanceViolations(calendarEntry, principalId); Set<LeaveBlock> onDemandTransfers = eligibilities.get(HrConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND); Interval calendarEntryInterval = new Interval(calendarEntry.getBeginPeriodDate().getTime(), calendarEntry.getEndPeriodDate().getTime()); //use the current date if on the current calendar? yes -> no warning given until accrual is reached. If accrual occurs on last day of period or last day of service interval //change, no warning given to the employee of balance limits being exceeded except on or after that day. if (!onDemandTransfers.isEmpty()) { for (LeaveBlock lb : onDemandTransfers) { LocalDate leaveDate = lb.getLeaveLocalDate(); LeaveSummary summary = LmServiceLocator.getLeaveSummaryService() .getLeaveSummaryAsOfDate(principalId, leaveDate.plusDays(1)); LeaveSummaryRow row = summary.getLeaveSummaryRowForAccrualCtgy(lb.getAccrualCategory()); if (row != null) { //AccrualCategory accrualCategory = HrServiceLocator.getAccrualCategoryService().getAccrualCategory(row.getAccrualCategoryId()); //AccrualCategoryRule currentRule = HrServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRuleForDate(accrualCategory, asOfDate, pha.getServiceDate()); if (calendarEntryInterval.contains(leaveDate.toDate().getTime())) { //do not allow the on-demand max balance action if the rule the action occurs under is no longer in effect, //or if the infraction did not occur within this interval. ( if it occurred during the previous interval, //the employee will have the option to take action in that interval up to & including the end date of that interval. ) row.setInfractingLeaveBlockId(lb.getAccrualCategoryRuleId()); AccrualCategoryRule aRule = HrServiceLocator.getAccrualCategoryRuleService() .getAccrualCategoryRule(lb.getAccrualCategoryRuleId()); if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.TRANSFER)) row.setTransferable(true); else if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.PAYOUT)) row.setPayoutable(true); boolean exists = false; for (LeaveSummaryRow maxedRow : maxedLeaveRows) { if (StringUtils.equals(maxedRow.getAccrualCategoryId(), row.getAccrualCategoryId())) exists = true; }// w w w .j ava2 s .co m if (!exists) maxedLeaveRows.add(row); } } } } } return maxedLeaveRows; }
From source file:org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate.java
License:Educational Community License
public TkTimeBlockAggregate(List<TimeBlock> timeBlocks, CalendarEntry payCalendarEntry, Calendar payCalendar, boolean useUserTimeZone, List<Interval> dayIntervals) { this.payCalendarEntry = payCalendarEntry; this.payCalendar = payCalendar; for (Interval dayInt : dayIntervals) { List<TimeBlock> dayTimeBlocks = new ArrayList<TimeBlock>(); for (TimeBlock timeBlock : timeBlocks) { // Assumption: Timezones can only be switched at pay period end boundaries. // If the above assumption becomes false, the logic below will need to // accommodate virtual chopping of time blocks to have them fit nicely // in the "days" that are displayed to users. DateTime beginTime = useUserTimeZone ? timeBlock.getBeginTimeDisplay() : timeBlock.getBeginDateTime().withZone(TKUtils.getSystemDateTimeZone()); DateTime endTime = useUserTimeZone ? timeBlock.getEndTimeDisplay() : timeBlock.getEndDateTime().withZone(TKUtils.getSystemDateTimeZone()); if (dayInt.contains(beginTime)) { if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) { // determine if the time block needs to be pushed forward / backward if (beginTime.getHourOfDay() < dayInt.getStart().getHourOfDay()) { timeBlock.setPushBackward(true); }//from ww w .ja v a2 s . c o m dayTimeBlocks.add(timeBlock); } } } dayTimeBlockList.add(dayTimeBlocks); } }
From source file:org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate.java
License:Educational Community License
public TkTimeBlockAggregate(List<TimeBlock> timeBlocks, List<LeaveBlock> leaveBlocks, CalendarEntry payCalendarEntry, Calendar payCalendar, boolean useUserTimeZone, List<Interval> dayIntervals) { this.payCalendarEntry = payCalendarEntry; this.payCalendar = payCalendar; for (Interval dayInt : dayIntervals) { List<TimeBlock> dayTimeBlocks = new ArrayList<TimeBlock>(); for (TimeBlock timeBlock : timeBlocks) { // Assumption: Timezones can only be switched at pay period end boundaries. // If the above assumption becomes false, the logic below will need to // accommodate virtual chopping of time blocks to have them fit nicely // in the "days" that are displayed to users. DateTime beginTime = useUserTimeZone ? timeBlock.getBeginTimeDisplay() : new DateTime(timeBlock.getBeginTimestamp(), TKUtils.getSystemDateTimeZone()); DateTime endTime = useUserTimeZone ? timeBlock.getEndTimeDisplay() : new DateTime(timeBlock.getEndTimestamp(), TKUtils.getSystemDateTimeZone()); if (dayInt.contains(beginTime)) { if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) { // determine if the time block needs to be pushed forward / backward if (beginTime.getHourOfDay() < dayInt.getStart().getHourOfDay()) { timeBlock.setPushBackward(true); }//w ww .j ava2 s .c om dayTimeBlocks.add(timeBlock); } } } dayTimeBlockList.add(dayTimeBlocks); List<LeaveBlock> dayLeaveBlocks = new ArrayList<LeaveBlock>(); for (LeaveBlock leaveBlock : leaveBlocks) { // Assumption: Timezones can only be switched at pay period end boundaries. // If the above assumption becomes false, the logic below will need to // accommodate virtual chopping of leave blocks to have them fit nicely // in the "days" that are displayed to users. DateTimeZone dateTimeZone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); DateTime beginTime = new DateTime(leaveBlock.getLeaveDate(), useUserTimeZone ? dateTimeZone : TKUtils.getSystemDateTimeZone()); DateTime endTime = new DateTime(leaveBlock.getLeaveDate(), useUserTimeZone ? dateTimeZone : TKUtils.getSystemDateTimeZone()); if (dayInt.contains(beginTime)) { if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) { dayLeaveBlocks.add(leaveBlock); } } } dayLeaveBlockList.add(dayLeaveBlocks); } }