-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHIBUI-754: filters re-order work in progress
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ava/edu/internet2/tier/shibboleth/admin/ui/controller/support/RestControllersSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.controller.support; | ||
|
|
||
| import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.MetadataResolver; | ||
| import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
| import org.springframework.web.client.HttpClientErrorException; | ||
|
|
||
| import static org.springframework.http.HttpStatus.NOT_FOUND; | ||
|
|
||
| /** | ||
| * Common functionality for REST controllers. | ||
| * | ||
| * @author Dmitriy Kopylenko | ||
| */ | ||
| @RestControllerAdvice | ||
| public class RestControllersSupport { | ||
|
|
||
| @Autowired | ||
| MetadataResolverRepository resolverRepository; | ||
|
|
||
| public MetadataResolver findResolverOrThrowHttp404(String resolverResourceId) { | ||
| MetadataResolver resolver = resolverRepository.findByResourceId(resolverResourceId); | ||
| if(resolver == null) { | ||
| throw new HttpClientErrorException(NOT_FOUND, "Metadata resolver is not found"); | ||
| } | ||
| return resolver; | ||
| } | ||
|
|
||
|
|
||
| @ExceptionHandler | ||
| public ResponseEntity<?> notFoundHandler(HttpClientErrorException ex) { | ||
| if(ex.getStatusCode() == NOT_FOUND) { | ||
| return ResponseEntity.status(NOT_FOUND).body(ex.getStatusText()); | ||
| } | ||
| throw ex; | ||
| } | ||
| } |