Skip to content

Commit

Permalink
[Issue 328] Resource not found exceptions (#329)
Browse files Browse the repository at this point in the history
* Return null to indicate not found

* Add file not found exception handler

* Add external asset directory config example

* Update README.md
  • Loading branch information
wwelling authored Jul 21, 2023
1 parent 538ce10 commit 154df64
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

}
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 154df64

Please sign in to comment.