-
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.
* Add ApplicationErrorResource JAX-RS resource * Add a factory method to ApplicationError.Resolved to create an instance from a boolean * Add ApplicationErrorPage model that represents a "page" of errors * Add dropwizard-core dependency (with exclusions for dependency convergence errors) * Make dropwizard-jdbi3 dependency provided scope Fixes #20
- Loading branch information
1 parent
38821a4
commit 7807c08
Showing
9 changed files
with
496 additions
and
3 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
30 changes: 30 additions & 0 deletions
30
src/main/java/org/kiwiproject/dropwizard/error/model/ApplicationErrorPage.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,30 @@ | ||
package org.kiwiproject.dropwizard.error.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.kiwiproject.search.PaginatedResult; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Represents a "page" of {@link ApplicationError} results, e.g. when using pagination. | ||
* | ||
* @implNote This class is not intended to be compared using equals or hashCode. | ||
*/ | ||
@Builder | ||
@ToString(exclude = "items") | ||
public class ApplicationErrorPage implements PaginatedResult { | ||
|
||
@Getter | ||
private final List<ApplicationError> items; | ||
|
||
@Getter | ||
private final long totalCount; | ||
|
||
@Getter | ||
private final int pageNumber; | ||
|
||
@Getter | ||
private final int pageSize; | ||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/org/kiwiproject/dropwizard/error/resource/ApplicationErrorResource.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,115 @@ | ||
package org.kiwiproject.dropwizard.error.resource; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
||
import com.codahale.metrics.annotation.ExceptionMetered; | ||
import com.codahale.metrics.annotation.Timed; | ||
import org.kiwiproject.dropwizard.error.dao.ApplicationErrorDao; | ||
import org.kiwiproject.dropwizard.error.dao.ApplicationErrorStatus; | ||
import org.kiwiproject.dropwizard.error.model.ApplicationError; | ||
import org.kiwiproject.dropwizard.error.model.ApplicationErrorPage; | ||
import org.kiwiproject.jaxrs.KiwiStandardResponses; | ||
|
||
import javax.ws.rs.DefaultValue; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Response; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.OptionalInt; | ||
import java.util.OptionalLong; | ||
|
||
/** | ||
* JAX-RS resource class for retrieving application errors, as well as marking them resolved. | ||
*/ | ||
@Path("/kiwi/application-errors") | ||
@Produces(APPLICATION_JSON) | ||
public class ApplicationErrorResource { | ||
|
||
private final ApplicationErrorDao errorDao; | ||
|
||
public ApplicationErrorResource(ApplicationErrorDao errorDao) { | ||
this.errorDao = errorDao; | ||
} | ||
|
||
/** | ||
* GET endpoint to retrieve an application error by ID. | ||
* | ||
* @param id the ID as a path parameter | ||
* @return the Response | ||
*/ | ||
@GET | ||
@Path("/{id}") | ||
@Timed | ||
@ExceptionMetered | ||
public Response getById(@PathParam("id") OptionalLong id) { | ||
Optional<ApplicationError> errorOptional = errorDao.getById(id.orElseThrow()); | ||
return KiwiStandardResponses.standardGetResponse("id", id, errorOptional, ApplicationError.class); | ||
} | ||
|
||
/** | ||
* GET endpoint to paginate application errors. | ||
* | ||
* @param statusParam status query parameter indicating which application errors to include | ||
* @param pageNumber the page number query parameter, starting from one | ||
* @param pageSize the page size query parameter | ||
* @return the Response | ||
* @see ApplicationErrorStatus | ||
*/ | ||
@GET | ||
@Timed | ||
@ExceptionMetered | ||
public Response getErrors(@QueryParam("status") @DefaultValue("UNRESOLVED") String statusParam, | ||
@QueryParam("pageNumber") @DefaultValue("1") OptionalInt pageNumber, | ||
@QueryParam("pageSize") @DefaultValue("25") OptionalInt pageSize) { | ||
|
||
var status = ApplicationErrorStatus.from(statusParam); | ||
var thePageNumber = pageNumber.orElseThrow(); | ||
var thePageSize = pageSize.orElseThrow(); | ||
var errors = errorDao.getErrors(status, thePageNumber, thePageSize); | ||
var count = errorDao.count(status); | ||
|
||
var appErrors = ApplicationErrorPage.builder() | ||
.pageNumber(thePageNumber) | ||
.pageSize(thePageSize) | ||
.totalCount(count) | ||
.items(errors) | ||
.build(); | ||
|
||
return Response.ok(appErrors).build(); | ||
} | ||
|
||
/** | ||
* Resolve an application error by ID. | ||
* | ||
* @param id the ID path parameter | ||
* @return the Response | ||
*/ | ||
@PUT | ||
@Path("/resolve/{id}") | ||
@Timed | ||
@ExceptionMetered | ||
public Response resolve(@PathParam("id") OptionalLong id) { | ||
var resolvedError = errorDao.resolve(id.orElseThrow()); | ||
return KiwiStandardResponses.standardPutResponse(resolvedError); | ||
} | ||
|
||
/** | ||
* Resolve <em>all</em> unresolved application errors. | ||
* | ||
* @return the Response | ||
*/ | ||
@PUT | ||
@Path("/resolve") | ||
@Timed | ||
@ExceptionMetered | ||
public Response resolveAllUnresolved() { | ||
var count = errorDao.resolveAllUnresolvedErrors(); | ||
var entity = Map.of("resolvedCount", count); | ||
return KiwiStandardResponses.standardPutResponse(entity); | ||
} | ||
} |
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
5 changes: 3 additions & 2 deletions
5
...java/org/kiwiproject/dropwizard/error/dao/jdbi3/PostgresJdbi3ApplicationErrorDaoTest.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
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
Oops, something went wrong.