List of usage examples for java.math BigDecimal intValue
@Override public int intValue()
From source file:com.ning.billing.recurly.RecurlyClient.java
/** * Refund a transaction//ww w.ja va2s . c o m * * @param transactionId recurly transaction id * @param amount amount to refund, null for full refund */ public void refundTransaction(final String transactionId, @Nullable final BigDecimal amount) { String url = Transactions.TRANSACTIONS_RESOURCE + "/" + transactionId; if (amount != null) { url = url + "?amount_in_cents=" + (amount.intValue() * 100); } doDELETE(url); }
From source file:org.kuali.kfs.gl.batch.service.PosterServiceTest.java
/** * Covers the posting of GL entries/*from w ww. j a va2 s .c o m*/ * * @throws Exception thrown if any exception is encountered for any reason */ public void testPostGlEntry() throws Exception { LOG.debug("testPostGlEntry() started"); String[] inputTransactions = { TestUtils.getFiscalYearForTesting() + "BA6044909-----5300---ACEX07CHKDPDBLANKFISC 12345214090047 EVERETT J PRESCOTT INC. 1445.00D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ", TestUtils.getFiscalYearForTesting() + "BA6044909-----5300---ACEX07CHKDPDBLANKFISC 12345214090047 EVERETT J PRESCOTT INC. 1445.00D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 " }; EntryHolder[] outputTransactions = { new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, inputTransactions[0]), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, inputTransactions[1]) }; clearBatchFiles(); clearGlEntryTable("BA", "6044909"); loadInputTransactions(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, inputTransactions); posterService.postMainEntries(); assertOriginEntries(2, outputTransactions); List glEntries = unitTestSqlDao .sqlSelect("select * from GL_ENTRY_T where fin_coa_cd = 'BA' and account_nbr = '6044909'"); assertEquals("Should be 2 GL entries", 2, glEntries.size()); Map glEntry = (Map) glEntries.get(0); BigDecimal ufy = (BigDecimal) glEntry.get("UNIV_FISCAL_YR"); assertEquals("univ_fiscal_yr wrong", TestUtils.getFiscalYearForTesting().intValue(), ufy.intValue()); assertEquals("fin_coa_cd wrong", "BA", (String) glEntry.get("FIN_COA_CD")); assertEquals("account_nbr wrong", "6044909", (String) glEntry.get("ACCOUNT_NBR")); assertEquals("sub_acct_nbr wrong", "-----", (String) glEntry.get("SUB_ACCT_NBR")); assertEquals("fin_object_cd wrong", "5300", (String) glEntry.get("FIN_OBJECT_CD")); assertEquals("fin_sub_obj_cd wrong", "---", (String) glEntry.get("FIN_SUB_OBJ_CD")); assertEquals("FIN_BALANCE_TYP_CD wrong", "AC", (String) glEntry.get("FIN_BALANCE_TYP_CD")); assertEquals("FIN_OBJ_TYP_CD wrong", "EX", (String) glEntry.get("FIN_OBJ_TYP_CD")); assertEquals("UNIV_FISCAL_PRD_CD wrong", "07", (String) glEntry.get("UNIV_FISCAL_PRD_CD")); assertEquals("FDOC_TYP_CD wrong", "CHKD", (String) glEntry.get("FDOC_TYP_CD")); assertEquals("FS_ORIGIN_CD wrong", "PD", (String) glEntry.get("FS_ORIGIN_CD")); assertEquals("FDOC_NBR wrong", "BLANKFISC", (String) glEntry.get("FDOC_NBR")); BigDecimal tesq = (BigDecimal) glEntry.get("TRN_ENTR_SEQ_NBR"); assertEquals("TRN_ENTR_SEQ_NBR wrong", 1, tesq.intValue()); assertEquals("TRN_LDGR_ENTR_DESC wrong", "214090047 EVERETT J PRESCOTT INC.", (String) glEntry.get("TRN_LDGR_ENTR_DESC")); assertEquals("TRN_LDGR_ENTR_AMT wrong", 1445.00, getAmount(glEntry, "TRN_LDGR_ENTR_AMT"), 0.01); assertEquals("TRN_DEBIT_CRDT_CD wrong", "D", (String) glEntry.get("TRN_DEBIT_CRDT_CD")); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); assertEquals("TRANSACTION_DT wrong", TestUtils.getFiscalYearForTesting() + "-01-05", sdf.format((Date) glEntry.get("TRANSACTION_DT"))); assertEquals("ORG_DOC_NBR wrong", "ABCDEFGHIJ", (String) glEntry.get("ORG_DOC_NBR")); assertEquals("PROJECT_CD wrong", "----------", (String) glEntry.get("PROJECT_CD")); assertEquals("ORG_REFERENCE_ID wrong", "12345678", (String) glEntry.get("ORG_REFERENCE_ID")); assertTrue("FDOC_REF_TYP_CD is not blank, was: '" + glEntry.get("FDOC_REF_TYP_CD") + "'", StringUtils.isEmpty((String) glEntry.get("FDOC_REF_TYP_CD"))); assertTrue("FS_REF_ORIGIN_CD is not blank, was: '" + glEntry.get("FS_REF_ORIGIN_CD") + "'", StringUtils.isEmpty((String) glEntry.get("FS_REF_ORIGIN_CD"))); assertTrue("FDOC_REF_NBR is not blank, was: '" + glEntry.get("FDOC_REF_NBR") + "'", StringUtils.isEmpty((String) glEntry.get("FDOC_REF_NBR"))); assertNull("FDOC_REVERSAL_DT is not null, was: '" + glEntry.get("FDOC_REVERSAL_DT") + "'", glEntry.get("FDOC_REVERSAL_DT")); assertTrue("TRN_ENCUM_UPDT_CD wrong", StringUtils.isBlank((String) glEntry.get("TRN_ENCUM_UPDT_CD"))); // The 2nd one should have a different sequence number glEntry = (Map) glEntries.get(1); tesq = (BigDecimal) glEntry.get("TRN_ENTR_SEQ_NBR"); assertEquals("TRN_ENTR_SEQ_NBR wrong", 2, tesq.intValue()); }
From source file:net.rptools.maptool.client.functions.LookupTableFunction.java
@Override public Object childEvaluate(Parser parser, String function, List<Object> params) throws ParserException { if ("getTableNames".equalsIgnoreCase(function)) { checkNumberOfParameters("getTableNames", params, 0, 1); String delim = ","; if (params.size() > 0) { delim = params.get(0).toString(); }//from w w w .java2 s.c o m if ("json".equalsIgnoreCase(delim)) return JSONArray.fromObject(getTableList(MapTool.getPlayer().isGM())); return StringUtils.join(getTableList(MapTool.getPlayer().isGM()), delim); } else if ("getTableVisible".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("getTableVisible", params, 1, 1); String name = params.get(0).toString(); LookupTable lookupTable = getMaptoolTable(name, function); return lookupTable.getVisible() ? "1" : "0"; } else if ("setTableVisible".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("setTableVisible", params, 2, 2); String name = params.get(0).toString(); String visible = params.get(1).toString(); LookupTable lookupTable = getMaptoolTable(name, function); lookupTable.setVisible(AbstractTokenAccessorFunction.getBooleanValue(visible)); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return lookupTable.getVisible() ? "1" : "0"; } else if ("getTableAccess".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("getTableAccess", params, 1, 1); String name = params.get(0).toString(); LookupTable lookupTable = getMaptoolTable(name, function); return lookupTable.getAllowLookup() ? "1" : "0"; } else if ("setTableAccess".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("setTableAccess", params, 2, 2); String name = params.get(0).toString(); String access = params.get(1).toString(); LookupTable lookupTable = getMaptoolTable(name, function); lookupTable.setAllowLookup(AbstractTokenAccessorFunction.getBooleanValue(access)); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return lookupTable.getAllowLookup() ? "1" : "0"; } else if ("getTableRoll".equalsIgnoreCase(function)) { checkNumberOfParameters("getTableRoll", params, 1, 1); String name = params.get(0).toString(); LookupTable lookupTable = getMaptoolTable(name, function); return lookupTable.getRoll(); } else if ("setTableRoll".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("setTableRoll", params, 2, 2); String name = params.get(0).toString(); String roll = params.get(1).toString(); LookupTable lookupTable = getMaptoolTable(name, function); lookupTable.setRoll(roll); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return lookupTable.getRoll(); } else if ("clearTable".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("clearTable", params, 1, 1); String name = params.get(0).toString(); LookupTable lookupTable = getMaptoolTable(name, function); lookupTable.clearEntries(); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return ""; } else if ("addTableEntry".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("addTableEntry", params, 4, 5); String name = params.get(0).toString(); String min = params.get(1).toString(); String max = params.get(2).toString(); String value = params.get(3).toString(); MD5Key asset = null; if (params.size() > 4) { asset = new MD5Key(params.get(4).toString()); } LookupTable lookupTable = getMaptoolTable(name, function); lookupTable.addEntry(Integer.valueOf(min), Integer.valueOf(max), value, asset); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return ""; } else if ("deleteTableEntry".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("deleteTableEntry", params, 2, 2); String name = params.get(0).toString(); String roll = params.get(1).toString(); LookupTable lookupTable = getMaptoolTable(name, function); LookupEntry entry = lookupTable.getLookup(roll); if (entry != null) { List<LookupEntry> oldlist = new ArrayList<LookupEntry>(lookupTable.getEntryList()); lookupTable.clearEntries(); for (LookupEntry e : oldlist) if (e != entry) lookupTable.addEntry(e.getMin(), e.getMax(), e.getValue(), e.getImageId()); } MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return ""; } else if ("createTable".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("createTable", params, 3, 4); String name = params.get(0).toString(); String visible = params.get(1).toString(); String lookups = params.get(2).toString(); MD5Key asset = null; if (params.size() > 3) { asset = new MD5Key(params.get(3).toString()); } LookupTable lookupTable = new LookupTable(); lookupTable.setName(name); lookupTable.setVisible(AbstractTokenAccessorFunction.getBooleanValue(visible)); lookupTable.setAllowLookup(AbstractTokenAccessorFunction.getBooleanValue(lookups)); if (asset != null) lookupTable.setTableImage(asset); MapTool.getCampaign().getLookupTableMap().put(name, lookupTable); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return ""; } else if ("deleteTable".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("deleteTable", params, 1, 1); String name = params.get(0).toString(); LookupTable lookupTable = getMaptoolTable(name, function); if (lookupTable != null) { MapTool.getCampaign().getLookupTableMap().remove(name); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); } return ""; } else if ("getTableImage".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("getTableImage", params, 1, 1); String name = params.get(0).toString(); LookupTable lookupTable = getMaptoolTable(name, function); return lookupTable.getTableImage(); } else if ("setTableImage".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("setTableImage", params, 2, 2); String name = params.get(0).toString(); MD5Key asset = new MD5Key(params.get(1).toString()); LookupTable lookupTable = getMaptoolTable(name, function); lookupTable.setTableImage(asset); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return ""; } else if ("copyTable".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("copyTable", params, 2, 2); String oldName = params.get(0).toString(); String newName = params.get(1).toString(); LookupTable oldTable = getMaptoolTable(oldName, function); if (oldTable != null) { LookupTable newTable = new LookupTable(oldTable); newTable.setName(newName); MapTool.getCampaign().getLookupTableMap().put(newName, newTable); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); } return ""; } else if ("setTableEntry".equalsIgnoreCase(function)) { checkTrusted(function); checkNumberOfParameters("setTableEntry", params, 3, 3); String name = params.get(0).toString(); String roll = params.get(1).toString(); String result = params.get(2).toString(); LookupTable lookupTable = getMaptoolTable(name, function); LookupEntry entry = lookupTable.getLookup(roll); if (entry == null) return 0; // no entry was found int rollInt = Integer.valueOf(roll); if (rollInt < entry.getMin() || rollInt > entry.getMax()) return 0; // entry was found but doesn't match List<LookupEntry> oldlist = new ArrayList<LookupEntry>(lookupTable.getEntryList()); lookupTable.clearEntries(); for (LookupEntry e : oldlist) if (e != entry) lookupTable.addEntry(e.getMin(), e.getMax(), e.getValue(), e.getImageId()); else lookupTable.addEntry(e.getMin(), e.getMax(), result, e.getImageId()); MapTool.serverCommand().updateCampaign(MapTool.getCampaign().getCampaignProperties()); return 1; } else { checkNumberOfParameters(function, params, 1, 3); String name = params.get(0).toString(); String roll = null; if (params.size() > 1) { roll = params.get(1).toString().length() == 0 ? null : params.get(1).toString(); } LookupTable lookupTable = MapTool.getCampaign().getLookupTableMap().get(name); if (!MapTool.getPlayer().isGM() && !lookupTable.getAllowLookup()) { if (lookupTable.getVisible()) { throw new ParserException(function + "(): " + I18N.getText("msg.error.tableUnknown") + name); } else { throw new ParserException( function + "(): " + I18N.getText("msg.error.tableAccessProhibited") + ": " + name); } } if (lookupTable == null) { throw new ParserException( I18N.getText("macro.function.LookupTableFunctions.unknownTable", function, name)); } LookupEntry result = lookupTable.getLookup(roll); if (function.equals("table") || function.equals("tbl")) { String val = result.getValue(); try { BigDecimal bival = new BigDecimal(val); return bival; } catch (NumberFormatException nfe) { return val; } } else { // We want the image URI if (result.getImageId() == null) { throw new ParserException( I18N.getText("macro.function.LookupTableFunctions.noImage", function, name)); } BigDecimal size = null; if (params.size() > 2) { if (params.get(2) instanceof BigDecimal) { size = (BigDecimal) params.get(2); } else { throw new ParserException( I18N.getText("macro.function.LookupTableFunctions.invalidSize", function)); } } StringBuilder assetId = new StringBuilder("asset://"); assetId.append(result.getImageId().toString()); if (size != null) { int i = Math.max(size.intValue(), 1); // Constrain to a minimum of 1 assetId.append("-"); assetId.append(i); } return assetId.toString(); } } }
From source file:org.mifosplatform.portfolio.loanaccount.api.LoansApiResource.java
@GET @Path("{loanId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveLoan(@PathParam("loanId") final Long loanId, @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly, @Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions); final LoanAccountData loanBasicDetails = this.loanReadPlatformService.retrieveOne(loanId); Collection<LoanTransactionData> loanRepayments = null; LoanScheduleData repaymentSchedule = null; Collection<LoanChargeData> charges = null; Collection<GuarantorData> guarantors = null; Collection<InsuranceData> insurances = null; Collection<CollateralData> collateral = null; CalendarData meeting = null;//from w w w . ja v a 2s . com Collection<NoteData> notes = null; PortfolioAccountData linkedAccount = null; Collection<LoanTaxData> taxes = null; Collection<LoanFeeMasterData> deposits = null; final Set<String> mandatoryResponseParameters = new HashSet<String>(); final Set<String> associationParameters = ApiParameterHelper .extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); if (!associationParameters.isEmpty()) { if (associationParameters.contains("all")) { associationParameters.addAll(Arrays.asList("repaymentSchedule", "transactions", "charges", "guarantors", "collateral", "notes", "linkedAccount", "insurances", "taxes", "deposits")); } if (associationParameters.contains("guarantors")) { mandatoryResponseParameters.add("guarantors"); guarantors = this.guarantorReadPlatformService.retrieveGuarantorsForLoan(loanId); if (CollectionUtils.isEmpty(guarantors)) { guarantors = null; } } if (associationParameters.contains("insurances")) { mandatoryResponseParameters.add("insurances"); insurances = this.insuranceReadPlatformService.retrieveInsuracetData(loanId); if (CollectionUtils.isEmpty(insurances)) { insurances = null; } } if (associationParameters.contains("transactions")) { mandatoryResponseParameters.add("transactions"); final Collection<LoanTransactionData> currentLoanRepayments = this.loanReadPlatformService .retrieveLoanTransactions(loanId); if (!CollectionUtils.isEmpty(currentLoanRepayments)) { loanRepayments = currentLoanRepayments; } } if (associationParameters.contains("repaymentSchedule")) { mandatoryResponseParameters.add("repaymentSchedule"); final RepaymentScheduleRelatedLoanData repaymentScheduleRelatedData = loanBasicDetails .repaymentScheduleRelatedData(); repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId, repaymentScheduleRelatedData); } if (associationParameters.contains("charges")) { mandatoryResponseParameters.add("charges"); charges = this.loanChargeReadPlatformService.retrieveLoanCharges(loanId); if (CollectionUtils.isEmpty(charges)) { charges = null; } } if (associationParameters.contains("taxes")) { mandatoryResponseParameters.add("taxes"); taxes = this.loanTaxReadPlatformService.retrieveLoanTaxes(loanId); if (CollectionUtils.isEmpty(taxes)) { taxes = null; } } if (associationParameters.contains("deposits")) { mandatoryResponseParameters.add("deposits"); deposits = this.loanFeeMasterDataReadPlatformService.retrieveLoanFeeMasterData(loanId); if (CollectionUtils.isEmpty(deposits)) { deposits = null; } } if (associationParameters.contains("collateral")) { mandatoryResponseParameters.add("collateral"); collateral = this.loanCollateralReadPlatformService.retrieveCollaterals(loanId); if (CollectionUtils.isEmpty(collateral)) { collateral = null; } } if (associationParameters.contains("meeting")) { mandatoryResponseParameters.add("meeting"); meeting = this.calendarReadPlatformService.retrieveLoanCalendar(loanId); } if (associationParameters.contains("notes")) { mandatoryResponseParameters.add("notes"); notes = this.noteReadPlatformService.retrieveNotesByResource(loanId, NoteType.LOAN.getValue()); if (CollectionUtils.isEmpty(notes)) { notes = null; } } if (associationParameters.contains("linkedAccount")) { mandatoryResponseParameters.add("linkedAccount"); linkedAccount = this.accountAssociationsReadPlatformService.retriveLoanAssociation(loanId); } } Collection<LoanProductData> productOptions = null; Collection<EnumOptionData> loanTermFrequencyTypeOptions = null; Collection<EnumOptionData> repaymentFrequencyTypeOptions = null; Collection<TransactionProcessingStrategyData> repaymentStrategyOptions = null; Collection<EnumOptionData> interestRateFrequencyTypeOptions = null; Collection<EnumOptionData> amortizationTypeOptions = null; Collection<EnumOptionData> interestTypeOptions = null; Collection<EnumOptionData> interestCalculationPeriodTypeOptions = null; Collection<FundData> fundOptions = null; Collection<StaffData> allowedLoanOfficers = null; Collection<ChargeData> chargeOptions = null; ChargeData chargeTemplate = null; Collection<CodeValueData> loanPurposeOptions = null; Collection<CodeValueData> loanCollateralOptions = null; Collection<CalendarData> calendarOptions = null; Collection<PortfolioAccountData> accountLinkingOptions = null; Collection<TaxMapData> taxMapData = null; Collection<FeeMasterData> feeMasterDataOptions = null; final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); if (template) { productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup(); loanTermFrequencyTypeOptions = this.dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions(); repaymentFrequencyTypeOptions = this.dropdownReadPlatformService .retrieveRepaymentFrequencyTypeOptions(); interestRateFrequencyTypeOptions = this.dropdownReadPlatformService .retrieveInterestRateFrequencyTypeOptions(); amortizationTypeOptions = this.dropdownReadPlatformService.retrieveLoanAmortizationTypeOptions(); interestTypeOptions = this.dropdownReadPlatformService.retrieveLoanInterestTypeOptions(); interestCalculationPeriodTypeOptions = this.dropdownReadPlatformService .retrieveLoanInterestRateCalculatedInPeriodOptions(); fundOptions = this.fundReadPlatformService.retrieveAllFunds(); repaymentStrategyOptions = this.dropdownReadPlatformService.retreiveTransactionProcessingStrategies(); final boolean feeChargesOnly = false; chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly); taxMapData = this.taxMapReadPlatformService.retriveTaxMapData(true); feeMasterDataOptions = this.feeMasterReadPlatformService.retrieveAllData("Deposit"); chargeTemplate = this.loanChargeReadPlatformService.retrieveLoanChargeTemplate(); allowedLoanOfficers = this.loanReadPlatformService .retrieveAllowedLoanOfficers(loanBasicDetails.officeId(), staffInSelectedOfficeOnly); loanPurposeOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LeasePurpose"); loanCollateralOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LeaseCollateral"); final CurrencyData currencyData = loanBasicDetails.currency(); String currencyCode = null; if (currencyData != null) { currencyCode = currencyData.code(); } final long[] accountStatus = { SavingsAccountStatusType.ACTIVE.getValue() }; accountLinkingOptions = this.portfolioAccountReadPlatformService.retrieveAllForLookup( PortfolioAccountType.SAVINGS.getValue(), loanBasicDetails.clientId(), currencyCode, accountStatus); if (!associationParameters.contains("linkedAccount")) { mandatoryResponseParameters.add("linkedAccount"); linkedAccount = this.accountAssociationsReadPlatformService.retriveLoanAssociation(loanId); } if (loanBasicDetails.groupId() != null) { calendarOptions = this.loanReadPlatformService.retrieveCalendars(loanBasicDetails.groupId()); } } //madhav used for the s BigDecimal principaPlusInterest = loanReadPlatformService.retrivePrincipalForReSchedule(loanId); if (principaPlusInterest.intValue() > 0) loanBasicDetails.setPrincipal(principaPlusInterest); final LoanAccountData loanAccount = LoanAccountData.associationsAndTemplate(loanBasicDetails, repaymentSchedule, loanRepayments, charges, collateral, guarantors, meeting, productOptions, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions, repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, loanPurposeOptions, loanCollateralOptions, calendarOptions, notes, insurances, accountLinkingOptions, linkedAccount, taxMapData, taxes, feeMasterDataOptions, deposits); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper .process(uriInfo.getQueryParameters(), mandatoryResponseParameters); return this.toApiJsonSerializer.serialize(settings, loanAccount, this.LOAN_DATA_PARAMETERS); }
From source file:org.kuali.kfs.gl.batch.service.PosterServiceTest.java
/** * Covers posting entry's effects on account balances * * @throws Exception thrown if any exception is encountered for any reason *///from www . j ava 2 s.c om public void testPostGlAccountBalance() throws Exception { LOG.debug("testPostGlAccountBalance() started"); String[] inputTransactions = { TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---TREX07CHKDPDGLACCTBA1 12345DESCRIPTION 123.45D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ", TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---ACEX07CHKDPDGLACCTBA1 12345DESCRIPTION 1445.00D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ", TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---TREX07CHKDPDGLACCTBA1 12345DESCRIPTION 345.00D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ", TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---CBEX07CHKDPDGLACCTBA1 12345DESCRIPTION 222.00 " + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ", TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---ACEX07CHKDPDGLACCTBA1 12345DESCRIPTION 5.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ", TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---TREX07CHKDPDGLACCTBA1 12345DESCRIPTION 5.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ", TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---CBEX07CHKDPDGLACCTBA1 12345DESCRIPTION -2.00 " + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 " }; EntryHolder[] outputTransactions = new EntryHolder[] { new EntryHolder( GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---TREX07CHKDPDGLACCTBA1 12345DESCRIPTION 123.45D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----4166---ACEX07CHKDPDGLACCTBA1 12345DESCRIPTION 1445.00D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----4166---TREX07CHKDPDGLACCTBA1 12345DESCRIPTION 345.00D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----4166---CBEX07CHKDPDGLACCTBA1 12345DESCRIPTION 222.00 " + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----4166---ACEX07CHKDPDGLACCTBA1 12345DESCRIPTION 5.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----4166---TREX07CHKDPDGLACCTBA1 12345DESCRIPTION 5.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----4166---CBEX07CHKDPDGLACCTBA1 12345DESCRIPTION -2.00 " + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ") }; clearBatchFiles(); clearGlAccountBalanceTable(); loadInputTransactions(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, inputTransactions); posterService.postMainEntries(); assertOriginEntries(2, outputTransactions); List balances = unitTestSqlDao.sqlSelect("select * from GL_ACCT_BALANCES_T"); assertEquals("Should be 1 balance", 1, balances.size()); Map bal = (Map) balances.get(0); BigDecimal a = (BigDecimal) bal.get("UNIV_FISCAL_YR"); assertEquals("UNIV_FISCAL_YR is wrong", TestUtils.getFiscalYearForTesting().intValue(), a.intValue()); assertEquals("FIN_COA_CD is wrong", "BA", bal.get("FIN_COA_CD")); assertEquals("ACCOUNT_NBR is wrong", "6044900", bal.get("ACCOUNT_NBR")); assertEquals("SUB_ACCT_NBR is wrong", "-----", bal.get("SUB_ACCT_NBR")); assertEquals("FIN_OBJECT_CD is wrong", "4166", bal.get("FIN_OBJECT_CD")); assertEquals("FIN_SUB_OBJ_CD is wrong", "---", bal.get("FIN_SUB_OBJ_CD")); assertEquals("CURR_BDLN_BAL_AMT is wrong", 220.00, getAmount(bal, "CURR_BDLN_BAL_AMT"), 0.01); assertEquals("ACLN_ACTLS_BAL_AMT is wrong", 1440.00, getAmount(bal, "ACLN_ACTLS_BAL_AMT"), 0.01); assertEquals("ACLN_ENCUM_BAL_AMT is wrong", 0.00, getAmount(bal, "ACLN_ENCUM_BAL_AMT"), 0.01); }
From source file:org.kuali.kfs.gl.batch.service.PosterServiceTest.java
/** * Covers entry posting's effects on encumbrances * * @throws Exception thrown if any exception is encountered for any reason */// w w w.ja v a 2 s . c o m public void testPostEncumbrance() throws Exception { LOG.debug("testPostEncumbrance() started"); String[] inputTransactions = { TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---IEEX06CHKDPDENCTEST01 12345214090047 EVERETT J PRESCOTT INC. 100.01D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 D ", TestUtils.getFiscalYearForTesting() + "BA6044900-----5215---IEEX06CHKDPDENCTEST01 12345214090047 EVERETT J PRESCOTT INC. 200.02D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 D ", TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---IEEX06CHKDPDENCTEST02 12345214090047 EVERETT J PRESCOTT INC. 50.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678CHKDPDENCTEST01 R ", TestUtils.getFiscalYearForTesting() + "BA6044900-----5215---IEEX06CHKDPDENCTEST02 12345214090047 EVERETT J PRESCOTT INC. 60.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678CHKDPDENCTEST01 R ", TestUtils.getFiscalYearForTesting() + "BA6044900-----5215---ACEX06CHKDPDENCTEST02 12345214090047 EVERETT J PRESCOTT INC. 60.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ", }; EntryHolder[] outputTransactions = new EntryHolder[] { new EntryHolder( GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils.getFiscalYearForTesting() + "BA6044900-----4166---IEEX06CHKDPDENCTEST01 12345214090047 EVERETT J PRESCOTT INC. 100.01D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 D "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----5215---IEEX06CHKDPDENCTEST01 12345214090047 EVERETT J PRESCOTT INC. 200.02D" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 D "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----4166---IEEX06CHKDPDENCTEST02 12345214090047 EVERETT J PRESCOTT INC. 50.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678CHKDPDENCTEST01 R "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----5215---IEEX06CHKDPDENCTEST02 12345214090047 EVERETT J PRESCOTT INC. 60.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678CHKDPDENCTEST01 R "), new EntryHolder(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, TestUtils .getFiscalYearForTesting() + "BA6044900-----5215---ACEX06CHKDPDENCTEST02 12345214090047 EVERETT J PRESCOTT INC. 60.00C" + TestUtils.getFiscalYearForTesting() + "-01-05ABCDEFGHIJ----------12345678 ") }; clearBatchFiles(); clearEncumbranceTable(); loadInputTransactions(GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE, inputTransactions); posterService.postMainEntries(); assertOriginEntries(2, outputTransactions); List encumbrances = unitTestSqlDao.sqlSelect("select * from GL_ENCUMBRANCE_T order by fin_object_cd"); assertEquals("Should be 2 encumbrances", 2, encumbrances.size()); Map enc4166 = (Map) encumbrances.get(0); Map enc5215 = (Map) encumbrances.get(1); BigDecimal a = (BigDecimal) enc4166.get("UNIV_FISCAL_YR"); assertEquals("UNIV_FISCAL_YR is wrong", TestUtils.getFiscalYearForTesting().intValue(), a.intValue()); assertEquals("FIN_COA_CD is wrong", "BA", enc4166.get("FIN_COA_CD")); assertEquals("ACCOUNT_NBR is wrong", "6044900", enc4166.get("ACCOUNT_NBR")); assertEquals("SUB_ACCT_NBR is wrong", "-----", enc4166.get("SUB_ACCT_NBR")); assertEquals("FIN_OBJECT_CD is wrong", "4166", enc4166.get("FIN_OBJECT_CD")); assertEquals("FIN_SUB_OBJ_CD is wrong", "---", enc4166.get("FIN_SUB_OBJ_CD")); assertEquals("FIN_BALANCE_TYP_CD is wrong", "IE", enc4166.get("FIN_BALANCE_TYP_CD")); assertEquals("FDOC_TYP_CD is wrong", "CHKD", enc4166.get("FDOC_TYP_CD")); assertEquals("FS_ORIGIN_CD is wrong", "PD", enc4166.get("FS_ORIGIN_CD")); assertEquals("FDOC_NBR is wrong", "ENCTEST01", enc4166.get("FDOC_NBR")); assertEquals("TRN_ENCUM_DESC is wrong", "214090047 EVERETT J PRESCOTT INC.", enc4166.get("TRN_ENCUM_DESC")); assertEquals("ACLN_ENCUM_AMT is wrong", 100.01, getAmount(enc4166, "ACLN_ENCUM_AMT"), 0.01); assertEquals("ACLN_ENCUM_CLS_AMT is wrong", 50, getAmount(enc4166, "ACLN_ENCUM_CLS_AMT"), 0.01); a = (BigDecimal) enc5215.get("UNIV_FISCAL_YR"); assertEquals("UNIV_FISCAL_YR is wrong", TestUtils.getFiscalYearForTesting().intValue(), a.intValue()); assertEquals("FIN_COA_CD is wrong", "BA", enc5215.get("FIN_COA_CD")); assertEquals("ACCOUNT_NBR is wrong", "6044900", enc5215.get("ACCOUNT_NBR")); assertEquals("SUB_ACCT_NBR is wrong", "-----", enc5215.get("SUB_ACCT_NBR")); assertEquals("FIN_OBJECT_CD is wrong", "5215", enc5215.get("FIN_OBJECT_CD")); assertEquals("FIN_SUB_OBJ_CD is wrong", "---", enc5215.get("FIN_SUB_OBJ_CD")); assertEquals("FIN_BALANCE_TYP_CD is wrong", "IE", enc5215.get("FIN_BALANCE_TYP_CD")); assertEquals("FDOC_TYP_CD is wrong", "CHKD", enc5215.get("FDOC_TYP_CD")); assertEquals("FS_ORIGIN_CD is wrong", "PD", enc5215.get("FS_ORIGIN_CD")); assertEquals("FDOC_NBR is wrong", "ENCTEST01", enc5215.get("FDOC_NBR")); assertEquals("TRN_ENCUM_DESC is wrong", "214090047 EVERETT J PRESCOTT INC.", enc5215.get("TRN_ENCUM_DESC")); assertEquals("ACLN_ENCUM_AMT is wrong", 200.02, getAmount(enc5215, "ACLN_ENCUM_AMT"), 0.01); assertEquals("ACLN_ENCUM_CLS_AMT is wrong", 60, getAmount(enc5215, "ACLN_ENCUM_CLS_AMT"), 0.01); }
From source file:is.idega.idegaweb.egov.gumbo.licenses.SendLicenseFeeClaimHandler.java
public void execute(ExecutionContext executionContext) throws Exception { CaseProcInstBind bind = getCasesBPMDAO() .getCaseProcInstBindByProcessInstanceId(executionContext.getProcessInstance().getId()); if (bind == null) { LOGGER.warning("Case and process instance bind can not be found by process instance ID: " + executionContext.getProcessInstance().getId()); return;/*www. j ava 2 s. c o m*/ } Case theCase = getCaseBusiness().getCase(bind.getCaseId()); if (theCase == null) { return; } String processDefinitionName = executionContext.getProcessDefinition().getName(); String shipID = (String) executionContext.getVariable("string_vesselRegistryNr"); String ssn = (String) executionContext.getVariable("string_ownerSocialNumber"); String subType = null; BigDecimal fishingLicenseKey = null; // create license if ("Grasleppa".equals(processDefinitionName)) { subType = (String) executionContext.getVariable("string_typeOfFishingLicense"); Timestamp fromStamp = (Timestamp) executionContext.getVariable("date_startOfFishing"); Timestamp toStamp = (Timestamp) executionContext.getVariable("date_endOfFishing"); String areaID = (String) executionContext.getVariable("string_fishingAreaId"); IWTimestamp from = new IWTimestamp(fromStamp); IWTimestamp to = new IWTimestamp(toStamp); fishingLicenseKey = getWSClient().createFishingLicense(shipID, areaID, from, to, theCase.getPrimaryKey().toString()); theCase.setMetaData(GumboConstants.DOF_FISHING_LICENSE_METADATA_KEY, fishingLicenseKey.toString()); if (fishingLicenseKey.intValue() == -1) { throw new GumboProcessException("Error creating fishing license"); } } else if ("Strandveidileyfi".equals(processDefinitionName)) { CheckReplyTypeUser quotaCheck = getWSClient().getQuotaTransferCheckForShip(shipID); boolean isValid = quotaCheck.getIsok().intValue() > 0; if (!isValid) { throw new GumboProcessException("Error creating fishing license"); } Timestamp fromStamp = (Timestamp) executionContext.getVariable("date_startOfFishing"); String postalCode = (String) executionContext.getVariable("string_ownerPostCode"); String areaID = null; CodeTypeUser areaInfo = getWSClient().getFishingAreaStrandveidi(postalCode); if (areaInfo == null) { throw new GumboProcessException("Error creating fishing license"); } Map<BigDecimal, VeidileyfagerdTypeUser> areas = getWSClient().getStrandveidiAreas(); if (areas != null && !areas.isEmpty()) { for (Iterator iterator = areas.keySet().iterator(); iterator.hasNext();) { VeidileyfagerdTypeUser item = areas.get(iterator.next()); if (item.getKodiSvaedis().equals(areaInfo.getCode())) { areaID = item.getVlyfId().toString(); break; } } } if (areaID == null) { throw new GumboProcessException("Error creating fishing license"); } IWTimestamp from = new IWTimestamp(fromStamp); fishingLicenseKey = getWSClient().createFishingLicense(shipID, areaID, from, null, theCase.getPrimaryKey().toString()); theCase.setMetaData(GumboConstants.DOF_FISHING_LICENSE_METADATA_KEY, fishingLicenseKey.toString()); if (fishingLicenseKey.intValue() == -1) { throw new GumboProcessException("Error creating fishing license"); } } else if ("Draganotaveidi".equals(processDefinitionName)) { Timestamp fromStamp = (Timestamp) executionContext.getVariable("date_startOfFishing"); IWTimestamp from = new IWTimestamp(fromStamp); IWTimestamp to = new IWTimestamp(from); to.setMonth(8); to.setDay(31); if (to.isEarlierThan(from)) { to.addYears(1); } String areaID = null; CodeTypeUser areaInfo = getWSClient().getFishingAreaForDraganotaveidi(shipID); Map<BigDecimal, VeidileyfagerdTypeUser> areas = getWSClient().getDragnotaAreas(from.getDate()); if (areas != null && !areas.isEmpty()) { for (Iterator iterator = areas.keySet().iterator(); iterator.hasNext();) { VeidileyfagerdTypeUser item = areas.get(iterator.next()); if (item.getKodiSvaedis().equals(areaInfo.getCode())) { areaID = item.getVlyfId().toString(); break; } } } if (areaID == null) { throw new GumboProcessException("Error creating fishing license"); } fishingLicenseKey = getWSClient().createFishingLicense(shipID, areaID, from, to, theCase.getPrimaryKey().toString()); theCase.setMetaData(GumboConstants.DOF_FISHING_LICENSE_METADATA_KEY, fishingLicenseKey.toString()); if (fishingLicenseKey.intValue() == -1) { throw new GumboProcessException("Error creating fishing license"); } } else if ("FishingLicense".equals(processDefinitionName)) { subType = (String) executionContext.getVariable("string_typeOfFishingLicense"); Timestamp fromStamp = (Timestamp) executionContext.getVariable("date_startOfFishing"); IWTimestamp from = new IWTimestamp(fromStamp); IWTimestamp to = new IWTimestamp(from); to.setMonth(8); to.setDay(31); if (to.isEarlierThan(from)) { to.addYears(1); } String areaID = null; Map<BigDecimal, VeidileyfagerdTypeUser> areas = getWSClient() .getAlmennAreas(FishingLicenseType.valueOf(subType)); if (areas != null && !areas.isEmpty()) { VeidileyfagerdTypeUser item = areas.values().iterator().next(); areaID = item.getVlyfId().toString(); } if (areaID == null) { throw new GumboProcessException("Error creating fishing license"); } fishingLicenseKey = getWSClient().createFishingLicense(shipID, areaID, from, to, theCase.getPrimaryKey().toString()); theCase.setMetaData(GumboConstants.DOF_FISHING_LICENSE_METADATA_KEY, fishingLicenseKey.toString()); if (fishingLicenseKey.intValue() == -1) { throw new GumboProcessException("Error creating fishing license"); } } boolean send = IWMainApplication.getDefaultIWApplicationContext().getApplicationSettings() .getBoolean("dof_send_claim", true); if (!send) { return; } // Create claim String claimKey = (subType == null) ? getFJSWSClient().createLicenseFeeClaim(ssn, shipID, getGumboDAO().getProcessPaymentCode(processDefinitionName)) : getFJSWSClient().createLicenseFeeClaim(ssn, shipID, getGumboDAO().getProcessPaymentCode(processDefinitionName, subType)); // System.out.println("claimKey = " + claimKey); if (claimKey != null) { theCase.setMetaData(GumboConstants.FJS_CLAIM_NUMBER_METADATA_KEY, claimKey); } else { getWSClient().cancelFishingLicense(fishingLicenseKey); // throw some exception!!!! throw new GumboProcessException("Error registering the claim"); } }
From source file:com.glaf.core.jdbc.QueryHelper.java
@SuppressWarnings("unchecked") public int getTotal(Connection conn, SqlExecutor sqlExecutor) { int total = 0; PreparedStatement psmt = null; ResultSet rs = null;//ww w . j a va2 s . c o m try { psmt = conn.prepareStatement(sqlExecutor.getSql()); if (sqlExecutor.getParameter() != null) { List<Object> values = (List<Object>) sqlExecutor.getParameter(); JdbcUtils.fillStatement(psmt, values); } rs = psmt.executeQuery(); if (rs.next()) { Object object = rs.getObject(1); if (object instanceof Integer) { Integer iCount = (Integer) object; total = iCount.intValue(); } else if (object instanceof Long) { Long iCount = (Long) object; total = iCount.intValue(); } else if (object instanceof BigDecimal) { BigDecimal bg = (BigDecimal) object; total = bg.intValue(); } else if (object instanceof BigInteger) { BigInteger bi = (BigInteger) object; total = bi.intValue(); } else { String x = object.toString(); if (StringUtils.isNotEmpty(x)) { total = Integer.parseInt(x); } } } } catch (Exception ex) { logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(psmt); JdbcUtils.close(rs); } return total; }
From source file:com.glaf.core.jdbc.QueryHelper.java
@SuppressWarnings("unchecked") public int getTotal(Connection conn, String sql, Map<String, Object> paramMap) { if (!DBUtils.isLegalQuerySql(sql)) { throw new RuntimeException(" SQL statement illegal "); }//from w w w. j a v a2 s . co m int total = -1; PreparedStatement psmt = null; ResultSet rs = null; try { List<Object> values = null; if (paramMap != null) { SqlExecutor sqlExecutor = DBUtils.replaceSQL(sql, paramMap); sql = sqlExecutor.getSql(); values = (List<Object>) sqlExecutor.getParameter(); } sql = DBUtils.removeOrders(sql); logger.debug("sql:\n" + sql); logger.debug("values:" + values); psmt = conn.prepareStatement(sql); if (values != null && !values.isEmpty()) { JdbcUtils.fillStatement(psmt, values); } rs = psmt.executeQuery(); if (rs.next()) { Object object = rs.getObject(1); if (object != null) { if (object instanceof Integer) { Integer iCount = (Integer) object; total = iCount.intValue(); } else if (object instanceof Long) { Long iCount = (Long) object; total = iCount.intValue(); } else if (object instanceof BigDecimal) { BigDecimal bg = (BigDecimal) object; total = bg.intValue(); } else if (object instanceof BigInteger) { BigInteger bi = (BigInteger) object; total = bi.intValue(); } else { String x = object.toString(); if (StringUtils.isNotEmpty(x)) { total = Integer.parseInt(x); } } } } } catch (Exception ex) { logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(psmt); JdbcUtils.close(rs); } return total; }
From source file:org.kalypso.model.hydrology.internal.binding.cm.LinearSumGenerator.java
/** * @param catchmentFeatures//from ww w .j a v a2 s . c o m * The catchment features will be taken from the generator itself, so they are not needed here. Leave them <code>null</code>. */ @Override public IObservation[] createRainfall(final Feature[] catchmentFeatures, final IStringResolver variables, final ILog log, IProgressMonitor monitor) throws CoreException { /* Monitor. */ if (monitor == null) monitor = new NullProgressMonitor(); try { /* Get the date range. */ final DateRange dateRange = getPeriod(variables); /* Get the catchments. */ final List<ICatchment> catchments = getCatchments(); /* HINT: Keep in mind, that the results must match the order of the catchments array. */ final IObservation[] results = new IObservation[catchments.size()]; /* Monitor. */ monitor.beginTask(String.format(Messages.getString("LinearSumGenerator_0"), catchments.size()), //$NON-NLS-1$ catchments.size() * 200); monitor.subTask(Messages.getString("LinearSumGenerator_1")); //$NON-NLS-1$ /* A catchment with the already used hash needs not to be calculated anymore. */ /* Because the result timeseries would be the same. */ /* Also the link in the catchment to the result timeseries should be the same. */ final List<String> usedHashes = new ArrayList<>(); /* Generate one timeseries for each catchment. */ for (int i = 0; i < catchments.size(); i++) { /* Get the catchment. */ final ICatchment catchment = catchments.get(i); final Feature areaLink = catchment.getAreaLink(); final String description = areaLink.getDescription(); /* Generate the message 1. */ final String message1 = String.format(Messages.getString("LinearSumGenerator_2"), i + 1, //$NON-NLS-1$ description); /* Monitor. */ monitor.subTask(message1); /* Log. */ if (log != null) log.log(new Status(IStatus.INFO, ModelNA.PLUGIN_ID, message1)); /* Memory for the factors and the observations of the catchments. */ final List<Double> factors = new ArrayList<>(); final List<IObservation> observations = new ArrayList<>(); /* Build the hash. */ final String hash = CatchmentHelper.buildHash(catchment); /* Was the target timeseries already generated by a previous catchment with the same hash. */ if (!usedHashes.contains(hash)) { /* Get the factorized timeseries. */ for (final IFactorizedTimeseries factorizedTimeseries : catchment.getFactorizedTimeseries()) { /* Get the factor. */ final BigDecimal factor = factorizedTimeseries.getFactor(); /* Get the timeseries link. */ final GMLXPath linkPath = new GMLXPath(IFactorizedTimeseries.PROPERTY_TIMESERIES_LINK); /* Get the filters from the gml. */ final IZmlFilter[] filters = getFilters().toArray(new IZmlFilter[] {}); /* Load the observation. */ final IObservation observation = readObservation(factorizedTimeseries, linkPath, filters, dateRange); /* If the factor is valid, add the factor and its observation. */ if (factor != null && factor.intValue() > 0 && factor.intValue() <= 100) { factors.add(new Double(factor.doubleValue() / 100)); observations.add(observation); } } /* Store the hash. */ usedHashes.add(hash); } /* Generate the message 2. */ final String message2 = String.format(Messages.getString("LinearSumGenerator_3"), i + 1, //$NON-NLS-1$ description, factors.size()); /* Monitor. */ monitor.worked(100); monitor.subTask(message2); /* Log. */ if (log != null) log.log(new Status(IStatus.INFO, ModelNA.PLUGIN_ID, message2)); /* Set the resulting observation for this catchment. */ final double[] factorDoubles = ArrayUtils.toPrimitive(factors.toArray(new Double[] {})); results[i] = RainfallGeneratorUtilities.combineObses(observations.toArray(new IObservation[] {}), factorDoubles, "catchmentGenerator://linearSum"); //$NON-NLS-1$ /* Monitor. */ monitor.worked(100); } return results; } catch (final Exception ex) { /* Create the error status. */ final IStatus status = new Status(IStatus.ERROR, ModelNA.PLUGIN_ID, ex.getLocalizedMessage(), ex); /* If there is a log, log to it. */ if (log != null) log.log(status); throw new CoreException(status); } finally { /* Monitor. */ monitor.done(); } }