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.calendar.web.LeaveCalendarAction.java

License:Educational Community License

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    LeaveCalendarForm leaveCalendarForm = (LeaveCalendarForm) form;
    String documentId = leaveCalendarForm.getDocumentId();
    String principalId = HrContext.getTargetPrincipalId();
    CalendarEntry calendarEntry = null;//  w  w  w  . j a  v  a 2  s.co m
    LeaveCalendarDocument leaveCalendarDocument = null;
    if (StringUtils.isNotBlank(documentId)) {
        leaveCalendarDocument = LmServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(documentId);

        if (leaveCalendarDocument != null) {
            calendarEntry = leaveCalendarDocument.getCalendarEntry();
        }
    } else {
        if (StringUtils.isNotBlank(leaveCalendarForm.getHrCalendarEntryId())) {
            calendarEntry = HrServiceLocator.getCalendarEntryService()
                    .getCalendarEntry(leaveCalendarForm.getHrCalendarEntryId());
        } else {
            calendarEntry = HrServiceLocator.getCalendarEntryService().getCurrentCalendarDatesForLeaveCalendar(
                    principalId, new LocalDate().toDateTimeAtStartOfDay());
        }

        if (calendarEntry != null) {
            if (LmServiceLocator.getLeaveCalendarService().shouldCreateLeaveDocument(principalId,
                    calendarEntry)) {
                leaveCalendarDocument = LmServiceLocator.getLeaveCalendarService()
                        .openLeaveCalendarDocument(principalId, calendarEntry);
            } else {
                LeaveCalendarDocumentHeader header = LmServiceLocator.getLeaveCalendarDocumentHeaderService()
                        .getDocumentHeader(principalId, calendarEntry.getBeginPeriodFullDateTime(),
                                calendarEntry.getEndPeriodFullDateTime());
                if (header != null) {
                    leaveCalendarDocument = LmServiceLocator.getLeaveCalendarService()
                            .getLeaveCalendarDocument(header.getDocumentId());
                }
            }
        }
    }

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

        CalendarEntry previousCalendarEntry = HrServiceLocator.getCalendarEntryService()
                .getPreviousCalendarEntryByCalendarId(calendarEntry.getHrCalendarId(), calendarEntry);
        if (previousCalendarEntry != null) {
            LocalDate previousBeginDate = previousCalendarEntry.getBeginPeriodFullDateTime().toLocalDate();
            LocalDate previousEndDate = previousCalendarEntry.getEndPeriodFullDateTime().toLocalDate()
                    .minusDays(1);

            PrincipalHRAttributes principalHRAttributes = HrServiceLocator.getPrincipalHRAttributeService()
                    .getPrincipalCalendar(principalId, previousEndDate);
            if (principalHRAttributes != null) {
                LocalDate serviceDate = principalHRAttributes.getServiceLocalDate();
                if (serviceDate != null) {
                    if (previousBeginDate.isEqual(serviceDate) || previousBeginDate.isAfter(serviceDate)) {
                        leaveCalendarForm
                                .setPrevHrCalendarEntryId(previousCalendarEntry.getHrCalendarEntryId());
                    }
                } else {
                    leaveCalendarForm.setPrevHrCalendarEntryId(previousCalendarEntry.getHrCalendarEntryId());
                }
            }
        }

        int planningMonths = ActionFormUtils.getPlanningMonthsForEmployee(principalId);
        if (planningMonths != 0) {
            List<CalendarEntry> futureCalendarEntries = HrServiceLocator.getCalendarEntryService()
                    .getFutureCalendarEntries(calendarEntry.getHrCalendarId(),
                            new LocalDate().toDateTimeAtStartOfDay(), planningMonths);
            if (!futureCalendarEntries.isEmpty()) {
                CalendarEntry nextCalendarEntry = HrServiceLocator.getCalendarEntryService()
                        .getNextCalendarEntryByCalendarId(calendarEntry.getHrCalendarId(), calendarEntry);
                CalendarEntry lastFutureCalendarEntry = futureCalendarEntries
                        .get(futureCalendarEntries.size() - 1);

                if (nextCalendarEntry != null && futureCalendarEntries != null) {
                    DateTime nextCalendarEntryBeginDate = nextCalendarEntry.getBeginPeriodFullDateTime();
                    DateTime lastFutureCalendarEntryBeginDate = lastFutureCalendarEntry
                            .getBeginPeriodFullDateTime();
                    if (nextCalendarEntryBeginDate.isBefore(lastFutureCalendarEntryBeginDate)
                            || nextCalendarEntryBeginDate.isEqual(lastFutureCalendarEntryBeginDate)) {
                        leaveCalendarForm.setNextHrCalendarEntryId(nextCalendarEntry.getHrCalendarEntryId());
                    }
                }
            }
        }

        setCalendarFields(request, leaveCalendarForm);
    } else {
        EntityNamePrincipalName entityNamePrincipalName = KimApiServiceLocator.getIdentityService()
                .getDefaultNamesForPrincipalId(principalId);
        GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "error.missing.leaveCalendar",
                entityNamePrincipalName.getPrincipalName());
    }

    ActionForward actionForward = super.execute(mapping, form, request, response);

    if (calendarEntry != null) {
        List<Assignment> assignments = HrServiceLocator.getAssignmentService()
                .getAssignmentsByCalEntryForLeaveCalendar(principalId, calendarEntry);
        List<String> assignmentKeys = new ArrayList<String>();
        for (Assignment assignment : assignments) {
            assignmentKeys.add(assignment.getAssignmentKey());
        }

        if (leaveCalendarDocument != null) {
            leaveCalendarForm.setLeaveCalendarDocument(leaveCalendarDocument);
            leaveCalendarForm.setDocumentId(leaveCalendarDocument.getDocumentId());
            leaveCalendarForm.setAssignmentDescriptions(leaveCalendarDocument.getAssignmentDescriptions());
        } else {
            leaveCalendarForm.setAssignmentDescriptions(HrServiceLocator.getAssignmentService()
                    .getAssignmentDescriptionsForAssignments(assignments));
        }

        if (HrServiceLocator.getHRPermissionService().canViewLeaveTabsWithNEStatus()) {
            if (LocalDate.now().isBefore(calendarEntry.getEndPeriodFullDateTime().toLocalDate())
                    || LocalDate.now().isEqual(calendarEntry.getEndPeriodFullDateTime().toLocalDate())) {
                setDocEditable(leaveCalendarForm, leaveCalendarDocument);
            }
        } else {
            setDocEditable(leaveCalendarForm, leaveCalendarDocument);
        }

        runAccrualService(leaveCalendarForm);

        List<LeaveBlock> leaveBlocks = getLeaveBlocks(principalId, calendarEntry, leaveCalendarDocument,
                assignmentKeys);

        setLeaveBlocks(leaveCalendarForm, principalId, leaveBlocks, assignmentKeys);
        setLeaveSummary(leaveCalendarForm);
        setMessages(leaveCalendarForm, leaveBlocks);

        setBlockSubmittable(leaveCalendarForm, leaveCalendarDocument);
    }

    return actionForward;
}

From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarAction.java

License:Educational Community License

protected void runAccrualService(LeaveCalendarForm leaveCalendarForm) {
    String principalId = HrContext.getTargetPrincipalId();
    CalendarEntry calendarEntry = leaveCalendarForm.getCalendarEntry();

    // check configuration setting for allowing accrual service to be ran from leave calendar
    String runAccrualFlag = ConfigContext.getCurrentContextConfig()
            .getProperty(LMConstants.RUN_ACCRUAL_FROM_CALENDAR);
    if (StringUtils.equals(runAccrualFlag, "true")) {
        // run accrual for future dates only, use planning month of leave plan for accrual period
        // only run the accrual if the calendar entry contains future dates
        if (calendarEntry.getEndPeriodDate().after(LocalDate.now().toDate())) {
            if (LmServiceLocator.getLeaveAccrualService().statusChangedSinceLastRun(principalId)) {
                LmServiceLocator.getLeaveAccrualService().calculateFutureAccrualUsingPlanningMonth(principalId,
                        calendarEntry.getBeginPeriodFullDateTime().toLocalDate(), HrContext.getPrincipalId());
            }//from   ww  w  . ja  v a 2 s. co  m
        }
    }
}

From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarAction.java

License:Educational Community License

protected void setLeaveSummary(LeaveCalendarForm leaveCalendarForm) throws Exception {
    String principalId = HrContext.getTargetPrincipalId();
    CalendarEntry calendarEntry = leaveCalendarForm.getCalendarEntry();
    PrincipalHRAttributes principalHRAttributes = HrServiceLocator.getPrincipalHRAttributeService()
            .getPrincipalCalendar(principalId, calendarEntry.getEndPeriodFullDateTime().toLocalDate());

    //check to see if we are on a previous leave plan
    if (principalHRAttributes != null) {
        DateTime currentYearBeginDate = HrServiceLocator.getLeavePlanService()
                .getFirstDayOfLeavePlan(principalHRAttributes.getLeavePlan(), LocalDate.now());
        DateTime calEntryEndDate = calendarEntry.getEndPeriodFullDateTime();
        if (calEntryEndDate.getMillis() > currentYearBeginDate.getMillis()) {
            //current or future year
            LeaveSummary ls = LmServiceLocator.getLeaveSummaryService().getLeaveSummary(principalId,
                    calendarEntry);//from w  w  w. ja va 2s.c  o m
            leaveCalendarForm.setLeaveSummary(ls);
        } else {
            //current year roll over date has been passed, all previous calendars belong to the previous leave plan calendar year.
            DateTime effDate = HrServiceLocator.getLeavePlanService().getRolloverDayOfLeavePlan(
                    principalHRAttributes.getLeavePlan(), calEntryEndDate.minusDays(1).toLocalDate());
            LeaveSummary ls = LmServiceLocator.getLeaveSummaryService()
                    .getLeaveSummaryAsOfDateWithoutFuture(principalId, effDate.toLocalDate());
            //override title element (based on date passed in)
            DateFormat formatter = new SimpleDateFormat("MMMM d");
            DateFormat formatter2 = new SimpleDateFormat("MMMM d yyyy");
            DateTime entryEndDate = new LocalDateTime(calendarEntry.getEndPeriodDate()).toDateTime();
            if (entryEndDate.getHourOfDay() == 0) {
                entryEndDate = entryEndDate.minusDays(1);
            }
            String aString = formatter.format(calendarEntry.getBeginPeriodDate()) + " - "
                    + formatter2.format(entryEndDate.toDate());
            ls.setPendingDatesString(aString);
            DateTimeFormatter fmt = DateTimeFormat.forPattern("MMM d, yyyy");
            ls.setNote("Values as of: " + fmt.print(effDate));
            leaveCalendarForm.setLeaveSummary(ls);
        }
    }
}

From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarAction.java

License:Educational Community License

protected void setMessages(LeaveCalendarForm leaveCalendarForm, List<LeaveBlock> leaveBlocks) {
    String principalId = HrContext.getTargetPrincipalId();
    CalendarEntry calendarEntry = leaveCalendarForm.getCalendarEntry();
    PrincipalHRAttributes principalHRAttributes = HrServiceLocator.getPrincipalHRAttributeService()
            .getPrincipalCalendar(principalId, calendarEntry.getEndPeriodFullDateTime().toLocalDate());

    Map<String, Set<String>> allMessages = LeaveCalendarValidationUtil
            .getWarningMessagesForLeaveBlocks(leaveBlocks);

    // add warning message for accrual categories that have exceeded max balance.
    // Could set a flag on the transferable rows here so that LeaveCalendarSubmit.do knows
    // which row(s) to transfer when user submits the calendar for approval.
    List<BalanceTransfer> losses = new ArrayList<BalanceTransfer>();

    Interval calendarInterval = new Interval(calendarEntry.getBeginPeriodDate().getTime(),
            calendarEntry.getEndPeriodDate().getTime());
    Map<String, Set<LeaveBlock>> maxBalInfractions = new HashMap<String, Set<LeaveBlock>>();

    Date effectiveDate = LocalDate.now().toDate();
    if (!calendarInterval.contains(effectiveDate.getTime())) {
        effectiveDate = calendarEntry.getEndPeriodDate();
    }/*w  w  w  . jav  a  2 s . c o m*/

    if (principalHRAttributes != null) {
        maxBalInfractions = LmServiceLocator.getAccrualCategoryMaxBalanceService()
                .getMaxBalanceViolations(calendarEntry, principalId);

        LeaveSummary summary = leaveCalendarForm.getLeaveSummary();
        for (Entry<String, Set<LeaveBlock>> entry : maxBalInfractions.entrySet()) {
            for (LeaveBlock lb : entry.getValue()) {
                AccrualCategory accrualCat = HrServiceLocator.getAccrualCategoryService()
                        .getAccrualCategory(lb.getAccrualCategory(), lb.getLeaveLocalDate());
                AccrualCategoryRule aRule = HrServiceLocator.getAccrualCategoryRuleService()
                        .getAccrualCategoryRule(lb.getAccrualCategoryRuleId());
                if (StringUtils.equals(aRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.LOSE)) {
                    DateTime aDate = null;
                    if (StringUtils.equals(aRule.getMaxBalanceActionFrequency(),
                            HrConstants.MAX_BAL_ACTION_FREQ.YEAR_END)) {
                        aDate = HrServiceLocator.getLeavePlanService().getRolloverDayOfLeavePlan(
                                principalHRAttributes.getLeavePlan(), lb.getLeaveLocalDate());
                    } else {
                        Calendar cal = HrServiceLocator.getCalendarService().getCalendarByPrincipalIdAndDate(
                                principalId, new LocalDate(lb.getLeaveDate()), true);
                        CalendarEntry leaveEntry = HrServiceLocator.getCalendarEntryService()
                                .getCurrentCalendarEntryByCalendarId(cal.getHrCalendarId(),
                                        new DateTime(lb.getLeaveDate()));
                        aDate = new DateTime(leaveEntry.getEndPeriodDate());
                    }
                    aDate = aDate.minusDays(1);
                    if (calendarInterval.contains(aDate.getMillis())
                            && aDate.toDate().compareTo(calendarEntry.getEndPeriodDate()) <= 0) {
                        //may want to calculate summary for all rows, displayable or not, and determine displayability via tags.
                        AccrualCategory accrualCategory = HrServiceLocator.getAccrualCategoryService()
                                .getAccrualCategory(aRule.getLmAccrualCategoryId());
                        BigDecimal accruedBalance = LmServiceLocator.getAccrualService()
                                .getAccruedBalanceForPrincipal(principalId, accrualCategory,
                                        lb.getLeaveLocalDate());

                        BalanceTransfer loseTransfer = LmServiceLocator.getBalanceTransferService()
                                .initializeTransfer(principalId, lb.getAccrualCategoryRuleId(), accruedBalance,
                                        lb.getLeaveLocalDate());
                        boolean valid = BalanceTransferValidationUtils.validateTransfer(loseTransfer);
                        if (valid) {
                            losses.add(loseTransfer);
                        }
                    }
                } else if (StringUtils.equals(HrConstants.MAX_BAL_ACTION_FREQ.ON_DEMAND,
                        aRule.getMaxBalanceActionFrequency())) {
                    if (calendarInterval.contains(lb.getLeaveDate().getTime())) {
                        // accrual categories within the leave plan that are hidden from the leave summary will not appear.
                        List<LeaveSummaryRow> summaryRows = summary.getLeaveSummaryRows();
                        List<LeaveSummaryRow> updatedSummaryRows = new ArrayList<LeaveSummaryRow>(
                                summaryRows.size());
                        //AccrualCategoryRule currentRule = HrServiceLocator.getAccrualCategoryRuleService().getAccrualCategoryRuleForDate(accrualCat, effectiveDate, principalCalendar.getServiceDate());
                        for (LeaveSummaryRow summaryRow : summaryRows) {
                            if (StringUtils.equals(summaryRow.getAccrualCategory(),
                                    accrualCat.getAccrualCategory())) {
                                if (StringUtils.equals(aRule.getActionAtMaxBalance(),
                                        HrConstants.ACTION_AT_MAX_BALANCE.PAYOUT)) {
                                    summaryRow.setPayoutable(true);
                                } else {
                                    if (StringUtils.equals(aRule.getActionAtMaxBalance(),
                                            HrConstants.ACTION_AT_MAX_BALANCE.TRANSFER)) {
                                        summaryRow.setTransferable(true);
                                    }
                                }

                                summaryRow.setInfractingLeaveBlockId(lb.getLmLeaveBlockId());
                            }
                            updatedSummaryRows.add(summaryRow);
                        }
                        summary.setLeaveSummaryRows(updatedSummaryRows);
                    }
                }

                if (calendarInterval.contains(lb.getLeaveDate().getTime())) {
                    // accrual categories within the leave plan that are hidden from the leave summary WILL appear.
                    String message = "You have exceeded the maximum balance limit for '"
                            + accrualCat.getAccrualCategory() + "' as of " + lb.getLeaveDate() + ". "
                            + "Depending upon the accrual category rules, leave over this limit may be forfeited.";
                    //  leave blocks are sorted in getMaxBalanceViolations() method, so we just take the one with the earliest leave date for an accrual category.
                    if (!StringUtils.contains(allMessages.get("warningMessages").toString(),
                            "You have exceeded the maximum balance limit for '"
                                    + accrualCat.getAccrualCategory())) {
                        allMessages.get("warningMessages").add(message);
                    }
                }
            }
        }
        leaveCalendarForm.setLeaveSummary(summary);
    }
    leaveCalendarForm.setForfeitures(losses);

    Map<String, Set<String>> transactionalMessages = LeaveCalendarValidationUtil.validatePendingTransactions(
            principalId, calendarEntry.getBeginPeriodFullDateTime().toLocalDate(),
            calendarEntry.getEndPeriodFullDateTime().toLocalDate());
    allMessages.get("infoMessages").addAll(transactionalMessages.get("infoMessages"));
    allMessages.get("warningMessages").addAll(transactionalMessages.get("warningMessages"));
    allMessages.get("actionMessages").addAll(transactionalMessages.get("actionMessages"));

    // add warning messages based on max carry over balances for each accrual category
    if (principalHRAttributes != null) {
        List<AccrualCategory> accrualCategories = HrServiceLocator.getAccrualCategoryService()
                .getActiveLeaveAccrualCategoriesForLeavePlan(principalHRAttributes.getLeavePlan(),
                        calendarEntry.getEndPeriodFullDateTime().toLocalDate());
        for (AccrualCategory accrualCategory : accrualCategories) {
            if (LmServiceLocator.getAccrualCategoryMaxCarryOverService().exceedsAccrualCategoryMaxCarryOver(
                    accrualCategory.getAccrualCategory(), principalId, calendarEntry,
                    calendarEntry.getEndPeriodFullDateTime().toLocalDate())) {
                String message = "Your pending leave balance is greater than the annual max carry over for accrual category '"
                        + accrualCategory.getAccrualCategory()
                        + "' and upon approval, the excess balance will be lost.";
                if (!allMessages.get("warningMessages").contains(message)) {
                    allMessages.get("warningMessages").add(message);
                }
            }
        }

        // KPME-1279 check for Absent Earn code to add warning.
        List<EarnCode> earnCodes = HrServiceLocator.getEarnCodeService().getEarnCodesForPrincipal(principalId,
                calendarEntry.getEndPeriodFullDateTime().toLocalDate(), true);
        if (earnCodes != null && !earnCodes.isEmpty()) {
            for (EarnCode earnCodeObj : earnCodes) {
                if (earnCodeObj != null) {
                    if ("Y".equalsIgnoreCase(earnCodeObj.getAffectPay())
                            && "N".equalsIgnoreCase(earnCodeObj.getEligibleForAccrual())) {
                        String message = "Absent time cannot be used until other accrual balances are zero or below a specified accrual balance.";
                        if (!allMessages.get("warningMessages").contains(message)) {
                            allMessages.get("warningMessages").add(message);
                            break;
                        }
                    }
                }
            }
        }
    }

    leaveCalendarForm.setWarningMessages(new ArrayList<String>(allMessages.get("warningMessages")));
    leaveCalendarForm.setInfoMessages(new ArrayList<String>(allMessages.get("infoMessages")));
    leaveCalendarForm.setActionMessages(new ArrayList<String>(allMessages.get("actionMessages")));
}

From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarAction.java

License:Educational Community License

private void setBlockSubmittable(LeaveCalendarForm leaveForm, LeaveCalendarDocument lcd) {

    leaveForm.setBlockSubmittable(false);

    if (leaveForm != null) {
        // Do NOT use leaveForm.getStartDate - We don't know why it's there
        if (leaveForm.getCalendarEntry().getBeginPeriodDate() != null
                && StringUtils.isBlank(leaveForm.getDocumentId())) {
            if (LocalDate.now()
                    .isBefore(leaveForm.getCalendarEntry().getBeginPeriodLocalDateTime().toLocalDate())) {
                leaveForm.setBlockSubmittable(true);
            }//from w  w  w . ja  va 2s.co  m
        }
    }
}

From source file:org.kuali.kpme.tklm.leave.donation.dao.LeaveDonationDaoOjbImpl.java

License:Educational Community License

@Override
public List<LeaveDonation> getLeaveDonations(LocalDate fromEffdt, LocalDate toEffdt, String donorsPrincipalId,
        String donatedAccrualCategory, String amountDonated, String recipientsPrincipalId,
        String recipientsAccrualCategory, String amountReceived, String active, String showHist) {
    List<LeaveDonation> results = new ArrayList<LeaveDonation>();

    Criteria root = new Criteria();

    Criteria effectiveDateFilter = new Criteria();
    if (fromEffdt != null) {
        effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
    }//  w  w  w .j  ava  2s. c  om
    if (toEffdt != null) {
        effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
    }
    if (fromEffdt == null && toEffdt == null) {
        effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
    }
    root.addAndCriteria(effectiveDateFilter);

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

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

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

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

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

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

    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(showHist, "N")) {
        root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(LeaveDonation.class,
                effectiveDateFilter, LeaveDonation.EQUAL_TO_FIELDS, false));
        root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(LeaveDonation.class,
                LeaveDonation.EQUAL_TO_FIELDS, false));
    }

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

    return results;
}

From source file:org.kuali.kpme.tklm.leave.override.dao.EmployeeOverrideDaoOjbImpl.java

License:Educational Community License

@Override
@SuppressWarnings("unchecked")
public List<EmployeeOverride> getEmployeeOverrides(String principalId, String leavePlan, String accrualCategory,
        String overrideType, LocalDate fromEffdt, LocalDate toEffdt, String active) {

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

    Criteria root = new Criteria();

    if (StringUtils.isNotBlank(principalId)) {
        root.addEqualTo("principalId", principalId);
    }/* w  w  w .  ja va2 s  . c om*/

    if (StringUtils.isNotBlank(leavePlan)) {
        root.addEqualTo("leavePlan", leavePlan);
    }

    if (StringUtils.isNotBlank(accrualCategory)) {
        root.addEqualTo("accrualCategory", accrualCategory);
    }

    if (StringUtils.isNotBlank(overrideType)) {
        root.addEqualTo("overrideType", overrideType);
    }

    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 (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);
    }

    root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(EmployeeOverride.class,
            effectiveDateFilter, EmployeeOverride.EQUAL_TO_FIELDS, false));
    root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EmployeeOverride.class,
            EmployeeOverride.EQUAL_TO_FIELDS, false));

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

    return results;
}

From source file:org.kuali.kpme.tklm.leave.payout.dao.LeavePayoutDaoOjbImpl.java

License:Educational Community License

@Override
public List<LeavePayout> getLeavePayouts(String principalId, String fromAccrualCategory, String payoutAmount,
        String earnCode, String forfeitedAmount, LocalDate fromEffdt, LocalDate toEffdt) {
    List<LeavePayout> results = new ArrayList<LeavePayout>();

    Criteria root = new Criteria();

    if (StringUtils.isNotBlank(principalId)) {
        root.addLike("principalId", principalId);
    }//from ww w.j  av  a  2 s  . com

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

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

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

    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(LeavePayout.class, root);
    results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));

    return results;
}

From source file:org.kuali.kpme.tklm.leave.payout.validation.LeavePayoutValidation.java

License:Educational Community License

/**
 * Are there any rules in place for effective date? i.e. not more than one year in advance...
 * @param date//from  ww  w .  j  av  a  2 s .c o  m
 * @return
 */
private boolean validateEffectiveDate(LocalDate date) {
    //Limit on future dates?
    if (date.isAfter(LocalDate.now().plusYears(1))) {
        GlobalVariables.getMessageMap().putError("document.newMaintainableObject.effectiveDate",
                "leavePayout.effectiveDate.overOneYear");
        return false;
    }
    return true;
}

From source file:org.kuali.kpme.tklm.leave.payout.web.LeavePayoutAction.java

License:Educational Community License

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

    LeavePayoutForm lpf = (LeavePayoutForm) form;
    //the leave calendar document that triggered this balance payout.
    String documentId = request.getParameter("documentId");
    String leaveBlockId = request.getParameter("accrualRuleId");
    String timesheet = request.getParameter("timesheet");

    boolean isTimesheet = false;
    if (StringUtils.equals(timesheet, "true")) {
        lpf.isTimesheet(true);// w  ww  .j  ava  2  s  .com
        isTimesheet = true;
    }
    if (ObjectUtils.isNotNull(leaveBlockId)) {
        AccrualCategoryRule aRule = HrServiceLocator.getAccrualCategoryRuleService()
                .getAccrualCategoryRule(leaveBlockId);
        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 payout for accrual category with action frequency " + aRule.getMaxBalanceActionFrequency());
                LOG.error(
                        "attempted to execute on-demand balance payout for accrual category with action frequency "
                                + aRule.getMaxBalanceActionFrequency());
                GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                        "attempted.payout.accrualcategory",
                        new String[] { aRule.getMaxBalanceActionFrequency() });
                return mapping.findForward("basic");
            } else {
                TimesheetDocument tsd = null;
                LeaveCalendarDocument lcd = null;
                String principalId = null;
                CalendarEntry calendarEntry = null;

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

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

                LeavePayout leavePayout = LmServiceLocator.getLeavePayoutService().initializePayout(principalId,
                        leaveBlockId, accruedBalance, LocalDate.now());
                leavePayout.setLeaveCalendarDocumentId(documentId);
                if (ObjectUtils.isNotNull(leavePayout)) {
                    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.getLeavePayoutService().submitToWorkflow(leavePayout);
                        // May need to update to save the business object to KPME's tables for record keeping.
                        leavePayout = LmServiceLocator.getLeavePayoutService().payout(leavePayout);
                        // May need to update to save the business object to KPME's tables for record keeping.
                        LeaveBlock forfeitedLeaveBlock = LmServiceLocator.getLeaveBlockService()
                                .getLeaveBlock(leavePayout.getForfeitedLeaveBlockId());
                        forfeitedLeaveBlock.setRequestStatus(HrConstants.REQUEST_STATUS.APPROVED);
                        LmServiceLocator.getLeaveBlockService().updateLeaveBlock(forfeitedLeaveBlock,
                                principalId);
                        return mapping.findForward("closeLeavePayoutDoc");
                    } else {
                        ActionForward forward = mapping.findForward("basic");
                        lpf.setLeaveCalendarDocumentId(documentId);
                        lpf.setLeavePayout(leavePayout);
                        lpf.setPayoutAmount(leavePayout.getPayoutAmount());
                        return forward;
                    }
                } else {
                    //                  throw new RuntimeException("could not initialize a balance payout");
                    LOG.error("could not initialize a balance payout");
                    GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                            "couldnot.initialize.payout");
                    return mapping.findForward("basic");
                }
            }
        } else {
            LOG.error("No rule for this accrual category could be found");
            //            throw new RuntimeException("No rule for this accrual category could be found");
            GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "no.acccatrule.found");
            return mapping.findForward("basic");
        }
    } 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.");
    }
}