List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testBuildLoanWithFee() throws Exception { createInitialCustomers();//from w w w. j av a 2 s . com LoanOfferingBO loanOffering = createLoanOffering(false); List<FeeView> feeViews = getFeeViews(); LoanOfferingInstallmentRange eligibleInstallmentRange = loanOffering.getEligibleInstallmentSameForAllLoan(); LoanBO loan = LoanBO.createLoan(TestUtils.makeUser(), loanOffering, group, AccountState.LOAN_APPROVED, new Money(getCurrency(), "300.0"), Short.valueOf("6"), new Date(System.currentTimeMillis()), false, 10.0, (short) 0, null, feeViews, null, DEFAULT_LOAN_AMOUNT, DEFAULT_LOAN_AMOUNT, eligibleInstallmentRange.getMaxNoOfInstall(), eligibleInstallmentRange.getMinNoOfInstall(), false, null); Assert.assertEquals(2, loan.getAccountFees().size()); for (AccountFeesEntity accountFees : loan.getAccountFees()) { if (accountFees.getFees().getFeeName().equals("One Time Amount Fee")) { Assert.assertEquals(new Double("120.0"), accountFees.getFeeAmount()); } else { Assert.assertEquals(new Double("10.0"), accountFees.getFeeAmount()); } } Map<String, String> fees1 = new HashMap<String, String>(); fees1.put("Periodic Fee", "10.0"); fees1.put("One Time Amount Fee", "120.0"); Map<String, String> fees2 = new HashMap<String, String>(); fees2.put("Periodic Fee", "10.0"); Set<AccountActionDateEntity> actionDateEntities = loan.getAccountActionDates(); Assert.assertEquals(6, actionDateEntities.size()); LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities); /* * TODO: fix this check checkFees(fees1, "130.0", paymentsArray[0]); */ checkFees(fees2, "10.0", paymentsArray[1]); checkFees(fees2, "10.0", paymentsArray[2]); checkFees(fees2, "10.0", paymentsArray[3]); checkFees(fees2, "10.0", paymentsArray[4]); checkFees(fees2, "10.0", paymentsArray[5]); deleteFee(feeViews); TestObjectFactory.removeObject(loanOffering); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testBuildLoan() throws Exception { createInitialCustomers();/* ww w . java2 s . c om*/ LoanOfferingBO loanOffering = createLoanOffering(false); List<FeeView> feeViews = getFeeViews(); LoanOfferingInstallmentRange eligibleInstallmentRange = loanOffering.getEligibleInstallmentSameForAllLoan(); LoanBO loan = LoanBO.createLoan(TestUtils.makeUser(), loanOffering, group, AccountState.LOAN_APPROVED, new Money(getCurrency(), "300.0"), Short.valueOf("6"), new Date(System.currentTimeMillis()), false, 10.0, (short) 0, null, feeViews, null, DEFAULT_LOAN_AMOUNT, DEFAULT_LOAN_AMOUNT, eligibleInstallmentRange.getMaxNoOfInstall(), eligibleInstallmentRange.getMinNoOfInstall(), false, null); Assert.assertNotNull(loan.getLoanSummary()); Assert.assertNotNull(loan.getPerformanceHistory()); Assert.assertEquals(new Money(getCurrency(), "300.0"), loan.getLoanSummary().getOriginalPrincipal()); Assert.assertEquals(new Money(getCurrency(), "300.0"), loan.getLoanAmount()); Assert.assertEquals(new Money(getCurrency(), "300.0"), loan.getLoanBalance()); Assert.assertEquals(Short.valueOf("6"), loan.getNoOfInstallments()); Assert.assertEquals(6, loan.getAccountActionDates().size()); Assert.assertEquals(loan.getNoOfInstallments().intValue(), loan.getAccountActionDates().size()); deleteFee(feeViews); TestObjectFactory.removeObject(loanOffering); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testCreateLoan() throws Exception { createInitialCustomers();//from ww w .j av a2 s .c o m LoanOfferingBO loanOffering = createLoanOffering(false); List<FeeView> feeViews = getFeeViews(); boolean isInterestDedAtDisb = false; Short noOfinstallments = (short) 6; LoanBO loan = createAndRetrieveLoanAccount(loanOffering, isInterestDedAtDisb, feeViews, noOfinstallments); Assert.assertEquals(2, loan.getAccountFees().size()); for (AccountFeesEntity accountFees : loan.getAccountFees()) { if (accountFees.getFees().getFeeName().equals("One Time Amount Fee")) { Assert.assertEquals(new Double("120.0"), accountFees.getFeeAmount()); } else { Assert.assertEquals(new Double("10.0"), accountFees.getFeeAmount()); } } Set<AccountActionDateEntity> actionDateEntities = loan.getAccountActionDates(); LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities); checkPrincipalAndInterest("50.4", "0.6", paymentsArray[0]); checkPrincipalAndInterest("50.4", "0.6", paymentsArray[1]); checkPrincipalAndInterest("50.4", "0.6", paymentsArray[2]); checkPrincipalAndInterest("50.4", "0.6", paymentsArray[3]); checkPrincipalAndInterest("50.4", "0.6", paymentsArray[4]); checkPrincipalAndInterest("48.0", "1.0", paymentsArray[5]); Assert.assertNotNull(loan.getLoanSummary()); Assert.assertNotNull(loan.getPerformanceHistory()); Assert.assertEquals(new Money(getCurrency(), "300.0"), loan.getLoanSummary().getOriginalPrincipal()); Assert.assertEquals(new Money(getCurrency(), "300.0"), loan.getLoanAmount()); Assert.assertEquals(new Money(getCurrency(), "300.0"), loan.getLoanBalance()); Assert.assertEquals(Short.valueOf("6"), loan.getNoOfInstallments()); Assert.assertEquals(6, loan.getAccountActionDates().size()); }
From source file:org.apache.ambari.server.controller.AmbariManagementControllerTest.java
@SuppressWarnings("serial") @Test/* ww w. j a v a 2s .c o m*/ public void testCreateActionsFailures() throws Exception { setupClusterWithHosts("c1", "HDP-2.0.7", new ArrayList<String>() { { add("h1"); } }, "centos5"); Cluster cluster = clusters.getCluster("c1"); cluster.setDesiredStackVersion(new StackId("HDP-2.0.7")); cluster.setCurrentStackVersion(new StackId("HDP-2.0.7")); ConfigFactory cf = injector.getInstance(ConfigFactory.class); Config config1 = cf.createNew(cluster, "global", new HashMap<String, String>() { { put("key1", "value1"); } }, new HashMap<String, Map<String, String>>()); config1.setTag("version1"); Config config2 = cf.createNew(cluster, "core-site", new HashMap<String, String>() { { put("key1", "value1"); } }, new HashMap<String, Map<String, String>>()); config2.setTag("version1"); config1.persist(); config2.persist(); cluster.addConfig(config1); cluster.addConfig(config2); cluster.addDesiredConfig("_test", Collections.singleton(config1)); cluster.addDesiredConfig("_test", Collections.singleton(config2)); Service hdfs = cluster.addService("HDFS"); hdfs.persist(); Service hive = cluster.addService("HIVE"); hive.persist(); hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist(); hdfs.addServiceComponent(Role.NAMENODE.name()).persist(); hdfs.addServiceComponent(Role.DATANODE.name()).persist(); hive.addServiceComponent(Role.HIVE_SERVER.name()).persist(); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost("h1").persist(); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost("h1").persist(); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost("h1").persist(); Map<String, String> params = new HashMap<String, String>() { { put("test", "test"); } }; RequestResourceFilter resourceFilter = new RequestResourceFilter("HDFS", null, null); ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", "NON_EXISTENT_CHECK", params, false); actionRequest.getResourceFilters().add(resourceFilter); Map<String, String> requestProperties = new HashMap<String, String>(); requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test"); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Unsupported action"); //actionRequest = new ExecuteActionRequest("c1", "NON_EXISTENT_SERVICE_CHECK", "HDFS", params); //expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Unsupported action"); actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION_DATANODE", params, false); actionRequest.getResourceFilters().add(resourceFilter); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Unsupported action DECOMMISSION_DATANODE for Service: HDFS and Component: null"); //actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION", "HDFS", params); //expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Unsupported action DECOMMISSION for Service: HDFS and Component: null"); resourceFilter = new RequestResourceFilter("HDFS", "HDFS_CLIENT", null); List<RequestResourceFilter> resourceFilters = new ArrayList<RequestResourceFilter>(); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION", null, resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Unsupported action DECOMMISSION for Service: HDFS and Component: HDFS_CLIENT"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HDFS", null, null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", null, "DECOMMISSION_DATANODE", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action DECOMMISSION_DATANODE does not exist"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("YARN", "RESOURCEMANAGER", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION", null, resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Service not found, clusterName=c1, serviceName=YARN"); Map<String, String> params2 = new HashMap<String, String>() { { put("included_hosts", "h1,h2"); put("excluded_hosts", "h1,h3"); } }; resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION", null, resourceFilters, null, params2, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Same host cannot be specified for inclusion as well as exclusion. Hosts: [h1]"); params2 = new HashMap<String, String>() { { put("included_hosts", " h1,h2"); put("excluded_hosts", "h4, h3"); put("slave_type", "HDFS_CLIENT"); } }; resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION", null, resourceFilters, null, params2, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Component HDFS_CLIENT is not supported for decommissioning."); List<String> hosts = new ArrayList<String>(); hosts.add("h6"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", hosts); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION", null, resourceFilters, null, params2, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Decommission command cannot be issued with target host(s) specified."); hdfs.getServiceComponent(Role.DATANODE.name()).getServiceComponentHost("h1").setState(State.INSTALLED); params2 = new HashMap<String, String>() { { put("excluded_hosts", "h1 "); } }; resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION", null, resourceFilters, null, params2, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Component DATANODE on host h1 cannot be decommissioned as its not in STARTED state"); params2 = new HashMap<String, String>() { { put("excluded_hosts", "h1 "); put("mark_draining_only", "true"); } }; actionRequest = new ExecuteActionRequest("c1", "DECOMMISSION", null, resourceFilters, null, params2, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "mark_draining_only is not a valid parameter for NAMENODE"); controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition("a1", ActionType.SYSTEM, "test,dirName", "", "", "Does file exist", TargetHostType.SPECIFIC, Short.valueOf("100"))); controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition("a2", ActionType.SYSTEM, "", "HDFS", "DATANODE", "Does file exist", TargetHostType.ANY, Short.valueOf("100"))); controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition("a3", ActionType.SYSTEM, "", "MAPREDUCE", "MAPREDUCE_CLIENT", "Does file exist", TargetHostType.ANY, Short.valueOf("100"))); controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition("a4", ActionType.SYSTEM, "", "HIVE", "", "Does file exist", TargetHostType.ANY, Short.valueOf("100"))); actionRequest = new ExecuteActionRequest("c1", null, "a1", null, null, null, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a1 requires input 'test' that is not provided"); actionRequest = new ExecuteActionRequest("c1", null, "a1", null, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a1 requires input 'dirName' that is not provided"); params.put("dirName", "dirName"); actionRequest = new ExecuteActionRequest("c1", null, "a1", null, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a1 requires explicit target host(s)"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HIVE", null, null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", null, "a2", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a2 targets service HIVE that does not match with expected HDFS"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HDFS", "HDFS_CLIENT", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", null, "a2", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a2 targets component HDFS_CLIENT that does not match with expected DATANODE"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HDFS2", "HDFS_CLIENT", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", null, "a1", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a1 targets service HDFS2 that does not exist"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HDFS", "HDFS_CLIENT2", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", null, "a1", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a1 targets component HDFS_CLIENT2 that does not exist"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("", "HDFS_CLIENT2", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", null, "a1", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a1 targets component HDFS_CLIENT2 without specifying the target service"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("", "", null); resourceFilters.add(resourceFilter); // targets a service that is not a member of the stack (e.g. MR not in HDP-2) actionRequest = new ExecuteActionRequest("c1", null, "a3", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Action a3 targets service MAPREDUCE that does not exist"); hosts = new ArrayList<String>(); hosts.add("h6"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("", "", hosts); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", null, "a2", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Request specifies host h6 but its not a valid host based on the target service=HDFS and component=DATANODE"); resourceFilters.clear(); resourceFilter = new RequestResourceFilter("HIVE", "", null); resourceFilters.add(resourceFilter); actionRequest = new ExecuteActionRequest("c1", null, "a4", resourceFilters, null, params, false); expectActionCreationErrorWithMessage(actionRequest, requestProperties, "Suitable hosts not found, component=, service=HIVE, cluster=c1, actionName=a4"); }
From source file:com.ah.ui.actions.monitor.ClientMonitorAction.java
private List<ClientTsInfo> getResultMessage(String message) throws Exception { // message = "station 0022:5800:ccbb:<br />AC: BE<br />ADMCTL: Disable<br /><br />AC: BK<br />ADMCTL: Disable<br /><br />AC: Vi<br />ADMCTL: Enable<br />Ts Info Tid: 6<br />direction: BIDI<br />min_data_rate: 0<br />mean_data_rate: 360000<br />peak_data_rate: 0 <br />inactivity_interval: 0<br />suspension_interval: 0 <br />service_start_time: 0 <br />min_phy_rate: 6500000 <br />medium_time: 2776 <br />dot1Dtag: 4 <br />psb: 0 <br /><br /><br />AC: Vo<br />ADMCTL: Enable<br />Ts Info Tid: 3<br />direction: BIDI<br />min_data_rate: 0<br />mean_data_rate: 83200<br />peak_data_rate: 0 <br />inactivity_interval: 0<br />suspension_interval: 0 <br />service_start_time: 0 <br />min_phy_rate: 6500000 <br />medium_time: 905 <br />dot1Dtag: 6 <br />psb: 0 <br /><br /><br /><br />"; List<ClientTsInfo> array = new ArrayList<ClientTsInfo>(); if (message.startsWith(ClientTsInfo.STATION)) { String[] section = message.split("<br /><br />"); for (int i = 0; i < section.length; i++) { String[] tmpObj = section[i].split("<br />"); ClientTsInfo object = new ClientTsInfo(); for (int s = 0; s < tmpObj.length; s++) { if (tmpObj[s] != null && tmpObj[s] != "") { String msg = null; String[] tmp = null; if (tmpObj[s].indexOf(":") > 0 && tmpObj[s].indexOf(" ") > 0) { if (tmpObj[s].indexOf(ClientTsInfo.TID) > 0) { tmp = tmpObj[s].split(" "); if (tmp.length > 3) { msg = tmp[3]; object.setTid(msg); }/*w w w .j av a 2s .c om*/ } if (tmpObj[s].startsWith(ClientTsInfo.ADMCTL)) { tmp = tmpObj[s].split(" "); if (tmp.length > 1) { msg = tmp[1]; object.setAdmctl(msg); } } if (tmpObj[s].startsWith(ClientTsInfo.AC)) { tmp = tmpObj[s].split(" "); if (tmp.length > 1) { msg = tmp[1]; object.setAc(msg); } } if (tmpObj[s].startsWith(ClientTsInfo.UP_DOT1DTAG)) { tmp = tmpObj[s].split(" "); if (tmp.length > 1) { msg = tmp[1]; object.setUp(msg); } } if (tmpObj[s].startsWith(ClientTsInfo.PSB)) { tmp = tmpObj[s].split(" "); if (tmp.length > 1) { if (NumberUtils.isNumber(tmp[1])) { switch (Short.valueOf(tmp[1])) { case 0: { msg = ClientTsInfo.UP_LEGACY; break; } case 1: { msg = ClientTsInfo.UP_UAPSD; break; } } } object.setPsb(msg); } } if (tmpObj[s].startsWith(ClientTsInfo.DIRECTION)) { tmp = tmpObj[s].split(" "); if (tmp.length > 1) { if (tmp[1].equalsIgnoreCase(ClientTsInfo.DIRECTION_BIDI)) { msg = ClientTsInfo.DIRECTION_BI_DIRECTION; } else if (tmp[1].equalsIgnoreCase(ClientTsInfo.UP)) { msg = ClientTsInfo.DIRECTION_UPLINK; } else { msg = ClientTsInfo.DIRECTION_DOWNLINK; } object.setDirection(msg); } } if (tmpObj[s].startsWith(ClientTsInfo.MEDIUM_TIME)) { tmp = tmpObj[s].split(" "); if (tmp.length > 1) { msg = tmp[1]; object.setMediumTime(msg); } } } } } if (object != null && object.getTid() != null) { array.add(object); } } } Collections.sort(array, new Comparator<ClientTsInfo>() { @Override public int compare(ClientTsInfo o1, ClientTsInfo o2) { return Integer.parseInt(o1.getTid()) - Integer.parseInt(o2.getTid()); } }); return array; }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testLoanScheduleRoundingWithMiscFee() throws Exception { createInitialCustomers();//from w w w. j a va 2s . c om LoanOfferingBO loanOffering = createLoanOffering(false); Short noOfinstallments = (short) 2; LoanBO loan = createButDontRetrieveLoanAccount(loanOffering, false, null, noOfinstallments, 0.0, new Money(getCurrency(), "300.0")); for (AccountActionDateEntity accountActionDate : loan.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDate; if (loanScheduleEntity.getInstallmentId() == 1) { Assert.assertEquals(new Money(getCurrency(), "150.0"), loanScheduleEntity.getTotalDueWithFees()); } else { Assert.assertEquals(new Money(getCurrency(), "150.0"), loanScheduleEntity.getTotalDueWithFees()); } } loan.applyCharge(Short.valueOf(AccountConstants.MISC_FEES), 10.0); for (AccountActionDateEntity accountActionDate : loan.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDate; if (loanScheduleEntity.getInstallmentId() == 1) { Assert.assertEquals(new Money(getCurrency(), "160.0"), loanScheduleEntity.getTotalDueWithFees()); Assert.assertEquals(new Money(getCurrency(), "150.0"), loanScheduleEntity.getPrincipal()); } else { Assert.assertEquals(new Money(getCurrency(), "150.0"), loanScheduleEntity.getTotalDueWithFees()); } } }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * @return/*from w ww.ja v a 2 s . c o m*/ */ public static Vector<QueryFieldPanel> getQueryFieldPanelsForMapping( final QueryFieldPanelContainerIFace container, Set<SpQueryField> fields, final TableTree tblTree, final Hashtable<String, TableTree> ttHash, final Component saveBtn, SpExportSchemaMapping schemaMapping, List<String> missingFlds, Map<String, Vector<MappedFieldInfo>> autoMaps) { Vector<QueryFieldPanel> result = new Vector<QueryFieldPanel>(); //Need to change columnDefStr if mapMode... //result.add(bldQueryFieldPanel(this, null, null, getColumnDefStr(), saveBtn)); result.add(new QueryFieldPanel(container, null, container.getColumnDefStr(), saveBtn, null, schemaMapping, null)); Vector<SpExportSchemaItem> sis = new Vector<SpExportSchemaItem>(); if (schemaMapping.getSpExportSchema() != null) { sis.addAll(schemaMapping.getSpExportSchema().getSpExportSchemaItems()); } Collections.sort(sis, new Comparator<SpExportSchemaItem>() { /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @Override public int compare(SpExportSchemaItem o1, SpExportSchemaItem o2) { return o1.getFieldName().compareTo(o2.getFieldName()); } }); for (SpExportSchemaItem schemaItem : sis) { //System.out.println("SchemaItem: " + schemaItem.getFieldName()); boolean autoMapped = false; SpQueryField fld = getQueryFieldMapping(schemaMapping, schemaItem); FieldQRI fieldQRI = null; if (fld == null && autoMaps != null) { Vector<MappedFieldInfo> mappedTos = autoMaps.get(schemaItem.getFieldName().toLowerCase()); if (mappedTos != null) { for (MappedFieldInfo mappedTo : mappedTos) { fieldQRI = getFieldQRI(tblTree, mappedTo.getFieldName(), mappedTo.isRel(), mappedTo.getStringId(), getTableIds(mappedTo.getTableIds()), 0, ttHash); if (fieldQRI != null) { if (!fieldQRI.isFieldHidden()) { autoMapped = true; } else { fieldQRI = null; } break; } } } //result.add(new QueryFieldPanel(container, null, // container.getColumnDefStr(), saveBtn, fld, schemaMapping, schemaItem)); } else if (fld != null) { fieldQRI = getFieldQRI(tblTree, fld.getFieldName(), fld.getIsRelFld() != null && fld.getIsRelFld(), fld.getStringId(), getTableIds(fld.getTableList()), 0, ttHash); } if (fieldQRI != null) { QueryFieldPanel newPanel = new QueryFieldPanel(container, fieldQRI, container.getColumnDefStr(), saveBtn, fld, schemaMapping, schemaItem); newPanel.setAutoMapped(autoMapped); result.add(newPanel); fieldQRI.setIsInUse(true); if (fieldQRI.isFieldHidden() && !container.isPromptMode() && !container.isForSchemaExport()) { UIRegistry.showLocalizedMsg("QB_FIELD_HIDDEN_TITLE", "QB_FIELD_HIDDEN_SHOULD_REMOVE", fieldQRI.getTitle()); } } else if (fld != null) { log.error("Couldn't find [" + fld.getFieldName() + "] [" + fld.getTableList() + "]"); if (!container.isForSchemaExport() && !container.isPromptMode()) { for (SpQueryField field : fields) { //ain't superstitious but checking ids in case //fld and field are different java objects if (field.getId().equals(fld.getId())) { SpExportSchemaItemMapping mappingForField = null; for (SpExportSchemaItemMapping m : schemaMapping.getMappings()) { if (m.getQueryField() != null && field.getId().equals(m.getQueryField().getId())) { mappingForField = m; break; } } if (mappingForField != null) { schemaMapping.getMappings().remove(mappingForField); mappingForField.setExportSchemaItem(null); mappingForField.setExportSchemaMapping(null); mappingForField.setQueryField(null); } fields.remove(field); field.setQuery(null); fld.setQuery(null); break; } } } if (missingFlds != null) { String fldText = fld.getColumnAlias() != null ? fld.getColumnAlias() : fld.getFieldName(); missingFlds.add(fldText); } } } List<SpQueryField> toRemove = new ArrayList<SpQueryField>(); //add 'auto-mapped' fields not mapped to a concept if (autoMaps != null && fields.size() == 0 /* a new mapping */) { int cnt = 0; for (Map.Entry<String, Vector<MappedFieldInfo>> me : autoMaps.entrySet()) { if (me.getKey().startsWith("Unmapped:")) { MappedFieldInfo fi = me.getValue().get(0); SpQueryField fld = new SpQueryField(); fld.initialize(); fld.setIsNot(false); fld.setAlwaysFilter(false); fld.setIsPrompt(true); fld.setIsRelFld(false); fld.setSortType(Byte.valueOf("0")); fld.setPosition(Short.valueOf(String.valueOf(result.size() - 1 + cnt++))); fld.setSpQueryFieldId(-1); fld.setIsDisplay(false); fld.setOperStart(fi.getOperator()); fld.setFieldName(fi.getFieldName()); fld.setStringId(fi.getStringId()); fld.setTableList(fi.getTableIds()); fld.setContextTableIdent(fi.getContextTableId()); fields.add(fld); toRemove.add(fld); } } } //now add un-mapped fields for (SpQueryField fld : fields) { //int insertAt = 0; if (fld.getMapping() == null || fld.getMapping().getExportSchemaItem() == null) { FieldQRI fieldQRI = getFieldQRI(tblTree, fld.getFieldName(), fld.getIsRelFld() != null && fld.getIsRelFld(), fld.getStringId(), getTableIds(fld.getTableList()), 0, ttHash); if (fieldQRI != null) { // result.insertElementAt(new QueryFieldPanel(container, fieldQRI, // container.getColumnDefStr(), saveBtn, fld, null, true), insertAt++); QueryFieldPanel newQfp = new QueryFieldPanel(container, fieldQRI, container.getColumnDefStr(), saveBtn, fld, schemaMapping, null); result.add(newQfp); fieldQRI.setIsInUse(true); if (fld.getSpQueryFieldId() == -1) { newQfp.setAutoMapped(true); newQfp.setQueryFieldForAutomapping(null); } if (fieldQRI.isFieldHidden() && !container.isPromptMode() && !container.isForSchemaExport()) { UIRegistry.showLocalizedMsg("QB_FIELD_HIDDEN_TITLE", "QB_FIELD_HIDDEN_SHOULD_REMOVE", fieldQRI.getTitle()); } } else { log.error("Couldn't find [" + fld.getFieldName() + "] [" + fld.getTableList() + "]"); if (!container.isForSchemaExport() && !container.isPromptMode()) { for (SpQueryField field : fields) { //ain't superstitious but checking ids in case //fld and field are different java objects if (field.getId().equals(fld.getId())) { SpExportSchemaItemMapping mappingForField = null; for (SpExportSchemaItemMapping m : schemaMapping.getMappings()) { if (m.getQueryField() != null && field.getId().equals(m.getQueryField().getId())) { mappingForField = m; break; } } if (mappingForField != null) { schemaMapping.getMappings().remove(mappingForField); mappingForField.setExportSchemaItem(null); mappingForField.setExportSchemaMapping(null); mappingForField.setQueryField(null); } toRemove.add(field); field.setQuery(null); fld.setQuery(null); break; } } } if (missingFlds != null) { missingFlds.add(fld.getColumnAlias()); } } } } for (SpQueryField f : toRemove) { fields.remove(f); } // now add placeHolder panel for adding new condition //result.add(new QueryFieldPanel(container, null, // container.getColumnDefStr(), saveBtn, null, null, null, true)); //now sort on queryfield position Collections.sort(result, new Comparator<QueryFieldPanel>() { /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @Override public int compare(QueryFieldPanel o1, QueryFieldPanel o2) { SpQueryField f1 = o1.getQueryField(); SpQueryField f2 = o2.getQueryField(); if (f1 != null && f2 != null) { return f1.getPosition().compareTo(f2.getPosition()); } else if (f1 != null) { return 1; } else if (f2 != null) { return -1; } else return 0; } }); return result; }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testApplyMiscCharge() throws Exception { accountBO = getLoanAccount();/*from www. ja v a 2s. c o m*/ Money intialTotalFeeAmount = ((LoanBO) accountBO).getLoanSummary().getOriginalFees(); TestObjectFactory.flushandCloseSession(); accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId()); UserContext uc = TestUtils.makeUser(); accountBO.setUserContext(uc); accountBO.applyCharge(Short.valueOf(AccountConstants.MISC_FEES), new Double("33")); for (AccountActionDateEntity accountActionDateEntity : accountBO.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity; if (loanScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) { Assert.assertEquals(new Money(getCurrency(), "33.0"), loanScheduleEntity.getMiscFee()); } } Assert.assertEquals(intialTotalFeeAmount.add(new Money(getCurrency(), "33.0")), ((LoanBO) accountBO).getLoanSummary().getOriginalFees()); LoanActivityEntity loanActivityEntity = (LoanActivityEntity) ((LoanBO) accountBO).getLoanActivityDetails() .toArray()[0]; Assert.assertEquals(AccountConstants.MISC_FEES_APPLIED, loanActivityEntity.getComments()); Assert.assertEquals(((LoanBO) accountBO).getLoanSummary().getOriginalFees(), loanActivityEntity.getFeeOutstanding()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
/** * TODO: Re-enable this method when rounding code can handle mid-stream * changes to the loan that require re-applying applyRounding(). (method * LoanBO.applyCharge() does. When this method sets payment status to PAID, * applyRounding applies only to unpaid installments, which it cannot * currently handle.)//w w w . j a va 2s . c om * <p/> * Note: this method should not directly set status to PAID, as it leaves * the loan in an inconsistent state. The the status is paid, but the * installment's state is inconsistent -- the "paidX" instance variable * still have value 0. */ public void testApplyMiscChargeWithFirstInstallmentPaid() throws Exception { accountBO = getLoanAccount(); Money intialTotalFeeAmount = ((LoanBO) accountBO).getLoanSummary().getOriginalFees(); TestObjectFactory.flushandCloseSession(); accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId()); for (AccountActionDateEntity accountActionDateEntity : accountBO.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity; if (loanScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) { loanScheduleEntity.setPaymentStatus(PaymentStatus.PAID); } } UserContext uc = TestUtils.makeUser(); accountBO.setUserContext(uc); accountBO.applyCharge(Short.valueOf("-1"), new Double("33")); // Change this to more clearly separate what we are testing for from the // machinery needed to get that data? for (AccountActionDateEntity accountActionDateEntity : accountBO.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity; if (loanScheduleEntity.getInstallmentId().equals(Short.valueOf("2"))) { Assert.assertEquals(new Money(getCurrency(), "33.0"), loanScheduleEntity.getMiscFee()); } } Assert.assertEquals(intialTotalFeeAmount.add(new Money(getCurrency(), "33.0")), ((LoanBO) accountBO).getLoanSummary().getOriginalFees()); LoanActivityEntity loanActivityEntity = (LoanActivityEntity) ((LoanBO) accountBO).getLoanActivityDetails() .toArray()[0]; Assert.assertEquals(AccountConstants.MISC_FEES_APPLIED, loanActivityEntity.getComments()); Assert.assertEquals(((LoanBO) accountBO).getLoanSummary().getOriginalFees(), loanActivityEntity.getFeeOutstanding()); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testApplyUpfrontFee() throws Exception { accountBO = getLoanAccount();/*from ww w . j a v a 2s . com*/ Money intialTotalFeeAmount = ((LoanBO) accountBO).getLoanSummary().getOriginalFees(); TestObjectFactory.flushandCloseSession(); FeeBO upfrontFee = TestObjectFactory.createOneTimeRateFee("Upfront Fee", FeeCategory.LOAN, Double.valueOf("20"), FeeFormula.AMOUNT, FeePayment.UPFRONT); accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId()); UserContext uc = TestUtils.makeUser(); accountBO.setUserContext(uc); accountBO.applyCharge(upfrontFee.getFeeId(), ((RateFeeBO) upfrontFee).getRate()); StaticHibernateUtil.commitTransaction(); StaticHibernateUtil.closeSession(); accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId()); Date lastAppliedDate = null; Money feeAmountApplied = new Money(getCurrency()); Map<String, String> fees2 = new HashMap<String, String>(); fees2.put("Upfront Fee", "60.0"); fees2.put("Mainatnence Fee", "100.0"); Set<AccountActionDateEntity> actionDateEntities = ((LoanBO) accountBO).getAccountActionDates(); Assert.assertEquals(6, actionDateEntities.size()); LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities); checkFees(fees2, paymentsArray[0], false); // setting of values here for (AccountActionDateEntity accountActionDateEntity : accountBO.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity; if (loanScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) { lastAppliedDate = loanScheduleEntity.getActionDate(); for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : loanScheduleEntity .getAccountFeesActionDetails()) { if (accountFeesActionDetailEntity.getFee().getFeeName().equalsIgnoreCase("Upfront Fee")) { feeAmountApplied = accountFeesActionDetailEntity.getFeeAmount(); } } } } Assert.assertEquals(intialTotalFeeAmount.add(feeAmountApplied), ((LoanBO) accountBO).getLoanSummary().getOriginalFees()); LoanActivityEntity loanActivityEntity = (LoanActivityEntity) ((LoanBO) accountBO).getLoanActivityDetails() .toArray()[0]; Assert.assertEquals(upfrontFee.getFeeName() + " applied", loanActivityEntity.getComments()); Assert.assertEquals(((LoanBO) accountBO).getLoanSummary().getOriginalFees(), loanActivityEntity.getFeeOutstanding()); AccountFeesEntity accountFeesEntity = accountBO.getAccountFees(upfrontFee.getFeeId()); Assert.assertEquals(FeeStatus.ACTIVE, accountFeesEntity.getFeeStatusAsEnum()); Assert.assertEquals(DateUtils.getDateWithoutTimeStamp(lastAppliedDate.getTime()), DateUtils.getDateWithoutTimeStamp(accountFeesEntity.getLastAppliedDate().getTime())); }