Example usage for org.apache.commons.lang.time StopWatch stop

List of usage examples for org.apache.commons.lang.time StopWatch stop

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch stop.

Prototype

public void stop() 

Source Link

Document

Stop the stopwatch.

This method ends a new timing session, allowing the time to be retrieved.

Usage

From source file:pt.ua.tm.gimli.writer.JNLPBAWriter.java

/**
 * Main program annotate a corpus using one or several models, and save the
 * result in the JNLPBA format.//  ww  w. j a  v  a 2s  . c  o  m
 * @param args Command line arguments.
 */
public static void main(String[] args) {
    // Start stopwatch
    StopWatch watch = new StopWatch();
    watch.start();

    CommandLineParser parser = new GnuParser();
    Options options = new Options();
    options.addOption("h", "help", false, "Print this usage information.");

    options.addOption("c", "corpus", true, "File with the corpus in the CoNNL format.");

    Option o = new Option("m", "model", true, MODEL_HELP);
    o.setArgs(Integer.MAX_VALUE);

    options.addOption(o);

    options.addOption("o", "output", true, "File to save the annotated corpus.");
    CommandLine commandLine = null;
    try {
        // Parse the program arguments
        commandLine = parser.parse(options, args);
    } catch (ParseException ex) {
        logger.error("There was a problem processing the input arguments.", ex);
        return;
    }

    // Show help text
    if (commandLine.hasOption('h')) {
        printHelp(options, "");
        return;
    }

    // Get corpus
    String corpus = null;
    if (commandLine.hasOption('c')) {
        corpus = commandLine.getOptionValue('c');
    } else {
        printHelp(options, "Please specify the corpus file.");
        return;
    }

    // Get models
    String[] input = null;
    if (commandLine.hasOption('m')) {
        input = commandLine.getOptionValues('m');
    } else {
        printHelp(options, "Please specify the models.");
        return;
    }

    // Parse models characteristics
    String[] models = new String[input.length];
    EntityType[] entities = new EntityType[input.length];
    String[] features = new String[input.length];
    Parsing[] parsing = new Parsing[input.length];

    String[] strs;
    for (int i = 0; i < input.length; i++) {
        strs = input[i].split(",");

        if (strs.length != 4) {
            printHelp(options, "Wrong input format for models.");
            return;
        }

        models[i] = strs[0].trim();
        entities[i] = EntityType.valueOf(strs[1].trim());
        parsing[i] = Parsing.valueOf(strs[2].trim().toUpperCase());
        features[i] = strs[3].trim();
    }

    // Get output
    String output = null;
    if (commandLine.hasOption('o')) {
        output = commandLine.getOptionValue('o');
    } else {
        printHelp(options, "Please specify the output file.");
        return;
    }

    // Check length consistency
    if ((features.length != models.length) || (features.length != entities.length)
            || (features.length != parsing.length)) {
        logger.error(
                "The number of feature files, parsing, entities and models are different from each other.");
        return;
    }

    // Give feedback
    logger.info("Corpus: {}", corpus);
    logger.info("Models:");
    for (int i = 0; i < models.length; i++) {
        logger.info("\t{}: {}, {}, {}, {}",
                new Object[] { i + 1, models[i], entities[i], features[i], parsing[i] });
    }
    logger.info("Output: {}", output);

    // Load model configurations
    ModelConfig[] mc = new ModelConfig[features.length];
    for (int i = 0; i < features.length; i++) {
        mc[i] = new ModelConfig(features[i]);
    }

    // Get unique entities
    ArrayList<EntityType> uniqueEntities = new ArrayList<EntityType>();
    for (int i = 0; i < entities.length; i++) {
        if (!uniqueEntities.contains(entities[i])) {
            uniqueEntities.add(entities[i]);
        }
    }

    // Load Corpus
    Corpus[] c = new Corpus[uniqueEntities.size()];
    try {
        for (int i = 0; i < uniqueEntities.size(); i++) {
            c[i] = new Corpus(LabelFormat.BIO, uniqueEntities.get(i), corpus);
        }
    } catch (GimliException ex) {
        logger.error("There was a problem loading the corpus.", ex);
        return;
    }

    // Combine models of the same entity
    for (int j = 0; j < uniqueEntities.size(); j++) {
        ArrayList<CRFModel> crfmodels = new ArrayList<CRFModel>();

        try {
            for (int i = 0; i < entities.length; i++) {
                if (entities[i].equals(uniqueEntities.get(j))) {
                    crfmodels.add(new CRFModel(mc[i], parsing[i], models[i]));
                }
            }
        } catch (GimliException ex) {
            logger.error("There was a problem loading a model.", ex);
            return;
        }

        Annotator a = new Annotator(c[j]);
        if (crfmodels.size() > 1) {

            logger.info("Annotating the corpus by combining {} models for {}...", crfmodels.size(),
                    uniqueEntities.get(j));
            a.annotate(crfmodels.toArray(new CRFModel[0]));
        } else {
            logger.info("Annotating the corpus using 1 model for {}...", uniqueEntities.get(j));
            a.annotate(crfmodels.get(0));
        }
    }

    // Post-processing
    for (int i = 0; i < c.length; i++) {
        Parentheses.processRemoving(c[i]);
        Abbreviation.process(c[i]);
    }

    // Write annotations to file
    logger.info("Writing the corpus in the JNLPBA format...");
    JNLPBAWriter writer = new JNLPBAWriter();

    try {
        if (c.length > 1) {
            //Annotator.writeJNLPBACombined(c, output);
            writer.write(c, output);
        } else {
            writer.write(c[0], output);
            //Annotator.writeJNLPBA(c[0], output);
        }
    } catch (GimliException ex) {
        logger.error("There was a problem writing the corpus to file.", ex);
        return;
    }

    // Time feedback
    watch.stop();
    logger.info("Done!");
    logger.info("Total time: {}", watch.toString());

    double time = (double) watch.getTime();
    double size = (double) c[0].size();

    double perSentence = time / size;
    double perAbstract = time / (size / 10.0);
    double perHundred = time / (size / 100.0);

    logger.info("Per sentence: {} seconds", String.format("%2.4f", perSentence / 1000.0));
    logger.info("Per abstract: {} seconds", String.format("%2.4f", perAbstract / 1000.0));
    logger.info("10 abstracts: {} seconds", String.format("%2.4f", perHundred / 1000.0));
}

From source file:pt.ua.tm.neji.batch.FileBatchExecutor.java

@Override
public void run(Class<? extends Processor> processorCls, Context context, Object... args) throws NejiException {
    //        System.setProperty("file.encoding", "UTF-8");

    logger.info("Initializing context...");
    context.initialize();/*from ww w .j av a 2  s . c  o m*/
    logger.info("Installing multi-threading support...");
    context.addMultiThreadingSupport(numThreads);

    //        try {
    //        logger.info("Starting thread pool with support for {} threads...", numThreads);
    //            executor = Executors.newFixedThreadPool(numThreads, new ProcessorThreadFactory());

    StopWatch timer = new StopWatch();
    timer.start();

    //            CorpusDirWalker walker = new CorpusDirWalker(processorCls, context,
    //                    inputWildcardFilter, compressed, storeDocuments, args);
    //
    //        // Store processed corpora
    //            walker.processFiles();
    //
    //            executor.shutdown();
    //            executor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);

    filesProcessed = processFiles(inputFolderPath, inputWildcardFilter, outputFolderPath, numThreads, context,
            processorCls, args);

    logger.info("Stopped thread pool.");

    logger.info("Terminating context...");
    context.terminate();

    timer.stop();
    logger.info("Processed {} files in {}", filesProcessed, timer.toString());
    //        } catch (IOException | InterruptedException ex) {
    //            throw new NejiException("Problem processing pipeline.", ex);
    //        }
}

From source file:pt.ua.tm.neji.evaluation.craft.statistics.FolderBatchExecutor.java

public void run(final Context context) throws NejiException {
    logger.info("Initializing context...");
    context.initialize();/*  w ww.j av a2  s . c  o m*/
    logger.info("Installing multi-threading support...");
    context.addMultiThreadingSupport(numThreads);

    ExecutorService executor;

    logger.info("Starting thread pool with support for {} threads...", numThreads);
    executor = Executors.newFixedThreadPool(numThreads);

    StopWatch timer = new StopWatch();
    timer.start();

    File inputFolder = new File(inputFolderPath);
    File[] files = inputFolder.listFiles(new FileUtil.Filter(new String[] { "txt" }));

    for (File file : files) {
        //            File a1File = new File(file.getAbsolutePath().replaceAll(".txt", ".ann"));
        File a1File = new File(file.getAbsolutePath().replaceAll(".txt", ".a1"));
        Processor processor = getDocumentProcessor(file, a1File, context);

        // Process entry
        executor.execute(processor);
    }

    executor.shutdown();
    try {
        executor.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    logger.info("Stopped thread pool.");

    logger.info("Terminating context...");
    context.terminate();

    timer.stop();
    logger.info("Processed {} files in {}", processedCorpora.size(), timer.toString());
}

From source file:pt.ua.tm.neji.parsing.TestDynamicParsing.java

public void test() throws IOException, NejiException {
    Constants.verbose = true;//from w w w.j a v  a  2  s  .c  o m
    StopWatch timer = new StopWatch();

    // create corpus
    Corpus corpus = new Corpus();
    corpus.setText(Variables.str1.gdep.text);

    // readies the parser
    Variables.parseWithDepParser(ParserLevel.TOKENIZATION, corpus, Variables.str1.gdep.text);

    // test if only tokenization was performed, no dependency features, lemmas, pos or chunks should exist
    timer.start();
    List<Sentence> sentences1 = Variables.parseWithDepParser(ParserLevel.TOKENIZATION, corpus,
            Variables.str1.gdep.text);
    timer.stop();
    logger.info("{}", sentences1.get(0).toExportFormat());
    logger.info("Tokenization took {}", timer.toString());
    timer.reset();

    // test if only lemmatization was performed, no dependency features, pos or chunks should exist
    timer.start();
    List<Sentence> sentences2 = Variables.parseWithDepParser(ParserLevel.LEMMATIZATION, corpus,
            Variables.str1.gdep.text);
    timer.stop();
    logger.info("{}", sentences2.get(0).toExportFormat());
    logger.info("Lemmatization took {}", timer.toString());
    timer.reset();

    // test if only pos was performed, no dependency features nor chunks should exist
    timer.start();
    List<Sentence> sentences3 = Variables.parseWithDepParser(ParserLevel.POS, corpus, Variables.str1.gdep.text);
    timer.stop();
    logger.info("{}", sentences3.get(0).toExportFormat());
    logger.info("POS took {}", timer.toString());
    timer.reset();

    // test if only chunking was performed, no dependency features should exist
    timer.start();
    List<Sentence> sentences4 = Variables.parseWithDepParser(ParserLevel.CHUNKING, corpus,
            Variables.str1.gdep.text);
    timer.stop();
    logger.info("{}", sentences4.get(0).toExportFormat());
    logger.info("Chunking took {}", timer.toString());
    timer.reset();

    // test if dependency parsing was performed
    timer.start();
    List<Sentence> sentences5 = Variables.parseWithDepParser(ParserLevel.DEPENDENCY, corpus,
            Variables.str1.gdep.text);
    timer.stop();
    logger.info("{}", sentences5.get(0).toExportFormat());
    logger.info("Dependency took {}", timer.toString());
    timer.reset();

}

From source file:pt.ua.tm.neji.train.batch.TrainBatchExecutor.java

@Override
public void run(Class<? extends Processor> processorCls, Context context, Object... args) throws NejiException {

    StopWatch timer = new StopWatch();

    logger.info("Initializing context...");
    context.initialize();/* ww  w  .j  a v  a  2s. c  om*/

    timer.start();

    if (((TrainContext) context).getPhase() == 1) { // Phase 1            

        // If input format requires annotations
        if (context.getConfiguration().getInputFormat().equals(InputFormat.BC2)) { // File + Annotations formats
            processFiles(inputSentencesFilePath, inputAnnotationsFilePath, (TrainContext) context, processorCls,
                    args);
        } else if (context.getConfiguration().getInputFormat().equals(InputFormat.A1)) { // Folder format
            processMultipleFiles(inputSentencesFilePath, numThreads, (TrainContext) context, processorCls,
                    args);
        } else { // File formats 
            processFiles(inputSentencesFilePath, (TrainContext) context, processorCls, args);
        }
    } else { // Phase 2

        // In this case inputSentencesFilePath contains the path to the corpus
        processFiles2((TrainContext) context, processorCls, args);
    }

    logger.info("Terminating context...");
    context.terminate();

    timer.stop();
    logger.info("Processed files in {}", timer.toString());
}

From source file:pt.ua.tm.neji.web.batch.ServerBatchExecutor.java

@Override
public void run(Class<? extends Processor> processorCls, Context context, Object... args) throws NejiException {

    // Add false positives
    if (service.getFalsePositives() != null) {
        byte[] fpByte = service.getFalsePositives().getBytes();
        context.getConfiguration().setFalsePositives(fpByte);
    } else {/*from w  ww  . j ava  2s .co  m*/
        context.getConfiguration().setFalsePositives(null);
    }

    // Add semantic groups normalization (just when exporting, if format 
    // equals to null, then is an annotate)        
    if ((format != null) && !service.getGroupsNormalization().isEmpty()) {
        byte[] gnByte = service.getGroupsNormalizationByteArray();
        context.getConfiguration().setSemanticGroupsNormalization(gnByte);
    } else {
        context.getConfiguration().setSemanticGroupsNormalization(null);
    }

    // Distribution of output streams to the pipeline
    Map<OutputFormat, OutputStream> formatToStreamMap = new HashMap<>();
    List<OutputStream> outputStreams = new ArrayList<>();

    for (OutputFormat f : context.getConfiguration().getOutputFormats()) {
        OutputStream o = new ByteArrayOutputStream();
        formatToStreamMap.put(f, o);
        outputStreams.add(o);
    }

    Processor processor;
    Pipeline p = new DefaultPipeline(corpus);
    try {
        if (args != null && args.length != 0) {
            processor = newProcessor(processorCls, context, inputStream, outputStreams, service, p, groups,
                    filterGroups, args);
        } else {
            processor = newProcessor(processorCls, context, inputStream, outputStreams, service, p, groups,
                    filterGroups);
        }
    } catch (NejiException ex) {
        String m = "There was a problem creating the server processor";
        logger.error(m, ex);
        throw new RuntimeException(m, ex);
    }

    logger.info("");
    logger.info("Started processing a new document...");
    StopWatch timer = new StopWatch();
    timer.start();

    executor.execute(processor);

    try {
        synchronized (processor) {
            processor.wait();
        }
    } catch (InterruptedException ex) {
        throw new RuntimeException("There was a problem running the annotation service.", ex);
    }

    timer.stop();
    logger.info("Processed document in {}", timer.toString());

    if (format != null) {
        OutputStream output = formatToStreamMap.get(format);
        annotatedText = output.toString();
    }
}

From source file:seava.j4e.web.controller.data.AbstractAsgnController.java

/**
 * Default handler for find action.//from  ww w.  j  a va  2 s .  co  m
 * 
 * @param resourceName
 * @param dataformat
 * @param dataString
 * @param paramString
 * @param resultStart
 * @param resultSize
 * @param orderByCol
 * @param orderBySense
 * @return
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "="
        + Constants.ASGN_ACTION_QUERY_LEFT)
@ResponseBody
public String findLeft(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_OBJECT_ID, required = true) String objectId,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_SELECTION_ID, required = true) String selectionId,
        @RequestParam(value = Constants.REQUEST_PARAM_FILTER, required = false, defaultValue = "{}") String dataString,
        @RequestParam(value = Constants.REQUEST_PARAM_PARAMS, required = false, defaultValue = "{}") String paramString,
        @RequestParam(value = Constants.REQUEST_PARAM_START, required = false, defaultValue = "0") int resultStart,
        @RequestParam(value = Constants.REQUEST_PARAM_SIZE, required = false, defaultValue = "500") int resultSize,
        @RequestParam(value = Constants.REQUEST_PARAM_SORT, required = false, defaultValue = "") String orderByCol,
        @RequestParam(value = Constants.REQUEST_PARAM_SENSE, required = false, defaultValue = "") String orderBySense,
        @RequestParam(value = Constants.REQUEST_PARAM_ORDERBY, required = false, defaultValue = "") String orderBy,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {

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

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {} ",
                    new Object[] { resourceName, dataFormat, Constants.ASGN_ACTION_QUERY_LEFT });
        }

        if (logger.isDebugEnabled()) {
            logger.debug("  --> request-filter: objectId={}, selectionId={} data={}",
                    new Object[] { objectId, selectionId, dataString });
            logger.debug("  --> request-params: {} ", new Object[] { paramString });
            logger.debug("  --> request-orderBy: sort={}, sense={}, orderBy={}",
                    new Object[] { orderByCol, orderBySense, orderBy });
            logger.debug("  --> request-result-range: {} ",
                    new Object[] { resultStart + "", (resultStart + resultSize) + "" });
        }

        this.prepareRequest(request, response);

        this.authorizeAsgnAction(resourceName, "find");

        IAsgnService<M, F, P> service = this.findAsgnService(this.serviceNameFromResourceName(resourceName));
        IDsMarshaller<M, F, P> marshaller = service.createMarshaller(dataFormat);

        IQueryBuilder<M, F, P> builder = service.createQueryBuilder().addFetchLimit(resultStart, resultSize);

        if (orderBy != null && !orderBy.equals("")) {
            List<ISortToken> sortTokens = marshaller.readSortTokens(orderBy);
            builder.addSortInfo(sortTokens);
        } else {
            builder.addSortInfo(orderByCol, orderBySense);
        }

        F filter = marshaller.readFilterFromString(dataString);
        P params = marshaller.readParamsFromString(paramString);

        List<M> list = service.findLeft(selectionId, filter, params, builder);
        long totalCount = service.countLeft(selectionId, filter, params, builder);

        IActionResultFind result = this.packfindResult(list, params, totalCount);
        stopWatch.stop();
        result.setExecutionTime(stopWatch.getTime());

        return marshaller.writeResultToString(result);
    } catch (Exception e) {
        return this.handleManagedException(ErrorCode.DB_QUERY_ERROR, e, response);
    } finally {
        this.finishRequest();
    }

}

From source file:seava.j4e.web.controller.data.AbstractAsgnController.java

/**
 * Default handler for find action.//from   w ww .  j av  a 2s .  c  o m
 * 
 * @param resourceName
 * @param dataformat
 * @param dataString
 * @param paramString
 * @param resultStart
 * @param resultSize
 * @param orderByCol
 * @param orderBySense
 * @return
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "="
        + Constants.ASGN_ACTION_QUERY_RIGHT)
@ResponseBody
public String findRight(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_OBJECT_ID, required = true) String objectId,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_SELECTION_ID, required = true) String selectionId,
        @RequestParam(value = Constants.REQUEST_PARAM_FILTER, required = false, defaultValue = "{}") String dataString,
        @RequestParam(value = Constants.REQUEST_PARAM_PARAMS, required = false, defaultValue = "{}") String paramString,
        @RequestParam(value = Constants.REQUEST_PARAM_START, required = false, defaultValue = "0") int resultStart,
        @RequestParam(value = Constants.REQUEST_PARAM_SIZE, required = false, defaultValue = "500") int resultSize,
        @RequestParam(value = Constants.REQUEST_PARAM_SORT, required = false, defaultValue = "") String orderByCol,
        @RequestParam(value = Constants.REQUEST_PARAM_SENSE, required = false, defaultValue = "") String orderBySense,
        @RequestParam(value = Constants.REQUEST_PARAM_ORDERBY, required = false, defaultValue = "") String orderBy,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {

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

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {} ",
                    new Object[] { resourceName, dataFormat, Constants.ASGN_ACTION_QUERY_RIGHT });
        }

        if (logger.isDebugEnabled()) {
            logger.debug("  --> request-filter: objectId={}, selectionId={} data={}",
                    new Object[] { objectId, selectionId, dataString });
            logger.debug("  --> request-params: {} ", new Object[] { paramString });
            logger.debug("  --> request-orderBy: sort={}, sense={}, orderBy={}",
                    new Object[] { orderByCol, orderBySense, orderBy });
            logger.debug("  --> request-result-range: {} ",
                    new Object[] { resultStart + "", (resultStart + resultSize) + "" });
        }

        this.prepareRequest(request, response);

        this.authorizeAsgnAction(resourceName, "find");

        IAsgnService<M, F, P> service = this.findAsgnService(this.serviceNameFromResourceName(resourceName));

        IDsMarshaller<M, F, P> marshaller = service.createMarshaller(dataFormat);

        IQueryBuilder<M, F, P> builder = service.createQueryBuilder().addFetchLimit(resultStart, resultSize);

        if (orderBy != null && !orderBy.equals("")) {
            List<ISortToken> sortTokens = marshaller.readSortTokens(orderBy);
            builder.addSortInfo(sortTokens);
        } else {
            builder.addSortInfo(orderByCol, orderBySense);
        }

        F filter = marshaller.readFilterFromString(dataString);
        P params = marshaller.readParamsFromString(paramString);

        List<M> list = service.findRight(selectionId, filter, params, builder);
        long totalCount = service.countRight(selectionId, filter, params, builder);

        IActionResultFind result = this.packfindResult(list, params, totalCount);
        stopWatch.stop();
        result.setExecutionTime(stopWatch.getTime());

        return marshaller.writeResultToString(result);
    } catch (Exception e) {
        return this.handleManagedException(ErrorCode.DB_QUERY_ERROR, e, response);
    } finally {
        this.finishRequest();
    }
}

From source file:seava.j4e.web.controller.data.AbstractAsgnController.java

/**
 * /*  www. j a va2s.c om*/
 * @param resourceName
 * @param dataFormat
 * @param objectId
 * @param selectionId
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "="
        + Constants.ASGN_ACTION_MOVE_LEFT)
@ResponseBody
public String moveLeft(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_OBJECT_ID, required = true) String objectId,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_SELECTION_ID, required = true) String selectionId,
        @RequestParam(value = "p_selected_ids", required = true) String selectedIds, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {

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

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {} ",
                    new Object[] { resourceName, dataFormat, Constants.ASGN_ACTION_MOVE_LEFT });
        }

        if (logger.isDebugEnabled()) {
            logger.debug("  --> request-filter: objectId={}, selectionId={}, selectedIds={} ",
                    new Object[] { objectId, selectionId, selectedIds });
        }

        this.prepareRequest(request, response);

        this.authorizeAsgnAction(resourceName, "update");

        IAsgnService<M, F, P> service = this.findAsgnService(this.serviceNameFromResourceName(resourceName));

        service.moveLeft(selectionId, this.selectedIdsAsList(selectedIds));
        stopWatch.stop();
        return "";
    } catch (Exception e) {
        return this.handleManagedException(ErrorCode.DB_UPDATE_ERROR, e, response);
    } finally {
        this.finishRequest();
    }

}

From source file:seava.j4e.web.controller.data.AbstractAsgnController.java

/**
 * /*from   w w  w.j a  v a 2  s .c  o m*/
 * @param resourceName
 * @param dataFormat
 * @param objectId
 * @param selectionId
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "="
        + Constants.ASGN_ACTION_MOVE_RIGHT)
@ResponseBody
public String moveRight(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_OBJECT_ID, required = true) String objectId,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_SELECTION_ID, required = true) String selectionId,
        @RequestParam(value = "p_selected_ids", required = true) String selectedIds, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {

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

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {} ",
                    new Object[] { resourceName, dataFormat, Constants.ASGN_ACTION_MOVE_RIGHT });
        }

        if (logger.isDebugEnabled()) {
            logger.debug("  --> request-filter: objectId={}, selectionId={}, selectedIds={} ",
                    new Object[] { objectId, selectionId, selectedIds });
        }

        this.prepareRequest(request, response);

        this.authorizeAsgnAction(resourceName, "update");

        IAsgnService<M, F, P> service = this.findAsgnService(this.serviceNameFromResourceName(resourceName));

        service.moveRight(selectionId, this.selectedIdsAsList(selectedIds));
        stopWatch.stop();

        return "";
    } catch (Exception e) {
        return this.handleManagedException(ErrorCode.DB_UPDATE_ERROR, e, response);
    } finally {
        this.finishRequest();
    }
}