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.common.PersonInfoAction.java

License:Educational Community License

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

    personForm.setPrincipalId(HrContext.getTargetPrincipalId());
    EntityNamePrincipalName name = KimApiServiceLocator.getIdentityService()
            .getDefaultNamesForPrincipalId(personForm.getPrincipalId());
    //Person person = KimApiServiceLocator.getPersonService().getPerson(personForm.getPrincipalId());
    if (name != null) {
        personForm.setPrincipalName(name.getPrincipalName());
        // set name
        personForm.setName(/*from   w  w w.j  a va  2 s .c  om*/
                name.getDefaultName() != null ? name.getDefaultName().getCompositeName() : StringUtils.EMPTY);
    }
    personForm.setJobs(
            HrServiceLocator.getJobService().getJobs(HrContext.getTargetPrincipalId(), LocalDate.now()));

    //KPME-1441
    PrincipalHRAttributes principalHRAttributes = HrServiceLocator.getPrincipalHRAttributeService()
            .getPrincipalCalendar(personForm.getPrincipalId(), LocalDate.now());
    if (principalHRAttributes != null && principalHRAttributes.getServiceDate() != null) {
        personForm.setServiceDate(principalHRAttributes.getServiceDate().toString());
    } else {
        personForm.setServiceDate("");
    }
    // KPME-1441

    if (principalHRAttributes != null && principalHRAttributes.getLeavePlan() != null) {
        List<AccrualCategory> accrualCategories = new ArrayList<AccrualCategory>();
        Map<String, BigDecimal> accrualCategoryRates = new HashMap<String, BigDecimal>();
        Map<String, String> accrualEarnIntervals = new HashMap<String, String>();
        Map<String, String> unitOfTime = new HashMap<String, String>();

        List<AccrualCategory> allAccrualCategories = HrServiceLocator.getAccrualCategoryService()
                .getActiveLeaveAccrualCategoriesForLeavePlan(principalHRAttributes.getLeavePlan(),
                        LocalDate.now());
        for (AccrualCategory accrualCategory : allAccrualCategories) {
            if (StringUtils.equalsIgnoreCase(accrualCategory.getHasRules(), "Y")) {
                AccrualCategoryRule accrualCategoryRule = HrServiceLocator.getAccrualCategoryRuleService()
                        .getAccrualCategoryRuleForDate(accrualCategory, LocalDate.now(),
                                principalHRAttributes.getServiceLocalDate());
                if (accrualCategoryRule != null) {
                    accrualCategories.add(accrualCategory);

                    accrualCategoryRates.put(accrualCategory.getAccrualCategory(),
                            accrualCategoryRule.getAccrualRate());

                    for (Map.Entry<String, String> entry : HrConstants.ACCRUAL_EARN_INTERVAL_MAP.entrySet()) {
                        if (accrualCategory.getAccrualEarnInterval().equals(entry.getKey())) {
                            accrualEarnIntervals.put(accrualCategory.getAccrualCategory(), entry.getValue());
                            break;
                        }
                    }

                    for (Map.Entry<String, String> entry : HrConstants.UNIT_OF_TIME.entrySet()) {
                        if (accrualCategory.getUnitOfTime().equals(entry.getKey())) {
                            unitOfTime.put(accrualCategory.getAccrualCategory(), entry.getValue());
                            break;
                        }
                    }
                }
            }
        }
        personForm.setAccrualCategories(accrualCategories);
        personForm.setAccrualCategoryRates(accrualCategoryRates);
        personForm.setAccrualEarnIntervals(accrualEarnIntervals);
        personForm.setUnitOfTime(unitOfTime);
    }

    setupRolesOnForm(personForm);

    List<Assignment> assignments = HrServiceLocator.getAssignmentService()
            .getAssignments(HrContext.getTargetPrincipalId(), LocalDate.now());

    Map<Long, Set<Assignment>> jobNumberToListAssignments = new HashMap<Long, Set<Assignment>>();
    Map<Long, Set<Person>> workAreaToApproverPerson = new HashMap<Long, Set<Person>>();
    Map<String, Set<Person>> deptToDeptAdminPerson = new HashMap<String, Set<Person>>();

    for (Assignment assignment : assignments) {
        Set<Assignment> jobAssignments = jobNumberToListAssignments.get(assignment.getJobNumber());
        if (jobAssignments == null) {
            jobAssignments = new HashSet<Assignment>();
        }
        jobAssignments.add(assignment);
        jobNumberToListAssignments.put(assignment.getJobNumber(), jobAssignments);

        Set<Person> approvers = workAreaToApproverPerson.get(assignment.getWorkArea());
        if (approvers == null) {
            approvers = new TreeSet<Person>(new Comparator<Person>() {
                @Override
                public int compare(Person person1, Person person2) {
                    return ObjectUtils.compare(person1.getPrincipalId(), person2.getPrincipalId());
                }
            });
        }
        approvers.addAll(getApprovers(assignment.getWorkArea()));
        workAreaToApproverPerson.put(assignment.getWorkArea(), approvers);

        Set<Person> departmentAdmins = deptToDeptAdminPerson.get(assignment.getDept());
        if (departmentAdmins == null) {
            departmentAdmins = new TreeSet<Person>(new Comparator<Person>() {
                @Override
                public int compare(Person person1, Person person2) {
                    return ObjectUtils.compare(person1.getPrincipalId(), person2.getPrincipalId());
                }
            });
        }
        departmentAdmins.addAll(getDeptartmentAdmins(assignment.getDept()));
        deptToDeptAdminPerson.put(assignment.getDept(), departmentAdmins);
    }

    personForm.setJobNumberToListAssignments(jobNumberToListAssignments);
    personForm.setWorkAreaToApproverPerson(workAreaToApproverPerson);
    personForm.setDeptToDeptAdminPerson(deptToDeptAdminPerson);

    return actForw;
}

From source file:org.kuali.kpme.tklm.common.WorkflowTagSupport.java

License:Educational Community License

public static boolean isLeaveCalendarRouteButtonEnabled(String documentId) {
    LeaveCalendarDocument leaveCalendarDocument = LmServiceLocator.getLeaveCalendarService()
            .getLeaveCalendarDocument(documentId);
    return isRouteButtonEnabled(documentId) && isNotDelinquent(documentId) && (HrServiceLocator
            .getHRPermissionService().canViewLeaveTabsWithEStatus()
            && LocalDate.now().toDate().compareTo(leaveCalendarDocument.getDocumentHeader().getEndDate()) > 0);
}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.AccruedLeaveBalance.java

License:Educational Community License

public AccruedLeaveBalance(AccrualCategory accrualCategory, PrincipalHRAttributes principalCalendar) {
    super(accrualCategory, principalCalendar);
    //bad, add asOfDate to constructor
    asOfDate = LocalDate.now();
    leaveBlocks = new ArrayList<LeaveBlock>();
    ytdEarned = new YearToDateEarnedLeaveBalance(accrualCategory, principalCalendar);
    ytdUsage = new YearToDateUsageLeaveBalance(accrualCategory, principalCalendar);
    carryOver = new CarryOverLeaveBalance(accrualCategory, principalCalendar);
}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.AvailableLeaveBalance.java

License:Educational Community License

public AvailableLeaveBalance(AccrualCategory accrualCategory, PrincipalHRAttributes principalCalendar) {
    super(accrualCategory, principalCalendar);
    asOfDate = LocalDate.now();
    pendingBalance = new PendingLeaveBalance(accrualCategory, principalCalendar);
    ytdUsage = new YearToDateUsageLeaveBalance(accrualCategory, principalCalendar);
    leaveBlocks = new ArrayList<LeaveBlock>();
}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.FmlaLeaveBalance.java

License:Educational Community License

public FmlaLeaveBalance(AccrualCategory accrualCategory, PrincipalHRAttributes principalCalendar) {
    super(accrualCategory, principalCalendar);
    asOfDate = LocalDate.now();
    leaveBlocks = new ArrayList<LeaveBlock>();
}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.KPMEAccrualCategoryBucket.java

License:Educational Community License

private void adjustAsOfDates(CalendarEntry calendarEntry, List<CalendarEntry> calendarEntries) {

    LocalDate newAsOfDate = null;

    //determine if the bucket is being switched to the current leave year
    //also compute max end date to determine if the bucket is being switched to a future leave year. ( could use leave plan service's getRollOverDate )
    boolean switchingToCurrentLeaveYear = false;
    LocalDate maxEndDate = LocalDate.now();
    for (CalendarEntry entry : calendarEntries) {
        if (entry.getHrCalendarEntryId().equals(calendarEntry.getHrCalendarEntryId())
                && entry.getHrCalendarId().equals(calendarEntry.getHrCalendarId())) {
            switchingToCurrentLeaveYear = true;
        }/*ww  w .  j a  va2  s  .  co  m*/
        if (entry.getEndPeriodDate().after(maxEndDate.toDate()))
            maxEndDate = LocalDate.fromDateFields(entry.getEndPeriodDate());
    }

    if (switchingToCurrentLeaveYear) {
        Interval otherCalendarInterval = new Interval(calendarEntry.getBeginPeriodDate().getTime(),
                calendarEntry.getEndPeriodDate().getTime());
        if (otherCalendarInterval.contains(LocalDate.now().toDate().getTime())) {
            //switching to the present calendar.
            newAsOfDate = LocalDate.now();
        } else if (otherCalendarInterval.getEnd().isBefore(LocalDate.now().toDate().getTime())) {
            //switching to a historical calendar in the current leave plan year, use calendar end date
            newAsOfDate = otherCalendarInterval.getEnd().toLocalDate().minusDays(1);
        } else {
            //switching to a future/planning calendar in the current leave plan year, use calendar start date.
            newAsOfDate = otherCalendarInterval.getStart().toLocalDate().minusDays(1);
        }
    } else if (calendarEntry.getEndPeriodDate().after(maxEndDate.toDate())) {
        //switching to a leave year beyond the current leave year, same as future/planning calendar in current leave year.
        newAsOfDate = LocalDate.fromDateFields(calendarEntry.getBeginPeriodDate()).minusDays(1);
    } else {
        //switching to a calendar period within a past leave calendar year.
        DateTime otherCalendarRolloverDate = HrServiceLocator.getLeavePlanService().getRolloverDayOfLeavePlan(
                principalCalendar.getLeavePlan(), LocalDate.fromDateFields(calendarEntry.getEndPeriodDate()));
        //for past leave calendar years, regardless of calendar period, we require values as of the rollover day.
        newAsOfDate = LocalDate.fromDateFields(otherCalendarRolloverDate.toDate()).minusDays(1);
    }

    //update asOfDates and calendar period end point dates for all leave balance objects
    for (Entry<String, List<LeaveBalance>> entry : leaveBalances.entrySet()) {
        for (LeaveBalance leaveBalance : entry.getValue()) {
            leaveBalance.asOfDate = newAsOfDate;
            leaveBalance.calendarPeriodBeginDate = LocalDate.fromDateFields(calendarEntry.getBeginPeriodDate());
            leaveBalance.calendarPeriodEndDate = LocalDate.fromDateFields(calendarEntry.getEndPeriodDate());
        }
    }

    //reset this buckets asOfDate
    asOfDate = newAsOfDate;

}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.KPMEAccrualCategoryBucket.java

License:Educational Community License

private void adjustBalances(CalendarEntry calendarEntry, DateTime rolloverDate, Set<String> assignmentKeys)
        throws KPMEBalanceException {

    //fetch calendar entries in this sequence belonging to the current leave year.
    String dateString = TKUtils.formatDate(LocalDate.now());
    List<CalendarEntry> calendarEntries = HrServiceLocator.getCalendarEntryService()
            .getAllCalendarEntriesForCalendarIdAndYear(calendarEntry.getHrCalendarId(),
                    dateString.substring(6, 10));

    //calendar change into a different leave calendar year
    if (rolloverDate != null) {

        //clear all balances.
        clearLeaveBalances();/* w w  w.j  av a 2 s . c  o  m*/

        //reset the asOfDate this bucket will go off of, as well as those of the leave balances
        adjustAsOfDates(calendarEntry, calendarEntries);

        //TODO: if in current calendar year, use current date + planning months for extent of fetch.
        List<LeaveBlock> leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocksSinceCarryOver(
                principalCalendar.getPrincipalId(),
                LmServiceLocator.getLeaveBlockService().getLastCarryOverBlocks(
                        principalCalendar.getPrincipalId(), rolloverDate.minusDays(1).toLocalDate()),
                rolloverDate.plusDays(365).toLocalDate(), true);

        //retrieve (if any) last carryover blocks given the new asOfDate
        Map<String, LeaveBlock> carryOverBlocks = LmServiceLocator.getLeaveBlockService()
                .getLastCarryOverBlocks(principalCalendar.getPrincipalId(), asOfDate);

        //method taken from leave summary service - map general leave block fetch by accrual category
        Map<String, List<LeaveBlock>> accrualCategoryMappedLeaveBlocks = mapLeaveBlocksByAccrualCategory(
                leaveBlocks);

        //merge carryOverBlock map with accrualCategoryMappedLeaveBlocks.
        for (Entry<String, LeaveBlock> entry : carryOverBlocks.entrySet()) {
            //TODO: modify CarryOverLeaveBalance to identify and make use of CARRY_OVER type leave block
            if (accrualCategoryMappedLeaveBlocks.containsKey(entry.getKey()))
                accrualCategoryMappedLeaveBlocks.get(entry.getKey()).add(entry.getValue());
            else {
                List<LeaveBlock> carryOverList = new ArrayList<LeaveBlock>();
                carryOverList.add(entry.getValue());
                accrualCategoryMappedLeaveBlocks.put(entry.getKey(), carryOverList);
            }

        }
        //add leave blocks, accrual category by accrual category, to this bucket.
        for (Entry<String, List<LeaveBlock>> entry : accrualCategoryMappedLeaveBlocks.entrySet()) {
            for (LeaveBlock leaveBlock : entry.getValue()) {
                try {
                    addLeaveBlock(leaveBlock);
                } catch (KPMEBalanceException e) {
                    InstantiationException ie = new InstantiationException();
                    ie.setStackTrace(e.getStackTrace());
                    ie.printStackTrace();
                }
            }
        }
    } else {
        //Calendar change within the same leave year.

        List<String> assignmentKeyList = new ArrayList<String>();
        assignmentKeyList.addAll(assignmentKeys);

        List<LeaveBlock> leaveBlocks = new ArrayList<LeaveBlock>();

        //determine which leave blocks are affected by the calendar change, remove them, and re-add them under the new asOfDate
        if (calendarEntry.getEndPeriodFullDateTime()
                .isBefore(viewingCalendarEntry.getEndPeriodFullDateTime().getMillis())) {
            //need to remove leave blocks from otherLeaveCalendarDocument begin date to thisLeaveCalendarDocument end date
            leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(
                    principalCalendar.getPrincipalId(),
                    LocalDate.fromDateFields(calendarEntry.getBeginPeriodDateTime()),
                    LocalDate.fromDateFields(viewingCalendarEntry.getEndPeriodDateTime()));
            //leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForLeaveCalendar(principalCalendar.getPrincipalId(), LocalDate.fromDateFields(calendarEntry.getBeginPeriodDateTime()), LocalDate.fromDateFields(viewingCalendarEntry.getEndPeriodDateTime()), assignmentKeyList);
        } else {
            //need to remove leave blocks from thisLeaveCalendarDocument begin date to otherLeaveCalendarDocument end date
            leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocks(
                    principalCalendar.getPrincipalId(),
                    LocalDate.fromDateFields(viewingCalendarEntry.getBeginPeriodDateTime()),
                    LocalDate.fromDateFields(calendarEntry.getEndPeriodDateTime()));
            //leaveBlocks = LmServiceLocator.getLeaveBlockService().getLeaveBlocksForLeaveCalendar(principalCalendar.getPrincipalId(), LocalDate.fromDateFields(viewingCalendarEntry.getBeginPeriodDateTime()), LocalDate.fromDateFields(calendarEntry.getEndPeriodDateTime()), assignmentKeyList);
        }
        //remove affected leave blocks
        for (LeaveBlock block : leaveBlocks) {
            removeLeaveBlock(block);
        }

        //update this bucket and its leave balances with new relative date information
        LocalDate newAsOfDate = null;
        DateTime currentLeavePlanStartDate = HrServiceLocator.getLeavePlanService()
                .getFirstDayOfLeavePlan(principalCalendar.getLeavePlan(), LocalDate.now());
        if (calendarEntry.getEndPeriodDate().before(currentLeavePlanStartDate.toDate())) {
            //require balances as of the final day of the leave calendar year.
            DateTime calendarEntryLeavePlanRolloverDate = HrServiceLocator.getLeavePlanService()
                    .getRolloverDayOfLeavePlan(principalCalendar.getLeavePlan(),
                            LocalDate.fromDateFields(calendarEntry.getEndPeriodDate()));
            newAsOfDate = LocalDate.fromDateFields(calendarEntryLeavePlanRolloverDate.toDate()).minusDays(1);
        } else {
            Interval interval = new Interval(calendarEntry.getBeginPeriodDateTime().getTime(),
                    calendarEntry.getEndPeriodDateTime().getTime());
            if (interval.contains(LocalDate.now().toDate().getTime())) {
                newAsOfDate = LocalDate.now();
            } else if (calendarEntry.getBeginPeriodDate().before(LocalDate.now().toDate()))
                newAsOfDate = LocalDate.fromDateFields(calendarEntry.getEndPeriodDate()).minusDays(1);
            else // if it's in the calendar interval above, the equals case is taken care of, begin date must be after today
                newAsOfDate = LocalDate.fromDateFields(calendarEntry.getBeginPeriodDate()).minusDays(1);
        }

        asOfDate = newAsOfDate;

        for (Entry<String, List<LeaveBalance>> leaveBalance : leaveBalances.entrySet()) {
            for (LeaveBalance balance : leaveBalance.getValue()) {
                balance.calendarPeriodBeginDate = LocalDate
                        .fromDateFields(calendarEntry.getBeginPeriodDateTime());
                balance.calendarPeriodEndDate = LocalDate.fromDateFields(calendarEntry.getEndPeriodDateTime());
                balance.asOfDate = newAsOfDate;
            }
        }
        //re-add the affected leave blocks under the new date / calendar information
        for (LeaveBlock block : leaveBlocks) {
            addLeaveBlock(block);
        }
    }
}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.LeaveBalance.java

License:Educational Community License

protected LeaveBalance(AccrualCategory accrualCategory, PrincipalHRAttributes principalCalendar) {
    this.accrualCategory = accrualCategory;
    this.principalCalendar = principalCalendar;
    asOfDate = LocalDate.now();
    balance = new BigDecimal(0);
}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.PendingLeaveBalance.java

License:Educational Community License

public PendingLeaveBalance(AccrualCategory accrualCategory, PrincipalHRAttributes principalCalendar) {
    super(accrualCategory, principalCalendar);
    asOfDate = LocalDate.now();
    leaveBlocks = new ArrayList<LeaveBlock>();
}

From source file:org.kuali.kpme.tklm.leave.accrual.bucket.YearToDateEarnedLeaveBalance.java

License:Educational Community License

public YearToDateEarnedLeaveBalance(AccrualCategory accrualCategory, PrincipalHRAttributes principalCalendar) {
    super(accrualCategory, principalCalendar);
    asOfDate = LocalDate.now();
    leaveBlocks = new ArrayList<LeaveBlock>();
}