List of usage examples for org.joda.time DateTime toLocalDate
public LocalDate toLocalDate()
LocalDate
with the same date and chronology. From source file:org.kuali.kpme.tklm.leave.approval.service.LeaveApprovalServiceImpl.java
License:Educational Community License
@Override public List<ApprovalLeaveSummaryRow> getLeaveApprovalSummaryRows(List<String> principalIds, CalendarEntry payCalendarEntry, List<Date> leaveSummaryDates) { DateTime payBeginDate = payCalendarEntry.getBeginPeriodFullDateTime(); DateTime payEndDate = payCalendarEntry.getEndPeriodFullDateTime(); List<ApprovalLeaveSummaryRow> rowList = new ArrayList<ApprovalLeaveSummaryRow>(); for (String principalId : principalIds) { ApprovalLeaveSummaryRow aRow = new ApprovalLeaveSummaryRow(); List<Note> notes = new ArrayList<Note>(); // List<String> warnings = new ArrayList<String>(); EntityNamePrincipalName name = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); aRow.setName(name != null && name.getDefaultName() != null && name.getDefaultName().getCompositeName() != null ? name.getDefaultName().getCompositeName() : principalId);/*from w w w.j a v a2s .co m*/ aRow.setPrincipalId(principalId); String lastApprovedString = "No previous approved leave calendar information"; LeaveCalendarDocumentHeader lastApprovedDoc = LmServiceLocator.getLeaveCalendarDocumentHeaderService() .getMaxEndDateApprovedLeaveCalendar(principalId); if (lastApprovedDoc != null) { lastApprovedString = "Last Approved: " + (new SimpleDateFormat("MMM yyyy")).format(lastApprovedDoc.getBeginDate()); } aRow.setLastApproveMessage(lastApprovedString); LeaveCalendarDocumentHeader aDoc = LmServiceLocator.getLeaveCalendarDocumentHeaderService() .getDocumentHeader(principalId, payBeginDate, payEndDate); if (aDoc != null) { aRow.setDocumentId(aDoc.getDocumentId()); aRow.setApprovalStatus(HrConstants.DOC_ROUTE_STATUS.get(aDoc.getDocumentStatus())); notes = getNotesForDocument(aDoc.getDocumentId()); } List<LeaveCalendarDocumentHeader> docList = LmServiceLocator.getLeaveCalendarDocumentHeaderService() .getApprovalDelinquentDocumentHeaders(principalId); if (docList.size() > LMConstants.DELINQUENT_LEAVE_CALENDARS_LIMIT) { aRow.setMoreThanOneCalendar(true); } List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principalId, payBeginDate.toLocalDate(), payEndDate.toLocalDate()); aRow.setLeaveBlockList(leaveBlocks); Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours = getEarnCodeLeaveHours(leaveBlocks, leaveSummaryDates); aRow.setEarnCodeLeaveHours(earnCodeLeaveHours); aRow.setNotes(notes); Map<String, Set<String>> allMessages = findWarnings(principalId, payCalendarEntry, leaveBlocks); Map<String, Set<String>> transactionalMessages = findTransactionsWithinPeriod(aDoc, payCalendarEntry); allMessages.get("infoMessages").addAll(transactionalMessages.get("infoMessages")); allMessages.get("warningMessages").addAll(transactionalMessages.get("warningMessages")); allMessages.get("actionMessages").addAll(transactionalMessages.get("actionMessages")); List<String> warningMessages = new ArrayList<String>(); warningMessages.addAll(allMessages.get("warningMessages")); warningMessages.addAll(allMessages.get("infoMessages")); warningMessages.addAll(allMessages.get("actionMessages")); aRow.setWarnings(warningMessages); //these are only warning messages. rowList.add(aRow); } return rowList; }
From source file:org.kuali.kpme.tklm.leave.approval.service.LeaveApprovalServiceImpl.java
License:Educational Community License
@Override public List<Map<String, Object>> getLeaveApprovalDetailSections(LeaveCalendarDocumentHeader lcdh) { List<Map<String, Object>> acRows = new ArrayList<Map<String, Object>>(); if (lcdh == null) { return acRows; }//from www .ja v a2 s.c o m String principalId = lcdh.getPrincipalId(); CalendarEntry calendarEntry = LmServiceLocator.getLeaveCalendarService() .getLeaveCalendarDocument(lcdh.getDocumentId()).getCalendarEntry(); //CalendarEntries calendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntriesByBeginAndEndDate(lcdh.getBeginDate(), lcdh.getEndDate()); if (calendarEntry != null) { DateTime beginDate = calendarEntry.getBeginPeriodFullDateTime(); DateTime endDate = calendarEntry.getEndPeriodFullDateTime(); LeaveSummary leaveSummary; List<Date> leaveSummaryDates = LmServiceLocator.getLeaveSummaryService() .getLeaveSummaryDates(calendarEntry); try { leaveSummary = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(principalId, calendarEntry); } catch (Exception e) { leaveSummary = null; } List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principalId, beginDate.toLocalDate(), endDate.toLocalDate()); Map<Date, Map<String, BigDecimal>> accrualCategoryLeaveHours = getAccrualCategoryLeaveHours(leaveBlocks, leaveSummaryDates); //get all accrual categories of this employee PrincipalHRAttributes pha = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(principalId, endDate.toLocalDate()); if (pha != null) { List<AccrualCategory> acList = HrServiceLocator.getAccrualCategoryService() .getActiveAccrualCategoriesForLeavePlan(pha.getLeavePlan(), endDate.toLocalDate()); for (AccrualCategory ac : acList) { List<BigDecimal> acDayDetails = new ArrayList<BigDecimal>(); Map<String, Object> displayMap = new HashMap<String, Object>(); BigDecimal totalAmount = BigDecimal.ZERO; displayMap.put("accrualCategory", ac.getAccrualCategory()); int index = 0; for (Date leaveSummaryDate : leaveSummaryDates) { acDayDetails.add(index, null); if (accrualCategoryLeaveHours.get(leaveSummaryDate) != null) { Map<String, BigDecimal> leaveHours = accrualCategoryLeaveHours.get(leaveSummaryDate); if (leaveHours.containsKey(ac.getAccrualCategory())) { BigDecimal amount = leaveHours.get(ac.getAccrualCategory()); totalAmount = totalAmount.add(amount); acDayDetails.set(index, amount); } } index++; } LeaveSummaryRow lsr = leaveSummary == null ? null : leaveSummary.getLeaveSummaryRowForAccrualCtgy(ac.getAccrualCategory()); displayMap.put("periodUsage", totalAmount); displayMap.put("availableBalance", BigDecimal.ZERO); displayMap.put("availableBalance", lsr == null ? BigDecimal.ZERO : lsr.getLeaveBalance()); displayMap.put("daysDetail", acDayDetails); displayMap.put("daysSize", acDayDetails.size()); acRows.add(displayMap); } } } return acRows; }
From source file:org.kuali.kpme.tklm.leave.batch.CarryOverJob.java
License:Educational Community License
@Override public void execute(JobExecutionContext context) throws JobExecutionException { String batchUserPrincipalId = getBatchUserPrincipalId(); if (batchUserPrincipalId != null) { JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); String leavePlan = jobDataMap.getString("leavePlan"); if (leavePlan != null) { LocalDate asOfDate = LocalDate.now(); LeavePlan leavePlanObj = getLeavePlanService().getLeavePlan(leavePlan, asOfDate); List<Assignment> assignments = getAssignmentService().getActiveAssignments(asOfDate); //holds a list of principalIds so this isn't run multiple time for the same person Set<String> principalIds = new HashSet<String>(); for (Assignment assignment : assignments) { String principalId = assignment.getPrincipalId(); if (assignment.getJob().isEligibleForLeave() && !principalIds.contains(principalId)) { PrincipalHRAttributes principalHRAttributes = getPrincipalHRAttributesService() .getPrincipalCalendar(principalId, asOfDate); principalIds.add(principalId); if (principalHRAttributes != null) { LocalDate serviceDate = principalHRAttributes.getServiceLocalDate(); if (serviceDate != null) { if (leavePlanObj != null && leavePlanObj.getLeavePlan() .equalsIgnoreCase(principalHRAttributes.getLeavePlan())) { DateTime leavePlanStartDate = getLeavePlanService() .getFirstDayOfLeavePlan(leavePlan, LocalDate.now()); DateTime lpPreviousLastDay = (new LocalDateTime(leavePlanStartDate)) .toDateTime().minus(1); DateTime lpPreviousFirstDay = getLeavePlanService() .getFirstDayOfLeavePlan(leavePlan, lpPreviousLastDay.toLocalDate()); List<LeaveBlock> prevYearCarryOverleaveBlocks = getLeaveBlockService() .getLeaveBlocksWithType(principalId, lpPreviousFirstDay.toLocalDate(), lpPreviousLastDay.toLocalDate(), LMConstants.LEAVE_BLOCK_TYPE.CARRY_OVER); LeaveSummary leaveSummary = getLeaveSummaryService() .getLeaveSummaryAsOfDateWithoutFuture(principalId, lpPreviousLastDay.toLocalDate()); //no existing carry over blocks. just create new if (CollectionUtils.isEmpty(prevYearCarryOverleaveBlocks)) { getLeaveBlockService().saveLeaveBlocks(createCarryOverLeaveBlocks( principalId, lpPreviousLastDay, leaveSummary)); } else { Map<String, LeaveBlock> existingCarryOver = new HashMap<String, LeaveBlock>( prevYearCarryOverleaveBlocks.size()); // just easier to get to things when in a map... for (LeaveBlock lb : prevYearCarryOverleaveBlocks) { existingCarryOver.put(lb.getAccrualCategory(), lb); }/*from www .j av a 2 s.c om*/ // update existing first for (Map.Entry<String, LeaveBlock> entry : existingCarryOver.entrySet()) { LeaveBlock carryOverBlock = entry.getValue(); LeaveSummaryRow lsr = leaveSummary .getLeaveSummaryRowForAccrualCtgy(entry.getKey()); //update values if (lsr.getAccruedBalance() != null) { if (lsr.getMaxCarryOver() != null && lsr.getAccruedBalance() .compareTo(lsr.getMaxCarryOver()) > 0) { carryOverBlock.setLeaveAmount(lsr.getMaxCarryOver()); } else { carryOverBlock.setLeaveAmount(lsr.getAccruedBalance()); } } getLeaveBlockService().updateLeaveBlock(carryOverBlock, batchUserPrincipalId); //remove row from leave summary leaveSummary.getLeaveSummaryRows().remove(lsr); } // create for any new accrual categories getLeaveBlockService().saveLeaveBlocks(createCarryOverLeaveBlocks( principalId, lpPreviousLastDay, leaveSummary)); } } } } } } } } else { String principalName = ConfigContext.getCurrentContextConfig() .getProperty(TkConstants.BATCH_USER_PRINCIPAL_NAME); LOG.error("Could not run batch jobs due to missing batch user " + principalName); } }
From source file:org.kuali.kpme.tklm.leave.batch.CarryOverJob.java
License:Educational Community License
private List<LeaveBlock> createCarryOverLeaveBlocks(String principalId, DateTime prevCalEndDate, LeaveSummary leaveSummary) {/*from w w w . j a v a2 s. c o m*/ List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>(); List<LeaveSummaryRow> leaveSummaryRows = leaveSummary.getLeaveSummaryRows(); if (leaveSummaryRows != null && !leaveSummaryRows.isEmpty()) { for (LeaveSummaryRow lsr : leaveSummaryRows) { AccrualCategory accrualCategory = getAccrualCategoryService() .getAccrualCategory(lsr.getAccrualCategoryId()); LeaveBlock leaveBlock = new LeaveBlock(); leaveBlock.setAccrualCategory(lsr.getAccrualCategory()); leaveBlock.setLeaveLocalDate(prevCalEndDate.toLocalDate()); leaveBlock.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.CARRY_OVER); //More than one earn code can be associated with an accrual category. Which one does this get? if (accrualCategory != null && accrualCategory.getEarnCode() != null) { leaveBlock.setEarnCode(accrualCategory.getEarnCode()); } leaveBlock.setAccrualGenerated(true); leaveBlock.setBlockId(0L); // ASk--Set null leaveBlock.setScheduleTimeOffId(null); if (lsr.getAccruedBalance() != null) { if (lsr.getMaxCarryOver() != null && lsr.getAccruedBalance().compareTo(lsr.getMaxCarryOver()) > 0) { leaveBlock.setLeaveAmount(lsr.getMaxCarryOver()); } else { leaveBlock.setLeaveAmount(lsr.getAccruedBalance()); } } leaveBlock.setPrincipalId(principalId); leaveBlock.setRequestStatus(HrConstants.REQUEST_STATUS.APPROVED); // Set EarnCode if (leaveBlock.getLeaveAmount() != null && leaveBlock.getEarnCode() != null) { leaveBlocks.add(leaveBlock); } } } return leaveBlocks; }
From source file:org.kuali.kpme.tklm.leave.block.LeaveBlockAggregate.java
License:Educational Community License
/** * build leaveBlockAggregate with given leaveBlocks, calendarEntry and dayIntervals * dayIntervals with full week span is for Time Calendar * @param LeaveBlocks/*ww w . j av a 2s. c o m*/ * @param leaveCalendarEntry * @param dayIntervals */ public LeaveBlockAggregate(List<LeaveBlock> leaveBlocks, CalendarEntry leaveCalendarEntry, List<Interval> dayIntervals) { this.leaveCalendarEntry = leaveCalendarEntry; for (Interval dayInt : dayIntervals) { List<LeaveBlock> dayLeaveBlocks = new ArrayList<LeaveBlock>(); DateTime localTime = dayInt.getStart().toLocalDateTime().toDateTime(); String intervalStartDateString = localTime.toLocalDate().toString(); for (LeaveBlock leaveBlock : leaveBlocks) { // if the interval end time is 0, ie the beginning of a day, use the date string of the interval start time // to check if the leave block should go into this interval. Leave blocks only have leaveDate, there's no leave time if (dayInt.getEnd().getHourOfDay() == 0) { String lbDateString = leaveBlock.getLeaveLocalDate().toString(); if (intervalStartDateString.equals(lbDateString)) { dayLeaveBlocks.add(leaveBlock); } } else { LocalDate localDate = leaveBlock.getLeaveLocalDate(); LocalDate dayIntBegin = dayInt.getStart().toLocalDate(); if (localDate.equals(dayIntBegin)) { dayLeaveBlocks.add(leaveBlock); } } } dayLeaveBlockList.add(dayLeaveBlocks); } }
From source file:org.kuali.kpme.tklm.leave.block.service.LeaveBlockServiceImpl.java
License:Educational Community License
@Override public void addLeaveBlocks(DateTime beginDate, DateTime endDate, CalendarEntry ce, String selectedEarnCode, BigDecimal hours, String description, Assignment selectedAssignment, String spanningWeeks, String leaveBlockType, String principalId) { DateTimeZone timezone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); DateTime calBeginDateTime = beginDate; DateTime calEndDateTime = endDate;/* w w w .j a v a 2s . co m*/ if (ce != null) { calBeginDateTime = ce.getBeginPeriodLocalDateTime().toDateTime(); calEndDateTime = ce.getEndPeriodLocalDateTime().toDateTime(); } else { LOG.error("Calendar Entry parameter is null."); return; // throw new RuntimeException("Calendar Entry parameter is null."); } Interval calendarInterval = new Interval(calBeginDateTime, calEndDateTime); // To create the correct interval by the given begin and end dates, // we need to plus one day on the end date to include that date List<Interval> leaveBlockIntervals = TKUtils.createDaySpan(beginDate.toLocalDate().toDateTimeAtStartOfDay(), endDate.toLocalDate().toDateTimeAtStartOfDay().plusDays(1), TKUtils.getSystemDateTimeZone()); // need to use beginDate and endDate of the calendar to find all leaveBlocks since LeaveCalendarDocument Id is not always available List<LeaveBlock> currentLeaveBlocks = getLeaveBlocks(principalId, calBeginDateTime.toLocalDate(), calEndDateTime.toLocalDate()); // use the current calendar's begin and end date to figure out if this pay period has a leaveDocument LeaveCalendarDocumentHeader lcdh = LmServiceLocator.getLeaveCalendarDocumentHeaderService() .getDocumentHeader(principalId, ce.getBeginPeriodLocalDateTime().toDateTime(), ce.getEndPeriodLocalDateTime().toDateTime()); String docId = lcdh == null ? null : lcdh.getDocumentId(); // TODO: need to integrate with the scheduled timeoff. Interval firstDay = null; DateTime currentDate = beginDate; for (Interval leaveBlockInt : leaveBlockIntervals) { if (calendarInterval.contains(leaveBlockInt)) { // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the leaveblock list if (StringUtils.isEmpty(spanningWeeks) && (leaveBlockInt.getStart().getDayOfWeek() == DateTimeConstants.SATURDAY || leaveBlockInt.getStart().getDayOfWeek() == DateTimeConstants.SUNDAY)) { // do nothing } else { // Currently, we store the accrual category value in the leave code table, but store accrual category id in the leaveBlock. // That's why there is a two step server call to get the id. This might be changed in the future. CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService() .getCurrentCalendarEntryByCalendarId(ce.getHrCalendarId(), new LocalDate().toDateTimeAtStartOfDay()); DateTime leaveBlockDate = leaveBlockInt.getStart(); String requestStatus = HrConstants.REQUEST_STATUS.USAGE; if (LmServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus( principalId, HrConstants.FLSA_STATUS_NON_EXEMPT, true)) { TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService() .getDocumentHeaderForDate(principalId, leaveBlockDate); if (tdh != null) { if (DateUtils.isSameDay(leaveBlockDate.toDate(), tdh.getEndDate()) || leaveBlockDate.isAfter(tdh.getEndDateTime())) { requestStatus = HrConstants.REQUEST_STATUS.PLANNED; } } else { requestStatus = HrConstants.REQUEST_STATUS.PLANNED; } } else { if (DateUtils.isSameDay(leaveBlockDate.toDate(), calendarEntry.getEndPeriodDateTime()) || leaveBlockDate.isAfter(calendarEntry.getEndPeriodFullDateTime())) { requestStatus = HrConstants.REQUEST_STATUS.PLANNED; } } EarnCode earnCodeObj = HrServiceLocator.getEarnCodeService().getEarnCode(selectedEarnCode, ce.getEndPeriodLocalDateTime().toDateTime().toLocalDate()); if (earnCodeObj != null && earnCodeObj.getRecordMethod().equals(HrConstants.RECORD_METHOD.TIME)) { if (firstDay != null) { if (!leaveBlockInt.contains(endDate)) { currentDate = leaveBlockInt.getStart(); } else if ((leaveBlockInt.getStartMillis() - endDate.getMillis()) != 0) { hours = TKUtils.getHoursBetween(leaveBlockInt.getStartMillis(), endDate.getMillis()); hours = negateHoursIfNecessary(leaveBlockType, hours); LeaveBlock leaveBlock = buildLeaveBlock(leaveBlockInt.getStart().toLocalDate(), docId, principalId, selectedEarnCode, hours, description, earnCodeObj.getAccrualCategory(), selectedAssignment, requestStatus, leaveBlockType, leaveBlockInt.getStart(), endDate); if (!currentLeaveBlocks.contains(leaveBlock)) { currentLeaveBlocks.add(leaveBlock); } break; } } if (leaveBlockInt.contains(currentDate)) { firstDay = leaveBlockInt; if (leaveBlockInt.contains(endDate) || (endDate.getMillis() == leaveBlockInt.getEnd().getMillis())) { hours = TKUtils.getHoursBetween(currentDate.getMillis(), endDate.getMillis()); hours = negateHoursIfNecessary(leaveBlockType, hours); LeaveBlock leaveBlock = buildLeaveBlock(leaveBlockInt.getStart().toLocalDate(), docId, principalId, selectedEarnCode, hours, description, earnCodeObj.getAccrualCategory(), selectedAssignment, requestStatus, leaveBlockType, currentDate, endDate); if (!currentLeaveBlocks.contains(leaveBlock)) { currentLeaveBlocks.add(leaveBlock); } break; } else { // create a leave block that wraps the 24 hr day hours = TKUtils.getHoursBetween(currentDate.getMillis(), firstDay.getEndMillis()); hours = negateHoursIfNecessary(leaveBlockType, hours); LeaveBlock leaveBlock = buildLeaveBlock(leaveBlockInt.getStart().toLocalDate(), docId, principalId, selectedEarnCode, hours, description, earnCodeObj.getAccrualCategory(), selectedAssignment, requestStatus, leaveBlockType, currentDate, firstDay.getEnd()); if (!currentLeaveBlocks.contains(leaveBlock)) { currentLeaveBlocks.add(leaveBlock); } } } } else { hours = negateHoursIfNecessary(leaveBlockType, hours); LeaveBlock leaveBlock = buildLeaveBlock(leaveBlockInt.getStart().toLocalDate(), docId, principalId, selectedEarnCode, hours, description, earnCodeObj.getAccrualCategory(), selectedAssignment, requestStatus, leaveBlockType, null, null); if (!currentLeaveBlocks.contains(leaveBlock)) { currentLeaveBlocks.add(leaveBlock); } } } } } saveLeaveBlocks(currentLeaveBlocks); }
From source file:org.kuali.kpme.tklm.leave.block.web.LeaveBlockController.java
License:Educational Community License
@RequestMapping(params = "methodToCall=submit") public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) { eventCount = 0;//w ww.j a va 2s . com sb.setLength(0); LeaveBlockForm leaveBlockForm = (LeaveBlockForm) form; if (leaveBlockForm.getFromDate() != null && leaveBlockForm.getToDate() != null && !leaveBlockForm.getFromDate().equals("") && !leaveBlockForm.getToDate().equals("")) { DateTime beginDate = new DateTime(leaveBlockForm.getFromDate()); DateTime endDate = new DateTime(leaveBlockForm.getToDate()); if (beginDate != null && endDate != null) { exportApprovedLeaves(beginDate.toLocalDate(), endDate.toLocalDate()); leaveBlockForm.setCalendarCount(String.valueOf(eventCount)); } } return getUIFModelAndView(leaveBlockForm); }
From source file:org.kuali.kpme.tklm.leave.calendar.LeaveCalendar.java
License:Educational Community License
public LeaveCalendar(String principalId, CalendarEntry calendarEntry, List<String> assignmentKeys) { super(calendarEntry); DateTime currentDisplayDateTime = getBeginDateTime(); DateTime endDisplayDateTime = getEndDateTime(); // Fill in the days if the first day or end day is in the middle of the week if (currentDisplayDateTime.getDayOfWeek() != DateTimeConstants.SUNDAY) { currentDisplayDateTime = currentDisplayDateTime.minusDays(currentDisplayDateTime.getDayOfWeek()); }/*from ww w . j av a2 s .c om*/ if (endDisplayDateTime.getDayOfWeek() != DateTimeConstants.SATURDAY) { endDisplayDateTime = endDisplayDateTime .plusDays(DateTimeConstants.SATURDAY - endDisplayDateTime.getDayOfWeek()); } LeaveCalendarWeek leaveCalendarWeek = new LeaveCalendarWeek(); Integer dayNumber = 0; List<LeaveBlock> blocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(principalId, calendarEntry.getBeginPeriodFullDateTime().toLocalDate(), calendarEntry.getEndPeriodFullDateTime().toLocalDate()); Map<String, List<LeaveBlock>> leaveBlockMap = new HashMap<String, List<LeaveBlock>>(); for (LeaveBlock lb : blocks) { String key = lb.getLeaveLocalDate().toString(); if (leaveBlockMap.containsKey(key)) { leaveBlockMap.get(key).add(lb); } else { leaveBlockMap.put(key, createNewLeaveBlockList(lb)); } } //KPME-2560 If leave calendar document is final status, then User wont be able to add leave blocks to the calendar. Boolean dayEditableFlag = true; LeaveCalendarDocumentHeader header = LmServiceLocator.getLeaveCalendarDocumentHeaderService() .getDocumentHeader(principalId, calendarEntry.getBeginPeriodFullDateTime(), calendarEntry.getEndPeriodFullDateTime()); if (header != null && header.getDocumentStatus().equals(HrConstants.ROUTE_STATUS.FINAL)) dayEditableFlag = false; while (currentDisplayDateTime.isBefore(endDisplayDateTime) || currentDisplayDateTime.isEqual(endDisplayDateTime)) { LeaveCalendarDay leaveCalendarDay = new LeaveCalendarDay(); // If the day is not within the current pay period, mark them as read only (gray) if (currentDisplayDateTime.isBefore(getBeginDateTime()) || currentDisplayDateTime.isEqual(getEndDateTime()) || currentDisplayDateTime.isAfter(getEndDateTime())) { leaveCalendarDay.setGray(true); } else { // This is for the div id of the days on the calendar. // It creates a day id like day_11/01/2011 which will make day parsing easier in the javascript. // leaveCalendarDay.setDayNumberDelta(currDateTime.toString(HrConstants.DT_BASIC_DATE_FORMAT)); // leaveCalendarDay.setDayNumberDelta(currDateTime.getDayOfMonth()); leaveCalendarDay.setDayNumberDelta(dayNumber); LocalDate leaveDate = currentDisplayDateTime.toLocalDate(); List<LeaveBlock> lbs = leaveBlockMap.get(currentDisplayDateTime.toLocalDate().toString()); if (lbs == null) { lbs = Collections.emptyList(); } // use given assignmentKeys to control leave blocks displayed on the calendar if (CollectionUtils.isNotEmpty(lbs) && CollectionUtils.isNotEmpty(assignmentKeys)) { List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService() .filterLeaveBlocksForLeaveCalendar(lbs, assignmentKeys); leaveCalendarDay.setLeaveBlocks(leaveBlocks); } else { leaveCalendarDay.setLeaveBlocks(lbs); } if (HrServiceLocator.getHRPermissionService().canViewLeaveTabsWithNEStatus()) { TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService() .getDocumentHeaderForDate(principalId, leaveDate.toDateTimeAtStartOfDay()); if (tdh != null) { if (DateUtils.isSameDay(leaveDate.toDate(), tdh.getEndDate()) || leaveDate.isAfter(LocalDate.fromDateFields(tdh.getEndDate()))) { leaveCalendarDay.setDayEditable(true); } } else { leaveCalendarDay.setDayEditable(true); } } else { leaveCalendarDay.setDayEditable(true); } //KPME-2560 If leave calendar document is final status, then User wont be able to add leave blocks to the calendar. if (!dayEditableFlag) leaveCalendarDay.setDayEditable(false); dayNumber++; } leaveCalendarDay.setDayNumberString(currentDisplayDateTime.dayOfMonth().getAsShortText()); leaveCalendarDay.setDateString(currentDisplayDateTime.toString(HrConstants.DT_BASIC_DATE_FORMAT)); leaveCalendarWeek.getDays().add(leaveCalendarDay); if (leaveCalendarWeek.getDays().size() == DateTimeConstants.DAYS_PER_WEEK) { getWeeks().add(leaveCalendarWeek); leaveCalendarWeek = new LeaveCalendarWeek(); } currentDisplayDateTime = currentDisplayDateTime.plusDays(1); } if (!leaveCalendarWeek.getDays().isEmpty()) { getWeeks().add(leaveCalendarWeek); } boolean isPlanningCal = LmServiceLocator.getLeaveCalendarService().isLeavePlanningCalendar(principalId, calendarEntry.getBeginPeriodFullDateTime().toLocalDate(), calendarEntry.getEndPeriodFullDateTime().toLocalDate()); Map<String, String> earnCodes = HrServiceLocator.getEarnCodeService().getEarnCodesForDisplay(principalId, isPlanningCal); setEarnCodeList(earnCodes); }
From source file:org.kuali.kpme.tklm.leave.calendar.LeaveRequestCalendar.java
License:Educational Community License
public LeaveRequestCalendar(DateTime beginDateTime, DateTime endDateTime, Map<String, List<LeaveRequestDocument>> leaveReqDocsMap, Map<String, List<LeaveBlock>> leaveBlocksMap, Map<String, List<LeaveBlockHistory>> disapprovedLBMap, String calendarType) { this.calendarType = calendarType; setBeginDateTime(beginDateTime);// w w w . j a va2s . c o m setEndDateTime(endDateTime); DateTime currentDisplayDateTime = new DateTime(beginDateTime.getMillis()); DateTime endDisplayDateTime = new DateTime(endDateTime.getMillis()); // Fill in the days if the first day or end day is in the middle of the week if (currentDisplayDateTime.getDayOfWeek() != DateTimeConstants.SUNDAY) { currentDisplayDateTime = currentDisplayDateTime.minusDays(currentDisplayDateTime.getDayOfWeek()); } if (endDisplayDateTime.getDayOfWeek() != DateTimeConstants.SATURDAY) { endDisplayDateTime = endDisplayDateTime .plusDays(DateTimeConstants.SATURDAY - endDisplayDateTime.getDayOfWeek()); } LeaveRequestCalendarWeek leaveReqCalendarWeek = new LeaveRequestCalendarWeek(); Integer dayNumber = 0; while (currentDisplayDateTime.isBefore(endDisplayDateTime) || currentDisplayDateTime.isEqual(endDisplayDateTime)) { LeaveRequestCalendarDay leaveReqCalendarDay = new LeaveRequestCalendarDay(); // If the day is not within the current pay period, mark them as read only (gray) if (StringUtils.equalsIgnoreCase("M", calendarType) && (currentDisplayDateTime.isBefore(getBeginDateTime()) || currentDisplayDateTime.isEqual(getEndDateTime()) || currentDisplayDateTime.isAfter(getEndDateTime()))) { leaveReqCalendarDay.setGray(true); } else { // This is for the div id of the days on the calendar. // It creates a day id like day_11/01/2011 which will make day parsing easier in the javascript. leaveReqCalendarDay.setDayNumberDelta(dayNumber); List<LeaveRequestDocument> reqDocs = leaveReqDocsMap .get(currentDisplayDateTime.toLocalDate().toString()); List<LeaveBlock> leaveBlocks = leaveBlocksMap.get(currentDisplayDateTime.toLocalDate().toString()); List<LeaveBlockHistory> disapprovedBlocks = disapprovedLBMap .get(currentDisplayDateTime.toLocalDate().toString()); List<LeaveRequestApprovalRow> rowList = new ArrayList<LeaveRequestApprovalRow>(); if (reqDocs == null) { reqDocs = Collections.emptyList(); } if (leaveBlocks == null) { leaveBlocks = Collections.emptyList(); } List<String> leaveBlockIds = new ArrayList<String>(); if (!reqDocs.isEmpty()) { for (LeaveRequestDocument lrd : reqDocs) { LeaveBlock lb = lrd.getLeaveBlock(); leaveBlockIds.add(lb.getLmLeaveBlockId()); String principalId = lb.getPrincipalId(); LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow(); // Set Employee Name EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); if (entityNamePrincipalName != null) { aRow.setPrincipalId(principalId); aRow.setEmployeeName( entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY : entityNamePrincipalName.getDefaultName().getCompositeName()); } aRow.setLeaveRequestDocId(lrd.getDocumentNumber()); aRow.setLeaveCode(lb.getEarnCode()); aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate())); aRow.setRequestedHours(lb.getLeaveAmount().toString()); aRow.setDescription( lrd.getDescription() == null ? lb.getDescription() : lrd.getDescription()); aRow.setAssignmentTitle(lb.getAssignmentTitle()); aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase()); rowList.add(aRow); } } if (!leaveBlocks.isEmpty()) { for (LeaveBlock lb : leaveBlocks) { if (!leaveBlockIds.contains(lb.getLmLeaveBlockId())) { String principalId = lb.getPrincipalId(); LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow(); // Set Employee Name EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator .getIdentityService().getDefaultNamesForPrincipalId(principalId); if (entityNamePrincipalName != null) { aRow.setPrincipalId(principalId); aRow.setEmployeeName( entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY : entityNamePrincipalName.getDefaultName().getCompositeName()); } aRow.setLeaveCode(lb.getEarnCode()); aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate())); aRow.setRequestedHours(lb.getLeaveAmount().toString()); aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase()); aRow.setDescription(lb.getDescription()); aRow.setAssignmentTitle(lb.getAssignmentTitle()); rowList.add(aRow); } } } // Adding disapproved blocks. if (disapprovedBlocks != null && !disapprovedBlocks.isEmpty()) { for (LeaveBlockHistory lb : disapprovedBlocks) { String principalId = lb.getPrincipalId(); LeaveRequestApprovalRow aRow = new LeaveRequestApprovalRow(); // Set Employee Name EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); if (entityNamePrincipalName != null) { aRow.setPrincipalId(principalId); aRow.setEmployeeName( entityNamePrincipalName.getDefaultName() == null ? StringUtils.EMPTY : entityNamePrincipalName.getDefaultName().getCompositeName()); } aRow.setLeaveCode(lb.getEarnCode()); aRow.setRequestedDate(TKUtils.formatDate(lb.getLeaveLocalDate())); aRow.setRequestedHours(lb.getLeaveAmount().toString()); aRow.setRequestStatus(lb.getRequestStatusString().toLowerCase()); aRow.setDescription(lb.getDescription()); aRow.setAssignmentTitle(lb.getAssignmentTitle()); rowList.add(aRow); } } leaveReqCalendarDay.setLeaveReqRows(rowList); if (!rowList.isEmpty() && rowList.size() > 0) { requestList.addAll(rowList); } dayNumber++; } leaveReqCalendarDay.setDayNumberString(currentDisplayDateTime.dayOfMonth().getAsShortText()); leaveReqCalendarDay .setDateString(currentDisplayDateTime.toString(HrConstants.DateTimeFormats.BASIC_DATE_FORMAT)); leaveReqCalendarWeek.getDays().add(leaveReqCalendarDay); if (leaveReqCalendarWeek.getDays().size() == DateTimeConstants.DAYS_PER_WEEK) { getWeeks().add(leaveReqCalendarWeek); leaveReqCalendarWeek = new LeaveRequestCalendarWeek(); } currentDisplayDateTime = currentDisplayDateTime.plusDays(1); } if (!leaveReqCalendarWeek.getDays().isEmpty()) { getWeeks().add(leaveReqCalendarWeek); } }
From source file:org.kuali.kpme.tklm.leave.calendar.service.LeaveCalendarServiceImpl.java
License:Educational Community License
@Override public LeaveCalendarDocument openLeaveCalendarDocument(String principalId, CalendarEntry calEntry) throws WorkflowException { LeaveCalendarDocument doc;/* w ww . j a v a2 s . c o m*/ DateTime begin = calEntry.getBeginPeriodFullDateTime(); DateTime end = calEntry.getEndPeriodFullDateTime(); LeaveCalendarDocumentHeader header = LmServiceLocator.getLeaveCalendarDocumentHeaderService() .getDocumentHeader(principalId, begin, end); if (header == null) { EntityNamePrincipalName person = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); String principalName = person != null && person.getDefaultName() != null ? person.getDefaultName().getCompositeName() : StringUtils.EMPTY; String beginDateString = TKUtils.formatDate(begin.toLocalDate()); String endDateString = TKUtils.formatDate(end.toLocalDate()); String leaveCalendarDocumentTitle = LeaveCalendarDocument.LEAVE_CALENDAR_DOCUMENT_TYPE + " - " + principalName + " (" + principalId + ") - " + beginDateString + "-" + endDateString; doc = initiateWorkflowDocument(principalId, begin, end, calEntry, LeaveCalendarDocument.LEAVE_CALENDAR_DOCUMENT_TYPE, leaveCalendarDocumentTitle); } else { doc = getLeaveCalendarDocument(header.getDocumentId()); } if (doc != null) { doc.setCalendarEntry(calEntry); } // TODO: need to set the summary return doc; }