Search in sources :

Example 1 with DataGridReplicateException

use of com.emc.metalnx.core.domain.exceptions.DataGridReplicateException in project metalnx-web by irods-contrib.

the class UploadController method upload.

@RequestMapping(value = "/", method = RequestMethod.POST, produces = { "text/plain" })
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<?> upload(final HttpServletRequest request) throws DataGridException {
    logger.info("upload()");
    String uploadMessage = "File Uploaded. ";
    String errorType = "";
    if (!(request instanceof MultipartHttpServletRequest)) {
        logger.warn("Request is not a multipart request.");
        uploadMessage = "Request is not a multipart request.";
        errorType = FATAL;
        return getUploadResponse(uploadMessage, errorType);
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    MultipartFile multipartFile = multipartRequest.getFile("file");
    logger.info("multipartFile:{}", multipartFile);
    boolean isRuleDeployment = Boolean.parseBoolean(multipartRequest.getParameter("ruleDeployment"));
    boolean checksum = Boolean.parseBoolean(multipartRequest.getParameter("checksum"));
    boolean replica = Boolean.parseBoolean(multipartRequest.getParameter("replica"));
    boolean overwrite = Boolean.parseBoolean(multipartRequest.getParameter("overwriteDuplicateFiles"));
    String resources = multipartRequest.getParameter("resources");
    String resourcesToUpload = multipartRequest.getParameter("resourcesToUpload");
    String destPath = multipartRequest.getParameter("uploadDestinationPath");
    logger.info("parsed parameters...");
    try {
        if (isRuleDeployment) {
            ruleDeploymentService.deployRule(multipartFile);
        } else {
            us.upload(multipartFile, destPath, checksum, replica, resources, resourcesToUpload, overwrite);
        }
    } catch (DataGridReplicateException e) {
        uploadMessage += e.getMessage();
        errorType = WARNING;
        logger.warn("DataGridReplicateException during upload, will pass back as a warning", e);
    } catch (DataGridRuleException e) {
        uploadMessage += METADATA_EXTRACTION_FAILED_MSG;
        errorType = WARNING;
        logger.warn("DataGridRule exception extracting metadata, will pass back as warning", e);
    } catch (DataGridException e) {
        uploadMessage = e.getMessage();
        errorType = FATAL;
        logger.error("DataGridException uploading file", e);
        logger.warn("DataGridException uplaoding file, will pass back as warning", e);
    // throw e;
    } catch (JargonException e) {
        uploadMessage = e.getMessage();
        errorType = FATAL;
        logger.error("JargonException uploading file", e);
        logger.warn("JargonException uplaoding file, will pass back as warning", e);
    } catch (Throwable t) {
        logger.error("unexpected exception in upload", t);
        errorType = FATAL;
        throw t;
    }
    return getUploadResponse(uploadMessage, errorType);
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) DataGridRuleException(com.emc.metalnx.core.domain.exceptions.DataGridRuleException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridReplicateException(com.emc.metalnx.core.domain.exceptions.DataGridReplicateException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 DataGridReplicateException (com.emc.metalnx.core.domain.exceptions.DataGridReplicateException)1 DataGridRuleException (com.emc.metalnx.core.domain.exceptions.DataGridRuleException)1 JargonException (org.irods.jargon.core.exception.JargonException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)1