List of usage examples for org.joda.time LocalDate toDateTimeAtStartOfDay
public DateTime toDateTimeAtStartOfDay()
From source file:org.kuali.kpme.tklm.leave.calendar.validation.LeaveCalendarValidationUtil.java
License:Educational Community License
public static List<String> validateAvailableLeaveBalanceForUsage(String earnCode, String leaveStartDateString, String leaveEndDateString, BigDecimal leaveAmount, LeaveBlock updatedLeaveBlock) { List<String> errors = new ArrayList<String>(); boolean earnCodeChanged = false; BigDecimal oldAmount = null;//from w w w . j a v a2s . c om if (leaveAmount == null) { leaveAmount = TKUtils.getHoursBetween(TKUtils.formatDateString(leaveStartDateString).toDate().getTime(), TKUtils.formatDateString(leaveEndDateString).toDate().getTime()); } if (updatedLeaveBlock != null) { if (!updatedLeaveBlock.getEarnCode().equals(earnCode)) { earnCodeChanged = true; } if (!updatedLeaveBlock.getLeaveAmount().equals(leaveAmount)) { oldAmount = updatedLeaveBlock.getLeaveAmount(); } } LocalDate startDate = TKUtils.formatDateString(leaveStartDateString); LocalDate endDate = TKUtils.formatDateString(leaveEndDateString); long daysSpan = TKUtils.getDaysBetween(startDate, endDate); EarnCode earnCodeObj = HrServiceLocator.getEarnCodeService().getEarnCode(earnCode, endDate); if (earnCodeObj != null && earnCodeObj.getAllowNegativeAccrualBalance().equals("N")) { AccrualCategory accrualCategory = HrServiceLocator.getAccrualCategoryService() .getAccrualCategory(earnCodeObj.getAccrualCategory(), endDate); if (accrualCategory != null) { DateTime nextIntervalDate = LmServiceLocator.getAccrualService().getNextAccrualIntervalDate( accrualCategory.getAccrualEarnInterval(), endDate.toDateTimeAtStartOfDay()); // get the usage checking cut off Date, normally it's the day before the next interval date DateTime usageEndDate = nextIntervalDate; if (nextIntervalDate.compareTo(endDate.toDateTimeAtCurrentTime()) > 0) { usageEndDate = nextIntervalDate.minusDays(1); } // use the end of the year as the interval date for usage checking of no-accrual hours, // normally no-accrual hours are from banked/transferred system scheduled time offs if (accrualCategory.getAccrualEarnInterval() .equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) { usageEndDate = endDate.toDateTimeAtStartOfDay().withMonthOfYear(DateTimeConstants.DECEMBER) .withDayOfMonth(31); } BigDecimal availableBalance = LmServiceLocator.getLeaveSummaryService() .getLeaveBalanceForAccrCatUpToDate(HrContext.getTargetPrincipalId(), startDate, endDate, accrualCategory.getAccrualCategory(), usageEndDate.toLocalDate()); if (oldAmount != null) { if (!earnCodeChanged || updatedLeaveBlock.getAccrualCategory() .equals(accrualCategory.getAccrualCategory())) { availableBalance = availableBalance.add(oldAmount.abs()); } } //multiply by days in span in case the user has also edited the start/end dates. BigDecimal desiredUsage = null; if (!HrConstants.EARN_CODE_TIME.equals(earnCodeObj.getRecordMethod())) { desiredUsage = leaveAmount.multiply(new BigDecimal(daysSpan + 1)); } else { desiredUsage = leaveAmount.multiply(new BigDecimal(daysSpan)); } if (desiredUsage.compareTo(availableBalance) > 0) { errors.add("Requested leave amount " + desiredUsage.toString() + " is greater than available leave balance " + availableBalance.toString()); //errorMessages } } } return errors; }
From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarAction.java
License:Educational Community License
/** * Recalculate accrual when a leave block with not-eligible-for-accrual earn code is added or deleted * calculate accrual only for the calendar entry period * @param earnCode//from w w w . j a v a2 s . c om * @param asOfDate * @param startDate * @param endDate */ private void rerunAccrualForNotEligibleForAccrualChanges(String earnCode, LocalDate asOfDate, LocalDate startDate, LocalDate endDate) { EarnCode ec = HrServiceLocator.getEarnCodeService().getEarnCode(earnCode, asOfDate); if (ec != null && ec.getEligibleForAccrual().equals("N")) { if (startDate != null && endDate != null) { // since we are only recalculating accrual for this pay period, we use "false" to not record the accrual run data LmServiceLocator.getLeaveAccrualService().runAccrual(HrContext.getTargetPrincipalId(), startDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay(), false); } } }
From source file:org.kuali.kpme.tklm.leave.payout.web.LeavePayoutLookupableHelperServiceImpl.java
License:Educational Community License
private List<LeavePayout> filterByPrincipalId(List<LeavePayout> payouts) { if (!payouts.isEmpty()) { Iterator<? extends BusinessObject> iter = payouts.iterator(); while (iter.hasNext()) { LeavePayout payout = (LeavePayout) iter.next(); LocalDate effectiveLocalDate = payout.getEffectiveLocalDate(); DateTime effectiveDate = effectiveLocalDate.toDateTimeAtStartOfDay(); String principalId = payout.getPrincipalId(); List<Job> principalsJobs = HrServiceLocator.getJobService().getActiveLeaveJobs(principalId, effectiveLocalDate); String userPrincipalId = HrContext.getPrincipalId(); boolean canView = false; //TODO - performance, get a job/dept map in 1 query for (Job job : principalsJobs) { if (job.isEligibleForLeave()) { String department = job.getDept(); String groupKeyCode = job.getGroupKeyCode(); Department departmentObj = HrServiceLocator.getDepartmentService().getDepartment(department, groupKeyCode, effectiveLocalDate); String location = departmentObj != null ? departmentObj.getGroupKey().getLocationId() : null;//from w w w. j av a 2s . co m if (LmServiceLocator.getLMPermissionService().isAuthorizedInDepartment(userPrincipalId, "View Leave Payout", department, groupKeyCode, effectiveDate) || LmServiceLocator.getLMPermissionService().isAuthorizedInLocation(userPrincipalId, "View Leave Payout", location, effectiveDate)) { canView = true; break; } else { //do NOT block approvers, processors, delegates from approving the document. List<Assignment> assignments = HrServiceLocator.getAssignmentService() .getActiveAssignmentsForJob(principalId, job.getJobNumber(), effectiveLocalDate); for (Assignment assignment : assignments) { if (HrServiceLocator.getKPMERoleService().principalHasRoleInWorkArea( userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER.getRoleName(), assignment.getWorkArea(), new DateTime(effectiveDate)) || HrServiceLocator.getKPMERoleService().principalHasRoleInWorkArea( userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER_DELEGATE.getRoleName(), assignment.getWorkArea(), new DateTime(effectiveDate)) || HrServiceLocator.getKPMERoleService().principalHasRoleInDepartment( userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.PAYROLL_PROCESSOR.getRoleName(), assignment.getDept(), assignment.getGroupKeyCode(), new DateTime(effectiveDate)) || HrServiceLocator.getKPMERoleService().principalHasRoleInDepartment( userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.PAYROLL_PROCESSOR_DELEGATE.getRoleName(), assignment.getDept(), assignment.getGroupKeyCode(), new DateTime(effectiveDate))) { canView = true; break; } } } } } if (!canView) { iter.remove(); } } } return payouts; }
From source file:org.kuali.kpme.tklm.leave.request.web.LeaveRequestAction.java
License:Educational Community License
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward forward = super.execute(mapping, form, request, response); LeaveRequestForm leaveForm = (LeaveRequestForm) form; String principalId = HrContext.getTargetPrincipalId(); DateTime currentDate = LocalDate.now().toDateTimeAtStartOfDay(); if (leaveForm.getNavString() == null) { leaveForm.setYear(LocalDate.now().getYear()); } else if (leaveForm.getNavString().equals("NEXT")) { leaveForm.setYear(leaveForm.getYear() + 1); } else if (leaveForm.getNavString().equals("PREV")) { leaveForm.setYear(leaveForm.getYear() - 1); }/*from w ww .j a v a 2 s.com*/ LocalDate beginDate = new LocalDate(leaveForm.getYear(), 1, 1); LocalDate endDate = new LocalDate(leaveForm.getYear(), 12, 31); // CalendarEntry calendarEntry = HrServiceLocator.getCalendarService().getCurrentCalendarDatesForLeaveCalendar(principalId, currentDate); CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService() .getCurrentCalendarDatesForLeaveCalendar(principalId, beginDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay()); // If the current pay period ends before the current leave calendar ends, then we need to include any planned leave blocks that occur // in this window between the current pay end and the beginning of the leave planning calendar (the next future leave period). // The most common scenario occurs when a non-monthly pay period ends before the current leave calendar ends. CalendarEntry payCalendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates( principalId, beginDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay()); Boolean checkLeaveEligible = true; Boolean nonExemptLeaveEligible = LmServiceLocator.getLeaveApprovalService() .isActiveAssignmentFoundOnJobFlsaStatus(principalId, HrConstants.FLSA_STATUS_NON_EXEMPT, checkLeaveEligible); if (nonExemptLeaveEligible && calendarEntry != null && payCalendarEntry != null) { if (payCalendarEntry.getEndPeriodDate().before(calendarEntry.getEndPeriodDate())) { calendarEntry = payCalendarEntry; } } if (calendarEntry != null) { if (calendarEntry.getEndPeriodLocalDateTime().getMillisOfDay() == 0) { // if the time of the end date is the beginning of a day, subtract one day from the end date currentDate = calendarEntry.getEndPeriodFullDateTime().minusDays(1); } else { currentDate = calendarEntry.getEndPeriodFullDateTime(); // only show leave requests from planning calendars on leave request page } } List<LeaveBlock> plannedLeaves = getLeaveBlocksWithRequestStatus(principalId, beginDate, endDate, HrConstants.REQUEST_STATUS.PLANNED); plannedLeaves.addAll(getLeaveBlocksWithRequestStatus(principalId, beginDate, endDate, HrConstants.REQUEST_STATUS.DEFERRED)); leaveForm.setPlannedLeaves(plannedLeaves); leaveForm.setPendingLeaves(getLeaveBlocksWithRequestStatus(principalId, beginDate, endDate, HrConstants.REQUEST_STATUS.REQUESTED)); leaveForm.setApprovedLeaves(getLeaveBlocksWithRequestStatus(principalId, beginDate, endDate, HrConstants.REQUEST_STATUS.APPROVED)); leaveForm.setDisapprovedLeaves(getDisapprovedLeaveBlockHistory(principalId, currentDate.toLocalDate())); leaveForm.setDocuments(getLeaveRequestDocuments(leaveForm)); return forward; }
From source file:org.kuali.kpme.tklm.leave.summary.service.LeaveSummaryServiceImpl.java
License:Educational Community License
protected LeaveSummary getLeaveSummary(String principalId, LocalDate startDate, LocalDate endDate, String accrualCategory, boolean includeFuture) { LeaveSummary ls = new LeaveSummary(); List<LeaveSummaryRow> rows = new ArrayList<LeaveSummaryRow>(); if (StringUtils.isEmpty(principalId) || startDate == null || endDate == null) { return ls; }/*from ww w. j a v a 2 s . co m*/ Set<String> leavePlans = getLeavePlans(principalId, startDate, endDate); PrincipalHRAttributes pha = getPrincipalHrAttributes(principalId, startDate, endDate); if (CollectionUtils.isNotEmpty(leavePlans)) { for (String aLpString : leavePlans) { LeavePlan lp = HrServiceLocator.getLeavePlanService().getLeavePlan(aLpString, startDate); if (lp == null) { continue; } DateTimeFormatter formatter = DateTimeFormat.forPattern("MMMM d"); DateTimeFormatter formatter2 = DateTimeFormat.forPattern("MMMM d yyyy"); DateTime entryEndDate = endDate.toDateTimeAtStartOfDay(); if (entryEndDate.getHourOfDay() == 0) { entryEndDate = entryEndDate.minusDays(1); } String aString = formatter.print(startDate) + " - " + formatter2.print(entryEndDate); ls.setPendingDatesString(aString); LeaveCalendarDocumentHeader approvedLcdh = LmServiceLocator.getLeaveCalendarDocumentHeaderService() .getMaxEndDateApprovedLeaveCalendar(principalId); if (approvedLcdh != null) { DateTime endApprovedDate = approvedLcdh.getEndDateTime(); LocalDateTime aLocalTime = approvedLcdh.getEndDateTime().toLocalDateTime(); DateTime endApprovedTime = aLocalTime .toDateTime(HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback()); if (endApprovedTime.getHourOfDay() == 0) { endApprovedDate = endApprovedDate.minusDays(1); } String datesString = formatter.print(approvedLcdh.getBeginDateTime()) + " - " + formatter2.print(endApprovedDate); ls.setYtdDatesString(datesString); } //until we have something that creates carry over, we need to grab everything. // Calculating leave bLocks from Calendar Year start instead of Service Date Map<String, LeaveBlock> carryOverBlocks = getLeaveBlockService().getLastCarryOverBlocks(principalId, startDate); boolean filterByAccrualCategory = false; if (StringUtils.isNotEmpty(accrualCategory)) { filterByAccrualCategory = true; //remove unwanted carry over blocks from map LeaveBlock carryOverBlock = carryOverBlocks.get(accrualCategory); carryOverBlocks = new HashMap<String, LeaveBlock>(1); if (ObjectUtils.isNotNull(carryOverBlock)) carryOverBlocks.put(carryOverBlock.getAccrualCategory(), carryOverBlock); } List<LeaveBlock> leaveBlocks = getLeaveBlockService().getLeaveBlocksSinceCarryOver(principalId, carryOverBlocks, endDate, filterByAccrualCategory); List<LeaveBlock> futureLeaveBlocks = new ArrayList<LeaveBlock>(); if (includeFuture) { if (!filterByAccrualCategory) { futureLeaveBlocks = getLeaveBlockService().getLeaveBlocks(principalId, endDate, endDate.plusMonths(Integer.parseInt(lp.getPlanningMonths()))); } else { futureLeaveBlocks = getLeaveBlockService().getLeaveBlocksWithAccrualCategory(principalId, endDate, endDate.plusMonths(Integer.parseInt(lp.getPlanningMonths())), accrualCategory); } } Map<String, List<LeaveBlock>> leaveBlockMap = mapLeaveBlocksByAccrualCategory(leaveBlocks); Map<String, List<LeaveBlock>> futureLeaveBlockMap = mapLeaveBlocksByAccrualCategory( futureLeaveBlocks); List<AccrualCategory> acList = HrServiceLocator.getAccrualCategoryService() .getActiveAccrualCategoriesForLeavePlan(lp.getLeavePlan(), endDate); if (CollectionUtils.isNotEmpty(acList)) { for (AccrualCategory ac : acList) { if (ac.getShowOnGrid().equals("Y")) { LeaveSummaryRow lsr = new LeaveSummaryRow(); lsr.setAccrualCategory(ac.getAccrualCategory()); lsr.setAccrualCategoryId(ac.getLmAccrualCategoryId()); //get max balances AccrualCategoryRule acRule = HrServiceLocator.getAccrualCategoryRuleService() .getAccrualCategoryRuleForDate(ac, endDate, pha.getServiceLocalDate()); //accrual category rule id set on a leave summary row will be useful in generating a relevant balance transfer //document from the leave calendar display. Could put this id in the request for balance transfer document. EmployeeOverride maxUsageOverride = LmServiceLocator.getEmployeeOverrideService() .getEmployeeOverride(principalId, lp.getLeavePlan(), ac.getAccrualCategory(), "MU", endDate); lsr.setAccrualCategoryRuleId( acRule == null ? null : acRule.getLmAccrualCategoryRuleId()); if (acRule != null && (acRule.getMaxBalance() != null || acRule.getMaxUsage() != null)) { if (acRule.getMaxUsage() != null) { lsr.setUsageLimit(new BigDecimal(acRule.getMaxUsage()).setScale(2)); } else { lsr.setUsageLimit(null); } } else { lsr.setUsageLimit(null); } if (maxUsageOverride != null) lsr.setUsageLimit(new BigDecimal(maxUsageOverride.getOverrideValue())); //Fetching leaveblocks for accCat with type CarryOver -- This is logic according to the CO blocks created from scheduler job. BigDecimal carryOver = BigDecimal.ZERO.setScale(2); lsr.setCarryOver(carryOver); //handle up to current leave blocks //CalendarEntry.getEndPeriodDate passed to fetch leave block amounts on last day of Calendar period assignApprovedValuesToRow(lsr, ac.getAccrualCategory(), leaveBlockMap.get(ac.getAccrualCategory()), lp, startDate, endDate); //how about the leave blocks on the calendar entry being currently handled?? /* if(carryOverBlocks.containsKey(lsr.getAccrualCategory())) { LeaveBlock carryOverBlock = carryOverBlocks.get(lsr.getAccrualCategory()); DateTime carryOverBlockLPStart = HrServiceLocator.getLeavePlanService().getFirstDayOfLeavePlan(lp.getLeavePlan(), carryOverBlock.getLeaveDate()); DateTime currentLPStart = HrServiceLocator.getLeavePlanService().getFirstDayOfLeavePlan(lp.getLeavePlan(), TKUtils.getCurrentDate()); if(carryOverBlockLPStart.equals(currentLPStart)) carryOver = carryOverBlock.getLeaveAmount(); }*/ //figure out past carry over values!!! //We now have list of past years accrual and use (with ordered keys!!!) //merge key sets if (carryOverBlocks.containsKey(lsr.getAccrualCategory())) { carryOver = carryOverBlocks.get(lsr.getAccrualCategory()).getLeaveAmount(); carryOver = carryOver.setScale(2); } Set<String> keyset = new HashSet<String>(); keyset.addAll(lsr.getPriorYearsUsage().keySet()); keyset.addAll(lsr.getPriorYearsTotalAccrued().keySet()); for (String key : keyset) { BigDecimal value = lsr.getPriorYearsTotalAccrued().get(key); if (value == null) { value = BigDecimal.ZERO; } carryOver = carryOver.add(value); BigDecimal use = lsr.getPriorYearsUsage().containsKey(key) ? lsr.getPriorYearsUsage().get(key) : BigDecimal.ZERO; carryOver = carryOver.add(use); EmployeeOverride carryOverOverride = LmServiceLocator.getEmployeeOverrideService() .getEmployeeOverride(principalId, lp.getLeavePlan(), ac.getAccrualCategory(), "MAC", endDate); if (acRule != null && acRule.getMaxCarryOver() != null) { BigDecimal carryOverDisplay = BigDecimal.ZERO; if (carryOverOverride != null) carryOverDisplay = new BigDecimal( carryOverOverride.getOverrideValue() < carryOver.longValue() ? carryOverOverride.getOverrideValue() : carryOver.longValue()); else carryOverDisplay = new BigDecimal( acRule.getMaxCarryOver() < carryOver.longValue() ? acRule.getMaxCarryOver() : carryOver.longValue()); carryOver = carryOverDisplay; } } lsr.setCarryOver(carryOver); if (acRule != null && acRule.getMaxCarryOver() != null) { EmployeeOverride carryOverOverride = LmServiceLocator.getEmployeeOverrideService() .getEmployeeOverride(principalId, lp.getLeavePlan(), ac.getAccrualCategory(), "MAC", endDate); if (carryOverOverride != null) lsr.setMaxCarryOver(new BigDecimal(carryOverOverride.getOverrideValue())); else lsr.setMaxCarryOver( new BigDecimal(acRule.getMaxCarryOver() < carryOver.longValue() ? acRule.getMaxCarryOver() : carryOver.longValue())); } //handle future leave blocks assignPendingValuesToRow(lsr, ac.getAccrualCategory(), futureLeaveBlockMap.get(ac.getAccrualCategory())); //compute Leave Balance BigDecimal leaveBalance = lsr.getAccruedBalance() .subtract(lsr.getPendingLeaveRequests()); //if leave balance is set //Employee overrides have already been taken into consideration and the appropriate values //for usage have been set by this point. // if (acRule != null && StringUtils.equals(acRule.getMaxBalFlag(), "Y")) { //there exists an accrual category rule with max balance limit imposed. //max bal flag = 'Y' has no precedence here with max-bal / balance transfers implemented. //unless institutions are not required to define a max balance limit for action_at_max_bal = LOSE. //Possibly preferable to procure forfeiture blocks through balance transfer if (lsr.getUsageLimit() != null) { //should not set leave balance to usage limit simply because it's not null. BigDecimal availableUsage = lsr.getUsageLimit() .subtract(lsr.getYtdApprovedUsage().add(lsr.getPendingLeaveRequests())); if (leaveBalance.compareTo(availableUsage) > 0) lsr.setLeaveBalance(availableUsage); else lsr.setLeaveBalance(leaveBalance); } else { //no usage limit lsr.setLeaveBalance(leaveBalance); } rows.add(lsr); } } // let's check for 'empty' accrual categories if (leaveBlockMap.containsKey(null) || futureLeaveBlockMap.containsKey(null)) { LeaveSummaryRow otherLeaveSummary = new LeaveSummaryRow(); //otherLeaveSummary.setAccrualCategory("Other"); assignApprovedValuesToRow(otherLeaveSummary, null, leaveBlockMap.get(null), lp, startDate, endDate); BigDecimal carryOver = BigDecimal.ZERO.setScale(2); for (Map.Entry<String, BigDecimal> entry : otherLeaveSummary.getPriorYearsTotalAccrued() .entrySet()) { carryOver = carryOver.add(entry.getValue()); BigDecimal use = otherLeaveSummary.getPriorYearsUsage().containsKey(entry.getKey()) ? otherLeaveSummary.getPriorYearsUsage().get(entry.getKey()) : BigDecimal.ZERO; carryOver = carryOver.add(use); } otherLeaveSummary.setCarryOver(carryOver); assignPendingValuesToRow(otherLeaveSummary, null, futureLeaveBlockMap.get(null)); otherLeaveSummary.setAccrualCategory("Other"); //compute Leave Balance // blank the avail otherLeaveSummary.setUsageLimit(null); otherLeaveSummary.setLeaveBalance(null); rows.add(otherLeaveSummary); } } } } ls.setLeaveSummaryRows(rows); return ls; }
From source file:org.kuali.kpme.tklm.leave.transfer.web.BalanceTransferLookupableHelperServiceImpl.java
License:Educational Community License
private List<BalanceTransfer> filterByPrincipalId(List<BalanceTransfer> transfers) { //TODO - performance if (!transfers.isEmpty()) { Iterator<? extends BusinessObject> iter = transfers.iterator(); while (iter.hasNext()) { BalanceTransfer transfer = (BalanceTransfer) iter.next(); LocalDate effectiveLocalDate = transfer.getEffectiveLocalDate(); DateTime effectiveDate = effectiveLocalDate.toDateTimeAtStartOfDay(); List<Job> principalsJobs = HrServiceLocator.getJobService() .getActiveLeaveJobs(transfer.getPrincipalId(), effectiveLocalDate); String userPrincipalId = HrContext.getPrincipalId(); boolean canView = false; for (Job job : principalsJobs) { if (job.isEligibleForLeave()) { String department = job.getDept(); String groupKeyCode = job.getGroupKeyCode(); Department departmentObj = HrServiceLocator.getDepartmentService().getDepartment(department, groupKeyCode, effectiveLocalDate); String location = departmentObj != null ? departmentObj.getGroupKey().getLocationId() : null;/*from w w w . ja va 2s .com*/ if (LmServiceLocator.getLMPermissionService().isAuthorizedInDepartment(userPrincipalId, "View Balance Transfer", department, groupKeyCode, effectiveDate) || LmServiceLocator.getLMPermissionService().isAuthorizedInLocation(userPrincipalId, "View Balance Transfer", location, effectiveDate)) { canView = true; break; } else { //do NOT block approvers, processors, delegates from viewing the object. List<Assignment> assignments = HrServiceLocator.getAssignmentService() .getActiveAssignmentsForJob(transfer.getPrincipalId(), job.getJobNumber(), effectiveLocalDate); for (Assignment assignment : assignments) { if (HrServiceLocator.getKPMERoleService().principalHasRoleInWorkArea( userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER.getRoleName(), assignment.getWorkArea(), new DateTime(effectiveDate)) || HrServiceLocator.getKPMERoleService().principalHasRoleInWorkArea( userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER_DELEGATE.getRoleName(), assignment.getWorkArea(), new DateTime(effectiveDate)) || HrServiceLocator.getKPMERoleService().principalHasRoleInDepartment( userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.PAYROLL_PROCESSOR.getRoleName(), assignment.getDept(), assignment.getGroupKeyCode(), new DateTime(effectiveDate)) || HrServiceLocator.getKPMERoleService().principalHasRoleInDepartment( userPrincipalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.PAYROLL_PROCESSOR_DELEGATE.getRoleName(), assignment.getDept(), assignment.getGroupKeyCode(), new DateTime(effectiveDate))) { canView = true; break; } } } } } if (!canView) { iter.remove(); } } } return transfers; }
From source file:org.kuali.kpme.tklm.time.approval.web.TimeApprovalWSAction.java
License:Educational Community License
/** * Action called via AJAX. (ajaj really...) * <p/>//from w w w. ja va 2s .c om * This search returns quick-results to the search box for the user to further * refine upon. The end value can then be form submitted. */ public ActionForward searchApprovalRows(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TimeApprovalActionForm taaf = (TimeApprovalActionForm) form; List<Map<String, String>> results = new LinkedList<Map<String, String>>(); List<String> workAreaList = new ArrayList<String>(); if (StringUtil.isEmpty(taaf.getSelectedWorkArea())) { String principalId = HrContext.getTargetPrincipalId(); Set<Long> workAreas = new HashSet<Long>(); workAreas.addAll(HrServiceLocator.getKPMERoleService().getWorkAreasForPrincipalInRole(principalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER.getRoleName(), new DateTime(), true)); workAreas.addAll(HrServiceLocator.getKPMERoleService().getWorkAreasForPrincipalInRole(principalId, KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER_DELEGATE.getRoleName(), new DateTime(), true)); for (Long workArea : workAreas) { workAreaList.add(workArea.toString()); } } else { workAreaList.add(taaf.getSelectedWorkArea()); } LocalDate endDate = taaf.getCalendarEntry().getEndPeriodFullDateTime().toLocalDate(); LocalDate beginDate = taaf.getCalendarEntry().getBeginPeriodFullDateTime().toLocalDate(); List<String> principalIds = TkServiceLocator.getTimeApproveService().getTimePrincipalIdsWithSearchCriteria( workAreaList, taaf.getSelectedPayCalendarGroup(), endDate, beginDate, endDate); if (StringUtils.equals(taaf.getSearchField(), CalendarApprovalForm.ORDER_BY_PRINCIPAL)) { for (String id : principalIds) { if (StringUtils.contains(id, taaf.getSearchTerm())) { Map<String, String> labelValue = new HashMap<String, String>(); labelValue.put("id", id); labelValue.put("result", id); results.add(labelValue); } } } else if (StringUtils.equals(taaf.getSearchField(), CalendarApprovalForm.ORDER_BY_DOCID)) { Map<String, TimesheetDocumentHeader> principalDocumentHeaders = TkServiceLocator.getTimeApproveService() .getPrincipalDocumentHeader(principalIds, beginDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay()); for (Map.Entry<String, TimesheetDocumentHeader> entry : principalDocumentHeaders.entrySet()) { if (StringUtils.contains(entry.getValue().getDocumentId(), taaf.getSearchTerm())) { Map<String, String> labelValue = new HashMap<String, String>(); // labelValue.put("id", entry.getValue().getDocumentId() + " (" + entry.getValue().getPrincipalId() + ")"); labelValue.put("id", entry.getValue().getDocumentId()); labelValue.put("result", entry.getValue().getPrincipalId()); results.add(labelValue); } } } taaf.setOutputString(JSONValue.toJSONString(results)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.time.detail.web.ActionFormUtils.java
License:Educational Community License
public static Map<String, String> getPayPeriodsMap(List<CalendarEntry> payPeriods, String viewPrincipal) { // use linked map to keep the order of the pay periods Map<String, String> pMap = Collections.synchronizedMap(new LinkedHashMap<String, String>()); if (payPeriods == null || payPeriods.isEmpty()) { return pMap; }// ww w. j av a2s . c om payPeriods.removeAll(Collections.singletonList(null)); Collections.sort(payPeriods); // sort the pay period list by getBeginPeriodDate Collections.reverse(payPeriods); // newest on top SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); for (CalendarEntry pce : payPeriods) { // Check if service date of user is after the Calendar entry DateTime asOfDate = pce.getEndPeriodFullDateTime().minusDays(1); PrincipalHRAttributes principalHRAttributes = null; if (viewPrincipal != null) { principalHRAttributes = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(viewPrincipal, asOfDate.toLocalDate()); } else { pMap.put(pce.getHrCalendarEntryId(), sdf.format(pce.getBeginPeriodDate()) + " - " + sdf.format((DateUtils.addMilliseconds(pce.getEndPeriodDate(), -1)))); } if (principalHRAttributes != null && pce != null && pce.getHrCalendarEntryId() != null && pce.getBeginPeriodDate() != null && pce.getEndPeriodDate() != null) { LocalDate startCalDate = principalHRAttributes.getServiceLocalDate(); if (startCalDate != null) { if (!(pce.getBeginPeriodFullDateTime().compareTo(startCalDate.toDateTimeAtStartOfDay()) < 0)) { //pMap.put(pce.getHrCalendarEntriesId(), sdf.format(pce.getBeginPeriodDate()) + " - " + sdf.format(pce.getEndPeriodDate())); //getting one millisecond of the endperioddate to match the actual pay period. i.e. pay period end at the 11:59:59:59...PM of that day pMap.put(pce.getHrCalendarEntryId(), sdf.format(pce.getBeginPeriodDate()) + " - " + sdf.format((DateUtils.addMilliseconds(pce.getEndPeriodDate(), -1)))); } } else { pMap.put(pce.getHrCalendarEntryId(), sdf.format(pce.getBeginPeriodDate()) + " - " + sdf.format((DateUtils.addMilliseconds(pce.getEndPeriodDate(), -1)))); } } } return pMap; }
From source file:org.kuali.kpme.tklm.time.missedpunch.MissedPunch.java
License:Educational Community License
public void setActionTime(String actionTime) { LocalDate localDate = actionDateTime != null ? LocalDate.fromDateFields(actionDateTime) : LocalDate.now(); LocalTime localTime = actionTime != null ? FORMATTER.parseLocalTime(actionTime) : null; actionDateTime = localTime != null ? localTime.toDateTime(localDate.toDateTimeAtStartOfDay()).toDate() : null;/*ww w. j a v a2s .co m*/ }
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(); }//from w w w. ja va2 s . com } 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; }