Example usage for java.lang Short valueOf

List of usage examples for java.lang Short valueOf

Introduction

In this page you can find the example usage for java.lang Short valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Short valueOf(short s) 

Source Link

Document

Returns a Short instance representing the specified short value.

Usage

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testUpdateLoanSuccessWithRegeneratingNewRepaymentSchedule() throws Exception {
    // newDate is the new disbursement date
    Date newDate = incrementCurrentDate(14);
    // first installment date is the first installment which is one
    // week after the disbursement date since this is a weekly loan
    Date firstInstallmentDate = incrementCurrentDate(21);
    accountBO = getLoanAccount();//from w ww .  j a v  a2 s . co m
    accountBO.setUserContext(TestObjectFactory.getContext());
    accountBO.changeStatus(AccountState.LOAN_APPROVED, null, "");

    LoanBO loanBO = (LoanBO) accountBO;
    ((LoanBO) accountBO).updateLoan(loanBO.isInterestDeductedAtDisbursement(), loanBO.getLoanAmount(),
            loanBO.getInterestRate(), loanBO.getNoOfInstallments(), newDate, loanBO.getGracePeriodDuration(),
            loanBO.getBusinessActivityId(), loanBO.getCollateralNote(), null, null, false, null, null);
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.closeSession();
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId());
    Date newActionDate = DateUtils.getDateWithoutTimeStamp(
            accountBO.getAccountActionDate(Short.valueOf("1")).getActionDate().getTime());
    Assert.assertEquals("New repayment schedule generated, so first installment date should be same as newDate",
            firstInstallmentDate, newActionDate);
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testUpdateLoanWithoutRegeneratingNewRepaymentSchedule() throws Exception {
    Date newDate = incrementCurrentDate(14);
    accountBO = getLoanAccount();/*from  ww  w.  j av a 2  s . co  m*/
    Date oldActionDate = DateUtils.getDateWithoutTimeStamp(
            accountBO.getAccountActionDate(Short.valueOf("1")).getActionDate().getTime());
    LoanBO loanBO = (LoanBO) accountBO;
    ((LoanBO) accountBO).updateLoan(loanBO.isInterestDeductedAtDisbursement(), loanBO.getLoanAmount(),
            loanBO.getInterestRate(), loanBO.getNoOfInstallments(), newDate, loanBO.getGracePeriodDuration(),
            loanBO.getBusinessActivityId(), loanBO.getCollateralNote(), null, null, false, null, null);
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.closeSession();
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId());
    Date newActionDate = DateUtils.getDateWithoutTimeStamp(
            accountBO.getAccountActionDate(Short.valueOf("1")).getActionDate().getTime());
    Assert.assertEquals(
            "Didn't generate new repayment schedule, so first installment date should be same as before ",
            oldActionDate, newActionDate);
}

From source file:com.mawujun.util.ArrayUtils.java

/**
 * <p>Removes occurrences of specified elements, in specified quantities,
 * from the specified array. All subsequent elements are shifted left.
 * For any element-to-be-removed specified in greater quantities than
 * contained in the original array, no change occurs beyond the
 * removal of the existing matching items.</p>
 *
 * <p>This method returns a new array with the same elements of the input
 * array except for the earliest-encountered occurrences of the specified
 * elements. The component type of the returned array is always the same
 * as that of the input array.</p>
 *
 * <pre>//  w  ww  . j ava2 s  . co  m
 * ArrayUtils.removeElements(null, 1, 2)      = null
 * ArrayUtils.removeElements([], 1, 2)        = []
 * ArrayUtils.removeElements([1], 2, 3)       = [1]
 * ArrayUtils.removeElements([1, 3], 1, 2)    = [3]
 * ArrayUtils.removeElements([1, 3, 1], 1)    = [3, 1]
 * ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
 * </pre>
 *
 * @param array  the array to remove the element from, may be {@code null}
 * @param values the elements to be removed
 * @return A new array containing the existing elements except the
 *         earliest-encountered occurrences of the specified elements.
 * @since 3.0.1
 */
public static short[] removeElements(short[] array, short... values) {
    if (isEmpty(array) || isEmpty(values)) {
        return clone(array);
    }
    HashMap<Short, MutableInt> occurrences = new HashMap<Short, MutableInt>(values.length);
    for (short v : values) {
        Short boxed = Short.valueOf(v);
        MutableInt count = occurrences.get(boxed);
        if (count == null) {
            occurrences.put(boxed, new MutableInt(1));
        } else {
            count.increment();
        }
    }
    HashSet<Integer> toRemove = new HashSet<Integer>();
    for (Map.Entry<Short, MutableInt> e : occurrences.entrySet()) {
        Short v = e.getKey();
        int found = 0;
        for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
            found = indexOf(array, v.shortValue(), found);
            if (found < 0) {
                break;
            }
            toRemove.add(found++);
        }
    }
    return removeAll(array, extractIndices(toRemove));
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testCreateNormalLoanAccount() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    MeetingBO meeting = TestObjectFactory.createMeeting(
            TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_SECOND_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", ApplicableTo.GROUPS, startDate,
            PrdStatus.LOAN_ACTIVE, 300.0, 1.2, 3, InterestType.FLAT, center.getCustomerMeeting().getMeeting());
    UserContext userContext = TestUtils.makeUser();
    userContext.setLocaleId(null);//from   w  w w. ja  v a 2 s. co m
    List<FeeView> feeViewList = new ArrayList<FeeView>();
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.LOAN, "100",
            RecurrenceType.WEEKLY, Short.valueOf("3"));
    feeViewList.add(new FeeView(userContext, periodicFee));
    FeeBO upfrontFee = TestObjectFactory.createOneTimeRateFee("Upfront Fee", FeeCategory.LOAN,
            Double.valueOf("20"), FeeFormula.AMOUNT, FeePayment.UPFRONT);
    feeViewList.add(new FeeView(userContext, upfrontFee));
    FeeBO disbursementFee = TestObjectFactory.createOneTimeAmountFee("Disbursement Fee", FeeCategory.LOAN, "30",
            FeePayment.TIME_OF_DISBURSEMENT);
    feeViewList.add(new FeeView(userContext, disbursementFee));

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            startDate, false, 1.2, (short) 0, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO,
            SHORT_ZERO, false);
    new TestObjectPersistence().persist(accountBO);

    Map<String, String> fees0 = new HashMap<String, String>();

    Map<String, String> fees1 = new HashMap<String, String>();
    fees1.put("Periodic Fee", "100.0");

    Map<String, String> fees2 = new HashMap<String, String>();
    fees2.put("Periodic Fee", "100.0");
    fees2.put("Upfront Fee", "60.0");

    Set<AccountActionDateEntity> actionDateEntities = ((LoanBO) accountBO).getAccountActionDates();
    LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities);

    checkLoanScheduleEntity(incrementCurrentDate(14), "50.8", "0.2", fees2, paymentsArray[0]);
    checkLoanScheduleEntity(null, "50.8", "0.2", fees0, paymentsArray[1]);
    checkLoanScheduleEntity(null, "50.8", "0.2", fees1, paymentsArray[2]);
    checkLoanScheduleEntity(null, "50.8", "0.2", fees1, paymentsArray[3]);
    checkLoanScheduleEntity(null, "50.8", "0.2", fees0, paymentsArray[4]);
    checkLoanScheduleEntity(incrementCurrentDate(14 * 6), "46.0", "0.0", fees1, paymentsArray[5]);

    Assert.assertEquals(3, accountBO.getAccountFees().size());
    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        if (accountFeesEntity.getFees().getFeeName().equals("Upfront Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "60.0"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("20.0"), accountFeesEntity.getFeeAmount());
        } else if (accountFeesEntity.getFees().getFeeName().equals("Disbursement Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "30.0"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("30.0"), accountFeesEntity.getFeeAmount());
        } else {
            Assert.assertEquals(new Money(getCurrency(), "100.0"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("100.0"), accountFeesEntity.getFeeAmount());
        }
    }
    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
    Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal());
    Assert.assertEquals(new Money(getCurrency(), "1.0"), loanSummaryEntity.getOriginalInterest());
    Assert.assertEquals(new Money(getCurrency(), "490.0"), loanSummaryEntity.getOriginalFees());
    Assert.assertEquals(new Money(getCurrency(), "0.0"), loanSummaryEntity.getOriginalPenalty());
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testCreateNormalLoanAccountWithPricipalOnlyGrace() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(
            TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_SECOND_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", "Loan".substring(0, 1),
            ApplicableTo.GROUPS, new Date(System.currentTimeMillis()), PrdStatus.LOAN_ACTIVE, 300.0, 1.2,
            (short) 3, InterestType.FLAT, true, false, center.getCustomerMeeting().getMeeting(),
            GraceType.PRINCIPALONLYGRACE, "1", "1");
    UserContext userContext = TestUtils.makeUser();
    userContext.setLocaleId(null);//from  w w  w. j  a v a2s  .  c  o m
    List<FeeView> feeViewList = new ArrayList<FeeView>();
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.LOAN, "100",
            RecurrenceType.WEEKLY, Short.valueOf("3"));
    feeViewList.add(new FeeView(userContext, periodicFee));
    FeeBO upfrontFee = TestObjectFactory.createOneTimeRateFee("Upfront Fee", FeeCategory.LOAN,
            Double.valueOf("20"), FeeFormula.AMOUNT, FeePayment.UPFRONT);
    feeViewList.add(new FeeView(userContext, upfrontFee));
    FeeBO disbursementFee = TestObjectFactory.createOneTimeAmountFee("Disbursement Fee", FeeCategory.LOAN, "30",
            FeePayment.TIME_OF_DISBURSEMENT);
    feeViewList.add(new FeeView(userContext, disbursementFee));

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            new Date(System.currentTimeMillis()), false, 1.2, (short) 1, null, feeViewList, null, DOUBLE_ZERO,
            DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, false);
    new TestObjectPersistence().persist(accountBO);

    Map<String, String> fees0 = new HashMap<String, String>();

    Map<String, String> fees1 = new HashMap<String, String>();
    fees1.put("Periodic Fee", "100.0");

    Map<String, String> fees2 = new HashMap<String, String>();
    fees2.put("Periodic Fee", "100.0");
    fees2.put("Upfront Fee", "60.0");

    Set<AccountActionDateEntity> actionDateEntities = ((LoanBO) accountBO).getAccountActionDates();
    LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities);

    checkLoanScheduleEntity(incrementCurrentDate(14), "0.0", "1.0", fees2, paymentsArray[0]);
    checkLoanScheduleEntity(null, "60.8", "0.2", fees0, paymentsArray[1]);
    checkLoanScheduleEntity(null, "60.8", "0.2", fees1, paymentsArray[2]);
    checkLoanScheduleEntity(null, "60.8", "0.2", fees1, paymentsArray[3]);
    checkLoanScheduleEntity(null, "60.8", "0.2", fees0, paymentsArray[4]);
    checkLoanScheduleEntity(incrementCurrentDate(14 * 6), "56.8", "-0.8", fees1, paymentsArray[5]);

    Assert.assertEquals(3, accountBO.getAccountFees().size());
    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        if (accountFeesEntity.getFees().getFeeName().equals("Upfront Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "60.0"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("20.0"), accountFeesEntity.getFeeAmount());
        } else if (accountFeesEntity.getFees().getFeeName().equals("Disbursement Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "30.0"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("30.0"), accountFeesEntity.getFeeAmount());
        } else {
            Assert.assertEquals(new Money(getCurrency(), "100.0"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("100.0"), accountFeesEntity.getFeeAmount());
        }
    }
    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
    Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal());
    Assert.assertEquals(new Money(getCurrency(), "1.0"), loanSummaryEntity.getOriginalInterest());
    Assert.assertEquals(new Money(getCurrency(), "490.0"), loanSummaryEntity.getOriginalFees());
    Assert.assertEquals(new Money(getCurrency(), "0.0"), loanSummaryEntity.getOriginalPenalty());
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testCreateNormalLoanAccountWithMonthlyInstallments() throws Exception {
    Short dayOfMonth = (short) 1;

    /*//from  w ww .  j  a  v a2  s  . c  o m
     * A date in the past won't work (we don't yet have a way of telling the
     * validation code "pretend it is such-and-such a date"). The
     * errors.startdateexception message says the date must be less than a
     * year in the future (it really means an end date less than the end of
     * next year).
     */
    long sampleTime = new DateMidnight(2010, 11, 24).getMillis();

    MeetingBO meeting = TestObjectFactory.getNewMeeting(MONTHLY, EVERY_SECOND_MONTH, CUSTOMER_MEETING, MONDAY);
    Calendar meetingStart = Calendar.getInstance();
    meetingStart.setTimeInMillis(sampleTime);
    meeting.setMeetingStartDate(meetingStart.getTime());
    meeting.getMeetingDetails().getMeetingRecurrence().setDayNumber(dayOfMonth);
    TestObjectFactory.createMeeting(meeting);
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    Date loanStart = new Date(sampleTime);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", ApplicableTo.GROUPS, loanStart,
            PrdStatus.LOAN_ACTIVE, 300.0, 1.2, 3, InterestType.FLAT, center.getCustomerMeeting().getMeeting());
    Calendar disbursementDate = new GregorianCalendar();
    disbursementDate.setTimeInMillis(sampleTime);
    int year = disbursementDate.get(Calendar.YEAR);
    int zeroBasedMonth = disbursementDate.get(Calendar.MONTH);
    /*
     * TODO: this "if" is a relic from when sampleTime was based on when the
     * test was run. We should test these two cases somehow.
     */
    if (disbursementDate.get(Calendar.DAY_OF_MONTH) == dayOfMonth.intValue()) {
        disbursementDate = new GregorianCalendar(year, zeroBasedMonth, dayOfMonth);
    } else {
        disbursementDate = new GregorianCalendar(year, zeroBasedMonth + 1, dayOfMonth);
    }
    UserContext userContext = TestUtils.makeUser();
    userContext.setLocaleId(null);
    List<FeeView> feeViewList = new ArrayList<FeeView>();
    FeeBO upfrontFee = TestObjectFactory.createOneTimeRateFee("Upfront Fee", FeeCategory.LOAN,
            Double.valueOf("20"), FeeFormula.AMOUNT, FeePayment.UPFRONT);
    feeViewList.add(new FeeView(userContext, upfrontFee));
    FeeBO disbursementFee = TestObjectFactory.createOneTimeRateFee("Disbursement Fee", FeeCategory.LOAN,
            Double.valueOf("30"), FeeFormula.AMOUNT_AND_INTEREST, FeePayment.TIME_OF_DISBURSEMENT);
    feeViewList.add(new FeeView(userContext, disbursementFee));
    FeeBO firstRepaymentFee = TestObjectFactory.createOneTimeRateFee("First Repayment Fee", FeeCategory.LOAN,
            Double.valueOf("40"), FeeFormula.INTEREST, FeePayment.TIME_OF_FIRSTLOANREPAYMENT);
    feeViewList.add(new FeeView(userContext, firstRepaymentFee));
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.LOAN, "100",
            RecurrenceType.MONTHLY, Short.valueOf("1"));
    feeViewList.add(new FeeView(userContext, periodicFee));
    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            disbursementDate.getTime(), false, 1.2, (short) 0, null, feeViewList, null, DOUBLE_ZERO,
            DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, false);
    new TestObjectPersistence().persist(accountBO);

    Map<String, String> fees1 = new HashMap<String, String>();
    fees1.put("Periodic Fee", "200.0");

    Map<String, String> fees3 = new HashMap<String, String>();
    fees3.put("Periodic Fee", "100.0");
    fees3.put("Upfront Fee", "60.0");
    fees3.put("First Repayment Fee", "1.5");

    Set<AccountActionDateEntity> actionDateEntities = ((LoanBO) accountBO).getAccountActionDates();
    LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities);

    checkLoanScheduleEntity(null, "50.9", "0.6", fees3, paymentsArray[0]);
    checkLoanScheduleEntity(null, "50.4", "0.6", fees1, paymentsArray[1]);
    checkLoanScheduleEntity(null, "50.4", "0.6", fees1, paymentsArray[2]);
    checkLoanScheduleEntity(null, "50.4", "0.6", fees1, paymentsArray[3]);
    checkLoanScheduleEntity(null, "50.4", "0.6", fees1, paymentsArray[4]);
    checkLoanScheduleEntity(null, "47.5", "1.5", fees1, paymentsArray[5]);

    Assert.assertEquals(4, accountBO.getAccountFees().size());
    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        if (accountFeesEntity.getFees().getFeeName().equals("Upfront Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "60.0"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("20.0"), accountFeesEntity.getFeeAmount());
        } else if (accountFeesEntity.getFees().getFeeName().equals("Disbursement Fee")) {
            // TODO: fee_rounding should there be 2 digits to
            // the right of the decimal here?
            Assert.assertEquals(new Money(getCurrency(), "91.08"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("30.0"), accountFeesEntity.getFeeAmount());
        } else if (accountFeesEntity.getFees().getFeeName().equals("First Repayment Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "1.44"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("40.0"), accountFeesEntity.getFeeAmount());
        } else {
            Assert.assertEquals(new Money(getCurrency(), "100.0"), accountFeesEntity.getAccountFeeAmount());
            Assert.assertEquals(new Double("100.0"), accountFeesEntity.getFeeAmount());
        }
    }
    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
    Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal());
    // TODO: fee_rounding is the difference in original interest just
    // a result of compounded rounding adjustments?
    // Assert.assertEquals(new Money(getCurrency(), "3.6"),
    // loanSummaryEntity.getOriginalInterest());
    Assert.assertEquals(new Money(getCurrency(), "4.5"), loanSummaryEntity.getOriginalInterest());
    // Assert.assertEquals(new Money(getCurrency(), "1252.5"),
    // loanSummaryEntity.getOriginalFees());
    Assert.assertEquals(new Money(getCurrency(), "1252.58"), loanSummaryEntity.getOriginalFees());
    Assert.assertEquals(new Money(getCurrency(), "0.0"), loanSummaryEntity.getOriginalPenalty());
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testDisburseLoanWithAllTypeOfFees() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    Short dayOfMonth = (short) 25;
    MeetingBO meeting = TestObjectFactory.getNewMeeting(MONTHLY, EVERY_MONTH, CUSTOMER_MEETING, MONDAY);

    TestObjectFactory.createMeeting(meeting);
    meeting.setMeetingStartDate(new Date());
    meeting.getMeetingDetails().getMeetingRecurrence().setDayNumber(dayOfMonth);
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", ApplicableTo.GROUPS, startDate,
            PrdStatus.LOAN_ACTIVE, 300.0, 1.2, 3, InterestType.FLAT, center.getCustomerMeeting().getMeeting());
    Calendar disbursementDate = new GregorianCalendar();
    int year = disbursementDate.get(Calendar.YEAR);
    int month = disbursementDate.get(Calendar.MONTH);
    int day = 25;
    if (disbursementDate.get(Calendar.DAY_OF_MONTH) == dayOfMonth.intValue()) {
        disbursementDate = new GregorianCalendar(year, month, day);
    } else {/*w  w w.  j  a va 2 s.  c  om*/
        disbursementDate = new GregorianCalendar(year, month + 1, day);
    }
    UserContext userContext = TestUtils.makeUser();
    userContext.setLocaleId(null);
    List<FeeView> feeViewList = new ArrayList<FeeView>();
    FeeBO upfrontFee = TestObjectFactory.createOneTimeRateFee("Upfront Fee", FeeCategory.LOAN,
            Double.valueOf("20"), FeeFormula.AMOUNT, FeePayment.UPFRONT);
    feeViewList.add(new FeeView(userContext, upfrontFee));
    FeeBO disbursementFee = TestObjectFactory.createOneTimeRateFee("Disbursement Fee", FeeCategory.LOAN,
            Double.valueOf("30"), FeeFormula.AMOUNT_AND_INTEREST, FeePayment.TIME_OF_DISBURSEMENT);
    feeViewList.add(new FeeView(userContext, disbursementFee));
    FeeBO firstRepaymentFee = TestObjectFactory.createOneTimeRateFee("First Repayment Fee", FeeCategory.LOAN,
            Double.valueOf("40"), FeeFormula.INTEREST, FeePayment.TIME_OF_FIRSTLOANREPAYMENT);
    feeViewList.add(new FeeView(userContext, firstRepaymentFee));
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.LOAN, "100",
            RecurrenceType.MONTHLY, Short.valueOf("1"));
    feeViewList.add(new FeeView(userContext, periodicFee));
    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            disbursementDate.getTime(), false, 1.2, (short) 0, null, feeViewList, null, DOUBLE_ZERO,
            DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, false);
    new TestObjectPersistence().persist(accountBO);

    disbursementDate = new GregorianCalendar();
    year = disbursementDate.get(Calendar.YEAR);
    month = disbursementDate.get(Calendar.MONTH);
    day = 25;
    if (disbursementDate.get(Calendar.DAY_OF_MONTH) == dayOfMonth.intValue()) {
        disbursementDate = new GregorianCalendar(year, month + 1, day);
    } else {
        disbursementDate = new GregorianCalendar(year, month + 2, day);
    }
    ((LoanBO) accountBO).disburseLoan("1234", disbursementDate.getTime(), Short.valueOf("1"),
            accountBO.getPersonnel(), disbursementDate.getTime(), Short.valueOf("1"));
    Session session = StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    session.save(accountBO);
    StaticHibernateUtil.getTransaction().commit();
}

From source file:ca.oson.json.Oson.java

private <E> String short2Json(FieldData objectDTO) {
    if (objectDTO == null || objectDTO.json2Java) {
        return null;
    }//  ww  w  .java2 s .c om

    Object value = objectDTO.valueToProcess;
    Class<E> returnType = objectDTO.returnType;

    if (returnType != null && value != null && (returnType == short.class || returnType == Short.class)) {
        Short valueToProcess = null;
        String valueToReturn = null;

        if (returnType == short.class) {
            valueToProcess = Short.valueOf((short) value);
        } else {
            valueToProcess = (Short) value;
        }

        if (valueToProcess != null) {
            try {
                Function function = objectDTO.getSerializer();
                if (function != null) {
                    try {
                        if (function instanceof DataMapper2JsonFunction) {
                            DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper,
                                    objectDTO.level, getPrettyIndentation());
                            return ((DataMapper2JsonFunction) function).apply(classData);

                        } else if (function instanceof Short2JsonFunction) {
                            return ((Short2JsonFunction) function).apply(valueToProcess);

                        } else {

                            Object returnedValue = null;
                            if (function instanceof FieldData2JsonFunction) {
                                FieldData2JsonFunction f = (FieldData2JsonFunction) function;
                                FieldData fieldData = objectDTO.clone();
                                returnedValue = f.apply(fieldData);
                            } else {
                                returnedValue = function.apply(value);
                            }

                            if (returnedValue instanceof Optional) {
                                returnedValue = ObjectUtil.unwrap(returnedValue);
                            }

                            if (returnedValue == null) {
                                return null;

                            } else if (returnedValue instanceof Short) {
                                valueToProcess = (Short) returnedValue;

                            } else {
                                objectDTO.valueToProcess = returnedValue;
                                return object2String(objectDTO);
                            }

                        }

                    } catch (Exception e) {
                    }
                }

                if (valueToProcess != null) {
                    Long min = objectDTO.getMin();
                    Long max = objectDTO.getMax();

                    if (min != null && min.shortValue() > valueToProcess) {
                        valueToProcess = min.shortValue();
                    }

                    if (max != null && max.shortValue() < valueToProcess) {
                        valueToProcess = max.shortValue();
                    }

                    Integer precision = objectDTO.getPrecision();
                    if (precision != null) {
                        valueToProcess = (Short) NumberUtil.setPrecision(valueToProcess, precision,
                                getRoundingMode());
                    }

                    return NumberUtil.toPlainString(valueToProcess);
                }

            } catch (Exception ex) {
                //ex.printStackTrace();
            }
        }
    }

    return short2JsonDefault(objectDTO);
}

From source file:com.mimp.controllers.personal.java

@RequestMapping(value = "/PersonalInasistenciaReunion", method = RequestMethod.GET)
public ModelAndView PersonalInasistenciaReunion_GET(ModelMap map, HttpSession session) {
    Personal usuario = (Personal) session.getAttribute("usuario");
    if (usuario == null) {
        String mensaje = "La sesin ha finalizado. Favor identificarse nuevamente";
        map.addAttribute("mensaje", mensaje);
        return new ModelAndView("login", map);
    }/*from  ww w . j av  a2 s  .c o  m*/

    long idReunion = Long.parseLong(session.getAttribute("idReunion").toString());
    long idFamilia = Long.parseLong(session.getAttribute("idFamilia").toString());
    String justificado = (String) session.getAttribute("justificado");
    String nombre = (String) session.getAttribute("nombre");
    String grupo = (String) session.getAttribute("grupo");
    String turno = (String) session.getAttribute("turno");
    long idTaller = Long.parseLong(session.getAttribute("idTaller").toString());
    String historial = (String) session.getAttribute("historial");

    ArrayList<AsistenciaFR> allAsistencias = new ArrayList();
    Reunion tempReun = new Reunion();
    ArrayList<FormularioSesion> allFormularios = new ArrayList();

    tempReun = ServicioPersonal.getReunion(idReunion);

    allAsistencias = ServicioPersonal.getAsistFR(idFamilia, idReunion);
    for (AsistenciaFR asistFR : allAsistencias) {
        Short sh = Short.valueOf(justificado);
        asistFR.setInasJus(sh);
        ServicioPersonal.updateAsistenciaFR(asistFR);
    }

    String mensaje_log = "El usuario: " + usuario.getNombre() + " " + usuario.getApellidoP() + " con ID: "
            + usuario.getIdpersonal() + ". Tom asistencia a la familia con ID: " + idFamilia + ".";

    String Tipo_registro = "Familia";

    try {
        String Numero_registro = String.valueOf(usuario.getIdpersonal());

        ServicioPersonal.InsertLog(usuario, Tipo_registro, Numero_registro, mensaje_log);
    } catch (Exception ex) {
    }

    allFormularios = ServicioPersonal.formulariosReunion(idReunion);
    map.addAttribute("nombre", nombre);
    map.addAttribute("grupo", grupo);
    map.addAttribute("turno", turno);
    map.addAttribute("formato", format);
    map.addAttribute("idTaller", idTaller);
    map.addAttribute("historial", historial);
    map.addAttribute("idReunion", idReunion);
    map.put("listaFormularios", allFormularios);
    map.put("reunion", tempReun);
    return new ModelAndView("/Personal/Informativa/toma_asistencia_reunion", map);
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testLoanPerfHistoryForUndisbursedLoans() throws Exception {
    accountBO = getLoanAccount();/* w w  w  . j a  v  a2 s  . co  m*/
    LoanBO loan = (LoanBO) accountBO;
    Date disbursementDate = offSetCurrentDate(28);
    AccountActionDateEntity accountActionDate1 = loan.getAccountActionDate((short) 1);
    AccountActionDateEntity accountActionDate2 = loan.getAccountActionDate((short) 2);
    accountBO.setUserContext(TestObjectFactory.getContext());
    accountBO.changeStatus(AccountState.LOAN_APPROVED, null, "");
    ((LoanScheduleEntity) accountActionDate1).setActionDate(offSetCurrentDate(21));
    ((LoanScheduleEntity) accountActionDate2).setActionDate(offSetCurrentDate(14));
    loan.setDisbursementDate(disbursementDate);
    accountBO = saveAndFetch(loan);
    loan = (LoanBO) accountBO;
    Assert.assertEquals(Integer.valueOf("0"), loan.getPerformanceHistory().getTotalNoOfMissedPayments());
    Assert.assertEquals(Short.valueOf("0"), loan.getPerformanceHistory().getDaysInArrears());
    Assert.assertEquals(Integer.valueOf("0"), loan.getPerformanceHistory().getNoOfPayments());
}