List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.biomart.configurator.controller.MartController.java
public void updateDatasetFromSource(Dataset ds) throws SQLException, DataModelException { Mart mart = ds.getParentMart();/* w w w. j a v a 2s .c o m*/ List<SourceSchema> sss = mart.getIncludedSchemas(); // assuming that only one for now if (McUtils.isCollectionEmpty(sss)) return; SourceSchema ss = sss.get(0); final DatabaseMetaData dmd = ss.getConnection().getMetaData(); final String catalog = ss.getConnection().getCatalog(); // List of objects storing orphan key column and its table name List<ForeignKey> orphanFKList = new ArrayList<ForeignKey>(); StringBuffer orphanSearch = new StringBuffer(); boolean orphanBool = false; /* * try { orphanBool = findOrphanFKFromDB(orphanFKList, orphanSearch, mart); if (orphanBool) { Frame frame = new * Frame(); Object[] options = { "Proceed", "Abort Synchronization" }; int n = JOptionPane .showOptionDialog( * frame, * "Some columns in relations no longer exist in source DB. This may be caused by renaming/dropping tables/columns in source DB.\n" * + * "When choose 'Proceed', you will be prompted to save this information for later use. Do you want to proceed?" * +"\n", "Schema Update Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, // do // not // * use a // custom // Icon options, // the titles of buttons options[1]); // default button title if (n == * JOptionPane.NO_OPTION) { return; } else{ new SaveOrphanKeyDialog("Orphan Relation", orphanSearch.toString()); * } } } catch (Exception e) { e.printStackTrace(); } // Now that user decides to sync GUI model to DB schema, * remove orphan foreign key clearOrphanForeignKey(orphanFKList); */ // Create a list of existing tables. During this method, we remove // from this list all tables that still exist in the database. At // the end of the method, the list contains only those tables // which no longer exist, so they will be dropped. final Collection<Table> tablesToBeDropped = new HashSet<Table>(ss.getTables()); // Load tables and views from database, then loop over them. ResultSet dbTables; String sName = ss.getJdbcLinkObject().getJdbcType().useSchema() ? ss.getJdbcLinkObject().getSchemaName() : catalog; dbTables = dmd.getTables(catalog, sName, "%", new String[] { "TABLE", "VIEW", "ALIAS", "SYNONYM" }); // Do the loop. final Collection<Table> tablesToBeKept = new HashSet<Table>(); while (dbTables.next()) { // Check schema and catalog. final String catalogName = dbTables.getString("TABLE_CAT"); final String schemaName = dbTables.getString("TABLE_SCHEM"); String schemaPrefix = schemaName; // What is the table called? final String dbTableName = dbTables.getString("TABLE_NAME"); Log.debug("Processing table " + catalogName + "." + dbTableName); // Look to see if we already have a table by this name defined. // If we do, reuse it. If not, create a new table. Table dbTable = ss.getTableByName(dbTableName); if (dbTable == null) try { dbTable = new SourceTable(ss, dbTableName); dbTable.setVisibleModified(true); ss.addTable(dbTable); } catch (final Throwable t) { throw new BioMartError(t); } // Add schema prefix to list. if (schemaPrefix != null) dbTable.addInPartitions(schemaPrefix); // Table exists, so remove it from our list of tables to be // dropped at the end of the method. tablesToBeDropped.remove(dbTable); tablesToBeKept.add(dbTable); } dbTables.close(); // Loop over all columns. for (final Iterator<Table> i = tablesToBeKept.iterator(); i.hasNext();) { final Table dbTable = (Table) i.next(); final String dbTableName = dbTable.getName(); // Make a list of all the columns in the table. Any columns // remaining in this list by the end of the loop will be // dropped. final Collection<Column> colsToBeDropped = new HashSet<Column>(dbTable.getColumnList()); // Clear out the existing schema partition info on all cols. for (final Iterator<Column> j = dbTable.getColumnList().iterator(); j.hasNext();) ((Column) j.next()).cleanInPartitions(); // Load the table columns from the database, then loop over // them. Log.debug("Loading table column list for " + dbTableName); ResultSet dbTblCols; dbTblCols = dmd.getColumns(catalog, sName, dbTableName, "%"); // FIXME: When using Oracle, if the table is a synonym then the // above call returns no results. while (dbTblCols.next()) { // Check schema and catalog. final String catalogName = dbTblCols.getString("TABLE_CAT"); final String schemaName = dbTblCols.getString("TABLE_SCHEM"); String schemaPrefix = null; // No prefix if partitions are empty; /* * if (!this.getPartitions().isEmpty()) { if ("".equals(dmd.getSchemaTerm())) // Use catalog name to get * prefix. schemaPrefix = (String) this.getPartitions().get( catalogName); else // Use schema name to * get prefix. schemaPrefix = (String) this.getPartitions().get( schemaName); // Don't want to include * if prefix is still null. if (schemaPrefix == null) continue; } */ // What is the column called, and is it nullable? final String dbTblColName = dbTblCols.getString("COLUMN_NAME"); Log.debug("Processing column " + dbTblColName); // Look to see if the column already exists on this table. // If it does, reuse it. Else, create it. Column dbTblCol = (Column) dbTable.getColumnByName(dbTblColName); if (dbTblCol == null) try { dbTblCol = new SourceColumn((SourceTable) dbTable, dbTblColName); dbTblCol.setVisibleModified(true); dbTable.addColumn(dbTblCol); } catch (final Throwable t) { throw new BioMartError(t); } // Column exists, so remove it from our list of columns to // be dropped at the end of the loop. colsToBeDropped.remove(dbTblCol); if (schemaPrefix != null) dbTblCol.addInPartitions(schemaPrefix); } dbTblCols.close(); // Drop all columns that are left in the list, as they no longer // exist in the database. for (final Iterator<Column> j = colsToBeDropped.iterator(); j.hasNext();) { final Column column = (Column) j.next(); Log.debug("Dropping redundant column " + column.getName()); dbTable.getColumnList().remove(column); } } // Remove from schema all tables not found in the database, using // the list we constructed above. for (final Iterator<Table> i = tablesToBeDropped.iterator(); i.hasNext();) { final Table existingTable = (Table) i.next(); Log.debug("Dropping redundant table " + existingTable); final String tableName = existingTable.getName(); // By clearing its keys we will also clear its relations. for (final Iterator<Key> j = existingTable.getKeys().iterator(); j.hasNext();) { j.next().removeAllRelations(); } existingTable.setPrimaryKey(null); existingTable.getForeignKeys().clear(); ss.removeTableByName(tableName); } // Get and create primary keys. // Work out a list of all foreign keys currently existing. // Any remaining in this list later will be dropped. final Collection<ForeignKey> fksToBeDropped = new HashSet<ForeignKey>(); for (final Iterator<Table> i = ss.getTables().iterator(); i.hasNext();) { final Table t = (Table) i.next(); fksToBeDropped.addAll(t.getForeignKeys()); // Obtain the primary key from the database. Even in databases // without referential integrity, the primary key is still // defined and can be obtained from the metadata. Log.debug("Loading table primary keys"); String searchCatalog = catalog; String searchSchema = sName; /* * if (!t.getSchemaPartitions().isEmpty()) { // Locate partition with first prefix. final String prefix = * (String) t.getSchemaPartitions() .iterator().next(); String schemaName = (String) new InverseMap(this * .getPartitions()).get(prefix); if (schemaName == null) // Should never happen. throw new BioMartError(); * if ("".equals(dmd.getSchemaTerm())) searchCatalog = schemaName; searchSchema = schemaName; } */ final ResultSet dbTblPKCols = dmd.getPrimaryKeys(searchCatalog, searchSchema, t.getName()); // Load the primary key columns into a map keyed by column // position. // In other words, the first column in the key has a map key of // 1, and so on. We do this because we can't guarantee we'll // read the key columns from the database in the correct order. // We keep the map sorted, so that when we iterate over it later // we get back the columns in the correct order. final Map<Short, Column> pkCols = new TreeMap<Short, Column>(); while (dbTblPKCols.next()) { final String pkColName = dbTblPKCols.getString("COLUMN_NAME"); final Short pkColPosition = new Short(dbTblPKCols.getShort("KEY_SEQ")); pkCols.put(pkColPosition, t.getColumnByName(pkColName)); } dbTblPKCols.close(); // Did DMD find a PK? If not, which is really unusual but // potentially may happen, attempt to find one by looking for a // single column with the same name as the table or with '_id' // appended. // Only do this if we are using key-guessing. if (pkCols.isEmpty() && ss.getJdbcLinkObject().isKeyGuessing()) { Log.debug("Found no primary key, so attempting to guess one"); // Plain version first. Column candidateCol = (Column) t.getColumnByName(t.getName()); // Try with '_id' appended if plain version turned up // nothing. if (candidateCol == null) candidateCol = (Column) t.getColumnByName(t.getName() + Resources.get("primaryKeySuffix")); // Found something? Add it to the primary key columns map, // with a dummy key of 1. (Use Short for the key because // that // is what DMD would have used had it found anything // itself). if (candidateCol != null) pkCols.put(Short.valueOf("1"), candidateCol); } // Obtain the existing primary key on the table, if the table // previously existed and even had one in the first place. final PrimaryKey existingPK = t.getPrimaryKey(); // Did we find a PK on the database copy of the table? if (!pkCols.isEmpty()) { // Yes, we found a PK on the database copy of the table. So, // create a new key based around the columns we identified. PrimaryKey candidatePK; try { candidatePK = new PrimaryKey(new ArrayList<Column>(pkCols.values())); } catch (final Throwable th) { throw new BioMartError(th); } // If the existing table has no PK, or has a PK which // matches and is not incorrect, or has a PK which does not // match // and is not handmade, replace that PK with the one we // found. // This way we preserve any existing handmade PKs, and don't // override any marked as incorrect. try { if (existingPK == null) t.setPrimaryKey(candidatePK); else if (existingPK.equals(candidatePK) && existingPK.getStatus().equals(ComponentStatus.HANDMADE)) existingPK.setStatus(ComponentStatus.INFERRED); else if (!existingPK.equals(candidatePK) && !existingPK.getStatus().equals(ComponentStatus.HANDMADE)) t.setPrimaryKey(candidatePK); } catch (final Throwable th) { throw new BioMartError(th); } } else // No, we did not find a PK on the database copy of the // table, so that table should not have a PK at all. So if the // existing table has a PK which is not handmade, remove it. if (existingPK != null && !existingPK.getStatus().equals(ComponentStatus.HANDMADE)) try { t.setPrimaryKey(null); } catch (final Throwable th) { throw new BioMartError(th); } } // Are we key-guessing? Key guess the foreign keys, passing in a // reference to the list of existing foreign keys. After this call // has completed, the list will contain all those foreign keys which // no longer exist, and can safely be dropped. if (ss.getJdbcLinkObject().isKeyGuessing()) this.synchroniseKeysUsingKeyGuessing(ss, fksToBeDropped); // Otherwise, use DMD to do the same, also passing in the list of // existing foreign keys to be updated as the call progresses. Also // pass in the DMD details so it doesn't have to work them out for // itself. else this.synchroniseKeysUsingDMD(ss, fksToBeDropped, dmd, sName, catalog); // Drop any foreign keys that are left over (but not handmade ones). for (final Iterator<ForeignKey> i = fksToBeDropped.iterator(); i.hasNext();) { final Key k = (Key) i.next(); if (k.getStatus().equals(ComponentStatus.HANDMADE)) continue; Log.debug("Dropping redundant foreign key " + k); for (final Iterator<Relation> r = k.getRelations().iterator(); r.hasNext();) { final Relation rel = (Relation) r.next(); rel.getFirstKey().getRelations().remove(rel); rel.getSecondKey().getRelations().remove(rel); } k.getTable().getForeignKeys().remove(k); } // rebuild mart this.rebuildMartFromSource(mart); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testGetNextMeetingDateAsFutureDate() throws Exception { Date startDate = new Date(System.currentTimeMillis()); MeetingBO meeting = TestObjectFactory .createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_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(startDate, meeting); accountBO = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Date(System.currentTimeMillis()), loanOffering); AccountActionDateEntity accountActionDateEntity = accountBO.getAccountActionDate(Short.valueOf("1")); Calendar currentDateCalendar = new GregorianCalendar(); int year = currentDateCalendar.get(Calendar.YEAR); int month = currentDateCalendar.get(Calendar.MONTH); int day = currentDateCalendar.get(Calendar.DAY_OF_MONTH); currentDateCalendar = new GregorianCalendar(year, month, day - 1); ((LoanScheduleEntity) accountActionDateEntity) .setActionDate(new java.sql.Date(currentDateCalendar.getTimeInMillis())); TestObjectFactory.updateObject(accountBO); accountBO = accountPersistence.getAccount(accountBO.getAccountId()); Assert.assertEquals(((LoanBO) accountBO).getNextMeetingDate().toString(), accountBO.getAccountActionDate(Short.valueOf("2")).getActionDate().toString()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testGetTotalAmountInArrearsWithPaymentDone() throws Exception { accountBO = getLoanAccount();//w ww . j a v a2 s .c o m AccountActionDateEntity accountActionDateEntity = accountBO.getAccountActionDate(Short.valueOf("1")); ((LoanScheduleEntity) accountActionDateEntity).setActionDate(offSetCurrentDate(1)); ((LoanScheduleEntity) accountActionDateEntity).setPaymentStatus(PaymentStatus.PAID); accountBO = saveAndFetch(accountBO); Assert.assertEquals(((LoanBO) accountBO).getTotalAmountInArrears(), TestUtils.createMoney()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testChangedStatusForLastInstallmentPaid() throws Exception { accountBO = getLoanAccount();//from w ww . j a va 2 s . co m Date startDate = new Date(System.currentTimeMillis()); java.sql.Date offSetDate = offSetCurrentDate(1); for (AccountActionDateEntity accountAction : accountBO.getAccountActionDates()) { ((LoanScheduleEntity) accountAction).setActionDate(offSetDate); } accountBO = saveAndFetch(accountBO); List<AccountActionDateEntity> accountActions = new ArrayList<AccountActionDateEntity>(); accountActions.addAll(accountBO.getAccountActionDates()); PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accountActions, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "1272.0"), null, accountBO.getPersonnel(), "5435345", Short.valueOf("1"), startDate, startDate); accountBO.applyPaymentWithPersist(paymentData); Assert.assertEquals("When Last installment is paid the status has been changed to closed", ((LoanBO) accountBO).getAccountState().getId().toString(), String.valueOf(AccountStates.LOANACC_OBLIGATIONSMET)); accountBO.getAccountPayments().clear(); }
From source file:com.funambol.foundation.items.dao.PIMContactDAO.java
/** * Creates a ContactWrapper object from a ResultSet. Only the basic data are * set.//from ww w. j av a 2 s . c om * * @param wrapperId the UID of the wrapper object to be returned * @param rs the result of the execution of a proper SQL SELECT statement on * the fnbl_pim_contact table, with the cursor before its first row * @return a newly created ContactWrapper initialized with the fields in the * result set * @throws java.sql.SQLException * @throws NotFoundException */ private static ContactWrapper createContact(String wrapperId, ResultSet rs) throws SQLException, NotFoundException { if (!rs.next()) { throw new NotFoundException("No contact found."); } ResultSetMetaData rsmd = rs.getMetaData(); ContactWrapper cw = null; Note note = null; Title title = null; String column = null; String userId = rs.getString(SQL_FIELD_USERID); Contact c = new Contact(); cw = new ContactWrapper(wrapperId, userId, c); int columnCount = rsmd.getColumnCount(); for (int i = 1; i <= columnCount; ++i) { column = rsmd.getColumnName(i); // // General // if (SQL_FIELD_ID.equalsIgnoreCase(column)) { // Does nothing: field already set at construction time } else if (SQL_FIELD_LAST_UPDATE.equalsIgnoreCase(column)) { cw.setLastUpdate(new Timestamp(rs.getLong(i))); } else if (SQL_FIELD_USERID.equalsIgnoreCase(column)) { // Does nothing: field already set at construction time } else if (SQL_FIELD_STATUS.equalsIgnoreCase(column)) { cw.setStatus(rs.getString(i).charAt(0)); } else if (SQL_FIELD_PHOTO_TYPE.equalsIgnoreCase(column)) { short phType = rs.getShort(i); if (!rs.wasNull()) { cw.setPhotoType(Short.valueOf(phType)); } // // contact details // } else if (SQL_FIELD_IMPORTANCE.equalsIgnoreCase(column)) { short importance = rs.getShort(i); if (!rs.wasNull()) { c.setImportance(Short.valueOf(importance)); } } else if (SQL_FIELD_SENSITIVITY.equalsIgnoreCase(column)) { short sensitivity = rs.getShort(i); if (!rs.wasNull()) { c.setSensitivity(Short.valueOf(sensitivity)); } } else if (SQL_FIELD_SUBJECT.equalsIgnoreCase(column)) { c.setSubject(rs.getString(i)); } else if (SQL_FIELD_FOLDER.equalsIgnoreCase(column)) { c.setFolder(rs.getString(i)); // // Personal details // } else if (SQL_FIELD_ANNIVERSARY.equalsIgnoreCase(column)) { c.getPersonalDetail().setAnniversary(rs.getString(i)); } else if (SQL_FIELD_FIRST_NAME.equalsIgnoreCase(column)) { c.getName().getFirstName().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_MIDDLE_NAME.equalsIgnoreCase(column)) { c.getName().getMiddleName().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_LAST_NAME.equalsIgnoreCase(column)) { c.getName().getLastName().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_DISPLAY_NAME.equalsIgnoreCase(column)) { c.getName().getDisplayName().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_BIRTHDAY.equalsIgnoreCase(column)) { c.getPersonalDetail().setBirthday(rs.getString(i)); } else if (SQL_FIELD_BODY.equalsIgnoreCase(column)) { String noteStr = rs.getString(i); if (noteStr != null) { note = new Note(); note.setNoteType(FIELD_NOTE); note.setPropertyValue(noteStr); c.addNote(note); } } else if (SQL_FIELD_CATEGORIES.equalsIgnoreCase(column)) { c.getCategories().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_CHILDREN.equalsIgnoreCase(column)) { c.getPersonalDetail().setChildren(rs.getString(i)); } else if (SQL_FIELD_HOBBIES.equalsIgnoreCase(column)) { c.getPersonalDetail().setHobbies(rs.getString(i)); } else if (SQL_FIELD_GENDER.equalsIgnoreCase(column)) { c.getPersonalDetail().setGender(rs.getString(i)); } else if (SQL_FIELD_INITIALS.equalsIgnoreCase(column)) { c.getName().getInitials().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_LANGUAGES.equalsIgnoreCase(column)) { c.setLanguages(rs.getString(i)); } else if (SQL_FIELD_NICKNAME.equalsIgnoreCase(column)) { c.getName().getNickname().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_SPOUSE.equalsIgnoreCase(column)) { c.getPersonalDetail().setSpouse(rs.getString(i)); } else if (SQL_FIELD_SUFFIX.equalsIgnoreCase(column)) { c.getName().getSuffix().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_TITLE.equalsIgnoreCase(column)) { c.getName().getSalutation().setPropertyValue(rs.getString(i)); // // Business details // } else if (SQL_FIELD_ASSISTANT.equalsIgnoreCase(column)) { c.getBusinessDetail().setAssistant(rs.getString(i)); } else if (SQL_FIELD_COMPANY.equalsIgnoreCase(column)) { c.getBusinessDetail().getCompany().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_COMPANIES.equalsIgnoreCase(column)) { c.getBusinessDetail().setCompanies(rs.getString(i)); } else if (SQL_FIELD_DEPARTMENT.equalsIgnoreCase(column)) { c.getBusinessDetail().getDepartment().setPropertyValue(rs.getString(i)); } else if (SQL_FIELD_JOB_TITLE.equalsIgnoreCase(column)) { String titleStr = null; titleStr = rs.getString(i); if (titleStr != null) { title = new Title(); title.setTitleType(FIELD_JOB_TITLE); title.setPropertyValue(titleStr); c.getBusinessDetail().addTitle(title); } } else if (SQL_FIELD_MANAGER.equalsIgnoreCase(column)) { c.getBusinessDetail().setManager(rs.getString(i)); } else if (SQL_FIELD_MILEAGE.equalsIgnoreCase(column)) { c.setMileage(rs.getString(i)); } else if (SQL_FIELD_OFFICE_LOCATION.equalsIgnoreCase(column)) { c.getBusinessDetail().setOfficeLocation(rs.getString(i)); } else if (SQL_FIELD_PROFESSION.equalsIgnoreCase(column)) { c.getBusinessDetail().getRole().setPropertyValue(rs.getString(i)); } else { throw new SQLException("Unhandled column: " + column); } } return cw; }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testHandleArrears() throws AccountException { accountBO = getLoanAccount();/* w w w .j a v a 2s. c o m*/ StaticHibernateUtil.commitTransaction(); StaticHibernateUtil.closeSession(); accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId()); int statusChangeHistorySize = accountBO.getAccountStatusChangeHistory().size(); ((LoanBO) accountBO).handleArrears(); Assert.assertEquals(Short.valueOf(AccountStates.LOANACC_BADSTANDING), accountBO.getAccountState().getId()); Assert.assertEquals(statusChangeHistorySize + 1, accountBO.getAccountStatusChangeHistory().size()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testChangedStatusOnPayment() throws Exception { accountBO = getLoanAccount();/*from ww w . j a v a 2 s .c om*/ StaticHibernateUtil.commitTransaction(); StaticHibernateUtil.closeSession(); accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId()); ((LoanBO) accountBO).handleArrears(); Assert.assertEquals("The status of account before payment should be active in bad standing", Short.valueOf(AccountStates.LOANACC_BADSTANDING), accountBO.getAccountState().getId()); accountBO = applyPaymentandRetrieveAccount(); Assert.assertEquals("The status of account after payment should be active in good standing", Short.valueOf(AccountStates.LOANACC_ACTIVEINGOODSTANDING), accountBO.getAccountState().getId()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testWaivePenaltyChargeDue() throws Exception { accountBO = getLoanAccount();/*from w ww . j av a 2 s .c o m*/ for (AccountActionDateEntity accountAction : ((LoanBO) accountBO).getAccountActionDates()) { LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction; if (accountActionDateEntity.getInstallmentId().equals(Short.valueOf("1"))) { accountActionDateEntity.setMiscPenalty(new Money(getCurrency(), "100")); } } ((LoanBO) accountBO).getLoanSummary().setOriginalPenalty(new Money(getCurrency(), "100")); TestObjectFactory.updateObject(accountBO); StaticHibernateUtil.closeSession(); LoanBO loanBO = TestObjectFactory.getObject(LoanBO.class, accountBO.getAccountId()); UserContext userContext = TestUtils.makeUser(); loanBO.setUserContext(userContext); loanBO.waiveAmountDue(WaiveEnum.PENALTY); StaticHibernateUtil.commitTransaction(); StaticHibernateUtil.closeSession(); loanBO = TestObjectFactory.getObject(LoanBO.class, loanBO.getAccountId()); for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) { LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction; if (accountActionDateEntity.getInstallmentId().equals(Short.valueOf("1"))) { Assert.assertEquals(new Money(getCurrency()), accountActionDateEntity.getMiscPenalty()); } } List<LoanActivityEntity> loanActivityDetailsSet = loanBO.getLoanActivityDetails(); LoanActivityEntity loanActivityEntity = loanActivityDetailsSet.get(0); Assert.assertEquals(LoanConstants.PENALTY_WAIVED, loanActivityEntity.getComments()); Assert.assertEquals(new Money(getCurrency(), "100"), loanActivityEntity.getPenalty()); Assert.assertEquals(new Timestamp(DateUtils.getCurrentDateWithoutTimeStamp().getTime()), loanActivityEntity.getTrxnCreatedDate()); Assert.assertEquals( loanBO.getLoanSummary().getOriginalPenalty().subtract(loanBO.getLoanSummary().getPenaltyPaid()), loanActivityEntity.getPenaltyOutstanding()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testWaiveFeeChargeDue() throws Exception { accountBO = getLoanAccount();/* www.j a v a 2s . c o m*/ StaticHibernateUtil.closeSession(); LoanBO loanBO = TestObjectFactory.getObject(LoanBO.class, accountBO.getAccountId()); UserContext userContext = TestUtils.makeUser(); loanBO.setUserContext(userContext); loanBO.waiveAmountDue(WaiveEnum.FEES); StaticHibernateUtil.commitTransaction(); StaticHibernateUtil.closeSession(); loanBO = TestObjectFactory.getObject(LoanBO.class, loanBO.getAccountId()); // Change this to more clearly separate what we are testing for from the // machinery needed to get that data? for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) { LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction; for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountActionDateEntity .getAccountFeesActionDetails()) { if (accountActionDateEntity.getInstallmentId().equals(Short.valueOf("1"))) { Assert.assertEquals(new Money(getCurrency()), accountFeesActionDetailEntity.getFeeAmount()); } else { Assert.assertEquals(new Money(getCurrency(), "100"), accountFeesActionDetailEntity.getFeeAmount()); } } } List<LoanActivityEntity> loanActivityDetailsSet = loanBO.getLoanActivityDetails(); LoanActivityEntity loanActivityEntity = loanActivityDetailsSet.get(0); Assert.assertEquals(LoanConstants.FEE_WAIVED, loanActivityEntity.getComments()); Assert.assertEquals(new Money(getCurrency(), "100"), loanActivityEntity.getFee()); Assert.assertEquals(new Timestamp(DateUtils.getCurrentDateWithoutTimeStamp().getTime()), loanActivityEntity.getTrxnCreatedDate()); Assert.assertEquals( loanBO.getLoanSummary().getOriginalFees().subtract(loanBO.getLoanSummary().getFeesPaid()), loanActivityEntity.getFeeOutstanding()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testWaiveFeeChargeOverDue() throws Exception { accountBO = getLoanAccount();/* ww w . j av a 2 s . c o m*/ StaticHibernateUtil.closeSession(); LoanBO loanBO = TestObjectFactory.getObject(LoanBO.class, accountBO.getAccountId()); Calendar calendar = new GregorianCalendar(); calendar.setTime(DateUtils.getCurrentDateWithoutTimeStamp()); calendar.add(calendar.WEEK_OF_MONTH, -1); java.sql.Date lastWeekDate = new java.sql.Date(calendar.getTimeInMillis()); Calendar date = new GregorianCalendar(); date.setTime(DateUtils.getCurrentDateWithoutTimeStamp()); date.add(date.WEEK_OF_MONTH, -2); java.sql.Date twoWeeksBeforeDate = new java.sql.Date(date.getTimeInMillis()); for (AccountActionDateEntity installment : loanBO.getAccountActionDates()) { if (installment.getInstallmentId().intValue() == 1) { ((LoanScheduleEntity) installment).setActionDate(lastWeekDate); } else if (installment.getInstallmentId().intValue() == 2) { ((LoanScheduleEntity) installment).setActionDate(twoWeeksBeforeDate); } } TestObjectFactory.updateObject(loanBO); StaticHibernateUtil.closeSession(); loanBO = TestObjectFactory.getObject(LoanBO.class, loanBO.getAccountId()); UserContext userContext = TestUtils.makeUser(); loanBO.setUserContext(userContext); loanBO.waiveAmountOverDue(WaiveEnum.FEES); TestObjectFactory.flushandCloseSession(); loanBO = TestObjectFactory.getObject(LoanBO.class, loanBO.getAccountId()); // Change this to more clearly separate what we are testing for from the // machinery needed to get that data? for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) { LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction; for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountActionDateEntity .getAccountFeesActionDetails()) { if (accountActionDateEntity.getInstallmentId().equals(Short.valueOf("1")) || accountActionDateEntity.getInstallmentId().equals(Short.valueOf("2"))) { Assert.assertEquals(new Money(getCurrency()), accountFeesActionDetailEntity.getFeeAmount()); } else { Assert.assertEquals(new Money(getCurrency(), "100"), accountFeesActionDetailEntity.getFeeAmount()); } } } List<LoanActivityEntity> loanActivityDetailsSet = loanBO.getLoanActivityDetails(); LoanActivityEntity loanActivityEntity = loanActivityDetailsSet.get(0); Assert.assertEquals(new Money(getCurrency(), "200"), loanActivityEntity.getFee()); Assert.assertEquals(new Timestamp(DateUtils.getCurrentDateWithoutTimeStamp().getTime()), loanActivityEntity.getTrxnCreatedDate()); Assert.assertEquals( loanBO.getLoanSummary().getOriginalFees().subtract(loanBO.getLoanSummary().getFeesPaid()), loanActivityEntity.getFeeOutstanding()); }