diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/ActiveMqContainer.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/ActiveMqContainer.java index e6adea358..208d013cb 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/ActiveMqContainer.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/ActiveMqContainer.java @@ -5,7 +5,7 @@ import java.nio.file.Path; -public class ActiveMqContainer extends GenericContainer { +public final class ActiveMqContainer extends GenericContainer { public static final int ACTIVEMQ_PORT = 5672; private static ActiveMqContainer container; diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/FakeMeshContainer.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/FakeMeshContainer.java index bf5e7938b..1bcecf74c 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/FakeMeshContainer.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/FakeMeshContainer.java @@ -7,7 +7,7 @@ import java.nio.file.Path; @Slf4j -public class FakeMeshContainer extends GenericContainer { +public final class FakeMeshContainer extends GenericContainer { public static final int FAKE_MESH_PORT = 8829; private static FakeMeshContainer container; diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/MongoDbContainer.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/MongoDbContainer.java index 223e11a9e..ac988e560 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/MongoDbContainer.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/container/MongoDbContainer.java @@ -4,7 +4,7 @@ import org.testcontainers.containers.GenericContainer; @Slf4j -public class MongoDbContainer extends GenericContainer { +public final class MongoDbContainer extends GenericContainer { public static final int MONGODB_PORT = 27017; public static final String DEFAULT_IMAGE_AND_TAG = "mongo:8.0"; diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/db/TimeToLiveTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/db/TimeToLiveTest.java index ae51f79fe..c27f73fb6 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/db/TimeToLiveTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/db/TimeToLiveTest.java @@ -48,13 +48,13 @@ public class TimeToLiveTest { private NhaisMongoClientConfiguration mongoConfig; @Test - void when_ApplicationStarts_then_TtlIndexExistsForInboundStateWithValueFromConfiguration() { + void When_ApplicationStarts_Expect_TtlIndexExistsForInboundStateWithValueFromConfiguration() { var indexOperations = mongoTemplate.indexOps(InboundState.class); assertThat(timeToLiveIndexExists(indexOperations)).isTrue(); } @Test - void when_ApplicationStarts_then_TtlIndexExistsForOutboundStateWithValueFromConfiguration() { + void When_ApplicationStarts_Expect_TtlIndexExistsForOutboundStateWithValueFromConfiguration() { var indexOperations = mongoTemplate.indexOps(OutboundState.class); assertThat(timeToLiveIndexExists(indexOperations)).isTrue(); } @@ -70,7 +70,7 @@ private boolean timeToLiveIndexExists(IndexOperations indexOperations) { @Test @Disabled("Long running test that depends on external TTL config, enable when needed") - void when_TimeToLiveHasPassedInInboundState_then_documentRemoved() { + void When_TimeToLiveHasPassedInInboundState_Expect_DocumentRemoved() { var inboundState = new InboundState() .setWorkflowId(WorkflowId.RECEP) .setSender("some_sender") @@ -89,7 +89,7 @@ void when_TimeToLiveHasPassedInInboundState_then_documentRemoved() { @Test @Disabled("Long running test that depends on external TTL config, enable when needed") - void when_TimeToLiveHasPassedInOutboundState_then_documentRemoved() { + void When_TimeToLiveHasPassedInOutboundState_Expect_DocumentRemoved() { var inboundState = new OutboundState() .setWorkflowId(WorkflowId.RECEP) .setSender("some_sender") diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/DeadLetterQueueTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/DeadLetterQueueTest.java index e70a8475a..f3086b80c 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/DeadLetterQueueTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/DeadLetterQueueTest.java @@ -37,7 +37,7 @@ public class DeadLetterQueueTest extends IntegrationBaseTest { private ObjectMapper objectMapper; @Test - public void whenSendingInvalidMessage_toMeshInboundQueue_thenMessageIsSentToDeadLetterQueue() throws JMSException { + public void When_SendingInvalidMessageToMeshInboundQueue_Expect_MessageIsSentToDeadLetterQueue() throws JMSException { clearDeadLetterQueue(meshInboundQueueName); sendToMeshInboundQueue(MESSAGE_CONTENT); @@ -48,10 +48,15 @@ public void whenSendingInvalidMessage_toMeshInboundQueue_thenMessageIsSentToDead } @Test - public void whenMeshOutboundQueueMessageCannotBeProcessed_thenMessageIsSentToDeadLetterQueue() throws Exception { + public void When_MeshOutboundQueueMessageCannotBeProcessed_Expect_MessageIsSentToDeadLetterQueue() throws Exception { String conversationId = Long.toString(System.currentTimeMillis()); when(conversationIdService.getCurrentConversationId()).thenReturn(conversationId); - OutboundMeshMessage meshMessage = OutboundMeshMessage.create("XX11", WorkflowId.REGISTRATION, MESSAGE_CONTENT, "2020-01-01T00:00:00Z", "asdf"); + OutboundMeshMessage meshMessage = OutboundMeshMessage.create( + "XX11", + WorkflowId.REGISTRATION, MESSAGE_CONTENT, + "2020-01-01T00:00:00Z", + "asdf" + ); doThrow(RuntimeException.class).when(meshClient).authenticate(); clearDeadLetterQueue(meshOutboundQueueName); @@ -62,5 +67,4 @@ public void whenMeshOutboundQueueMessageCannotBeProcessed_thenMessageIsSentToDea assertThat(message.getStringProperty(JmsHeaders.CONVERSATION_ID)).isEqualTo(conversationId); assertThat(parseTextMessage(message)).isEqualTo(objectMapper.writeValueAsString(meshMessage)); } - } diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueMultiTransactionTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueMultiTransactionTest.java index 8432b30ed..6167ea9ec 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueMultiTransactionTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueMultiTransactionTest.java @@ -65,10 +65,10 @@ public class InboundMeshQueueMultiTransactionTest extends IntegrationBaseTest { private static final String TRANSACTION_5_OPERATION_ID = OperationId.buildOperationId(RECIPIENT, TN_5); private static final String TRANSACTION_6_OPERATION_ID = OperationId.buildOperationId(RECIPIENT, TN_6); private static final Instant INTERCHANGE_TRANSLATION_TIMESTAMP = ZonedDateTime - .of(2020, 1, 25, 12, 35, 0, 0, TimestampService.UKZone) + .of(2020, 1, 25, 12, 35, 0, 0, TimestampService.UK_ZONE) .toInstant(); - private static final Instant GENERATED_TIMESTAMP = ZonedDateTime.of(2020, 6, 10, 14, 38, 0, 0, TimestampService.UKZone) + private static final Instant GENERATED_TIMESTAMP = ZonedDateTime.of(2020, 6, 10, 14, 38, 0, 0, TimestampService.UK_ZONE) .toInstant(); private static final String ISO_GENERATED_TIMESTAMP = new TimestampService().formatInISO(GENERATED_TIMESTAMP); @@ -103,7 +103,9 @@ void setUp() { } @Test - void whenMeshInboundQueueRegistrationMessageIsReceived_thenMessageIsHandled(SoftAssertions softly) throws IOException, JMSException, JSONException { + void When_MeshInboundQueueRegistrationMessageIsReceived_Expect_MessageIsHandled(SoftAssertions softly) + throws IOException, JMSException, JSONException { + var meshMessage = new MeshMessage() .setWorkflowId(WorkflowId.REGISTRATION) .setContent(new String(Files.readAllBytes(interchange.getFile().toPath()))); @@ -179,7 +181,7 @@ private void assertGpSystemInboundQueueMessages( // all transactions come from the same interchange and use the same conversation id String conversationId = message.getStringProperty("ConversationId"); - if(previousConversationId == null) { + if (previousConversationId == null) { previousConversationId = conversationId; } softly.assertThat(conversationId).isEqualTo(previousConversationId); diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueRecepTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueRecepTest.java index d5725e1ea..158ff11d6 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueRecepTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueRecepTest.java @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.core.io.Resource; import org.springframework.test.annotation.DirtiesContext; import uk.nhs.digital.nhsconnect.nhais.IntegrationBaseTest; @@ -41,7 +40,7 @@ public class InboundMeshQueueRecepTest extends IntegrationBaseTest { private static final String SENDER = "FHS1"; private static final String RECIPIENT = "GP05"; private static final Instant TRANSLATION_TIMESTAMP = ZonedDateTime - .of(2020, 6, 20, 14, 0, 0, 0, TimestampService.UKZone) + .of(2020, 6, 20, 14, 0, 0, 0, TimestampService.UK_ZONE) .toInstant(); // Mongo only supports millis precision private static final Instant PROCESSED_TIMESTAMP = Instant.now().truncatedTo(ChronoUnit.MILLIS); @@ -65,7 +64,7 @@ void setUp() { } @Test - void whenMeshInboundQueueRecepMessageIsReceived_thenRecepHandled(SoftAssertions softly) throws IOException { + void When_MeshInboundQueueRecepMessageIsReceived_Expect_RecepHandled(SoftAssertions softly) throws IOException { createOutboundStateRecords(); sendToMeshInboundQueue(new MeshMessage() diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueRegistrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueRegistrationTest.java index 64c4770e3..4c0b024b1 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueRegistrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundMeshQueueRegistrationTest.java @@ -42,9 +42,9 @@ public class InboundMeshQueueRegistrationTest extends IntegrationBaseTest { private static final ReferenceTransactionType.Inbound TRANSACTION_TYPE = ReferenceTransactionType.Inbound.APPROVAL; private static final String OPERATION_ID = OperationId.buildOperationId(RECIPIENT, TN); private static final Instant TRANSLATION_TIMESTAMP = ZonedDateTime - .of(2020, 1, 25, 12, 35, 0, 0, TimestampService.UKZone) + .of(2020, 1, 25, 12, 35, 0, 0, TimestampService.UK_ZONE) .toInstant(); - private static final Instant GENERATED_TIMESTAMP = ZonedDateTime.of(2020, 6, 10, 14, 38, 00, 0, TimestampService.UKZone) + private static final Instant GENERATED_TIMESTAMP = ZonedDateTime.of(2020, 6, 10, 14, 38, 00, 0, TimestampService.UK_ZONE) .toInstant(); private static final String ISO_GENERATED_TIMESTAMP = new TimestampService().formatInISO(GENERATED_TIMESTAMP); @@ -66,7 +66,9 @@ void setUp() { } @Test - void whenMeshInboundQueueRegistrationMessageIsReceived_thenMessageIsHandled(SoftAssertions softly) throws IOException, JMSException, JSONException { + void When_MeshInboundQueueRegistrationMessageIsReceived_Expect_MessageIsHandled(SoftAssertions softly) + throws IOException, JMSException, JSONException { + var meshMessage = new MeshMessage() .setWorkflowId(WorkflowId.REGISTRATION) .setContent(new String(Files.readAllBytes(interchange.getFile().toPath()))) diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundStateRepositoryTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundStateRepositoryTest.java index 6fd49274e..f222ecfe2 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundStateRepositoryTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundStateRepositoryTest.java @@ -26,7 +26,7 @@ public class InboundStateRepositoryTest { private InboundStateRepository inboundStateRepository; @Test - void whenDuplicateInterchangeInboundStateInserted_thenThrowsException() { + void When_DuplicateInterchangeInboundStateInserted_Expect_ThrowsException() { var inboundState = new InboundState() .setWorkflowId(WorkflowId.REGISTRATION) .setSender("some_sender") @@ -44,7 +44,7 @@ void whenDuplicateInterchangeInboundStateInserted_thenThrowsException() { } @Test - void whenDuplicateRecepInboundStateInserted_thenThrowsException() { + void When_DuplicateRecepInboundStateInserted_Expect_ThrowsException() { var inboundState = new InboundState() .setWorkflowId(WorkflowId.RECEP) .setSender("some_sender") diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundUserAcceptanceTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundUserAcceptanceTest.java index 1582bd26e..e0f57943b 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundUserAcceptanceTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/inbound/InboundUserAcceptanceTest.java @@ -103,7 +103,9 @@ private void verifyThatCloseQuarterNotificationIsNotPresentOnGpSystemInboundQueu assertThat(gpSystemInboundQueueMessage).isNull(); } - private void verifyThatNonCloseQuarterNotificationMessageIsTranslated(TestData testData, Message gpSystemInboundQueueMessage) throws JMSException, JSONException { + private void verifyThatNonCloseQuarterNotificationMessageIsTranslated(TestData testData, Message gpSystemInboundQueueMessage) + throws JMSException, JSONException { + assertThat(gpSystemInboundQueueMessage).isNotNull(); // assert transaction type in JMS header is correct assertMessageHeaders(gpSystemInboundQueueMessage, "fp69_prior_notification"); @@ -130,19 +132,25 @@ private void assertOutboundRecepMessage(String recep) { List messageIds = waitFor(() -> { List inboxMessageIds = nhaisMeshClient.getInboxMessageIds(); return inboxMessageIds.isEmpty() ? null : inboxMessageIds; - } ); + }); var meshMessage = nhaisMeshClient.getEdifactMessage(messageIds.get(0)); Interchange expectedRecep = edifactParser.parse(recep); Interchange actualRecep = edifactParser.parse(meshMessage.getContent()); - assertThat(meshMessage.getWorkflowId()).isEqualTo(WorkflowId.RECEP); - assertThat(actualRecep.getInterchangeHeader().getRecipient()).isEqualTo(expectedRecep.getInterchangeHeader().getRecipient()); - assertThat(actualRecep.getInterchangeHeader().getSender()).isEqualTo(expectedRecep.getInterchangeHeader().getSender()); - assertThat(actualRecep.getInterchangeHeader().getSequenceNumber()).isEqualTo(expectedRecep.getInterchangeHeader().getSequenceNumber()); + assertThat(meshMessage.getWorkflowId()) + .isEqualTo(WorkflowId.RECEP); + assertThat(actualRecep.getInterchangeHeader().getRecipient()) + .isEqualTo(expectedRecep.getInterchangeHeader().getRecipient()); + assertThat(actualRecep.getInterchangeHeader().getSender()) + .isEqualTo(expectedRecep.getInterchangeHeader().getSender()); + assertThat(actualRecep.getInterchangeHeader().getSequenceNumber()) + .isEqualTo(expectedRecep.getInterchangeHeader().getSequenceNumber()); assertThat(filterTimestampedSegments(actualRecep)).containsExactlyElementsOf(filterTimestampedSegments(expectedRecep)); - assertThat(actualRecep.getInterchangeTrailer().getNumberOfMessages()).isEqualTo(expectedRecep.getInterchangeTrailer().getNumberOfMessages()); - assertThat(actualRecep.getInterchangeTrailer().getSequenceNumber()).isEqualTo(expectedRecep.getInterchangeTrailer().getSequenceNumber()); + assertThat(actualRecep.getInterchangeTrailer().getNumberOfMessages()) + .isEqualTo(expectedRecep.getInterchangeTrailer().getNumberOfMessages()); + assertThat(actualRecep.getInterchangeTrailer().getSequenceNumber()) + .isEqualTo(expectedRecep.getInterchangeTrailer().getSequenceNumber()); } private List filterTimestampedSegments(Interchange recep) { diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshClientIntegrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshClientIntegrationTest.java index 1d82e7217..f36f00853 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshClientIntegrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshClientIntegrationTest.java @@ -60,14 +60,14 @@ void beforeEach() { } @Test - void When_CallingMeshSendMessageEndpoint_Then_MessageIdIsReturned() { + void When_CallingMeshSendMessageEndpoint_Expect_MessageIdIsReturned() { MeshMessageId meshMessageId = meshClient.sendEdifactMessage(OUTBOUND_MESH_MESSAGE); assertThat(meshMessageId).isNotNull(); assertThat(meshMessageId.getMessageID()).isNotEmpty(); } @Test - void When_CallingMeshGetMessageEndpoint_Then_MessageIsReturned() { + void When_CallingMeshGetMessageEndpoint_Expect_MessageIsReturned() { MeshMessageId testMessageId = meshClient.sendEdifactMessage(OUTBOUND_MESH_MESSAGE); InboundMeshMessage meshMessage = nhaisMeshClient.getEdifactMessage(testMessageId.getMessageID()); @@ -76,7 +76,7 @@ void When_CallingMeshGetMessageEndpoint_Then_MessageIsReturned() { } @Test - void When_CallingGetMessageWithLargeContentAndWrongWorkflowId_Then_MeshWorkflowUnknownExceptionIsThrown() { + void When_CallingGetMessageWithLargeContentAndWrongWorkflowId_Expect_MeshWorkflowUnknownExceptionIsThrown() { MeshMessageId testMessageId = sendLargeMessageWithWrongWorkflowId(); assertThatThrownBy(() -> nhaisMeshClient.getEdifactMessage(testMessageId.getMessageID())) @@ -108,7 +108,7 @@ private T parseInto(Class clazz, CloseableHttpResponse response) throws I } @Test - void When_CallingMeshAcknowledgeEndpoint_Then_NoExceptionIsThrown() { + void When_CallingMeshAcknowledgeEndpoint_Expect_NoExceptionIsThrown() { MeshMessageId testMessageId = meshClient.sendEdifactMessage(OUTBOUND_MESH_MESSAGE); assertThatCode(() -> nhaisMeshClient.acknowledgeMessage(testMessageId.getMessageID())) @@ -116,31 +116,31 @@ void When_CallingMeshAcknowledgeEndpoint_Then_NoExceptionIsThrown() { } @Test - void When_PollingFromMesh_Then_EmptyListIsReturned() { + void When_PollingFromMesh_Expect_EmptyListIsReturned() { assertThat(meshClient.getInboxMessageIds()).isEqualTo(List.of()); } @Test - void When_PollingFromMeshAfterSendingMsg_Then_ListWithMsgIdIsReturned() { + void When_PollingFromMeshAfterSendingMsg_Expect_ListWithMsgIdIsReturned() { MeshMessageId testMessageId = meshClient.sendEdifactMessage(OUTBOUND_MESH_MESSAGE); assertThat(nhaisMeshClient.getInboxMessageIds()).contains(testMessageId.getMessageID()); } @Test - void When_Authenticating_Then_NoExceptionThrown() { + void When_Authenticating_Expect_NoExceptionThrown() { assertThatCode(() -> meshClient.authenticate()).doesNotThrowAnyException(); } @Test - void When_downloadMessageThatDoesNotExist_then_throwException() { + void When_DownloadMessageThatDoesNotExist_Expect_ExceptionThrown() { assertThatExceptionOfType(MeshApiConnectionException.class).isThrownBy( () -> meshClient.getEdifactMessage("thisisaninvalidmessageid1234567890") ); } @Test - void When_downloadMessageThatIsGone_then_throwException() { + void When_DownloadingMessageWhichIsGone_Expect_ExceptionThrown() { MeshMessageId testMessageId = meshClient.sendEdifactMessage(OUTBOUND_MESH_MESSAGE); var messageId = testMessageId.getMessageID(); nhaisMeshClient.acknowledgeMessage(messageId); diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshConnectivityIntegrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshConnectivityIntegrationTest.java index 81946b3f8..23bdb4dd3 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshConnectivityIntegrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshConnectivityIntegrationTest.java @@ -37,7 +37,7 @@ public class MeshConnectivityIntegrationTest { * @throws Exception */ @Test - void when_CallingMeshCountMessagesEndpoint_Then_Http200IsReturned() throws Exception { + void When_CallingMeshCountMessagesEndpoint_Expect_Http200IsReturned() throws Exception { try (CloseableHttpClient client = meshHttpClientBuilder.build()) { HttpGet httpGet = new HttpGet(meshConfig.getHost() + meshConfig.getMailboxId() + "/count"); httpGet.setHeaders(new MeshHeaders(meshConfig).createMinimalHeaders()); diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/OutboundUserAcceptanceTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/OutboundUserAcceptanceTest.java index a94e1409d..4e8f7da26 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/OutboundUserAcceptanceTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/OutboundUserAcceptanceTest.java @@ -41,7 +41,7 @@ public class OutboundUserAcceptanceTest extends IntegrationBaseTest { private static final String RECIPIENT = "XX11"; private static final String SENDER = "TES5"; private static final Instant GENERATED_TIMESTAMP = ZonedDateTime - .of(2020, 6, 10, 14, 38, 10, 0, TimestampService.UKZone) + .of(2020, 6, 10, 14, 38, 10, 0, TimestampService.UK_ZONE) .toInstant(); @Autowired private MockMvc mockMvc; diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/AmendmentControllerIntegrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/AmendmentControllerIntegrationTest.java index a8b62495b..5f960e677 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/AmendmentControllerIntegrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/AmendmentControllerIntegrationTest.java @@ -62,21 +62,21 @@ public class AmendmentControllerIntegrationTest { private Resource duplicateExtensionPatches; @Test - void whenNotJson_thenReturns400() throws Exception { + void When_NotJson_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(notJsonPayload.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenDuplicatedPatches_thenReturns400() throws Exception { + void When_DuplicatedPatches_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(duplicatedPatches.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenMissingHealthcarePartyCode_thenReturns400() throws Exception { + void When_MissingHealthcarePartyCode_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(missingHealthcarePartyCode.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); @@ -84,56 +84,56 @@ void whenMissingHealthcarePartyCode_thenReturns400() throws Exception { @Test - void whenEmptyPatches_thenReturns400() throws Exception { + void When_EmptyPatches_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(emptyPatches.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenEmptyPatchObject_thenReturns400() throws Exception { + void When_EmptyPatchObject_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(emptyPatchObject.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenMissingNhsNumber_thenReturns400() throws Exception { + void When_MissingNhsNumber_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(missingNhsNumber.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenMissingGpCode_thenReturns400() throws Exception { + void When_MissingGpCode_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(missingGpCode.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenMissingPatches_thenReturns400() throws Exception { + void When_MissingPatches_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(missingPatches.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenMissingGpTradingPartnerCode_thenReturns400() throws Exception { + void When_MissingGpTradingPartnerCode_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(missingGpTradingPartnerCode.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenInvalidJsonStructure_thenReturns400() throws Exception { + void When_InvalidJsonStructure_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(invalidJsonStructure.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); } @Test - void whenDuplicateExtensionPatches_thenReturns400() throws Exception { + void When_DuplicateExtensionPatches_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(duplicateExtensionPatches.getFile().toPath())); mockMvc.perform(patch("/fhir/Patient/9999999999").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()); diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/DeductionIntegrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/DeductionIntegrationTest.java index 523d56827..76a70eeb0 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/DeductionIntegrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/DeductionIntegrationTest.java @@ -81,7 +81,7 @@ public class DeductionIntegrationTest { private Resource deductionWithNullReasonForDeduction; @Test - void whenBlankNhsNumber_thenRespond400() throws Exception { + void When_BlankNhsNumber_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithBlankNhsNumber.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -91,7 +91,7 @@ void whenBlankNhsNumber_thenRespond400() throws Exception { } @Test - void whenEmptyNhsNumber_thenRespond400() throws Exception { + void When_EmptyNhsNumber_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithEmptyNhsNumber.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -102,7 +102,7 @@ void whenEmptyNhsNumber_thenRespond400() throws Exception { } @Test - void whenNoNhsNumber_thenRespond400() throws Exception { + void When_NoNhsNumber_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithNoNhsNumber.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -112,7 +112,7 @@ void whenNoNhsNumber_thenRespond400() throws Exception { } @Test - void whenNullNhsNumber_thenRespond400() throws Exception { + void When_NullNhsNumber_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithNullNhsNumber.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -122,7 +122,7 @@ void whenNullNhsNumber_thenRespond400() throws Exception { } @Test - void whenBlankDateOfDeduction_thenRespond400() throws Exception { + void When_BlankDateOfDeduction_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithBlankDateOfDeduction.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -132,7 +132,7 @@ void whenBlankDateOfDeduction_thenRespond400() throws Exception { } @Test - void whenEmptyDateOfDeduction_thenRespond400() throws Exception { + void When_EmptyDateOfDeduction_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithEmptyDateOfDeduction.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -143,7 +143,7 @@ void whenEmptyDateOfDeduction_thenRespond400() throws Exception { } @Test - void whenNoDateOfDeduction_thenRespond400() throws Exception { + void When_NoDateOfDeduction_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithNoDateOfDeduction.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -153,7 +153,7 @@ void whenNoDateOfDeduction_thenRespond400() throws Exception { } @Test - void whenNullDateOfDeduction_thenRespond400() throws Exception { + void When_NullDateOfDeduction_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithNullDateOfDeduction.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -163,7 +163,7 @@ void whenNullDateOfDeduction_thenRespond400() throws Exception { } @Test - void whenBlankReasonForDeduction_thenRespond400() throws Exception { + void When_BlankReasonForDeduction_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithBlankReasonForDeduction.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -173,7 +173,7 @@ void whenBlankReasonForDeduction_thenRespond400() throws Exception { } @Test - void whenEmptyReasonForDeduction_thenRespond400() throws Exception { + void When_EmptyReasonForDeduction_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithEmptyReasonForDeduction.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -184,7 +184,7 @@ void whenEmptyReasonForDeduction_thenRespond400() throws Exception { } @Test - void whenNoReasonForDeduction_thenRespond400() throws Exception { + void When_NoReasonForDeduction_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithNoReasonForDeduction.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -194,7 +194,7 @@ void whenNoReasonForDeduction_thenRespond400() throws Exception { } @Test - void whenNullReasonForDeduction_thenRespond400() throws Exception { + void When_NullReasonForDeduction_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionWithNullReasonForDeduction.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/FhirControllerIntegrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/FhirControllerIntegrationTest.java index c3620ccc2..6b4e7e7aa 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/FhirControllerIntegrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/FhirControllerIntegrationTest.java @@ -69,7 +69,7 @@ public class FhirControllerIntegrationTest { private Resource acceptanceUnknownRecipient; @Test - void whenNotJson_thenReturns400() throws Exception { + void When_NotJson_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(notJsonPayload.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.acceptance").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -79,7 +79,7 @@ void whenNotJson_thenReturns400() throws Exception { } @Test - void whenDeductionNoDestinationHaCipher_thenRerturns400() throws Exception { + void When_DeductionNoDestinationHaCipher_Expect_Rerturns400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionNoHaCipher.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.deduction").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -90,7 +90,7 @@ void whenDeductionNoDestinationHaCipher_thenRerturns400() throws Exception { } @Test - void whenRemovalNoDestinationHaCipher_thenRerturns400() throws Exception { + void When_RemovalNoDestinationHaCipher_Expect_Rerturns400() throws Exception { String requestBody = new String(Files.readAllBytes(removalNoHaCipher.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.removal").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -102,7 +102,7 @@ void whenRemovalNoDestinationHaCipher_thenRerturns400() throws Exception { @Test - void whenDeductionNoGpCode_thenReturns400() throws Exception { + void When_DeductionNoGpCode_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionNoGpCode.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.deduction").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -113,7 +113,7 @@ void whenDeductionNoGpCode_thenReturns400() throws Exception { } @Test - void whenRemovalNoGpCode_thenReturns400() throws Exception { + void When_RemovalNoGpCode_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(removalNoGpCode.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.removal").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -124,7 +124,7 @@ void whenRemovalNoGpCode_thenReturns400() throws Exception { } @Test - void whenDeductionNpGpTradingPartnerCode_thenReturns400() throws Exception { + void When_DeductionNpGpTradingPartnerCode_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionNoTradingPartnerCode.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.deduction").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -135,7 +135,7 @@ void whenDeductionNpGpTradingPartnerCode_thenReturns400() throws Exception { } @Test - void whenRemovalNpGpTradingPartnerCode_thenReturns400() throws Exception { + void When_RemovalNpGpTradingPartnerCode_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(removalNoTradingPartnerCode.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.removal").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -146,7 +146,7 @@ void whenRemovalNpGpTradingPartnerCode_thenReturns400() throws Exception { } @Test - void whenDeductionInvalidJsonStructure_thenReturns400() throws Exception { + void When_DeductionInvalidJsonStructure_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(deductionInvalidJsonStructure.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.deduction").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -157,7 +157,7 @@ void whenDeductionInvalidJsonStructure_thenReturns400() throws Exception { } @Test - void whenRemovalInvalidJsonStructure_thenReturns400() throws Exception { + void When_RemovalInvalidJsonStructure_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(removalInvalidJsonStructure.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.removal").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -168,7 +168,7 @@ void whenRemovalInvalidJsonStructure_thenReturns400() throws Exception { } @Test - void whenUnknownRecipient_thenReturns400() throws Exception { + void When_UnknownRecipient_Expect_Returns400() throws Exception { String requestBody = new String(Files.readAllBytes(acceptanceUnknownRecipient.getFile().toPath())); MvcResult result = mockMvc.perform(post("/fhir/Patient/$nhais.acceptance").contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/HealthcheckIntegrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/HealthcheckIntegrationTest.java index 6163d5e74..a3ac50799 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/HealthcheckIntegrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/HealthcheckIntegrationTest.java @@ -25,7 +25,7 @@ public class HealthcheckIntegrationTest { private MockMvc mockMvc; @Test - void whenHealthcheck_thenReturns200() throws Exception { + void When_Healthcheck_Expect_Returns200() throws Exception { mockMvc.perform(get("/healthcheck")) .andExpect(status().isOk()); } diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/RemovalIntegrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/RemovalIntegrationTest.java index 635e99231..1713a4417 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/RemovalIntegrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/RemovalIntegrationTest.java @@ -72,7 +72,7 @@ public class RemovalIntegrationTest { private FhirParser fhirParser; @Test - void whenBlankNhsNumber_thenRespond400() throws Exception { + void When_BlankNhsNumber_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithBlankNhsNumber.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -83,7 +83,7 @@ void whenBlankNhsNumber_thenRespond400() throws Exception { @Test - void whenEmptyNhsNumber_thenRespond400() throws Exception { + void When_EmptyNhsNumber_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithEmptyNhsNumber.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -98,7 +98,7 @@ void whenEmptyNhsNumber_thenRespond400() throws Exception { @Test - void whenNoNhsNumber_thenRespond400() throws Exception { + void When_NoNhsNumber_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithNoNhsNumber.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -108,7 +108,7 @@ void whenNoNhsNumber_thenRespond400() throws Exception { } @Test - void whenNullNhsNumber_thenRespond400() throws Exception { + void When_NullNhsNumber_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithNullNhsNumber.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -118,7 +118,7 @@ void whenNullNhsNumber_thenRespond400() throws Exception { } @Test - void whenBlankFreeText_thenRespond400() throws Exception { + void When_BlankFreeText_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithBlankFreeText.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -128,7 +128,7 @@ void whenBlankFreeText_thenRespond400() throws Exception { } @Test - void whenEmptyFreeText_thenRespond400() throws Exception { + void When_EmptyFreeText_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithEmptyFreeText.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -138,7 +138,7 @@ void whenEmptyFreeText_thenRespond400() throws Exception { } @Test - void whenNoFreeText_thenRespond400() throws Exception { + void When_NoFreeText_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithNoFreeText.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -148,7 +148,7 @@ void whenNoFreeText_thenRespond400() throws Exception { } @Test - void whenNullFreeText_thenRespond400() throws Exception { + void When_NullFreeText_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithNullFreeText.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -158,18 +158,19 @@ void whenNullFreeText_thenRespond400() throws Exception { } @Test - void whenBlankGpTradingPartnerCode_thenRespond400() throws Exception { + void When_BlankGpTradingPartnerCode_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithBlankGpTradingPartnerCode.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) .andReturn(); OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString()); - assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).contains("Value gpTradingPartnerCode is blank or missing in FHIR Parameters"); + assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()) + .contains("Value gpTradingPartnerCode is blank or missing in FHIR Parameters"); } @Test - void whenEmptyGpTradingPartnerCode_thenRespond400() throws Exception { + void When_EmptyGpTradingPartnerCode_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithEmptyGpTradingPartnerCode.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) @@ -179,23 +180,25 @@ void whenEmptyGpTradingPartnerCode_thenRespond400() throws Exception { } @Test - void whenNoGpTradingPartnerCode_thenRespond400() throws Exception { + void When_NoGpTradingPartnerCode_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithNoGpTradingPartnerCode.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) .andReturn(); OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString()); - assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).contains("Value gpTradingPartnerCode is blank or missing in FHIR Parameters"); + assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()) + .contains("Value gpTradingPartnerCode is blank or missing in FHIR Parameters"); } @Test - void whenNullGpTradingPartnerCode_thenRespond400() throws Exception { + void When_NullGpTradingPartnerCode_Expect_Respond400() throws Exception { String requestBody = new String(Files.readAllBytes(removalWithNullGpTradingPartnerCode.getFile().toPath())); MvcResult result = mockMvc.perform(post(URL).contentType("application/json").content(requestBody)) .andExpect(status().isBadRequest()) .andReturn(); OperationOutcome operationOutcome = (OperationOutcome) fhirParser.parse(result.getResponse().getContentAsString()); - assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()).contains("Value gpTradingPartnerCode is blank or missing in FHIR Parameters"); + assertThat(operationOutcome.getIssueFirstRep().getDetails().getText()) + .contains("Value gpTradingPartnerCode is blank or missing in FHIR Parameters"); } diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/SequenceServiceIntegrationTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/SequenceServiceIntegrationTest.java index 898707f51..9b201fb52 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/SequenceServiceIntegrationTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/controller/SequenceServiceIntegrationTest.java @@ -34,16 +34,16 @@ @Slf4j @DirtiesContext public class SequenceServiceIntegrationTest { - private final static String SENDER_1 = "test-sender-1"; - private final static String SENDER_2 = "test-sender-2"; - private final static String RECIPIENT_1 = "test-recipient-1"; - private final static String RECIPIENT_2 = "test-recipient-2"; - private final static String TRANSACTION_SENDER = "gp-sender"; - private final static String TRANSACTION_KEY = String.format("TN-%s", TRANSACTION_SENDER); - private final static String INTERCHANGE_KEY_1 = String.format("SIS-%s-%s", SENDER_1, RECIPIENT_1); - private final static String INTERCHANGE_KEY_2 = String.format("SIS-%s-%s", SENDER_2, RECIPIENT_2); - private final static String INTERCHANGE_MESSAGE_KEY_1 = String.format("SMS-%s-%s", SENDER_1, RECIPIENT_1); - private final static String INTERCHANGE_MESSAGE_KEY_2 = String.format("SMS-%s-%s", SENDER_2, RECIPIENT_2); + private static final String SENDER_1 = "test-sender-1"; + private static final String SENDER_2 = "test-sender-2"; + private static final String RECIPIENT_1 = "test-recipient-1"; + private static final String RECIPIENT_2 = "test-recipient-2"; + private static final String TRANSACTION_SENDER = "gp-sender"; + private static final String TRANSACTION_KEY = String.format("TN-%s", TRANSACTION_SENDER); + private static final String INTERCHANGE_KEY_1 = String.format("SIS-%s-%s", SENDER_1, RECIPIENT_1); + private static final String INTERCHANGE_KEY_2 = String.format("SIS-%s-%s", SENDER_2, RECIPIENT_2); + private static final String INTERCHANGE_MESSAGE_KEY_1 = String.format("SMS-%s-%s", SENDER_1, RECIPIENT_1); + private static final String INTERCHANGE_MESSAGE_KEY_2 = String.format("SMS-%s-%s", SENDER_2, RECIPIENT_2); @Autowired private MockMvc mockMvc; @@ -53,7 +53,7 @@ public class SequenceServiceIntegrationTest { private SequenceDao sequenceDao; @Test - public void When_GenerateTransactionId_Then_IncreasedByOne() { + public void When_GenerateTransactionId_Expect_IncreasedByOne() { resetCounter(TRANSACTION_SENDER); assertThat(sequenceService.generateTransactionNumber(TRANSACTION_SENDER)).isEqualTo(1L); @@ -62,7 +62,7 @@ public void When_GenerateTransactionId_Then_IncreasedByOne() { } @Test - public void When_GenerateInterchangeId_Then_IncreasedByOne() { + public void When_GenerateInterchangeId_Expect_IncreasedByOne() { resetCounter(INTERCHANGE_KEY_1); assertThat(sequenceService.generateInterchangeSequence(SENDER_1, RECIPIENT_1)).isEqualTo(1L); @@ -71,7 +71,7 @@ public void When_GenerateInterchangeId_Then_IncreasedByOne() { } @Test - public void When_GenerateMessageId_Then_IncreasedByOne() { + public void When_GenerateMessageId_Expect_IncreasedByOne() { resetCounter(INTERCHANGE_MESSAGE_KEY_1); assertThat(sequenceService.generateMessageSequence(SENDER_1, RECIPIENT_1)).isEqualTo(1L); @@ -80,14 +80,14 @@ public void When_GenerateMessageId_Then_IncreasedByOne() { } @Test - public void When_GenerateIdAfter_9_999_999_Then_CounterReset() { + public void When_GenerateIdGreaterThan9999999_Expect_CounterReset() { setCounter(TRANSACTION_KEY, 9_999_999L); assertThat(sequenceService.generateTransactionNumber(TRANSACTION_SENDER)).isEqualTo(1L); } @Test - public void When_GenerateDifferentId_Then_Expect_SeparateSequence() { + public void When_GenerateDifferentId_Expect_Expect_SeparateSequence() { resetCounter(TRANSACTION_KEY); resetCounter(INTERCHANGE_KEY_1); resetCounter(INTERCHANGE_MESSAGE_KEY_1); @@ -98,7 +98,7 @@ public void When_GenerateDifferentId_Then_Expect_SeparateSequence() { } @Test - public void When_GenerateInterchangeId_Then_Expect_SeparateSequenceForEachKey() { + public void When_GenerateInterchangeId_Expect_Expect_SeparateSequenceForEachKey() { resetCounter(INTERCHANGE_KEY_1); resetCounter(INTERCHANGE_KEY_2); @@ -109,7 +109,7 @@ public void When_GenerateInterchangeId_Then_Expect_SeparateSequenceForEachKey() } @Test - public void When_GenerateMessageId_Then_Expect_SeparateSequenceForEachKey() { + public void When_GenerateMessageId_Expect_Expect_SeparateSequenceForEachKey() { resetCounter(INTERCHANGE_MESSAGE_KEY_1); resetCounter(INTERCHANGE_MESSAGE_KEY_2); @@ -120,7 +120,7 @@ public void When_GenerateMessageId_Then_Expect_SeparateSequenceForEachKey() { } @Test - public void When_GenerateTransactionIdInParallel_Then_Expect_CorrectValues() { + public void When_GenerateTransactionIdInParallel_Expect_Expect_CorrectValues() { resetCounter(TRANSACTION_KEY); List expectedList = LongStream.rangeClosed(1, 100) diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/repository/OutboundStateRepositoryExtensionsImplTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/repository/OutboundStateRepositoryExtensionsImplTest.java index 6fcb7fce1..0ed255bf3 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/repository/OutboundStateRepositoryExtensionsImplTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/repository/OutboundStateRepositoryExtensionsImplTest.java @@ -36,7 +36,7 @@ public class OutboundStateRepositoryExtensionsImplTest { private OutboundStateRepository outboundStateRepository; @Test - void whenUpdatingRecep_thenRecepDetailsAreUpdated() { + void When_UpdatingRecep_Expect_RecepDetailsAreUpdated() { var outboundState = new OutboundState() .setSender(SENDER) @@ -73,7 +73,7 @@ void whenUpdatingRecep_thenRecepDetailsAreUpdated() { } @Test - void whenUpdatingNonExistingEntity_thenReturnsEmpty() { + void When_UpdatingNonExistingEntity_Expect_ReturnsEmpty() { var recep = new OutboundState.Recep() .setInterchangeSequence(RECEP_INTERCHANGE_SEQUENCE) .setProcessedTimestamp(RECEP_PROCESSED_TIMESTAMP) diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/repository/OutboundStateRepositoryTest.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/repository/OutboundStateRepositoryTest.java index c2c8bc260..0ea5ac916 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/repository/OutboundStateRepositoryTest.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/outbound/repository/OutboundStateRepositoryTest.java @@ -24,7 +24,7 @@ public class OutboundStateRepositoryTest { private OutboundStateRepository outboundStateRepository; @Test - void whenDuplicateInterchangeOutboundStateInserted_thenThrowsException() { + void When_DuplicateInterchangeOutboundStateInserted_Expect_ExceptionThrown() { var outboundState = new OutboundState() .setWorkflowId(WorkflowId.REGISTRATION) .setSender("some_sender") @@ -42,7 +42,7 @@ void whenDuplicateInterchangeOutboundStateInserted_thenThrowsException() { } @Test - void whenDuplicateRecepOutboundStateInserted_thenThrowsException() { + void When_DuplicateRecepOutboundStateInserted_Expect_ExceptionThrown() { var outboundState = new OutboundState() .setWorkflowId(WorkflowId.RECEP) .setSender("some_sender") diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/AbstractArgumentsProvider.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/AbstractArgumentsProvider.java index a501f2f0e..002a2bc93 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/AbstractArgumentsProvider.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/AbstractArgumentsProvider.java @@ -24,7 +24,7 @@ abstract class AbstractArgumentsProvider implements ArgumentsProvider { public abstract String getFolder(); - abstract public Stream provideArguments(ExtensionContext context) throws Exception; + public abstract Stream provideArguments(ExtensionContext context) throws Exception; protected String readResource(List resources, String fileEnding) { return resources.stream() diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/InboundArgumentsProvider.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/InboundArgumentsProvider.java index 7d878e663..88f03a775 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/InboundArgumentsProvider.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/InboundArgumentsProvider.java @@ -24,7 +24,12 @@ public Stream provideArguments(ExtensionContext context) th .peek(es -> { if (es.getValue().size() != 3) { throw new IllegalStateException(String.format( - "There should be 3 test data files: '%s', '%s' and '%s': %s", FHIR_FILE_ENDING, EDIFACT_FILE_ENDING, RECEP_FILE_ENDING, es.getKey())); + "There should be 3 test data files: '%s', '%s' and '%s': %s", + FHIR_FILE_ENDING, + EDIFACT_FILE_ENDING, + RECEP_FILE_ENDING, + es.getKey()) + ); } }) .collect(Collectors.toMap( diff --git a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/OutboundArgumentsProvider.java b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/OutboundArgumentsProvider.java index c660731be..2d3be2303 100644 --- a/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/OutboundArgumentsProvider.java +++ b/src/intTest/java/uk/nhs/digital/nhsconnect/nhais/uat/common/OutboundArgumentsProvider.java @@ -23,15 +23,21 @@ public Stream provideArguments(ExtensionContext context) th .entrySet().stream() .peek(es -> { if (es.getValue().size() != 2) { - throw new IllegalStateException(String.format( - "There should be 2 test data files: 'N.%s' and 'N.%s': %s", FHIR_FILE_ENDING, EDIFACT_FILE_ENDING, es.getKey())); + throw new IllegalStateException( + String.format( + "There should be 2 test data files: 'N.%s' and 'N.%s': %s", + FHIR_FILE_ENDING, + EDIFACT_FILE_ENDING, + es.getKey() + ) + ); } }) .collect(Collectors.toMap( Map.Entry::getKey, es -> TestData.builder() - .edifact(readResource(es.getValue(),EDIFACT_FILE_ENDING)) - .json(readResource(es.getValue(),FHIR_FILE_ENDING)) + .edifact(readResource(es.getValue(), EDIFACT_FILE_ENDING)) + .json(readResource(es.getValue(), FHIR_FILE_ENDING)) .build())); return grouped.entrySet().stream() diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/IntegrationAdaptorNhaisApplication.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/IntegrationAdaptorNhaisApplication.java index c92df9d8a..ee0509fcb 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/IntegrationAdaptorNhaisApplication.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/IntegrationAdaptorNhaisApplication.java @@ -9,8 +9,7 @@ @EnableScheduling @SpringBootApplication public class IntegrationAdaptorNhaisApplication { - - public static void main(String[] args) { - SpringApplication.run(IntegrationAdaptorNhaisApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(IntegrationAdaptorNhaisApplication.class, args); + } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/AmqpConfiguration.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/AmqpConfiguration.java index 5b1004deb..4355da83f 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/AmqpConfiguration.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/AmqpConfiguration.java @@ -79,7 +79,7 @@ static class CustomRedeliveryPolicy implements JmsRedeliveryPolicy { private final int maxRedeliveries; private final int outcome; - public CustomRedeliveryPolicy(int maxRedeliveries, int outcome) { + CustomRedeliveryPolicy(int maxRedeliveries, int outcome) { this.maxRedeliveries = maxRedeliveries; this.outcome = outcome; } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/AppConfiguration.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/AppConfiguration.java index 8fc563296..f4e763931 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/AppConfiguration.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/AppConfiguration.java @@ -21,7 +21,7 @@ public class AppConfiguration { @Bean public AmazonS3 getS3Client() { - if(trustStoreUrl != null && trustStoreUrl.startsWith("s3")) { + if (trustStoreUrl != null && trustStoreUrl.startsWith("s3")) { return AmazonS3ClientBuilder.standard() .build(); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/NhaisMongoClientConfiguration.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/NhaisMongoClientConfiguration.java index 1ba4f7d02..35159290d 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/NhaisMongoClientConfiguration.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/NhaisMongoClientConfiguration.java @@ -70,10 +70,16 @@ private String createConnectionString() { LOGGER.info("A value was provided from mongodb host. Generating a connection string from individual properties."); return createConnectionStringFromProperties(); } else if (!Strings.isNullOrEmpty(uri)) { - LOGGER.info("A mongodb connection string provided in spring.data.mongodb.uri and will be used to configure the database connection."); + LOGGER.info( + "A mongodb connection string provided in spring.data.mongodb.uri " + + "and will be used to configure the database connection." + ); return uri; } else { - LOGGER.error("Mongodb must be configured using a connection string or individual properties. Both uri and host are null or empty"); + LOGGER.error( + "Mongodb must be configured using a connection string or individual properties. " + + "Both uri and host are null or empty" + ); throw new RuntimeException("Missing mongodb connection string and/or properties"); } } @@ -92,7 +98,10 @@ private String createConnectionStringFromProperties() { LOGGER.debug("The generated connection will use use options '{}'", options); cs += "/?" + options; } else { - LOGGER.warn("No options for the mongodb connection string were provided. If connecting to a cluster the driver may not work as expected."); + LOGGER.warn( + "No options for the mongodb connection string were provided." + + "If connecting to a cluster the driver may not work as expected." + ); } return cs; } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/CosmosTtlCreator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/CosmosTtlCreator.java index 84ca90b63..9fc8007f0 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/CosmosTtlCreator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/CosmosTtlCreator.java @@ -19,7 +19,11 @@ public CosmosTtlCreator(IndexOperations indexOperations, Duration duration) { public void create(Class clazz) { if (ttlIndexHasChanged()) { - LOGGER.info("TTL value has changed for {} - dropping index and creating new one using value {}", clazz.getSimpleName(), duration); + LOGGER.info( + "TTL value has changed for {} - dropping index and creating new one using value {}", + clazz.getSimpleName(), + duration + ); String indexName = findTtlIndex().map(IndexInfo::getName).orElseThrow(); indexOperations.dropIndex(indexName); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/MongoTtlCreator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/MongoTtlCreator.java index f04f1ae50..15cb3874f 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/MongoTtlCreator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/MongoTtlCreator.java @@ -20,7 +20,11 @@ public MongoTtlCreator(IndexOperations indexOperations, Duration duration) { public void create(Class clazz) { if (ttlIndexHasChanged()) { - LOGGER.info("TTL value has changed for {} - dropping index and creating new one using value {}", clazz.getSimpleName(), duration); + LOGGER.info( + "TTL value has changed for {} - dropping index and creating new one using value {}", + clazz.getSimpleName(), + duration + ); indexOperations.dropIndex(TTL_INDEX_NAME); } indexOperations.ensureIndex( diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/TimeToLiveConfiguration.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/TimeToLiveConfiguration.java index a559e94d7..ffaeb2dd3 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/TimeToLiveConfiguration.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/TimeToLiveConfiguration.java @@ -23,7 +23,7 @@ public class TimeToLiveConfiguration { @PostConstruct public void init() { - if(mongoConfig.isAutoIndexCreation()) { + if (mongoConfig.isAutoIndexCreation()) { createTimeToLiveIndex(InboundState.class); createTimeToLiveIndex(OutboundState.class); } @@ -33,7 +33,7 @@ private void createTimeToLiveIndex(Class clazz) { var duration = mongoConfig.getTtl(); var indexOperations = mongoTemplate.indexOps(clazz); - if(mongoConfig.isCosmosDbEnabled()) { + if (mongoConfig.isCosmosDbEnabled()) { new CosmosTtlCreator(indexOperations, duration).create(clazz); } else { new MongoTtlCreator(indexOperations, duration).create(clazz); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/TtlCreator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/TtlCreator.java index 4d32f4363..0bfbb8dda 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/TtlCreator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/configuration/ttl/TtlCreator.java @@ -13,9 +13,9 @@ public abstract class TtlCreator { protected final IndexOperations indexOperations; protected final Duration duration; - abstract public void create(Class clazz); + public abstract void create(Class clazz); - abstract protected Optional findTtlIndex(); + protected abstract Optional findTtlIndex(); protected boolean ttlIndexHasChanged() { Optional ttlIndex = findTtlIndex(); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/EdifactParser.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/EdifactParser.java index 0f2a37e76..895c41846 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/EdifactParser.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/EdifactParser.java @@ -24,7 +24,7 @@ @Component public class EdifactParser { - private final String TRANSACTION_START_SEGMENT = ReferenceTransactionNumber.KEY_QUALIFIER; + private static final String TRANSACTION_START_SEGMENT = ReferenceTransactionNumber.KEY_QUALIFIER; public Interchange parse(String edifact) { var allEdifactSegments = Arrays.asList(Split.bySegmentTerminator(edifact.replaceAll("\\n", "").strip())); @@ -61,7 +61,8 @@ private Message parseMessage(List singleMessageEdifactSegments) { // there might be no transaction inside - RECEP - so all message lines belong to the message .orElse(messageTrailerIndex); - var onlyMessageLines = new ArrayList<>(singleMessageEdifactSegments.subList(0, firstTransactionStartIndex)); // first lines until transaction + // first lines until transaction + var onlyMessageLines = new ArrayList<>(singleMessageEdifactSegments.subList(0, firstTransactionStartIndex)); onlyMessageLines.add(singleMessageEdifactSegments.get(messageTrailerIndex)); var message = new Message(onlyMessageLines); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepConsumerService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepConsumerService.java index 4a5953602..33dd1e78b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepConsumerService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepConsumerService.java @@ -82,7 +82,10 @@ private List prepareOutboun .collect(Collectors.toList()); } - private OutboundStateRepositoryExtensions.UpdateRecepParams prepareOutboundStateUpdateParams(Message message, ReferenceMessageRecep referenceMessageRecep) { + private OutboundStateRepositoryExtensions.UpdateRecepParams prepareOutboundStateUpdateParams( + Message message, + ReferenceMessageRecep referenceMessageRecep + ) { //sender is swapped with recipient as communication is done the opposite way var outboundSender = message.getInterchange().getInterchangeHeader().getRecipient(); var outboundRecipient = message.getInterchange().getInterchangeHeader().getSender(); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepProducerService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepProducerService.java index fb2604fb2..0bdcf0320 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepProducerService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepProducerService.java @@ -78,14 +78,24 @@ private List mapToReferenceMessageReceps(Interchange rece .collect(Collectors.toList()); } - private void setTimestamps(RecepHeader recepInterchangeHeader, RecepBeginningOfMessage recepBeginningOfMessage, RecepMessageDateTime recepTranslationDateTime) { + private void setTimestamps( + RecepHeader recepInterchangeHeader, + RecepBeginningOfMessage recepBeginningOfMessage, + RecepMessageDateTime recepTranslationDateTime + ) { var currentTimestamp = timestampService.getCurrentTimestamp(); recepInterchangeHeader.setTranslationTime(currentTimestamp); recepBeginningOfMessage.setTimestamp(currentTimestamp); recepTranslationDateTime.setTimestamp(currentTimestamp); } - private void setSequenceNumbers(List recepMessageSegments, RecepHeader recepInterchangeHeader, RecepMessageHeader recepMessageHeader, MessageTrailer recepMessageTrailer, InterchangeTrailer recepInterchangeTrailer) { + private void setSequenceNumbers( + List recepMessageSegments, + RecepHeader recepInterchangeHeader, + RecepMessageHeader recepMessageHeader, + MessageTrailer recepMessageTrailer, + InterchangeTrailer recepInterchangeTrailer + ) { var recepInterchangeSequence = sequenceService.generateInterchangeSequence( recepInterchangeHeader.getSender(), recepInterchangeHeader.getRecipient()); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RegistrationConsumerService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RegistrationConsumerService.java index d1d2194a1..d55f0b155 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RegistrationConsumerService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/RegistrationConsumerService.java @@ -3,7 +3,6 @@ import com.google.common.collect.Streams; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import uk.nhs.digital.nhsconnect.nhais.inbound.queue.InboundGpSystemService; @@ -23,7 +22,6 @@ import uk.nhs.digital.nhsconnect.nhais.outbound.state.OutboundState; import uk.nhs.digital.nhsconnect.nhais.outbound.state.OutboundStateFactory; import uk.nhs.digital.nhsconnect.nhais.outbound.state.OutboundStateRepository; -import uk.nhs.digital.nhsconnect.nhais.utils.OperationId; import java.util.Collection; import java.util.List; @@ -138,7 +136,7 @@ private List prepareSupplierQueueDataToSend(L } private void logInterchangeReceived(Interchange interchange) { - if(LOGGER.isInfoEnabled()) { + if (LOGGER.isInfoEnabled()) { var interchangeHeader = interchange.getInterchangeHeader(); LOGGER.info("Translating EDIFACT interchange from Sender={} to Recipient={} with RIS={} containing {} messages", interchangeHeader.getSender(), interchangeHeader.getRecipient(), interchangeHeader.getSequenceNumber(), @@ -147,7 +145,7 @@ private void logInterchangeReceived(Interchange interchange) { } private void logRecepSentFor(Interchange interchange) { - if(LOGGER.isInfoEnabled()) { + if (LOGGER.isInfoEnabled()) { var interchangeHeader = interchange.getInterchangeHeader(); LOGGER.info("Published for async send to MESH a RECEP for the interchange from Sender={} to Recipient={} with RIS={}", interchangeHeader.getSender(), interchangeHeader.getRecipient(), interchangeHeader.getSequenceNumber()); @@ -155,7 +153,7 @@ private void logRecepSentFor(Interchange interchange) { } private void logTransactionReceived(Transaction transaction, String operationId) { - if(LOGGER.isInfoEnabled()) { + if (LOGGER.isInfoEnabled()) { var message = transaction.getMessage(); var type = transaction.getMessage().getReferenceTransactionType().getTransactionType().getAbbreviation(); LOGGER.info("Translating EDIFACT transaction TN={} OperationId={} of message Type={} RMS={}", diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/CloseQuarterNotificationMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/CloseQuarterNotificationMapper.java index 5887377be..5339e8b33 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/CloseQuarterNotificationMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/CloseQuarterNotificationMapper.java @@ -10,7 +10,7 @@ public class CloseQuarterNotificationMapper implements FhirTransactionMapper { @Override public Parameters map(Transaction transaction) { - return new Parameters();//this mapper is intentionally left blank, parameters are not modified for close quarter notification + return new Parameters(); //this mapper is intentionally left blank, parameters are not modified for close quarter notification } @Override diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/DeductionRejectionTransactionMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/DeductionRejectionTransactionMapper.java index 393eb90af..a26ff3549 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/DeductionRejectionTransactionMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/DeductionRejectionTransactionMapper.java @@ -27,7 +27,9 @@ public Parameters map(Transaction transaction) { var freeText = transaction .getFreeText() - .orElseThrow(() -> new EdifactValidationException("HA Notes (Free Text) are mandatory for inbound deduction request rejection")); + .orElseThrow( + () -> new EdifactValidationException("HA Notes (Free Text) are mandatory for inbound deduction request rejection") + ); parameters.addParameter() .setName(ParameterNames.FREE_TEXT) .setValue(new StringType(freeText.getFreeTextValue())); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/DeductionTransactionMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/DeductionTransactionMapper.java index 63480e5ed..1b8650c0d 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/DeductionTransactionMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/DeductionTransactionMapper.java @@ -19,7 +19,7 @@ @Component public class DeductionTransactionMapper implements FhirTransactionMapper { - private final static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); @Override public Parameters map(Transaction transaction) { @@ -27,18 +27,30 @@ public Parameters map(Transaction transaction) { transaction.getPersonName() .map(PersonName::getNhsNumber) .map(NhsIdentifier::new) - .ifPresentOrElse(nhsIdentifier -> ParametersExtension.extractPatient(parameters).setIdentifier(List.of(nhsIdentifier)), - () -> {throw new EdifactValidationException("Missing mandatory patient NHS number");}); + .ifPresentOrElse( + nhsIdentifier -> ParametersExtension.extractPatient(parameters).setIdentifier(List.of(nhsIdentifier)), + () -> { + throw new EdifactValidationException("Missing mandatory patient NHS number"); + } + ); transaction.getDeductionReasonCode() .map(DeductionReasonCode::getCode) - .ifPresentOrElse(code -> parameters.addParameter(ParameterNames.DEDUCTION_REASON_CODE, code), - () -> {throw new EdifactValidationException("Missing mandatory deduction reason code");}); + .ifPresentOrElse( + code -> parameters.addParameter(ParameterNames.DEDUCTION_REASON_CODE, code), + () -> { + throw new EdifactValidationException("Missing mandatory deduction reason code"); + } + ); transaction.getDeductionDate() .map(DeductionDate::getDate) - .ifPresentOrElse(deductionDate -> parameters.addParameter(ParameterNames.DATE_OF_DEDUCTION, deductionDate.format(DATE_TIME_FORMATTER)), - () -> {throw new EdifactValidationException("Missing mandatory date of deduction");}); + .ifPresentOrElse( + deductionDate -> parameters.addParameter(ParameterNames.DATE_OF_DEDUCTION, deductionDate.format(DATE_TIME_FORMATTER)), + () -> { + throw new EdifactValidationException("Missing mandatory date of deduction"); + } + ); transaction.getNewHealthAuthorityName() .map(NewHealthAuthorityName::getHaName) diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/FP69PriorNotificationTransactionMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/FP69PriorNotificationTransactionMapper.java index 90cd9f3ed..121a7474b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/FP69PriorNotificationTransactionMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/FP69PriorNotificationTransactionMapper.java @@ -93,7 +93,8 @@ private void mapDateOfBirth(Patient patient, Transaction transaction) { patient::setBirthDate, () -> { throw new EdifactValidationException( - "For an FP69 prior notification (reference F9) the DTM+329 segment is required to provide the patient date of birth"); + "For an FP69 prior notification (reference F9) the DTM+329 segment is required to provide the patient date of birth" + ); }); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/NullableStringType.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/NullableStringType.java index 51aecf3a1..c76c02495 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/NullableStringType.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/NullableStringType.java @@ -3,11 +3,11 @@ import org.hl7.fhir.r4.model.StringType; class NullableStringType extends StringType { - public NullableStringType(String theValue) { + NullableStringType(String theValue) { super(theValue); } - public NullableStringType() { + NullableStringType() { super(null); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/TransactionMapperConfig.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/TransactionMapperConfig.java index 5f7885cc9..0f4d0f27b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/TransactionMapperConfig.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/fhir/mapper/TransactionMapperConfig.java @@ -12,7 +12,9 @@ @Configuration public class TransactionMapperConfig { @Bean - public Map getTransactionMappers(Set fhirTransactionMappers) { + public Map getTransactionMappers( + Set fhirTransactionMappers + ) { return fhirTransactionMappers.stream() .collect(Collectors.toMap(FhirTransactionMapper::getTransactionType, Function.identity())); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/jsonpatch/mapper/GenderPatchTransactionMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/jsonpatch/mapper/GenderPatchTransactionMapper.java index b6b05d751..42e4fdcee 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/jsonpatch/mapper/GenderPatchTransactionMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/jsonpatch/mapper/GenderPatchTransactionMapper.java @@ -1,6 +1,5 @@ package uk.nhs.digital.nhsconnect.nhais.inbound.jsonpatch.mapper; -import uk.nhs.digital.nhsconnect.nhais.inbound.jsonpatch.mapper.PatchTransactionMapper; import uk.nhs.digital.nhsconnect.nhais.model.edifact.PersonSex; import uk.nhs.digital.nhsconnect.nhais.model.edifact.Transaction; import uk.nhs.digital.nhsconnect.nhais.model.jsonpatch.AmendmentPatch; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/queue/UnknownWorkflowException.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/queue/UnknownWorkflowException.java index 83ca279f7..392da5f71 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/queue/UnknownWorkflowException.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/queue/UnknownWorkflowException.java @@ -3,7 +3,7 @@ import uk.nhs.digital.nhsconnect.nhais.rest.exception.NhaisBaseException; class UnknownWorkflowException extends NhaisBaseException { - public UnknownWorkflowException(Object workflowId) { + UnknownWorkflowException(Object workflowId) { super("Unknown workflow id: " + workflowId); } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/state/InboundStateFactory.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/state/InboundStateFactory.java index 0c573297d..b005e9e06 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/state/InboundStateFactory.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/state/InboundStateFactory.java @@ -9,7 +9,6 @@ import uk.nhs.digital.nhsconnect.nhais.model.edifact.ReferenceTransactionType; import uk.nhs.digital.nhsconnect.nhais.model.edifact.Transaction; import uk.nhs.digital.nhsconnect.nhais.utils.ConversationIdService; -import uk.nhs.digital.nhsconnect.nhais.utils.OperationId; import uk.nhs.digital.nhsconnect.nhais.utils.TimestampService; @Component diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/state/InboundStateRepository.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/state/InboundStateRepository.java index 84b4a633d..93c3f48da 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/state/InboundStateRepository.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/inbound/state/InboundStateRepository.java @@ -10,5 +10,12 @@ @Repository public interface InboundStateRepository extends CrudRepository { @Query("{ 'workflowId' : ?0, 'sndr' : ?1, 'recip' : ?2, 'intSeq' : ?3, 'msgSeq' : ?4, 'tn' : ?5}") - Optional findBy(WorkflowId workflowId, String sender, String recipient, Long interchangeSequence, Long messageSequence, Long transactionNumber); + Optional findBy( + WorkflowId workflowId, + String sender, + String recipient, + Long interchangeSequence, + Long messageSequence, + Long transactionNumber + ); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshService.java index 60c533a22..f6293ba23 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/MeshService.java @@ -51,9 +51,9 @@ public MeshService(MeshClient meshClient, @Scheduled(fixedRateString = "${nhais.mesh.wakeupIntervalInMilliseconds}") public void scanMeshInboxForMessages() { - if (!meshMailBoxScheduler.isEnabled()){ - LOGGER.warn("Not running the MESH mailbox polling cycle because it is disabled. Set variable " + - "NHAIS_SCHEDULER_ENABLED to true to enable it."); + if (!meshMailBoxScheduler.isEnabled()) { + LOGGER.warn("Not running the MESH mailbox polling cycle because it is disabled. Set variable " + + "NHAIS_SCHEDULER_ENABLED to true to enable it."); return; } LOGGER.info("Requesting lock from database to run MESH mailbox polling cycle"); @@ -63,18 +63,22 @@ public void scanMeshInboxForMessages() { List inboxMessageIds = authenticateAndGetInboxMessageIds(); for (int i = 0; i < inboxMessageIds.size(); i++) { String messageId = inboxMessageIds.get(i); - if(sufficientTimeRemainsInPollingCycle(pollingCycleElapsedTime)) { + if (sufficientTimeRemainsInPollingCycle(pollingCycleElapsedTime)) { processSingleMessage(messageId); } else { - LOGGER.warn("Insufficient time remains to complete the polling cycle. Processed {} of {} messages from inbox.", i + 1, inboxMessageIds.size()); + LOGGER.warn( + "Insufficient time remains to complete the polling cycle. Processed {} of {} messages from inbox.", + i + 1, + inboxMessageIds.size() + ); return; } } LOGGER.info("Completed MESH mailbox polling cycle. Processed all messages from inbox."); } else { - LOGGER.info("Could not obtain database lock to run MESH mailbox polling cycle: insufficient time has elapsed " + - "since the previous polling cycle or another adaptor instance has already started the polling cycle. " + - "Next scan in {} seconds", TimeUnit.SECONDS.convert(wakeupIntervalInMilliseconds, TimeUnit.MILLISECONDS)); + LOGGER.info("Could not obtain database lock to run MESH mailbox polling cycle: insufficient time has elapsed " + + "since the previous polling cycle or another adaptor instance has already started the polling cycle. " + + "Next scan in {} seconds", TimeUnit.SECONDS.convert(wakeupIntervalInMilliseconds, TimeUnit.MILLISECONDS)); } } @@ -101,7 +105,10 @@ private void processSingleMessage(String messageId) { meshClient.acknowledgeMessage(meshMessage.getMeshMessageId()); LOGGER.info("Acknowledged MeshMessageId={} on MESH API", messageId); } catch (MeshWorkflowUnknownException ex) { - LOGGER.warn("MeshMessageId={} has an unsupported MeshWorkflowId={} and has been left in the inbox.", messageId, ex.getWorkflowId()); + LOGGER.warn( + "MeshMessageId={} has an unsupported MeshWorkflowId={} and has been left in the inbox.", + messageId, ex.getWorkflowId() + ); } catch (Exception ex) { LOGGER.error("Error during reading of MESH message. MeshMessageId={}", messageId, ex); // skip message with error and attempt to download the next one diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/RecipientMailboxIdMappings.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/RecipientMailboxIdMappings.java index e4cb3e4f0..f8529b6a0 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/RecipientMailboxIdMappings.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/RecipientMailboxIdMappings.java @@ -45,7 +45,9 @@ private Map createMappings() { private void validateMappings(String[] rows) { if (rows.length < 2) { - throw new MeshRecipientUnknownException("NHAIS_MESH_RECIPIENT_MAILBOX_ID_MAPPINGS env var doesn't contain valid recipient to mailbox mapping"); + throw new MeshRecipientUnknownException( + "NHAIS_MESH_RECIPIENT_MAILBOX_ID_MAPPINGS env var doesn't contain valid recipient to mailbox mapping" + ); } } } \ No newline at end of file diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshApiConnectionException.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshApiConnectionException.java index 5c8ec2ba4..e0336b211 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshApiConnectionException.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshApiConnectionException.java @@ -6,11 +6,25 @@ public class MeshApiConnectionException extends NhaisBaseException { public MeshApiConnectionException(String description, HttpStatus expectedStatus, HttpStatus actualStatus) { - super(description + " Expected status code: " + expectedStatus.value() + ", but received: " + actualStatus.value()); + super( + description + + " Expected status code: " + + expectedStatus.value() + + ", but received: " + + actualStatus.value() + ); } public MeshApiConnectionException(String description, HttpStatus expectedStatus, HttpStatus actualStatus, String content) { - super(description + " Expected status code: " + expectedStatus.value() + ", but received: " + actualStatus.value() + " with response content\n" + content); + super( + description + + " Expected status code: " + + expectedStatus.value() + + ", but received: " + + actualStatus.value() + + " with response content\n" + + content + ); } public MeshApiConnectionException(String message) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshClient.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshClient.java index 0ce6bf38b..e6770f5ad 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshClient.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshClient.java @@ -9,7 +9,6 @@ import org.apache.http.HttpResponse; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -58,7 +57,12 @@ public void authenticate() { public MeshMessageId sendEdifactMessage(OutboundMeshMessage outboundMeshMessage) { final var loggingName = "Send a message"; String recipientMailbox = recipientMailboxIdMappings.getRecipientMailboxId(outboundMeshMessage); - LOGGER.info("Sending to MESH API: recipient: {}, MESH mailbox: {}, workflow: {}", outboundMeshMessage.getHaTradingPartnerCode(), recipientMailbox, outboundMeshMessage.getWorkflowId()); + LOGGER.info( + "Sending to MESH API: recipient: {}, MESH mailbox: {}, workflow: {}", + outboundMeshMessage.getHaTradingPartnerCode(), + recipientMailbox, + outboundMeshMessage.getWorkflowId() + ); try (CloseableHttpClient client = meshHttpClientBuilder.build()) { var request = meshRequests.sendMessage(recipientMailbox, outboundMeshMessage.getWorkflowId()); String contentString = outboundMeshMessage.getContent(); @@ -174,12 +178,15 @@ private void logResponse(String type, HttpResponse response) { // log as INFO - these are useful for normal operation to trace requests and error reports LOGGER.info("MESH '{}' response status line: {}", type, response.getStatusLine()); LOGGER.info("MESH '{}' response headers: {}", type, response.getAllHeaders()); - if (LOGGER.isDebugEnabled()) { - if (response.getEntity() != null) { - var entity = response.getEntity(); - LOGGER.debug("MESH '{}' response content encoding: {}, content type: {}, content length: {}", type, entity.getContentEncoding(), entity.getContentType(), entity.getContentLength()); - // response is usually not "repeatable" so we can only decode it once. Log response content separately. - } + if (LOGGER.isDebugEnabled() && response.getEntity() != null) { + var entity = response.getEntity(); + LOGGER.debug( + "MESH '{}' response content encoding: {}, content type: {}, content length: {}", + type, + entity.getContentEncoding(), + entity.getContentType(), entity.getContentLength() + ); + // response is usually not "repeatable" so we can only decode it once. Log response content separately. } } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshRequests.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshRequests.java index 7831963fb..4afcb5c3c 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshRequests.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/http/MeshRequests.java @@ -16,31 +16,31 @@ public class MeshRequests { private final MeshHeaders meshHeaders; - public HttpPost authenticate(){ + public HttpPost authenticate() { var request = new HttpPost(meshConfig.getHost() + meshConfig.getMailboxId()); request.setHeaders(meshHeaders.createAuthenticateHeaders()); return request; } - public HttpPost sendMessage(String recipient, WorkflowId workflowId){ + public HttpPost sendMessage(String recipient, WorkflowId workflowId) { var request = new HttpPost(meshConfig.getHost() + meshConfig.getMailboxId() + "/outbox"); request.setHeaders(meshHeaders.createSendHeaders(recipient, workflowId)); return request; } - public HttpGet getMessage(String messageId){ + public HttpGet getMessage(String messageId) { var request = new HttpGet(meshConfig.getHost() + meshConfig.getMailboxId() + "/inbox/" + messageId); request.setHeaders(meshHeaders.createMinimalHeaders()); return request; } - public HttpGet getMessageIds(){ + public HttpGet getMessageIds() { var request = new HttpGet(meshConfig.getHost() + meshConfig.getMailboxId() + "/inbox"); request.setHeaders(meshHeaders.createMinimalHeaders()); return request; } - public HttpPut acknowledge(String messageId){ + public HttpPut acknowledge(String messageId) { var request = new HttpPut(meshConfig.getHost() + meshConfig.getMailboxId() + "/inbox/" + messageId + "/status/acknowledged"); request.setHeaders(meshHeaders.createMinimalHeaders()); return request; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/message/WorkflowId.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/message/WorkflowId.java index 53d1bb243..d039f0443 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/message/WorkflowId.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/message/WorkflowId.java @@ -20,7 +20,7 @@ public String toString() { return workflowId; } - public static WorkflowId fromString(String workflowId){ + public static WorkflowId fromString(String workflowId) { return Arrays.stream(WorkflowId.values()) .filter(workflow -> workflow.workflowId.equalsIgnoreCase(workflowId)) .findFirst() diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/scheduler/SchedulerTimestampRepositoryExtensionsImpl.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/scheduler/SchedulerTimestampRepositoryExtensionsImpl.java index acf9065bf..feb44ae49 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/scheduler/SchedulerTimestampRepositoryExtensionsImpl.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/scheduler/SchedulerTimestampRepositoryExtensionsImpl.java @@ -41,12 +41,20 @@ public boolean updateTimestamp(String schedulerType, Instant timestamp, long sec return updateSuccessful(result); } else { - LOGGER.info("{} collection does not exist or it is empty. Document with timestamp will be created", MESH_TIMESTAMP_COLLECTION_NAME); + LOGGER.info( + "{} collection does not exist or it is empty. Document with timestamp will be created", + MESH_TIMESTAMP_COLLECTION_NAME + ); SchedulerTimestamp schedulerTimestamp = new SchedulerTimestamp(schedulerType, timestampService.getCurrentTimestamp()); try { mongoOperations.save(schedulerTimestamp, MESH_TIMESTAMP_COLLECTION_NAME); } catch (MongoWriteException | DuplicateKeyException e) { - LOGGER.warn("Unable to create new document for scheduler type " + schedulerType + ". Most likely another instance already created the document.", e); + LOGGER.warn( + "Unable to create new document for scheduler type " + + schedulerType + + ". Most likely another instance already created the document.", + e + ); } return false; } @@ -57,7 +65,10 @@ private boolean documentAlreadyExists(String schedulerType) { var query = query(where(SCHEDULER_TYPE).is(schedulerType)); var count = mongoOperations.count(query, MESH_TIMESTAMP_COLLECTION_NAME); if (count > 1) { - LOGGER.error("More than one document exists for schedulerType {}. This can cause unexpected scheduling behaviour.", schedulerType); + LOGGER.error( + "More than one document exists for schedulerType {}. This can cause unexpected scheduling behaviour.", + schedulerType + ); } return count >= 1; } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/AuthorizationHashGenerator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/AuthorizationHashGenerator.java index 73796a12b..18ba06268 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/AuthorizationHashGenerator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/AuthorizationHashGenerator.java @@ -12,16 +12,26 @@ class AuthorizationHashGenerator { - private final static String HMAC_SHA256_ALGORITHM_NAME = "HmacSHA256"; + private static final String HMAC_SHA256_ALGORITHM_NAME = "HmacSHA256"; @SneakyThrows public String computeHash(MeshConfig meshConfig, Nonce nonce, String timestamp) { - String hashInput = String.join(":", meshConfig.getMailboxId(), nonce.value, nonce.count, meshConfig.getMailboxPassword(), timestamp); - - Mac sha256_HMAC = Mac.getInstance(HMAC_SHA256_ALGORITHM_NAME); - SecretKeySpec secret_key = new SecretKeySpec(meshConfig.getSharedKey().getBytes(StandardCharsets.UTF_8), HMAC_SHA256_ALGORITHM_NAME); - sha256_HMAC.init(secret_key); - - return Hex.encodeHexString(sha256_HMAC.doFinal(hashInput.getBytes(StandardCharsets.UTF_8))); + String hashInput = String.join( + ":", + meshConfig.getMailboxId(), + nonce.value, + nonce.count, + meshConfig.getMailboxPassword(), + timestamp + ); + + Mac sha256HMAC = Mac.getInstance(HMAC_SHA256_ALGORITHM_NAME); + SecretKeySpec secretKeySpec = new SecretKeySpec( + meshConfig.getSharedKey().getBytes(StandardCharsets.UTF_8), + HMAC_SHA256_ALGORITHM_NAME + ); + sha256HMAC.init(secretKeySpec); + + return Hex.encodeHexString(sha256HMAC.doFinal(hashInput.getBytes(StandardCharsets.UTF_8))); } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/MeshAuthorizationToken.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/MeshAuthorizationToken.java index e0261e4a1..3d04aa17e 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/MeshAuthorizationToken.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/MeshAuthorizationToken.java @@ -3,7 +3,6 @@ import java.time.Instant; import uk.nhs.digital.nhsconnect.nhais.mesh.http.MeshConfig; -import uk.nhs.digital.nhsconnect.nhais.utils.TimestampService; /** * MESH authorization token @@ -11,12 +10,17 @@ */ public class MeshAuthorizationToken { - private final static String MESSAGE_TYPE = "NHSMESH "; + private static final String MESSAGE_TYPE = "NHSMESH "; private final String data; private final String hash; - public MeshAuthorizationToken(MeshConfig meshConfig, Instant timestamp, Nonce nonce, AuthorizationHashGenerator authorizationHashGenerator) { + public MeshAuthorizationToken( + MeshConfig meshConfig, + Instant timestamp, + Nonce nonce, + AuthorizationHashGenerator authorizationHashGenerator + ) { String prefix = MESSAGE_TYPE + meshConfig.getMailboxId(); String currentTimeFormatted = new TokenTimestamp(timestamp).getValue(); this.data = String.join(":", prefix, nonce.value, nonce.count, currentTimeFormatted); @@ -27,7 +31,7 @@ public MeshAuthorizationToken(MeshConfig meshConfig) { this(meshConfig, Instant.now(), new Nonce(), new AuthorizationHashGenerator()); } - public String getValue(){ + public String getValue() { return String.join(":", data, hash); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/Nonce.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/Nonce.java index 82acd57c8..c48da2ab6 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/Nonce.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/Nonce.java @@ -15,7 +15,7 @@ class Nonce { @NonNull final String value; final String count = "1"; //token should use Nonce only once - public Nonce() { + Nonce() { this.value = UUID.randomUUID().toString(); } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/TokenTimestamp.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/TokenTimestamp.java index 946ba3eb9..0facdc930 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/TokenTimestamp.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/TokenTimestamp.java @@ -9,11 +9,11 @@ @RequiredArgsConstructor class TokenTimestamp { - private static final String TIMESTAMP_FORMAT= "yyyyMMddHHmm"; + private static final String TIMESTAMP_FORMAT = "yyyyMMddHHmm"; @NonNull private final Instant datetime; public String getValue() { - return DateTimeFormatter.ofPattern(TIMESTAMP_FORMAT).withZone(TimestampService.UKZone).format(datetime); + return DateTimeFormatter.ofPattern(TIMESTAMP_FORMAT).withZone(TimestampService.UK_ZONE).format(datetime); } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/AcceptanceCode.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/AcceptanceCode.java index d29b50cd6..33185d6ed 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/AcceptanceCode.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/AcceptanceCode.java @@ -26,9 +26,9 @@ public class AcceptanceCode extends Segment { "I" = "Internal transfer within partnership" "S" = "Acceptance with same GP new FHSA" */ - private final static String KEY = "HEA"; - private final static String ACD_PREFIX = "ACD"; - private final static String ZZZ_SUFFIX = ":ZZZ"; + private static final String KEY = "HEA"; + private static final String ACD_PREFIX = "ACD"; + private static final String ZZZ_SUFFIX = ":ZZZ"; private @NonNull String code; private static boolean isCodeAllowed(String inputCode) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/AcceptanceType.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/AcceptanceType.java index e617aa129..3154853e2 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/AcceptanceType.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/AcceptanceType.java @@ -15,9 +15,9 @@ @Builder @Data public class AcceptanceType extends Segment { - private final static String KEY = "HEA"; - private final static String APT_PREFIX = "ATP"; - private final static String ZZZ_SUFFIX = ":ZZZ"; + private static final String KEY = "HEA"; + private static final String APT_PREFIX = "ATP"; + private static final String ZZZ_SUFFIX = ":ZZZ"; private @NonNull AvailableTypes acceptanceType; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/BeginningOfMessage.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/BeginningOfMessage.java index a4ff53b02..7c840cb6b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/BeginningOfMessage.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/BeginningOfMessage.java @@ -9,7 +9,7 @@ * example: BGM+++507' */ @Getter @Setter @RequiredArgsConstructor -public class BeginningOfMessage extends Segment{ +public class BeginningOfMessage extends Segment { @Override public String getKey() { return "BGM"; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DeductionDate.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DeductionDate.java index d2dfee98c..07f46bd64 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DeductionDate.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DeductionDate.java @@ -17,7 +17,7 @@ @AllArgsConstructor @Getter @EqualsAndHashCode(callSuper = false) @ToString -public class DeductionDate extends Segment{ +public class DeductionDate extends Segment { public static final String KEY = "DTM"; private static final String TYPE_CODE = "961"; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DeductionReasonCode.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DeductionReasonCode.java index c0c2ddaf6..f3504f5d2 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DeductionReasonCode.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DeductionReasonCode.java @@ -17,8 +17,8 @@ @AllArgsConstructor public class DeductionReasonCode extends Segment { - public final static String KEY = "GIS"; - private final static String ZZZ_SUFFIX = ":ZZZ"; + public static final String KEY = "GIS"; + private static final String ZZZ_SUFFIX = ":ZZZ"; private final @NonNull String code; public static DeductionReasonCode fromString(String edifactString) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DrugsMarker.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DrugsMarker.java index 5b43d5bea..5626b8c68 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DrugsMarker.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/DrugsMarker.java @@ -12,10 +12,10 @@ @RequiredArgsConstructor @EqualsAndHashCode(callSuper = false) public class DrugsMarker extends Segment { - private final static String KEY = "HEA"; - private final static String APT_PREFIX = "DM"; - private final static String ZZZ_SUFFIX = ":ZZZ"; - public final static String KEY_PREFIX = KEY + PLUS_SEPARATOR + APT_PREFIX; + private static final String KEY = "HEA"; + private static final String APT_PREFIX = "DM"; + private static final String ZZZ_SUFFIX = ":ZZZ"; + public static final String KEY_PREFIX = KEY + PLUS_SEPARATOR + APT_PREFIX; @Getter private final boolean drugsMarker; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/FP69ExpiryDate.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/FP69ExpiryDate.java index beb92abf7..ba942594b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/FP69ExpiryDate.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/FP69ExpiryDate.java @@ -16,11 +16,11 @@ @EqualsAndHashCode(callSuper = false) @Data public class FP69ExpiryDate extends Segment { - private final static String KEY = "DTM"; - private final static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(TimestampService.UKZone); - private final static String QUALIFIER = "962"; - public final static String KEY_QUALIFIER = KEY + PLUS_SEPARATOR + QUALIFIER; - private final static String DATE_FORMAT = "102"; + private static final String KEY = "DTM"; + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(TimestampService.UK_ZONE); + private static final String QUALIFIER = "962"; + public static final String KEY_QUALIFIER = KEY + PLUS_SEPARATOR + QUALIFIER; + private static final String DATE_FORMAT = "102"; private final @NonNull LocalDate expiryDate; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/FP69ReasonCode.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/FP69ReasonCode.java index b7c9e67b0..4ac3aad67 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/FP69ReasonCode.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/FP69ReasonCode.java @@ -13,10 +13,10 @@ @Data public class FP69ReasonCode extends Segment { - private final static String KEY = "HEA"; - private final static String QUALIFIER = "FRN"; - public final static String KEY_QUALIFIER = KEY + PLUS_SEPARATOR + QUALIFIER; - private final static String ZZZ_SUFFIX = ":ZZZ"; + private static final String KEY = "HEA"; + private static final String QUALIFIER = "FRN"; + public static final String KEY_QUALIFIER = KEY + PLUS_SEPARATOR + QUALIFIER; + private static final String ZZZ_SUFFIX = ":ZZZ"; private final @NonNull Integer code; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/HealthAuthorityNameAndAddress.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/HealthAuthorityNameAndAddress.java index 6159e0ead..513869925 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/HealthAuthorityNameAndAddress.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/HealthAuthorityNameAndAddress.java @@ -12,7 +12,7 @@ * Example NAD+FHS+XX1:954' */ @Getter @Setter @RequiredArgsConstructor -public class HealthAuthorityNameAndAddress extends Segment{ +public class HealthAuthorityNameAndAddress extends Segment { public static final String KEY = "NAD"; public static final String QUALIFIER = "FHS"; @@ -47,8 +47,13 @@ public void preValidate() throws EdifactValidationException { } public static HealthAuthorityNameAndAddress fromString(String edifactString) { - if(!edifactString.startsWith(HealthAuthorityNameAndAddress.KEY_QUALIFIER)){ - throw new IllegalArgumentException("Can't create " + HealthAuthorityNameAndAddress.class.getSimpleName() + " from " + edifactString); + if (!edifactString.startsWith(HealthAuthorityNameAndAddress.KEY_QUALIFIER)) { + throw new IllegalArgumentException( + "Can't create " + + HealthAuthorityNameAndAddress.class.getSimpleName() + + " from " + + edifactString + ); } String[] keySplit = Split.byPlus(edifactString); String identifier = Split.byColon(keySplit[2])[0]; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/InterchangeHeader.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/InterchangeHeader.java index c4ed86744..f1a1a914c 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/InterchangeHeader.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/InterchangeHeader.java @@ -27,7 +27,7 @@ public class InterchangeHeader extends Segment { public static final String KEY = "UNB"; - private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyMMdd:HHmm").withZone(TimestampService.UKZone); + private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyMMdd:HHmm").withZone(TimestampService.UK_ZONE); private static final long MAX_INTERCHANGE_SEQUENCE = 99_999_999L; private static final String RECEP_ENDING = "+RECEP+++EDIFACT TRANSFER"; @@ -42,7 +42,10 @@ public static InterchangeHeader fromString(String edifactString) { } String[] split = Split.byPlus(edifactString); - ZonedDateTime translationTime = ZonedDateTime.parse(split[4], DateTimeFormatter.ofPattern("yyMMdd:HHmm").withZone(TimestampService.UKZone)); + ZonedDateTime translationTime = ZonedDateTime.parse( + split[4], + DateTimeFormatter.ofPattern("yyMMdd:HHmm").withZone(TimestampService.UK_ZONE) + ); return new InterchangeHeader(split[2], split[3], translationTime.toInstant(), Long.valueOf(split[5])); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/InterchangeTrailer.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/InterchangeTrailer.java index e3f19b923..a6d059a4a 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/InterchangeTrailer.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/InterchangeTrailer.java @@ -50,7 +50,7 @@ public void preValidate() throws EdifactValidationException { } public static InterchangeTrailer fromString(String edifactString) { - if(!edifactString.startsWith(InterchangeTrailer.KEY)){ + if (!edifactString.startsWith(InterchangeTrailer.KEY)) { throw new IllegalArgumentException("Can't create " + InterchangeTrailer.class.getSimpleName() + " from " + edifactString); } String[] split = Split.byPlus( diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/MessageHeader.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/MessageHeader.java index 874d01da4..70b73bbdb 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/MessageHeader.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/MessageHeader.java @@ -28,7 +28,7 @@ public String getKey() { @Override public String getValue() { String formattedSequenceNumber = String.format("%08d", sequenceNumber); - return formattedSequenceNumber+"+FHSREG:0:1:FH:FHS001"; + return formattedSequenceNumber + "+FHSREG:0:1:FH:FHS001"; } @Override @@ -47,7 +47,7 @@ public void preValidate() { } public static MessageHeader fromString(String edifactString) { - if(!edifactString.startsWith(MessageHeader.KEY)){ + if (!edifactString.startsWith(MessageHeader.KEY)) { throw new IllegalArgumentException("Can't create " + MessageHeader.class.getSimpleName() + " from " + edifactString); } String[] split = Split.byPlus(edifactString); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/MessageTrailer.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/MessageTrailer.java index 484404dea..f376b662d 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/MessageTrailer.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/MessageTrailer.java @@ -13,7 +13,7 @@ * example: UNT+18+00000003' */ @Getter @Setter @RequiredArgsConstructor -public class MessageTrailer extends Segment{ +public class MessageTrailer extends Segment { public static final String KEY = "UNT"; private @NonNull Integer numberOfSegments; @@ -35,10 +35,10 @@ protected void validateStateful() throws EdifactValidationException { if (sequenceNumber == null) { throw new EdifactValidationException(getKey() + ": Attribute sequenceNumber is required"); } - if (sequenceNumber <= 0){ + if (sequenceNumber <= 0) { throw new EdifactValidationException(getKey() + ": Attribute sequenceNumber must be greater than or equal to zero"); } - if (numberOfSegments <= 1){ + if (numberOfSegments <= 1) { throw new EdifactValidationException(getKey() + ": Attribute numberOfSegments must be greater than or equal to 2"); } } @@ -49,7 +49,7 @@ public void preValidate() throws EdifactValidationException { } public static MessageTrailer fromString(String edifactString) { - if(!edifactString.startsWith(MessageTrailer.KEY)){ + if (!edifactString.startsWith(MessageTrailer.KEY)) { throw new IllegalArgumentException("Can't create " + MessageTrailer.class.getSimpleName() + " from " + edifactString); } String[] split = Split.byPlus( diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PartyQualifier.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PartyQualifier.java index 1b3f6fc3b..d5733c7b3 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PartyQualifier.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PartyQualifier.java @@ -12,9 +12,9 @@ @Builder @Data public class PartyQualifier extends Segment { - private final static String KEY = "NAD"; - private final static String CODE = "FHS"; - private final static String REGISTRATION_ID = ":954"; + private static final String KEY = "NAD"; + private static final String CODE = "FHS"; + private static final String REGISTRATION_ID = ":954"; //NAD+FHS+XX1:954' private @NonNull String organization; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonAddress.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonAddress.java index dc99025fa..1a757c8ec 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonAddress.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonAddress.java @@ -19,10 +19,10 @@ @Builder @Data public class PersonAddress extends Segment { - private final static String KEY = "NAD"; - private final static String QUALIFIER = "PAT"; - public final static String KEY_QUALIFIER = KEY + PLUS_SEPARATOR + QUALIFIER; - private final static int POSTAL_CODE_OFFSET = 5; + private static final String KEY = "NAD"; + private static final String QUALIFIER = "PAT"; + public static final String KEY_QUALIFIER = KEY + PLUS_SEPARATOR + QUALIFIER; + private static final int POSTAL_CODE_OFFSET = 5; private static final String EMPTY_FIRST_ADDRESS_LINE_PLACEHOLDER = "??"; private String addressLine1; private String addressLine2; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfBirth.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfBirth.java index 0c9aee300..5f1b93033 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfBirth.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfBirth.java @@ -16,11 +16,11 @@ @Data public class PersonDateOfBirth extends Segment { //DTM+329:19911106:102' - private final static String KEY = "DTM"; - private final static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(TimestampService.UKZone); - private final static String QUALIFIER = "329"; - public final static String KEY_QUALIFIER = KEY + PLUS_SEPARATOR + QUALIFIER; - private final static String DATE_FORMAT = "102"; + private static final String KEY = "DTM"; + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(TimestampService.UK_ZONE); + private static final String QUALIFIER = "329"; + public static final String KEY_QUALIFIER = KEY + PLUS_SEPARATOR + QUALIFIER; + private static final String DATE_FORMAT = "102"; private @NonNull LocalDate dateOfBirth; public static PersonDateOfBirth fromString(String edifactString) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfEntry.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfEntry.java index a83dd290b..e9f980709 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfEntry.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfEntry.java @@ -15,10 +15,10 @@ @RequiredArgsConstructor public class PersonDateOfEntry extends Segment { - private final static String KEY = "DTM"; - private final static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(TimestampService.UKZone); - private final static String QUALIFIER = "957"; - private final static String DATE_FORMAT = "102"; + private static final String KEY = "DTM"; + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(TimestampService.UK_ZONE); + private static final String QUALIFIER = "957"; + private static final String DATE_FORMAT = "102"; private final @NonNull LocalDate dateOfEntry; @Override diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfExit.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfExit.java index a567612c6..6e5a5ff28 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfExit.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonDateOfExit.java @@ -15,10 +15,10 @@ @RequiredArgsConstructor public class PersonDateOfExit extends Segment { - private final static String KEY = "DTM"; - private final static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(TimestampService.UKZone); - private final static String QUALIFIER = "958"; - private final static String DATE_FORMAT = "102"; + private static final String KEY = "DTM"; + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(TimestampService.UK_ZONE); + private static final String QUALIFIER = "958"; + private static final String DATE_FORMAT = "102"; private final @NonNull LocalDate dateOfExit; @Override diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonOldAddress.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonOldAddress.java index e47f4d55f..91e97c3b8 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonOldAddress.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonOldAddress.java @@ -6,7 +6,6 @@ import org.apache.commons.lang3.StringUtils; import uk.nhs.digital.nhsconnect.nhais.model.edifact.message.EdifactValidationException; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -18,8 +17,8 @@ @Builder @Data public class PersonOldAddress extends Segment { - private final static String KEY = "NAD"; - private final static String PAT_CODE = "PER"; + private static final String KEY = "NAD"; + private static final String PAT_CODE = "PER"; private String addressLine1; private String addressLine2; private String addressLine3; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonPlaceOfBirth.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonPlaceOfBirth.java index f7c2e99bb..39a437d06 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonPlaceOfBirth.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonPlaceOfBirth.java @@ -22,9 +22,9 @@ public String getKey() { @Override public String getValue() { - return QUALIFIER + - PLUS_SEPARATOR + - location; + return QUALIFIER + + PLUS_SEPARATOR + + location; } @Override diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonSex.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonSex.java index 968abdec7..4998221fa 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonSex.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PersonSex.java @@ -18,7 +18,7 @@ @Builder @Data public class PersonSex extends Segment { - public final static String KEY = "PDI"; + public static final String KEY = "PDI"; //PDI+1' private @NonNull Gender gender; @@ -48,7 +48,7 @@ public static PersonSex fromString(String edifactString) { if (!edifactString.startsWith(PersonSex.KEY)) { throw new IllegalArgumentException("Can't create " + PersonSex.class.getSimpleName() + " from " + edifactString); } - String[] components = StringUtils.split(edifactString,PLUS_SEPARATOR); + String[] components = StringUtils.split(edifactString, PLUS_SEPARATOR); return PersonSex.builder() .gender(Gender.fromCode(components[1])) .build(); @@ -60,14 +60,14 @@ public enum Gender { FEMALE("2"), OTHER("9"); - private final static Map FROM_FHIR_MAP = ImmutableMap.of( + private static final Map FROM_FHIR_MAP = ImmutableMap.of( Enumerations.AdministrativeGender.UNKNOWN, Gender.UNKNOWN, Enumerations.AdministrativeGender.MALE, Gender.MALE, Enumerations.AdministrativeGender.FEMALE, Gender.FEMALE, Enumerations.AdministrativeGender.OTHER, Gender.OTHER ); - private final static Map To_FHIR_MAP = ImmutableMap.of( + private static final Map TO_FHIR_MAP = ImmutableMap.of( Gender.UNKNOWN, Enumerations.AdministrativeGender.UNKNOWN, Gender.MALE, Enumerations.AdministrativeGender.MALE, Gender.FEMALE, Enumerations.AdministrativeGender.FEMALE, @@ -100,7 +100,7 @@ public static Gender fromFhir(Enumerations.AdministrativeGender fhirGender) { } public static Enumerations.AdministrativeGender toFhir(Gender gender) { - return To_FHIR_MAP.get(gender); + return TO_FHIR_MAP.get(gender); } public String getName() { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PreviousGpName.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PreviousGpName.java index 1a33dd41e..c65b64d73 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PreviousGpName.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/PreviousGpName.java @@ -25,11 +25,11 @@ public String getKey() { @Override public String getValue() { - return PREVIOUS_GP_QUALIFIER + - PLUS_SEPARATOR + - PLUS_SEPARATOR + - PLUS_SEPARATOR + - partyName; + return PREVIOUS_GP_QUALIFIER + + PLUS_SEPARATOR + + PLUS_SEPARATOR + + PLUS_SEPARATOR + + partyName; } @Override diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepBeginningOfMessage.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepBeginningOfMessage.java index e60683fd0..017eee458 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepBeginningOfMessage.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepBeginningOfMessage.java @@ -15,9 +15,9 @@ @RequiredArgsConstructor @NoArgsConstructor public class RecepBeginningOfMessage extends Segment { - private final static String DATE_TIME_FORMAT = "yyyyMMddHHmm"; - private final static String BGM_PREFIX = "+600+243:"; - private final static String BGM_SUFFIX = ":306+64"; + private static final String DATE_TIME_FORMAT = "yyyyMMddHHmm"; + private static final String BGM_PREFIX = "+600+243:"; + private static final String BGM_SUFFIX = ":306+64"; private @NonNull Instant timestamp; @@ -44,6 +44,6 @@ public void preValidate() { } private DateTimeFormatter getDateTimeFormat() { - return DateTimeFormatter.ofPattern(DATE_TIME_FORMAT).withZone(TimestampService.UKZone); + return DateTimeFormatter.ofPattern(DATE_TIME_FORMAT).withZone(TimestampService.UK_ZONE); } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepMessageDateTime.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepMessageDateTime.java index dafa2dc6a..cc5365d37 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepMessageDateTime.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepMessageDateTime.java @@ -34,7 +34,7 @@ public class RecepMessageDateTime extends Segment { public static final String KEY_QUALIFIER = KEY + "+" + TYPE_CODE; private static final String FORMAT_CODE = "306"; private static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmm") - .withZone(TimestampService.UKZone); + .withZone(TimestampService.UK_ZONE); /** * When creating a new RecepTimestamp the timestamp is not provided. This is considered "stateful" and a value * that is shared across multiple segments. For outbound registration messages the RecepProducerService sets this diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepNationalHealthBody.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepNationalHealthBody.java index 29e637e6e..f967f3d91 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepNationalHealthBody.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RecepNationalHealthBody.java @@ -13,7 +13,7 @@ @Setter @RequiredArgsConstructor public class RecepNationalHealthBody extends Segment { - private final static String KEY = "NHS"; + private static final String KEY = "NHS"; //example: NHS+FHS:819:201+4826940:814:202' private @NonNull String cipher; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceInterchangeRecep.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceInterchangeRecep.java index e145bedb3..e5cbdd001 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceInterchangeRecep.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceInterchangeRecep.java @@ -54,7 +54,12 @@ public void preValidate() throws EdifactValidationException { public static ReferenceInterchangeRecep fromString(String edifactString) { if (!edifactString.startsWith(KEY_QUALIFIER)) { - throw new IllegalArgumentException("Can't create " + ReferenceInterchangeRecep.class.getSimpleName() + " from " + edifactString); + throw new IllegalArgumentException( + "Can't create " + + ReferenceInterchangeRecep.class.getSimpleName() + + " from " + + edifactString + ); } String[] keySplit = Split.byPlus(edifactString); String[] sequenceWithCodeAndCount = Split.byColon(keySplit[1]); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceMessageRecep.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceMessageRecep.java index e925ad275..13540e673 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceMessageRecep.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceMessageRecep.java @@ -49,7 +49,7 @@ public void preValidate() throws EdifactValidationException { } public static ReferenceMessageRecep fromString(String edifactString) { - if(!edifactString.startsWith(KEY_QUALIFIER)){ + if (!edifactString.startsWith(KEY_QUALIFIER)) { throw new IllegalArgumentException("Can't create " + ReferenceMessageRecep.class.getSimpleName() + " from " + edifactString); } String values = Split.byColon( diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceTransactionNumber.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceTransactionNumber.java index 8b2e32553..a6d22fa5b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceTransactionNumber.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ReferenceTransactionNumber.java @@ -46,8 +46,13 @@ protected void validateStateful() throws EdifactValidationException { } public static ReferenceTransactionNumber fromString(String edifactString) { - if(!edifactString.startsWith(ReferenceTransactionNumber.KEY_QUALIFIER)){ - throw new IllegalArgumentException("Can't create " + ReferenceTransactionNumber.class.getSimpleName() + " from " + edifactString); + if (!edifactString.startsWith(ReferenceTransactionNumber.KEY_QUALIFIER)) { + throw new IllegalArgumentException( + "Can't create " + + ReferenceTransactionNumber.class.getSimpleName() + + " from " + + edifactString + ); } String[] split = Split.byColon(edifactString); return new ReferenceTransactionNumber(Long.valueOf(split[1])); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RegistrationMessageDateTime.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RegistrationMessageDateTime.java index 2066a4118..ccb6e6588 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RegistrationMessageDateTime.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/RegistrationMessageDateTime.java @@ -34,7 +34,7 @@ public class RegistrationMessageDateTime extends Segment { public static final String KEY_QUALIFIER = KEY + "+" + TYPE_CODE; private static final String FORMAT_CODE = "203"; private static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmm") - .withZone(TimestampService.UKZone); + .withZone(TimestampService.UK_ZONE); /** * When creating a new RegistrationTimestamp the timestamp is not provided. This is considered "stateful" and a * value thas is shared across multiple segments. The FhirToEdifactService sets this value as a pre-precessing step @@ -44,7 +44,12 @@ public class RegistrationMessageDateTime extends Segment { public static RegistrationMessageDateTime fromString(String edifactString) { if (!edifactString.startsWith(KEY_QUALIFIER)) { - throw new IllegalArgumentException("Can't create " + RegistrationMessageDateTime.class.getSimpleName() + " from " + edifactString); + throw new IllegalArgumentException( + "Can't create " + + RegistrationMessageDateTime.class.getSimpleName() + + " from " + + edifactString + ); } String timestamp = Split.byColon(edifactString)[1]; Instant instant = ZonedDateTime.parse(timestamp, DATE_TIME_FORMAT).toInstant(); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ResidentialInstituteNameAndAddress.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ResidentialInstituteNameAndAddress.java index 99fa5b298..7c4984246 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ResidentialInstituteNameAndAddress.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/ResidentialInstituteNameAndAddress.java @@ -50,7 +50,12 @@ public void preValidate() throws EdifactValidationException { public static ResidentialInstituteNameAndAddress fromString(String edifactString) { if (!edifactString.startsWith(ResidentialInstituteNameAndAddress.KEY_QUALIFIER)) { - throw new IllegalArgumentException("Can't create " + ResidentialInstituteNameAndAddress.class.getSimpleName() + " from " + edifactString); + throw new IllegalArgumentException( + "Can't create " + + ResidentialInstituteNameAndAddress.class.getSimpleName() + + " from " + + edifactString + ); } String[] components = Split.byPlus(edifactString); String code = Split.byColon(components[2])[0]; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/Segment.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/Segment.java index fcd553856..6b162e53c 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/Segment.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/Segment.java @@ -9,7 +9,7 @@ public abstract class Segment { protected static final String PLUS_SEPARATOR = "+"; - protected final static String COLON_SEPARATOR = ":"; + protected static final String COLON_SEPARATOR = ":"; private static final String TERMINATOR = "'"; protected static List removeEmptyTrailingFields(List list, Predicate predicate) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/message/EdifactValidationException.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/message/EdifactValidationException.java index f5383034c..1de441df4 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/message/EdifactValidationException.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/edifact/message/EdifactValidationException.java @@ -1,8 +1,7 @@ package uk.nhs.digital.nhsconnect.nhais.model.edifact.message; public class EdifactValidationException extends ToEdifactParsingException { - public EdifactValidationException(String message) - { + public EdifactValidationException(String message) { super(message); } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/BirthPlaceExtension.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/BirthPlaceExtension.java index 94ea84780..83ee8bf59 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/BirthPlaceExtension.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/BirthPlaceExtension.java @@ -5,7 +5,7 @@ import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.StringType; -@DatatypeDef(name="Extension") +@DatatypeDef(name = "Extension") public class BirthPlaceExtension extends Extension { public static final String URL = "http://hl7.org/fhir/StructureDefinition/patient-birthPlace"; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/DrugsMarkerExtension.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/DrugsMarkerExtension.java index 459e35ee4..073652ae2 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/DrugsMarkerExtension.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/DrugsMarkerExtension.java @@ -4,7 +4,7 @@ import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.StringType; -@DatatypeDef(name="Extension") +@DatatypeDef(name = "Extension") public class DrugsMarkerExtension extends Extension { public static final String URL = "https://fhir.nhs.uk/R4/StructureDefinition/Extension-UKCore-NHAIS-DrugsDispensedMarker"; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/NhsIdentifier.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/NhsIdentifier.java index ed67a2e4e..7ed9d427b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/NhsIdentifier.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/NhsIdentifier.java @@ -4,7 +4,7 @@ import org.hl7.fhir.r4.model.Identifier; -@DatatypeDef(name="Identifier") +@DatatypeDef(name = "Identifier") public class NhsIdentifier extends Identifier { public static final String SYSTEM = "https://fhir.nhs.uk/Id/nhs-number"; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ParameterNames.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ParameterNames.java index a70c2b7cf..c9fbc9326 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ParameterNames.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ParameterNames.java @@ -1,7 +1,7 @@ package uk.nhs.digital.nhsconnect.nhais.model.fhir; public final class ParameterNames { - public final static String ACCEPTANCE_CODE = "acceptanceCode"; + public static final String ACCEPTANCE_CODE = "acceptanceCode"; public static final String ACCEPTANCE_TYPE = "acceptanceType"; public static final String ACCEPTANCE_DATE = "acceptanceDate"; public static final String ENTRY_DATE = "dateOfUkEntry"; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ParametersExtension.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ParametersExtension.java index 45be7c2d9..5c4f8657c 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ParametersExtension.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ParametersExtension.java @@ -60,7 +60,15 @@ public T extractResource(String name, Class clazz) { .map(Parameters.ParametersParameterComponent::getResource) .map(clazz::cast) .findFirst() - .orElseThrow(() -> new FhirValidationException("Resource " + clazz.getSimpleName() + " with name " + name + " is missing in FHIR Parameters")); + .orElseThrow( + () -> new FhirValidationException( + "Resource " + + clazz.getSimpleName() + + " with name " + + name + + " is missing in FHIR Parameters" + ) + ); } public static String extractValue(Parameters parameters, String name) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/PatientName.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/PatientName.java index 8604f199c..a9c1cc7d3 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/PatientName.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/PatientName.java @@ -10,7 +10,7 @@ import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.model.StringType; -@DatatypeDef(name="HumanName") +@DatatypeDef(name = "HumanName") @Builder public class PatientName extends HumanName { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ResidentialInstituteExtension.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ResidentialInstituteExtension.java index b1eace66e..e43633db2 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ResidentialInstituteExtension.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/fhir/ResidentialInstituteExtension.java @@ -5,7 +5,7 @@ import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.StringType; -@DatatypeDef(name="Extension") +@DatatypeDef(name = "Extension") public class ResidentialInstituteExtension extends Extension { public static final String URL = "https://fhir.nhs.uk/R4/StructureDefinition/Extension-UKCore-NHAIS-ResidentialInstituteCode"; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentBooleanExtension.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentBooleanExtension.java index 515cce63b..b97c1dffc 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentBooleanExtension.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentBooleanExtension.java @@ -1,7 +1,6 @@ package uk.nhs.digital.nhsconnect.nhais.model.jsonpatch; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; import uk.nhs.digital.nhsconnect.nhais.model.fhir.DrugsMarkerExtension; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentPatch.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentPatch.java index 29564da3c..e35fe29b7 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentPatch.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentPatch.java @@ -30,8 +30,7 @@ public class AmendmentPatch { public Object getValue() { if (this.isExtension()) { return value; - } - else if (value != null) { + } else if (value != null) { return value.get(); } else { return null; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentSimpleValue.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentSimpleValue.java index b005c2f0e..487c6c144 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentSimpleValue.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentSimpleValue.java @@ -9,7 +9,7 @@ @Setter @ToString @RequiredArgsConstructor -public class AmendmentSimpleValue implements AmendmentValue{ +public class AmendmentSimpleValue implements AmendmentValue { private final String value; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentValue.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentValue.java index 2382f3284..f2a7cb39e 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentValue.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/model/jsonpatch/AmendmentValue.java @@ -12,13 +12,13 @@ public interface AmendmentValue { String get(); @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - static AmendmentValue from(String input){ + static AmendmentValue from(String input) { return new AmendmentSimpleValue(input); } @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) static AmendmentValue from(@JsonProperty(value = "url") String url, @JsonProperty(value = "valueBoolean") boolean valueBoolean, - @JsonProperty(value = "valueString") String valueString){ + @JsonProperty(value = "valueString") String valueString) { switch (url) { case DrugsMarkerExtension.URL: return new AmendmentBooleanExtension.DrugsDispensedMarker(valueBoolean); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/AbstractToEdifactService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/AbstractToEdifactService.java index f91e3695c..cfa5efbf3 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/AbstractToEdifactService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/AbstractToEdifactService.java @@ -64,7 +64,13 @@ protected void generateTimestamp(T translationItems) { protected void createSegments(T translationItems) throws FhirValidationException { var segments = new ArrayList(); - segments.add(new InterchangeHeader(translationItems.getSender(), translationItems.getRecipient(), translationItems.getTranslationTimestamp())); + segments.add( + new InterchangeHeader( + translationItems.getSender(), + translationItems.getRecipient(), + translationItems.getTranslationTimestamp() + ) + ); segments.add(new MessageHeader()); List messageSegments = createMessageSegments(translationItems); segments.addAll(messageSegments); @@ -88,12 +94,20 @@ protected void generateSequenceNumbers(T translationItems) { sequenceService.generateMessageSequence(translationItems.getSender(), translationItems.getRecipient())); translationItems.setTransactionNumber( sequenceService.generateTransactionNumber(translationItems.getSender())); - LOGGER.info("Generated sequence numbers SIS={} SMS={} TN={} for sender={} and recipient={}", translationItems.getSendInterchangeSequence(), - translationItems.getSendMessageSequence(), translationItems.getTransactionNumber(), translationItems.getSender(), translationItems.getRecipient()); + LOGGER.info( + "Generated sequence numbers SIS={} SMS={} TN={} for sender={} and recipient={}", + translationItems.getSendInterchangeSequence(), + translationItems.getSendMessageSequence(), + translationItems.getTransactionNumber(), + translationItems.getSender(), + translationItems.getRecipient() + ); } protected void setOperationId(T translationItems) { - translationItems.setOperationId(OperationId.buildOperationId(translationItems.getSender(), translationItems.getTransactionNumber())); + translationItems.setOperationId( + OperationId.buildOperationId(translationItems.getSender(), translationItems.getTransactionNumber()) + ); } protected void recordOutboundState(T translationItems) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/FhirValidationException.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/FhirValidationException.java index 5817bd2f8..1bad7b782 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/FhirValidationException.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/FhirValidationException.java @@ -26,10 +26,10 @@ public OperationOutcome.IssueType getIssueType() { private static String createMessage(ValidationResult validationResult) { int numberOfMessages = validationResult.getMessages().size(); StringBuilder b = new StringBuilder("JSON FHIR Resource failed validation"); - if(numberOfMessages >= 1) { + if (numberOfMessages >= 1) { b.append(": ").append(validationResult.getMessages().get(0).getMessage()); } - if(numberOfMessages >= 2) { + if (numberOfMessages >= 2) { b.append(" (and ").append(numberOfMessages - 1).append(" more error messages truncated)"); } return b.toString(); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/OutboundQueueService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/OutboundQueueService.java index 2b9b98f24..ef7d1a5d8 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/OutboundQueueService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/OutboundQueueService.java @@ -36,8 +36,12 @@ public class OutboundQueueService { @SneakyThrows public void publish(OutboundMeshMessage messageContent) { - LOGGER.info("Publishing message to MESH outbound queue for asynchronous sending to MESH API OperationId={} recipient={} workflow={}", - messageContent.getOperationId(), messageContent.getHaTradingPartnerCode(), messageContent.getWorkflowId()); + LOGGER.info( + "Publishing message to MESH outbound queue for asynchronous sending to MESH API OperationId={} recipient={} workflow={}", + messageContent.getOperationId(), + messageContent.getHaTradingPartnerCode(), + messageContent.getWorkflowId() + ); LOGGER.debug("Publishing message content to outbound mesh queue: {}", messageContent); messageContent.setMessageSentTimestamp(timestampService.formatInISO(timestampService.getCurrentTimestamp())); jmsTemplate.send(meshOutboundQueueName, session -> { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirController.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirController.java index 408f17ff3..2458a2147 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirController.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirController.java @@ -35,7 +35,9 @@ public class FhirController { @PostMapping(path = "/fhir/Patient/{transactionTypeParam}", consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.ACCEPTED) - public ResponseEntity fromFhirToEdifact(@PathVariable String transactionTypeParam, @RequestBody String body) throws FhirValidationException { + public ResponseEntity fromFhirToEdifact(@PathVariable String transactionTypeParam, @RequestBody String body) + throws FhirValidationException { + LOGGER.info("Handling a request for Patient operation {}", transactionTypeParam); Parameters parameters = fhirParser.parseParameters(body); ReferenceTransactionType.Outbound transactionType = new TransactionTypeMapper().mapTransactionType(transactionTypeParam); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirToEdifactService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirToEdifactService.java index 72edaaf3d..afc1bef78 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirToEdifactService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirToEdifactService.java @@ -41,7 +41,9 @@ public FhirToEdifactService(OutboundStateRepository outboundStateRepository, this.fhirToEdifactSegmentTranslator = fhirToEdifactSegmentTranslator; } - public OutboundMeshMessage convertToEdifact(Parameters parameters, ReferenceTransactionType.Outbound transactionType) throws FhirValidationException, EdifactValidationException { + public OutboundMeshMessage convertToEdifact(Parameters parameters, ReferenceTransactionType.Outbound transactionType) + throws FhirValidationException, EdifactValidationException { + FhirTranslationItems translationItems = new TranslationItems(); translationItems.setParameters(parameters); translationItems.setSender(getSenderTradingPartnerCode(translationItems.getParameters())); @@ -69,7 +71,9 @@ private String getOrganizationIdentifier(Reference reference) throws FhirValidat @Override protected List createMessageSegments(FhirTranslationItems translationItems) throws FhirValidationException { - return fhirToEdifactSegmentTranslator.createMessageSegments(translationItems.getParameters(), translationItems.getTransactionType()); + return fhirToEdifactSegmentTranslator.createMessageSegments( + translationItems.getParameters(), + translationItems.getTransactionType() + ); } - } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/jsonpatch/AmendmentController.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/jsonpatch/AmendmentController.java index 4e9e5a8fb..7c9f6f623 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/jsonpatch/AmendmentController.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/jsonpatch/AmendmentController.java @@ -85,7 +85,9 @@ private void validateDuplicatedPaths(List patches) { .collect(Collectors.toSet()); if (patchesWithoutExtensions.size() != amendmentPaths.size()) { - throw new AmendmentValidationException("Request contains path that is used multiple times. Each patch path must only be used once within the amendment request"); + throw new AmendmentValidationException( + "Request contains path that is used multiple times." + + "Each patch path must only be used once within the amendment request"); } } @@ -100,7 +102,10 @@ private void validateDuplicatedExtensions(List patches) { .filter(AmendmentPatch::isExtension) .collect(Collectors.toList()); if (allExtensionPatches.size() != extensionTypes.size()) { - throw new AmendmentValidationException("Request contains extension that is used multiple times. Each extension patch must only be used once within the amendment request"); + throw new AmendmentValidationException( + "Request contains extension that is used multiple times. " + + "Each extension patch must only be used once within the amendment request" + ); } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/jsonpatch/AmendmentValidationException.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/jsonpatch/AmendmentValidationException.java index 4492f810e..f45cf6f5c 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/jsonpatch/AmendmentValidationException.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/jsonpatch/AmendmentValidationException.java @@ -4,7 +4,7 @@ class AmendmentValidationException extends BadRequestException { - public AmendmentValidationException(String message) { + AmendmentValidationException(String message) { super(message); } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/DrugsMarkerMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/DrugsMarkerMapper.java index 60059854f..2d3ab86ca 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/DrugsMarkerMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/DrugsMarkerMapper.java @@ -9,8 +9,8 @@ @Component public class DrugsMarkerMapper implements OptionalFromFhirToEdifactMapper { - private final String AFFIRMATIVE_VALUE = "true"; - private final String NEGATIVE_VALUE = "false"; + private static final String AFFIRMATIVE_VALUE = "true"; + private static final String NEGATIVE_VALUE = "false"; public DrugsMarker map(Parameters parameters) { String markerValue = ParametersExtension.extractExtensionValue(parameters, DrugsMarkerExtension.URL) diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/FromFhirToEdifactMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/FromFhirToEdifactMapper.java index 75ed2adfe..36bd691cb 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/FromFhirToEdifactMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/FromFhirToEdifactMapper.java @@ -19,7 +19,11 @@ static FromFhirToEdifactMapper optional(OptionalFromFhirToEdifactMapper ma return new SkipMapper(); } - static FromFhirToEdifactMapper optionalGroup(Segment startSegment, Collection> mappers, Parameters parameters) { + static FromFhirToEdifactMapper optionalGroup( + Segment startSegment, + Collection> mappers, + Parameters parameters + ) { List> mappableSegments = mappers .stream() .filter(mapper -> mapper.inputDataExists(parameters)) diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/GpNameAndAddressMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/GpNameAndAddressMapper.java index bbe7c35b7..a70206daf 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/GpNameAndAddressMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/GpNameAndAddressMapper.java @@ -10,7 +10,7 @@ @Component public class GpNameAndAddressMapper implements FromFhirToEdifactMapper { - private final static String GP_CODE = "900"; + private static final String GP_CODE = "900"; public GpNameAndAddress map(Parameters parameters) { Patient patient = ParametersExtension.extractPatient(parameters); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/OptionalFromFhirToEdifactMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/OptionalFromFhirToEdifactMapper.java index 4075c9d05..5ea600fcf 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/OptionalFromFhirToEdifactMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/OptionalFromFhirToEdifactMapper.java @@ -3,7 +3,7 @@ import org.hl7.fhir.r4.model.Parameters; import uk.nhs.digital.nhsconnect.nhais.model.edifact.Segment; -public interface OptionalFromFhirToEdifactMapper extends FromFhirToEdifactMapper{ +public interface OptionalFromFhirToEdifactMapper extends FromFhirToEdifactMapper { boolean inputDataExists(Parameters parameters); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/TransactionTypeMapper.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/TransactionTypeMapper.java index e90ef3d2c..7a51acc6e 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/TransactionTypeMapper.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/mapper/TransactionTypeMapper.java @@ -9,7 +9,7 @@ public class TransactionTypeMapper { public ReferenceTransactionType.Outbound mapTransactionType(String transactionTypeParam) { - switch(transactionTypeParam) { + switch (transactionTypeParam) { case "$nhais.acceptance": return ReferenceTransactionType.Outbound.ACCEPTANCE; case "$nhais.removal": return ReferenceTransactionType.Outbound.REMOVAL; case "$nhais.deduction": return ReferenceTransactionType.Outbound.DEDUCTION; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/FhirToEdifactSegmentTranslator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/FhirToEdifactSegmentTranslator.java index 526c7cb3a..1ab780164 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/FhirToEdifactSegmentTranslator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/FhirToEdifactSegmentTranslator.java @@ -31,7 +31,9 @@ public class FhirToEdifactSegmentTranslator { private final DeductionTranslator deductionTranslator; private final RemovalTranslator removalTranslator; - public List createMessageSegments(Parameters parameters, ReferenceTransactionType.TransactionType transactionType) throws FhirValidationException { + public List createMessageSegments(Parameters parameters, ReferenceTransactionType.TransactionType transactionType) + throws FhirValidationException { + switch ((ReferenceTransactionType.Outbound) transactionType) { case ACCEPTANCE: return delegateAcceptance(parameters); diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceFirstTranslator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceFirstTranslator.java index 2cea100ee..a373e6e87 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceFirstTranslator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceFirstTranslator.java @@ -60,7 +60,7 @@ public class AcceptanceFirstTranslator implements FhirToEdifactTranslator { public List translate(Parameters parameters) throws FhirValidationException { boolean nhsNumberIsMissing = validator.nhsNumberIsMissing(parameters); boolean placeOfBirthIsMissing = validator.placeOfBirthIsMissing(parameters); - if(nhsNumberIsMissing && placeOfBirthIsMissing) { + if (nhsNumberIsMissing && placeOfBirthIsMissing) { throw new FhirValidationException("Place of birth is mandatory when NHS number is missing"); } if (validator.surnameIsMissing(parameters)) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceImmigrantTranslator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceImmigrantTranslator.java index 12a25bf89..0c379509a 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceImmigrantTranslator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceImmigrantTranslator.java @@ -70,7 +70,7 @@ public class AcceptanceImmigrantTranslator implements FhirToEdifactTranslator { public List translate(Parameters parameters) throws FhirValidationException { boolean nhsNumberIsMissing = validator.nhsNumberIsMissing(parameters); boolean placeOfBirthIsMissing = validator.placeOfBirthIsMissing(parameters); - if(nhsNumberIsMissing && placeOfBirthIsMissing) { + if (nhsNumberIsMissing && placeOfBirthIsMissing) { throw new FhirValidationException("Place of birth is mandatory when NHS number is missing"); } if (validator.surnameIsMissing(parameters)) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceTransferInTranslator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceTransferInTranslator.java index 272e782ea..2c500bef7 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceTransferInTranslator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/acceptance/AcceptanceTransferInTranslator.java @@ -66,7 +66,7 @@ public class AcceptanceTransferInTranslator implements FhirToEdifactTranslator { public List translate(Parameters parameters) throws FhirValidationException { boolean nhsNumberIsMissing = validator.nhsNumberIsMissing(parameters); boolean placeOfBirthIsMissing = validator.placeOfBirthIsMissing(parameters); - if(nhsNumberIsMissing && placeOfBirthIsMissing) { + if (nhsNumberIsMissing && placeOfBirthIsMissing) { throw new FhirValidationException("Place of birth is mandatory when NHS number is missing"); } if (validator.surnameIsMissing(parameters)) { diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/deduction/DeductionTranslator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/deduction/DeductionTranslator.java index 259890c87..5250986f0 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/deduction/DeductionTranslator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/deduction/DeductionTranslator.java @@ -42,7 +42,7 @@ public class DeductionTranslator implements FhirToEdifactTranslator { @Override public List translate(Parameters parameters) throws FhirValidationException { - if(validator.nhsNumberIsMissing(parameters)) { + if (validator.nhsNumberIsMissing(parameters)) { throw new FhirValidationException("Patient resource property /identifier/0/value (NHS Number) is required"); } List segments = Stream.of( diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/removal/RemovalTranslator.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/removal/RemovalTranslator.java index 45306d169..317fe5224 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/removal/RemovalTranslator.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/outbound/translator/removal/RemovalTranslator.java @@ -38,7 +38,11 @@ public class RemovalTranslator implements FhirToEdifactTranslator { @Override public List translate(Parameters parameters) throws FhirValidationException { if (validator.nhsNumberIsMissing(parameters)) { - throw new FhirValidationException("Patient resource property " + PatientJsonPaths.NHS_NUMBER_PATH + " (NHS Number) is required"); + throw new FhirValidationException( + "Patient resource property " + + PatientJsonPaths.NHS_NUMBER_PATH + + " (NHS Number) is required" + ); } return Stream.of( //BGM diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/rest/exception/BadRequestException.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/rest/exception/BadRequestException.java index afaae391a..1fbeb2948 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/rest/exception/BadRequestException.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/rest/exception/BadRequestException.java @@ -25,7 +25,7 @@ public BadRequestException(Throwable cause) { } @Override - final public IBaseOperationOutcome getOperationOutcome() { + public final IBaseOperationOutcome getOperationOutcome() { return operationOutcome; } @@ -34,7 +34,7 @@ public OperationOutcome.IssueType getIssueType() { } @Override - final public HttpStatus getStatusCode() { + public final HttpStatus getStatusCode() { return HttpStatus.BAD_REQUEST; } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceDao.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceDao.java index aa29137a4..546849a0b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceDao.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceDao.java @@ -1,7 +1,6 @@ package uk.nhs.digital.nhsconnect.nhais.sequence; import org.springframework.data.repository.CrudRepository; -import uk.nhs.digital.nhsconnect.nhais.sequence.OutboundSequenceId; public interface SequenceDao extends CrudRepository { } \ No newline at end of file diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceRepository.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceRepository.java index 17f0032f2..963d7963b 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceRepository.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceRepository.java @@ -15,10 +15,10 @@ @Slf4j @Repository public class SequenceRepository { - private final static String KEY = "key"; - private final static String SEQUENCE_NUMBER = "sequenceNumber"; - private final static long MAX_SEQUENCE_NUMBER = 100_000_000L; - private final static long MAX_TRANSACTION_SEQUENCE_NUMBER = 10_000_000L; + private static final String KEY = "key"; + private static final String SEQUENCE_NUMBER = "sequenceNumber"; + private static final long MAX_SEQUENCE_NUMBER = 100_000_000L; + private static final long MAX_TRANSACTION_SEQUENCE_NUMBER = 10_000_000L; @Autowired private MongoOperations mongoOperations; @@ -45,6 +45,6 @@ private Long increment(String key, Long maxSequenceNumber) { new Update().inc(SEQUENCE_NUMBER, 1), options().returnNew(true).upsert(true), OutboundSequenceId.class)) - .getSequenceNumber() % maxSequenceNumber; + .getSequenceNumber() % maxSequenceNumber; } } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceService.java index 1308d2d3c..3a6744b7a 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/sequence/SequenceService.java @@ -6,9 +6,9 @@ @Service public class SequenceService { - private final static String TRANSACTION_KEY_FORMAT = "TN-%s"; - private final static String INTERCHANGE_FORMAT = "SIS-%s-%s"; - private final static String INTERCHANGE_MESSAGE_FORMAT = "SMS-%s-%s"; + private static final String TRANSACTION_KEY_FORMAT = "TN-%s"; + private static final String INTERCHANGE_FORMAT = "SIS-%s-%s"; + private static final String INTERCHANGE_MESSAGE_FORMAT = "SMS-%s-%s"; @Autowired private SequenceRepository sequenceRepository; diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/HttpHeaders.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/HttpHeaders.java index 11ba8064e..94514451d 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/HttpHeaders.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/HttpHeaders.java @@ -1,5 +1,5 @@ package uk.nhs.digital.nhsconnect.nhais.utils; public final class HttpHeaders { - public static String OPERATION_ID = "OperationId"; + public static final String OPERATION_ID = "OperationId"; } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/JmsHeaders.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/JmsHeaders.java index a8d2a2588..d24f59d8d 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/JmsHeaders.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/JmsHeaders.java @@ -1,7 +1,7 @@ package uk.nhs.digital.nhsconnect.nhais.utils; public final class JmsHeaders { - public static String OPERATION_ID = "OperationId"; - public static String TRANSACTION_TYPE = "TransactionType"; - public static String CONVERSATION_ID = "ConversationId"; + public static final String OPERATION_ID = "OperationId"; + public static final String TRANSACTION_TYPE = "TransactionType"; + public static final String CONVERSATION_ID = "ConversationId"; } diff --git a/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/TimestampService.java b/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/TimestampService.java index 90247b3cf..5cbf47654 100644 --- a/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/TimestampService.java +++ b/src/main/java/uk/nhs/digital/nhsconnect/nhais/utils/TimestampService.java @@ -9,7 +9,7 @@ @Component public class TimestampService { - public static final ZoneId UKZone = ZoneId.of("Europe/London"); + public static final ZoneId UK_ZONE = ZoneId.of("Europe/London"); public Instant getCurrentTimestamp() { var now = Instant.now(); @@ -18,7 +18,7 @@ public Instant getCurrentTimestamp() { public String formatInISO(Instant timestamp) { return DateTimeFormatter.ISO_DATE_TIME - .withZone(TimestampService.UKZone) + .withZone(TimestampService.UK_ZONE) .format(timestamp); } } diff --git a/src/recepResponder/java/uk/nhs/digital/nhsconnect/nhais/ResponderNhaisApplication.java b/src/recepResponder/java/uk/nhs/digital/nhsconnect/nhais/ResponderNhaisApplication.java index 11bc8fb5d..e48aa89be 100644 --- a/src/recepResponder/java/uk/nhs/digital/nhsconnect/nhais/ResponderNhaisApplication.java +++ b/src/recepResponder/java/uk/nhs/digital/nhsconnect/nhais/ResponderNhaisApplication.java @@ -12,17 +12,15 @@ @EnableScheduling @SpringBootApplication public class ResponderNhaisApplication { - - public static void main(String[] args) { + public static void main(String[] args) { SpringApplication.run(ResponderNhaisApplication.class, args); } - @Configuration - class Config { - - @Bean - String registrationConsumerService() { + @Configuration + class Config { + @Bean + String registrationConsumerService() { return RecepResponderService.class.getSimpleName(); } - } + } } diff --git a/src/test/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepProducerServiceTest.java b/src/test/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepProducerServiceTest.java index d75da447b..b2665d220 100644 --- a/src/test/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepProducerServiceTest.java +++ b/src/test/java/uk/nhs/digital/nhsconnect/nhais/inbound/RecepProducerServiceTest.java @@ -40,7 +40,7 @@ class RecepProducerServiceTest { private static final Long INTERCHANGE_SEQUENCE = 45L; private static final Long MESSAGE_SEQUENCE_1 = 56L; private static final Instant FIXED_TIME = ZonedDateTime - .of(2020, 4, 27, 17, 37, 0, 0, TimestampService.UKZone) + .of(2020, 4, 27, 17, 37, 0, 0, TimestampService.UK_ZONE) .toInstant(); private static final long RECEP_INTERCHANGE_SEQUENCE = 123123; private static final long RECEP_MESSAGE_SEQUENCE = 234234; diff --git a/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/AuthorizationHashGeneratorTest.java b/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/AuthorizationHashGeneratorTest.java index c7007534e..e93437891 100644 --- a/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/AuthorizationHashGeneratorTest.java +++ b/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/AuthorizationHashGeneratorTest.java @@ -24,7 +24,7 @@ class AuthorizationHashGeneratorTest { private final static String MAILBOX_PASSWORD = "mailbox_password"; private final static String SHARED_KEY = "shared_key"; - private final static Instant FIXED_TIME_LOCAL = ZonedDateTime.of(1991,11,6,12,30,0,0, TimestampService.UKZone) + private final static Instant FIXED_TIME_LOCAL = ZonedDateTime.of(1991,11,6,12,30,0,0, TimestampService.UK_ZONE) .toInstant(); private final static String UUID = "73eefd69-811f-44d0-81f8-a54ff352a991"; diff --git a/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/MeshAuthorizationTokenTest.java b/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/MeshAuthorizationTokenTest.java index 7c04e79b3..601bee4ac 100644 --- a/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/MeshAuthorizationTokenTest.java +++ b/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/MeshAuthorizationTokenTest.java @@ -22,7 +22,7 @@ class MeshAuthorizationTokenTest { private final static String AUTHORIZATION_HASH = "474c0634fd2267e41252bddfb40031d85e433599a8015c74546e95b05c2df569"; private final static String MAILBOX_ID = "mailbox_id"; - private final static Instant FIXED_TIME_LOCAL = ZonedDateTime.of(1991,11,6,12,30,0,0, TimestampService.UKZone) + private final static Instant FIXED_TIME_LOCAL = ZonedDateTime.of(1991,11,6,12,30,0,0, TimestampService.UK_ZONE) .toInstant(); private final static String UUID = "73eefd69-811f-44d0-81f8-a54ff352a991"; diff --git a/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/TokenTimestampTest.java b/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/TokenTimestampTest.java index 39f2e73e1..17b2ed673 100644 --- a/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/TokenTimestampTest.java +++ b/src/test/java/uk/nhs/digital/nhsconnect/nhais/mesh/token/TokenTimestampTest.java @@ -11,7 +11,7 @@ class TokenTimestampTest { - private final static Instant FIXED_TIME_LOCAL = ZonedDateTime.of(1991,11,6,12,30,0,0, TimestampService.UKZone) + private final static Instant FIXED_TIME_LOCAL = ZonedDateTime.of(1991,11,6,12,30,0,0, TimestampService.UK_ZONE) .toInstant(); @Test diff --git a/src/test/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirToEdifactServiceTest.java b/src/test/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirToEdifactServiceTest.java index c88075505..947cf2b07 100644 --- a/src/test/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirToEdifactServiceTest.java +++ b/src/test/java/uk/nhs/digital/nhsconnect/nhais/outbound/fhir/FhirToEdifactServiceTest.java @@ -85,7 +85,7 @@ public void beforeEach() { when(sequenceService.generateInterchangeSequence(GP_TRADING_PARTNER_CODE, HA_TRADING_PARTNER_CODE)).thenReturn(SIS); when(sequenceService.generateTransactionNumber(GP_TRADING_PARTNER_CODE)).thenReturn(TN); expectedTimestamp = ZonedDateTime - .of(2020, 4, 27, 17, 37, 0, 0, TimestampService.UKZone) + .of(2020, 4, 27, 17, 37, 0, 0, TimestampService.UK_ZONE) .toInstant(); when(timestampService.getCurrentTimestamp()).thenReturn(expectedTimestamp); // segments related to state management only