Example usage for org.joda.time LocalDate now

List of usage examples for org.joda.time LocalDate now

Introduction

In this page you can find the example usage for org.joda.time LocalDate now.

Prototype

public static LocalDate now() 

Source Link

Document

Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:org.kuali.kpme.tklm.leave.request.approval.web.LeaveRequestApprovalAction.java

License:Educational Community License

private List<ActionItem> getActionItems(String calGroup, String dept, List<String> workAreaList) {
    String principalId = HrContext.getTargetPrincipalId();
    List<ActionItem> actionList = KewApiServiceLocator.getActionListService()
            .getActionItemsForPrincipal(principalId);
    List<ActionItem> resultsList = new ArrayList<ActionItem>();

    LocalDate currentDate = LocalDate.now();
    List<String> principalIds = LmServiceLocator.getLeaveApprovalService()
            .getLeavePrincipalIdsWithSearchCriteria(workAreaList, calGroup, currentDate, currentDate,
                    currentDate);//www  . ja va  2  s . co m

    if (CollectionUtils.isNotEmpty(principalIds)) {
        for (ActionItem anAction : actionList) {
            String docId = anAction.getDocumentId();
            if (anAction.getDocName().equals(LeaveRequestDocument.LEAVE_REQUEST_DOCUMENT_TYPE)) {
                LeaveRequestDocument lrd = LmServiceLocator.getLeaveRequestDocumentService()
                        .getLeaveRequestDocument(docId);
                if (lrd != null) {
                    LeaveBlock lb = lrd.getLeaveBlock();
                    if (lb != null) {
                        if (principalIds.contains(lb.getPrincipalId())) {
                            resultsList.add(anAction);
                        }
                    }
                }
            }
        }
    }

    return resultsList;
}

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);
    }/* ww  w  .  j  a v  a2  s .c  om*/
    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

@Override
// startDate is the leave request start date, endDat is leave request end date, usageEndDate is the date before next accrual interval date for leave requst end date
// will get leave balance up to the next earn interval for a certain date, including usage up to that next earn interval
public BigDecimal getLeaveBalanceForAccrCatUpToDate(String principalId, LocalDate startDate, LocalDate endDate,
        String accrualCategory, LocalDate usageEndDate) {
    BigDecimal leaveBalance = BigDecimal.ZERO;
    if (StringUtils.isEmpty(principalId) || startDate == null || endDate == null
            || StringUtils.isEmpty(accrualCategory) || usageEndDate == null) {
        return leaveBalance;
    }//  ww  w. j  a  v  a2 s .co  m

    LeaveSummaryRow lsr = new LeaveSummaryRow();
    AccrualCategory ac = HrServiceLocator.getAccrualCategoryService().getAccrualCategory(accrualCategory,
            endDate);

    if (ac != null) {
        LeavePlan lp = HrServiceLocator.getLeavePlanService().getLeavePlan(ac.getLeavePlan(),
                ac.getEffectiveLocalDate());
        if (lp == null) {
            return leaveBalance;
        }
        PrincipalHRAttributes pha = getPrincipalHrAttributes(principalId, startDate, endDate);
        //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);
        //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, true);
        List<LeaveBlock> acLeaveBlocks = new ArrayList<LeaveBlock>();
        for (LeaveBlock lb : leaveBlocks) {
            if (StringUtils.equals(lb.getAccrualCategory(), accrualCategory)) {
                acLeaveBlocks.add(lb);
            }
        }
        // get all leave blocks from the requested date to the usageEndDate
        List<LeaveBlock> futureLeaveBlocks = getLeaveBlockService()
                .getLeaveBlocksWithAccrualCategory(principalId, endDate, usageEndDate, accrualCategory);
        EmployeeOverride maxUsageOverride = LmServiceLocator.getEmployeeOverrideService()
                .getEmployeeOverride(principalId, lp.getLeavePlan(), accrualCategory, "MU", usageEndDate);

        //get max balances
        AccrualCategoryRule acRule = HrServiceLocator.getAccrualCategoryRuleService()
                .getAccrualCategoryRuleForDate(ac, LocalDate.now(), 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.
        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 creatLed from scheduler job.
        BigDecimal carryOver = BigDecimal.ZERO.setScale(2);
        lsr.setCarryOver(carryOver);

        assignApprovedValuesToRow(lsr, ac.getAccrualCategory(), acLeaveBlocks, lp, startDate, endDate);

        //merge key sets
        if (carryOverBlocks.containsKey(lsr.getAccrualCategory())) {
            carryOver = carryOverBlocks.get(lsr.getAccrualCategory()).getLeaveAmount();
        }
        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);
            if (acRule != null && acRule.getMaxCarryOver() != null
                    && acRule.getMaxCarryOver() < carryOver.longValue()) {
                carryOver = new BigDecimal(acRule.getMaxCarryOver());
            }
        }

        lsr.setCarryOver(carryOver);
        //handle future leave blocks
        assignPendingValuesToRow(lsr, ac.getAccrualCategory(), futureLeaveBlocks);
        //compute Leave Balance
        leaveBalance = lsr.getAccruedBalance().subtract(lsr.getPendingLeaveRequests());
        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);
        }
    }
    leaveBalance = lsr.getLeaveBalance();
    return leaveBalance;
}

From source file:org.kuali.kpme.tklm.leave.timeoff.dao.SystemScheduledTimeOffDaoOjbImpl.java

License:Educational Community License

@Override
@SuppressWarnings("unchecked")
public List<SystemScheduledTimeOff> getSystemScheduledTimeOffs(LocalDate fromEffdt, LocalDate toEffdt,
        String earnCode, LocalDate fromAccruedDate, LocalDate toAccruedDate, LocalDate fromSchTimeOffDate,
        LocalDate toSchTimeOffDate, String active, String showHistory) {

    List<SystemScheduledTimeOff> results = new ArrayList<SystemScheduledTimeOff>();

    Criteria root = new Criteria();

    if (StringUtils.isNotBlank(earnCode)) {
        root.addLike("earnCode", earnCode);
    }/*from  w ww  .j a v a2  s. c  om*/

    Criteria effectiveDateFilter = new Criteria();
    if (fromEffdt != null) {
        effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
    }
    if (toEffdt != null) {
        effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
    }
    if (fromEffdt == null && toEffdt == null) {
        effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
    }
    root.addAndCriteria(effectiveDateFilter);

    if (fromAccruedDate != null) {
        root.addGreaterOrEqualThan("accruedDate", fromAccruedDate.toDate());
    }
    if (toAccruedDate != null) {
        root.addLessOrEqualThan("accruedDate", toAccruedDate.toDate());
    }

    if (fromSchTimeOffDate != null) {
        root.addGreaterOrEqualThan("scheduledTimeOffDate", fromSchTimeOffDate.toDate());
    }
    if (toSchTimeOffDate != null) {
        root.addLessOrEqualThan("scheduledTimeOffDate", toSchTimeOffDate.toDate());
    }

    if (StringUtils.isNotBlank(active)) {
        Criteria activeFilter = new Criteria();
        if (StringUtils.equals(active, "Y")) {
            activeFilter.addEqualTo("active", true);
        } else if (StringUtils.equals(active, "N")) {
            activeFilter.addEqualTo("active", false);
        }
        root.addAndCriteria(activeFilter);
    }

    if (StringUtils.equals(showHistory, "N")) {
        //               ImmutableList<String> fields = new ImmutableList.Builder<String>()
        //                    .add("earnCode")
        //                    .add("accruedDate") //Not part of Primary Business Key
        //                    .build();
        //           KPME-2273/1965 Primary Business Keys List. Using list from now on
        root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(
                SystemScheduledTimeOff.class, effectiveDateFilter, SystemScheduledTimeOff.fields, false));
        root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(SystemScheduledTimeOff.class,
                SystemScheduledTimeOff.fields, false));
    }

    Query query = QueryFactory.newQuery(SystemScheduledTimeOff.class, root);
    results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));

    return results;
}

From source file:org.kuali.kpme.tklm.leave.transfer.dao.BalanceTransferDaoOjbImpl.java

License:Educational Community License

@Override
public List<BalanceTransfer> getBalanceTransfers(String principalId, String fromAccrualCategory,
        String transferAmount, String toAccrualCategory, String amountTransferred, String forfeitedAmount,
        LocalDate fromEffdt, LocalDate toEffdt) {
    List<BalanceTransfer> results = new ArrayList<BalanceTransfer>();

    Criteria root = new Criteria();

    if (StringUtils.isNotBlank(principalId)) {
        root.addLike("principalId", principalId);
    }//from   ww w  . j a va2s.  co m

    if (StringUtils.isNotBlank(fromAccrualCategory)) {
        root.addLike("fromAccrualCategory", fromAccrualCategory);
    }

    if (StringUtils.isNotBlank(transferAmount)) {
        root.addLike("transferAmount", transferAmount);
    }

    if (StringUtils.isNotBlank(toAccrualCategory)) {
        root.addLike("toAccrualCategory", toAccrualCategory);
    }

    if (StringUtils.isNotBlank(amountTransferred)) {
        root.addLike("amountTransferred", amountTransferred);
    }

    if (StringUtils.isNotBlank(forfeitedAmount)) {
        root.addLike("forfeitedAmount", forfeitedAmount);
    }

    Criteria effectiveDateFilter = new Criteria();
    if (fromEffdt != null) {
        effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
    }
    if (toEffdt != null) {
        effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
    }
    if (fromEffdt == null && toEffdt == null) {
        effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
    }
    root.addAndCriteria(effectiveDateFilter);

    Query query = QueryFactory.newQuery(BalanceTransfer.class, root);
    results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));

    return results;
}

From source file:org.kuali.kpme.tklm.leave.transfer.validation.BalanceTransferValidation.java

License:Educational Community License

private boolean validateEffectiveDate(LocalDate date) {
    if (DateUtils.addYears(LocalDate.now().toDate(), 1).compareTo(date.toDate()) > 0)
        return true;
    else//from  w  ww  .ja v  a2 s . c  o  m
        GlobalVariables.getMessageMap().putError("document.newMaintainableObject.effectiveDate",
                "balanceTransfer.effectiveDate.error");
    return false;
}

From source file:org.kuali.kpme.tklm.leave.transfer.web.BalanceTransferAction.java

License:Educational Community License

public ActionForward balanceTransferOnDemand(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    GlobalVariables.getMessageMap().putWarning("document.transferAmount",
            "balanceTransfer.transferAmount.adjust");

    BalanceTransferForm btf = (BalanceTransferForm) form;
    //the leave calendar document that triggered this balance transfer.
    String documentId = request.getParameter("documentId");
    String accrualRuleId = request.getParameter("accrualRuleId");
    String timesheet = request.getParameter("timesheet");
    boolean isTimesheet = false;
    if (StringUtils.equals(timesheet, "true")) {
        btf.isTimesheet(true);//w  ww  .j  a  v a2  s  .  co  m
        isTimesheet = true;
    }
    if (ObjectUtils.isNotNull(accrualRuleId)) {
        //LeaveBlock lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock(leaveBlockId);
        AccrualCategoryRule aRule = HrServiceLocator.getAccrualCategoryRuleService()
                .getAccrualCategoryRule(accrualRuleId);
        if (ObjectUtils.isNotNull(aRule)) {
            //should somewhat safegaurd against url fabrication.
            if (!StringUtils.equals(aRule.getMaxBalanceActionFrequency(),
                    HrConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND)) {
                //               throw new RuntimeException("attempted to execute on-demand balance transfer for accrual category with action frequency " + aRule.getMaxBalanceActionFrequency());
                LOG.error(
                        "attempted to execute on-demand balance transfer for accrual category with action frequency "
                                + aRule.getMaxBalanceActionFrequency());
                GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                        "attempted.baltransfer.accrualcategory",
                        new String[] { aRule.getMaxBalanceActionFrequency() });
                return mapping.findForward("basic");
            } else {
                String principalId = null;

                if (isTimesheet) {
                    TimesheetDocument tsd = TkServiceLocator.getTimesheetService()
                            .getTimesheetDocument(documentId);
                    principalId = tsd == null ? null : tsd.getPrincipalId();
                } else {
                    LeaveCalendarDocument lcd = LmServiceLocator.getLeaveCalendarService()
                            .getLeaveCalendarDocument(documentId);
                    principalId = lcd == null ? null : lcd.getPrincipalId();
                }

                AccrualCategoryRule accrualRule = HrServiceLocator.getAccrualCategoryRuleService()
                        .getAccrualCategoryRule(accrualRuleId);
                AccrualCategory accrualCategory = HrServiceLocator.getAccrualCategoryService()
                        .getAccrualCategory(accrualRule.getLmAccrualCategoryId());
                BigDecimal accruedBalance = LmServiceLocator.getAccrualService()
                        .getAccruedBalanceForPrincipal(principalId, accrualCategory, LocalDate.now());

                BalanceTransfer balanceTransfer = LmServiceLocator.getBalanceTransferService()
                        .initializeTransfer(principalId, aRule.getLmAccrualCategoryRuleId(), accruedBalance,
                                LocalDate.now());
                balanceTransfer.setLeaveCalendarDocumentId(documentId);
                if (ObjectUtils.isNotNull(balanceTransfer)) {
                    if (StringUtils.equals(aRule.getActionAtMaxBalance(),
                            HrConstants.ACTION_AT_MAX_BALANCE.LOSE)) {
                        // this particular combination of action / action frequency does not particularly make sense
                        // unless for some reason users still need to be prompted to submit the loss.
                        // For now, we treat as though it is a valid use-case.
                        //LmServiceLocator.getBalanceTransferService().submitToWorkflow(balanceTransfer);
                        // May need to update to save the business object to KPME's tables for record keeping.
                        balanceTransfer = LmServiceLocator.getBalanceTransferService()
                                .transfer(balanceTransfer);
                        // May need to update to save the business object to KPME's tables for record keeping.
                        LeaveBlock forfeitedLeaveBlock = LmServiceLocator.getLeaveBlockService()
                                .getLeaveBlock(balanceTransfer.getForfeitedLeaveBlockId());
                        forfeitedLeaveBlock.setRequestStatus(HrConstants.REQUEST_STATUS.APPROVED);
                        LmServiceLocator.getLeaveBlockService().updateLeaveBlock(forfeitedLeaveBlock,
                                principalId);
                        return mapping.findForward("closeBalanceTransferDoc");
                    } else {
                        ActionForward forward = mapping.findForward("basic");
                        btf.setLeaveCalendarDocumentId(documentId);
                        btf.setBalanceTransfer(balanceTransfer);
                        btf.setTransferAmount(balanceTransfer.getTransferAmount());
                        return forward;
                    }
                } else {
                    LOG.error("could not initialize a balance transfer");
                    GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                            "couldnot.initialize.baltransfer");
                    //                  throw new RuntimeException("could not initialize a balance transfer");
                    return mapping.findForward("basic");
                }

            }
        } else {
            LOG.error("No rule for this accrual category could be found");
            GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "no.acccatrule.found");
            return mapping.findForward("basic");
            //            throw new RuntimeException("No rule for this accrual category could be found");
        }
    } else {
        LOG.error("No accrual category rule id has been sent in the request.");
        GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "no.acccat.ruleid.sent");
        return mapping.findForward("basic");
        //         throw new RuntimeException("No accrual category rule id has been sent in the request.");
    }
}

From source file:org.kuali.kpme.tklm.time.approval.service.TimeApproveServiceImpl.java

License:Educational Community License

private boolean isSynchronousUser(String principalId) {
    List<Assignment> assignments = HrServiceLocator.getAssignmentService().getAssignments(principalId,
            LocalDate.now());
    boolean isSynchronousUser = false;
    if (CollectionUtils.isNotEmpty(assignments)) {
        for (Assignment assignment : assignments) {
            TimeCollectionRule tcr = TkServiceLocator.getTimeCollectionRuleService()
                    .getTimeCollectionRule(assignment.getDept(), assignment.getWorkArea(), LocalDate.now());
            isSynchronousUser |= (tcr == null || tcr.isClockUserFl());
        }/*from  ww  w  . j  a  v a2 s  . co  m*/
    }
    return isSynchronousUser;
}

From source file:org.kuali.kpme.tklm.time.approval.web.TimeApprovalAction.java

License:Educational Community License

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionForward actionForward = super.execute(mapping, form, request, response);

    TimeApprovalActionForm timeApprovalActionForm = (TimeApprovalActionForm) form;
    String documentId = timeApprovalActionForm.getDocumentId();

    setSearchFields(timeApprovalActionForm);

    CalendarEntry calendarEntry = null;//from   w  w  w .  ja  va  2  s  .co m
    if (StringUtils.isNotBlank(documentId)) {
        TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService()
                .getTimesheetDocument(documentId);

        if (timesheetDocument != null) {
            calendarEntry = timesheetDocument.getCalendarEntry();
            timeApprovalActionForm.setCalendarDocument(timesheetDocument);
        }
    } else if (timeApprovalActionForm.getHrCalendarEntryId() != null) {
        calendarEntry = HrServiceLocator.getCalendarEntryService()
                .getCalendarEntry(timeApprovalActionForm.getHrCalendarEntryId());
    } else {
        Calendar calendar = HrServiceLocator.getCalendarService()
                .getCalendarByGroup(timeApprovalActionForm.getSelectedPayCalendarGroup());
        if (calendar != null) {
            calendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarEntryByCalendarId(
                    calendar.getHrCalendarId(), LocalDate.now().toDateTimeAtStartOfDay());
        }
    }

    if (calendarEntry != null) {
        timeApprovalActionForm.setHrCalendarEntryId(calendarEntry.getHrCalendarEntryId());
        timeApprovalActionForm.setCalendarEntry(calendarEntry);
        timeApprovalActionForm.setBeginCalendarEntryDate(calendarEntry.getBeginPeriodDateTime());
        timeApprovalActionForm
                .setEndCalendarEntryDate(DateUtils.addMilliseconds(calendarEntry.getEndPeriodDateTime(), -1));

        CalendarEntry prevCalendarEntry = HrServiceLocator.getCalendarEntryService()
                .getPreviousCalendarEntryByCalendarId(calendarEntry.getHrCalendarId(), calendarEntry);
        timeApprovalActionForm.setPrevHrCalendarEntryId(
                prevCalendarEntry != null ? prevCalendarEntry.getHrCalendarEntryId() : null);

        CalendarEntry nextCalendarEntry = HrServiceLocator.getCalendarEntryService()
                .getNextCalendarEntryByCalendarId(calendarEntry.getHrCalendarId(), calendarEntry);
        timeApprovalActionForm.setNextHrCalendarEntryId(
                nextCalendarEntry != null ? nextCalendarEntry.getHrCalendarEntryId() : null);

        setCalendarFields(timeApprovalActionForm);

        timeApprovalActionForm.setPayCalendarLabels(TkServiceLocator.getTimeSummaryService()
                .getHeaderForSummary(timeApprovalActionForm.getCalendarEntry(), new ArrayList<Boolean>()));
        setApprovalTables(timeApprovalActionForm, request, getPrincipalIds(timeApprovalActionForm));

        //           if (timeApprovalActionForm.getApprovalRows() != null && !timeApprovalActionForm.getApprovalRows().isEmpty()) {
        //              timeApprovalActionForm.setOutputString(timeApprovalActionForm.getApprovalRows().get(0).getOutputString());
        //           }
    }

    return actionForward;
}

From source file:org.kuali.kpme.tklm.time.batch.ClockedInEmployeeJob.java

License:Educational Community License

private Set<Person> getApprovers(Long workArea) {
    Set<Person> approvers = new HashSet<Person>();
    DateTime date = LocalDate.now().toDateTimeAtStartOfDay();
    List<RoleMember> roleMembers = HrServiceLocator.getKPMERoleService().getRoleMembersInWorkArea(
            KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER.getRoleName(), workArea, date, true);

    for (RoleMember roleMember : roleMembers) {
        Person person = KimApiServiceLocator.getPersonService().getPerson(roleMember.getMemberId());
        if (person != null) {
            approvers.add(person);/*from   w  w  w  . j  a va  2 s  . c o  m*/
        }
    }

    return approvers;
}