Example usage for org.joda.time LocalDate toString

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

Introduction

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

Prototype

@ToString
public String toString() 

Source Link

Document

Output the date time in ISO8601 format (yyyy-MM-dd).

Usage

From source file:org.mifosplatform.portfolio.loanaccount.domain.Loan.java

License:Mozilla Public License

public Map<String, Object> loanApplicationApproval(final AppUser currentUser, final JsonCommand command,
        final JsonArray disbursementDataArray, final LoanLifecycleStateMachine loanLifecycleStateMachine) {

    validateAccountStatus(LoanEvent.LOAN_APPROVED);

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    /*//  www  . ja v  a2  s  .co m
     * statusEnum is holding the possible new status derived from
     * loanLifecycleStateMachine.transition.
     */

    final LoanStatus newStatusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_APPROVED,
            LoanStatus.fromInt(this.loanStatus));

    /*
     * FIXME: There is no need to check below condition, if
     * loanLifecycleStateMachine.transition is doing it's responsibility
     * properly. Better implementation approach is, if code passes invalid
     * combination of states (fromState and toState), state machine should
     * return invalidate state and below if condition should check for not
     * equal to invalidateState, instead of check new value is same as
     * present value.
     */

    if (!newStatusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) {
        this.loanStatus = newStatusEnum.getValue();
        actualChanges.put("status", LoanEnumerations.status(this.loanStatus));

        // only do below if status has changed in the 'approval' case
        LocalDate approvedOn = command.localDateValueOfParameterNamed("approvedOnDate");
        String approvedOnDateChange = command.stringValueOfParameterNamed("approvedOnDate");
        if (approvedOn == null) {
            approvedOn = command.localDateValueOfParameterNamed("eventDate");
            approvedOnDateChange = command.stringValueOfParameterNamed("eventDate");
        }

        LocalDate expecteddisbursementDate = command.localDateValueOfParameterNamed("expectedDisbursementDate");

        BigDecimal approvedLoanAmount = command
                .bigDecimalValueOfParameterNamed(LoanApiConstants.approvedLoanAmountParameterName);

        if (approvedLoanAmount != null) {

            // Approved amount has to be less than or equal to principal
            // amount demanded

            if (approvedLoanAmount.compareTo(this.proposedPrincipal) == -1) {

                this.approvedPrincipal = approvedLoanAmount;

                /*
                 * All the calculations are done based on the principal
                 * amount, so it is necessary to set principal amount to
                 * approved amount
                 */

                this.loanRepaymentScheduleDetail.setPrincipal(approvedLoanAmount);

                actualChanges.put(LoanApiConstants.approvedLoanAmountParameterName, approvedLoanAmount);
                actualChanges.put(LoanApiConstants.disbursementPrincipalParameterName, approvedLoanAmount);
            } else if (approvedLoanAmount.compareTo(this.proposedPrincipal) == 1) {
                final String errorMessage = "Loan approved amount can't be greater than loan amount demanded.";
                throw new InvalidLoanStateTransitionException("approval",
                        "amount.can't.be.greater.than.loan.amount.demanded", errorMessage,
                        this.proposedPrincipal, approvedLoanAmount);
            }

            /* Update disbursement details */
            if (disbursementDataArray != null) {
                updateDisbursementDetails(command, actualChanges);
            }
        }
        if (loanProduct.isMultiDisburseLoan()) {

            if (this.disbursementDetails.isEmpty()) {
                final String errorMessage = "For this loan product, disbursement details must be provided";
                throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName,
                        errorMessage);
            }

            if (this.disbursementDetails.size() > loanProduct.maxTrancheCount()) {
                final String errorMessage = "Number of tranche shouldn't be greter than "
                        + loanProduct.maxTrancheCount();
                throw new ExceedingTrancheCountException(LoanApiConstants.disbursementDataParameterName,
                        errorMessage, loanProduct.maxTrancheCount(), disbursementDetails.size());
            }
        }
        this.approvedOnDate = approvedOn.toDate();
        this.approvedBy = currentUser;
        actualChanges.put("locale", command.locale());
        actualChanges.put("dateFormat", command.dateFormat());
        actualChanges.put("approvedOnDate", approvedOnDateChange);

        final LocalDate submittalDate = new LocalDate(this.submittedOnDate);
        if (approvedOn.isBefore(submittalDate)) {
            final String errorMessage = "The date on which a loan is approved cannot be before its submittal date: "
                    + submittalDate.toString();
            throw new InvalidLoanStateTransitionException("approval", "cannot.be.before.submittal.date",
                    errorMessage, getApprovedOnDate(), submittalDate);
        }

        if (expecteddisbursementDate != null) {
            this.expectedDisbursementDate = expecteddisbursementDate.toDate();
            actualChanges.put("expectedDisbursementDate", expectedDisbursementDate);

            if (expecteddisbursementDate.isBefore(approvedOn)) {
                final String errorMessage = "The expected disbursement date should be either on or after the approval date: "
                        + approvedOn.toString();
                throw new InvalidLoanStateTransitionException("expecteddisbursal",
                        "should.be.on.or.after.approval.date", errorMessage, getApprovedOnDate(),
                        expecteddisbursementDate);
            }
        }

        validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_APPROVED, approvedOn);

        if (approvedOn.isAfter(DateUtils.getLocalDateOfTenant())) {
            final String errorMessage = "The date on which a loan is approved cannot be in the future.";
            throw new InvalidLoanStateTransitionException("approval", "cannot.be.a.future.date", errorMessage,
                    getApprovedOnDate());
        }

        if (this.loanOfficer != null) {
            final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory = LoanOfficerAssignmentHistory
                    .createNew(this, this.loanOfficer, approvedOn);
            this.loanOfficerHistory.add(loanOfficerAssignmentHistory);
        }
    }

    return actualChanges;
}

From source file:org.projectbuendia.client.filter.db.patient.AgeFilter.java

License:Apache License

@Override
public String[] getSelectionArgs(CharSequence constraint) {
    LocalDate earliestBirthdate = LocalDate.now().minusYears(mYears);
    return new String[] { earliestBirthdate.toString() };
}

From source file:org.projectbuendia.client.json.LocalDateSerializer.java

License:Apache License

@Override
public JsonElement serialize(LocalDate date, Type type, JsonSerializationContext context) {
    return new JsonPrimitive(date.toString());
}

From source file:org.projectbuendia.client.utils.date.Dates.java

License:Apache License

/** Converts a LocalDate to a yyyy-mm-dd String. */
@Nullable/*from   w  w w .  j a v a 2s. c o m*/
public static String toString(@Nullable LocalDate date) {
    return date == null ? null : date.toString();
}

From source file:org.projectbuendia.client.utils.Utils.java

License:Apache License

/** Converts a nullable LocalDate to a yyyy-mm-dd String. */
public static @Nullable String toString(@Nullable LocalDate date) {
    return date == null ? null : date.toString();
}

From source file:org.qi4j.runtime.types.JodaLocalDateType.java

License:Open Source License

public void toJSON(Object value, JSONWriter json) throws JSONException {
    LocalDate date = (LocalDate) value;
    json.value(date.toString());
}

From source file:org.qi4j.runtime.types.JodaLocalDateType.java

License:Open Source License

public Object toJSON(Object value) throws JSONException {
    LocalDate date = (LocalDate) value;
    return date.toString();
}

From source file:org.supercsv.cellprocessor.joda.FmtLocalDate.java

License:Apache License

/**
 * {@inheritDoc}//from ww  w.  ja  va 2 s  .  co m
 */
@Override
protected String format(final LocalDate jodaType) {
    return jodaType.toString();
}

From source file:se.inera.statistics.hsa.adapter.LocalDateAdapter.java

License:Open Source License

/**
 * Converts a Joda Time LocalDate to an xs:date.
 *///from www  . j a v a 2  s. com
public static String printDate(LocalDate date) {
    return date.toString();
}

From source file:vn.webapp.controller.cp.RoomsController.java

@RequestMapping(value = "add-a-room-loan", method = RequestMethod.POST)
public String addARoomLoan(HttpServletRequest request,
        @Valid @ModelAttribute("roomLoanFormAdd") RoomLoanValidation roomLoanValidation, BindingResult result,
        Map model, HttpSession session) {

    if (result.hasErrors()) {
        List<AcademicYear> academicYearList = academicYearService.list();
        AcademicYear curAcadYear = academicYearService.getCurAcadYear();
        List<AcademicYear> otherAcadYearList = new ArrayList<AcademicYear>();
        for (AcademicYear aY : academicYearList) {
            if (!aY.getACAYEAR_Code().equals(curAcadYear.getACAYEAR_Code()))
                otherAcadYearList.add(aY);
        }/*from   w w w  .ja  v  a  2  s . co  m*/
        model.put("academicYearList", otherAcadYearList);
        model.put("curAcadYear", curAcadYear);
        return "cp.addRoomLoan";
    } else {
        String academicYear = roomLoanValidation.getAcademicYear();
        String dateString = roomLoanValidation.getDayMonthYearInput_day();
        String dayString = roomLoanValidation.getDayWeekInput_day();
        String weekString = roomLoanValidation.getDayWeekInput_week();
        String room = roomLoanValidation.getRoomCode();
        String slotStart = roomLoanValidation.getSlotStart();
        String slotEnd = roomLoanValidation.getSlotEnd();

        /* Convert date to day and week */
        List<AcademicYear> academicYearList = academicYearService.list();
        String firstdateStr = "";
        String enddateStr = "";
        for (AcademicYear aY : academicYearList) {
            if (aY.getACAYEAR_Code().equals(academicYear)) {
                firstdateStr = aY.getACAYEAR_FromDate();
                enddateStr = aY.getACAYEAR_ToDate();
                break;
            }
        }

        DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");
        LocalDate firstdate = fmt.parseLocalDate(firstdateStr);
        LocalDate enddate = fmt.parseLocalDate(enddateStr);

        if (!dateString.equals("")) {
            LocalDate querydate = fmt.parseLocalDate(dateString);
            int dayNum = Days.daysBetween(firstdate, querydate).getDays();
            if ((dayNum <= 0) || (Days.daysBetween(querydate, enddate).getDays() < 0)) {
                session.setAttribute("errorAddRoomLoanFwd",
                        "Ngy bn nhp khng c trong nm h?c. Hy ch?n ngy hp l!");
                return "cp.addRoomLoan";
            }
            dayString = Integer.toString(querydate.getDayOfWeek() + 1);
            if (dayString.equals("8"))
                dayString = "Ch nht";
            weekString = Integer.toString(dayNum / 7 + 1);
            roomLoanValidation.setDayWeekInput_day(dayString);
            roomLoanValidation.setDayWeekInput_week(weekString);
        } else if (!(dayString.equals("") || weekString.equals(""))) {
            try {
                if (dayString.equals("Ch nht"))
                    dayString = "8";
                LocalDate querydate = firstdate
                        .plusDays(7 * (Integer.parseInt(weekString) - 1) + Integer.parseInt(dayString) - 2);
                roomLoanValidation.setDayMonthYearInput_day(querydate.toString());
            } catch (Exception e) {
                roomLoanValidation.setDayMonthYearInput_day("Nhi?u ngy");
            }
        } else {
            session.setAttribute("errorAddRoomLoanFwd", "Khng th thm thng tin mn phng "
                    + roomLoanValidation.getRoomCode() + " v thiu thng tin ngy thng mn phng");
            return "redirect:" + this.baseUrl + "/cp/AddRoomLoan.html";
        }

        if (roomsService.loadByCode(room) == null) {
            session.setAttribute("errorAddRoomLoanFwd", "M phng " + room
                    + " khng c trong c s d liu phng. Hy kim tra li!");
            return "redirect:" + this.baseUrl + "/cp/AddRoomLoan.html";
        }

        try {
            String RL_Code = roomLoanValidation.getRoomCode() + "-" + roomLoanValidation.getAcademicYear() + "-"
                    + roomLoanValidation.getDayWeekInput_week() + "-"
                    + roomLoanValidation.getDayWeekInput_day();
            RoomLoan roomLoan = roomLoanService.loadByCode(RL_Code);
            if (roomLoan == null)
                roomLoanService.save(roomLoanValidation.getRoomCode(), roomLoanValidation.getDayWeekInput_day(),
                        roomLoanValidation.getDayWeekInput_week(), roomLoanValidation.getAcademicYear(),
                        roomLoanValidation.getDayMonthYearInput_day(),
                        roomLoanValidation.getSlotStart() + "-" + roomLoanValidation.getSlotEnd(),
                        roomLoanValidation.getNote());
            return "redirect:" + this.baseUrl + "/cp/RoomLoans.html";
        } catch (Exception e) {
            model.put("status", "You failed to edit room loan for" + roomLoanValidation.getRoomCode());
        }
    }
    return "cp.addRoomLoan";
}