diff --git a/README.md b/README.md index 719146648..e2c45ea02 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,22 @@ Here is a list of some dependencies used: The basic Spring Boot application configuration can be found at [src/main/resources/application.yml](https://github.com/vivo-community/scholars-discovery/blob/master/src/main/resources/application.yml). Here you be able to configure basic server and spring configuration as well as custom configuration for Scholars Discovery. There are several configuration POJOs to represent configurations. They can be found in [src/main/java/edu/tamu/scholars/middleware/config/model](https://github.com/vivo-community/scholars-discovery/tree/master/src/main/java/edu/tamu/scholars/middleware/config/model), and [src/main/java/edu/tamu/scholars/middleware/auth/config](https://github.com/vivo-community/scholars-discovery/tree/master/src/main/java/edu/tamu/scholars/middleware/auth/config). +## Assets + +Assets are hosted at `/file/:id/:filename` and configured location `middleware.assets-location`. + +Tested options are + +Assets stored in src/main/resources/assets +``` +middleware.assets-location: classpath:/assets +``` + +Assets stored in externally +``` +middleware.assets-location: file:/scholars/assets +``` + ### Harvesting Harvesting can be configured via ```middleware.harvesters``` and represented with [HarvesterConfig](https://github.com/vivo-community/scholars-discovery/blob/master/src/main/java/edu/tamu/scholars/middleware/config/model/HarvesterConfig.java). For each harvester, a bean will be created in which specifies the type of harvester and which document types it maps to. The reference implementation is the local triplestore harvester. @@ -59,9 +75,7 @@ Solr is configured via ```spring.data.solr```. 3. Start Solr ```bash - cd solr - docker build --tag=scholars/solr . - docker run -d -p 8983:8983 scholars/solr + cd solr && docker build --tag=scholars/solr . && docker run -d -p 8983:8983 scholars/solr && cd .. ``` 5. Build and Run the application diff --git a/src/main/java/edu/tamu/scholars/middleware/config/WebMvcConfig.java b/src/main/java/edu/tamu/scholars/middleware/config/WebMvcConfig.java index 37a3dc674..62bc30897 100644 --- a/src/main/java/edu/tamu/scholars/middleware/config/WebMvcConfig.java +++ b/src/main/java/edu/tamu/scholars/middleware/config/WebMvcConfig.java @@ -71,6 +71,10 @@ protected Resource getResource(String resourcePath, Resource location) throws IO location = new FileUrlResource(resourcePath); } + if (!location.getFile().exists()) { + location = null; + } + return location; } diff --git a/src/main/java/edu/tamu/scholars/middleware/discovery/advice/DiscoveryControllerAdvice.java b/src/main/java/edu/tamu/scholars/middleware/discovery/advice/DiscoveryControllerAdvice.java index 8c38dbb9d..6067e4e13 100644 --- a/src/main/java/edu/tamu/scholars/middleware/discovery/advice/DiscoveryControllerAdvice.java +++ b/src/main/java/edu/tamu/scholars/middleware/discovery/advice/DiscoveryControllerAdvice.java @@ -1,5 +1,7 @@ package edu.tamu.scholars.middleware.discovery.advice; +import java.io.FileNotFoundException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -30,4 +32,11 @@ public class DiscoveryControllerAdvice { return exception.getMessage(); } + @ResponseStatus(value = HttpStatus.NOT_FOUND) + @ExceptionHandler(value = FileNotFoundException.class) + public @ResponseBody String handleFileNotFoundException(FileNotFoundException exception) { + logger.error(exception.getMessage(), exception); + return exception.getMessage(); + } + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a117d5fd1..b3d79155d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,7 +2,10 @@ ui: url: http://localhost:4200 middleware: + ## copy a~n to src/main/resources/assets/a~n assets-location: classpath:/assets + ## works in Windows and expected to work on Linux + # assets-location: file:/Users/wwelling/Development/scholars/scholars-discovery/assets load-defaults: true update-defaults: true allowed-origins: