List of usage examples for org.springframework.util StopWatch stop
public void stop() throws IllegalStateException
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;/* ww w.j a va 2s . co 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();/*from w ww .ja v a2s.com*/ 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();//from ww w.ja va 2s . co m 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.// w w w .ja va 2 s . 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();/* w w w . j a v a 2 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();//w w w. j a va2 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. 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); }
From source file:no.abmu.organisationregister.service.hibernate3.OrganisationUnitServiceH3Impl.java
public SchemaList getReportData(OrgUnitFinderSpecificationBean finderBean) { SchemaList schemaList = new SchemaList(); StopWatch stopWatch = new StopWatch("getReportData"); stopWatch.start("Sok i DB"); OrgUnitReportFinderSpecification reportFinder = new OrgUnitReportFinderSpecification(finderBean); List<OrgUnitReportData> resultList = (List<OrgUnitReportData>) find(reportFinder); for (OrgUnitReportData orgUnitReportData : resultList) { Map<String, Object> reportDataMap = orgUnitReportData.getReportData(); schemaList.add(reportDataMap);//from ww w. ja v a 2 s .co m } Comparator comparator = new SortingFieldSchemaComparator("countyNumberAndNameSortingField"); schemaList.setComparator(comparator); schemaList.sort(); stopWatch.stop(); logger.info("Creating reportData new method tok " + stopWatch.getTotalTimeMillis() + " milliseconds and returned " + resultList.size() + " elements " + " and schemaList has " + schemaList.size() + " elements"); return schemaList; }
From source file:no.abmu.organisationregister.service.hibernate3.OrganisationUnitServiceH3Impl.java
private SchemaList reportDataForOrganisationUnits(OrganisationUnit[] organisationUnits) { SchemaList reportData = new SchemaList(); StopWatch stopWatch = new StopWatch("reportDataForOrganisationUnits"); stopWatch.start("Sok i DB"); OrganisationUnit organisationUnit;/* w w w.ja v a 2 s . c o m*/ for (int i = 0; i < organisationUnits.length; i++) { organisationUnit = organisationUnits[i]; reportData.add(reportDataForOrganisationUnit(organisationUnit)); } stopWatch.stop(); logger.info("Creating reportData old method tok " + stopWatch.getTotalTimeMillis() + " milliseconds and number of OrgUnits input " + organisationUnits.length + " elements " + " and schemaList has " + reportData.size() + " elements"); return reportData; }
From source file:no.abmu.organisationregister.util.OrganisationUnitImportExcelParser.java
/** * Check for necessary input values./* w ww . j a va 2s .c om*/ * * 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[] notNullNames = { ORG_TYPE, NAVN_BOKMAL }; // {ORG_TYPE, NAVN_BOKMAL, ADRESSE_POST, POSTNR, POST_STED}; String errorMessage = checkInputValues(notNullNames); if (errorMessage != null) { logger.error(errorMessage); } else { logger.info("All nessesary input values were present ..."); } stopWatch.stop(); logger.info("Testing nessesary input values tok " + stopWatch.getTotalTimeMillis() + " ms."); return errorMessage; }
From source file:no.abmu.organisationregister.util.OrganisationUnitImportExcelParser.java
public int organisationUnitDuplicationCount() { logger.info("Executing organisationUnitDuplicationCount"); int duplicationCount = 0; StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w w w.ja v a 2 s . c o m load(); for (; hasNext(); next()) { String organisationUnitName = getCellValueAsString("NAME BOKMAL"); Set<OrganisationUnit> orgUnits = DataLoaderUtils.findOrganisationUnitByName(baseService, organisationUnitName); if (orgUnits.size() > 0) { String warningMessage = "On row " + +getCurrentRowIdx() + " " + orgUnits.size() + " organisationUnits has the name: '" + organisationUnitName + "'."; logger.warn(warningMessage); duplicationCount++; } } if (duplicationCount > 0) { logger.error(duplicationCount + " dublication found to bad ... "); } else { logger.info("No duplication found, good."); } stopWatch.stop(); logger.info("Testing for dublication tok " + stopWatch.getTotalTimeMillis() + " ms."); return duplicationCount; }