Example usage for org.springframework.util StopWatch start

List of usage examples for org.springframework.util StopWatch start

Introduction

In this page you can find the example usage for org.springframework.util StopWatch start.

Prototype

public void start(String taskName) throws IllegalStateException 

Source Link

Document

Start a named task.

Usage

From source file:no.abmu.abmstatistikk.annualstatistic.webflow.HighSchoolLibraryValidator.java

public void validateAndSave(Object obj, Errors errors) {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing validateAndSave");
    }/*from  ww w  . ja  v a 2  s.c o m*/

    StopWatch stopWatch = new StopWatch();
    stopWatch.start("validateAndSave");

    SchemaReport schemaReport = webFlowService.webSchemaValuesToDataBaseSchema(this, (WebSchemaDefinition) obj);

    FolkeBibScreen folkeBibScreen = new FolkeBibScreen(schemaReport.getReport());

    super.validate(folkeBibScreen, errors); // Has to be super or else endless loop.
    webFlowService.saveDataBaseSchemaIfNoError(folkeBibScreen, errors);

    stopWatch.stop();
    logger.info("[validateAndSave] tok [" + stopWatch.getTotalTimeMillis() + "] ms");

}

From source file:no.abmu.abmstatistikk.web.ABMStatistikkCommentReportController.java

/**
 * Custom handler handleCommentReportPrimarySchoolExcelFile.
 * // w w  w .  java2  s.c o  m
 * @param request current HTTP request
 * @param response current HTTP response
 * @return a ModelAndView to render the response
 * @throws ServletException
 */
public ModelAndView handleCommentReportPrimarySchoolExcelFile(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    logger.info(" XXXXXXXXXXXXXXXXXXX createMAVOrganisationTypeAndSchemaToFile: START ");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start("handleCommentReportPrimarySchoolExcelFile");

    // OrganisationType
    String organisationType = OrganisationTypeNameConst.PRIMARY_SCHOOL_LIBRARY;

    // Schema
    SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion
            .newInstance(SchemaName.PRIMARY_SCHOOL_LIBRARY_STATISTIC, STATISTICAL_YEAR);

    // View
    String viewName = "grunnskoleBibCommentsReportXlsViewToFile";

    ModelAndView mav = commentReportData(organisationType, schemaTypeNameAndVersion, viewName);

    stopWatch.stop();
    logger.info("[private:handleCommentReportPrimarySchoolExcelFile] tok [" + stopWatch.getTotalTimeMillis()
            + "] ms");
    logger.info(" XXXXXXXXXXXXXXXXXXX handleCommentReportPrimarySchoolExcelFile: STOP ");

    return mav;
}

From source file:no.abmu.abmstatistikk.web.ABMStatistikkCommentReportController.java

/**
 * Custom handler handleCommentReportHighSchoolLibrariesExcelFile.
 * /* w w  w .j  a v a  2s  .co m*/
 * @param request current HTTP request
 * @param response current HTTP response
 * @return a ModelAndView to render the response
 * @throws ServletException
 */
public ModelAndView handleCommentReportHighSchoolLibrariesExcelFile(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    logger.info(" XXXXXXXXXXXXXXXXXXX handleCommentReportHighSchoolLibrariesExcelFile: START ");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start("handleCommentReportHighSchoolLibrariesExcelFile");

    // OrganisationType
    String organisationType = OrganisationTypeNameConst.HIGH_SCHOOL_LIBRARY;

    // Schema
    SchemaTypeNameAndVersion schemaTypeNameAndVersion = SchemaTypeNameAndVersion
            .newInstance(SchemaName.HIGH_SCHOOL_LIBRARY_STATISTIC, STATISTICAL_YEAR);

    // View
    String viewName = "vgsBibCommentsReportXlsViewToFile";
    ModelAndView mav = commentReportData(organisationType, schemaTypeNameAndVersion, viewName);

    stopWatch.stop();
    logger.info("[private:handleCommentReportHighSchoolLibrariesExcelFile] tok ["
            + stopWatch.getTotalTimeMillis() + "] ms");
    logger.info(" XXXXXXXXXXXXXXXXXXX handleCommentReportHighSchoolLibrariesExcelFile: FINISH ");

    return mav;
}

From source file:no.abmu.abmstatistikk.web.AbstractOrganisationBrowsingController.java

/**
 * Browse by county./*from  w  w w .ja v  a  2s.c  o m*/
 *  
 * @param request current HTTP request
 * @param attribute in current HttpSession
 * @param organisationTypeName name on organisationType to browse
 * @param viewName name of the View to render, to be resolved
 * by the DispatcherServlet's ViewResolver
 * @return ModelAndView holder for both Model and View in 
 * the web MVC framework to be resolved by a DispatcherServlet.
 */
protected ModelAndView browseOrgTypeByCounty(HttpServletRequest request, String attribute,
        String organisationTypeName, String viewName) {

    /*
     * This should be replaced with AOP in an XML spring config-file.
     */
    if (!isSecureContext()) {
        logger.error("[browseOrgTypeByCounty]: no securityService, logg off.");
        return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
    }

    StopWatch stopWatch = new StopWatch("browseOrgType");
    stopWatch.start("Mav_for_browsing_organisationType_by_county");

    Integer countynumber = getCountyNumberFromRequestOrLoggedOnUser(request);
    if (null == countynumber || countynumber.intValue() == 0) {
        logger.error("[browseOrgTypeByCounty]: no countynumber");
        return new ModelAndView(ViewNameConst.REDIRECT_2_MAIN_MENU);
    }

    OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean();
    finderBean.setOrganisationTypeName(organisationTypeName);
    finderBean.setCountyNumber(countynumber);
    finderBean.setTodayAsActiveDate();

    ModelAndView mav = browse(request, attribute, finderBean, viewName);

    stopWatch.stop();
    logger.info("Getting ModelAndview for organisationType  " + organisationTypeName + " for county "
            + countynumber + " tok " + stopWatch.getTotalTimeMillis() + " milliseconds.");

    return mav;
}

From source file:no.abmu.abmstatistikk.web.AbstractReportController.java

protected ModelAndView createMAVForOrganisationUnit(HttpServletRequest request, String view,
        SchemaTypeNameAndVersion schemaTypeNameAndVersion) {

    Assert.checkRequiredArgument("request", request);
    Assert.checkRequiredArgument("view", view);
    Assert.checkRequiredArgument("schemaTypeAndName", schemaTypeNameAndVersion);

    StopWatch stopWatch = new StopWatch();
    stopWatch.start("private_createMAVForOrganisationUnit");

    if (noLoggedOnStatusInfo(request)) {
        logger.error("No loggedOnStatus exists, logout.");
        return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
    }/*  w  ww. j av  a 2  s.co  m*/

    Long workingSchemaOrgUnitId = changeWorkingSchemaOrgUnitIdOrGetCurrent(request);
    if (workingSchemaOrgUnitId == null) {
        logger.error("No workingSchemaOrgUnitId or LoggedOnOrgUnitId exists, log off");
        return new ModelAndView(ViewNameConst.LOGOFF_VIEW);

    }

    //        String schemaVersion = Integer.toString(reportPeriod);
    OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean();
    finderBean.setOrganisationUnitId(workingSchemaOrgUnitId);

    SchemaList jasperReportDataSource = reportService.createFullReportData(finderBean,
            schemaTypeNameAndVersion);

    if (schemaTypeNameAndVersion.getYear() >= 2009
            && schemaTypeNameAndVersion.getSchemaName().equals(SchemaName.KUD_CULTURAL_ACTIVITY_REPORT)) {
        int reportPeriod = schemaTypeNameAndVersion.getYear();

        int oneYearBack = reportPeriod - 1;
        String prefixOneYearBack = "LastYear";
        SchemaTypeNameAndVersion kudActivitySchemaAndVersionOneYearBack = SchemaTypeNameAndVersion
                .newInstance(SchemaName.KUD_CULTURAL_ACTIVITY_REPORT, oneYearBack);

        reportService.getReportDataForOrganisationUnits(jasperReportDataSource,
                kudActivitySchemaAndVersionOneYearBack, prefixOneYearBack);

        int twoYearBack = reportPeriod - 2;
        String prefixTwoYearBack = "YearBeforeLastYear";
        SchemaTypeNameAndVersion kudActivitySchemaAndVersionTwoYearBack = SchemaTypeNameAndVersion
                .newInstance(SchemaName.KUD_CULTURAL_ACTIVITY_REPORT, twoYearBack);
        reportService.getReportDataForOrganisationUnits(jasperReportDataSource,
                kudActivitySchemaAndVersionTwoYearBack, prefixTwoYearBack);

    }

    SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();

    SchemaPdfLogo pdfLogo = SchemaPdfLogo.newInstance(schemaTypeNameAndVersion);

    Locale locale = sessionLocaleResolver.resolveLocale(request);
    logger.info("We are using locale=[" + locale.toString() + "]");

    int reportPeriod = schemaTypeNameAndVersion.getYear();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("logourl", pdfLogo.getLogoUrl());
    model.put("logoheight", pdfLogo.getLogoHeight());
    model.put("logowidth", pdfLogo.getLogoWidth());
    model.put("reportData", jasperReportDataSource);
    model.put("abmstatistikk.reportPeriod", Integer.toString(reportPeriod));
    model.put("abmstatistikk.budgetYear", Integer.toString(reportPeriod + 1));
    model.put(JRParameter.REPORT_LOCALE, locale);

    ModelAndView mav = new ModelAndView(view, model);

    stopWatch.stop();
    if (logger.isDebugEnabled()) {
        logger.debug("[private:createMAVForOrganisationUnit] tok[" + stopWatch.getTotalTimeMillis() + "] ms");
    }

    return mav;
}

From source file:no.abmu.abmstatistikk.web.AbstractReportController.java

protected ModelAndView basicReportDataByMuncipality(HttpServletRequest request,
        OrgUnitFinderSpecificationBean finderBean, SchemaTypeNameAndVersion schemaTypeNameAndVersion,
        String viewName) {/*  w  w w . j a va2s .  c  om*/

    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.abmstatistikk.web.AbstractStatusBrowsingController.java

/**
 * Refreshable status browser.//  w  w w  .ja  v a 2 s.co m
 * @param request current HTTP request
 * @param attribute to use store RefreshablePageholder in current http session
 * @param organisationType name of organisation type
 * @param schemaType name of schema type
 * @param view - if sucess use this view as view in ModelAndView
 * @param year - report year
 * @return a ModelAndView to render the response
 */
protected ModelAndView statusBrowser(HttpServletRequest request, String attribute,
        OrgUnitFinderSpecificationBean finderBean, SchemaTypeNameAndVersion schemaTypeNameAndVersion,
        String view) {

    logger.info("Executing statusBrowser on organisationType='" + finderBean.getOrganisationTypeName()
            + "' and schemaType='" + schemaTypeNameAndVersion.toString() + "'");
    StopWatch stopWatch = new StopWatch("browseOrgType");

    /*
     * This should be replaced with AOP in an XML spring config-file.
     */
    if (!isSecureContext()) {
        return new ModelAndView(ViewNameConst.LOGOFF_VIEW);
    }
    stopWatch.start("Mav_for_browsing_organisationType");
    Map model = statusBrowse(request, attribute, finderBean, schemaTypeNameAndVersion);

    stopWatch.stop();
    logger.info("Getting ModelAndview for organisationType  " + finderBean.getOrganisationTypeName() + " tok "
            + stopWatch.getTotalTimeMillis() + " milliseconds.");

    return new ModelAndView(view, model);

}

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 . j  a  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.lise.service.hibernate3.LiseImportServiceH3Impl.java

private void processSheetOne(Session session, LiseImportExcelParser excelParser) {

    List<Entity> entityStorList = new ArrayList<Entity>();
    Consortium currentConsortium = null;
    Product currentProduct = null;/* w w w  .j a  v a2 s .  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 ww  w  .j  a va 2s .  c om
    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("   =============================================================================  ");
}