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.time.approval.service.TimeApproveServiceImpl.java
License:Educational Community License
@Override public List<ApprovalTimeSummaryRow> getApprovalSummaryRows(String calGroup, List<String> principalIds, List<String> payCalendarLabels, CalendarEntry payCalendarEntry) { DateTime payBeginDate = payCalendarEntry.getBeginPeriodFullDateTime(); DateTime payEndDate = payCalendarEntry.getEndPeriodFullDateTime(); List<Map<String, Object>> timeBlockJsonMap = new ArrayList<Map<String, Object>>(); List<ApprovalTimeSummaryRow> rows = new LinkedList<ApprovalTimeSummaryRow>(); Map<String, TimesheetDocumentHeader> principalDocumentHeader = getPrincipalDocumentHeader(principalIds, payBeginDate, payEndDate);//from w w w .j av a 2 s . c o m Calendar payCalendar = HrServiceLocator.getCalendarService() .getCalendar(payCalendarEntry.getHrCalendarId()); DateTimeZone dateTimeZone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); List<Interval> dayIntervals = TKUtils.getDaySpanForCalendarEntry(payCalendarEntry); String color = null; Map<String, String> userColorMap = new HashMap<String, String>(); Set<String> randomColors = new HashSet<String>(); for (String principalId : principalIds) { TimesheetDocumentHeader tdh = new TimesheetDocumentHeader(); String documentId = ""; if (principalDocumentHeader.containsKey(principalId)) { tdh = principalDocumentHeader.get(principalId); documentId = principalDocumentHeader.get(principalId).getDocumentId(); } List<TimeBlock> timeBlocks = new ArrayList<TimeBlock>(); List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>(); List<Note> notes = new ArrayList<Note>(); List<String> warnings = new ArrayList<String>(); ApprovalTimeSummaryRow approvalSummaryRow = new ApprovalTimeSummaryRow(); if (principalDocumentHeader.containsKey(principalId)) { approvalSummaryRow.setApprovalStatus(HrConstants.DOC_ROUTE_STATUS.get(tdh.getDocumentStatus())); } if (StringUtils.isNotBlank(documentId)) { TimesheetDocument td = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId); timeBlocks = td.getTimeBlocks(); //timeBlocks = TkServiceLocator.getTimeBlockService() // .getTimeBlocks(documentId); List<String> assignKeys = new ArrayList<String>(); for (Assignment a : td.getAssignments()) { assignKeys.add(a.getAssignmentKey()); } leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForTimeCalendar(principalId, payBeginDate.toLocalDate(), payEndDate.toLocalDate(), assignKeys); notes = getNotesForDocument(documentId); Map<String, List<LocalDate>> earnCodeMap = new HashMap<String, List<LocalDate>>(); for (TimeBlock tb : td.getTimeBlocks()) { if (!earnCodeMap.containsKey(tb.getEarnCode())) { List<LocalDate> lst = new ArrayList<LocalDate>(); lst.add(tb.getBeginDateTime().toLocalDate()); earnCodeMap.put(tb.getEarnCode(), lst); } else earnCodeMap.get(tb.getEarnCode()).add(tb.getBeginDateTime().toLocalDate()); } warnings = HrServiceLocator.getEarnCodeGroupService().getWarningTextFromEarnCodeGroups(earnCodeMap); // Get Timesheet blocks List<Interval> intervals = TKUtils.getFullWeekDaySpanForCalendarEntry(payCalendarEntry); TkTimeBlockAggregate tbAggregate = buildAndMergeAggregates(timeBlocks, leaveBlocks, payCalendarEntry, payCalendar, dayIntervals); // TkTimeBlockAggregate tbAggregate = new TkTimeBlockAggregate(timeBlocks, payCalendarEntry, payCalendar, true,intervals); // use both time aggregate to populate the calendar TkCalendar cal = TkCalendar.getCalendar(tbAggregate); for (CalendarWeek week : cal.getWeeks()) { for (CalendarDay day : week.getDays()) { TkCalendarDay tkDay = (TkCalendarDay) day; for (TimeBlockRenderer renderer : tkDay.getBlockRenderers()) { Map<String, Object> timeBlockMap = new HashMap<String, Object>(); // set title.. StringBuffer title = new StringBuffer(); if (!renderer.getEarnCodeType().equalsIgnoreCase(HrConstants.EARN_CODE_AMOUNT)) { if (renderer.getDetailRenderers() != null && !renderer.getDetailRenderers().isEmpty()) { for (TimeHourDetailRenderer thdr : renderer.getDetailRenderers()) { title.append("\n"); title = new StringBuffer(thdr.getTitle()); title.append(" - " + thdr.getHours()); } } } timeBlockMap.put("start", tkDay.getDateString()); StringBuffer titleString = new StringBuffer(); titleString.append(renderer.getTitle()); if (renderer.getTimeRange() != null && !renderer.getTimeRange().isEmpty()) { titleString.append("\n" + renderer.getTimeRange()); } titleString.append("\n" + title.toString()); timeBlockMap.put("title", titleString.toString()); timeBlockMap.put("id", tkDay.getDayNumberString()); if (!userColorMap.containsKey(principalId)) { color = TKUtils.getRandomColor(randomColors); randomColors.add(color); userColorMap.put(principalId, color); } color = userColorMap.get(principalId); timeBlockMap.put("color", userColorMap.get(principalId)); timeBlockMap.put("className", "event-approval"); timeBlockJsonMap.add(timeBlockMap); } } } warnings = HrServiceLocator.getEarnCodeGroupService() .getWarningTextFromEarnCodeGroups(td.getEarnCodeMap()); } Map<String, Set<String>> transactionalWarnings = LeaveCalendarValidationUtil .validatePendingTransactions(principalId, payCalendarEntry.getBeginPeriodFullDateTime().toLocalDate(), payCalendarEntry.getEndPeriodFullDateTime().toLocalDate()); warnings.addAll(transactionalWarnings.get("infoMessages")); warnings.addAll(transactionalWarnings.get("warningMessages")); warnings.addAll(transactionalWarnings.get("actionMessages")); Map<String, Set<String>> eligibleTransfers = findWarnings(principalId, payCalendarEntry); warnings.addAll(eligibleTransfers.get("warningMessages")); Map<String, BigDecimal> hoursToPayLabelMap = getHoursToPayDayMap(principalId, payEndDate, payCalendarLabels, timeBlocks, leaveBlocks, null, payCalendarEntry, payCalendar, dateTimeZone, dayIntervals); Map<String, BigDecimal> hoursToFlsaPayLabelMap = getHoursToFlsaWeekMap(principalId, payEndDate, payCalendarLabels, timeBlocks, leaveBlocks, null, payCalendarEntry, payCalendar, dateTimeZone, dayIntervals); EntityNamePrincipalName name = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); approvalSummaryRow.setName(name != null && name.getDefaultName() != null && name.getDefaultName().getCompositeName() != null ? name.getDefaultName().getCompositeName() : principalId); approvalSummaryRow.setPrincipalId(principalId); approvalSummaryRow.setColor(userColorMap.get(principalId)); approvalSummaryRow.setPayCalendarGroup(calGroup); approvalSummaryRow.setDocumentId(documentId); approvalSummaryRow.setHoursToPayLabelMap(hoursToPayLabelMap); approvalSummaryRow.setHoursToFlsaPayLabelMap(hoursToFlsaPayLabelMap); approvalSummaryRow.setPeriodTotal(hoursToPayLabelMap.get("Period Total")); approvalSummaryRow.setLstTimeBlocks(timeBlocks); approvalSummaryRow.setNotes(notes); approvalSummaryRow.setWarnings(warnings); // Compare last clock log versus now and if > threshold // highlight entry ClockLog lastClockLog = TkServiceLocator.getClockLogService().getLastClockLog(principalId); if (isSynchronousUser(principalId)) { approvalSummaryRow.setClockStatusMessage(createLabelForLastClockLog(lastClockLog)); } if (lastClockLog != null && (StringUtils.equals(lastClockLog.getClockAction(), TkConstants.CLOCK_IN) || StringUtils.equals(lastClockLog.getClockAction(), TkConstants.LUNCH_IN))) { DateTime startTime = lastClockLog.getClockDateTime(); DateTime endTime = new DateTime(); Hours hour = Hours.hoursBetween(startTime, endTime); if (hour != null) { int elapsedHours = hour.getHours(); if (elapsedHours >= TkConstants.NUMBER_OF_HOURS_CLOCKED_IN_APPROVE_TAB_HIGHLIGHT) { approvalSummaryRow.setClockedInOverThreshold(true); } } } rows.add(approvalSummaryRow); } String outputString = JSONValue.toJSONString(timeBlockJsonMap); if (rows != null && !rows.isEmpty()) { rows.get(0).setOutputString(outputString); } return rows; }
From source file:org.kuali.kpme.tklm.time.batch.ClockedInEmployeeJob.java
License:Educational Community License
public void execute(JobExecutionContext context) throws JobExecutionException { //Get Configuration Settings BigDecimal hourLimit = getHourLimit(); String jobAction = getJobAction(); String batchJobPrincipalId = BatchJobUtil.getBatchUserPrincipalId(); // code to send one email per approver // Map<String, Map<String, String>> notificationMap = new HashMap<String, Map<String, String>>(); DateTime asOfDate = new LocalDate().toDateTimeAtStartOfDay(); List<CalendarEntry> calendarEntries = HrServiceLocator.getCalendarEntryService() .getCurrentCalendarEntriesNeedsScheduled(30, asOfDate); for (CalendarEntry calendarEntry : calendarEntries) { Calendar calendar = HrServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId()); if (StringUtils.equals(calendar.getCalendarTypes(), "Pay")) { DateTime beginDate = calendarEntry.getBeginPeriodFullDateTime(); DateTime endDate = calendarEntry.getEndPeriodFullDateTime(); List<TimesheetDocumentHeader> timesheetDocumentHeaders = TkServiceLocator .getTimesheetDocumentHeaderService().getDocumentHeaders(beginDate, endDate); for (TimesheetDocumentHeader timesheetDocumentHeader : timesheetDocumentHeaders) { String principalId = timesheetDocumentHeader.getPrincipalId(); List<Assignment> assignments = HrServiceLocator.getAssignmentService() .getAllAssignmentsByCalEntryForTimeCalendar(principalId, calendarEntry); for (Assignment assignment : assignments) { String groupKeyCode = assignment.getGroupKeyCode(); String jobNumber = String.valueOf(assignment.getJobNumber()); String workArea = String.valueOf(assignment.getWorkArea()); String task = String.valueOf(assignment.getTask()); ClockLog lastClockLog = TkServiceLocator.getClockLogService().getLastClockLog(groupKeyCode, principalId, jobNumber, workArea, task, calendarEntry); if (lastClockLog != null && TkConstants.ON_THE_CLOCK_CODES.contains(lastClockLog.getClockAction())) { DateTime lastClockLogDateTime = lastClockLog.getClockDateTime(); DateTime currentDate = new DateTime(); Period p = new Period(lastClockLogDateTime, currentDate); BigDecimal hoursBetween = new BigDecimal(p.getHours()); BigDecimal dayHours = new BigDecimal(p.getDays() * 24); hoursBetween = hoursBetween.add(dayHours); if (hoursBetween.compareTo(hourLimit) > 0) { if (jobAction.equals("NOTIFY")) { //code to send one notification per employee to all approvers of employee for (Person approver : getApprovers(assignment.getWorkArea())) { EntityNamePrincipalName employee = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); String approverSubject = "Employee Clocked In Over " + hourLimit.toString() + " Hours Notification"; StringBuilder approverNotification = new StringBuilder(); approverNotification.append(employee.getPrincipalName() + " (" + principalId + ") has been clocked in since "); SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM d yyyy HH:mm a"); String dateTime = sdf.format( new java.sql.Date(lastClockLog.getClockDateTime().getMillis())); approverNotification.append(dateTime); approverNotification.append( " for work area " + assignment.getWorkAreaObj().getDescription()); HrServiceLocator.getKPMENotificationService().sendNotification( approverSubject, approverNotification.toString(), approver.getPrincipalId()); }/*from w ww. j a v a 2 s . c o m*/ /* Code to send one email per approver - Create notification Map<String, String> hourInfo = new HashMap<String, String>(); hourInfo.put(principalId, hoursBetween.toString()); for (Person person : getApprovers(lastClockLog.getWorkArea())) { if (notificationMap.containsKey(person.getPrincipalId())) { notificationMap.get(person.getPrincipalId()).put(principalId, hoursBetween.toString()); } else { notificationMap.put(person.getPrincipalId(), hourInfo); } } */ } else if (jobAction.equals("CLOCK_OUT")) { //Clock User Out ClockLog clockOut = TkServiceLocator.getClockLogService().processClockLog( principalId, timesheetDocumentHeader.getDocumentId(), currentDate, assignment, calendarEntry, TKUtils.getIPNumber(), currentDate.toLocalDate(), "CO", true, batchJobPrincipalId); TkServiceLocator.getClockLogService().saveClockLog(clockOut); // Notify User String employeeSubject = "You have been clocked out of " + assignment.getAssignmentDescription(); StringBuilder employeeNotification = new StringBuilder(); employeeNotification.append( "You have been Clocked out of " + assignment.getAssignmentDescription() + " on " + clockOut.getClockDateTime()); HrServiceLocator.getKPMENotificationService().sendNotification(employeeSubject, employeeNotification.toString(), principalId); //add Note to time sheet Note.Builder builder = Note.Builder .create(timesheetDocumentHeader.getDocumentId(), batchJobPrincipalId); builder.setCreateDate(new DateTime()); builder.setText("Clock out from " + assignment.getAssignmentDescription() + " on " + clockOut.getClockDateTime() + " was initiated by the Clocked In Employee Batch Job"); KewApiServiceLocator.getNoteService().createNote(builder.build()); } } } } } } } /* code to send one email per approver for (Map.Entry<String, Map<String, String>> approverEntry : notificationMap.entrySet()) { String subject = "Users clocked in over " + hourLimit.toString() + " hours"; StringBuilder notification = new StringBuilder(); notification.append("The following users have been clocked in for over " + hourLimit.toString() + " hours:"); notification.append(SystemUtils.LINE_SEPARATOR); for (Map.Entry<String, String> employeeEntry : approverEntry.getValue().entrySet()) { notification.append(KimApiServiceLocator.getPersonService().getPerson(employeeEntry.getKey()).getPrincipalName()); notification.append(" (" + employeeEntry.getKey() + ") : " + employeeEntry.getValue() + " hours"); notification.append(SystemUtils.LINE_SEPARATOR); } HrServiceLocator.getKPMENotificationService().sendNotification(subject, notification.toString(), approverEntry.getKey()); } */ }
From source file:org.kuali.kpme.tklm.time.batch.EmployeeApprovalJob.java
License:Educational Community License
public void execute(JobExecutionContext context) throws JobExecutionException { try {/*from ww w . j a v a 2 s .c o m*/ JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); String batchUserPrincipalId = getBatchUserPrincipalId(); String hrCalendarEntryId = jobDataMap.getString("hrCalendarEntryId"); CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService() .getCalendarEntry(hrCalendarEntryId); Calendar calendar = HrServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId()); DateTime beginDate = calendarEntry.getBeginPeriodFullDateTime(); DateTime endDate = calendarEntry.getEndPeriodFullDateTime(); if (StringUtils.equals(calendar.getCalendarTypes(), "Pay")) { List<TimesheetDocumentHeader> timesheetDocumentHeaders = TkServiceLocator .getTimesheetDocumentHeaderService().getDocumentHeaders(beginDate, endDate); for (TimesheetDocumentHeader timesheetDocumentHeader : timesheetDocumentHeaders) { if (timesheetDocumentHeader != null) { String docId = timesheetDocumentHeader.getDocumentId(); TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService() .getTimesheetDocument(docId); if (timesheetDocument != null) { if (TkConstants.EMPLOYEE_APPROVAL_DOC_STATUS .contains(KEWServiceLocator.getRouteHeaderService().getDocumentStatus(docId))) { // use the range of the calendar entry to retrieve the correct PrincipalHrAtrribute record for the employee // then check if the calendar name/id matches the one from the calendar entry String principalId = timesheetDocument.getPrincipalId(); PrincipalHRAttributes phraRecord = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(principalId, endDate.toLocalDate()); if (phraRecord != null && phraRecord.getPayCalendar().equals(calendar.getCalendarName())) { TkServiceLocator.getTimesheetService().routeTimesheet(batchUserPrincipalId, timesheetDocument, HrConstants.BATCH_JOB_ACTIONS.BATCH_JOB_ROUTE); } } } } } } else if (StringUtils.equals(calendar.getCalendarTypes(), "Leave")) { List<LeaveCalendarDocumentHeader> leaveCalendarDocumentHeaders = LmServiceLocator .getLeaveCalendarDocumentHeaderService().getDocumentHeaders(beginDate, endDate); for (LeaveCalendarDocumentHeader leaveCalendarDocumentHeader : leaveCalendarDocumentHeaders) { if (leaveCalendarDocumentHeader != null) { String docId = leaveCalendarDocumentHeader.getDocumentId(); LeaveCalendarDocument leaveCalendarDocument = LmServiceLocator.getLeaveCalendarService() .getLeaveCalendarDocument(docId); if (TkConstants.EMPLOYEE_APPROVAL_DOC_STATUS .contains(KEWServiceLocator.getRouteHeaderService().getDocumentStatus(docId))) { String principalId = leaveCalendarDocument.getPrincipalId(); PrincipalHRAttributes phraRecord = HrServiceLocator.getPrincipalHRAttributeService() .getPrincipalCalendar(principalId, endDate.toLocalDate()); if (phraRecord != null && phraRecord.getLeaveCalendar().equals(calendar.getCalendarName())) { LmServiceLocator.getLeaveCalendarService().routeLeaveCalendar(batchUserPrincipalId, leaveCalendarDocument, HrConstants.BATCH_JOB_ACTIONS.BATCH_JOB_ROUTE); } } } } } } catch (Exception ex) { TkServiceLocator.getBatchJobService().updateStatus(context.getJobDetail(), BatchJobService.FAILED_JOB_STATUS_CODE); ex.printStackTrace(); } TkServiceLocator.getBatchJobService().updateStatus(context.getJobDetail(), BatchJobService.SUCCEEDED_JOB_STATUS_CODE); }
From source file:org.kuali.kpme.tklm.time.batch.EndPayPeriodJob.java
License:Educational Community License
public void execute(JobExecutionContext context) throws JobExecutionException { String batchUserPrincipalId = getBatchUserPrincipalId(); if (batchUserPrincipalId != null) { JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); String hrCalendarEntryId = jobDataMap.getString("hrCalendarEntryId"); String tkClockLogId = jobDataMap.getString("tkClockLogId"); CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService() .getCalendarEntry(hrCalendarEntryId); Calendar calendar = HrServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId()); calendarEntry.setCalendarObj(calendar); DateTime beginPeriodDateTime = calendarEntry.getBeginPeriodFullDateTime(); DateTime endPeriodDateTime = calendarEntry.getEndPeriodFullDateTime(); ClockLog openClockLog = TkServiceLocator.getClockLogService().getClockLog(tkClockLogId); String ipAddress = openClockLog.getIpAddress(); String principalId = openClockLog.getPrincipalId(); TimesheetDocumentHeader timesheetDocumentHeader = TkServiceLocator.getTimesheetDocumentHeaderService() .getDocumentHeader(principalId, beginPeriodDateTime, endPeriodDateTime); if (timesheetDocumentHeader != null) { TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService() .getTimesheetDocument(timesheetDocumentHeader.getDocumentId()); AssignmentDescriptionKey assignmentKey = new AssignmentDescriptionKey(openClockLog.getJobNumber(), openClockLog.getWorkArea(), openClockLog.getTask()); Assignment assignment = timesheetDocument.getAssignment(assignmentKey); TkServiceLocator.getClockLogService().processClockLog(endPeriodDateTime, assignment, calendarEntry, ipAddress, endPeriodDateTime.toLocalDate(), timesheetDocument, TkConstants.CLOCK_OUT, false, principalId, batchUserPrincipalId); TkServiceLocator.getClockLogService().processClockLog(beginPeriodDateTime, assignment, calendarEntry, ipAddress, beginPeriodDateTime.toLocalDate(), timesheetDocument, TkConstants.CLOCK_IN, false, principalId, batchUserPrincipalId); }// ww w .j av a 2 s . c om } 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.time.detail.validation.TimeDetailValidationUtil.java
License:Educational Community License
public static List<String> validateTimeEntryDetails(BigDecimal hours, BigDecimal amount, String startTimeS, String endTimeS, String startDateS, String endDateS, TimesheetDocument timesheetDocument, String selectedEarnCode, String selectedAssignment, boolean acrossDays, String timeblockId, String overtimePref, boolean spanningWeeks) { List<String> errors = new ArrayList<String>(); if (timesheetDocument == null) { errors.add("No timesheet document found."); }//w ww. ja v a 2s . c o m if (errors.size() > 0) return errors; CalendarEntry payCalEntry = timesheetDocument.getCalendarEntry(); errors.addAll(TimeDetailValidationUtil.validateDates(startDateS, endDateS)); errors.addAll(TimeDetailValidationUtil.validateTimes(startTimeS, endTimeS)); if (errors.size() > 0) return errors; Long startTime; Long endTime; startTime = TKUtils.convertDateStringToDateTimeWithoutZone(startDateS, startTimeS).getMillis(); endTime = TKUtils.convertDateStringToDateTimeWithoutZone(endDateS, endTimeS).getMillis(); errors.addAll(validateInterval(payCalEntry, startTime, endTime)); if (errors.size() > 0) return errors; EarnCode earnCode = new EarnCode(); if (StringUtils.isNotBlank(selectedEarnCode)) { earnCode = HrServiceLocator.getEarnCodeService().getEarnCode(selectedEarnCode, payCalEntry.getEndPeriodFullDateTime().toLocalDate()); if (earnCode != null && earnCode.getRecordMethod() != null && earnCode.getRecordMethod().equalsIgnoreCase(HrConstants.EARN_CODE_TIME)) { if (startTimeS == null) errors.add("The start time is blank."); if (endTimeS == null) errors.add("The end time is blank."); if (startTime - endTime == 0) errors.add("Start time and end time cannot be equivalent"); } } if (errors.size() > 0) return errors; DateTime startTemp = new DateTime(startTime); DateTime endTemp = new DateTime(endTime); if (errors.size() == 0 && !acrossDays && !StringUtils.equals(TkConstants.EARN_CODE_CPE, overtimePref)) { Hours hrs = Hours.hoursBetween(startTemp, endTemp); if (hrs.getHours() >= 24) errors.add("One timeblock cannot exceed 24 hours"); } if (errors.size() > 0) return errors; //Check that assignment is valid for both days AssignmentDescriptionKey assignKey = HrServiceLocator.getAssignmentService() .getAssignmentDescriptionKey(selectedAssignment); Assignment assign = HrServiceLocator.getAssignmentService().getAssignment(assignKey, startTemp.toLocalDate()); if (assign == null) errors.add("Assignment is not valid for start date " + TKUtils.formatDate(new LocalDate(startTime))); assign = HrServiceLocator.getAssignmentService().getAssignment(assignKey, endTemp.toLocalDate()); if (assign == null) errors.add("Assignment is not valid for end date " + TKUtils.formatDate(new LocalDate(endTime))); if (errors.size() > 0) return errors; //------------------------ // some of the simple validations are in the js side in order to reduce the server calls // 1. check if the begin / end time is empty - tk.calenadr.js // 2. check the time format - timeparse.js // 3. only allows decimals to be entered in the hour field //------------------------ //------------------------ // check if the begin / end time are valid //------------------------ if ((startTime.compareTo(endTime) > 0 || endTime.compareTo(startTime) < 0)) { errors.add("The time or date is not valid."); } if (errors.size() > 0) return errors; // KPME-1446 // ------------------------------- // check if there is a weekend day when the include weekends flag is checked //-------------------------------- errors.addAll(validateSpanningWeeks(spanningWeeks, startTemp, endTemp)); if (errors.size() > 0) return errors; //------------------------ // check if the overnight shift is across days //------------------------ if (acrossDays && hours == null && amount == null) { if (startTemp.getHourOfDay() > endTemp.getHourOfDay() && !(endTemp.getDayOfYear() - startTemp.getDayOfYear() <= 1 && endTemp.getHourOfDay() == 0)) { errors.add("The \"apply to each day\" box should not be checked."); } } if (errors.size() > 0) return errors; //------------------------ // Amount cannot be zero //------------------------ if (amount != null && earnCode != null && StringUtils.equals(earnCode.getEarnCodeType(), HrConstants.EARN_CODE_AMOUNT)) { if (amount.equals(BigDecimal.ZERO)) { errors.add("Amount cannot be zero."); } if (amount.scale() > 2) { errors.add("Amount cannot have more than two digits after decimal point."); } } if (errors.size() > 0) return errors; //------------------------ // check if the hours entered for hourly earn code is greater than 24 hours per day // Hours cannot be zero //------------------------ if (hours != null && earnCode != null && StringUtils.equals(earnCode.getEarnCodeType(), HrConstants.EARN_CODE_HOUR)) { if (hours.equals(BigDecimal.ZERO)) { errors.add("Hours cannot be zero."); } if (hours.scale() > 2) { errors.add("Hours cannot have more than two digits after decimal point."); } int dayDiff = endTemp.getDayOfYear() - startTemp.getDayOfYear() + 1; if (hours.compareTo(new BigDecimal(dayDiff * 24)) == 1) { errors.add("Cannot enter more than 24 hours per day."); } } if (errors.size() > 0) return errors; //------------------------ // check if time blocks overlap with each other. Note that the tkTimeBlockId is used to // determine is it's updating an existing time block or adding a new one //------------------------ boolean isRegularEarnCode = StringUtils.equals(assign.getJob().getPayTypeObj().getRegEarnCode(), selectedEarnCode); errors.addAll(validateOverlap(startTime, endTime, acrossDays, startDateS, endTimeS, startTemp, endTemp, timesheetDocument, timeblockId, isRegularEarnCode)); if (errors.size() > 0) return errors; // Accrual Hour Limits Validation //errors.addAll(TkServiceLocator.getTimeOffAccrualService().validateAccrualHoursLimitByEarnCode(timesheetDocument, selectedEarnCode)); return errors; }
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; }//w w w . ja va 2s . 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.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 ww. jav a 2 s. c o m*/ } 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.missedpunch.validation.MissedPunchDocumentRule.java
License:Educational Community License
/** * Validates whether the MissedPunch has a valid time relative to the last Clock Log. * * @param missedPunch The Missed Punch to check * * @return true if the MissedPunch has a valid time relative to the last Clock Log, false otherwise *//* ww w .j a v a2 s. c o m*/ protected boolean validateClockTime(MissedPunch missedPunch) { boolean valid = true; if (missedPunch.getActionFullDateTime() != null) { DateTime userActionDateTime = missedPunch.getActionFullDateTime(); DateTimeZone userTimeZone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); DateTime actionDateTime = new DateTime(userActionDateTime, userTimeZone) .withZone(TKUtils.getSystemDateTimeZone()); if (actionDateTime.toLocalDate().isAfter(LocalDate.now())) { GlobalVariables.getMessageMap().putError("document.actionDate", "clock.mp.future.date"); valid = false; } if (actionDateTime.toLocalDate().isEqual(LocalDate.now()) && actionDateTime.isAfterNow()) { GlobalVariables.getMessageMap().putError("document.actionTime", "clock.mp.future.time"); valid = false; } ClockLog lastClockLog = TkServiceLocator.getClockLogService() .getLastClockLog(missedPunch.getPrincipalId()); if (lastClockLog != null) { DateTime clockLogDateTime = lastClockLog.getClockDateTime(); DateTime boundaryMax = clockLogDateTime.plusDays(1); if ((!StringUtils.equals(lastClockLog.getClockAction(), TkConstants.CLOCK_OUT) && actionDateTime.isAfter(boundaryMax)) || actionDateTime.isBefore(clockLogDateTime)) { GlobalVariables.getMessageMap().putError("document.actionTime", "clock.mp.invalid.datetime"); valid = false; } } } return valid; }
From source file:org.kuali.kpme.tklm.time.service.permission.TKPermissionServiceImpl.java
License:Educational Community License
@Override public boolean canEditRegEarnCode(TimeBlock tb) { AssignmentDescriptionKey adk = new AssignmentDescriptionKey(tb.getJobNumber(), tb.getWorkArea(), tb.getTask());/*from ww w.ja v a 2 s . co m*/ Assignment anAssignment = HrServiceLocator.getAssignmentService().getAssignment(adk, tb.getBeginDateTime().toLocalDate()); if (anAssignment != null) { // use timesheet's end date to get Time Collection Rule TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService() .getDocumentHeader(tb.getDocumentId()); DateTime aDate = tb.getBeginDateTime(); if (tdh != null && tdh.getEndDate() != null) { aDate = tdh.getEndDateTime(); } TimeCollectionRule tcr = TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRule( anAssignment.getDept(), anAssignment.getWorkArea(), anAssignment.getJob().getHrPayType(), aDate.toLocalDate()); if (tcr == null || tcr.isClockUserFl()) { // use assignment to get the payType object, then check if the regEarnCode of the paytyep matches the earn code of the timeblock // if they do match, then return false PayType pt = HrServiceLocator.getPayTypeService().getPayType(anAssignment.getJob().getHrPayType(), anAssignment.getJob().getEffectiveLocalDate()); if (pt != null && pt.getRegEarnCode().equals(tb.getEarnCode())) { return false; } } } return true; }
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 ww .ja v a 2 s.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; }