Search in sources :

Example 1 with FileBrowserFileRequest

use of org.entando.entando.web.filebrowser.model.FileBrowserFileRequest in project entando-core by entando.

the class FileBrowserControllerIntegrationTest method createBody.

private String createBody(String filename, String path, boolean isProtected, String content) throws Exception {
    FileBrowserFileRequest request = new FileBrowserFileRequest();
    request.setFilename(filename);
    if (null != content) {
        request.setBase64(content.getBytes());
    }
    request.setPath(path);
    request.setProtectedFolder(isProtected);
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(request);
}
Also used : FileBrowserFileRequest(org.entando.entando.web.filebrowser.model.FileBrowserFileRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with FileBrowserFileRequest

use of org.entando.entando.web.filebrowser.model.FileBrowserFileRequest in project entando-core by entando.

the class FileBrowserValidator method validate.

@Override
public void validate(Object target, Errors errors) {
    FileBrowserRequest request = (FileBrowserRequest) target;
    String path = request.getPath();
    if (path.endsWith("/")) {
        if (request instanceof FileBrowserFileRequest) {
            errors.rejectValue("path", ERRCODE_INVALID_PATH, new String[] { path }, "fileBrowser.filename.invalidPath");
            return;
        } else {
            path = path.substring(0, path.length() - 1);
        }
    }
    if (!path.contains("/")) {
        return;
    }
    try {
        String directory = path.substring(0, path.lastIndexOf("/"));
        if (!this.getStorageManager().exists(directory, request.isProtectedFolder())) {
            throw new ResourceNotFoundException(FileBrowserValidator.ERRCODE_RESOURCE_DOES_NOT_EXIST, "parent folder", path);
        }
        if (request instanceof FileBrowserFileRequest) {
            FileBrowserFileRequest fileRequest = (FileBrowserFileRequest) target;
            String extractedFileName = path.substring(path.lastIndexOf("/") + 1, path.length());
            if (!extractedFileName.equalsIgnoreCase(fileRequest.getFilename())) {
                errors.rejectValue("filename", ERRCODE_FILENAME_MISMATCH, new String[] { fileRequest.getFilename(), extractedFileName }, "fileBrowser.filename.body.mismatch");
                throw new ValidationConflictException((BindingResult) errors);
            }
        }
    } catch (ValidationConflictException vce) {
        throw vce;
    } catch (ResourceNotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Error checking path {} , protected {} ", path, request.isProtectedFolder(), e);
        throw new RestServerError("error checking path", e);
    }
}
Also used : FileBrowserRequest(org.entando.entando.web.filebrowser.model.FileBrowserRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FileBrowserFileRequest(org.entando.entando.web.filebrowser.model.FileBrowserFileRequest) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Aggregations

FileBrowserFileRequest (org.entando.entando.web.filebrowser.model.FileBrowserFileRequest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)1 RestServerError (org.entando.entando.aps.system.exception.RestServerError)1 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)1 FileBrowserRequest (org.entando.entando.web.filebrowser.model.FileBrowserRequest)1