diff --git a/src/main/java/com/poststats/golf/api/EventApi.java b/src/main/java/com/poststats/golf/api/EventApi.java index 3d1ce07..d645d03 100644 --- a/src/main/java/com/poststats/golf/api/EventApi.java +++ b/src/main/java/com/poststats/golf/api/EventApi.java @@ -111,10 +111,10 @@ public class EventApi { @POST @Path("/document/{documentId}/send") - @RolesAllowed( - Constants.EVENT_ROLE_PREFIX - + "communicate" - ) + @RolesAllowed( + Constants.EVENT_ROLE_PREFIX + + "communicate" + ) @Produces(Constants.V1_JSON) @Operation( summary = "Sends the specified document.", @@ -144,10 +144,10 @@ public class EventApi { @POST @Path("/document/{documentId}/sendTest/{personId}") - @RolesAllowed( - Constants.EVENT_ROLE_PREFIX - + "communicate" - ) + @RolesAllowed( + Constants.EVENT_ROLE_PREFIX + + "communicate" + ) @Produces(Constants.V1_JSON) @Operation( summary = "Sends the specified document to the specified person.", diff --git a/src/main/java/com/poststats/golf/api/EventFinanceApi.java b/src/main/java/com/poststats/golf/api/EventFinanceApi.java index b6b8778..1448f57 100644 --- a/src/main/java/com/poststats/golf/api/EventFinanceApi.java +++ b/src/main/java/com/poststats/golf/api/EventFinanceApi.java @@ -15,6 +15,7 @@ import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.SecurityContext; @@ -48,7 +49,7 @@ public class EventFinanceApi { ) @Produces(Constants.V1_JSON) @SecurityRequirement(name = "basic") - @Operation(summary = "Retrieves the balances of all participants in an event.") + @Operation(summary = "Retrieves the balances of all persons associated with an event.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "401", description = "Not authenticated"), @@ -56,8 +57,11 @@ public class EventFinanceApi { @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") }) public List> getBalanceByPersonsAsJson(@Context - SecurityContext securityContext) throws JsonProcessingException { - Map personsBalances = this.eventFinanceService.getPersonsBalances(this.eventId); + SecurityContext securityContext, @QueryParam("minBalance") + Float minBalance, @QueryParam("maxBalance") + Float maxBalance) throws JsonProcessingException { + Map personsBalances = this.eventFinanceService.getPersonsBalances(this.eventId, minBalance, + maxBalance); List> personsBalancesJson = new ArrayList<>(personsBalances.size()); for (DataSet personBalance : personsBalances.values()) { @@ -80,7 +84,7 @@ public class EventFinanceApi { ) @Produces("text/csv") @SecurityRequirement(name = "basic") - @Operation(summary = "Retrieves the balances of all participants in an event.") + @Operation(summary = "Retrieves the balances of all persons associated with an event.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "401", description = "Not authenticated"), @@ -115,4 +119,68 @@ public class EventFinanceApi { }; } + @GET + @Path("/balance/person/{personId}") + @RolesAllowed( + Constants.EVENT_ROLE_PREFIX + + "member" + ) + @Produces(Constants.V1_JSON) + @SecurityRequirement(name = "basic") + @Operation(summary = "Retrieves the balance of a person in an event.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "Success"), + @ApiResponse(responseCode = "401", description = "Not authenticated"), + @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), + @ApiResponse( + responseCode = "404", + description = "An event or person with the specified IDs could not be found" + ) + }) + public Map getBalanceByPersonsAsJson(@Context + SecurityContext securityContext, @PathParam("personId") + long personId) throws JsonProcessingException { + DataSet personBalance = this.eventFinanceService.getPersonBalance(this.eventId, personId); + + Map personBalanceJson = new HashMap<>(5); + personBalanceJson.put("personId", personBalance.getLong("personID")); + personBalanceJson.put("expense", personBalance.getFloat("expense")); + personBalanceJson.put("paid", personBalance.getFloat("paid")); + personBalanceJson.put("balance", personBalance.getFloat("balance")); + + return personBalanceJson; + } + + @GET + @Path("/series/balance/persons") + @RolesAllowed( + Constants.EVENT_ROLE_PREFIX + + "member" + ) + @Produces(Constants.V1_JSON) + @SecurityRequirement(name = "basic") + @Operation(summary = "Retrieves the cumulative balances of all persons associated with a series prior to an event.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "Success"), + @ApiResponse(responseCode = "401", description = "Not authenticated"), + @ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"), + @ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found") + }) + public List> getSeriesBalanceByPersonsAsJson(@Context + SecurityContext securityContext) throws JsonProcessingException { + Map personsBalances = this.eventFinanceService.getSeriesPersonsPreviousBalances(this.eventId); + + List> personsBalancesJson = new ArrayList<>(personsBalances.size()); + for (DataSet personBalance : personsBalances.values()) { + Map personBalanceJson = new HashMap<>(5); + personBalanceJson.put("personId", personBalance.getLong("personID")); + personBalanceJson.put("expense", personBalance.getFloat("expense")); + personBalanceJson.put("paid", personBalance.getFloat("paid")); + personBalanceJson.put("balance", personBalance.getFloat("balance")); + personsBalancesJson.add(personBalanceJson); + } + + return personsBalancesJson; + } + } diff --git a/src/main/java/com/poststats/golf/service/EventFinanceService.java b/src/main/java/com/poststats/golf/service/EventFinanceService.java index e523e50..7d8943a 100644 --- a/src/main/java/com/poststats/golf/service/EventFinanceService.java +++ b/src/main/java/com/poststats/golf/service/EventFinanceService.java @@ -1,79 +1,81 @@ package com.poststats.golf.service; -import java.util.Map; - import com.brianlong.sql.DataSet; +import java.util.Map; /** * This service provides financial metadata about the event, series, associated * people, or a combination of those. - * - * The balance metadata includes money `paid`, `expenses`, and `balance`. The + * + * The balance metadata includes money `paid`, `expenses`, and `balance`. The * balance numerically consistent with the perspective of the person, not the - * event organizers. That means it is positive when the person paid more than + * event organizers. That means it is positive when the person paid more than * they should owe and negative if they owe money. - * + * * @author brian */ public interface EventFinanceService { - /** - * Computes and retrieves the person balances for those associated with the - * specified event. - * - * @param eventId The unique identifier of an event. - * @return A map of `personId` to balance metadata. - */ - Map getPersonsBalances(long eventId); - - /** - * Computes and retrieves the person balances for those associated with the - * specified event. - * - * @param eventId The unique identifier of an event. - * @param minBalance The minimum balance for returned balances; `0.01` for those that have paid more than they owe; `null` for no constraint. - * @param maxBalance The maximum balance for returned balances; `-0.01` for those that owe; `null` for no constraint. - * @return A map of `personId` to balance metadata. - */ + /** + * Computes and retrieves the person balances for those associated with the + * specified event. + * + * @param eventId The unique identifier of an event. + * @return A map of `personId` to balance metadata. + */ + Map getPersonsBalances(long eventId); + + /** + * Computes and retrieves the person balances for those associated with the + * specified event. + * + * @param eventId The unique identifier of an event. + * @param minBalance The minimum balance for returned balances; `0.01` for those + * that have paid more than they owe; `null` for no + * constraint. + * @param maxBalance The maximum balance for returned balances; `-0.01` for + * those that owe; `null` for no constraint. + * @return A map of `personId` to balance metadata. + */ Map getPersonsBalances(long eventId, Float minBalance, Float maxBalance); - /** - * Computes and retrieves the specified person's balance for the specified - * event. - * - * @param eventId The unique identifier of an event. - * @param personId The unique identifier of a person. - * @return Balance metadata. - */ - DataSet getPersonBalance(long eventId, long personId); + /** + * Computes and retrieves the specified person's balance for the specified + * event. + * + * @param eventId The unique identifier of an event. + * @param personId The unique identifier of a person. + * @return Balance metadata. + */ + DataSet getPersonBalance(long eventId, long personId); - /** - * Computes and retrieves all associated persons' cumulative balance for - * all events in the series before the specified event. - * - * @param eventId The unique identifier of an event. - * @return A map of `personId` to balance metadata. - */ - Map getSeriesPersonsBalances(long eventId); + /** + * Computes and retrieves all associated persons' cumulative balance for all + * events in the series before the specified event. + * + * @param eventId The unique identifier of an event. + * @return A map of `personId` to balance metadata. + */ + Map getSeriesPersonsPreviousBalances(long eventId); - /** - * Computes and retrieves the specified person's balances for all events in - * the specified series. - * - * @param seriesId The unique identifier of a series. - * @param personId The unique identifier of a person. - * @return A map of `eventId` to balance metadata. - */ - Map getSeriesPersonBalances(int seriesId, long personId); + /** + * Computes and retrieves the specified person's balances for all events in the + * specified series. + * + * @param seriesId The unique identifier of a series. + * @param personId The unique identifier of a person. + * @return A map of `eventId` to balance metadata. + */ + Map getSeriesPersonBalances(int seriesId, long personId); - /** - * Computes and retrieves the specified person's balances for all events in - * the series before the specified event. - * - * @param eventId The unique identifier of an event. - * @param personId The unique identifier of a person. - * @return A map of `eventId` to balance metadata. - */ - Map getSeriesPersonPreviousBalances(long eventId, long personId); + /** + * Computes and retrieves the specified person's balances for all events in the + * series before the specified event. + * + * @param eventId The unique identifier of an event. + * @param personId The unique identifier of a person. + * @return A map of `eventId` to balance metadata. + */ + Map getSeriesPersonPreviousBalances(long eventId, long personId); } diff --git a/src/main/java/com/poststats/golf/service/db/EventFinanceServiceDAO.java b/src/main/java/com/poststats/golf/service/db/EventFinanceServiceDAO.java index 4627f85..d7763d4 100644 --- a/src/main/java/com/poststats/golf/service/db/EventFinanceServiceDAO.java +++ b/src/main/java/com/poststats/golf/service/db/EventFinanceServiceDAO.java @@ -1,9 +1,5 @@ package com.poststats.golf.service.db; -import java.sql.SQLException; -import java.time.LocalDate; -import java.util.Map; - import com.brianlong.sql.DataSet; import com.brianlong.sql.FlexPreparedStatement; import com.brianlong.util.FlexMap; @@ -14,20 +10,22 @@ import com.poststats.provider.NonTransactionalProvider; import com.poststats.provider.Statement; import com.poststats.provider.StatementProvider; import com.poststats.service.ServiceException; - import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import java.sql.SQLException; +import java.time.LocalDate; +import java.util.Map; @ApplicationScoped public class EventFinanceServiceDAO implements EventFinanceService { - - @Inject - private EventService eventService; - @Override - public Map getPersonsBalances(long eventId) { - return this.getPersonsBalances(eventId, null, null); - } + @Inject + private EventService eventService; + + @Override + public Map getPersonsBalances(long eventId) { + return this.getPersonsBalances(eventId, null, null); + } @Override public Map getPersonsBalances(long eventId, Float minBalance, Float maxBalance) { @@ -36,8 +34,8 @@ public class EventFinanceServiceDAO implements EventFinanceService { try { for (int i = 1; i <= 5; i++) fps.setIntegerU(i, eventId); - fps.setFloat(6, minBalance == null ? Float.NEGATIVE_INFINITY : minBalance); - fps.setFloat(7, maxBalance == null ? Float.POSITIVE_INFINITY : maxBalance); + fps.setFloat(6, minBalance == null ? -1e20f : minBalance); + fps.setFloat(7, maxBalance == null ? 1e20f : maxBalance); return fps.executeQuery().getAllRows("personID", Long.class); } finally { fps.close(); @@ -47,124 +45,124 @@ public class EventFinanceServiceDAO implements EventFinanceService { } } - @Override - public DataSet getPersonBalance(long eventId, long personId) { - try { - FlexPreparedStatement fps = this.sqlSelectPersonBalances.buildPreparedStatement(); - try { - for (int i = 1; i <= 10; i += 2) { - fps.setIntegerU(i, eventId); - fps.setIntegerU(i+1, personId); - } - return fps.executeQuery().getNextRow(); - } finally { - fps.close(); - } - } catch (SQLException se) { - throw new ServiceException(se); - } - } + @Override + public DataSet getPersonBalance(long eventId, long personId) { + try { + FlexPreparedStatement fps = this.sqlSelectPersonBalances.buildPreparedStatement(); + try { + for (int i = 1; i <= 10; i += 2) { + fps.setIntegerU(i, eventId); + fps.setIntegerU(i + 1, personId); + } + return fps.executeQuery().getNextRow(); + } finally { + fps.close(); + } + } catch (SQLException se) { + throw new ServiceException(se); + } + } - @Override - public Map getSeriesPersonsBalances(long eventId) { - FlexMap event = this.eventService.get(eventId); - int seriesId = event.getInteger("seriesID"); - LocalDate liveline = event.getDate("liveline"); - - try { - FlexPreparedStatement fps = this.sqlSelectSeriesBalances.buildPreparedStatement(); - try { - for (int i = 1; i <= 15; i += 3) { - fps.setSmallintU(i, seriesId); - fps.setIntegerU(i+1, eventId); - fps.setDate(i+2, liveline); - } - return fps.executeQuery().getAllRows("personID", Long.class); - } finally { - fps.close(); - } - } catch (SQLException se) { - throw new ServiceException(se); - } - } + @Override + public Map getSeriesPersonsPreviousBalances(long eventId) { + FlexMap event = this.eventService.get(eventId); + int seriesId = event.getInteger("seriesID"); + LocalDate liveline = event.getDate("liveline"); - @Override - public Map getSeriesPersonBalances(int seriesId, long personId) { - return this.getSeriesPersonBalances(seriesId, null, null, personId); - } + try { + FlexPreparedStatement fps = this.sqlSelectSeriesBalances.buildPreparedStatement(); + try { + for (int i = 1; i <= 15; i += 3) { + fps.setSmallintU(i, seriesId); + fps.setIntegerU(i + 1, eventId); + fps.setDate(i + 2, liveline); + } + return fps.executeQuery().getAllRows("personID", Long.class); + } finally { + fps.close(); + } + } catch (SQLException se) { + throw new ServiceException(se); + } + } - @Override - public Map getSeriesPersonPreviousBalances(long eventId, long personId) { - FlexMap event = this.eventService.get(eventId); - int seriesId = event.getInteger("seriesID"); - LocalDate liveline = event.getDate("liveline"); - return this.getSeriesPersonBalances(seriesId, eventId, liveline, personId); - } - - private Map getSeriesPersonBalances(int seriesId, Long eventId, LocalDate liveline, long personId) { - if (eventId == null) - eventId = -1L; - if (liveline == null) - liveline = LocalDate.now().plusYears(10L); - - try { - FlexPreparedStatement fps = this.sqlSelectSeriesPersonEventBalances.buildPreparedStatement(); - try { - for (int i = 1; i <= 20; i += 4) { - fps.setSmallintU(i, seriesId); - fps.setIntegerU(i+1, eventId); - fps.setDate(i+2, liveline); - fps.setIntegerU(i+3, personId); - } - return fps.executeQuery().getAllRows("personID", Long.class); - } finally { - fps.close(); - } - } catch (SQLException se) { - throw new ServiceException(se); - } - } + @Override + public Map getSeriesPersonBalances(int seriesId, long personId) { + return this.getSeriesPersonBalances(seriesId, null, null, personId); + } - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement( - sql = "SELECT TT.personID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance " - + "FROM (" - + " SELECT ALL EP.personID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid " - + " FROM ~g~.EventPerson EP " - + " LEFT JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) " - + " WHERE EP.eventID=? " - + " UNION ALL " - + " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid " - + " FROM ~g~.EventPerson EP " - + " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) " - + " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) " - + " WHERE EP.eventID=? AND EPO.answer='Y' AND EO.amount IS NOT NULL AND EO.waive IS FALSE " - + " UNION ALL " - + " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid " - + " FROM ~g~.EventPerson EP " - + " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) " - + " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) " - + " WHERE EP.eventID=? AND EPO.itemID IS NOT NULL " - + " AND (EO.multiple IS FALSE OR EO.funded='option' OR EO.static IS NOT NULL) " - + " AND EO.amount IS NOT NULL AND EO.waive IS FALSE " - + " UNION ALL " - + " SELECT ALL EP.personID, EP.epersonID, EOI.amount expenses, 0 paid " - + " FROM ~g~.EventPerson EP " - + " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) " - + " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) " - + " INNER JOIN ~g~.EventOptionItem EOI ON (EPO.itemID=EOI.itemID) " - + " WHERE EP.eventID=? AND EO.waive IS FALSE AND EO.funded='selection' AND EOI.amount IS NOT NULL " - + " UNION ALL " - + " SELECT ALL EPP.personID, EP.epersonID, 0 expenses, EPP.amount paid " - + " FROM ~g~.EventPersonPayment EPP " - + " LEFT JOIN ~g~.EventPerson EP ON (EPP.eventID=EP.eventID AND EPP.personID=EP.personID) " - + " WHERE EPP.eventID=?) TT " - + "GROUP BY TT.personID " - + "HAVING (SUM(TT.paid)-SUM(TT.expenses))>=? AND (SUM(TT.paid)-SUM(TT.expenses))<=? " - ) - private StatementProvider sqlSelectBalances; + @Override + public Map getSeriesPersonPreviousBalances(long eventId, long personId) { + FlexMap event = this.eventService.get(eventId); + int seriesId = event.getInteger("seriesID"); + LocalDate liveline = event.getDate("liveline"); + return this.getSeriesPersonBalances(seriesId, eventId, liveline, personId); + } + + private Map getSeriesPersonBalances(int seriesId, Long eventId, LocalDate liveline, long personId) { + if (eventId == null) + eventId = -1L; + if (liveline == null) + liveline = LocalDate.now().plusYears(10L); + + try { + FlexPreparedStatement fps = this.sqlSelectSeriesPersonEventBalances.buildPreparedStatement(); + try { + for (int i = 1; i <= 20; i += 4) { + fps.setSmallintU(i, seriesId); + fps.setIntegerU(i + 1, eventId); + fps.setDate(i + 2, liveline); + fps.setIntegerU(i + 3, personId); + } + return fps.executeQuery().getAllRows("personID", Long.class); + } finally { + fps.close(); + } + } catch (SQLException se) { + throw new ServiceException(se); + } + } + + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement( + sql = "SELECT TT.personID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance " + + "FROM (" + + " SELECT ALL EP.personID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid " + + " FROM ~g~.EventPerson EP " + + " LEFT JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) " + + " WHERE EP.eventID=? " + + " UNION ALL " + + " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid " + + " FROM ~g~.EventPerson EP " + + " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) " + + " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) " + + " WHERE EP.eventID=? AND EPO.answer='Y' AND EO.amount IS NOT NULL AND EO.waive IS FALSE " + + " UNION ALL " + + " SELECT ALL EP.personID, EP.epersonID, EO.amount expenses, 0 paid " + + " FROM ~g~.EventPerson EP " + + " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) " + + " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) " + + " WHERE EP.eventID=? AND EPO.itemID IS NOT NULL " + + " AND (EO.multiple IS FALSE OR EO.funded='option' OR EO.static IS NOT NULL) " + + " AND EO.amount IS NOT NULL AND EO.waive IS FALSE " + + " UNION ALL " + + " SELECT ALL EP.personID, EP.epersonID, EOI.amount expenses, 0 paid " + + " FROM ~g~.EventPerson EP " + + " INNER JOIN ~g~.EventPersonOption EPO ON (EP.epersonID=EPO.epersonID) " + + " INNER JOIN ~g~.EventOption EO ON (EPO.optionID=EO.optionID) " + + " INNER JOIN ~g~.EventOptionItem EOI ON (EPO.itemID=EOI.itemID) " + + " WHERE EP.eventID=? AND EO.waive IS FALSE AND EO.funded='selection' AND EOI.amount IS NOT NULL " + + " UNION ALL " + + " SELECT ALL EPP.personID, EP.epersonID, 0 expenses, EPP.amount paid " + + " FROM ~g~.EventPersonPayment EPP " + + " LEFT JOIN ~g~.EventPerson EP ON (EPP.eventID=EP.eventID AND EPP.personID=EP.personID) " + + " WHERE EPP.eventID=?) TT " + + "GROUP BY TT.personID " + + "HAVING (SUM(TT.paid)-SUM(TT.expenses))>=? AND (SUM(TT.paid)-SUM(TT.expenses))<=? " + ) + private StatementProvider sqlSelectBalances; @Inject @NonTransactionalProvider @@ -205,96 +203,96 @@ public class EventFinanceServiceDAO implements EventFinanceService { ) private StatementProvider sqlSelectPersonBalances; - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement( - sql = "SELECT TT.personID, TT.epersonID, SUM(TT.expenses) expenses, SUM(TT.paid) paid, (SUM(TT.paid)-SUM(TT.expenses)) balance " - + "FROM (" - + " SELECT ALL EP.personID, EP.epersonID, IF(EB.projectedValue IS NULL, 0, EB.projectedValue) expenses, 0 paid " - + " FROM ~g~.Event E " - + " INNER JOIN ~g~.EventPerson EP ON (E.eventID=EP.eventID) " - + " INNER JOIN ~g~.EventBudget EB ON (EP.eventID=EB.eventID) " - + " WHERE E.seriesID=? AND E.eventID<>? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline? AND E.liveline implements EventPersonService { - - @Inject - private EventFinanceService eventFinanceService; + + @Inject + private EventFinanceService eventFinanceService; @Override public FlexMap get(long eventId, long personId) { @@ -185,173 +183,188 @@ public class EventPersonServiceDAO extends CacheableServiceDAO imple + "WHERE ECL.eventID=? AND ECL.listID=? " ) private StatementProvider sqlSelectByListId; - - public List getByAutolist(long eventId, String autolist) { - switch (autolist) { - case "balance": - Map balances = this.eventFinanceService.getPersonsBalances(eventId, null, -0.01f); - return new ArrayList<>(balances.values()); - default: - } - - StatementProvider statementProvider = this.getStatementProviderByAutolist(autolist); - try { - FlexPreparedStatement fps = this.getStatementByAutolist(statementProvider, eventId, autolist); - try { - return fps.executeQuery().getAllRows(); - } finally { - fps.close(); - } - } catch (SQLException se) { - throw new ServiceException(se); - } - } - private StatementProvider getStatementProviderByAutolist(String autolist) { - switch (autolist) { - case "all": - return this.sqlSelectEventAllIds; - case "signed": - return this.sqlSelectEventParticipantIds; - case "unsigned": - return this.sqlSelectEventRumormillIds; - case "rookies": - return this.sqlSelectEventRookieIds; - case "rookies-refs": - return this.sqlSelectEventRookieReferralIds; - case "options": - return this.sqlSelectEventParticipantIdsWithUnansweredOptions; - default: - } + public List getByAutolist(long eventId, String autolist) { + switch (autolist) { + case "balance": + Map balances = this.eventFinanceService.getPersonsBalances(eventId, null, -0.01f); + return new ArrayList<>(balances.values()); + default: + } - if (autolist.startsWith("previous")) { - if (autolist.length() > "previous".length()) { - return this.sqlSelectRecentSeriesParticipantIds; - } else { - return this.sqlSelectSeriesParticipantIds; - } - } else { - throw new IllegalArgumentException(); - } - } + StatementProvider statementProvider = this.getStatementProviderByAutolist(autolist); + try { + FlexPreparedStatement fps = this.getStatementByAutolist(statementProvider, eventId, autolist); + try { + return fps.executeQuery().getAllRows(); + } finally { + fps.close(); + } + } catch (SQLException se) { + throw new ServiceException(se); + } + } - private FlexPreparedStatement getStatementByAutolist(StatementProvider statementProvider, long eventId, String autolist) throws SQLException { - int weeks = -1; - if (autolist.startsWith("previous") && autolist.length() > "previous".length()) - weeks = Integer.parseInt(autolist.substring("previous".length() + 1)); + private StatementProvider getStatementProviderByAutolist(String autolist) { + switch (autolist) { + case "all": + return this.sqlSelectEventAllIds; + case "signed": + return this.sqlSelectEventParticipantIds; + case "unsigned": + return this.sqlSelectEventRumormillIds; + case "rookies": + return this.sqlSelectEventRookieIds; + case "rookies-refs": + return this.sqlSelectEventRookieReferralIds; + case "options": + return this.sqlSelectEventParticipantIdsWithUnansweredOptions; + default: + } - FlexPreparedStatement fps = statementProvider.buildPreparedStatement(); - try { - int c = 1; - fps.setIntegerU(c++, eventId); - if (weeks >= 0) { - fps.setIntegerU(c++, eventId); - fps.setSmallintU(c++, weeks); - fps.setSmallintU(c++, weeks); - } - if (autolist.equals("all") || autolist.equals("rookies-refs") || autolist.startsWith("previous")) { - fps.setIntegerU(c++, eventId); - } - - return fps; - } catch (SQLException se) { - fps.close(); - throw se; - } - } + if (autolist.startsWith("previous")) { + if (autolist.length() > "previous".length()) { + return this.sqlSelectRecentSeriesParticipantIds; + } else { + return this.sqlSelectSeriesParticipantIds; + } + } else { + throw new IllegalArgumentException(); + } + } - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT personID, epersonID FROM ~g~.EventPerson WHERE eventID=?") - private StatementProvider sqlSelectEventParticipantIds; + private FlexPreparedStatement getStatementByAutolist(StatementProvider statementProvider, long eventId, + String autolist) throws SQLException { + int weeks = -1; + if (autolist.startsWith("previous") && autolist.length() > "previous".length()) + weeks = Integer.parseInt(autolist.substring("previous".length() + 1)); - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT personID, NULL epersonID FROM ~g~.EventPersonContract WHERE eventID=?") - private StatementProvider sqlSelectEventRumormillIds; + FlexPreparedStatement fps = statementProvider.buildPreparedStatement(); + try { + int c = 1; + fps.setIntegerU(c++, eventId); + if (weeks >= 0) { + fps.setIntegerU(c++, eventId); + fps.setSmallintU(c++, weeks); + fps.setSmallintU(c++, weeks); + } + if (autolist.equals("all") || autolist.equals("rookies-refs") || autolist.startsWith("previous")) { + fps.setIntegerU(c++, eventId); + } - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT personID, epersonID FROM ~g~.EventPerson WHERE eventID=? " - + "UNION " - + "SELECT personID, NULL epersonID FROM ~g~.EventPersonContract WHERE eventID=? ") - private StatementProvider sqlSelectEventAllIds; + return fps; + } catch (SQLException se) { + fps.close(); + throw se; + } + } - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT DISTINCT EP.personID, EP.epersonID " - + "FROM ~g~.EventPerson EP " - + " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) " - + "WHERE EP.eventID=? AND EP2.epersonID IS NULL") - private StatementProvider sqlSelectEventRookieIds; + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement(sql = "SELECT personID, epersonID FROM ~g~.EventPerson WHERE eventID=?") + private StatementProvider sqlSelectEventParticipantIds; - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT DISTINCT EP.personID " - + "FROM ~g~.EventPerson EP " - + " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) " - + "WHERE EP.eventID=? AND EP2.epersonID IS NULL " - + "UNION " - + "SELECT DISTINCT P.referralPersonID " - + "FROM ~g~.EventPerson EP " - + " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) " - + " INNER JOIN ~p~.Person P ON (EP.personID=P.personID) " - + "WHERE EP.eventID=? AND EP2.epersonID IS NULL AND P.referralPersonID IS NOT NULL") - private StatementProvider sqlSelectEventRookieReferralIds; + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement(sql = "SELECT personID, NULL epersonID FROM ~g~.EventPersonContract WHERE eventID=?") + private StatementProvider sqlSelectEventRumormillIds; - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT EP.personID, EP.epersonID " - + "FROM ~g~.EventPerson EP " - + " INNER JOIN ?TT? TT1 ON (EP.personID=TT1.personID) " - + "WHERE EP.eventID=? " - + "GROUP BY EP.personID HAVING SUM(TT1.balance) < 0 ") - private StatementProvider sqlSelectEventParticipantIdsWithBalance; + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement( + sql = "SELECT personID, epersonID FROM ~g~.EventPerson WHERE eventID=? " + + "UNION " + + "SELECT personID, NULL epersonID FROM ~g~.EventPersonContract WHERE eventID=? " + ) + private StatementProvider sqlSelectEventAllIds; - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT DISTINCT EP.personID, EP.epersonID " - + "FROM ~g~.EventOption EO " - + " INNER JOIN ~g~.EventPerson EP ON (EO.eventID=EP.eventID) " - + " LEFT JOIN ~g~.EventPersonOption EPO ON (EO.optionID=EPO.optionID AND EP.epersonID=EPO.epersonID) " - + "WHERE EO.eventID=? " - + " AND (EO.liveline IS NULL OR EO.liveline<=CURRENT_DATE) " - + " AND (EO.deadline IS NULL OR EO.deadline>=CURRENT_DATE) " - + " AND EPO.optionID IS NULL ") - private StatementProvider sqlSelectEventParticipantIdsWithUnansweredOptions; + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement( + sql = "SELECT DISTINCT EP.personID, EP.epersonID " + + "FROM ~g~.EventPerson EP " + + " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) " + + "WHERE EP.eventID=? AND EP2.epersonID IS NULL" + ) + private StatementProvider sqlSelectEventRookieIds; - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT DISTINCT EP.personID " - + "FROM ~g~.Event E " - + " INNER JOIN ~g~.Event E2 ON (E.seriesID=E2.seriesID) " - + " INNER JOIN ~g~.EventPerson EP ON (E2.eventID=EP.eventID) " - + "WHERE E.eventID=? AND E2.eventID<>? " - + "UNION DISTINCT " - + "SELECT personID FROM ~g~.EventPersonContract WHERE eventID=? ") - private StatementProvider sqlSelectSeriesParticipantIds; + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement( + sql = "SELECT DISTINCT EP.personID " + + "FROM ~g~.EventPerson EP " + + " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) " + + "WHERE EP.eventID=? AND EP2.epersonID IS NULL " + + "UNION " + + "SELECT DISTINCT P.referralPersonID " + + "FROM ~g~.EventPerson EP " + + " LEFT JOIN ~g~.EventPerson EP2 ON (EP.eventID<>EP2.eventID AND EP.personID=EP2.personID) " + + " INNER JOIN ~p~.Person P ON (EP.personID=P.personID) " + + "WHERE EP.eventID=? AND EP2.epersonID IS NULL AND P.referralPersonID IS NOT NULL" + ) + private StatementProvider sqlSelectEventRookieReferralIds; - @Inject - @NonTransactionalProvider - @GolfProvider - @Statement(sql = "SELECT DISTINCT EP.personID " - + "FROM ~g~.Event E " - + " INNER JOIN ~g~.Event E2 ON (E.seriesID=E2.seriesID) " - + " INNER JOIN ~g~.EventPerson EP ON (E2.eventID=EP.eventID) " - + "WHERE E.eventID=? AND E2.eventID<>? " - + " AND ((E2.deadline IS NOT NULL AND DATE_ADD(E2.deadline, INTERVAL ? WEEK)>=CURRENT_DATE) " - + " OR (E2.liveline IS NOT NULL AND DATE_ADD(E2.liveline, INTERVAL ? WEEK)>=CURRENT_DATE)) " - + "UNION DISTINCT " - + "SELECT personID FROM ~g~.EventPersonContract WHERE eventID=? ") - private StatementProvider sqlSelectRecentSeriesParticipantIds; + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement( + sql = "SELECT EP.personID, EP.epersonID " + + "FROM ~g~.EventPerson EP " + + " INNER JOIN ?TT? TT1 ON (EP.personID=TT1.personID) " + + "WHERE EP.eventID=? " + + "GROUP BY EP.personID HAVING SUM(TT1.balance) < 0 " + ) + private StatementProvider sqlSelectEventParticipantIdsWithBalance; + + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement( + sql = "SELECT DISTINCT EP.personID, EP.epersonID " + + "FROM ~g~.EventOption EO " + + " INNER JOIN ~g~.EventPerson EP ON (EO.eventID=EP.eventID) " + + " LEFT JOIN ~g~.EventPersonOption EPO ON (EO.optionID=EPO.optionID AND EP.epersonID=EPO.epersonID) " + + "WHERE EO.eventID=? " + + " AND (EO.liveline IS NULL OR EO.liveline<=CURRENT_DATE) " + + " AND (EO.deadline IS NULL OR EO.deadline>=CURRENT_DATE) " + + " AND EPO.optionID IS NULL " + ) + private StatementProvider sqlSelectEventParticipantIdsWithUnansweredOptions; + + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement( + sql = "SELECT DISTINCT EP.personID " + + "FROM ~g~.Event E " + + " INNER JOIN ~g~.Event E2 ON (E.seriesID=E2.seriesID) " + + " INNER JOIN ~g~.EventPerson EP ON (E2.eventID=EP.eventID) " + + "WHERE E.eventID=? AND E2.eventID<>? " + + "UNION DISTINCT " + + "SELECT personID FROM ~g~.EventPersonContract WHERE eventID=? " + ) + private StatementProvider sqlSelectSeriesParticipantIds; + + @Inject + @NonTransactionalProvider + @GolfProvider + @Statement( + sql = "SELECT DISTINCT EP.personID " + + "FROM ~g~.Event E " + + " INNER JOIN ~g~.Event E2 ON (E.seriesID=E2.seriesID) " + + " INNER JOIN ~g~.EventPerson EP ON (E2.eventID=EP.eventID) " + + "WHERE E.eventID=? AND E2.eventID<>? " + + " AND ((E2.deadline IS NOT NULL AND DATE_ADD(E2.deadline, INTERVAL ? WEEK)>=CURRENT_DATE) " + + " OR (E2.liveline IS NOT NULL AND DATE_ADD(E2.liveline, INTERVAL ? WEEK)>=CURRENT_DATE)) " + + "UNION DISTINCT " + + "SELECT personID FROM ~g~.EventPersonContract WHERE eventID=? " + ) + private StatementProvider sqlSelectRecentSeriesParticipantIds; @Override protected DataSet fetchOne(BigInteger epersonId) throws SQLException {