src/main/java/edu/ucla/library/bucketeer/handlers/LoadCsvHandler.java
@Override
    public void handle(final RoutingContext aContext) {
        final HttpServerResponse response = aContext.response();
        final HttpServerRequest request = aContext.request();
        final MultiMap formAttributes = request.formAttributes();
        final Set<FileUpload> csvUploads = aContext.fileUploads();
        final String slackHandle = StringUtils.trimToNull(formAttributes.get(Constants.SLACK_HANDLE));

        if (slackHandle == null) {
            final String errorMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_050);
            final String extendedErrorMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_071);

            // Slack handle is required -- don't accept the form without it being supplied
            response.setStatusCode(HTTP.BAD_REQUEST);
            response.setStatusMessage(errorMessage);
            response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
            response.end(StringUtils.format(myExceptionPage, errorMessage + extendedErrorMessage));
        } else if (csvUploads.isEmpty()) {
            final String errorMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_049);
            final String extendedErrorMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_071);

            // An uploaded CSV file is required -- don't accept the form without it being supplied
            response.setStatusCode(HTTP.BAD_REQUEST);
            response.setStatusMessage(errorMessage);
            response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
            response.end(StringUtils.format(myExceptionPage, errorMessage + extendedErrorMessage));
        } else {
            final String cleanSlackHandle = slackHandle.replace(Constants.AT, Constants.EMPTY);
            final String runFailures = StringUtils.trimTo(formAttributes.get(Constants.FAILURES_ONLY), "false");
            final boolean subsequentRun = Boolean.parseBoolean(runFailures);
            final FileUpload csvFile = csvUploads.iterator().next();
            final String filePath = csvFile.uploadedFileName();
            final String fileName = csvFile.fileName();
            final String jobName = FileUtils.stripExt(fileName);

            LOGGER.info(MessageCodes.BUCKETEER_051, cleanSlackHandle, fileName, filePath);

            if (myVertx == null) {
                myVertx = aContext.vertx();
            }

            try {
                final Job job = JobFactory.getInstance().createJob(jobName, new File(filePath), subsequentRun);

                // Set the Slack handle
                job.setSlackHandle(cleanSlackHandle);

                initiateJob(job, response);
            } catch (final FileNotFoundException details) {
                final String exceptionMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_073);
                final String exceptionName = LOGGER.getMessage(MessageCodes.BUCKETEER_074);

                LOGGER.error(details, details.getMessage());

                response.setStatusCode(HTTP.INTERNAL_SERVER_ERROR);
                response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
                response.end(StringUtils.format(myExceptionPage, exceptionName + exceptionMessage));
            } catch (final IOException details) {
                final String exceptionName = LOGGER.getMessage(MessageCodes.BUCKETEER_074);

                LOGGER.error(details, details.getMessage());

                response.setStatusCode(HTTP.INTERNAL_SERVER_ERROR);
                response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
                response.end(StringUtils.format(myExceptionPage, exceptionName + details.getMessage()));
            } catch (final ProcessingException details) {
                final String statusMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_072);

                response.setStatusCode(HTTP.BAD_REQUEST);
                response.setStatusMessage(statusMessage);
                response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
                response.end(StringUtils.format(myExceptionPage, details.getMessages("<br>")));
            }
        }
    }
/**
     * Handles the CSV upload request.
     *
     * @param aContext A routing context
     */
Handles the CSV upload request.
@param aContext A routing context
Handles the CSV upload request . @param aContext A routing context
@Override
    public void handle(final RoutingContext aContext) {
        final HttpServerResponse response = aContext.response();
        final HttpServerRequest request = aContext.request();
        final MultiMap formAttributes = request.formAttributes();
        final Set<FileUpload> csvUploads = aContext.fileUploads();
        final String slackHandle = StringUtils.trimToNull(formAttributes.get(Constants.SLACK_HANDLE));
        if (slackHandle == null) {
            final String errorMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_050);
            final String extendedErrorMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_071);
            response.setStatusCode(HTTP.BAD_REQUEST);
            response.setStatusMessage(errorMessage);
            response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
            response.end(StringUtils.format(myExceptionPage, errorMessage + extendedErrorMessage));
        } else if (csvUploads.isEmpty()) {
            final String errorMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_049);
            final String extendedErrorMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_071);
            response.setStatusCode(HTTP.BAD_REQUEST);
            response.setStatusMessage(errorMessage);
            response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
            response.end(StringUtils.format(myExceptionPage, errorMessage + extendedErrorMessage));
        } else {
            final String cleanSlackHandle = slackHandle.replace(Constants.AT, Constants.EMPTY);
            final String runFailures = StringUtils.trimTo(formAttributes.get(Constants.FAILURES_ONLY), "false");
            final boolean subsequentRun = Boolean.parseBoolean(runFailures);
            final FileUpload csvFile = csvUploads.iterator().next();
            final String filePath = csvFile.uploadedFileName();
            final String fileName = csvFile.fileName();
            final String jobName = FileUtils.stripExt(fileName);
            LOGGER.info(MessageCodes.BUCKETEER_051, cleanSlackHandle, fileName, filePath);
            if (myVertx == null) {
                myVertx = aContext.vertx();
            }
            try {
                final Job job = JobFactory.getInstance().createJob(jobName, new File(filePath), subsequentRun);
                job.setSlackHandle(cleanSlackHandle);
                initiateJob(job, response);
            } catch (final FileNotFoundException details) {
                final String exceptionMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_073);
                final String exceptionName = LOGGER.getMessage(MessageCodes.BUCKETEER_074);
                LOGGER.error(details, details.getMessage());
                response.setStatusCode(HTTP.INTERNAL_SERVER_ERROR);
                response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
                response.end(StringUtils.format(myExceptionPage, exceptionName + exceptionMessage));
            } catch (final IOException details) {
                final String exceptionName = LOGGER.getMessage(MessageCodes.BUCKETEER_074);
                LOGGER.error(details, details.getMessage());
                response.setStatusCode(HTTP.INTERNAL_SERVER_ERROR);
                response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
                response.end(StringUtils.format(myExceptionPage, exceptionName + details.getMessage()));
            } catch (final ProcessingException details) {
                final String statusMessage = LOGGER.getMessage(MessageCodes.BUCKETEER_072);
                response.setStatusCode(HTTP.BAD_REQUEST);
                response.setStatusMessage(statusMessage);
                response.putHeader(Constants.CONTENT_TYPE, Constants.HTML);
                response.end(StringUtils.format(myExceptionPage, details.getMessages("<br>")));
            }
        }
    }
@ Override public void handle ( final RoutingContext aContext ) { final HttpServerResponse response = aContext . response ( ) ; final HttpServerRequest request = aContext . request ( ) ; final MultiMap formAttributes = request . formAttributes ( ) ; final Set < FileUpload > csvUploads = aContext . fileUploads ( ) ; final String slackHandle = StringUtils . trimToNull ( formAttributes . get ( Constants . SLACK_HANDLE ) ) ; if ( slackHandle == null ) { final String errorMessage = LOGGER . getMessage ( MessageCodes . BUCKETEER_050 ) ; final String extendedErrorMessage = LOGGER . getMessage ( MessageCodes . BUCKETEER_071 ) ; response . setStatusCode ( HTTP . BAD_REQUEST ) ; response . setStatusMessage ( errorMessage ) ; response . putHeader ( Constants . CONTENT_TYPE , Constants . HTML ) ; response . end ( StringUtils . format ( myExceptionPage , errorMessage + extendedErrorMessage ) ) ; } else if ( csvUploads . isEmpty ( ) ) { final String errorMessage = LOGGER . getMessage ( MessageCodes . BUCKETEER_049 ) ; final String extendedErrorMessage = LOGGER . getMessage ( MessageCodes . BUCKETEER_071 ) ; response . setStatusCode ( HTTP . BAD_REQUEST ) ; response . setStatusMessage ( errorMessage ) ; response . putHeader ( Constants . CONTENT_TYPE , Constants . HTML ) ; response . end ( StringUtils . format ( myExceptionPage , errorMessage + extendedErrorMessage ) ) ; } else { final String cleanSlackHandle = slackHandle . replace ( Constants . AT , Constants . EMPTY ) ; final String runFailures = StringUtils . trimTo ( formAttributes . get ( Constants . FAILURES_ONLY ) , "false" ) ; final boolean subsequentRun = Boolean . parseBoolean ( runFailures ) ; final FileUpload csvFile = csvUploads . iterator ( ) . next ( ) ; final String filePath = csvFile . uploadedFileName ( ) ; final String fileName = csvFile . fileName ( ) ; final String jobName = FileUtils . stripExt ( fileName ) ; LOGGER . info ( MessageCodes . BUCKETEER_051 , cleanSlackHandle , fileName , filePath ) ; if ( myVertx == null ) { myVertx = aContext . vertx ( ) ; } try { final Job job = JobFactory . getInstance ( ) . createJob ( jobName , new File ( filePath ) , subsequentRun ) ; job . setSlackHandle ( cleanSlackHandle ) ; initiateJob ( job , response ) ; } catch ( final FileNotFoundException details ) { final String exceptionMessage = LOGGER . getMessage ( MessageCodes . BUCKETEER_073 ) ; final String exceptionName = LOGGER . getMessage ( MessageCodes . BUCKETEER_074 ) ; LOGGER . error ( details , details . getMessage ( ) ) ; response . setStatusCode ( HTTP . INTERNAL_SERVER_ERROR ) ; response . putHeader ( Constants . CONTENT_TYPE , Constants . HTML ) ; response . end ( StringUtils . format ( myExceptionPage , exceptionName + exceptionMessage ) ) ; } catch ( final IOException details ) { final String exceptionName = LOGGER . getMessage ( MessageCodes . BUCKETEER_074 ) ; LOGGER . error ( details , details . getMessage ( ) ) ; response . setStatusCode ( HTTP . INTERNAL_SERVER_ERROR ) ; response . putHeader ( Constants . CONTENT_TYPE , Constants . HTML ) ; response . end ( StringUtils . format ( myExceptionPage , exceptionName + details . getMessage ( ) ) ) ; } catch ( final ProcessingException details ) { final String statusMessage = LOGGER . getMessage ( MessageCodes . BUCKETEER_072 ) ; response . setStatusCode ( HTTP . BAD_REQUEST ) ; response . setStatusMessage ( statusMessage ) ; response . putHeader ( Constants . CONTENT_TYPE , Constants . HTML ) ; response . end ( StringUtils . format ( myExceptionPage , details . getMessages ( "<br>" ) ) ) ; } } }
Handles the CSV upload request.
Handles the CSV upload request .
// Slack handle is required -- don't accept the form without it being supplied // An uploaded CSV file is required -- don't accept the form without it being supplied // Set the Slack handle