class MassConvertController {

    @RequestMapping(value = "/batch", method = RequestMethod.GET)
    public void convert(@RequestParam(PARAM_URL) String sourceUrlParams,
                        @RequestParam(value = PARAM_URL_TEMPLATE, required = false, defaultValue = DEFAULT_URL_TEMPLATE) String sourceUrlTemplate,
                        @RequestParam(value = PARAM_OUT_FORMAT, required = false, defaultValue = DEFAULT_OUT_FORMAT) String outputFormat,
                        HttpServletResponse response) throws Exception {

        if (sourceUrlParams == null || sourceUrlParams.length() == 0) {
            throw new Exception("Required parameter missing: " + PARAM_URL);
        }


        String[] sourceUrls = getSourceUrls(sourceUrlTemplate, sourceUrlParams);
        Arrays.sort(sourceUrls);

        String batchSignature = calculateBatchSignature(sourceUrls);

        String batchFilePath = batchDao.findBatchPath(batchSignature, outputFormat);

        if (batchFilePath != null) { // already packed
            sendRedirect(response, batchFilePath);
            return;
        }


        List<Callable<Object>> tasks = new ArrayList<Callable<Object>>(sourceUrls.length);

        for (final String sourceUrl : sourceUrls) {
            tasks.add(createSingleConversionTask(sourceUrl, outputFormat));
        }

        converterExecutor.invokeAll(tasks); // make sure all files are converted


        File batchFile = zipFiles(sourceUrls, outputFormat, batchSignature);

        batchDao.addBatch(batchSignature, outputFormat, batchFile);
        batchFilePath = batchDao.findBatchPath(batchSignature, outputFormat);
        sendRedirect(response, batchFilePath);
    }

}