Search in sources :

Example 1 with StorageFileNotFoundException

use of nikita.common.util.exceptions.StorageFileNotFoundException in project nikita-noark5-core by HiOA-ABI.

the class DocumentObjectService method loadAsResource.

@Override
public Resource loadAsResource(DocumentObject documentObject) {
    String filename = documentObject.getReferenceDocumentFile();
    try {
        Path file = load(filename);
        Resource resource = new UrlResource(file.toUri());
        if (resource.exists() || resource.isReadable()) {
            return resource;
        } else {
            throw new StorageFileNotFoundException("Could not read file: " + filename);
        }
    } catch (MalformedURLException e) {
        throw new StorageFileNotFoundException("Could not read file: " + filename);
    }
}
Also used : Path(java.nio.file.Path) StorageFileNotFoundException(nikita.common.util.exceptions.StorageFileNotFoundException) MalformedURLException(java.net.MalformedURLException) UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 Path (java.nio.file.Path)1 StorageFileNotFoundException (nikita.common.util.exceptions.StorageFileNotFoundException)1 Resource (org.springframework.core.io.Resource)1 UrlResource (org.springframework.core.io.UrlResource)1