From f5f06a1ba05f9a05d2f8e4d1b9d3574a40b016f3 Mon Sep 17 00:00:00 2001 From: Hauke Hund Date: Wed, 21 Feb 2024 05:26:47 +0100 Subject: [PATCH 1/4] adds debug log options for db statements, request headers & current user --- dsf-bpe/dsf-bpe-server/pom.xml | 4 + .../dev/dsf/bpe/BpeJerseyApplication.java | 17 + .../java/dev/dsf/bpe/dao/AbstractDaoJdbc.java | 7 +- .../dev/dsf/bpe/dao/LastEventTimeDaoJdbc.java | 11 +- .../dao/ProcessPluginResourcesDaoJdbc.java | 15 +- .../dev/dsf/bpe/dao/ProcessStateDaoJdbc.java | 9 +- .../dev/dsf/bpe/spring/config/DaoConfig.java | 8 +- .../bpe/spring/config/PropertiesConfig.java | 27 + dsf-bpe/pom.xml | 5 + dsf-common/dsf-common-auth/pom.xml | 4 + .../auth/logging/CurrentUserLogger.java | 62 ++ .../dsf/common/auth/logout/LogoutService.java | 7 - dsf-common/dsf-common-db/pom.xml | 24 + .../dsf/common/db/ConnectionWithLogger.java | 347 ++++++++++ .../dsf/common/db/DataSourceWithLogger.java | 92 +++ .../db/PreparedStatementWithLogger.java | 651 ++++++++++++++++++ .../status/webservice/StatusService.java | 9 +- dsf-common/pom.xml | 8 +- dsf-fhir/dsf-fhir-server/pom.xml | 4 + .../dev/dsf/fhir/FhirJerseyApplication.java | 17 + .../dsf/fhir/dao/command/CreateCommand.java | 4 +- .../dao/jdbc/AbstractResourceDaoJdbc.java | 13 - .../dao/jdbc/ActivityDefinitionDaoJdbc.java | 1 - .../dsf/fhir/dao/jdbc/EndpointDaoJdbc.java | 5 - .../dev/dsf/fhir/dao/jdbc/HistroyDaoJdbc.java | 6 - .../fhir/dao/jdbc/NamingSystemDaoJdbc.java | 3 - .../jdbc/OrganizationAffiliationDaoJdbc.java | 6 - .../fhir/dao/jdbc/OrganizationDaoJdbc.java | 3 - .../dsf/fhir/dao/jdbc/ReadAccessDaoJdbc.java | 5 - .../dsf/fhir/dao/jdbc/ReadByUrlDaoJdbc.java | 5 - .../fhir/dao/jdbc/SubscriptionDaoJdbc.java | 5 - .../dev/dsf/fhir/help/ExceptionHandler.java | 2 +- .../dev/dsf/fhir/help/ResponseGenerator.java | 12 +- .../basic/AbstractBooleanParameter.java | 4 +- .../dev/dsf/fhir/spring/config/DaoConfig.java | 13 +- .../fhir/spring/config/PropertiesConfig.java | 27 + .../impl/AbstractResourceServiceImpl.java | 11 +- .../jaxrs/AbstractResourceServiceJaxrs.java | 26 - .../webservice/jaxrs/BinaryServiceJaxrs.java | 4 - .../jaxrs/ConformanceServiceJaxrs.java | 7 - .../webservice/jaxrs/RootServiceJaxrs.java | 10 - .../StructureDefinitionServiceJaxrs.java | 12 - .../secure/AbstractResourceServiceSecure.java | 22 - .../secure/AbstractServiceSecure.java | 21 - .../secure/ConformanceServiceSecure.java | 2 - .../webservice/secure/RootServiceSecure.java | 6 - .../StructureDefinitionServiceSecure.java | 8 - .../java/dev/dsf/fhir/dao/AbstractDbTest.java | 14 +- .../fhir/dao/AbstractReadAccessDaoTest.java | 115 ++-- .../dsf/fhir/dao/AbstractResourceDaoTest.java | 27 +- .../java/dev/dsf/fhir/dao/BinaryDaoTest.java | 4 +- .../java/dev/dsf/fhir/dao/HistoryDaoTest.java | 14 +- .../integration/AbstractIntegrationTest.java | 8 +- .../integration/BundleIntegrationTest.java | 9 +- .../fhir/integration/TaskIntegrationTest.java | 5 +- dsf-fhir/pom.xml | 5 + pom.xml | 2 +- 57 files changed, 1433 insertions(+), 341 deletions(-) create mode 100644 dsf-common/dsf-common-auth/src/main/java/dev/dsf/common/auth/logging/CurrentUserLogger.java create mode 100644 dsf-common/dsf-common-db/pom.xml create mode 100644 dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/ConnectionWithLogger.java create mode 100644 dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/DataSourceWithLogger.java create mode 100644 dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/PreparedStatementWithLogger.java diff --git a/dsf-bpe/dsf-bpe-server/pom.xml b/dsf-bpe/dsf-bpe-server/pom.xml index 8e6340800..568513ae0 100755 --- a/dsf-bpe/dsf-bpe-server/pom.xml +++ b/dsf-bpe/dsf-bpe-server/pom.xml @@ -42,6 +42,10 @@ dev.dsf dsf-common-documentation + + dev.dsf + dsf-common-db + dev.dsf dsf-common-status diff --git a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/BpeJerseyApplication.java b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/BpeJerseyApplication.java index ab62d92f6..363de6b18 100755 --- a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/BpeJerseyApplication.java +++ b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/BpeJerseyApplication.java @@ -1,5 +1,9 @@ package dev.dsf.bpe; +import java.util.logging.Level; + +import org.glassfish.jersey.logging.LoggingFeature; +import org.glassfish.jersey.logging.LoggingFeature.Verbosity; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature; import org.slf4j.Logger; @@ -7,7 +11,9 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; +import dev.dsf.bpe.spring.config.PropertiesConfig; import dev.dsf.common.auth.filter.AuthenticationFilter; +import dev.dsf.common.auth.logging.CurrentUserLogger; import jakarta.inject.Inject; import jakarta.servlet.ServletContext; import jakarta.ws.rs.ApplicationPath; @@ -41,5 +47,16 @@ public BpeJerseyApplication(ServletContext servletContext) register(AuthenticationFilter.class); register(RolesAllowedDynamicFeature.class); + + if (context.getBean(PropertiesConfig.class).getDebugLogMessageCurrentUser()) + register(CurrentUserLogger.class); + + if (context.getBean(PropertiesConfig.class).getDebugLogMessageWebserviceRequest()) + { + java.util.logging.Logger l = java.util.logging.Logger.getLogger(BpeJerseyApplication.class.getName()); + l.setLevel(Level.FINE); + LoggingFeature loggingFeature = new LoggingFeature(l, Verbosity.HEADERS_ONLY); + register(loggingFeature); + } } } diff --git a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/AbstractDaoJdbc.java b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/AbstractDaoJdbc.java index 24ec2b087..510662622 100644 --- a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/AbstractDaoJdbc.java +++ b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/AbstractDaoJdbc.java @@ -2,14 +2,15 @@ import java.util.Objects; -import org.apache.commons.dbcp2.BasicDataSource; +import javax.sql.DataSource; + import org.springframework.beans.factory.InitializingBean; public abstract class AbstractDaoJdbc implements InitializingBean { - protected final BasicDataSource dataSource; + protected final DataSource dataSource; - public AbstractDaoJdbc(BasicDataSource dataSource) + public AbstractDaoJdbc(DataSource dataSource) { this.dataSource = dataSource; } diff --git a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/LastEventTimeDaoJdbc.java b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/LastEventTimeDaoJdbc.java index 28b4bd64c..7e6d43368 100644 --- a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/LastEventTimeDaoJdbc.java +++ b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/LastEventTimeDaoJdbc.java @@ -10,18 +10,15 @@ import java.util.Objects; import java.util.Optional; -import org.apache.commons.dbcp2.BasicDataSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import javax.sql.DataSource; + import org.springframework.beans.factory.InitializingBean; public class LastEventTimeDaoJdbc extends AbstractDaoJdbc implements LastEventTimeDao, InitializingBean { - private static final Logger logger = LoggerFactory.getLogger(LastEventTimeDaoJdbc.class); - private final String type; - public LastEventTimeDaoJdbc(BasicDataSource dataSource, String type) + public LastEventTimeDaoJdbc(DataSource dataSource, String type) { super(dataSource); @@ -47,7 +44,6 @@ public Optional readLastEventTime() throws SQLException { statement.setString(1, type); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -77,7 +73,6 @@ public LocalDateTime writeLastEventTime(LocalDateTime lastEvent) throws SQLExcep statement.setString(3, type); statement.setTimestamp(4, Timestamp.valueOf(lastEvent)); - logger.trace("Executing query '{}'", statement); statement.execute(); } } diff --git a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/ProcessPluginResourcesDaoJdbc.java b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/ProcessPluginResourcesDaoJdbc.java index a083876ed..1cfc42525 100644 --- a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/ProcessPluginResourcesDaoJdbc.java +++ b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/ProcessPluginResourcesDaoJdbc.java @@ -12,11 +12,10 @@ import java.util.Objects; import java.util.UUID; -import org.apache.commons.dbcp2.BasicDataSource; +import javax.sql.DataSource; + import org.hl7.fhir.r4.model.ResourceType; import org.postgresql.util.PGobject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import ca.uhn.fhir.parser.DataFormatException; import dev.dsf.bpe.plugin.ProcessIdAndVersion; @@ -25,9 +24,7 @@ public class ProcessPluginResourcesDaoJdbc extends AbstractDaoJdbc implements ProcessPluginResourcesDao { - private static final Logger logger = LoggerFactory.getLogger(ProcessPluginResourcesDaoJdbc.class); - - public ProcessPluginResourcesDaoJdbc(BasicDataSource dataSource) + public ProcessPluginResourcesDaoJdbc(DataSource dataSource) { super(dataSource); } @@ -39,7 +36,6 @@ public Map> getResources() throws SQLExc PreparedStatement statement = connection.prepareStatement( "SELECT process_key_and_version, resource_type, resource_id, url, version, name, identifier FROM process_plugin_resources ORDER BY process_key_and_version")) { - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { Map> resources = new HashMap<>(); @@ -117,7 +113,6 @@ public void addOrRemoveResources(Collection newReso statement.setObject(6, uuidToPgObject(resourceInfo.getResourceId())); statement.addBatch(); - logger.trace("Executing query '{}'", statement); statement.executeBatch(); } @@ -145,7 +140,6 @@ else if (ResourceType.NamingSystem.equals(resourceType)) statement.setObject(4, uuidToPgObject(resourceInfo.getResourceId())); statement.addBatch(); - logger.trace("Executing query '{}'", statement); statement.executeBatch(); } @@ -173,7 +167,6 @@ else if (ResourceType.Task.equals(resourceType)) statement.setObject(4, uuidToPgObject(resourceInfo.getResourceId())); statement.addBatch(); - logger.trace("Executing query '{}'", statement); statement.executeBatch(); } @@ -194,7 +187,6 @@ else if (ResourceType.Task.equals(resourceType)) statement.setObject(1, uuidToPgObject(deletedId)); statement.addBatch(); - logger.trace("Executing query '{}'", statement); } statement.executeBatch(); @@ -213,7 +205,6 @@ else if (ResourceType.Task.equals(resourceType)) statement.setString(1, process.toString()); statement.addBatch(); - logger.trace("Executing query '{}'", statement); } statement.executeBatch(); diff --git a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/ProcessStateDaoJdbc.java b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/ProcessStateDaoJdbc.java index 99d84eb28..e0bfb7048 100644 --- a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/ProcessStateDaoJdbc.java +++ b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/dao/ProcessStateDaoJdbc.java @@ -9,18 +9,14 @@ import java.util.Map.Entry; import java.util.Objects; -import org.apache.commons.dbcp2.BasicDataSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import javax.sql.DataSource; import dev.dsf.bpe.plugin.ProcessIdAndVersion; import dev.dsf.bpe.plugin.ProcessState; public class ProcessStateDaoJdbc extends AbstractDaoJdbc implements ProcessStateDao { - private static final Logger logger = LoggerFactory.getLogger(ProcessStateDaoJdbc.class); - - public ProcessStateDaoJdbc(BasicDataSource dataSource) + public ProcessStateDaoJdbc(DataSource dataSource) { super(dataSource); } @@ -49,7 +45,6 @@ public void updateStates(Map states) throws S statement.addBatch(); } - logger.trace("Executing query '{}'", statement); statement.executeBatch(); } } diff --git a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/DaoConfig.java b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/DaoConfig.java index 7c5aec7a8..0a188028b 100644 --- a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/DaoConfig.java +++ b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/DaoConfig.java @@ -1,5 +1,7 @@ package dev.dsf.bpe.spring.config; +import javax.sql.DataSource; + import org.apache.commons.dbcp2.BasicDataSource; import org.postgresql.Driver; import org.springframework.beans.factory.annotation.Autowired; @@ -12,6 +14,7 @@ import dev.dsf.bpe.dao.ProcessPluginResourcesDaoJdbc; import dev.dsf.bpe.dao.ProcessStateDao; import dev.dsf.bpe.dao.ProcessStateDaoJdbc; +import dev.dsf.common.db.DataSourceWithLogger; @Configuration public class DaoConfig @@ -20,7 +23,7 @@ public class DaoConfig private PropertiesConfig propertiesConfig; @Bean - public BasicDataSource dataSource() + public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(Driver.class.getName()); @@ -31,7 +34,8 @@ public BasicDataSource dataSource() dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("SELECT 1"); - return dataSource; + + return new DataSourceWithLogger(propertiesConfig.getDebugLogMessageDbStatement(), dataSource); } private String toString(char[] password) diff --git a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/PropertiesConfig.java b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/PropertiesConfig.java index 59d86d013..22d27a35e 100644 --- a/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/PropertiesConfig.java +++ b/dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/PropertiesConfig.java @@ -253,6 +253,18 @@ public class PropertiesConfig implements InitializingBean @Value("${dev.dsf.bpe.debug.log.message.variablesLocal:false}") private boolean debugLogMessageVariablesLocal; + @Documentation(description = "To enable logging of webservices requests set to `true`.", recommendation = "This debug function should only be activated during development. WARNNING: Confidential information may be leaked via the debug log!") + @Value("${dev.dsf.bpe.debug.log.message.webserviceRequest:false}") + private boolean debugLogMessageWebserviceRequest; + + @Documentation(description = "To enable logging of DB queries set to `true`.", recommendation = "This debug function should only be activated during development. WARNNING: Confidential information may be leaked via the debug log!") + @Value("${dev.dsf.bpe.debug.log.message.dbStatement:false}") + private boolean debugLogMessageDbStatement; + + @Documentation(description = "To enable logging of the currently requesting user set to `true`.", recommendation = "This debug function should only be activated during development. WARNNING: Confidential information may be leaked via the debug log!") + @Value("${dev.dsf.bpe.debug.log.message.currentUser:false}") + private boolean debugLogMessageCurrentUser; + @Value("${dev.dsf.server.status.port}") private int jettyStatusConnectorPort; @@ -599,6 +611,21 @@ public boolean getDebugLogMessageVariablesLocal() return debugLogMessageVariablesLocal; } + public boolean getDebugLogMessageWebserviceRequest() + { + return debugLogMessageWebserviceRequest; + } + + public boolean getDebugLogMessageDbStatement() + { + return debugLogMessageDbStatement; + } + + public boolean getDebugLogMessageCurrentUser() + { + return debugLogMessageCurrentUser; + } + public int getJettyStatusConnectorPort() { return jettyStatusConnectorPort; diff --git a/dsf-bpe/pom.xml b/dsf-bpe/pom.xml index c56025ff5..e59d274d2 100755 --- a/dsf-bpe/pom.xml +++ b/dsf-bpe/pom.xml @@ -134,6 +134,11 @@ dsf-common-documentation ${project.version} + + dev.dsf + dsf-common-db + ${project.version} + dev.dsf dsf-common-jetty diff --git a/dsf-common/dsf-common-auth/pom.xml b/dsf-common/dsf-common-auth/pom.xml index f3e1c67e5..b6ae67376 100644 --- a/dsf-common/dsf-common-auth/pom.xml +++ b/dsf-common/dsf-common-auth/pom.xml @@ -27,6 +27,10 @@ jakarta.ws.rs jakarta.ws.rs-api + + jakarta.annotation + jakarta.annotation-api + org.springframework diff --git a/dsf-common/dsf-common-auth/src/main/java/dev/dsf/common/auth/logging/CurrentUserLogger.java b/dsf-common/dsf-common-auth/src/main/java/dev/dsf/common/auth/logging/CurrentUserLogger.java new file mode 100644 index 000000000..e29d3ba3c --- /dev/null +++ b/dsf-common/dsf-common-auth/src/main/java/dev/dsf/common/auth/logging/CurrentUserLogger.java @@ -0,0 +1,62 @@ +package dev.dsf.common.auth.logging; + +import java.io.IOException; +import java.security.Principal; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import dev.dsf.common.auth.conf.Identity; +import dev.dsf.common.auth.conf.OrganizationIdentity; +import dev.dsf.common.auth.conf.PractitionerIdentity; +import jakarta.annotation.Priority; +import jakarta.ws.rs.ConstrainedTo; +import jakarta.ws.rs.RuntimeType; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.container.PreMatching; +import jakarta.ws.rs.core.SecurityContext; + +@ConstrainedTo(RuntimeType.SERVER) +@PreMatching +@Priority(Integer.MIN_VALUE) +public class CurrentUserLogger implements ContainerRequestFilter +{ + private static final Logger logger = LoggerFactory.getLogger(CurrentUserLogger.class); + + @Override + public void filter(ContainerRequestContext requestContext) throws IOException + { + Identity identity = getCurrentIdentity(requestContext.getSecurityContext()); + + if (identity instanceof OrganizationIdentity) + { + logger.debug("Current organization identity '{}', dsf-roles {}", identity.getName(), + identity.getDsfRoles()); + } + else if (identity instanceof PractitionerIdentity practitioner) + { + logger.debug("Current practitioner identity '{}', dsf-roles {}, practitioner-roles {}", identity.getName(), + identity.getDsfRoles(), practitioner.getPractionerRoles().stream() + .map(c -> c.getSystem() + "|" + c.getCode()).collect(Collectors.joining(", ", "[", "]"))); + } + } + + private Identity getCurrentIdentity(SecurityContext context) + { + Principal principal = context.getUserPrincipal(); + if (principal != null) + { + if (principal instanceof Identity identity) + return identity; + else + { + logger.warn("Unknown current user principal of type {}", principal.getClass().getName()); + return null; + } + } + else + return null; + } +} diff --git a/dsf-common/dsf-common-auth/src/main/java/dev/dsf/common/auth/logout/LogoutService.java b/dsf-common/dsf-common-auth/src/main/java/dev/dsf/common/auth/logout/LogoutService.java index d30de0884..1b0692df6 100644 --- a/dsf-common/dsf-common-auth/src/main/java/dev/dsf/common/auth/logout/LogoutService.java +++ b/dsf-common/dsf-common-auth/src/main/java/dev/dsf/common/auth/logout/LogoutService.java @@ -1,8 +1,5 @@ package dev.dsf.common.auth.logout; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.ws.rs.GET; @@ -15,13 +12,9 @@ public class LogoutService { public static final String PATH = "logout"; - private static final Logger logger = LoggerFactory.getLogger(LogoutService.class); - @GET public void logout(@Context UriInfo uri, @Context HttpServletRequest request) throws ServletException { - logger.trace("GET {}", uri.getRequestUri().toString()); - request.logout(); } } diff --git a/dsf-common/dsf-common-db/pom.xml b/dsf-common/dsf-common-db/pom.xml new file mode 100644 index 000000000..d03a254eb --- /dev/null +++ b/dsf-common/dsf-common-db/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + dsf-common-db + + + dev.dsf + dsf-common-pom + 1.5.0-SNAPSHOT + + + + + org.apache.commons + commons-dbcp2 + + + commons-logging + commons-logging + + + + + \ No newline at end of file diff --git a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/ConnectionWithLogger.java b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/ConnectionWithLogger.java new file mode 100644 index 000000000..b40b557f9 --- /dev/null +++ b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/ConnectionWithLogger.java @@ -0,0 +1,347 @@ +package dev.dsf.common.db; + +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.NClob; +import java.sql.PreparedStatement; +import java.sql.SQLClientInfoException; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Savepoint; +import java.sql.ShardingKey; +import java.sql.Statement; +import java.sql.Struct; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Executor; + +public class ConnectionWithLogger implements Connection +{ + private final boolean loggerEnabled; + + private final Connection delegate; + + public ConnectionWithLogger(boolean loggerEnabled, Connection delegate) + { + this.loggerEnabled = loggerEnabled; + this.delegate = delegate; + } + + public T unwrap(Class iface) throws SQLException + { + return delegate.unwrap(iface); + } + + public boolean isWrapperFor(Class iface) throws SQLException + { + return delegate.isWrapperFor(iface); + } + + public Statement createStatement() throws SQLException + { + return delegate.createStatement(); + } + + public PreparedStatement prepareStatement(String sql) throws SQLException + { + return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql)); + } + + public CallableStatement prepareCall(String sql) throws SQLException + { + return delegate.prepareCall(sql); + } + + public String nativeSQL(String sql) throws SQLException + { + return delegate.nativeSQL(sql); + } + + public void setAutoCommit(boolean autoCommit) throws SQLException + { + delegate.setAutoCommit(autoCommit); + } + + public boolean getAutoCommit() throws SQLException + { + return delegate.getAutoCommit(); + } + + public void commit() throws SQLException + { + delegate.commit(); + } + + public void rollback() throws SQLException + { + delegate.rollback(); + } + + public void close() throws SQLException + { + delegate.close(); + } + + public boolean isClosed() throws SQLException + { + return delegate.isClosed(); + } + + public DatabaseMetaData getMetaData() throws SQLException + { + return delegate.getMetaData(); + } + + public void setReadOnly(boolean readOnly) throws SQLException + { + delegate.setReadOnly(readOnly); + } + + public boolean isReadOnly() throws SQLException + { + return delegate.isReadOnly(); + } + + public void setCatalog(String catalog) throws SQLException + { + delegate.setCatalog(catalog); + } + + public String getCatalog() throws SQLException + { + return delegate.getCatalog(); + } + + public void setTransactionIsolation(int level) throws SQLException + { + delegate.setTransactionIsolation(level); + } + + public int getTransactionIsolation() throws SQLException + { + return delegate.getTransactionIsolation(); + } + + public SQLWarning getWarnings() throws SQLException + { + return delegate.getWarnings(); + } + + public void clearWarnings() throws SQLException + { + delegate.clearWarnings(); + } + + public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException + { + return delegate.createStatement(resultSetType, resultSetConcurrency); + } + + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException + { + return new PreparedStatementWithLogger(loggerEnabled, + delegate.prepareStatement(sql, resultSetType, resultSetConcurrency)); + } + + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException + { + return delegate.prepareCall(sql, resultSetType, resultSetConcurrency); + } + + public Map> getTypeMap() throws SQLException + { + return delegate.getTypeMap(); + } + + public void setTypeMap(Map> map) throws SQLException + { + delegate.setTypeMap(map); + } + + public void setHoldability(int holdability) throws SQLException + { + delegate.setHoldability(holdability); + } + + public int getHoldability() throws SQLException + { + return delegate.getHoldability(); + } + + public Savepoint setSavepoint() throws SQLException + { + return delegate.setSavepoint(); + } + + public Savepoint setSavepoint(String name) throws SQLException + { + return delegate.setSavepoint(name); + } + + public void rollback(Savepoint savepoint) throws SQLException + { + delegate.rollback(savepoint); + } + + public void releaseSavepoint(Savepoint savepoint) throws SQLException + { + delegate.releaseSavepoint(savepoint); + } + + public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException + { + return delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + } + + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException + { + return new PreparedStatementWithLogger(loggerEnabled, + delegate.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)); + } + + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException + { + return delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); + } + + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException + { + return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, autoGeneratedKeys)); + } + + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException + { + return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, columnIndexes)); + } + + public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException + { + return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, columnNames)); + } + + public Clob createClob() throws SQLException + { + return delegate.createClob(); + } + + public Blob createBlob() throws SQLException + { + return delegate.createBlob(); + } + + public NClob createNClob() throws SQLException + { + return delegate.createNClob(); + } + + public SQLXML createSQLXML() throws SQLException + { + return delegate.createSQLXML(); + } + + public boolean isValid(int timeout) throws SQLException + { + return delegate.isValid(timeout); + } + + public void setClientInfo(String name, String value) throws SQLClientInfoException + { + delegate.setClientInfo(name, value); + } + + public void setClientInfo(Properties properties) throws SQLClientInfoException + { + delegate.setClientInfo(properties); + } + + public String getClientInfo(String name) throws SQLException + { + return delegate.getClientInfo(name); + } + + public Properties getClientInfo() throws SQLException + { + return delegate.getClientInfo(); + } + + public Array createArrayOf(String typeName, Object[] elements) throws SQLException + { + return delegate.createArrayOf(typeName, elements); + } + + public Struct createStruct(String typeName, Object[] attributes) throws SQLException + { + return delegate.createStruct(typeName, attributes); + } + + public void setSchema(String schema) throws SQLException + { + delegate.setSchema(schema); + } + + public String getSchema() throws SQLException + { + return delegate.getSchema(); + } + + public void abort(Executor executor) throws SQLException + { + delegate.abort(executor); + } + + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException + { + delegate.setNetworkTimeout(executor, milliseconds); + } + + public int getNetworkTimeout() throws SQLException + { + return delegate.getNetworkTimeout(); + } + + public void beginRequest() throws SQLException + { + delegate.beginRequest(); + } + + public void endRequest() throws SQLException + { + delegate.endRequest(); + } + + public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) + throws SQLException + { + return delegate.setShardingKeyIfValid(shardingKey, superShardingKey, timeout); + } + + public boolean setShardingKeyIfValid(ShardingKey shardingKey, int timeout) throws SQLException + { + return delegate.setShardingKeyIfValid(shardingKey, timeout); + } + + public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException + { + delegate.setShardingKey(shardingKey, superShardingKey); + } + + public void setShardingKey(ShardingKey shardingKey) throws SQLException + { + delegate.setShardingKey(shardingKey); + } + + @Override + public String toString() + { + return delegate.toString(); + } +} diff --git a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/DataSourceWithLogger.java b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/DataSourceWithLogger.java new file mode 100644 index 000000000..f9cc764a9 --- /dev/null +++ b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/DataSourceWithLogger.java @@ -0,0 +1,92 @@ +package dev.dsf.common.db; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.ConnectionBuilder; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.ShardingKeyBuilder; + +import javax.sql.DataSource; + +import org.apache.commons.dbcp2.BasicDataSource; + +public class DataSourceWithLogger implements DataSource +{ + private final boolean loggerEnabled; + + private final BasicDataSource delegate; + + public DataSourceWithLogger(boolean loggerEnabled, BasicDataSource delegate) + { + this.loggerEnabled = loggerEnabled; + this.delegate = delegate; + } + + public T unwrap(Class iface) throws SQLException + { + if (BasicDataSource.class.equals(iface)) + return iface.cast(delegate); + + return delegate.unwrap(iface); + } + + public boolean isWrapperFor(Class iface) throws SQLException + { + if (BasicDataSource.class.equals(iface)) + return true; + + return delegate.isWrapperFor(iface); + } + + public Connection getConnection() throws SQLException + { + return new ConnectionWithLogger(loggerEnabled, delegate.getConnection()); + } + + public Connection getConnection(String username, String password) throws SQLException + { + return new ConnectionWithLogger(loggerEnabled, delegate.getConnection(username, password)); + } + + public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException + { + return delegate.getParentLogger(); + } + + public PrintWriter getLogWriter() throws SQLException + { + return delegate.getLogWriter(); + } + + public void setLogWriter(PrintWriter out) throws SQLException + { + delegate.setLogWriter(out); + } + + public void setLoginTimeout(int seconds) throws SQLException + { + delegate.setLoginTimeout(seconds); + } + + public int getLoginTimeout() throws SQLException + { + return delegate.getLoginTimeout(); + } + + public ConnectionBuilder createConnectionBuilder() throws SQLException + { + return delegate.createConnectionBuilder(); + } + + public ShardingKeyBuilder createShardingKeyBuilder() throws SQLException + { + return delegate.createShardingKeyBuilder(); + } + + @Override + public String toString() + { + return delegate.toString(); + } +} diff --git a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/PreparedStatementWithLogger.java b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/PreparedStatementWithLogger.java new file mode 100644 index 000000000..3a20372b8 --- /dev/null +++ b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/PreparedStatementWithLogger.java @@ -0,0 +1,651 @@ +package dev.dsf.common.db; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.Date; +import java.sql.NClob; +import java.sql.ParameterMetaData; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLType; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PreparedStatementWithLogger implements PreparedStatement +{ + private static final Logger logger = LoggerFactory.getLogger(PreparedStatementWithLogger.class); + private final boolean loggerEnabled; + + private final PreparedStatement delegate; + + public PreparedStatementWithLogger(boolean loggerEnabled, PreparedStatement delegate) + { + this.loggerEnabled = loggerEnabled; + this.delegate = delegate; + } + + private void logStatement() + { + if (loggerEnabled) + logger.debug("Executing query '{}'", this); + } + + private void logStatement(String sql) + { + if (loggerEnabled) + logger.debug("Executing query '{}'", sql); + } + + public T unwrap(Class iface) throws SQLException + { + return delegate.unwrap(iface); + } + + public ResultSet executeQuery(String sql) throws SQLException + { + logStatement(sql); + + return delegate.executeQuery(sql); + } + + public ResultSet executeQuery() throws SQLException + { + logStatement(); + + return delegate.executeQuery(); + } + + public boolean isWrapperFor(Class iface) throws SQLException + { + return delegate.isWrapperFor(iface); + } + + public int executeUpdate(String sql) throws SQLException + { + logStatement(sql); + + return delegate.executeUpdate(sql); + } + + public int executeUpdate() throws SQLException + { + logStatement(); + + return delegate.executeUpdate(); + } + + public void setNull(int parameterIndex, int sqlType) throws SQLException + { + delegate.setNull(parameterIndex, sqlType); + } + + public void close() throws SQLException + { + delegate.close(); + } + + public int getMaxFieldSize() throws SQLException + { + return delegate.getMaxFieldSize(); + } + + public void setBoolean(int parameterIndex, boolean x) throws SQLException + { + delegate.setBoolean(parameterIndex, x); + } + + public void setByte(int parameterIndex, byte x) throws SQLException + { + delegate.setByte(parameterIndex, x); + } + + public void setMaxFieldSize(int max) throws SQLException + { + delegate.setMaxFieldSize(max); + } + + public void setShort(int parameterIndex, short x) throws SQLException + { + delegate.setShort(parameterIndex, x); + } + + public int getMaxRows() throws SQLException + { + return delegate.getMaxRows(); + } + + public void setInt(int parameterIndex, int x) throws SQLException + { + delegate.setInt(parameterIndex, x); + } + + public void setMaxRows(int max) throws SQLException + { + delegate.setMaxRows(max); + } + + public void setLong(int parameterIndex, long x) throws SQLException + { + delegate.setLong(parameterIndex, x); + } + + public void setEscapeProcessing(boolean enable) throws SQLException + { + delegate.setEscapeProcessing(enable); + } + + public void setFloat(int parameterIndex, float x) throws SQLException + { + delegate.setFloat(parameterIndex, x); + } + + public void setDouble(int parameterIndex, double x) throws SQLException + { + delegate.setDouble(parameterIndex, x); + } + + public int getQueryTimeout() throws SQLException + { + return delegate.getQueryTimeout(); + } + + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException + { + delegate.setBigDecimal(parameterIndex, x); + } + + public void setQueryTimeout(int seconds) throws SQLException + { + delegate.setQueryTimeout(seconds); + } + + public void setString(int parameterIndex, String x) throws SQLException + { + delegate.setString(parameterIndex, x); + } + + public void setBytes(int parameterIndex, byte[] x) throws SQLException + { + delegate.setBytes(parameterIndex, x); + } + + public void cancel() throws SQLException + { + delegate.cancel(); + } + + public void setDate(int parameterIndex, Date x) throws SQLException + { + delegate.setDate(parameterIndex, x); + } + + public SQLWarning getWarnings() throws SQLException + { + return delegate.getWarnings(); + } + + public void setTime(int parameterIndex, Time x) throws SQLException + { + delegate.setTime(parameterIndex, x); + } + + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException + { + delegate.setTimestamp(parameterIndex, x); + } + + public void clearWarnings() throws SQLException + { + delegate.clearWarnings(); + } + + public void setCursorName(String name) throws SQLException + { + delegate.setCursorName(name); + } + + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException + { + delegate.setAsciiStream(parameterIndex, x, length); + } + + public boolean execute(String sql) throws SQLException + { + logStatement(sql); + + return delegate.execute(sql); + } + + @Deprecated + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException + { + delegate.setUnicodeStream(parameterIndex, x, length); + } + + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException + { + delegate.setBinaryStream(parameterIndex, x, length); + } + + public ResultSet getResultSet() throws SQLException + { + return delegate.getResultSet(); + } + + public int getUpdateCount() throws SQLException + { + return delegate.getUpdateCount(); + } + + public void clearParameters() throws SQLException + { + delegate.clearParameters(); + } + + public boolean getMoreResults() throws SQLException + { + return delegate.getMoreResults(); + } + + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException + { + delegate.setObject(parameterIndex, x, targetSqlType); + } + + public void setFetchDirection(int direction) throws SQLException + { + delegate.setFetchDirection(direction); + } + + public void setObject(int parameterIndex, Object x) throws SQLException + { + delegate.setObject(parameterIndex, x); + } + + public int getFetchDirection() throws SQLException + { + return delegate.getFetchDirection(); + } + + public void setFetchSize(int rows) throws SQLException + { + delegate.setFetchSize(rows); + } + + public int getFetchSize() throws SQLException + { + return delegate.getFetchSize(); + } + + public boolean execute() throws SQLException + { + logStatement(); + + return delegate.execute(); + } + + public int getResultSetConcurrency() throws SQLException + { + return delegate.getResultSetConcurrency(); + } + + public int getResultSetType() throws SQLException + { + return delegate.getResultSetType(); + } + + public void addBatch(String sql) throws SQLException + { + delegate.addBatch(sql); + } + + public void addBatch() throws SQLException + { + delegate.addBatch(); + } + + public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException + { + delegate.setCharacterStream(parameterIndex, reader, length); + } + + public void clearBatch() throws SQLException + { + delegate.clearBatch(); + } + + public int[] executeBatch() throws SQLException + { + logStatement(); + + return delegate.executeBatch(); + } + + public void setRef(int parameterIndex, Ref x) throws SQLException + { + delegate.setRef(parameterIndex, x); + } + + public void setBlob(int parameterIndex, Blob x) throws SQLException + { + delegate.setBlob(parameterIndex, x); + } + + public void setClob(int parameterIndex, Clob x) throws SQLException + { + delegate.setClob(parameterIndex, x); + } + + public void setArray(int parameterIndex, Array x) throws SQLException + { + delegate.setArray(parameterIndex, x); + } + + public Connection getConnection() throws SQLException + { + return delegate.getConnection(); + } + + public ResultSetMetaData getMetaData() throws SQLException + { + return delegate.getMetaData(); + } + + public boolean getMoreResults(int current) throws SQLException + { + return delegate.getMoreResults(current); + } + + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException + { + delegate.setDate(parameterIndex, x, cal); + } + + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException + { + delegate.setTime(parameterIndex, x, cal); + } + + public ResultSet getGeneratedKeys() throws SQLException + { + return delegate.getGeneratedKeys(); + } + + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException + { + delegate.setTimestamp(parameterIndex, x, cal); + } + + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException + { + return delegate.executeUpdate(sql, autoGeneratedKeys); + } + + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException + { + delegate.setNull(parameterIndex, sqlType, typeName); + } + + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException + { + return delegate.executeUpdate(sql, columnIndexes); + } + + public void setURL(int parameterIndex, URL x) throws SQLException + { + delegate.setURL(parameterIndex, x); + } + + public ParameterMetaData getParameterMetaData() throws SQLException + { + return delegate.getParameterMetaData(); + } + + public int executeUpdate(String sql, String[] columnNames) throws SQLException + { + return delegate.executeUpdate(sql, columnNames); + } + + public void setRowId(int parameterIndex, RowId x) throws SQLException + { + delegate.setRowId(parameterIndex, x); + } + + public void setNString(int parameterIndex, String value) throws SQLException + { + delegate.setNString(parameterIndex, value); + } + + public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException + { + delegate.setNCharacterStream(parameterIndex, value, length); + } + + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException + { + logStatement(sql); + + return delegate.execute(sql, autoGeneratedKeys); + } + + public void setNClob(int parameterIndex, NClob value) throws SQLException + { + delegate.setNClob(parameterIndex, value); + } + + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException + { + delegate.setClob(parameterIndex, reader, length); + } + + public boolean execute(String sql, int[] columnIndexes) throws SQLException + { + logStatement(sql); + + return delegate.execute(sql, columnIndexes); + } + + public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException + { + delegate.setBlob(parameterIndex, inputStream, length); + } + + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException + { + delegate.setNClob(parameterIndex, reader, length); + } + + public boolean execute(String sql, String[] columnNames) throws SQLException + { + logStatement(sql); + + return delegate.execute(sql, columnNames); + } + + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException + { + delegate.setSQLXML(parameterIndex, xmlObject); + } + + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException + { + delegate.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + } + + public int getResultSetHoldability() throws SQLException + { + return delegate.getResultSetHoldability(); + } + + public boolean isClosed() throws SQLException + { + return delegate.isClosed(); + } + + public void setPoolable(boolean poolable) throws SQLException + { + delegate.setPoolable(poolable); + } + + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException + { + delegate.setAsciiStream(parameterIndex, x, length); + } + + public boolean isPoolable() throws SQLException + { + return delegate.isPoolable(); + } + + public void closeOnCompletion() throws SQLException + { + delegate.closeOnCompletion(); + } + + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException + { + delegate.setBinaryStream(parameterIndex, x, length); + } + + public boolean isCloseOnCompletion() throws SQLException + { + return delegate.isCloseOnCompletion(); + } + + public long getLargeUpdateCount() throws SQLException + { + return delegate.getLargeUpdateCount(); + } + + public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException + { + delegate.setCharacterStream(parameterIndex, reader, length); + } + + public void setLargeMaxRows(long max) throws SQLException + { + delegate.setLargeMaxRows(max); + } + + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException + { + delegate.setAsciiStream(parameterIndex, x); + } + + public long getLargeMaxRows() throws SQLException + { + return delegate.getLargeMaxRows(); + } + + public long[] executeLargeBatch() throws SQLException + { + return delegate.executeLargeBatch(); + } + + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException + { + delegate.setBinaryStream(parameterIndex, x); + } + + public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException + { + delegate.setCharacterStream(parameterIndex, reader); + } + + public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException + { + delegate.setNCharacterStream(parameterIndex, value); + } + + public long executeLargeUpdate(String sql) throws SQLException + { + return delegate.executeLargeUpdate(sql); + } + + public void setClob(int parameterIndex, Reader reader) throws SQLException + { + delegate.setClob(parameterIndex, reader); + } + + public long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException + { + return delegate.executeLargeUpdate(sql, autoGeneratedKeys); + } + + public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException + { + delegate.setBlob(parameterIndex, inputStream); + } + + public void setNClob(int parameterIndex, Reader reader) throws SQLException + { + delegate.setNClob(parameterIndex, reader); + } + + public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException + { + return delegate.executeLargeUpdate(sql, columnIndexes); + } + + public void setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength) throws SQLException + { + delegate.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + } + + public long executeLargeUpdate(String sql, String[] columnNames) throws SQLException + { + return delegate.executeLargeUpdate(sql, columnNames); + } + + public void setObject(int parameterIndex, Object x, SQLType targetSqlType) throws SQLException + { + delegate.setObject(parameterIndex, x, targetSqlType); + } + + public String enquoteLiteral(String val) throws SQLException + { + return delegate.enquoteLiteral(val); + } + + public long executeLargeUpdate() throws SQLException + { + return delegate.executeLargeUpdate(); + } + + public String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException + { + return delegate.enquoteIdentifier(identifier, alwaysQuote); + } + + public boolean isSimpleIdentifier(String identifier) throws SQLException + { + return delegate.isSimpleIdentifier(identifier); + } + + public String enquoteNCharLiteral(String val) throws SQLException + { + return delegate.enquoteNCharLiteral(val); + } + + @Override + public String toString() + { + return delegate.toString(); + } +} diff --git a/dsf-common/dsf-common-status/src/main/java/dev/dsf/common/status/webservice/StatusService.java b/dsf-common/dsf-common-status/src/main/java/dev/dsf/common/status/webservice/StatusService.java index 834ffe424..b86e1619d 100644 --- a/dsf-common/dsf-common-status/src/main/java/dev/dsf/common/status/webservice/StatusService.java +++ b/dsf-common/dsf-common-status/src/main/java/dev/dsf/common/status/webservice/StatusService.java @@ -4,7 +4,8 @@ import java.sql.SQLException; import java.util.Objects; -import org.apache.commons.dbcp2.BasicDataSource; +import javax.sql.DataSource; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; @@ -30,10 +31,10 @@ public class StatusService implements InitializingBean private static final Logger logger = LoggerFactory.getLogger(StatusService.class); - private final BasicDataSource dataSource; + private final DataSource dataSource; private final int statusConnectorPort; - public StatusService(BasicDataSource dataSource, int statusConnectorPort) + public StatusService(DataSource dataSource, int statusConnectorPort) { this.dataSource = dataSource; this.statusConnectorPort = statusConnectorPort; @@ -48,8 +49,6 @@ public void afterPropertiesSet() throws Exception @GET public Response status(@Context UriInfo uri, @Context HttpHeaders headers, @Context HttpServletRequest request) { - logger.trace("GET {}, Local port {}", uri.getRequestUri().toString(), request.getLocalPort()); - if (request.getLocalPort() != statusConnectorPort) { logger.warn("Sending '401 Unauthorized' request not on status port {}", statusConnectorPort); diff --git a/dsf-common/pom.xml b/dsf-common/pom.xml index 9e8dded2d..4ff427581 100644 --- a/dsf-common/pom.xml +++ b/dsf-common/pom.xml @@ -12,10 +12,11 @@ dsf-common-auth + dsf-common-config + dsf-common-db dsf-common-documentation dsf-common-jetty dsf-common-status - dsf-common-config dsf-common-ui @@ -50,6 +51,11 @@ dsf-common-config ${project.version} + + ${project.groupId} + dsf-common-db + ${project.version} + ${project.groupId} dsf-common-documentation diff --git a/dsf-fhir/dsf-fhir-server/pom.xml b/dsf-fhir/dsf-fhir-server/pom.xml index 19897e320..4d8ef5c35 100755 --- a/dsf-fhir/dsf-fhir-server/pom.xml +++ b/dsf-fhir/dsf-fhir-server/pom.xml @@ -42,6 +42,10 @@ dev.dsf dsf-common-config + + dev.dsf + dsf-common-db + dev.dsf dsf-common-documentation diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/FhirJerseyApplication.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/FhirJerseyApplication.java index 38b23f266..a4dbe2553 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/FhirJerseyApplication.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/FhirJerseyApplication.java @@ -1,5 +1,9 @@ package dev.dsf.fhir; +import java.util.logging.Level; + +import org.glassfish.jersey.logging.LoggingFeature; +import org.glassfish.jersey.logging.LoggingFeature.Verbosity; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature; import org.slf4j.Logger; @@ -8,6 +12,8 @@ import org.springframework.web.context.support.WebApplicationContextUtils; import dev.dsf.common.auth.filter.AuthenticationFilter; +import dev.dsf.common.auth.logging.CurrentUserLogger; +import dev.dsf.fhir.spring.config.PropertiesConfig; import jakarta.inject.Inject; import jakarta.servlet.ServletContext; import jakarta.ws.rs.ApplicationPath; @@ -41,5 +47,16 @@ public FhirJerseyApplication(ServletContext servletContext) register(AuthenticationFilter.class); register(RolesAllowedDynamicFeature.class); + + if (context.getBean(PropertiesConfig.class).getDebugLogMessageCurrentUser()) + register(CurrentUserLogger.class); + + if (context.getBean(PropertiesConfig.class).getDebugLogMessageWebserviceRequest()) + { + java.util.logging.Logger l = java.util.logging.Logger.getLogger(FhirJerseyApplication.class.getName()); + l.setLevel(Level.FINE); + LoggingFeature loggingFeature = new LoggingFeature(l, Verbosity.HEADERS_ONLY); + register(loggingFeature); + } } } diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/command/CreateCommand.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/command/CreateCommand.java index f89e0d129..5134b3e67 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/command/CreateCommand.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/command/CreateCommand.java @@ -177,7 +177,7 @@ private Optional checkAlreadyExists(Connection connection, String ifNo return Optional.empty(); if (ifNoneExist.isBlank()) - throw new WebApplicationException(responseGenerator.badIfNoneExistHeaderValue(ifNoneExist)); + throw new WebApplicationException(responseGenerator.badIfNoneExistHeaderValue("blank", ifNoneExist)); if (!ifNoneExist.contains("?")) ifNoneExist = '?' + ifNoneExist; @@ -185,7 +185,7 @@ private Optional checkAlreadyExists(Connection connection, String ifNo UriComponents componentes = UriComponentsBuilder.fromUriString(ifNoneExist).build(); String path = componentes.getPath(); if (path != null && !path.isBlank()) - throw new WebApplicationException(responseGenerator.badIfNoneExistHeaderValue(ifNoneExist)); + throw new WebApplicationException(responseGenerator.badIfNoneExistHeaderValue("no resource", ifNoneExist)); Map> queryParameters = parameterConverter .urlDecodeQueryParameters(componentes.getQueryParams()); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/AbstractResourceDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/AbstractResourceDaoJdbc.java index 679daa506..196bea629 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/AbstractResourceDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/AbstractResourceDaoJdbc.java @@ -305,7 +305,6 @@ private R create(Connection connection, R resource, UUID uuid) throws SQLExcepti { preparedStatementFactory.configureCreateStatement(statement, resource, uuid); - logger.trace("Executing query '{}'", statement); statement.execute(); } @@ -344,7 +343,6 @@ public Optional readWithTransaction(Connection connection, UUID uuid) { preparedStatementFactory.configureReadByIdStatement(statement, uuid); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -402,7 +400,6 @@ public Optional readVersionWithTransaction(Connection connection, UUID uuid, { preparedStatementFactory.configureReadByIdAndVersionStatement(statement, uuid, version); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -459,7 +456,6 @@ public Optional readIncludingDeletedWithTransaction(Connection connection, UU { preparedStatementFactory.configureReadByIdStatement(statement, uuid); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -497,7 +493,6 @@ public List readAllWithTransaction(Connection connection) throws SQLException try (PreparedStatement statement = connection .prepareStatement("SELECT " + getResourceColumn() + " FROM current_" + getResourceTable())) { - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { List all = new ArrayList<>(); @@ -537,7 +532,6 @@ public boolean existsNotDeletedWithTransaction(Connection connection, String idS { statement.setObject(1, preparedStatementFactory.uuidToPgObject(uuid)); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { return result.next() && !result.getBoolean(1); @@ -556,7 +550,6 @@ public boolean existsNotDeletedWithTransaction(Connection connection, String idS statement.setObject(1, preparedStatementFactory.uuidToPgObject(uuid)); statement.setLong(2, version); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { return result.next() && !result.getBoolean(1); @@ -678,7 +671,6 @@ private R update(Connection connection, R resource, long version) throws SQLExce { preparedStatementFactory.configureUpdateNewRowSqlStatement(statement, uuid, version, resource); - logger.trace("Executing query '{}'", statement); statement.execute(); } @@ -728,7 +720,6 @@ protected final Optional getLatestVersionIfExists(UUID uuid, Conn { statement.setObject(1, preparedStatementFactory.uuidToPgObject(uuid)); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -788,7 +779,6 @@ protected final boolean delete(Connection connection, UUID uuid) throws SQLExcep statement.setObject(2, preparedStatementFactory.uuidToPgObject(uuid)); statement.setObject(3, preparedStatementFactory.uuidToPgObject(uuid)); - logger.trace("Executing query '{}'", statement); statement.execute(); logger.debug("{} with ID {} marked as deleted", resourceTypeName, uuid); @@ -818,7 +808,6 @@ public PartialResult searchWithTransaction(Connection connection, DbSearchQue { query.modifyStatement(statement, connection::createArrayOf); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -835,7 +824,6 @@ public PartialResult searchWithTransaction(Connection connection, DbSearchQue { query.modifyStatement(statement, connection::createArrayOf); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { ResultSetMetaData metaData = result.getMetaData(); @@ -957,7 +945,6 @@ public void deletePermanentlyWithTransaction(Connection connection, UUID uuid) { statement.setObject(1, preparedStatementFactory.uuidToPgObject(uuid)); - logger.trace("Executing query '{}'", statement); statement.execute(); logger.debug("{} with ID {} deleted permanently", resourceTypeName, uuid); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ActivityDefinitionDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ActivityDefinitionDaoJdbc.java index 64c714c0c..c339773d6 100644 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ActivityDefinitionDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ActivityDefinitionDaoJdbc.java @@ -105,7 +105,6 @@ public Optional readByProcessUrlVersionAndStatusDraftOrActiv statement.setString(1, processUrl); statement.setString(2, processVersion); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { List definitions = new ArrayList<>(); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/EndpointDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/EndpointDaoJdbc.java index a2dad1bbc..661b5a500 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/EndpointDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/EndpointDaoJdbc.java @@ -9,8 +9,6 @@ import javax.sql.DataSource; import org.hl7.fhir.r4.model.Endpoint; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import ca.uhn.fhir.context.FhirContext; import dev.dsf.fhir.dao.EndpointDao; @@ -24,8 +22,6 @@ public class EndpointDaoJdbc extends AbstractResourceDaoJdbc implements EndpointDao { - private static final Logger logger = LoggerFactory.getLogger(EndpointDaoJdbc.class); - public EndpointDaoJdbc(DataSource dataSource, DataSource permanentDeleteDataSource, FhirContext fhirContext) { super(dataSource, permanentDeleteDataSource, fhirContext, Endpoint.class, "endpoints", "endpoint", @@ -61,7 +57,6 @@ public boolean existsActiveNotDeletedByAddress(String address) throws SQLExcepti { statement.setString(1, address); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { return result.next() && result.getInt(1) > 0; diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/HistroyDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/HistroyDaoJdbc.java index 5cde09147..cb89536d6 100644 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/HistroyDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/HistroyDaoJdbc.java @@ -20,8 +20,6 @@ import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Resource; import org.postgresql.util.PGobject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import ca.uhn.fhir.context.FhirContext; @@ -39,8 +37,6 @@ public class HistroyDaoJdbc implements HistoryDao, InitializingBean { - private static final Logger logger = LoggerFactory.getLogger(HistroyDaoJdbc.class); - private final DataSource dataSource; private final FhirContext fhirContext; private final BinaryDaoJdbc binaryDao; @@ -112,7 +108,6 @@ private History readHistory(List filter, PageAndCount pag { configureStatement(statement, id, resource, filter, atParameters, sinceParameter); - logger.trace("Executing count query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -128,7 +123,6 @@ private History readHistory(List filter, PageAndCount pag { configureStatement(statement, id, resource, filter, atParameters, sinceParameter); - logger.trace("Executing read query '{}'", statement); try (ResultSet result = statement.executeQuery()) { while (result.next()) diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/NamingSystemDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/NamingSystemDaoJdbc.java index 80dfe77c1..33b2692c2 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/NamingSystemDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/NamingSystemDaoJdbc.java @@ -64,7 +64,6 @@ public Optional readByNameWithTransaction(Connection connection, S { statement.setString(1, name); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -89,7 +88,6 @@ public boolean existsWithUniqueIdUriEntry(Connection connection, String uniqueId { statement.setString(1, namingSystem); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { boolean found = result.next() && result.getInt(1) > 0; @@ -117,7 +115,6 @@ public boolean existsWithUniqueIdUriEntryResolvable(Connection connection, Strin { statement.setString(1, namingSystem); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { boolean found = result.next() && result.getInt(1) > 0; diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/OrganizationAffiliationDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/OrganizationAffiliationDaoJdbc.java index d63be7057..930f3ccee 100644 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/OrganizationAffiliationDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/OrganizationAffiliationDaoJdbc.java @@ -13,8 +13,6 @@ import javax.sql.DataSource; import org.hl7.fhir.r4.model.OrganizationAffiliation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import ca.uhn.fhir.context.FhirContext; import dev.dsf.fhir.dao.OrganizationAffiliationDao; @@ -29,8 +27,6 @@ public class OrganizationAffiliationDaoJdbc extends AbstractResourceDaoJdbc implements OrganizationAffiliationDao { - private static final Logger logger = LoggerFactory.getLogger(OrganizationAffiliationDaoJdbc.class); - public OrganizationAffiliationDaoJdbc(DataSource dataSource, DataSource permanentDeleteDataSource, FhirContext fhirContext) { @@ -85,7 +81,6 @@ public List readActiveNotDeletedByMemberOrganizationIde statement.setString(1, "[{\"system\": \"http://dsf.dev/sid/organization-identifier\", \"value\": \"" + identifierValue + "\"}]"); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { List affiliations = new ArrayList<>(); @@ -131,7 +126,6 @@ public boolean existsNotDeletedByParentOrganizationMemberOrganizationRoleAndNotE statement.setString(3, "[{\"code\": \"" + roleCode + "\", \"system\": \"" + roleSystem + "\"}]"); statement.setString(4, "Endpoint/" + endpoint.toString()); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { return result.next() && result.getInt(1) > 0; diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/OrganizationDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/OrganizationDaoJdbc.java index 3cde16975..dfcaa2985 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/OrganizationDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/OrganizationDaoJdbc.java @@ -73,7 +73,6 @@ public Optional readActiveNotDeletedByThumbprint(String thumbprint + thumbprintHex + "\"}]"; statement.setString(1, search); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -116,7 +115,6 @@ public Optional readActiveNotDeletedByIdentifier(String identifier + identifierValue + "\"}]"; statement.setString(1, search); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) @@ -158,7 +156,6 @@ public boolean existsNotDeletedByThumbprintWithTransaction(Connection connection + thumbprintHex + "\"}]"; statement.setString(1, search); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ReadAccessDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ReadAccessDaoJdbc.java index a8f538485..aa4a5d58f 100644 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ReadAccessDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ReadAccessDaoJdbc.java @@ -12,8 +12,6 @@ import javax.sql.DataSource; import org.postgresql.util.PGobject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import ca.uhn.fhir.parser.DataFormatException; @@ -21,8 +19,6 @@ public class ReadAccessDaoJdbc implements ReadAccessDao, InitializingBean { - private static final Logger logger = LoggerFactory.getLogger(ReadAccessDaoJdbc.class); - private final DataSource dataSource; public ReadAccessDaoJdbc(DataSource dataSource) @@ -52,7 +48,6 @@ public List getAccessTypes(Connection connection, UUID resourceId, long statement.setLong(2, version); statement.setObject(3, uuidToPgObject(organizationId)); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { List accessTypes = new ArrayList<>(); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ReadByUrlDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ReadByUrlDaoJdbc.java index a583a5fb4..ab13bbdfa 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ReadByUrlDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/ReadByUrlDaoJdbc.java @@ -11,15 +11,11 @@ import javax.sql.DataSource; import org.hl7.fhir.r4.model.DomainResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import dev.dsf.fhir.function.BiFunctionWithSqlException; class ReadByUrlDaoJdbc { - private static final Logger logger = LoggerFactory.getLogger(ReadByUrlDaoJdbc.class); - private final Supplier dataSourceSupplier; private final BiFunctionWithSqlException resourceExtractor; @@ -119,7 +115,6 @@ Optional readByUrlAndVersionWithTransaction(Connection connection, String url if (version != null && !version.isBlank()) statement.setString(2, version); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { if (result.next()) diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/SubscriptionDaoJdbc.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/SubscriptionDaoJdbc.java index fedfe3ad8..641a872d0 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/SubscriptionDaoJdbc.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/dao/jdbc/SubscriptionDaoJdbc.java @@ -11,8 +11,6 @@ import javax.sql.DataSource; import org.hl7.fhir.r4.model.Subscription; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import ca.uhn.fhir.context.FhirContext; import dev.dsf.fhir.dao.SubscriptionDao; @@ -24,8 +22,6 @@ public class SubscriptionDaoJdbc extends AbstractResourceDaoJdbc implements SubscriptionDao { - private static final Logger logger = LoggerFactory.getLogger(SubscriptionDaoJdbc.class); - public SubscriptionDaoJdbc(DataSource dataSource, DataSource permanentDeleteDataSource, FhirContext fhirContext) { super(dataSource, permanentDeleteDataSource, fhirContext, Subscription.class, "subscriptions", "subscription", @@ -59,7 +55,6 @@ public List readByStatus(Subscription.SubscriptionStatus status) t { statement.setString(1, status.toCode()); - logger.trace("Executing query '{}'", statement); try (ResultSet result = statement.executeQuery()) { List all = new ArrayList<>(); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ExceptionHandler.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ExceptionHandler.java index a18673655..3c8afef73 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ExceptionHandler.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ExceptionHandler.java @@ -232,7 +232,7 @@ public WebApplicationException notMarkedDeleted(String resourceTypeName, Resourc public WebApplicationException gone(String serverBase, String resourceTypeName, ResourceDeletedException e) { - logger.error("{} with id {} is marked as deleted", resourceTypeName, e.getId()); + logger.warn("{} with given id is marked as deleted", resourceTypeName); OperationOutcome outcome = responseGenerator.createOutcome(IssueSeverity.ERROR, IssueType.DELETED, "Resource with id " + e.getId() + " is marked as deleted."); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ResponseGenerator.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ResponseGenerator.java index 8686c9998..f717f3efa 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ResponseGenerator.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ResponseGenerator.java @@ -323,7 +323,7 @@ private OperationOutcome toOperationOutcome(List erro public Response pathVsElementId(String resourceTypeName, String id, IdType resourceId) { - logger.warn("Path id not equal to {} id ({} vs. {})", resourceTypeName, id, resourceId.getIdPart()); + logger.warn("Path id not equal to {}.id", resourceTypeName); OperationOutcome out = createOutcome(IssueSeverity.ERROR, IssueType.PROCESSING, "Path id not equal to " + resourceTypeName + " id (" + id + " vs. " + resourceId.getIdPart() + ")"); @@ -374,16 +374,16 @@ public Response updateAsCreateNotAllowed(String resourceTypeName) public Response multipleExists(String resourceTypeName, String ifNoneExistsHeaderValue) { - logger.warn("Multiple {} resources with criteria {} exist", resourceTypeName, ifNoneExistsHeaderValue); + logger.warn("Multiple {} resources with If-None-Exist criteria exist", resourceTypeName); OperationOutcome outcome = createOutcome(IssueSeverity.ERROR, IssueType.MULTIPLEMATCHES, "Multiple " + resourceTypeName + " resources with criteria '" + ifNoneExistsHeaderValue + "' exist"); return Response.status(Status.PRECONDITION_FAILED).entity(outcome).build(); } - public Response badIfNoneExistHeaderValue(String ifNoneExistsHeaderValue) + public Response badIfNoneExistHeaderValue(String logMessageReason, String ifNoneExistsHeaderValue) { - logger.warn("Bad If-None-Exist header value '{}'", ifNoneExistsHeaderValue); + logger.warn("Bad If-None-Exist header value: {}", logMessageReason); OperationOutcome outcome = createOutcome(IssueSeverity.ERROR, IssueType.PROCESSING, "Bad If-None-Exist header value '" + ifNoneExistsHeaderValue + "'"); @@ -395,7 +395,7 @@ public Response badIfNoneExistHeaderValue(String ifNoneExistsHeaderValue, { String unsupportedQueryParametersString = unsupportedQueryParameters.stream() .map(SearchQueryParameterError::toString).collect(Collectors.joining("; ")); - logger.warn("Bad If-None-Exist header value '{}', unsupported query parameter{} {}", ifNoneExistsHeaderValue, + logger.warn("Bad If-None-Exist header value, unsupported query parameter{} {}", unsupportedQueryParameters.size() != 1 ? "s" : "", unsupportedQueryParametersString); OperationOutcome outcome = createOutcome(IssueSeverity.ERROR, IssueType.PROCESSING, @@ -406,7 +406,7 @@ public Response badIfNoneExistHeaderValue(String ifNoneExistsHeaderValue, public Response oneExists(Resource resource, String ifNoneExistsHeaderValue) { - logger.info("{} with criteria {} exists", resource.getResourceType().name(), ifNoneExistsHeaderValue); + logger.info("{} with criteria from 'If-None-Exist' header exists", resource.getResourceType().name()); OperationOutcome outcome = createOutcome(IssueSeverity.INFORMATION, IssueType.DUPLICATE, "Resource with criteria '" + ifNoneExistsHeaderValue + "' exists"); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/search/parameters/basic/AbstractBooleanParameter.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/search/parameters/basic/AbstractBooleanParameter.java index 2e473644b..c6a877fe3 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/search/parameters/basic/AbstractBooleanParameter.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/search/parameters/basic/AbstractBooleanParameter.java @@ -6,6 +6,8 @@ import org.hl7.fhir.r4.model.Resource; +import com.google.common.base.Objects; + import dev.dsf.fhir.search.SearchQueryParameterError; import dev.dsf.fhir.search.SearchQueryParameterError.SearchQueryParameterErrorType; @@ -69,6 +71,6 @@ public String getBundleUriQueryParameterValue() @Override protected boolean resourceMatches(R resource) { - return hasBoolean.test(resource) && getBoolean.apply(resource) == value; + return hasBoolean.test(resource) && Objects.equal(getBoolean.apply(resource), value); } } diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/DaoConfig.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/DaoConfig.java index 373fcbca4..a26169c42 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/DaoConfig.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/DaoConfig.java @@ -1,11 +1,14 @@ package dev.dsf.fhir.spring.config; +import javax.sql.DataSource; + import org.apache.commons.dbcp2.BasicDataSource; import org.postgresql.Driver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import dev.dsf.common.db.DataSourceWithLogger; import dev.dsf.fhir.dao.ActivityDefinitionDao; import dev.dsf.fhir.dao.BinaryDao; import dev.dsf.fhir.dao.BundleDao; @@ -76,7 +79,7 @@ public class DaoConfig private FhirConfig fhirConfig; @Bean - public BasicDataSource dataSource() + public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(Driver.class.getName()); @@ -87,11 +90,12 @@ public BasicDataSource dataSource() dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("SELECT 1"); - return dataSource; + + return new DataSourceWithLogger(propertiesConfig.getDebugLogMessageDbStatement(), dataSource); } @Bean - public BasicDataSource permanentDeleteDataSource() + public DataSource permanentDeleteDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(Driver.class.getName()); @@ -102,7 +106,8 @@ public BasicDataSource permanentDeleteDataSource() dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("SELECT 1"); - return dataSource; + + return new DataSourceWithLogger(propertiesConfig.getDebugLogMessageDbStatement(), dataSource); } private String toString(char[] password) diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/PropertiesConfig.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/PropertiesConfig.java index 3e206bf7f..6e4933a2e 100644 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/PropertiesConfig.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/PropertiesConfig.java @@ -105,6 +105,18 @@ public class PropertiesConfig implements InitializingBean @Value("${dev.dsf.fhir.server.static.resource.cache:true}") private boolean staticResourceCacheEnabled; + @Documentation(description = "To enable logging of webservices requests set to `true`.", recommendation = "This debug function should only be activated during development. WARNNING: Confidential information may be leaked via the debug log!") + @Value("${dev.dsf.fhir.debug.log.message.webserviceRequest:false}") + private boolean debugLogMessageWebserviceRequest; + + @Documentation(description = "To enable logging of DB queries set to `true`.", recommendation = "This debug function should only be activated during development. WARNNING: Confidential information may be leaked via the debug log!") + @Value("${dev.dsf.fhir.debug.log.message.dbStatement:false}") + private boolean debugLogMessageDbStatement; + + @Documentation(description = "To enable logging of the currently requesting user set to `true`.", recommendation = "This debug function should only be activated during development. WARNNING: Confidential information may be leaked via the debug log!") + @Value("${dev.dsf.fhir.debug.log.message.currentUser:false}") + private boolean debugLogMessageCurrentUser; + @Value("${dev.dsf.server.status.port}") private int jettyStatusConnectorPort; @@ -301,4 +313,19 @@ public ProxyConfig proxyConfig() { return new ProxyConfigImpl(proxyUrl, proxyUsername, proxyPassword, proxyNoProxy); } + + public boolean getDebugLogMessageWebserviceRequest() + { + return debugLogMessageWebserviceRequest; + } + + public boolean getDebugLogMessageDbStatement() + { + return debugLogMessageDbStatement; + } + + public boolean getDebugLogMessageCurrentUser() + { + return debugLogMessageCurrentUser; + } } diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java index ee28a4a57..e455b1830 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java @@ -286,7 +286,8 @@ private void checkAlreadyExists(HttpHeaders headers) throws WebApplicationExcept return; // header not found, nothing to check against if (ifNoneExistHeader.get().isBlank()) - throw new WebApplicationException(responseGenerator.badIfNoneExistHeaderValue(ifNoneExistHeader.get())); + throw new WebApplicationException( + responseGenerator.badIfNoneExistHeaderValue("blank", ifNoneExistHeader.get())); String ifNoneExistHeaderValue = ifNoneExistHeader.get(); if (!ifNoneExistHeaderValue.contains("?")) @@ -295,16 +296,16 @@ private void checkAlreadyExists(HttpHeaders headers) throws WebApplicationExcept UriComponents componentes = UriComponentsBuilder.fromUriString(ifNoneExistHeaderValue).build(); String path = componentes.getPath(); if (path != null && !path.isBlank()) - throw new WebApplicationException(responseGenerator.badIfNoneExistHeaderValue(ifNoneExistHeader.get())); + throw new WebApplicationException( + responseGenerator.badIfNoneExistHeaderValue("no resource", ifNoneExistHeader.get())); Map> queryParameters = parameterConverter .urlDecodeQueryParameters(componentes.getQueryParams()); if (Arrays.stream(SearchQuery.STANDARD_PARAMETERS).anyMatch(queryParameters::containsKey)) { logger.warn( - "{} Header contains query parameter not applicable in this conditional create context: '{}', parameters {} will be ignored", - Constants.HEADER_IF_NONE_EXIST, ifNoneExistHeader.get(), - Arrays.toString(SearchQuery.STANDARD_PARAMETERS)); + "{} Header contains query parameter not applicable in this conditional create context, parameters {} will be ignored", + Constants.HEADER_IF_NONE_EXIST, Arrays.toString(SearchQuery.STANDARD_PARAMETERS)); queryParameters = queryParameters.entrySet().stream() .filter(e -> !Arrays.stream(SearchQuery.STANDARD_PARAMETERS).anyMatch(p -> p.equals(e.getKey()))) diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/AbstractResourceServiceJaxrs.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/AbstractResourceServiceJaxrs.java index 7747a6bd7..b892579ff 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/AbstractResourceServiceJaxrs.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/AbstractResourceServiceJaxrs.java @@ -1,8 +1,6 @@ package dev.dsf.fhir.webservice.jaxrs; import org.hl7.fhir.r4.model.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import ca.uhn.fhir.rest.api.Constants; @@ -24,8 +22,6 @@ public abstract class AbstractResourceServiceJaxrs> extends AbstractServiceJaxrs implements BasicResourceService, InitializingBean { - private static final Logger logger = LoggerFactory.getLogger(AbstractResourceServiceJaxrs.class); - public AbstractResourceServiceJaxrs(S delegate) { super(delegate); @@ -39,8 +35,6 @@ public AbstractResourceServiceJaxrs(S delegate) @Override public Response create(R resource, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("POST {}", uri.getRequestUri().toString()); - return delegate.create(resource, uri, headers); } @@ -51,8 +45,6 @@ public Response create(R resource, @Context UriInfo uri, @Context HttpHeaders he @Override public Response read(@PathParam("id") String id, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.read(id, uri, headers); } @@ -64,8 +56,6 @@ public Response read(@PathParam("id") String id, @Context UriInfo uri, @Context public Response vread(@PathParam("id") String id, @PathParam("version") long version, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.vread(id, version, uri, headers); } @@ -76,8 +66,6 @@ public Response vread(@PathParam("id") String id, @PathParam("version") long ver @Override public Response history(@Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.history(uri, headers); } @@ -88,8 +76,6 @@ public Response history(@Context UriInfo uri, @Context HttpHeaders headers) @Override public Response history(@PathParam("id") String id, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.history(id, uri, headers); } @@ -102,8 +88,6 @@ public Response history(@PathParam("id") String id, @Context UriInfo uri, @Conte @Override public Response update(@PathParam("id") String id, R resource, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("PUT {}", uri.getRequestUri().toString()); - return delegate.update(id, resource, uri, headers); } @@ -115,8 +99,6 @@ public Response update(@PathParam("id") String id, R resource, @Context UriInfo @Override public Response update(R resource, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("PUT {}", uri.getRequestUri().toString()); - return delegate.update(resource, uri, headers); } @@ -129,8 +111,6 @@ public Response update(R resource, @Context UriInfo uri, @Context HttpHeaders he @Override public Response delete(@PathParam("id") String id, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("DELETE {}", uri.getRequestUri().toString()); - return delegate.delete(id, uri, headers); } @@ -142,8 +122,6 @@ public Response delete(@PathParam("id") String id, @Context UriInfo uri, @Contex @Override public Response delete(@Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("DELETE {}", uri.getRequestUri().toString()); - return delegate.delete(uri, headers); } @@ -153,8 +131,6 @@ public Response delete(@Context UriInfo uri, @Context HttpHeaders headers) @Override public Response search(@Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.search(uri, headers); } @@ -168,8 +144,6 @@ public Response search(@Context UriInfo uri, @Context HttpHeaders headers) public Response deletePermanently(@PathParam("delete") String deletePath, @PathParam("id") String id, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("POST {}", uri.getRequestUri().toString()); - return delegate.deletePermanently(deletePath, id, uri, headers); } } diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/BinaryServiceJaxrs.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/BinaryServiceJaxrs.java index a1c90bd92..62eca6d33 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/BinaryServiceJaxrs.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/BinaryServiceJaxrs.java @@ -66,8 +66,6 @@ public void afterPropertiesSet() throws Exception @Override public Response create(InputStream in, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("POST {}", uri.getRequestUri().toString()); - try (in) { String securityContext = getSecurityContext(headers); @@ -243,8 +241,6 @@ private boolean isValidFhirRequest(UriInfo uri, HttpHeaders headers) public Response update(@PathParam("id") String id, InputStream in, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("PUT {}", uri.getRequestUri().toString()); - try (in) { String securityContext = getSecurityContext(headers); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/ConformanceServiceJaxrs.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/ConformanceServiceJaxrs.java index c32b74c04..29ea3e465 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/ConformanceServiceJaxrs.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/ConformanceServiceJaxrs.java @@ -1,8 +1,5 @@ package dev.dsf.fhir.webservice.jaxrs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import ca.uhn.fhir.rest.api.Constants; import dev.dsf.fhir.webservice.specification.ConformanceService; import jakarta.ws.rs.GET; @@ -22,8 +19,6 @@ public class ConformanceServiceJaxrs extends AbstractServiceJaxrs implemen { public static final String PATH = ""; - private static final Logger logger = LoggerFactory.getLogger(RootServiceJaxrs.class); - public RootServiceJaxrs(RootService delegate) { super(delegate); @@ -35,8 +31,6 @@ public RootServiceJaxrs(RootService delegate) @Override public Response root(@Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.root(uri, headers); } @@ -45,8 +39,6 @@ public Response root(@Context UriInfo uri, @Context HttpHeaders headers) @Override public Response history(@Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.history(uri, headers); } @@ -56,8 +48,6 @@ public Response history(@Context UriInfo uri, @Context HttpHeaders headers) @Override public Response handleBundle(Bundle bundle, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("POST {}", uri.getRequestUri().toString()); - return delegate.handleBundle(bundle, uri, headers); } } diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/StructureDefinitionServiceJaxrs.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/StructureDefinitionServiceJaxrs.java index 373ff159b..2f0aeca6c 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/StructureDefinitionServiceJaxrs.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/jaxrs/StructureDefinitionServiceJaxrs.java @@ -2,8 +2,6 @@ import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.StructureDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import dev.dsf.fhir.webservice.specification.StructureDefinitionService; import jakarta.ws.rs.GET; @@ -22,8 +20,6 @@ public class StructureDefinitionServiceJaxrs { public static final String PATH = "StructureDefinition"; - private static final Logger logger = LoggerFactory.getLogger(StructureDefinitionServiceJaxrs.class); - public StructureDefinitionServiceJaxrs(StructureDefinitionService delegate) { super(delegate); @@ -35,8 +31,6 @@ public StructureDefinitionServiceJaxrs(StructureDefinitionService delegate) public Response postSnapshotNew(@PathParam("snapshot") String snapshotPath, Parameters parameters, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("POST {}", uri.getRequestUri().toString()); - return delegate.postSnapshotNew(snapshotPath, parameters, uri, headers); } @@ -46,8 +40,6 @@ public Response postSnapshotNew(@PathParam("snapshot") String snapshotPath, Para public Response getSnapshotNew(@PathParam("snapshot") String snapshotPath, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.getSnapshotNew(snapshotPath, uri, headers); } @@ -57,8 +49,6 @@ public Response getSnapshotNew(@PathParam("snapshot") String snapshotPath, @Cont public Response postSnapshotExisting(@PathParam("snapshot") String snapshotPath, @PathParam("id") String id, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("POST {}", uri.getRequestUri().toString()); - return delegate.postSnapshotExisting(snapshotPath, id, uri, headers); } @@ -68,8 +58,6 @@ public Response postSnapshotExisting(@PathParam("snapshot") String snapshotPath, public Response getSnapshotExisting(@PathParam("snapshot") String snapshotPath, @PathParam("id") String id, @Context UriInfo uri, @Context HttpHeaders headers) { - logger.trace("GET {}", uri.getRequestUri().toString()); - return delegate.getSnapshotExisting(snapshotPath, id, uri, headers); } } diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractResourceServiceSecure.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractResourceServiceSecure.java index e14555412..364f5238d 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractResourceServiceSecure.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractResourceServiceSecure.java @@ -140,8 +140,6 @@ private Response withResourceValidation(R resource, UriInfo uri, HttpHeaders hea @Override public Response create(R resource, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - resolveLiteralInternalRelatedArtifactOrAttachmentUrls(resource); Optional reasonCreateAllowed = authorizationRule.reasonCreateAllowed(getCurrentIdentity(), resource); @@ -207,8 +205,6 @@ else if (reference.hasAttachment()) @Override public Response read(String id, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Response read = delegate.read(id, uri, headers); if (read.hasEntity() && resourceType.isInstance(read.getEntity())) @@ -276,8 +272,6 @@ else if (read.hasEntity()) @Override public Response vread(String id, long version, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Response read = delegate.vread(id, version, uri, headers); if (read.hasEntity() && resourceType.isInstance(read.getEntity())) @@ -345,8 +339,6 @@ else if (read.hasEntity()) @Override public Response history(UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Optional reasonHistoryAllowed = authorizationRule.reasonHistoryAllowed(getCurrentIdentity()); if (reasonHistoryAllowed.isEmpty()) { @@ -368,8 +360,6 @@ public Response history(UriInfo uri, HttpHeaders headers) @Override public Response history(String id, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Optional reasonHistoryAllowed = authorizationRule.reasonHistoryAllowed(getCurrentIdentity()); if (reasonHistoryAllowed.isEmpty()) { @@ -391,8 +381,6 @@ public Response history(String id, UriInfo uri, HttpHeaders headers) @Override public Response update(String id, R resource, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Optional dbResource = exceptionHandler.handleSqlAndResourceDeletedException(serverBase, resourceTypeName, () -> dao.read(parameterConverter.toUuid(resourceTypeName, id))); @@ -454,8 +442,6 @@ else if (!updated.hasEntity() @Override public Response update(R resource, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Map> queryParameters = uri.getQueryParameters(); PartialResult result = getExisting(queryParameters); @@ -564,8 +550,6 @@ private PartialResult getExisting(Map> queryParameters) @Override public Response delete(String id, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Optional dbResource = exceptionHandler .handleSqlException(() -> dao.readIncludingDeleted(parameterConverter.toUuid(resourceTypeName, id))); @@ -607,8 +591,6 @@ resourceTypeName, resourceId, resourceVersion, getCurrentIdentity().getName(), @Override public Response delete(UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Map> queryParameters = uri.getQueryParameters(); if (Arrays.stream(SearchQuery.STANDARD_PARAMETERS).anyMatch(queryParameters::containsKey)) { @@ -672,8 +654,6 @@ else if (result.getTotal() == 1) @Override public Response search(UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Optional reasonSearchAllowed = authorizationRule.reasonSearchAllowed(getCurrentIdentity()); if (reasonSearchAllowed.isEmpty()) { @@ -695,8 +675,6 @@ public Response search(UriInfo uri, HttpHeaders headers) @Override public Response deletePermanently(String deletePath, String id, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Optional dbResource = exceptionHandler .handleSqlException(() -> dao.readIncludingDeleted(parameterConverter.toUuid(resourceTypeName, id))); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractServiceSecure.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractServiceSecure.java index 72e60b6a5..ad9a1a05f 100644 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractServiceSecure.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractServiceSecure.java @@ -1,15 +1,11 @@ package dev.dsf.fhir.webservice.secure; import java.util.Objects; -import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; -import dev.dsf.common.auth.conf.Identity; -import dev.dsf.common.auth.conf.OrganizationIdentity; -import dev.dsf.common.auth.conf.PractitionerIdentity; import dev.dsf.fhir.help.ResponseGenerator; import dev.dsf.fhir.service.ReferenceResolver; import dev.dsf.fhir.webservice.base.AbstractDelegatingBasicService; @@ -19,7 +15,6 @@ public abstract class AbstractServiceSecure extends AbstractDelegatingBasicService implements InitializingBean { - private static final Logger logger = LoggerFactory.getLogger(AbstractServiceSecure.class); protected static final Logger audit = LoggerFactory.getLogger("dsf-audit-logger"); protected final String serverBase; @@ -50,20 +45,4 @@ protected final Response forbidden(String operation) { return responseGenerator.forbiddenNotAllowed(operation, currentIdentityProvider.getCurrentIdentity()); } - - protected void logCurrentIdentity() - { - Identity identity = getCurrentIdentity(); - if (identity instanceof OrganizationIdentity) - { - logger.debug("Current organization identity '{}', dsf-roles '{}'", identity.getName(), - identity.getDsfRoles()); - } - else if (identity instanceof PractitionerIdentity practitioner) - { - logger.debug("Current practitioner identity '{}', dsf-roles '{}', practitioner-roles '{}'", - identity.getName(), identity.getDsfRoles(), practitioner.getPractionerRoles().stream() - .map(c -> c.getSystem() + "|" + c.getCode()).collect(Collectors.joining(", ", "[", "]"))); - } - } } diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/ConformanceServiceSecure.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/ConformanceServiceSecure.java index 1b718630b..898ad4b19 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/ConformanceServiceSecure.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/ConformanceServiceSecure.java @@ -18,8 +18,6 @@ public ConformanceServiceSecure(ConformanceService delegate, String serverBase, @Override public Response getMetadata(String mode, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - // get metadata allowed for all authenticated users return delegate.getMetadata(mode, uri, headers); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/RootServiceSecure.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/RootServiceSecure.java index d4e62b751..a655dd9c6 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/RootServiceSecure.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/RootServiceSecure.java @@ -42,8 +42,6 @@ public void afterPropertiesSet() throws Exception @Override public Response root(UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - // get root allowed for all authenticated users return delegate.root(uri, headers); @@ -52,8 +50,6 @@ public Response root(UriInfo uri, HttpHeaders headers) @Override public Response handleBundle(Bundle bundle, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Optional reasonHandleBundleAllowed = reasonHandleBundleAllowed(bundle); if (reasonHandleBundleAllowed.isEmpty()) @@ -88,8 +84,6 @@ private Optional reasonHandleBundleAllowed(Bundle bundle) @Override public Response history(UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - Optional reasonHistoryAllowed = authorizationRule.reasonHistoryAllowed(getCurrentIdentity()); if (reasonHistoryAllowed.isEmpty()) { diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/StructureDefinitionServiceSecure.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/StructureDefinitionServiceSecure.java index 8a0eb3120..ccd7ad151 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/StructureDefinitionServiceSecure.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/StructureDefinitionServiceSecure.java @@ -35,32 +35,24 @@ public StructureDefinitionServiceSecure(StructureDefinitionService delegate, Str @Override public Response postSnapshotNew(String snapshotPath, Parameters parameters, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - return delegate.postSnapshotNew(snapshotPath, parameters, uri, headers); } @Override public Response getSnapshotNew(String snapshotPath, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - return delegate.getSnapshotNew(snapshotPath, uri, headers); } @Override public Response postSnapshotExisting(String snapshotPath, String id, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - return delegate.postSnapshotExisting(snapshotPath, id, uri, headers); } @Override public Response getSnapshotExisting(String snapshotPath, String id, UriInfo uri, HttpHeaders headers) { - logCurrentIdentity(); - return delegate.getSnapshotExisting(snapshotPath, id, uri, headers); } } diff --git a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractDbTest.java b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractDbTest.java index 7ec4f31a3..8d79cc45a 100644 --- a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractDbTest.java +++ b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractDbTest.java @@ -2,12 +2,16 @@ import java.util.Map; +import javax.sql.DataSource; + import org.apache.commons.dbcp2.BasicDataSource; import org.postgresql.Driver; import org.slf4j.bridge.SLF4JBridgeHandler; import com.fasterxml.jackson.core.StreamReadConstraints; +import dev.dsf.common.db.DataSourceWithLogger; + public abstract class AbstractDbTest { static @@ -20,6 +24,8 @@ public abstract class AbstractDbTest StreamReadConstraints.builder().maxStringLength(Integer.MAX_VALUE).build()); } + protected static final boolean LOG_DB_STATEMENTS = true; + protected static final String CHANGE_LOG_FILE = "db/db.changelog.xml"; protected static final String DATABASE_USERS_GROUP = "server_users_group"; @@ -38,7 +44,7 @@ public abstract class AbstractDbTest "db.server_permanent_delete_user", DATABASE_DELETE_USER, "db.server_permanent_delete_user_password", DATABASE_DELETE_USER_PASSWORD); - public static BasicDataSource createDefaultDataSource(String host, int port, String databaseName) + public static DataSource createDefaultDataSource(String host, int port, String databaseName) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(Driver.class.getName()); @@ -50,10 +56,10 @@ public static BasicDataSource createDefaultDataSource(String host, int port, Str dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("SELECT 1"); - return dataSource; + return new DataSourceWithLogger(LOG_DB_STATEMENTS, dataSource); } - public static BasicDataSource createPermanentDeleteDataSource(String host, int port, String databaseName) + public static DataSource createPermanentDeleteDataSource(String host, int port, String databaseName) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(Driver.class.getName()); @@ -65,6 +71,6 @@ public static BasicDataSource createPermanentDeleteDataSource(String host, int p dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("SELECT 1"); - return dataSource; + return new DataSourceWithLogger(LOG_DB_STATEMENTS, dataSource); } } diff --git a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractReadAccessDaoTest.java b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractReadAccessDaoTest.java index c9a88b407..f4b0cb833 100644 --- a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractReadAccessDaoTest.java +++ b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractReadAccessDaoTest.java @@ -63,7 +63,7 @@ protected void assertReadAccessEntryCount(int totalExpectedCount, int expectedCo String accessType, Organization organization, OrganizationAffiliation organizationAffiliation) throws Exception { - try (Connection connection = getDefaultDataSource().getConnection(); + try (Connection connection = defaultDataSource.getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT count(*) FROM read_access")) { try (ResultSet result = statement.executeQuery()) @@ -81,7 +81,7 @@ protected void assertReadAccessEntryCount(int totalExpectedCount, int expectedCo if (organizationAffiliation != null) query.append(" AND organization_affiliation_id = ?"); - try (Connection connection = getDefaultDataSource().getConnection(); + try (Connection connection = defaultDataSource.getConnection(); PreparedStatement statement = connection.prepareStatement(query.toString())) { statement.setObject(1, toUuidObject(resource.getIdElement().getIdPart())); @@ -141,8 +141,8 @@ public void testReadAccessTriggerOrganization() throws Exception Organization org = new Organization(); org.setActive(true); org.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("org.com"); - Organization createdOrg = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()).create(org); + Organization createdOrg = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext) + .create(org); D d = createResource(); readAccessHelper.addOrganization(d, createdOrg); @@ -169,8 +169,8 @@ public void testReadAccessTriggerOrganizationResourceFirst() throws Exception Organization org = new Organization(); org.setActive(true); org.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue(orgIdentifier); - Organization createdOrg = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()).create(org); + Organization createdOrg = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext) + .create(org); assertReadAccessEntryCount(2, 1, createdD, READ_ACCESS_TAG_VALUE_LOCAL); assertReadAccessEntryCount(2, 1, createdD, READ_ACCESS_TAG_VALUE_ORGANIZATION, createdOrg); @@ -179,8 +179,8 @@ public void testReadAccessTriggerOrganizationResourceFirst() throws Exception @Test public void testReadAccessTriggerOrganization2Organizations1Matching() throws Exception { - OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, + fhirContext); Organization org1 = new Organization(); org1.setActive(true); @@ -205,8 +205,8 @@ public void testReadAccessTriggerOrganization2Organizations1Matching() throws Ex @Test public void testReadAccessTriggerOrganization2Organizations2Matching() throws Exception { - OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, + fhirContext); Organization org1 = new Organization(); org1.setActive(true); @@ -240,8 +240,7 @@ public void testReadAccessTriggerRole() throws Exception memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -252,8 +251,8 @@ public void testReadAccessTriggerRole() throws Exception aff.getOrganization().setReference("Organization/" + createdParentOrg.getIdElement().getIdPart()); aff.getParticipatingOrganization().setReference("Organization/" + createdMemberOrg.getIdElement().getIdPart()); - OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()).create(aff); + OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext).create(aff); D d = createResource(); readAccessHelper.addRole(d, "parent.com", "http://dsf.dev/fhir/CodeSystem/organization-role", "DIC"); @@ -283,8 +282,7 @@ public void testReadAccessTriggerRoleResourceFirst() throws Exception memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -295,8 +293,8 @@ public void testReadAccessTriggerRoleResourceFirst() throws Exception aff.getOrganization().setReference("Organization/" + createdParentOrg.getIdElement().getIdPart()); aff.getParticipatingOrganization().setReference("Organization/" + createdMemberOrg.getIdElement().getIdPart()); - OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()).create(aff); + OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext).create(aff); assertReadAccessEntryCount(2, 1, createdD, READ_ACCESS_TAG_VALUE_LOCAL); assertReadAccessEntryCount(2, 1, createdD, READ_ACCESS_TAG_VALUE_ROLE, createdMemberOrg, createdAff); @@ -317,8 +315,7 @@ public void testReadAccessTriggerRole2Organizations1Matching() throws Exception memberOrg2.setActive(true); memberOrg2.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member2.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg1 = orgDao.create(memberOrg1); Organization createdMemberOrg2 = orgDao.create(memberOrg2); @@ -340,7 +337,7 @@ public void testReadAccessTriggerRole2Organizations1Matching() throws Exception .setReference("Organization/" + createdMemberOrg2.getIdElement().getIdPart()); OrganizationAffiliationDaoJdbc organizationAffiliationDao = new OrganizationAffiliationDaoJdbc( - getDefaultDataSource(), getPermanentDeleteDataSource(), getFhirContext()); + defaultDataSource, permanentDeleteDataSource, fhirContext); OrganizationAffiliation createdAff1 = organizationAffiliationDao.create(aff1); OrganizationAffiliation createdAff2 = organizationAffiliationDao.create(aff2); @@ -369,8 +366,7 @@ public void testReadAccessTriggerRole2Organizations2Matching() throws Exception memberOrg2.setActive(true); memberOrg2.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member2.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg1 = orgDao.create(memberOrg1); Organization createdMemberOrg2 = orgDao.create(memberOrg2); @@ -392,7 +388,7 @@ public void testReadAccessTriggerRole2Organizations2Matching() throws Exception .setReference("Organization/" + createdMemberOrg2.getIdElement().getIdPart()); OrganizationAffiliationDaoJdbc organizationAffiliationDao = new OrganizationAffiliationDaoJdbc( - getDefaultDataSource(), getPermanentDeleteDataSource(), getFhirContext()); + defaultDataSource, permanentDeleteDataSource, fhirContext); OrganizationAffiliation createdAff1 = organizationAffiliationDao.create(aff1); OrganizationAffiliation createdAff2 = organizationAffiliationDao.create(aff2); @@ -447,8 +443,8 @@ public void testReadAccessTriggerLocalUpdate() throws Exception @Test public void testReadAccessTriggerOrganizationUpdate() throws Exception { - final OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + final OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext); Organization org = new Organization(); org.setActive(true); @@ -481,7 +477,7 @@ public void testReadAccessTriggerOrganizationUpdate() throws Exception public void testReadAccessTriggerRoleUpdate() throws Exception { final OrganizationAffiliationDaoJdbc organizationAffiliationDao = new OrganizationAffiliationDaoJdbc( - getDefaultDataSource(), getPermanentDeleteDataSource(), getFhirContext()); + defaultDataSource, permanentDeleteDataSource, fhirContext); Organization parentOrg = new Organization(); parentOrg.setActive(true); @@ -491,8 +487,7 @@ public void testReadAccessTriggerRoleUpdate() throws Exception memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -531,7 +526,7 @@ public void testReadAccessTriggerRoleUpdate() throws Exception public void testReadAccessTriggerRoleUpdateMemberOrganizationNonActive() throws Exception { final OrganizationAffiliationDaoJdbc organizationAffiliationDao = new OrganizationAffiliationDaoJdbc( - getDefaultDataSource(), getPermanentDeleteDataSource(), getFhirContext()); + defaultDataSource, permanentDeleteDataSource, fhirContext); Organization parentOrg = new Organization(); parentOrg.setActive(true); @@ -541,8 +536,7 @@ public void testReadAccessTriggerRoleUpdateMemberOrganizationNonActive() throws memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -581,7 +575,7 @@ public void testReadAccessTriggerRoleUpdateMemberOrganizationNonActive() throws public void testReadAccessTriggerRoleUpdateParentOrganizationNonActive() throws Exception { final OrganizationAffiliationDaoJdbc organizationAffiliationDao = new OrganizationAffiliationDaoJdbc( - getDefaultDataSource(), getPermanentDeleteDataSource(), getFhirContext()); + defaultDataSource, permanentDeleteDataSource, fhirContext); Organization parentOrg = new Organization(); parentOrg.setActive(true); @@ -591,8 +585,7 @@ public void testReadAccessTriggerRoleUpdateParentOrganizationNonActive() throws memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -631,7 +624,7 @@ public void testReadAccessTriggerRoleUpdateParentOrganizationNonActive() throws public void testReadAccessTriggerRoleUpdateMemberAndParentOrganizationNonActive() throws Exception { final OrganizationAffiliationDaoJdbc organizationAffiliationDao = new OrganizationAffiliationDaoJdbc( - getDefaultDataSource(), getPermanentDeleteDataSource(), getFhirContext()); + defaultDataSource, permanentDeleteDataSource, fhirContext); Organization parentOrg = new Organization(); parentOrg.setActive(true); @@ -641,8 +634,7 @@ public void testReadAccessTriggerRoleUpdateMemberAndParentOrganizationNonActive( memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -724,8 +716,8 @@ public void testReadAccessTriggerLocalDelete() throws Exception @Test public void testReadAccessTriggerOrganizationDeleteOrganization() throws Exception { - final OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + final OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext); Organization org = new Organization(); org.setActive(true); @@ -759,8 +751,8 @@ public void testReadAccessTriggerOrganizationDeleteOrganization() throws Excepti @Test public void testReadAccessTriggerOrganizationDeleteResource() throws Exception { - final OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + final OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext); Organization org = new Organization(); org.setActive(true); @@ -801,8 +793,7 @@ public void testReadAccessTriggerRoleDeleteOrganizationAffiliation() throws Exce memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -813,8 +804,8 @@ public void testReadAccessTriggerRoleDeleteOrganizationAffiliation() throws Exce aff.getOrganization().setReference("Organization/" + createdParentOrg.getIdElement().getIdPart()); aff.getParticipatingOrganization().setReference("Organization/" + createdMemberOrg.getIdElement().getIdPart()); - OrganizationAffiliationDaoJdbc orgAffDao = new OrganizationAffiliationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + OrganizationAffiliationDaoJdbc orgAffDao = new OrganizationAffiliationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext); OrganizationAffiliation createdAff = orgAffDao.create(aff); D d = createResource(); @@ -851,8 +842,7 @@ public void testReadAccessTriggerRoleDeleteResource() throws Exception memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -863,8 +853,8 @@ public void testReadAccessTriggerRoleDeleteResource() throws Exception aff.getOrganization().setReference("Organization/" + createdParentOrg.getIdElement().getIdPart()); aff.getParticipatingOrganization().setReference("Organization/" + createdMemberOrg.getIdElement().getIdPart()); - OrganizationAffiliationDaoJdbc orgAffDao = new OrganizationAffiliationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + OrganizationAffiliationDaoJdbc orgAffDao = new OrganizationAffiliationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext); OrganizationAffiliation createdAff = orgAffDao.create(aff); D d = createResource(); @@ -900,8 +890,7 @@ public void testReadAccessTriggerRoleDeleteMember() throws Exception memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -912,8 +901,8 @@ public void testReadAccessTriggerRoleDeleteMember() throws Exception aff.getOrganization().setReference("Organization/" + createdParentOrg.getIdElement().getIdPart()); aff.getParticipatingOrganization().setReference("Organization/" + createdMemberOrg.getIdElement().getIdPart()); - OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()).create(aff); + OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext).create(aff); D d = createResource(); readAccessHelper.addRole(d, "parent.com", "http://dsf.dev/fhir/CodeSystem/organization-role", "DIC"); @@ -949,8 +938,7 @@ public void testReadAccessTriggerRoleDeleteParent() throws Exception memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -961,8 +949,8 @@ public void testReadAccessTriggerRoleDeleteParent() throws Exception aff.getOrganization().setReference("Organization/" + createdParentOrg.getIdElement().getIdPart()); aff.getParticipatingOrganization().setReference("Organization/" + createdMemberOrg.getIdElement().getIdPart()); - OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()).create(aff); + OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext).create(aff); D d = createResource(); readAccessHelper.addRole(d, "parent.com", "http://dsf.dev/fhir/CodeSystem/organization-role", "DIC"); @@ -998,8 +986,7 @@ public void testReadAccessTriggerRoleDeleteMemberAndParent() throws Exception memberOrg.setActive(true); memberOrg.addIdentifier().setSystem(ORGANIZATION_IDENTIFIER_SYSTEM).setValue("member.com"); - OrganizationDao orgDao = new OrganizationDaoJdbc(getDefaultDataSource(), getPermanentDeleteDataSource(), - getFhirContext()); + OrganizationDao orgDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, fhirContext); Organization createdParentOrg = orgDao.create(parentOrg); Organization createdMemberOrg = orgDao.create(memberOrg); @@ -1010,8 +997,8 @@ public void testReadAccessTriggerRoleDeleteMemberAndParent() throws Exception aff.getOrganization().setReference("Organization/" + createdParentOrg.getIdElement().getIdPart()); aff.getParticipatingOrganization().setReference("Organization/" + createdMemberOrg.getIdElement().getIdPart()); - OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()).create(aff); + OrganizationAffiliation createdAff = new OrganizationAffiliationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext).create(aff); D d = createResource(); readAccessHelper.addRole(d, "parent.com", "http://dsf.dev/fhir/CodeSystem/organization-role", "DIC"); @@ -1044,8 +1031,8 @@ public void testReadAccessTriggerRoleDeleteMemberAndParent() throws Exception private void testSearchWithUserFilterAfterReadAccessTrigger(String accessType, Consumer readAccessModifier, Function userCreator, int expectedCount) throws Exception { - OrganizationDao organizationDao = new OrganizationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + OrganizationDao organizationDao = new OrganizationDaoJdbc(defaultDataSource, permanentDeleteDataSource, + fhirContext); Organization org = new Organization(); Organization createdOrg = organizationDao.create(org); diff --git a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractResourceDaoTest.java b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractResourceDaoTest.java index 5e315f987..6de3c7ee7 100755 --- a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractResourceDaoTest.java +++ b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/AbstractResourceDaoTest.java @@ -42,8 +42,8 @@ public interface TriFunction R apply(A a, B b, C c); } - protected static BasicDataSource defaultDataSource; - protected static BasicDataSource permanentDeleteDataSource; + protected static DataSource defaultDataSource; + protected static DataSource permanentDeleteDataSource; @ClassRule public static final PostgreSqlContainerLiquibaseTemplateClassRule liquibaseRule = new PostgreSqlContainerLiquibaseTemplateClassRule( @@ -58,21 +58,21 @@ public static void beforeClass() throws Exception { defaultDataSource = createDefaultDataSource(liquibaseRule.getHost(), liquibaseRule.getMappedPort(5432), liquibaseRule.getDatabaseName()); - defaultDataSource.start(); + defaultDataSource.unwrap(BasicDataSource.class).start(); permanentDeleteDataSource = createPermanentDeleteDataSource(liquibaseRule.getHost(), liquibaseRule.getMappedPort(5432), liquibaseRule.getDatabaseName()); - permanentDeleteDataSource.start(); + permanentDeleteDataSource.unwrap(BasicDataSource.class).start(); } @AfterClass public static void afterClass() throws Exception { if (defaultDataSource != null) - defaultDataSource.close(); + defaultDataSource.unwrap(BasicDataSource.class).close(); if (permanentDeleteDataSource != null) - permanentDeleteDataSource.close(); + permanentDeleteDataSource.unwrap(BasicDataSource.class).close(); } protected final Class resouceClass; @@ -99,21 +99,6 @@ public C getDao() return dao; } - public FhirContext getFhirContext() - { - return fhirContext; - } - - public BasicDataSource getDefaultDataSource() - { - return defaultDataSource; - } - - public BasicDataSource getPermanentDeleteDataSource() - { - return permanentDeleteDataSource; - } - public Logger getLogger() { return logger; diff --git a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/BinaryDaoTest.java b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/BinaryDaoTest.java index e06b4a6f8..8a2e6ad49 100755 --- a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/BinaryDaoTest.java +++ b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/BinaryDaoTest.java @@ -1043,8 +1043,8 @@ public void testReadAccessTriggerSecurityContextLocalDelete() throws Exception @Test public void testReadAccessTriggerSecurityContextOrganizationDelete() throws Exception { - final OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(getDefaultDataSource(), - getPermanentDeleteDataSource(), getFhirContext()); + final OrganizationDaoJdbc organizationDao = new OrganizationDaoJdbc(defaultDataSource, + permanentDeleteDataSource, fhirContext); Organization org = new Organization(); org.setActive(true); diff --git a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/HistoryDaoTest.java b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/HistoryDaoTest.java index b8e335ce0..23b58d3fc 100644 --- a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/HistoryDaoTest.java +++ b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/dao/HistoryDaoTest.java @@ -6,6 +6,8 @@ import java.util.Collections; import java.util.UUID; +import javax.sql.DataSource; + import org.apache.commons.dbcp2.BasicDataSource; import org.hl7.fhir.r4.model.Organization; import org.junit.AfterClass; @@ -30,8 +32,8 @@ public class HistoryDaoTest extends AbstractDbTest { - private static BasicDataSource defaultDataSource; - private static BasicDataSource permanentDeleteDataSource; + private static DataSource defaultDataSource; + private static DataSource permanentDeleteDataSource; @ClassRule public static final PostgreSqlContainerLiquibaseTemplateClassRule liquibaseRule = new PostgreSqlContainerLiquibaseTemplateClassRule( @@ -46,18 +48,18 @@ public static void beforeClass() throws Exception { defaultDataSource = createDefaultDataSource(liquibaseRule.getHost(), liquibaseRule.getMappedPort(5432), liquibaseRule.getDatabaseName()); - defaultDataSource.start(); + defaultDataSource.unwrap(BasicDataSource.class).start(); permanentDeleteDataSource = createPermanentDeleteDataSource(liquibaseRule.getHost(), liquibaseRule.getMappedPort(5432), liquibaseRule.getDatabaseName()); - permanentDeleteDataSource.start(); + permanentDeleteDataSource.unwrap(BasicDataSource.class).start(); } @AfterClass public static void afterClass() throws Exception { - defaultDataSource.close(); - permanentDeleteDataSource.close(); + defaultDataSource.unwrap(BasicDataSource.class).close(); + permanentDeleteDataSource.unwrap(BasicDataSource.class).close(); } private final FhirContext fhirContext = FhirContext.forR4(); diff --git a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/AbstractIntegrationTest.java b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/AbstractIntegrationTest.java index 4f7d3ed62..d559e57dd 100755 --- a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/AbstractIntegrationTest.java +++ b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/AbstractIntegrationTest.java @@ -28,6 +28,8 @@ import java.util.function.Function; import java.util.function.Supplier; +import javax.sql.DataSource; + import org.apache.commons.dbcp2.BasicDataSource; import org.eclipse.jetty.security.SecurityHandler; import org.eclipse.jetty.server.Server; @@ -86,7 +88,7 @@ public abstract class AbstractIntegrationTest extends AbstractDbTest @ClassRule public static final X509Certificates certificates = new X509Certificates(); - protected static BasicDataSource defaultDataSource; + protected static DataSource defaultDataSource; @ClassRule public static final PostgreSqlContainerLiquibaseTemplateClassRule liquibaseRule = new PostgreSqlContainerLiquibaseTemplateClassRule( @@ -123,7 +125,7 @@ public static void beforeClass() throws Exception { defaultDataSource = createDefaultDataSource(liquibaseRule.getHost(), liquibaseRule.getMappedPort(5432), liquibaseRule.getDatabaseName()); - defaultDataSource.start(); + defaultDataSource.unwrap(BasicDataSource.class).start(); logger.info("Creating Bundle ..."); createTestBundle(certificates.getClientCertificate(), certificates.getExternalClientCertificate()); @@ -328,7 +330,7 @@ private static void createTestBundle(ClientCertificate clientCertificate, @AfterClass public static void afterClass() throws Exception { - defaultDataSource.close(); + defaultDataSource.unwrap(BasicDataSource.class).close(); try { diff --git a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/BundleIntegrationTest.java b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/BundleIntegrationTest.java index 5225dd55a..7a56bb32d 100644 --- a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/BundleIntegrationTest.java +++ b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/BundleIntegrationTest.java @@ -17,7 +17,8 @@ import java.util.Optional; import java.util.UUID; -import org.apache.commons.dbcp2.BasicDataSource; +import javax.sql.DataSource; + import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent; import org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent; @@ -184,7 +185,7 @@ public void testPostTransactionBundle() throws Exception checkReturnBundle(BundleType.TRANSACTIONRESPONSE, rBundle, bundle.getEntry().size(), Arrays.asList("200 OK", "201 Created", "200 OK", "200 OK", "200 OK", "200 OK", "200 OK", "404 Not Found")); - BasicDataSource dataSource = getSpringWebApplicationContext().getBean("dataSource", BasicDataSource.class); + DataSource dataSource = getSpringWebApplicationContext().getBean("dataSource", DataSource.class); try (Connection connection = dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT count(*) FROM current_patients"); ResultSet result = statement.executeQuery()) @@ -208,7 +209,7 @@ public void testPostBatchBundle() throws Exception checkReturnBundle(BundleType.BATCHRESPONSE, rBundle, bundle.getEntry().size(), Arrays.asList("200 OK", "201 Created", "200 OK", "200 OK", "200 OK", "200 OK", "200 OK", "404 Not Found")); - BasicDataSource dataSource = getSpringWebApplicationContext().getBean("dataSource", BasicDataSource.class); + DataSource dataSource = getSpringWebApplicationContext().getBean("dataSource", DataSource.class); try (Connection connection = dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT count(*) FROM current_patients"); ResultSet result = statement.executeQuery()) @@ -317,7 +318,7 @@ public void testPostPartialyFailingBatchBundle() throws Exception checkReturnBundle(BundleType.BATCHRESPONSE, rBundle, bundle.getEntry().size(), Arrays.asList("200 OK", "405 Method Not Allowed")); - BasicDataSource dataSource = getSpringWebApplicationContext().getBean("dataSource", BasicDataSource.class); + DataSource dataSource = getSpringWebApplicationContext().getBean("dataSource", DataSource.class); try (Connection connection = dataSource.getConnection(); PreparedStatement statement = connection .prepareStatement("SELECT count(*) FROM current_patients WHERE patient_id::text = ?")) diff --git a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/TaskIntegrationTest.java b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/TaskIntegrationTest.java index bf511404d..578f04677 100755 --- a/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/TaskIntegrationTest.java +++ b/dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/TaskIntegrationTest.java @@ -19,7 +19,8 @@ import java.util.Optional; import java.util.UUID; -import org.apache.commons.dbcp2.BasicDataSource; +import javax.sql.DataSource; + import org.hl7.fhir.r4.model.ActivityDefinition; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent; @@ -1386,7 +1387,7 @@ public void testUpdateTaskFromInProgressToCompletedWithNonExistingInputReference ReferenceExtractor referenceExtractor = getSpringWebApplicationContext().getBean(ReferenceExtractor.class); ReferenceResolver referenceResolver = getSpringWebApplicationContext().getBean(ReferenceResolver.class); ResponseGenerator responseGenerator = getSpringWebApplicationContext().getBean(ResponseGenerator.class); - BasicDataSource dataSource = getSpringWebApplicationContext().getBean("dataSource", BasicDataSource.class); + DataSource dataSource = getSpringWebApplicationContext().getBean("dataSource", DataSource.class); ReferencesHelperImpl referencesHelper = new ReferencesHelperImpl<>(0, TestOrganizationIdentity.local(organizationProvider.getLocalOrganization().get()), task, getBaseUrl(), diff --git a/dsf-fhir/pom.xml b/dsf-fhir/pom.xml index e63f02bcc..7e4096f08 100755 --- a/dsf-fhir/pom.xml +++ b/dsf-fhir/pom.xml @@ -118,6 +118,11 @@ dsf-common-config ${project.version} + + dev.dsf + dsf-common-db + ${project.version} + dev.dsf dsf-common-documentation diff --git a/pom.xml b/pom.xml index 85825c4fa..59d7ccedd 100755 --- a/pom.xml +++ b/pom.xml @@ -526,7 +526,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.1 + 3.5.2 org.apache.maven.plugins From ad5cefdd7aa04d8e5b3fb680f92f24b7d8591f84 Mon Sep 17 00:00:00 2001 From: Hauke Hund Date: Wed, 21 Feb 2024 06:10:07 +0100 Subject: [PATCH 2/4] logging cleanup --- .../java/dev/dsf/fhir/help/ResponseGenerator.java | 4 ++-- .../impl/AbstractResourceServiceImpl.java | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ResponseGenerator.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ResponseGenerator.java index f717f3efa..33eeaf8b0 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ResponseGenerator.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/help/ResponseGenerator.java @@ -395,8 +395,8 @@ public Response badIfNoneExistHeaderValue(String ifNoneExistsHeaderValue, { String unsupportedQueryParametersString = unsupportedQueryParameters.stream() .map(SearchQueryParameterError::toString).collect(Collectors.joining("; ")); - logger.warn("Bad If-None-Exist header value, unsupported query parameter{} {}", - unsupportedQueryParameters.size() != 1 ? "s" : "", unsupportedQueryParametersString); + logger.warn("Bad If-None-Exist header value, {} unsupported query parameter{}", + unsupportedQueryParameters.size(), unsupportedQueryParameters.size() != 1 ? "s" : ""); OperationOutcome outcome = createOutcome(IssueSeverity.ERROR, IssueType.PROCESSING, "Bad If-None-Exist header value '" + ifNoneExistsHeaderValue + "', unsupported query parameter" diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java index e455b1830..ccf50f4c8 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java @@ -259,14 +259,14 @@ private Optional checkReference(Resource resource, Connection { return switch (reference.getType(serverBase)) { - case LITERAL_INTERNAL, RELATED_ARTEFACT_LITERAL_INTERNAL_URL, ATTACHMENT_LITERAL_INTERNAL_URL -> - referenceResolver.checkLiteralInternalReference(resource, reference, connection); + case LITERAL_INTERNAL, RELATED_ARTEFACT_LITERAL_INTERNAL_URL, ATTACHMENT_LITERAL_INTERNAL_URL -> referenceResolver + .checkLiteralInternalReference(resource, reference, connection); - case LITERAL_EXTERNAL, RELATED_ARTEFACT_LITERAL_EXTERNAL_URL, ATTACHMENT_LITERAL_EXTERNAL_URL -> - referenceResolver.checkLiteralExternalReference(resource, reference); + case LITERAL_EXTERNAL, RELATED_ARTEFACT_LITERAL_EXTERNAL_URL, ATTACHMENT_LITERAL_EXTERNAL_URL -> referenceResolver + .checkLiteralExternalReference(resource, reference); - case LOGICAL -> - referenceResolver.checkLogicalReference(getCurrentIdentity(), resource, reference, connection); + case LOGICAL -> referenceResolver.checkLogicalReference(getCurrentIdentity(), resource, reference, + connection); // unknown URLs to non FHIR servers in related artifacts must not be checked case RELATED_ARTEFACT_UNKNOWN_URL, ATTACHMENT_UNKNOWN_URL -> Optional.empty(); @@ -431,7 +431,7 @@ private Optional toDate(String rfc1123DateValue) @Override public Response vread(String id, long version, UriInfo uri, HttpHeaders headers) { - Optional read = exceptionHandler.handleSqlAndResourceDeletedException(serverBase, id, + Optional read = exceptionHandler.handleSqlAndResourceDeletedException(serverBase, resourceTypeName, () -> dao.readVersion(parameterConverter.toUuid(resourceTypeName, id), version)); Optional ifNoneMatch = getHeaderString(headers, Constants.HEADER_IF_NONE_MATCH, From 7a09e0ed613d8c2dce39acc4b40f3c291f32034e Mon Sep 17 00:00:00 2001 From: Hauke Hund Date: Wed, 21 Feb 2024 06:17:37 +0100 Subject: [PATCH 3/4] code formatting --- .../webservice/impl/AbstractResourceServiceImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java index ccf50f4c8..1778674d7 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/impl/AbstractResourceServiceImpl.java @@ -259,14 +259,14 @@ private Optional checkReference(Resource resource, Connection { return switch (reference.getType(serverBase)) { - case LITERAL_INTERNAL, RELATED_ARTEFACT_LITERAL_INTERNAL_URL, ATTACHMENT_LITERAL_INTERNAL_URL -> referenceResolver - .checkLiteralInternalReference(resource, reference, connection); + case LITERAL_INTERNAL, RELATED_ARTEFACT_LITERAL_INTERNAL_URL, ATTACHMENT_LITERAL_INTERNAL_URL -> + referenceResolver.checkLiteralInternalReference(resource, reference, connection); - case LITERAL_EXTERNAL, RELATED_ARTEFACT_LITERAL_EXTERNAL_URL, ATTACHMENT_LITERAL_EXTERNAL_URL -> referenceResolver - .checkLiteralExternalReference(resource, reference); + case LITERAL_EXTERNAL, RELATED_ARTEFACT_LITERAL_EXTERNAL_URL, ATTACHMENT_LITERAL_EXTERNAL_URL -> + referenceResolver.checkLiteralExternalReference(resource, reference); - case LOGICAL -> referenceResolver.checkLogicalReference(getCurrentIdentity(), resource, reference, - connection); + case LOGICAL -> + referenceResolver.checkLogicalReference(getCurrentIdentity(), resource, reference, connection); // unknown URLs to non FHIR servers in related artifacts must not be checked case RELATED_ARTEFACT_UNKNOWN_URL, ATTACHMENT_UNKNOWN_URL -> Optional.empty(); From a6a32a1a18b25518d161d3faa1eb09f515b5507f Mon Sep 17 00:00:00 2001 From: Hauke Hund Date: Wed, 21 Feb 2024 06:24:50 +0100 Subject: [PATCH 4/4] code cleanup --- .../dsf/common/db/ConnectionWithLogger.java | 60 +++++++++ .../dsf/common/db/DataSourceWithLogger.java | 11 ++ .../db/PreparedStatementWithLogger.java | 114 ++++++++++++++++++ .../secure/AbstractResourceServiceSecure.java | 3 - 4 files changed, 185 insertions(+), 3 deletions(-) diff --git a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/ConnectionWithLogger.java b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/ConnectionWithLogger.java index b40b557f9..802962134 100644 --- a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/ConnectionWithLogger.java +++ b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/ConnectionWithLogger.java @@ -32,116 +32,139 @@ public ConnectionWithLogger(boolean loggerEnabled, Connection delegate) this.delegate = delegate; } + @Override public T unwrap(Class iface) throws SQLException { return delegate.unwrap(iface); } + @Override public boolean isWrapperFor(Class iface) throws SQLException { return delegate.isWrapperFor(iface); } + @Override public Statement createStatement() throws SQLException { return delegate.createStatement(); } + @Override public PreparedStatement prepareStatement(String sql) throws SQLException { return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql)); } + @Override public CallableStatement prepareCall(String sql) throws SQLException { return delegate.prepareCall(sql); } + @Override public String nativeSQL(String sql) throws SQLException { return delegate.nativeSQL(sql); } + @Override public void setAutoCommit(boolean autoCommit) throws SQLException { delegate.setAutoCommit(autoCommit); } + @Override public boolean getAutoCommit() throws SQLException { return delegate.getAutoCommit(); } + @Override public void commit() throws SQLException { delegate.commit(); } + @Override public void rollback() throws SQLException { delegate.rollback(); } + @Override public void close() throws SQLException { delegate.close(); } + @Override public boolean isClosed() throws SQLException { return delegate.isClosed(); } + @Override public DatabaseMetaData getMetaData() throws SQLException { return delegate.getMetaData(); } + @Override public void setReadOnly(boolean readOnly) throws SQLException { delegate.setReadOnly(readOnly); } + @Override public boolean isReadOnly() throws SQLException { return delegate.isReadOnly(); } + @Override public void setCatalog(String catalog) throws SQLException { delegate.setCatalog(catalog); } + @Override public String getCatalog() throws SQLException { return delegate.getCatalog(); } + @Override public void setTransactionIsolation(int level) throws SQLException { delegate.setTransactionIsolation(level); } + @Override public int getTransactionIsolation() throws SQLException { return delegate.getTransactionIsolation(); } + @Override public SQLWarning getWarnings() throws SQLException { return delegate.getWarnings(); } + @Override public void clearWarnings() throws SQLException { delegate.clearWarnings(); } + @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { return delegate.createStatement(resultSetType, resultSetConcurrency); } + @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { @@ -149,57 +172,68 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res delegate.prepareStatement(sql, resultSetType, resultSetConcurrency)); } + @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return delegate.prepareCall(sql, resultSetType, resultSetConcurrency); } + @Override public Map> getTypeMap() throws SQLException { return delegate.getTypeMap(); } + @Override public void setTypeMap(Map> map) throws SQLException { delegate.setTypeMap(map); } + @Override public void setHoldability(int holdability) throws SQLException { delegate.setHoldability(holdability); } + @Override public int getHoldability() throws SQLException { return delegate.getHoldability(); } + @Override public Savepoint setSavepoint() throws SQLException { return delegate.setSavepoint(); } + @Override public Savepoint setSavepoint(String name) throws SQLException { return delegate.setSavepoint(name); } + @Override public void rollback(Savepoint savepoint) throws SQLException { delegate.rollback(savepoint); } + @Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { delegate.releaseSavepoint(savepoint); } + @Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); } + @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { @@ -207,133 +241,159 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res delegate.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)); } + @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); } + @Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, autoGeneratedKeys)); } + @Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, columnIndexes)); } + @Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, columnNames)); } + @Override public Clob createClob() throws SQLException { return delegate.createClob(); } + @Override public Blob createBlob() throws SQLException { return delegate.createBlob(); } + @Override public NClob createNClob() throws SQLException { return delegate.createNClob(); } + @Override public SQLXML createSQLXML() throws SQLException { return delegate.createSQLXML(); } + @Override public boolean isValid(int timeout) throws SQLException { return delegate.isValid(timeout); } + @Override public void setClientInfo(String name, String value) throws SQLClientInfoException { delegate.setClientInfo(name, value); } + @Override public void setClientInfo(Properties properties) throws SQLClientInfoException { delegate.setClientInfo(properties); } + @Override public String getClientInfo(String name) throws SQLException { return delegate.getClientInfo(name); } + @Override public Properties getClientInfo() throws SQLException { return delegate.getClientInfo(); } + @Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { return delegate.createArrayOf(typeName, elements); } + @Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return delegate.createStruct(typeName, attributes); } + @Override public void setSchema(String schema) throws SQLException { delegate.setSchema(schema); } + @Override public String getSchema() throws SQLException { return delegate.getSchema(); } + @Override public void abort(Executor executor) throws SQLException { delegate.abort(executor); } + @Override public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { delegate.setNetworkTimeout(executor, milliseconds); } + @Override public int getNetworkTimeout() throws SQLException { return delegate.getNetworkTimeout(); } + @Override public void beginRequest() throws SQLException { delegate.beginRequest(); } + @Override public void endRequest() throws SQLException { delegate.endRequest(); } + @Override public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) throws SQLException { return delegate.setShardingKeyIfValid(shardingKey, superShardingKey, timeout); } + @Override public boolean setShardingKeyIfValid(ShardingKey shardingKey, int timeout) throws SQLException { return delegate.setShardingKeyIfValid(shardingKey, timeout); } + @Override public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException { delegate.setShardingKey(shardingKey, superShardingKey); } + @Override public void setShardingKey(ShardingKey shardingKey) throws SQLException { delegate.setShardingKey(shardingKey); diff --git a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/DataSourceWithLogger.java b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/DataSourceWithLogger.java index f9cc764a9..21825a50b 100644 --- a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/DataSourceWithLogger.java +++ b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/DataSourceWithLogger.java @@ -23,6 +23,7 @@ public DataSourceWithLogger(boolean loggerEnabled, BasicDataSource delegate) this.delegate = delegate; } + @Override public T unwrap(Class iface) throws SQLException { if (BasicDataSource.class.equals(iface)) @@ -31,6 +32,7 @@ public T unwrap(Class iface) throws SQLException return delegate.unwrap(iface); } + @Override public boolean isWrapperFor(Class iface) throws SQLException { if (BasicDataSource.class.equals(iface)) @@ -39,46 +41,55 @@ public boolean isWrapperFor(Class iface) throws SQLException return delegate.isWrapperFor(iface); } + @Override public Connection getConnection() throws SQLException { return new ConnectionWithLogger(loggerEnabled, delegate.getConnection()); } + @Override public Connection getConnection(String username, String password) throws SQLException { return new ConnectionWithLogger(loggerEnabled, delegate.getConnection(username, password)); } + @Override public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { return delegate.getParentLogger(); } + @Override public PrintWriter getLogWriter() throws SQLException { return delegate.getLogWriter(); } + @Override public void setLogWriter(PrintWriter out) throws SQLException { delegate.setLogWriter(out); } + @Override public void setLoginTimeout(int seconds) throws SQLException { delegate.setLoginTimeout(seconds); } + @Override public int getLoginTimeout() throws SQLException { return delegate.getLoginTimeout(); } + @Override public ConnectionBuilder createConnectionBuilder() throws SQLException { return delegate.createConnectionBuilder(); } + @Override public ShardingKeyBuilder createShardingKeyBuilder() throws SQLException { return delegate.createShardingKeyBuilder(); diff --git a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/PreparedStatementWithLogger.java b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/PreparedStatementWithLogger.java index 3a20372b8..1d97314a7 100644 --- a/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/PreparedStatementWithLogger.java +++ b/dsf-common/dsf-common-db/src/main/java/dev/dsf/common/db/PreparedStatementWithLogger.java @@ -52,11 +52,13 @@ private void logStatement(String sql) logger.debug("Executing query '{}'", sql); } + @Override public T unwrap(Class iface) throws SQLException { return delegate.unwrap(iface); } + @Override public ResultSet executeQuery(String sql) throws SQLException { logStatement(sql); @@ -64,6 +66,7 @@ public ResultSet executeQuery(String sql) throws SQLException return delegate.executeQuery(sql); } + @Override public ResultSet executeQuery() throws SQLException { logStatement(); @@ -71,11 +74,13 @@ public ResultSet executeQuery() throws SQLException return delegate.executeQuery(); } + @Override public boolean isWrapperFor(Class iface) throws SQLException { return delegate.isWrapperFor(iface); } + @Override public int executeUpdate(String sql) throws SQLException { logStatement(sql); @@ -83,6 +88,7 @@ public int executeUpdate(String sql) throws SQLException return delegate.executeUpdate(sql); } + @Override public int executeUpdate() throws SQLException { logStatement(); @@ -90,141 +96,169 @@ public int executeUpdate() throws SQLException return delegate.executeUpdate(); } + @Override public void setNull(int parameterIndex, int sqlType) throws SQLException { delegate.setNull(parameterIndex, sqlType); } + @Override public void close() throws SQLException { delegate.close(); } + @Override public int getMaxFieldSize() throws SQLException { return delegate.getMaxFieldSize(); } + @Override public void setBoolean(int parameterIndex, boolean x) throws SQLException { delegate.setBoolean(parameterIndex, x); } + @Override public void setByte(int parameterIndex, byte x) throws SQLException { delegate.setByte(parameterIndex, x); } + @Override public void setMaxFieldSize(int max) throws SQLException { delegate.setMaxFieldSize(max); } + @Override public void setShort(int parameterIndex, short x) throws SQLException { delegate.setShort(parameterIndex, x); } + @Override public int getMaxRows() throws SQLException { return delegate.getMaxRows(); } + @Override public void setInt(int parameterIndex, int x) throws SQLException { delegate.setInt(parameterIndex, x); } + @Override public void setMaxRows(int max) throws SQLException { delegate.setMaxRows(max); } + @Override public void setLong(int parameterIndex, long x) throws SQLException { delegate.setLong(parameterIndex, x); } + @Override public void setEscapeProcessing(boolean enable) throws SQLException { delegate.setEscapeProcessing(enable); } + @Override public void setFloat(int parameterIndex, float x) throws SQLException { delegate.setFloat(parameterIndex, x); } + @Override public void setDouble(int parameterIndex, double x) throws SQLException { delegate.setDouble(parameterIndex, x); } + @Override public int getQueryTimeout() throws SQLException { return delegate.getQueryTimeout(); } + @Override public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { delegate.setBigDecimal(parameterIndex, x); } + @Override public void setQueryTimeout(int seconds) throws SQLException { delegate.setQueryTimeout(seconds); } + @Override public void setString(int parameterIndex, String x) throws SQLException { delegate.setString(parameterIndex, x); } + @Override public void setBytes(int parameterIndex, byte[] x) throws SQLException { delegate.setBytes(parameterIndex, x); } + @Override public void cancel() throws SQLException { delegate.cancel(); } + @Override public void setDate(int parameterIndex, Date x) throws SQLException { delegate.setDate(parameterIndex, x); } + @Override public SQLWarning getWarnings() throws SQLException { return delegate.getWarnings(); } + @Override public void setTime(int parameterIndex, Time x) throws SQLException { delegate.setTime(parameterIndex, x); } + @Override public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { delegate.setTimestamp(parameterIndex, x); } + @Override public void clearWarnings() throws SQLException { delegate.clearWarnings(); } + @Override public void setCursorName(String name) throws SQLException { delegate.setCursorName(name); } + @Override public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { delegate.setAsciiStream(parameterIndex, x, length); } + @Override public boolean execute(String sql) throws SQLException { logStatement(sql); @@ -232,67 +266,80 @@ public boolean execute(String sql) throws SQLException return delegate.execute(sql); } + @Override @Deprecated public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { delegate.setUnicodeStream(parameterIndex, x, length); } + @Override public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { delegate.setBinaryStream(parameterIndex, x, length); } + @Override public ResultSet getResultSet() throws SQLException { return delegate.getResultSet(); } + @Override public int getUpdateCount() throws SQLException { return delegate.getUpdateCount(); } + @Override public void clearParameters() throws SQLException { delegate.clearParameters(); } + @Override public boolean getMoreResults() throws SQLException { return delegate.getMoreResults(); } + @Override public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { delegate.setObject(parameterIndex, x, targetSqlType); } + @Override public void setFetchDirection(int direction) throws SQLException { delegate.setFetchDirection(direction); } + @Override public void setObject(int parameterIndex, Object x) throws SQLException { delegate.setObject(parameterIndex, x); } + @Override public int getFetchDirection() throws SQLException { return delegate.getFetchDirection(); } + @Override public void setFetchSize(int rows) throws SQLException { delegate.setFetchSize(rows); } + @Override public int getFetchSize() throws SQLException { return delegate.getFetchSize(); } + @Override public boolean execute() throws SQLException { logStatement(); @@ -300,36 +347,43 @@ public boolean execute() throws SQLException return delegate.execute(); } + @Override public int getResultSetConcurrency() throws SQLException { return delegate.getResultSetConcurrency(); } + @Override public int getResultSetType() throws SQLException { return delegate.getResultSetType(); } + @Override public void addBatch(String sql) throws SQLException { delegate.addBatch(sql); } + @Override public void addBatch() throws SQLException { delegate.addBatch(); } + @Override public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { delegate.setCharacterStream(parameterIndex, reader, length); } + @Override public void clearBatch() throws SQLException { delegate.clearBatch(); } + @Override public int[] executeBatch() throws SQLException { logStatement(); @@ -337,106 +391,127 @@ public int[] executeBatch() throws SQLException return delegate.executeBatch(); } + @Override public void setRef(int parameterIndex, Ref x) throws SQLException { delegate.setRef(parameterIndex, x); } + @Override public void setBlob(int parameterIndex, Blob x) throws SQLException { delegate.setBlob(parameterIndex, x); } + @Override public void setClob(int parameterIndex, Clob x) throws SQLException { delegate.setClob(parameterIndex, x); } + @Override public void setArray(int parameterIndex, Array x) throws SQLException { delegate.setArray(parameterIndex, x); } + @Override public Connection getConnection() throws SQLException { return delegate.getConnection(); } + @Override public ResultSetMetaData getMetaData() throws SQLException { return delegate.getMetaData(); } + @Override public boolean getMoreResults(int current) throws SQLException { return delegate.getMoreResults(current); } + @Override public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { delegate.setDate(parameterIndex, x, cal); } + @Override public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { delegate.setTime(parameterIndex, x, cal); } + @Override public ResultSet getGeneratedKeys() throws SQLException { return delegate.getGeneratedKeys(); } + @Override public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { delegate.setTimestamp(parameterIndex, x, cal); } + @Override public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { return delegate.executeUpdate(sql, autoGeneratedKeys); } + @Override public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { delegate.setNull(parameterIndex, sqlType, typeName); } + @Override public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { return delegate.executeUpdate(sql, columnIndexes); } + @Override public void setURL(int parameterIndex, URL x) throws SQLException { delegate.setURL(parameterIndex, x); } + @Override public ParameterMetaData getParameterMetaData() throws SQLException { return delegate.getParameterMetaData(); } + @Override public int executeUpdate(String sql, String[] columnNames) throws SQLException { return delegate.executeUpdate(sql, columnNames); } + @Override public void setRowId(int parameterIndex, RowId x) throws SQLException { delegate.setRowId(parameterIndex, x); } + @Override public void setNString(int parameterIndex, String value) throws SQLException { delegate.setNString(parameterIndex, value); } + @Override public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { delegate.setNCharacterStream(parameterIndex, value, length); } + @Override public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { logStatement(sql); @@ -444,16 +519,19 @@ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException return delegate.execute(sql, autoGeneratedKeys); } + @Override public void setNClob(int parameterIndex, NClob value) throws SQLException { delegate.setNClob(parameterIndex, value); } + @Override public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { delegate.setClob(parameterIndex, reader, length); } + @Override public boolean execute(String sql, int[] columnIndexes) throws SQLException { logStatement(sql); @@ -461,16 +539,19 @@ public boolean execute(String sql, int[] columnIndexes) throws SQLException return delegate.execute(sql, columnIndexes); } + @Override public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { delegate.setBlob(parameterIndex, inputStream, length); } + @Override public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { delegate.setNClob(parameterIndex, reader, length); } + @Override public boolean execute(String sql, String[] columnNames) throws SQLException { logStatement(sql); @@ -478,166 +559,199 @@ public boolean execute(String sql, String[] columnNames) throws SQLException return delegate.execute(sql, columnNames); } + @Override public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { delegate.setSQLXML(parameterIndex, xmlObject); } + @Override public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { delegate.setObject(parameterIndex, x, targetSqlType, scaleOrLength); } + @Override public int getResultSetHoldability() throws SQLException { return delegate.getResultSetHoldability(); } + @Override public boolean isClosed() throws SQLException { return delegate.isClosed(); } + @Override public void setPoolable(boolean poolable) throws SQLException { delegate.setPoolable(poolable); } + @Override public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { delegate.setAsciiStream(parameterIndex, x, length); } + @Override public boolean isPoolable() throws SQLException { return delegate.isPoolable(); } + @Override public void closeOnCompletion() throws SQLException { delegate.closeOnCompletion(); } + @Override public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { delegate.setBinaryStream(parameterIndex, x, length); } + @Override public boolean isCloseOnCompletion() throws SQLException { return delegate.isCloseOnCompletion(); } + @Override public long getLargeUpdateCount() throws SQLException { return delegate.getLargeUpdateCount(); } + @Override public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { delegate.setCharacterStream(parameterIndex, reader, length); } + @Override public void setLargeMaxRows(long max) throws SQLException { delegate.setLargeMaxRows(max); } + @Override public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { delegate.setAsciiStream(parameterIndex, x); } + @Override public long getLargeMaxRows() throws SQLException { return delegate.getLargeMaxRows(); } + @Override public long[] executeLargeBatch() throws SQLException { return delegate.executeLargeBatch(); } + @Override public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { delegate.setBinaryStream(parameterIndex, x); } + @Override public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { delegate.setCharacterStream(parameterIndex, reader); } + @Override public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { delegate.setNCharacterStream(parameterIndex, value); } + @Override public long executeLargeUpdate(String sql) throws SQLException { return delegate.executeLargeUpdate(sql); } + @Override public void setClob(int parameterIndex, Reader reader) throws SQLException { delegate.setClob(parameterIndex, reader); } + @Override public long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException { return delegate.executeLargeUpdate(sql, autoGeneratedKeys); } + @Override public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { delegate.setBlob(parameterIndex, inputStream); } + @Override public void setNClob(int parameterIndex, Reader reader) throws SQLException { delegate.setNClob(parameterIndex, reader); } + @Override public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException { return delegate.executeLargeUpdate(sql, columnIndexes); } + @Override public void setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength) throws SQLException { delegate.setObject(parameterIndex, x, targetSqlType, scaleOrLength); } + @Override public long executeLargeUpdate(String sql, String[] columnNames) throws SQLException { return delegate.executeLargeUpdate(sql, columnNames); } + @Override public void setObject(int parameterIndex, Object x, SQLType targetSqlType) throws SQLException { delegate.setObject(parameterIndex, x, targetSqlType); } + @Override public String enquoteLiteral(String val) throws SQLException { return delegate.enquoteLiteral(val); } + @Override public long executeLargeUpdate() throws SQLException { return delegate.executeLargeUpdate(); } + @Override public String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException { return delegate.enquoteIdentifier(identifier, alwaysQuote); } + @Override public boolean isSimpleIdentifier(String identifier) throws SQLException { return delegate.isSimpleIdentifier(identifier); } + @Override public String enquoteNCharLiteral(String val) throws SQLException { return delegate.enquoteNCharLiteral(val); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractResourceServiceSecure.java b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractResourceServiceSecure.java index 364f5238d..fbc3613e0 100755 --- a/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractResourceServiceSecure.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/webservice/secure/AbstractResourceServiceSecure.java @@ -56,7 +56,6 @@ public abstract class AbstractResourceServiceSecure, R protected final ReferenceExtractor referenceExtractor; protected final Class resourceType; protected final String resourceTypeName; - protected final String serverBase; protected final D dao; protected final ExceptionHandler exceptionHandler; protected final ParameterConverter parameterConverter; @@ -75,7 +74,6 @@ public AbstractResourceServiceSecure(S delegate, String serverBase, ResponseGene this.referenceExtractor = referenceExtractor; this.resourceType = resourceType; this.resourceTypeName = resourceType.getAnnotation(ResourceDef.class).name(); - this.serverBase = serverBase; this.dao = dao; this.exceptionHandler = exceptionHandler; this.parameterConverter = parameterConverter; @@ -92,7 +90,6 @@ public void afterPropertiesSet() throws Exception Objects.requireNonNull(referenceExtractor, "referenceExtractor"); Objects.requireNonNull(resourceType, "resourceType"); Objects.requireNonNull(resourceTypeName, "resourceTypeName"); - Objects.requireNonNull(serverBase, "serverBase"); Objects.requireNonNull(dao, "dao"); Objects.requireNonNull(exceptionHandler, "exceptionHandler"); Objects.requireNonNull(parameterConverter, "parameterConverter");