added swagger auth; fixed connection handling
This commit is contained in:
37
src/main/java/com/poststats/golf/api/BaseApi.java
Normal file
37
src/main/java/com/poststats/golf/api/BaseApi.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.poststats.golf.api;
|
||||
|
||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
|
||||
import io.swagger.v3.oas.annotations.info.Contact;
|
||||
import io.swagger.v3.oas.annotations.info.Info;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityScheme;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
import jakarta.ws.rs.Path;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author brian.long@poststats.com
|
||||
*/
|
||||
@RequestScoped
|
||||
@Path("/")
|
||||
@OpenAPIDefinition(
|
||||
info = @Info(
|
||||
contact = @Contact(name = "Brian Long", email = "brian.long@poststats.com"),
|
||||
title = "PostStats Golf API",
|
||||
description = "An API providing access to PostStats Golf objects.",
|
||||
version = "v1"
|
||||
)
|
||||
)
|
||||
@SecurityScheme(name = "basic", type = SecuritySchemeType.HTTP, scheme = "BASIC")
|
||||
public class BaseApi {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.logger.debug("BaseApi init");
|
||||
}
|
||||
|
||||
}
|
@@ -6,6 +6,7 @@ import com.poststats.golf.service.EventFinanceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
@@ -43,6 +44,7 @@ public class EventFinanceApi {
|
||||
@Path("/balance/persons")
|
||||
@RolesAllowed(Constants.EVENT_ROLE_PREFIX + "member")
|
||||
@Produces(Constants.V1_JSON)
|
||||
@SecurityRequirement(name = "basic")
|
||||
@Operation(summary = "Retrieves the balances of all participants in an event.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Success"),
|
||||
@@ -71,6 +73,7 @@ public class EventFinanceApi {
|
||||
@Path("/balance/persons/csv")
|
||||
@RolesAllowed(Constants.EVENT_ROLE_PREFIX + "finance")
|
||||
@Produces("text/csv")
|
||||
@SecurityRequirement(name = "basic")
|
||||
@Operation(summary = "Retrieves the balances of all participants in an event.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Success"),
|
||||
|
@@ -10,6 +10,7 @@ import com.poststats.transformer.impl.DaoConverter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
@@ -52,6 +53,7 @@ public class EventPersonApi {
|
||||
@Path("/people")
|
||||
@RolesAllowed(Constants.EVENT_ROLE_PREFIX + "member")
|
||||
@Produces(Constants.V1_JSON)
|
||||
@SecurityRequirement(name = "basic")
|
||||
@Operation(summary = "Retrieves limited meta-data about all the participants and administrators in an event.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Success"),
|
||||
@@ -67,6 +69,7 @@ public class EventPersonApi {
|
||||
@Path("/people/detail")
|
||||
@RolesAllowed(Constants.EVENT_ROLE_PREFIX + "member")
|
||||
@Produces(Constants.V1_JSON)
|
||||
@SecurityRequirement(name = "basic")
|
||||
@Operation(summary = "Retrieves detailed meta-data about all the participants and administrators in an event.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Success"),
|
||||
@@ -84,6 +87,7 @@ public class EventPersonApi {
|
||||
@Path("/people/csv")
|
||||
@RolesAllowed(Constants.EVENT_ROLE_PREFIX + "membership")
|
||||
@Produces("text/csv")
|
||||
@SecurityRequirement(name = "basic")
|
||||
@Operation(summary = "Retrieves address book meta-data about all the participants and administrators in an event.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Success"),
|
||||
@@ -114,6 +118,7 @@ public class EventPersonApi {
|
||||
@Path("/participants/csv")
|
||||
@RolesAllowed(Constants.EVENT_ROLE_PREFIX + "membership")
|
||||
@Produces("text/csv")
|
||||
@SecurityRequirement(name = "basic")
|
||||
@Operation(summary = "Retrieves address book meta-data about all the participants in an event.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Success"),
|
||||
@@ -130,6 +135,7 @@ public class EventPersonApi {
|
||||
@Path("/series/participants")
|
||||
@RolesAllowed(Constants.EVENT_ROLE_PREFIX + "membership")
|
||||
@Produces(Constants.V1_JSON)
|
||||
@SecurityRequirement(name = "basic")
|
||||
@Operation(summary = "Retrieves limited meta-data about all the participants in an event series.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Success"),
|
||||
|
@@ -7,10 +7,7 @@ import com.poststats.golf.api.model.Series;
|
||||
import com.poststats.golf.service.EventService;
|
||||
import com.poststats.golf.service.SeriesService;
|
||||
import com.poststats.transformer.impl.DaoConverter;
|
||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.info.Contact;
|
||||
import io.swagger.v3.oas.annotations.info.Info;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -36,13 +33,6 @@ import org.slf4j.LoggerFactory;
|
||||
@RequestScoped
|
||||
@Path("/golf/series/{seriesId}")
|
||||
@Tag(name = "Event Series API")
|
||||
@OpenAPIDefinition(
|
||||
info = @Info(
|
||||
contact = @Contact(name = "Brian Long", email = "brian.long@poststats.com"),
|
||||
title = "PostStats Golf API",
|
||||
description = "An API providing access to PostStats Golf objects."
|
||||
)
|
||||
)
|
||||
public class SeriesApi {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
@@ -1,14 +1,18 @@
|
||||
package com.poststats.golf.provider.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.poststats.golf.provider.GolfProvider;
|
||||
import com.poststats.provider.ConnectionProvider;
|
||||
import com.poststats.provider.DataSourceProvider;
|
||||
import com.poststats.provider.NonTransactionalProvider;
|
||||
import com.poststats.service.ServiceException;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import java.sql.Connection;
|
||||
|
||||
@ApplicationScoped
|
||||
@NonTransactionalProvider
|
||||
@@ -28,7 +32,11 @@ public class DefaultConnectionProvider implements ConnectionProvider {
|
||||
|
||||
@PreDestroy
|
||||
public void release() {
|
||||
this.dsp.get().release(this.dbcon);
|
||||
try {
|
||||
this.dbcon.close();
|
||||
} catch (SQLException se) {
|
||||
throw new ServiceException(se);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,15 +1,19 @@
|
||||
package com.poststats.golf.provider.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.poststats.golf.provider.GolfProvider;
|
||||
import com.poststats.provider.ConnectionProvider;
|
||||
import com.poststats.provider.DataSourceProvider;
|
||||
import com.poststats.provider.TransactionalProvider;
|
||||
import com.poststats.service.ServiceException;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.TransactionScoped;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
|
||||
@TransactionScoped
|
||||
@TransactionalProvider
|
||||
@@ -29,7 +33,11 @@ public class TxConnectionProvider implements ConnectionProvider, Serializable {
|
||||
|
||||
@PreDestroy
|
||||
public void release() {
|
||||
this.dsp.get().release(this.dbcon);
|
||||
try {
|
||||
this.dbcon.close();
|
||||
} catch (SQLException se) {
|
||||
throw new ServiceException(se);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user