List of usage examples for org.springframework.util StopWatch StopWatch
public StopWatch()
From source file:no.abmu.abmstatistikk.web.AbstractReportController.java
protected ModelAndView basicReportDataByMuncipality(HttpServletRequest request, OrgUnitFinderSpecificationBean finderBean, SchemaTypeNameAndVersion schemaTypeNameAndVersion, String viewName) {/*from w w w . j av a 2s . c o m*/ Assert.checkRequiredArgument("request", request); Assert.checkRequiredArgument("finderBean", finderBean); Assert.checkRequiredArgument("schemaTypeNameAndVersion", schemaTypeNameAndVersion); Assert.checkRequiredArgument("viewName", viewName); if (logger.isDebugEnabled()) { logger.debug("Executing: reportDataByMuncipality"); } /* * This should be replaced with AOP in an XML spring config-file. */ if (!isSecureContext()) { logger.error("[reportDataByMuncipality]: no secureContext loging off"); return new ModelAndView(ViewNameConst.LOGOFF_VIEW); } Integer municipalityNumber = getMuncipalityNumberFromRequestOrLoggedOnUser(request); if (null == municipalityNumber) { logger.error("[reportDataByMuncipality]: could not get any municipality number, return to mainmenu."); return new ModelAndView(ViewNameConst.REDIRECT_2_MAIN_MENU); } StopWatch stopWatch = new StopWatch(); stopWatch.start("private_createByMuncipalityReportData"); finderBean.setMuncipalityNumber(municipalityNumber); SchemaList jasperReportDataSource = reportService.createBasicReportData(finderBean, schemaTypeNameAndVersion); Map<String, Object> model = getModel(jasperReportDataSource); model.put("abmstatistikk.reportPeriod", schemaTypeNameAndVersion.getVersion()); ModelAndView mav = new ModelAndView(viewName, model); stopWatch.stop(); logger.info("[private:createByMuncipalityReportData] tok[" + stopWatch.getTotalTimeMillis() + "] ms"); return mav; }
From source file:no.abmu.common.jasperreports.JasperReportsXlsViewToFile.java
/** * Perform rendering for a single Jasper Reports exporter, that is, * for a pre-defined output format.// w w w .ja va2 s .c o m */ protected void renderReport(JasperPrint populatedReport, Map model, HttpServletResponse response) throws Exception { log.info(" XXXXXXXXXXXXXXXXXXX renderReport: START "); StopWatch stopWatch = new StopWatch(); stopWatch.start("renderReport"); // Prepare report for rendering. JRExporter exporter = createExporter(); if (getConvertedExporterParameters() != null) { exporter.setParameters(getConvertedExporterParameters()); } // We need to write binary output to the response OutputStream. // Render report into local OutputStream. // IE workaround: write into byte array first. ByteArrayOutputStream baos = new ByteArrayOutputStream(OUTPUT_BYTE_ARRAY_INITIAL_SIZE); JasperReportsUtils.render(exporter, populatedReport, baos); // Flush byte array to servlet output stream. java.io.FileOutputStream fileOutputStream = new FileOutputStream(getOutPutFileName()); baos.writeTo(fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); stopWatch.stop(); log.info("[private:renderReport] tok[" + stopWatch.getTotalTimeMillis() + "] ms"); log.info(" XXXXXXXXXXXXXXXXXXX renderReport: FINISH "); }
From source file:no.abmu.finances.service.hibernate3.FinanceServiceHelperH3Impl.java
public ReportStatus[] getReportStatusBySchemaTypeAndVersion( List<OrganisationUnitForBrowsing> orgUnitsForBrodwsing, String schemaTypeName, String version) { StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from w w w . j a v a2 s . c om*/ String finishFieldNumber = getFinishFieldNumberForSchemaTypeAndVersion(schemaTypeName, version); List<ReportStatus> reportStatusAsList = new ArrayList<ReportStatus>(); for (OrganisationUnitForBrowsing orgForBrowse : orgUnitsForBrodwsing) { ReportDataH3FinderSpecification finderSpecification = new ReportDataH3FinderSpecification( schemaTypeName, version, orgForBrowse.getOrganisationUnitId()); MainReportData reportData = (MainReportData) financeService.findSingle(finderSpecification); reportStatusAsList.add(createReportStatus(orgForBrowse, reportData, finishFieldNumber)); } stopWatch.stop(); logger.info("Finish prosessing of reportStatus for schemaType:" + schemaTypeName + " with " + orgUnitsForBrodwsing.size() + " elements in " + stopWatch.getTotalTimeMillis() + " ms"); return reportStatusAsList.toArray(new ReportStatus[reportStatusAsList.size()]); }
From source file:no.abmu.lise.service.AbstractLiseImportService.java
private boolean checkOrganisationUnits(OrganisationRegisterBaseService baseService, ExcelParser excelParser, Map<String, String> excelColumnNames, boolean printWarningMessage) { StopWatch stopWatch = new StopWatch(); stopWatch.start();// w w w .j a va 2 s.c o m int rowsWithOutMatch = 0; int numOfRowsWithData = excelParser.countNumberOfRowsInSheetBeforeStopTag(); // Get organisationUnit column name String organisationUnitExcelColumnName = excelColumnNames .get(DataLoaderUtils.KEY_ORGANISATIONUNIT_NAME_EXCEL_COLUMN); // First get a unique set of organisationUnit names Set<String> organisationUnitNames = new LinkedHashSet<String>(); Set<String> foundOrganisationUnitNames = new LinkedHashSet<String>(); Set<String> notFoundOrganisationUnitNames = new LinkedHashSet<String>(); excelParser.load(); for (; excelParser.hasNext(); excelParser.next()) { String orgUnitName = excelParser.getCellValueAsString(organisationUnitExcelColumnName); organisationUnitNames.add(orgUnitName); OrganisationUnit organisationUnit = DataLoaderUtils.checkForAndGetOneAndOnlyOneOrganisationUnit( excelParser, baseService, excelColumnNames, printWarningMessage); if (organisationUnit != null) { foundOrganisationUnitNames.add(orgUnitName); } else { notFoundOrganisationUnitNames.add(orgUnitName); rowsWithOutMatch++; } } // Report result in log. String resultToLog = "The processed excel sheet had " + numOfRowsWithData + " rows with " + organisationUnitNames.size() + " distinkt organisationUnitNames, of which " + foundOrganisationUnitNames.size() + " have exact match, and " + notFoundOrganisationUnitNames.size() + " do not have exact match. We have " + rowsWithOutMatch + " rows without match."; logger.info(resultToLog); // System.out.println(resultToLog); stopWatch.stop(); String timeMessage = "Testing for organisationUnit matches tok " + stopWatch.getTotalTimeMillis() + " ms."; logger.info(timeMessage); // System.out.println(timeMessage); return (rowsWithOutMatch == 0); }
From source file:no.abmu.lise.service.hibernate3.LiseImportServiceH3Impl.java
private void processSheetOne(Session session, LiseImportExcelParser excelParser) { List<Entity> entityStorList = new ArrayList<Entity>(); Consortium currentConsortium = null; Product currentProduct = null;//from ww w.j a v a 2 s . c o m String currentProductName = null; int productSaved = 0; int productCustomerRelationSaved = 0; int productCustomerRelationNotSaved = 0; int linkToCustomerContactPerson = 0; int linkToSupplierContactPerson = 0; int missingLinkToCustomerContactPerson = 0; int missingLinkToSupplierContactPerson = 0; int numberOfCustomerProductComment = 0; excelParser.setSheetName("Sheet1"); excelParser.load(); Date creationTime = new Date(); StopWatch stopWatch = new StopWatch(); stopWatch.start("processSheetOne"); logger.debug("Starting building the Domain model:"); for (; excelParser.hasNext(); excelParser.next()) { Consortium consortiumInLine = createConsortium(excelParser); Assert.assertNotNull("consortiumInLine", consortiumInLine); if (!consortiumInLine.equals(currentConsortium)) { // New current consortium currentConsortium = consortiumInLine; String logMessage = "Row " + excelParser.getCurrentRowNumber() + " in " + excelParser.getSheetName() + " new consortium ==> " + currentConsortium.getConsortiumName(); logger.info(logMessage); // Get supplier Map<String, String> supplierExcelColumnMap = excelParser.getConsortiumSupplierOrgUnitColumns(); OrganisationUnit supplier = getOrganisationUnit(session, excelParser, supplierExcelColumnMap); if (supplier != null) { currentConsortium.setSupplier(supplier); } else { String warningMessage = "Row " + excelParser.getCurrentRowNumber() + " in " + excelParser.getSheetName() + " did not find supplier ==> " + excelParser.getSupplierName(); logger.warn(warningMessage); } // Get supplier contact person String supContactPersonName = excelParser.getConsortiumSupplierContactPerson(); ExtendedContactPerson supplierContactPerson = findContactPerson(session, supContactPersonName); if (supplierContactPerson != null) { currentConsortium.setSupplierContactPerson(supplierContactPerson); linkToSupplierContactPerson++; } else { String warningMessage = "Row " + excelParser.getCurrentRowNumber() + " in " + excelParser.getSheetName() + " no supplier contact person ==> " + supContactPersonName; logger.warn(warningMessage); missingLinkToSupplierContactPerson++; } // Get abmu administrator contact person String abmuContactPersonName = excelParser.getConsortiumAbmuContactPerson(); ExtendedContactPerson abmuContactPerson = findContactPerson(session, abmuContactPersonName); if (abmuContactPerson != null) { currentConsortium.setAbmuContactPerson(abmuContactPerson); } else { String warningMessage = "Row " + excelParser.getCurrentRowNumber() + " in " + excelParser.getSheetName() + " no ABMU contact person ==> " + abmuContactPersonName; logger.warn(warningMessage); } entityStorList.add(currentConsortium); } Product productInLine = createProduct(excelParser); Assert.assertNotNull("productInLine", productInLine); Assert.assertNotNull("productInLine.getProductName()", productInLine.getProductName()); if (!productInLine.getProductName().equals(currentProductName)) { // New current product currentProduct = productInLine; currentProductName = currentProduct.getProductName(); String logMessage = "Row " + excelParser.getCurrentRowNumber() + " in " + excelParser.getSheetName() + " new product ==> " + currentProduct.getProductName(); logger.info(logMessage); currentConsortium.addProduct(currentProduct); productSaved++; } // Get customer Map<String, String> customerExcelColumnMap = excelParser.getRelationCustomerProductOrgUnitColumns(); OrganisationUnit customer = getOrganisationUnit(session, excelParser, customerExcelColumnMap); if (customer != null) { ProductCustomerRelation productCustomerRelation = new ProductCustomerRelation(currentProduct, customer); // Get customer contact person String contactPersonName = excelParser.getRcpContactPerson(); ExtendedContactPerson customerContactPerson = findContactPerson(session, contactPersonName); if (customerContactPerson != null) { productCustomerRelation.setCustomerContactPerson(customerContactPerson); linkToCustomerContactPerson++; } else { String warningMessage = "Row " + excelParser.getCurrentRowNumber() + " in " + excelParser.getSheetName() + "] no customer contact person ==> " + contactPersonName; logger.warn(warningMessage); missingLinkToCustomerContactPerson++; } currentProduct.addProductCustomerRelations(productCustomerRelation); productCustomerRelationSaved++; LiseComment customerProductComment = getCustomerProductComment(excelParser); if (customerProductComment != null) { customerProductComment.setCreated(creationTime); customerProductComment.setLastUpdated(creationTime); productCustomerRelation.addLiseComment(customerProductComment); numberOfCustomerProductComment++; } } else { String warnMessage = "Row " + excelParser.getCurrentRowNumber() + " in " + excelParser.getSheetName() + " no customer with name (" + excelParser.getSupplierName() + ")."; logger.warn(warnMessage); productCustomerRelationNotSaved++; } } creationTime = new Date(); // // Save // Hibernate3Util.saveEntities(session, entityStorList); stopWatch.stop(); logger.info(" ============================================================================= "); logger.info("Saved [" + entityStorList.size() + "] consortium."); logger.info("Saved [" + productSaved + "] products."); logger.info("Saved [" + productCustomerRelationSaved + "] productCustomerRelations."); logger.info("Saved [" + linkToSupplierContactPerson + "] link to supplier contactPerson."); logger.info("Saved [" + linkToCustomerContactPerson + "] link to customer contactPerson."); logger.info("Saved [" + numberOfCustomerProductComment + "] customer product comments."); logger.info("Missing [" + productCustomerRelationNotSaved + "] productCustomerRelations."); logger.info("Missing [" + missingLinkToSupplierContactPerson + "] link to supplier contactPerson."); logger.info("Missing [" + missingLinkToCustomerContactPerson + "] link to customer contactPerson."); logger.info("TransactionTime [" + stopWatch.getLastTaskTimeMillis() + "] in ms."); logger.info(" ============================================================================= "); }
From source file:no.abmu.lise.service.hibernate3.LiseImportServiceH3Impl.java
private void precessSheetTwo(Session session, LiseImportExcelParser excelParser) { List<Entity> entityStorList = new ArrayList<Entity>(); int noConsortium = 0; int noInvoiceNumber = 0; excelParser.setSheetName("Sheet2"); excelParser.load();//w ww .j a v a 2s . c o m Date creationTime = new Date(); StopWatch stopWatch = new StopWatch(); stopWatch.start("precessSheetTwo"); logger.debug("Starting building the Domain model:"); for (; excelParser.hasNext(); excelParser.next()) { Consortium consortiumFromDb = findConsortiumInDb(excelParser); if (consortiumFromDb != null) { Consortium consortiumInSession = (Consortium) session.get(Consortium.class, consortiumFromDb.getId()); String logMessage = "Row " + excelParser.getCurrentRowNumber() + " in " + excelParser.getSheetName() + " prosessing consortium ==> " + consortiumInSession.getConsortiumName(); logger.info(logMessage); PaymentToSupplier paymentToSupplier = createPaymentToSupplier(excelParser); if (paymentToSupplier.getLiseComment() != null) { paymentToSupplier.getLiseComment().setCreated(creationTime); paymentToSupplier.getLiseComment().setLastUpdated(creationTime); } if (StringUtil.isEmpty(paymentToSupplier.getInvoiceNumber())) { noInvoiceNumber++; String errorMessage = "Row " + excelParser.getCurrentRowNumber() + " no invoice number for consortium " + consortiumInSession.getConsortiumName(); logger.error(errorMessage); paymentToSupplier.setInvoiceNumber("DUMMY"); } consortiumInSession.addPaymentToSupplier(paymentToSupplier); entityStorList.add(consortiumInSession); } else { noConsortium++; } } creationTime = new Date(); // // Save // Hibernate3Util.saveEntities(session, entityStorList); stopWatch.stop(); logger.info(" ============================================================================= "); logger.info("Saving [" + entityStorList.size() + "] consortium with payment to supplier infomation."); logger.info("Payment to supplier with wissing [" + noInvoiceNumber + "] invoice number."); logger.info("Missing [" + noConsortium + "] consortium with payment to supplier infomation."); logger.info("TransactionTime [" + stopWatch.getLastTaskTimeMillis() + "] in ms."); logger.info(" ============================================================================= "); }
From source file:no.abmu.lise.service.hibernate3.LiseImportServiceH3Impl.java
private void processSheetThree(Session session, LiseImportExcelParser excelParser) { List<Entity> entityStorList = new ArrayList<Entity>(); int noProductCustomerRelation = 0; excelParser.setSheetName("Sheet3"); excelParser.load();//www . j a v a 2s . c om Date creationTime = new Date(); StopWatch stopWatch = new StopWatch(); stopWatch.start("processSheetThree"); for (; excelParser.hasNext(); excelParser.next()) { ProductCustomerRelation productCustomerFromDb = findProductCustomerRelInDb(excelParser); if (productCustomerFromDb != null) { ProductCustomerRelation productCustomerRelInSession = (ProductCustomerRelation) session .get(ProductCustomerRelation.class, productCustomerFromDb.getId()); InvoiceToCustomer invoiceToCustomer = createInvoiceToCustomer(excelParser); // Make sure we have currency on all invoices to customer if (invoiceToCustomer.getCurrency() == null) { Product product = productCustomerRelInSession.getProduct(); Consortium consortium = product.getConsortium(); invoiceToCustomer.setCurrency(consortium.getCurrency()); } // Setting up percentage currency buffer if (invoiceToCustomer.getCurrency().equals(Currency.getInstance("NOK"))) { invoiceToCustomer.setPercentageCurrencyBuffer(BigDecimal.valueOf(0)); } else { invoiceToCustomer.setPercentageCurrencyBuffer(BigDecimal.valueOf(1.75)); } // Be sure there are original amount if (invoiceToCustomer.getOriginalAmount() == null) { invoiceToCustomer.setOriginalAmount(BigDecimal.valueOf(0)); } if (invoiceToCustomer.getLiseComment() != null) { invoiceToCustomer.getLiseComment().setCreated(creationTime); invoiceToCustomer.getLiseComment().setLastUpdated(creationTime); } productCustomerRelInSession.addInvoicesToCustomer(invoiceToCustomer); entityStorList.add(productCustomerRelInSession); } else { noProductCustomerRelation++; } } creationTime = new Date(); // // Save // Hibernate3Util.saveEntities(session, entityStorList); stopWatch.stop(); logger.info(" ============================================================================= "); logger.info("Saving [" + entityStorList.size() + "] product customer relations with invoice information."); logger.info( "Missing [" + noProductCustomerRelation + "] product customer relations with invoice information."); logger.info("TransactionTime [" + stopWatch.getLastTaskTimeMillis() + "] in ms."); logger.info(" ============================================================================= "); }
From source file:no.abmu.lise.util.LiseImportExcelParser.java
/** * Check for necessary input values.//from ww w . ja v a2s.c o m * * Returns null if OK, else error message with description of missing * input values. * * @return - errorMessage equals Null if OK, else description of * missing input values. */ public String checkInputValues() { logger.info("Start testing for nessesary input values ..."); StopWatch stopWatch = new StopWatch(); stopWatch.start(); String[] notNullNamesSheet1 = { SUPPLIER_NAME, CONSORTIUM_NAME, C_AGREEMENT_START_DATE, PRODUCT_NAME, // P_DESCRIPTION, C_CURRENCY, RelationCustomerProduct_NAME }; String[] notNullNamesSheet2 = { CONSORTIUM_NAME, C_AGREEMENT_START_DATE, SP_PAYMENT_YEAR, SP_PAYMENT_CURRENCY, SP_PAYMENT_AMOUNT }; String[] notNullNamesSheet3 = { PRODUCT_NAME, CUSTOMER_NAME, CUSTOMERPAYMENT_INVOICE_YEAR }; StringBuffer resBuffer = new StringBuffer(); checkSheetForNotNullNames("Sheet1", notNullNamesSheet1, resBuffer); checkSheetForNotNullNames("Sheet2", notNullNamesSheet2, resBuffer); checkSheetForNotNullNames("Sheet3", notNullNamesSheet3, resBuffer); String errorMessage = resBuffer.toString(); if (StringUtil.notEmpty(errorMessage)) { logger.error(errorMessage); } else { logger.info("All nessesary input values were present ..."); } stopWatch.stop(); logger.info("Testing nessesary input values took " + stopWatch.getTotalTimeMillis() + " ms."); return errorMessage; }
From source file:no.abmu.lise.util.LiseImportExcelParser.java
public boolean checkExistenceOfOrganisations() { logger.info("Executing checkExistenceOfOrganisations"); boolean missingOrganisations = false; Set<String> organisationNames = new HashSet<String>(); StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from ww w .j av a2 s. c o m*/ load(); for (; hasNext(); next()) { String name = getRelationCustomerProductname(); if (!organisationNames.contains(name)) { organisationNames.add(name); } String supplierName = getSupplierName(); if (!organisationNames.contains(supplierName)) { organisationNames.add(supplierName); } } setSheetName("Sheet3"); load(); for (; hasNext(); next()) { String name = getCustomerName(); if (!organisationNames.contains(name)) { organisationNames.add(name); } } logger.info("Found a total of (" + organisationNames.size() + ") organisationunits in the excel file ..."); StopWatch stopWatchGetOrgunits = new StopWatch(); stopWatchGetOrgunits.start(); Object[] allOrganisations = baseService.findAll(no.abmu.organisationregister.domain.OrganisationUnit.class); stopWatchGetOrgunits.stop(); logger.info("Getting '" + allOrganisations.length + "' OrganisationUnits from db took '" + stopWatchGetOrgunits.getTotalTimeMillis() + "' ms."); for (int i = 0; i < allOrganisations.length; i++) { OrganisationUnit organisationUnit = (OrganisationUnit) allOrganisations[i]; String name = organisationUnit.getName().getReference(); if (!organisationNames.contains(name)) { logger.error("NO OrganisationUnit is registered for (" + name + ") this should be registered !"); missingOrganisations = true; } } stopWatch.stop(); logger.info("Testing for existence of organisations took " + stopWatch.getTotalTimeMillis() + " ms."); return missingOrganisations; }
From source file:no.abmu.organisationregister.service.AbstractOrganisationUnitImportService.java
private boolean checkOrganisationUnits(ExcelParser excelParser, Map<String, String> excelColumnNames, boolean printWarningMessage) { StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from w w w .j a v a2s . c om*/ int rowsWithOutMatch = 0; int numOfRowsWithData = excelParser.countNumberOfRowsInSheetBeforeStopTag(); // Get organisationUnit column name String organisationUnitExcelColumnName = excelColumnNames .get(DataLoaderUtils.KEY_ORGANISATIONUNIT_NAME_EXCEL_COLUMN); // First get a unique set of organisationUnit names Set<String> organisationUnitNames = new LinkedHashSet<String>(); Set<String> foundOrganisationUnitNames = new LinkedHashSet<String>(); Set<String> notFoundOrganisationUnitNames = new LinkedHashSet<String>(); excelParser.load(); for (; excelParser.hasNext(); excelParser.next()) { String orgUnitName = excelParser.getCellValueAsString(organisationUnitExcelColumnName); organisationUnitNames.add(orgUnitName); OrganisationUnit organisationUnit = DataLoaderUtils.checkForAndGetOneAndOnlyOneOrganisationUnit( excelParser, baseService, excelColumnNames, printWarningMessage); if (organisationUnit != null) { foundOrganisationUnitNames.add(orgUnitName); } else { notFoundOrganisationUnitNames.add(orgUnitName); rowsWithOutMatch++; } } // Report result in log. logger.info( "The processed excel sheet had " + numOfRowsWithData + " rows with " + organisationUnitNames.size() + " distinkt organisationUnitNames, of which " + foundOrganisationUnitNames.size() + " have exact match, and " + notFoundOrganisationUnitNames.size() + " do not have exact match. We have " + rowsWithOutMatch + " rows without match."); stopWatch.stop(); logger.info("Testing for organisationUnit matches tok " + stopWatch.getTotalTimeMillis() + " ms."); return (rowsWithOutMatch == 0); }