From 9627dba9411ae05c8643e7b84993479c3657887e Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Wed, 5 Jul 2023 10:42:10 -0400 Subject: [PATCH] fixed resource-scoped @PathParam --- .../com/poststats/golf/api/CourseApi.java | 16 ++++++---- .../java/com/poststats/golf/api/EventApi.java | 19 ++++++++---- .../poststats/golf/api/EventFinanceApi.java | 23 ++++++++------- .../poststats/golf/api/EventPersonApi.java | 22 +++++++++----- .../com/poststats/golf/api/EventRoundApi.java | 23 ++++++++++----- .../com/poststats/golf/api/GolferApi.java | 12 ++++++-- .../com/poststats/golf/api/SeriesApi.java | 14 ++++++--- .../com/poststats/golf/api/impl/BaseApi.java | 22 -------------- .../poststats/golf/api/impl/CourseApi.java | 23 +++++---------- .../com/poststats/golf/api/impl/EventApi.java | 24 ++++++--------- .../golf/api/impl/EventFinanceApi.java | 29 +++++++------------ .../golf/api/impl/EventPersonApi.java | 21 +++++--------- .../golf/api/impl/EventRoundApi.java | 23 +++++---------- .../poststats/golf/api/impl/GolferApi.java | 17 ++++------- .../poststats/golf/api/impl/SeriesApi.java | 19 ++++-------- 15 files changed, 137 insertions(+), 170 deletions(-) delete mode 100644 src/main/java/com/poststats/golf/api/impl/BaseApi.java diff --git a/src/main/java/com/poststats/golf/api/CourseApi.java b/src/main/java/com/poststats/golf/api/CourseApi.java index a2d7c08..b41fc30 100644 --- a/src/main/java/com/poststats/golf/api/CourseApi.java +++ b/src/main/java/com/poststats/golf/api/CourseApi.java @@ -21,11 +21,17 @@ import jakarta.ws.rs.Produces; @Tag(name = "Course API") @ApiResponse(responseCode = "200", description = "Success") @ApiResponse(responseCode = "404", description = "A golf course with the specified ID could not be found") -public interface CourseApi { +public abstract class CourseApi { @Parameter(description = "A unique identifier for a golf course") + @NotNull + @Positive @PathParam("courseId") - void setCourseId(@NotNull @Positive int courseId); + private int courseId; + + protected int getCourseId() { + return this.courseId; + } @GET @Produces(Constants.V1_JSON) @@ -33,7 +39,7 @@ public interface CourseApi { summary = "Retrieves meta-data about a course.", description = "Retreives name, location, and other direct meta-data about the specified course." ) - Course get(); + public abstract Course get(); @GET @Path("/nine/byName/{name}") @@ -42,7 +48,7 @@ public interface CourseApi { summary = "Retrieves meta-data about a course nine.", description = "Retreives name, location, and other direct meta-data about the specified course." ) - CourseNine getNine(@PathParam("name") String name); + public abstract CourseNine getNine(@PathParam("name") String name); @GET @Path("/nine/{nineId:[0-9]+}") @@ -51,6 +57,6 @@ public interface CourseApi { summary = "Retrieves limited meta-data about a course nine.", description = "Retreives name, location, and other direct meta-data about the specified course." ) - CourseNine getNine(@PathParam("nineId") long courseNineId); + public abstract CourseNine getNine(@PathParam("nineId") long courseNineId); } diff --git a/src/main/java/com/poststats/golf/api/EventApi.java b/src/main/java/com/poststats/golf/api/EventApi.java index ae4619f..af49831 100644 --- a/src/main/java/com/poststats/golf/api/EventApi.java +++ b/src/main/java/com/poststats/golf/api/EventApi.java @@ -20,10 +20,16 @@ import jakarta.ws.rs.Produces; */ @Path("/golf/event/{eventId}") @Tag(name = "Event API") -public interface EventApi { +public abstract class EventApi { + @NotNull + @Positive @PathParam("eventId") - void setEventId(@NotNull @Positive long eventId); + private long eventId; + + protected long getEventId() { + return this.eventId; + } @GET @Produces(Constants.V1_JSON) @@ -35,7 +41,7 @@ public interface EventApi { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - Event get(); + public abstract Event get(); @GET @Path("/detail") @@ -48,7 +54,7 @@ public interface EventApi { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - Event getDetail(); + public abstract Event getDetail(); @POST @Path("/document/{documentId}/send") @@ -68,7 +74,7 @@ public interface EventApi { description = "An event or document with the specified ID could not be found" ) }) - void sendDocument(@PathParam("documentId") long documentId); + public abstract void sendDocument(@PathParam("documentId") long documentId); @POST @Path("/document/{documentId}/sendTest/{personId}") @@ -88,6 +94,7 @@ public interface EventApi { description = "An event, document, or person with the specified ID could not be found" ) }) - void sendTestDocument(@PathParam("documentId") long documentId, @PathParam("personId") long personId); + public abstract void sendTestDocument(@PathParam("documentId") long documentId, + @PathParam("personId") long personId); } diff --git a/src/main/java/com/poststats/golf/api/EventFinanceApi.java b/src/main/java/com/poststats/golf/api/EventFinanceApi.java index b2a9c29..f26c01b 100644 --- a/src/main/java/com/poststats/golf/api/EventFinanceApi.java +++ b/src/main/java/com/poststats/golf/api/EventFinanceApi.java @@ -16,16 +16,20 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.QueryParam; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.SecurityContext; import jakarta.ws.rs.core.StreamingOutput; @Path("/golf/event/{eventId}/finance") @Tag(name = "Event Finance API") -public interface EventFinanceApi { +public abstract class EventFinanceApi { + @NotNull + @Positive @PathParam("eventId") - void setEventId(@NotNull @Positive long eventId); + private long eventId; + + protected long getEventId() { + return this.eventId; + } @GET @Path("/balance/persons") @@ -42,8 +46,8 @@ public interface EventFinanceApi { @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - List> getBalanceByPersonsAsJson(@Context SecurityContext securityContext, - @QueryParam("minBalance") Float minBalance, @QueryParam("maxBalance") Float maxBalance); + public abstract List> getBalanceByPersonsAsJson(@QueryParam("minBalance") Float minBalance, + @QueryParam("maxBalance") Float maxBalance); @GET @Path("/balance/persons/csv") @@ -60,7 +64,7 @@ public interface EventFinanceApi { @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - StreamingOutput getBalanceByPersonsAsCsv(@Context SecurityContext securityContext); + public abstract StreamingOutput getBalanceByPersonsAsCsv(); @GET @Path("/balance/person/{personId}") @@ -80,8 +84,7 @@ public interface EventFinanceApi { description = "An event or person with the specified IDs could not be found" ) }) - Map getBalanceByPersonsAsJson(@Context SecurityContext securityContext, - @PathParam("personId") long personId); + public abstract Map getBalanceByPersonsAsJson(@PathParam("personId") long personId); @GET @Path("/series/balance/persons") @@ -98,6 +101,6 @@ public interface EventFinanceApi { @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - List> getSeriesBalanceByPersonsAsJson(@Context SecurityContext securityContext); + public abstract List> getSeriesBalanceByPersonsAsJson(); } diff --git a/src/main/java/com/poststats/golf/api/EventPersonApi.java b/src/main/java/com/poststats/golf/api/EventPersonApi.java index 080182f..b63d476 100644 --- a/src/main/java/com/poststats/golf/api/EventPersonApi.java +++ b/src/main/java/com/poststats/golf/api/EventPersonApi.java @@ -21,10 +21,16 @@ import jakarta.ws.rs.core.StreamingOutput; @Path("/golf/event/{eventId}") @Tag(name = "Event Participant API") -public interface EventPersonApi { +public abstract class EventPersonApi { + @NotNull + @Positive @PathParam("eventId") - void setEventId(@NotNull @Positive long eventId); + private long eventId; + + protected long getEventId() { + return this.eventId; + } @GET @Path("/people") @@ -41,7 +47,7 @@ public interface EventPersonApi { @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - List get(); + public abstract List get(); @GET @Path("/people/detail") @@ -58,7 +64,7 @@ public interface EventPersonApi { @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - List getDetail(); + public abstract List getDetail(); @GET @Path("/people/csv") @@ -75,7 +81,7 @@ public interface EventPersonApi { @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - StreamingOutput getAsCsv(); + public abstract StreamingOutput getAsCsv(); @GET @Path("/participants") @@ -85,7 +91,7 @@ public interface EventPersonApi { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - List getParticipants(); + public abstract List getParticipants(); @GET @Path("/participants/csv") @@ -102,7 +108,7 @@ public interface EventPersonApi { @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - StreamingOutput getParticipantsAsCsv(); + public abstract StreamingOutput getParticipantsAsCsv(); @GET @Path("/series/participants") @@ -119,6 +125,6 @@ public interface EventPersonApi { @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) - Set getSeriesParticipants(); + public abstract Set getSeriesParticipants(); } diff --git a/src/main/java/com/poststats/golf/api/EventRoundApi.java b/src/main/java/com/poststats/golf/api/EventRoundApi.java index 371e71e..720522e 100644 --- a/src/main/java/com/poststats/golf/api/EventRoundApi.java +++ b/src/main/java/com/poststats/golf/api/EventRoundApi.java @@ -26,10 +26,16 @@ import jakarta.ws.rs.core.StreamingOutput; */ @Path("/golf/event/{eventId}") @Tag(name = "Event Round API") -public interface EventRoundApi { +public abstract class EventRoundApi { + @NotNull + @Positive @PathParam("eventId") - void setEventId(@NotNull @Positive long eventId); + private long eventId; + + protected long getEventId() { + return this.eventId; + } @GET @Path("/rounds/next") @@ -45,7 +51,7 @@ public interface EventRoundApi { description = "An event with the specified ID or upcoming event rounds could not be found" ) }) - List getNext(); + public abstract List getNext(); @GET @Path("/round/{eroundId:[0-9]+}") @@ -61,7 +67,7 @@ public interface EventRoundApi { description = "An event or event round with the specified ID could not be found" ) }) - EventRound getOne(@PathParam("eroundId") long eroundId); + public abstract EventRound getOne(@PathParam("eroundId") long eroundId); @GET @Path("/rounds") @@ -77,7 +83,7 @@ public interface EventRoundApi { description = "An event with the specified ID or any event rounds could not be found" ) }) - List getAll(); + public abstract List getAll(); @GET @Path("/round/{eroundId:[0-9]+}/pairings") @@ -90,7 +96,7 @@ public interface EventRoundApi { description = "An event or its round with the specified ID could not be found" ) }) - List getPairings(@PathParam("eroundId") long eroundId); + public abstract List getPairings(@PathParam("eroundId") long eroundId); @GET @Path("/round/{eroundId:[0-9]+}/pairings/csv") @@ -103,7 +109,7 @@ public interface EventRoundApi { description = "An event or its round with the specified ID could not be found" ) }) - StreamingOutput getPairingsAsCsv(@PathParam("eroundId") long eroundId, + public abstract StreamingOutput getPairingsAsCsv(@PathParam("eroundId") long eroundId, @QueryParam("orderBy") List orderBys, @QueryParam("lastNameFirst") boolean lastNameFirst); @@ -118,6 +124,7 @@ public interface EventRoundApi { description = "An event with the specified ID or upcoming event rounds could not be found" ) }) - EventRoundPairing getPairing(@PathParam("eroundId") long eroundId, @PathParam("pairingID") BigInteger pairingId); + public abstract EventRoundPairing getPairing(@PathParam("eroundId") long eroundId, + @PathParam("pairingID") BigInteger pairingId); } diff --git a/src/main/java/com/poststats/golf/api/GolferApi.java b/src/main/java/com/poststats/golf/api/GolferApi.java index 79e8ce3..fbb2bf5 100644 --- a/src/main/java/com/poststats/golf/api/GolferApi.java +++ b/src/main/java/com/poststats/golf/api/GolferApi.java @@ -19,10 +19,16 @@ import jakarta.ws.rs.Produces; */ @Path("/golfer/{personId}") @Tag(name = "Golfer API") -public interface GolferApi { +public abstract class GolferApi { + @NotNull + @Positive @PathParam("personId") - void setPersonId(@NotNull @Positive long personId); + private long personId; + + protected long getPersonId() { + return this.personId; + } @GET @Produces(Constants.V1_JSON) @@ -34,6 +40,6 @@ public interface GolferApi { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "404", description = "A golfer with the specified ID could not be found") }) - Golfer get(); + public abstract Golfer get(); } diff --git a/src/main/java/com/poststats/golf/api/SeriesApi.java b/src/main/java/com/poststats/golf/api/SeriesApi.java index 59014bf..baa911e 100644 --- a/src/main/java/com/poststats/golf/api/SeriesApi.java +++ b/src/main/java/com/poststats/golf/api/SeriesApi.java @@ -23,10 +23,16 @@ import jakarta.ws.rs.QueryParam; */ @Path("/golf/series/{seriesId}") @Tag(name = "Event Series API") -public interface SeriesApi { +public abstract class SeriesApi { + @NotNull + @Positive @PathParam("seriesId") - void setSeriesId(@NotNull @Positive int seriesId); + private int seriesId; + + protected int getSeriesId() { + return this.seriesId; + } @GET @Produces(Constants.V1_JSON) @@ -38,7 +44,7 @@ public interface SeriesApi { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "404", description = "An event series with the specified ID could not be found") }) - Series get(); + public abstract Series get(); @GET @Path("/events") @@ -51,6 +57,6 @@ public interface SeriesApi { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "404", description = "An event series with the specified ID could not be found") }) - List getEvents(@QueryParam("reverse") Boolean reverse); + public abstract List getEvents(@QueryParam("reverse") Boolean reverse); } diff --git a/src/main/java/com/poststats/golf/api/impl/BaseApi.java b/src/main/java/com/poststats/golf/api/impl/BaseApi.java deleted file mode 100644 index 8fe010f..0000000 --- a/src/main/java/com/poststats/golf/api/impl/BaseApi.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.poststats.golf.api.impl; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import jakarta.annotation.PostConstruct; -import jakarta.enterprise.context.RequestScoped; - -/** - * @author brian.long@poststats.com - */ -@RequestScoped -public class BaseApi implements com.poststats.golf.api.BaseApi { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @PostConstruct - public void init() { - this.logger.debug("BaseApi init"); - } - -} diff --git a/src/main/java/com/poststats/golf/api/impl/CourseApi.java b/src/main/java/com/poststats/golf/api/impl/CourseApi.java index 8b11aa3..23936b4 100644 --- a/src/main/java/com/poststats/golf/api/impl/CourseApi.java +++ b/src/main/java/com/poststats/golf/api/impl/CourseApi.java @@ -13,8 +13,6 @@ import com.poststats.transformer.impl.DaoConverter; import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Positive; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.Response.Status; @@ -22,9 +20,7 @@ import jakarta.ws.rs.core.Response.Status; * @author brian.long@poststats.com */ @RequestScoped -public class CourseApi implements com.poststats.golf.api.CourseApi { - - private int courseId; +public class CourseApi extends com.poststats.golf.api.CourseApi { @Inject private Logger logger; @@ -43,20 +39,15 @@ public class CourseApi implements com.poststats.golf.api.CourseApi { @PostConstruct public void init() { - this.logger.debug("CourseApi init: {}", this.courseId); - } - - @Override - public void setCourseId(@NotNull @Positive int courseId) { - this.courseId = courseId; + this.logger.debug("CourseApi init: {}", this.getCourseId()); } @Override public Course get() { - FlexMap row = this.courseService.get(this.courseId); + FlexMap row = this.courseService.get(this.getCourseId()); if (row == null) throw new WebApplicationException("Course not found", Status.NOT_FOUND); - this.logger.trace("found: {}", this.courseId); + this.logger.trace("found: {}", this.getCourseId()); this.facilityService.inject("facilityID", row, "facility"); return this.converter.convertValue(row, Course.class); @@ -64,10 +55,10 @@ public class CourseApi implements com.poststats.golf.api.CourseApi { @Override public CourseNine getNine(String name) { - FlexMap row = this.courseNineService.getNine(this.courseId, name); + FlexMap row = this.courseNineService.getNine(this.getCourseId(), name); if (row == null) throw new WebApplicationException("Course nine not found", Status.NOT_FOUND); - this.logger.trace("found: {}", this.courseId); + this.logger.trace("found: {}", this.getCourseId()); this.courseService.injectDeep("courseID", row, "course"); return this.converter.convertValue(row, CourseNine.class); @@ -78,7 +69,7 @@ public class CourseApi implements com.poststats.golf.api.CourseApi { FlexMap row = this.courseNineService.getNine(courseNineId); if (row == null) throw new WebApplicationException("Course nine not found", Status.NOT_FOUND); - if (this.courseId != row.getInteger("courseID")) + if (this.getCourseId() != row.getInteger("courseID")) throw new WebApplicationException("Course nine not found", Status.NOT_FOUND); this.logger.trace("found: {}", courseNineId); diff --git a/src/main/java/com/poststats/golf/api/impl/EventApi.java b/src/main/java/com/poststats/golf/api/impl/EventApi.java index b0b2b7b..7ce45aa 100644 --- a/src/main/java/com/poststats/golf/api/impl/EventApi.java +++ b/src/main/java/com/poststats/golf/api/impl/EventApi.java @@ -7,7 +7,6 @@ import java.util.Collections; import java.util.Map; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.brianlong.cache.CacheRetrievalException; import com.brianlong.util.FlexMap; @@ -30,11 +29,10 @@ import jakarta.ws.rs.core.Response.Status; * @author brian.long@poststats.com */ @RequestScoped -public class EventApi implements com.poststats.golf.api.EventApi { +public class EventApi extends com.poststats.golf.api.EventApi { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - private long eventId; + @Inject + private Logger logger; @Inject private EventService eventService; @@ -56,16 +54,12 @@ public class EventApi implements com.poststats.golf.api.EventApi { @PostConstruct public void init() { - this.logger.debug("EventApi init: {}", this.eventId); - } - - public void setEventId(long eventId) { - this.eventId = eventId; + this.logger.debug("EventApi init: {}", this.getEventId()); } @Override public Event get() { - FlexMap row = this.eventService.get(this.eventId); + FlexMap row = this.eventService.get(this.getEventId()); if (row == null) throw new WebApplicationException("Event not found", Status.NOT_FOUND); @@ -75,7 +69,7 @@ public class EventApi implements com.poststats.golf.api.EventApi { @Override public Event getDetail() { - FlexMap row = this.eventService.get(this.eventId); + FlexMap row = this.eventService.get(this.getEventId()); if (row == null) throw new WebApplicationException("Event not found", Status.NOT_FOUND); @@ -85,7 +79,7 @@ public class EventApi implements com.poststats.golf.api.EventApi { @Override public void sendDocument(long documentId) { - FlexMap document = this.eventDocumentService.get(this.eventId, documentId); + FlexMap document = this.eventDocumentService.get(this.getEventId(), documentId); if (document == null) throw new WebApplicationException("Document not found", Status.NOT_FOUND); @@ -104,11 +98,11 @@ public class EventApi implements com.poststats.golf.api.EventApi { @Override public void sendTestDocument(long documentId, long personId) { - FlexMap document = this.eventDocumentService.get(this.eventId, documentId); + FlexMap document = this.eventDocumentService.get(this.getEventId(), documentId); if (document == null) throw new WebApplicationException("Document not found", Status.NOT_FOUND); - FlexMap eperson = this.eventPersonService.get(this.eventId, personId); + FlexMap eperson = this.eventPersonService.get(this.getEventId(), personId); if (eperson == null) throw new WebApplicationException("Person not found", Status.NOT_FOUND); diff --git a/src/main/java/com/poststats/golf/api/impl/EventFinanceApi.java b/src/main/java/com/poststats/golf/api/impl/EventFinanceApi.java index d6185fc..fa3da0f 100644 --- a/src/main/java/com/poststats/golf/api/impl/EventFinanceApi.java +++ b/src/main/java/com/poststats/golf/api/impl/EventFinanceApi.java @@ -17,27 +17,17 @@ import com.poststats.golf.service.EventFinanceService; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; import jakarta.ws.rs.WebApplicationException; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.SecurityContext; import jakarta.ws.rs.core.StreamingOutput; @RequestScoped -public class EventFinanceApi implements com.poststats.golf.api.EventFinanceApi { - - private long eventId; +public class EventFinanceApi extends com.poststats.golf.api.EventFinanceApi { @Inject private EventFinanceService eventFinanceService; @Override - public void setEventId(long eventId) { - this.eventId = eventId; - } - - @Override - public List> getBalanceByPersonsAsJson(@Context SecurityContext securityContext, - Float minBalance, Float maxBalance) { - Map personsBalances = this.eventFinanceService.getPersonsBalances(this.eventId, minBalance, + public List> getBalanceByPersonsAsJson(Float minBalance, Float maxBalance) { + Map personsBalances = this.eventFinanceService.getPersonsBalances(this.getEventId(), minBalance, maxBalance); List> personsBalancesJson = new ArrayList<>(personsBalances.size()); @@ -54,8 +44,8 @@ public class EventFinanceApi implements com.poststats.golf.api.EventFinanceApi { } @Override - public StreamingOutput getBalanceByPersonsAsCsv(@Context SecurityContext securityContext) { - Map personsBalances = this.eventFinanceService.getPersonsBalances(this.eventId); + public StreamingOutput getBalanceByPersonsAsCsv() { + Map personsBalances = this.eventFinanceService.getPersonsBalances(this.getEventId()); return new StreamingOutput() { @Override @@ -82,8 +72,8 @@ public class EventFinanceApi implements com.poststats.golf.api.EventFinanceApi { } @Override - public Map getBalanceByPersonsAsJson(@Context SecurityContext securityContext, long personId) { - DataSet personBalance = this.eventFinanceService.getPersonBalance(this.eventId, personId); + public Map getBalanceByPersonsAsJson(long personId) { + DataSet personBalance = this.eventFinanceService.getPersonBalance(this.getEventId(), personId); Map personBalanceJson = new HashMap<>(5); personBalanceJson.put("personId", personBalance.getLong("personID")); @@ -95,8 +85,9 @@ public class EventFinanceApi implements com.poststats.golf.api.EventFinanceApi { } @Override - public List> getSeriesBalanceByPersonsAsJson(@Context SecurityContext securityContext) { - Map personsBalances = this.eventFinanceService.getSeriesPersonsPreviousBalances(this.eventId); + public List> getSeriesBalanceByPersonsAsJson() { + Map personsBalances = this.eventFinanceService + .getSeriesPersonsPreviousBalances(this.getEventId()); List> personsBalancesJson = new ArrayList<>(personsBalances.size()); for (DataSet personBalance : personsBalances.values()) { diff --git a/src/main/java/com/poststats/golf/api/impl/EventPersonApi.java b/src/main/java/com/poststats/golf/api/impl/EventPersonApi.java index faaa11b..350ea27 100644 --- a/src/main/java/com/poststats/golf/api/impl/EventPersonApi.java +++ b/src/main/java/com/poststats/golf/api/impl/EventPersonApi.java @@ -22,9 +22,7 @@ import jakarta.inject.Inject; import jakarta.ws.rs.core.StreamingOutput; @RequestScoped -public class EventPersonApi implements com.poststats.golf.api.EventPersonApi { - - private long eventId; +public class EventPersonApi extends com.poststats.golf.api.EventPersonApi { @Inject private EventService eventService; @@ -38,45 +36,40 @@ public class EventPersonApi implements com.poststats.golf.api.EventPersonApi { @Inject private DaoConverter converter; - @Override - public void setEventId(long eventId) { - this.eventId = eventId; - } - @Override public List get() { - return this.converter.convertValue(this.eventPersonService.getPeople(this.eventId), EventPerson.class); + return this.converter.convertValue(this.eventPersonService.getPeople(this.getEventId()), EventPerson.class); } @Override public List getDetail() { - List persons = this.eventPersonService.getPeople(this.eventId); + List persons = this.eventPersonService.getPeople(this.getEventId()); this.golferService.injectDeep("personID", persons, "golfer"); return this.converter.convertValue(persons, EventPerson.class); } @Override public StreamingOutput getAsCsv() { - List persons = this.eventPersonService.getPeople(this.eventId); + List persons = this.eventPersonService.getPeople(this.getEventId()); return this.toCsv(persons); } @Override public List getParticipants() { - List participants = this.eventPersonService.getParticipants(this.eventId); + List participants = this.eventPersonService.getParticipants(this.getEventId()); this.golferService.injectDeep("personID", participants, "golfer"); return this.converter.convertValue(participants, EventPerson.class); } @Override public StreamingOutput getParticipantsAsCsv() { - List persons = this.eventPersonService.getParticipants(this.eventId); + List persons = this.eventPersonService.getParticipants(this.getEventId()); return this.toCsv(persons); } @Override public Set getSeriesParticipants() { - int seriesId = this.eventService.getSeriesId(this.eventId); + int seriesId = this.eventService.getSeriesId(this.getEventId()); Set eventIds = this.eventService.getIdsBySeriesId(seriesId); Set personIds = new HashSet<>(); diff --git a/src/main/java/com/poststats/golf/api/impl/EventRoundApi.java b/src/main/java/com/poststats/golf/api/impl/EventRoundApi.java index e4c4917..63c3938 100644 --- a/src/main/java/com/poststats/golf/api/impl/EventRoundApi.java +++ b/src/main/java/com/poststats/golf/api/impl/EventRoundApi.java @@ -16,7 +16,6 @@ import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.brianlong.util.FlexMap; import com.poststats.formatter.PersonFormatter; @@ -42,11 +41,10 @@ import jakarta.ws.rs.core.StreamingOutput; * @author brian.long@poststats.com */ @RequestScoped -public class EventRoundApi implements com.poststats.golf.api.EventRoundApi { +public class EventRoundApi extends com.poststats.golf.api.EventRoundApi { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - private long eventId; + @Inject + private Logger logger; @Inject private PersonService golferService; @@ -65,17 +63,12 @@ public class EventRoundApi implements com.poststats.golf.api.EventRoundApi { @PostConstruct public void init() { - this.logger.debug("EventRoundApi init: {}", this.eventId); - } - - @Override - public void setEventId(long eventId) { - this.eventId = eventId; + this.logger.debug("EventRoundApi init: {}", this.getEventId()); } @Override public List getNext() { - List rows = this.roundService.getUpcoming(this.eventId); + List rows = this.roundService.getUpcoming(this.getEventId()); if (rows == null || rows.isEmpty()) throw new WebApplicationException("No event round was found", Status.NOT_FOUND); @@ -88,9 +81,9 @@ public class EventRoundApi implements com.poststats.golf.api.EventRoundApi { FlexMap row = this.roundService.get(eroundId); if (row == null) throw new WebApplicationException("Event round not found", Status.NOT_FOUND); - if (this.eventId != row.getLong("eventID")) { + if (this.getEventId() != row.getLong("eventID")) { this.logger.warn("The event round {} was requested without the appropriate event ID {}", eroundId, - this.eventId); + this.getEventId()); throw new WebApplicationException("Event round not found", Status.NOT_FOUND); } @@ -100,7 +93,7 @@ public class EventRoundApi implements com.poststats.golf.api.EventRoundApi { @Override public List getAll() { - Map rows = this.roundService.getByEventId(this.eventId); + Map rows = this.roundService.getByEventId(this.getEventId()); if (rows.isEmpty()) throw new WebApplicationException("No event rounds found", Status.NOT_FOUND); diff --git a/src/main/java/com/poststats/golf/api/impl/GolferApi.java b/src/main/java/com/poststats/golf/api/impl/GolferApi.java index 07b1beb..b1b15a3 100644 --- a/src/main/java/com/poststats/golf/api/impl/GolferApi.java +++ b/src/main/java/com/poststats/golf/api/impl/GolferApi.java @@ -1,7 +1,6 @@ package com.poststats.golf.api.impl; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.brianlong.util.FlexMap; import com.poststats.golf.api.model.Golfer; @@ -18,11 +17,10 @@ import jakarta.ws.rs.core.Response.Status; * @author brian.long@poststats.com */ @RequestScoped -public class GolferApi implements com.poststats.golf.api.GolferApi { +public class GolferApi extends com.poststats.golf.api.GolferApi { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - private long personId; + @Inject + private Logger logger; @Inject private PersonService personService; @@ -35,17 +33,12 @@ public class GolferApi implements com.poststats.golf.api.GolferApi { @PostConstruct public void init() { - this.logger.debug("GolferApi init: {}", this.personId); - } - - @Override - public void setPersonId(long personId) { - this.personId = personId; + this.logger.debug("GolferApi init: {}", this.getPersonId()); } @Override public Golfer get() { - FlexMap row = this.personService.get(this.personId); + FlexMap row = this.personService.get(this.getPersonId()); if (row == null) throw new WebApplicationException("Event not found", Status.NOT_FOUND); diff --git a/src/main/java/com/poststats/golf/api/impl/SeriesApi.java b/src/main/java/com/poststats/golf/api/impl/SeriesApi.java index d84970d..55d5269 100644 --- a/src/main/java/com/poststats/golf/api/impl/SeriesApi.java +++ b/src/main/java/com/poststats/golf/api/impl/SeriesApi.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.brianlong.util.FlexMap; import com.poststats.golf.api.model.Event; @@ -24,11 +23,10 @@ import jakarta.ws.rs.core.Response.Status; * @author brian.long@poststats.com */ @RequestScoped -public class SeriesApi implements com.poststats.golf.api.SeriesApi { +public class SeriesApi extends com.poststats.golf.api.SeriesApi { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - private int seriesId; + @Inject + private Logger logger; @Inject private SeriesService seriesService; @@ -41,17 +39,12 @@ public class SeriesApi implements com.poststats.golf.api.SeriesApi { @PostConstruct public void init() { - this.logger.debug("SeriesApi init: {}", this.seriesId); - } - - @Override - public void setSeriesId(int seriesId) { - this.seriesId = seriesId; + this.logger.debug("SeriesApi init: {}", this.getSeriesId()); } @Override public Series get() { - FlexMap row = this.seriesService.get(this.seriesId); + FlexMap row = this.seriesService.get(this.getSeriesId()); if (row == null) throw new WebApplicationException("Series not found", Status.NOT_FOUND); @@ -60,7 +53,7 @@ public class SeriesApi implements com.poststats.golf.api.SeriesApi { @Override public List getEvents(Boolean reverse) { - Map rows = this.eventService.getBySeriesId(this.seriesId); + Map rows = this.eventService.getBySeriesId(this.getSeriesId()); if (rows.isEmpty()) throw new WebApplicationException("Series or events not found", Status.NOT_FOUND);