From ed7d3d408d960c492d1b68df96411a6adafae63c Mon Sep 17 00:00:00 2001 From: Joe Fong Date: Thu, 10 Aug 2023 16:26:19 +0100 Subject: [PATCH] [PRMT-3744] WIP Start working with ebean to connect to postgres db --- build.gradle | 14 ++++ .../configuration/EBeanConfiguration.java | 79 +++++++++++++++++++ .../e2etests/exception/NotFoundException.java | 9 +++ .../model/database/Acknowledgement.java | 22 ++++++ .../property/AbstractSsmRetriever.java | 15 ---- ...roperties.java => DynamoDbProperties.java} | 2 +- .../property/EhrRepositoryProperties.java | 12 +-- .../property/Gp2gpMessengerProperties.java | 8 +- .../prm/e2etests/property/MeshProperties.java | 14 ++-- .../prm/e2etests/property/NhsProperties.java | 11 ++- .../property/PdsAdaptorProperties.java | 11 +-- .../property/PostgresDbProperties.java | 44 +++++++++++ .../e2etests/property/QueueProperties.java | 12 +-- .../ActiveSuspensionsDatabaseRepository.java | 4 +- .../EhrOutDatabaseAcknowledgeRepository.java | 29 +++++++ .../TransferTrackerDatabaseRepository.java | 4 +- src/main/resources/application.yml | 6 ++ .../prm/e2etests/test/RepositoryE2ETest.java | 12 +++ 18 files changed, 259 insertions(+), 49 deletions(-) create mode 100644 src/main/java/uk/nhs/prm/e2etests/configuration/EBeanConfiguration.java create mode 100644 src/main/java/uk/nhs/prm/e2etests/exception/NotFoundException.java create mode 100644 src/main/java/uk/nhs/prm/e2etests/model/database/Acknowledgement.java delete mode 100644 src/main/java/uk/nhs/prm/e2etests/property/AbstractSsmRetriever.java rename src/main/java/uk/nhs/prm/e2etests/property/{DatabaseProperties.java => DynamoDbProperties.java} (92%) create mode 100644 src/main/java/uk/nhs/prm/e2etests/property/PostgresDbProperties.java create mode 100644 src/main/java/uk/nhs/prm/e2etests/repository/EhrOutDatabaseAcknowledgeRepository.java diff --git a/build.gradle b/build.gradle index ed416ec5..79558081 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id 'org.owasp.dependencycheck' version '7.4.4' id 'org.springframework.boot' version '3.1.1' id 'io.spring.dependency-management' version '1.1.0' + id 'io.ebean' version '13.6.5' } group 'uk.nhs.prm' @@ -53,6 +54,10 @@ dependencies { // Data Access implementation 'software.amazon.awssdk:dynamodb-enhanced:2.20.121' + implementation 'org.postgresql:postgresql:42.6.0' + implementation 'io.ebean:ebean:13.6.5' + + annotationProcessor 'io.ebean:querybean-generator:13.6.5' compileOnly 'org.projectlombok:lombok' @@ -62,6 +67,7 @@ dependencies { annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' + annotationProcessor 'io.ebean:querybean-generator:13.6.5' testAnnotationProcessor 'org.projectlombok:lombok' @@ -71,6 +77,7 @@ dependencies { testImplementation 'org.xmlunit:xmlunit-core:2.9.1' testImplementation 'org.xmlunit:xmlunit-matchers:2.9.1' testImplementation 'com.swiftmq:swiftmq-client:12.5.4' + testImplementation 'io.ebean:ebean-test:13.6.5' } tasks.withType(Test).configureEach { @@ -87,6 +94,13 @@ configurations { } dependencies { + + + implementation 'io.ebean:ebean-gradle-plugin:11.39.1' + implementation 'io.ebean:ebean-gradle-plugin:11.39.1' + implementation 'io.ebean:ebean-gradle-plugin:11.39.1' + implementation 'io.ebean:ebean-api:13.20.1-jakarta' + implementation 'io.ebean:ebean-postgres:13.20.1-jakarta' implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0' groovyScript localGroovy() } diff --git a/src/main/java/uk/nhs/prm/e2etests/configuration/EBeanConfiguration.java b/src/main/java/uk/nhs/prm/e2etests/configuration/EBeanConfiguration.java new file mode 100644 index 00000000..1a868085 --- /dev/null +++ b/src/main/java/uk/nhs/prm/e2etests/configuration/EBeanConfiguration.java @@ -0,0 +1,79 @@ +package uk.nhs.prm.e2etests.configuration; + +import io.ebean.Database; +import io.ebean.DatabaseFactory; +import io.ebean.config.DatabaseConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import uk.nhs.prm.e2etests.property.PostgresDbProperties; + +import java.util.Properties; + +@Configuration +public class EBeanConfiguration { + private final PostgresDbProperties databaseProperties; + + public EBeanConfiguration( + PostgresDbProperties databaseProperties + ) { + this.databaseProperties = databaseProperties; + } + +// /** +// * Simple Spring bean factory for creating the EbeanServer. +// */ +// public class MyEbeanServerFactory implements FactoryBean { +// +// public EbeanServer getObject() throws Exception { +// +// return createEbeanServer(); +// } +// +// public Class getObjectType() { +// return EbeanServer.class; +// } +// +// public boolean isSingleton() { +// return true; +// } +// +// /** +// * Create a EbeanServer instance. +// */ +// private EbeanServer createEbeanServer() { +// +// ServerConfig config = new ServerConfig(); +// config.setName("pg"); +// +// // load configuration from ebean.properties +// config.loadFromProperties(); +// config.setDefaultServer(true); +// ... +// // other programmatic configuration +// +// return EbeanServerFactory.create(config); +// } +// } + + + + + @Bean + public Database ehrOutDatabase() { + DatabaseConfig configuration = new DatabaseConfig(); + + Properties properties = new Properties(); + properties.put("ebean.db.ddl.generate", "true"); + properties.put("ebean.db.ddl.run", "true"); + properties.put("datasource.db.databaseDriver", "org.postgresql.Driver"); + properties.put("datasource.db.username", databaseProperties.getEhrOutDatabaseUsername()); + properties.put("datasource.db.password", databaseProperties.getEhrOutDatabasePassword()); + properties.put("datasource.db.databaseUrl", String.format("jdbc:postgresql://%s/%s", + databaseProperties.getEhrOutDatabaseHost(), + databaseProperties.getEhrOutDatabaseName())); + + configuration.loadFromProperties(properties); + return DatabaseFactory.create(configuration); + } +} \ No newline at end of file diff --git a/src/main/java/uk/nhs/prm/e2etests/exception/NotFoundException.java b/src/main/java/uk/nhs/prm/e2etests/exception/NotFoundException.java new file mode 100644 index 00000000..065af4fb --- /dev/null +++ b/src/main/java/uk/nhs/prm/e2etests/exception/NotFoundException.java @@ -0,0 +1,9 @@ +package uk.nhs.prm.e2etests.exception; + +public class NotFoundException extends RuntimeException { + private static final String MESSAGE = "A record could not be found with ID: %s"; + + public NotFoundException(String id) { + super(String.format(MESSAGE, id)); + } +} diff --git a/src/main/java/uk/nhs/prm/e2etests/model/database/Acknowledgement.java b/src/main/java/uk/nhs/prm/e2etests/model/database/Acknowledgement.java new file mode 100644 index 00000000..b2f314de --- /dev/null +++ b/src/main/java/uk/nhs/prm/e2etests/model/database/Acknowledgement.java @@ -0,0 +1,22 @@ +package uk.nhs.prm.e2etests.model.database; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import java.time.LocalDateTime; +import java.util.UUID; +import lombok.Getter; + +@Entity +@Getter +public class Acknowledgement { + @Id + private UUID messageId; + private String acknowledgementTypeCode; + private String acknowledgementDetail; + private String service; + private String referencedMessageId; + private String messageRef; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + private LocalDateTime deletedAt; +} \ No newline at end of file diff --git a/src/main/java/uk/nhs/prm/e2etests/property/AbstractSsmRetriever.java b/src/main/java/uk/nhs/prm/e2etests/property/AbstractSsmRetriever.java deleted file mode 100644 index f4f3a542..00000000 --- a/src/main/java/uk/nhs/prm/e2etests/property/AbstractSsmRetriever.java +++ /dev/null @@ -1,15 +0,0 @@ -package uk.nhs.prm.e2etests.property; - -import uk.nhs.prm.e2etests.service.SsmService; - -public abstract class AbstractSsmRetriever { - private final SsmService ssmService; - - protected AbstractSsmRetriever(SsmService ssmService) { - this.ssmService = ssmService; - } - - protected String getAwsSsmParameterValue(String ssmParameterName) { - return ssmService.getSsmParameterValue(ssmParameterName); - } -} diff --git a/src/main/java/uk/nhs/prm/e2etests/property/DatabaseProperties.java b/src/main/java/uk/nhs/prm/e2etests/property/DynamoDbProperties.java similarity index 92% rename from src/main/java/uk/nhs/prm/e2etests/property/DatabaseProperties.java rename to src/main/java/uk/nhs/prm/e2etests/property/DynamoDbProperties.java index 46fb69db..96d43cf2 100644 --- a/src/main/java/uk/nhs/prm/e2etests/property/DatabaseProperties.java +++ b/src/main/java/uk/nhs/prm/e2etests/property/DynamoDbProperties.java @@ -6,7 +6,7 @@ @Getter @Component -public class DatabaseProperties { +public class DynamoDbProperties { @Value("${aws.configuration.databaseNames.transferTrackerDb}") private String transferTrackerDbName; diff --git a/src/main/java/uk/nhs/prm/e2etests/property/EhrRepositoryProperties.java b/src/main/java/uk/nhs/prm/e2etests/property/EhrRepositoryProperties.java index 5ece5ca9..006a014f 100644 --- a/src/main/java/uk/nhs/prm/e2etests/property/EhrRepositoryProperties.java +++ b/src/main/java/uk/nhs/prm/e2etests/property/EhrRepositoryProperties.java @@ -9,7 +9,7 @@ @Getter @Component -public class EhrRepositoryProperties extends AbstractSsmRetriever { +public class EhrRepositoryProperties { @Value("${nhs.services.gp2gp.odsCodes.repoDev}") private String repoDevOdsCode; @@ -28,16 +28,16 @@ public class EhrRepositoryProperties extends AbstractSsmRetriever { @Value("${aws.configuration.serviceUrls.ehrRepository}") private String ehrRepositoryUrl; + private final SsmService ssmService; + @Autowired - public EhrRepositoryProperties(SsmService ssmService) { - super(ssmService); - } + public EhrRepositoryProperties(SsmService ssmService) { this.ssmService = ssmService; } public String getLiveTestApiKey() { - return super.getAwsSsmParameterValue(this.liveTestApiKey); + return this.ssmService.getSsmParameterValue(this.liveTestApiKey); } public String getE2eTestApiKey() { - return super.getAwsSsmParameterValue(this.e2eTestApiKey); + return this.ssmService.getSsmParameterValue(this.e2eTestApiKey); } } \ No newline at end of file diff --git a/src/main/java/uk/nhs/prm/e2etests/property/Gp2gpMessengerProperties.java b/src/main/java/uk/nhs/prm/e2etests/property/Gp2gpMessengerProperties.java index 655b4b51..fdd6b208 100644 --- a/src/main/java/uk/nhs/prm/e2etests/property/Gp2gpMessengerProperties.java +++ b/src/main/java/uk/nhs/prm/e2etests/property/Gp2gpMessengerProperties.java @@ -9,7 +9,7 @@ @Getter @Component -public class Gp2gpMessengerProperties extends AbstractSsmRetriever { +public class Gp2gpMessengerProperties { @Value("${nhs.services.gp2gp.odsCodes.tppPtlInt}") private String tppPtlIntOdsCode; @@ -23,12 +23,14 @@ public class Gp2gpMessengerProperties extends AbstractSsmRetriever { @Value("${aws.configuration.serviceUrls.gp2GpMessenger}") private String gp2gpMessengerUrl; + private final SsmService ssmService; + @Autowired public Gp2gpMessengerProperties(SsmService ssmService) { - super(ssmService); + this.ssmService = ssmService; } public String getLiveTestApiKey() { - return super.getAwsSsmParameterValue(this.liveTestApiKey); + return this.ssmService.getSsmParameterValue(this.liveTestApiKey); } } diff --git a/src/main/java/uk/nhs/prm/e2etests/property/MeshProperties.java b/src/main/java/uk/nhs/prm/e2etests/property/MeshProperties.java index 632930e5..133f0dad 100644 --- a/src/main/java/uk/nhs/prm/e2etests/property/MeshProperties.java +++ b/src/main/java/uk/nhs/prm/e2etests/property/MeshProperties.java @@ -6,7 +6,7 @@ import uk.nhs.prm.e2etests.service.SsmService; @Component -public class MeshProperties extends AbstractSsmRetriever { +public class MeshProperties { @Value("${aws.configuration.ssm.parameters.mesh.mailboxId}") private String mailboxId; @@ -21,25 +21,27 @@ public class MeshProperties extends AbstractSsmRetriever { private static final String MAILBOX_SERVICE_OUTBOX_URL = "https://msg.intspineservices.nhs.uk/messageexchange/%s/outbox"; + private final SsmService ssmService; + @Autowired public MeshProperties(SsmService ssmService) { - super(ssmService); + this.ssmService = ssmService; } public String getMailboxId() { - return super.getAwsSsmParameterValue(this.mailboxId); + return ssmService.getSsmParameterValue(this.mailboxId); } public String getClientCert() { - return super.getAwsSsmParameterValue(this.clientCert); + return ssmService.getSsmParameterValue(this.clientCert); } public String getClientKey() { - return super.getAwsSsmParameterValue(this.clientKey); + return ssmService.getSsmParameterValue(this.clientKey); } public String getMailboxPassword() { - return super.getAwsSsmParameterValue(this.mailboxPassword); + return ssmService.getSsmParameterValue(this.mailboxPassword); } public String getMailboxServiceOutboxUrl() { diff --git a/src/main/java/uk/nhs/prm/e2etests/property/NhsProperties.java b/src/main/java/uk/nhs/prm/e2etests/property/NhsProperties.java index 360fe590..0bcec45c 100644 --- a/src/main/java/uk/nhs/prm/e2etests/property/NhsProperties.java +++ b/src/main/java/uk/nhs/prm/e2etests/property/NhsProperties.java @@ -1,5 +1,6 @@ package uk.nhs.prm.e2etests.property; +import com.amazonaws.services.dynamodbv2.xspec.SS; import lombok.Getter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -11,7 +12,7 @@ @Getter @Component -public class NhsProperties extends AbstractSsmRetriever { +public class NhsProperties { @Value("${nhs.environment}") private String nhsEnvironment; @@ -27,17 +28,19 @@ public class NhsProperties extends AbstractSsmRetriever { @Value("${nhs.syntheticPatient.nhsNumberPrefix.nonProd}") private String syntheticPatientNhsNumberPrefixNonProd; + private final SsmService ssmService; + @Autowired public NhsProperties(SsmService ssmService) { - super(ssmService); + this.ssmService = ssmService; } public String getRepoOdsCode() { - return super.getAwsSsmParameterValue(repoOdsCode); + return ssmService.getSsmParameterValue(repoOdsCode); } public List getSafeListedPatientList() { - String rawSafeListedPatientListStringFromSsm = super.getAwsSsmParameterValue(safeListedPatients); + String rawSafeListedPatientListStringFromSsm = ssmService.getSsmParameterValue(safeListedPatients); return Arrays.asList(rawSafeListedPatientListStringFromSsm.split(",")); } diff --git a/src/main/java/uk/nhs/prm/e2etests/property/PdsAdaptorProperties.java b/src/main/java/uk/nhs/prm/e2etests/property/PdsAdaptorProperties.java index 28fe2090..c09a179c 100644 --- a/src/main/java/uk/nhs/prm/e2etests/property/PdsAdaptorProperties.java +++ b/src/main/java/uk/nhs/prm/e2etests/property/PdsAdaptorProperties.java @@ -7,7 +7,7 @@ import uk.nhs.prm.e2etests.service.SsmService; @Component -public class PdsAdaptorProperties extends AbstractSsmRetriever { +public class PdsAdaptorProperties { @Value("${aws.configuration.ssm.parameters.pdsAdaptor.performanceApiKey}") private String performanceApiKey; @@ -21,21 +21,22 @@ public class PdsAdaptorProperties extends AbstractSsmRetriever { @Value("${aws.configuration.serviceUrls.pdsAdaptor}") private String pdsAdaptorUrl; + private final SsmService ssmService; @Autowired public PdsAdaptorProperties(SsmService ssmService) { - super(ssmService); + this.ssmService = ssmService; } public String getPerformanceApiKey() { - return super.getAwsSsmParameterValue(this.performanceApiKey); + return ssmService.getSsmParameterValue(this.performanceApiKey); } public String getLiveTestApiKey() { - return super.getAwsSsmParameterValue(this.liveTestApiKey); + return ssmService.getSsmParameterValue(this.liveTestApiKey); } public String getE2eTestApiKey() { - return super.getAwsSsmParameterValue(this.e2eTestApiKey); + return ssmService.getSsmParameterValue(this.e2eTestApiKey); } } \ No newline at end of file diff --git a/src/main/java/uk/nhs/prm/e2etests/property/PostgresDbProperties.java b/src/main/java/uk/nhs/prm/e2etests/property/PostgresDbProperties.java new file mode 100644 index 00000000..5e1714ae --- /dev/null +++ b/src/main/java/uk/nhs/prm/e2etests/property/PostgresDbProperties.java @@ -0,0 +1,44 @@ +package uk.nhs.prm.e2etests.property; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import uk.nhs.prm.e2etests.service.SsmService; + +@Component +public class PostgresDbProperties { + @Value("${aws.configuration.ssm.parameters.ehrOut.database.host}") + private String ehrOutDatabaseHost; + + @Value("${aws.configuration.ssm.parameters.ehrOut.database.name}") + private String ehrOutDatabaseName; + + @Value("${aws.configuration.ssm.parameters.ehrOut.database.username}") + private String ehrOutDatabaseUsername; + + @Value("${aws.configuration.ssm.parameters.ehrOut.database.password}") + private String ehrOutDatabasePassword; + + private final SsmService ssmService; + + @Autowired + public PostgresDbProperties(SsmService ssmService) { + this.ssmService = ssmService; + } + + public String getEhrOutDatabaseHost() { + return this.ssmService.getSsmParameterValue(this.ehrOutDatabaseHost); + } + + public String getEhrOutDatabaseName() { + return this.ssmService.getSsmParameterValue(this.ehrOutDatabaseName); + } + + public String getEhrOutDatabaseUsername() { + return this.ssmService.getSsmParameterValue(this.ehrOutDatabaseUsername); + } + + public String getEhrOutDatabasePassword() { + return this.ssmService.getSsmParameterValue(this.ehrOutDatabasePassword); + } +} \ No newline at end of file diff --git a/src/main/java/uk/nhs/prm/e2etests/property/QueueProperties.java b/src/main/java/uk/nhs/prm/e2etests/property/QueueProperties.java index 121e97b5..f4bafd93 100644 --- a/src/main/java/uk/nhs/prm/e2etests/property/QueueProperties.java +++ b/src/main/java/uk/nhs/prm/e2etests/property/QueueProperties.java @@ -12,7 +12,7 @@ import java.util.regex.Pattern; @Component -public class QueueProperties extends AbstractSsmRetriever { +public class QueueProperties { private static final String TEMPLATE_QUEUE_URL = "https://sqs.eu-west-2.amazonaws.com/%s/%s-%s"; @Value("${aws.configuration.queueNames.meshForwarder.nemsEventsObservability}") @@ -94,23 +94,25 @@ public class QueueProperties extends AbstractSsmRetriever { private final String awsAccountNumber; + private final SsmService ssmService; + @Autowired public QueueProperties( SsmService ssmService, NhsProperties nhsProperties, ActiveRoleArn activeRoleArn ) { - super(ssmService); + this.ssmService = ssmService; this.nhsEnvironment = nhsProperties.getNhsEnvironment(); this.awsAccountNumber = activeRoleArn.getAccountNo(); } public String getMqAppUsername() { - return super.getAwsSsmParameterValue(this.mqAppUsername); + return this.ssmService.getSsmParameterValue(this.mqAppUsername); } public String getMqAppPassword() { - return super.getAwsSsmParameterValue(this.mqAppPassword); + return this.ssmService.getSsmParameterValue(this.mqAppPassword); } public String getMeshForwarderNemsEventsObservabilityQueueUri() { @@ -203,7 +205,7 @@ public String getGp2gpMessengerObservabilityQueueUrl() { public AmqpEndpoint getAmqpEndpoint() { // In the event this fails, there is also an 'amqp-endpoint-1' in SSM - return formatAmqpEndpoint(super.getAwsSsmParameterValue(this.amqpEndpoint)); + return formatAmqpEndpoint(this.ssmService.getSsmParameterValue(this.amqpEndpoint)); } private String getQueueUrl(String queueName) { diff --git a/src/main/java/uk/nhs/prm/e2etests/repository/ActiveSuspensionsDatabaseRepository.java b/src/main/java/uk/nhs/prm/e2etests/repository/ActiveSuspensionsDatabaseRepository.java index eec1ffb8..44d64bf3 100644 --- a/src/main/java/uk/nhs/prm/e2etests/repository/ActiveSuspensionsDatabaseRepository.java +++ b/src/main/java/uk/nhs/prm/e2etests/repository/ActiveSuspensionsDatabaseRepository.java @@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; -import uk.nhs.prm.e2etests.property.DatabaseProperties; +import uk.nhs.prm.e2etests.property.DynamoDbProperties; import software.amazon.awssdk.enhanced.dynamodb.Key; import org.springframework.stereotype.Component; import lombok.extern.log4j.Log4j2; @@ -19,7 +19,7 @@ public class ActiveSuspensionsDatabaseRepository { @Autowired public ActiveSuspensionsDatabaseRepository( - DatabaseProperties databaseProperties, + DynamoDbProperties databaseProperties, DynamoDbEnhancedClient dynamoDbEnhancedClient ) { final TableSchema tableSchema = diff --git a/src/main/java/uk/nhs/prm/e2etests/repository/EhrOutDatabaseAcknowledgeRepository.java b/src/main/java/uk/nhs/prm/e2etests/repository/EhrOutDatabaseAcknowledgeRepository.java new file mode 100644 index 00000000..ce3fd52f --- /dev/null +++ b/src/main/java/uk/nhs/prm/e2etests/repository/EhrOutDatabaseAcknowledgeRepository.java @@ -0,0 +1,29 @@ +package uk.nhs.prm.e2etests.repository; + +import io.ebean.DB; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; +import io.ebean.Database; +import uk.nhs.prm.e2etests.exception.NotFoundException; +import uk.nhs.prm.e2etests.model.database.Acknowledgement; + +import java.util.Optional; +import java.util.UUID; + +@Repository +public class EhrOutDatabaseAcknowledgeRepository { + private final Database database; + + @Autowired + public EhrOutDatabaseAcknowledgeRepository( + Database ehrOutDatabase + ) { + this.database = ehrOutDatabase; + } + + public Acknowledgement findAcknowledgementById(UUID id) { + return Optional + .ofNullable(this.database.find(Acknowledgement.class, id)) + .orElseThrow(() -> new NotFoundException(id.toString())); + } +} diff --git a/src/main/java/uk/nhs/prm/e2etests/repository/TransferTrackerDatabaseRepository.java b/src/main/java/uk/nhs/prm/e2etests/repository/TransferTrackerDatabaseRepository.java index 24432fd3..00194cbe 100644 --- a/src/main/java/uk/nhs/prm/e2etests/repository/TransferTrackerDatabaseRepository.java +++ b/src/main/java/uk/nhs/prm/e2etests/repository/TransferTrackerDatabaseRepository.java @@ -5,7 +5,7 @@ import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable; import uk.nhs.prm.e2etests.model.database.TransferTrackerRecord; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; -import uk.nhs.prm.e2etests.property.DatabaseProperties; +import uk.nhs.prm.e2etests.property.DynamoDbProperties; import software.amazon.awssdk.enhanced.dynamodb.Key; import org.springframework.stereotype.Component; import lombok.extern.log4j.Log4j2; @@ -19,7 +19,7 @@ public class TransferTrackerDatabaseRepository { @Autowired public TransferTrackerDatabaseRepository( - DatabaseProperties databaseProperties, + DynamoDbProperties databaseProperties, DynamoDbEnhancedClient dynamoDbEnhancedClient ) { final TableSchema tableSchema = diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 97bf7d96..9097f961 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -24,6 +24,12 @@ aws: odsCode: /repo/${NHS_ENVIRONMENT}/user-input/external/repository-ods-code liveTestApiKey: /repo/${NHS_ENVIRONMENT}/user-input/api-keys/ehr-repo/live-test e2eTestApiKey: /repo/${NHS_ENVIRONMENT}/user-input/api-keys/ehr-repo/e2e-test + ehrOut: + database: + host: /repo/${NHS_ENVIRONMENT}/output/prm-repo-ehr-out-service/db-host + name: /repo/${NHS_ENVIRONMENT}/output/prm-repo-ehr-out-service/db-name + username: /repo/${NHS_ENVIRONMENT}/user-input/ehr-out-service-db-username + password: /repo/${NHS_ENVIRONMENT}/user-input/ehr-out-service-db-password queue: mqAppUsername: /repo/${NHS_ENVIRONMENT}/user-input/mq-app-username mqAppPassword: /repo/${NHS_ENVIRONMENT}/user-input/mq-app-password diff --git a/src/test/java/uk/nhs/prm/e2etests/test/RepositoryE2ETest.java b/src/test/java/uk/nhs/prm/e2etests/test/RepositoryE2ETest.java index 8d329262..533b96e4 100644 --- a/src/test/java/uk/nhs/prm/e2etests/test/RepositoryE2ETest.java +++ b/src/test/java/uk/nhs/prm/e2etests/test/RepositoryE2ETest.java @@ -19,6 +19,7 @@ import uk.nhs.prm.e2etests.model.RepoIncomingMessage; import uk.nhs.prm.e2etests.model.RepoIncomingMessageBuilder; import uk.nhs.prm.e2etests.model.SqsMessage; +import uk.nhs.prm.e2etests.model.database.Acknowledgement; import uk.nhs.prm.e2etests.model.database.TransferTrackerRecord; import uk.nhs.prm.e2etests.model.response.PdsAdaptorResponse; import uk.nhs.prm.e2etests.model.templatecontext.ContinueRequestTemplateContext; @@ -40,6 +41,7 @@ import uk.nhs.prm.e2etests.queue.ehrtransfer.observability.EhrTransferServiceTransferCompleteOQ; import uk.nhs.prm.e2etests.queue.ehrtransfer.observability.EhrTransferServiceUnhandledOQ; import uk.nhs.prm.e2etests.queue.gp2gpmessenger.observability.Gp2GpMessengerOQ; +import uk.nhs.prm.e2etests.repository.EhrOutDatabaseAcknowledgeRepository; import uk.nhs.prm.e2etests.service.PdsAdaptorService; import uk.nhs.prm.e2etests.service.TemplatingService; import uk.nhs.prm.e2etests.service.TransferTrackerService; @@ -75,6 +77,7 @@ class RepositoryE2ETest { private final PdsAdaptorService pdsAdaptorService; private final TemplatingService templatingService; + private final EhrOutDatabaseAcknowledgeRepository ehrOutDatabaseAcknowledgeRepository; private final SimpleAmqpQueue mhsInboundQueue; private final Gp2GpMessengerOQ gp2gpMessengerOQ; private final EhrTransferServiceTransferCompleteOQ ehrTransferServiceTransferCompleteOQ; @@ -95,6 +98,7 @@ public RepositoryE2ETest( TransferTrackerService transferTrackerService, PdsAdaptorService pdsAdaptorService, TemplatingService templatingService, + EhrOutDatabaseAcknowledgeRepository ehrOutDatabaseAcknowledgeRepository, SimpleAmqpQueue mhsInboundQueue, Gp2GpMessengerOQ gp2gpMessengerOQ, EhrTransferServiceTransferCompleteOQ ehrTransferServiceTransferCompleteOQ, @@ -112,6 +116,7 @@ public RepositoryE2ETest( this.transferTrackerService = transferTrackerService; this.pdsAdaptorService = pdsAdaptorService; this.templatingService = templatingService; + this.ehrOutDatabaseAcknowledgeRepository = ehrOutDatabaseAcknowledgeRepository; this.mhsInboundQueue = mhsInboundQueue; this.gp2gpMessengerOQ = gp2gpMessengerOQ; this.ehrTransferServiceTransferCompleteOQ = ehrTransferServiceTransferCompleteOQ; @@ -139,6 +144,13 @@ void init() { gp2gpMessengerOQ.deleteAllMessages(); } + @Test + void shouldConnectToEhrOutDatabase() { + // a temporary test just to confirm the connection to database + Acknowledgement record = ehrOutDatabaseAcknowledgeRepository.findAcknowledgementById(UUID.fromString("b9ef46f4-d311-47fb-ab93-a7d48133ec3a")); + assertThat(record.getAcknowledgementTypeCode()).isEqualTo("AA"); + } + // The following test should eventually test that we can send a small EHR - until we have an EHR in repo/test patient ready to send, // we are temporarily doing a smaller test to cover from amqp -> ehr out queue @Test