diff --git a/NOTICE b/NOTICE index 76438017b3ddabc7a0a9c3507f0281a96f10031f..b3825be3100afeffddfcd47b206963d86ef9b71e 100644 --- a/NOTICE +++ b/NOTICE @@ -76,7 +76,7 @@ The following software have components provided under the terms of this license: - Apache Log4j JUL Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-jul) - Apache Log4j SLF4J Binding (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl) - Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j) -- AssertJ fluent assertions (from ${project.parent.url}#${project.artifactId}, https://repo1.maven.org/maven2/org/assertj/assertj-core) +- AssertJ Core (from ${project.organization.url}#${project.artifactId}) - Asynchronous Http Client (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client) - Asynchronous Http Client Netty Utils (from https://repo1.maven.org/maven2/org/asynchttpclient/async-http-client-netty-utils) - AutoValue Annotations (from https://github.com/google/auto/tree/master/value, https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations) @@ -321,8 +321,8 @@ The following software have components provided under the terms of this license: - proto-google-cloud-iamcredentials-v1 (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/java-iamcredentials/proto-google-cloud-iamcredentials-v1, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-iamcredentials-v1) - proto-google-cloud-logging-v2 (from https://github.com/googleapis/java-logging/proto-google-cloud-logging-v2, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2) - proto-google-cloud-pubsub-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-pubsub/proto-google-cloud-pubsub-v1) -- proto-google-common-protos (from https://github.com/googleapis/api-client-staging, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-common-protos) -- proto-google-iam-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-iam-v1) +- proto-google-common-protos (from https://github.com/googleapis/api-client-staging, https://github.com/googleapis/gapic-generator-java, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-common-protos) +- proto-google-iam-v1 (from https://github.com/googleapis/gapic-generator-java, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-iam-v1) - resilience4j (from https://github.com/resilience4j/resilience4j, https://resilience4j.readme.io, ttps://resilience4j.readme.io) - spring-boot-starter-undertow (from https://spring.io/projects/spring-boot) - spring-security-crypto (from http://spring.io/spring-security, https://spring.io/projects/spring-security, https://spring.io/spring-security) @@ -353,7 +353,7 @@ BSD-2-Clause ======================================================================== The following software have components provided under the terms of this license: -- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java) +- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java, https://repo1.maven.org/maven2/com/google/api/api-common) - GAX (Google Api eXtensions) for Java (Core) (from https://repo1.maven.org/maven2/com/google/api/gax) - GAX (Google Api eXtensions) for Java (HTTP JSON) (from https://repo1.maven.org/maven2/com/google/api/gax-httpjson) - GAX (Google Api eXtensions) for Java (gRPC) (from https://repo1.maven.org/maven2/com/google/api/gax-grpc) @@ -371,7 +371,7 @@ BSD-3-Clause ======================================================================== The following software have components provided under the terms of this license: -- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java) +- API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java, https://repo1.maven.org/maven2/com/google/api/api-common) - ASM Core (from http://asm.ow2.io/, http://asm.ow2.org/) - AspectJ Weaver (from http://www.aspectj.org, https://www.eclipse.org/aspectj/) - Expression Language 3.0 (from http://el-spec.java.net, http://uel.java.net, https://projects.eclipse.org/projects/ee4j.el) diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/ProcessNotification.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/ProcessNotification.java index 900fd07d9e0acc1afc5dae1fff496ac39181b84c..6a882c419d24ed36ca98a9726c06e9b7ed5d5630 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/ProcessNotification.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/ProcessNotification.java @@ -14,6 +14,7 @@ package org.opengroup.osdu.notification.provider.azure.messageBus; +import com.google.api.client.util.Strings; import com.microsoft.applicationinsights.TelemetryClient; import com.microsoft.applicationinsights.telemetry.RequestTelemetry; import com.microsoft.azure.servicebus.IMessage; @@ -59,13 +60,16 @@ public class ProcessNotification { String dataPartitionId = notificationContent.getExtractAttributes().get(DpsHeaders.DATA_PARTITION_ID); String correlationId = notificationContent.getExtractAttributes().get(DpsHeaders.CORRELATION_ID); - + String collaborationId = null; + if (notificationContent.getExtractAttributes().containsKey("x-collaboration")) + collaborationId = notificationContent.getExtractAttributes().get("x-collaboration"); ConcurrentMap properties = telemetryClient.getContext().getProperties(); properties.put("correlation-id",correlationId); - properties.put("data-partition-id", dataPartitionId); - - MDC.setContextMap(mdcContextMap.getContextMap(correlationId, dataPartitionId)); - dpsHeaders.setThreadContext(dataPartitionId, correlationId); + properties.put("data-partition-id", dataPartitionId); + if (!Strings.isNullOrEmpty(collaborationId)) + properties.put("x-collaboration", collaborationId); + MDC.setContextMap(mdcContextMap.getContextMap(correlationId, dataPartitionId, collaborationId)); + dpsHeaders.setThreadContext(dataPartitionId, correlationId, collaborationId); LOGGER.info("Notification process started for message with id: {}", message.getMessageId()); diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/extractor/ServiceBusRequestBodyExtractor.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/extractor/ServiceBusRequestBodyExtractor.java index 070029c6be6fb7e2f73c50636d0047517fdaf57d..68ec87316d7845604d69149ee630b6b210015852 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/extractor/ServiceBusRequestBodyExtractor.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/extractor/ServiceBusRequestBodyExtractor.java @@ -15,12 +15,15 @@ package org.opengroup.osdu.notification.provider.azure.messageBus.extractor; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import com.google.gson.Gson; import com.microsoft.azure.servicebus.IMessage; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.notification.provider.azure.models.NotificationRecordsChangedData; import org.opengroup.osdu.notification.provider.azure.models.NotificationServiceBusRequest; import org.opengroup.osdu.notification.provider.azure.messageBus.interfaces.IPullRequestBodyExtractor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; @@ -40,7 +43,6 @@ public class ServiceBusRequestBodyExtractor implements IPullRequestBodyExtractor private static final Gson GSON = new Gson(); private NotificationServiceBusRequest notificationRequest; private NotificationRecordsChangedData notificationRecordsChangedData; - public void InitializeExtractor(IMessage message) { this.message = message; @@ -53,6 +55,9 @@ public class ServiceBusRequestBodyExtractor implements IPullRequestBodyExtractor attributes.put("correlation-id", this.notificationRecordsChangedData.getCorrelationId()); attributes.put("data-partition-id", this.notificationRecordsChangedData.getDataPartitionId()); attributes.put("account-id", this.notificationRecordsChangedData.getAccountId()); + if (!Strings.isNullOrEmpty(this.notificationRecordsChangedData.getCollaborationDirectives())) { + attributes.put("x-collaboration", this.notificationRecordsChangedData.getCollaborationDirectives()); + } return attributes; } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeaders.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeaders.java index b02fe38df5244618ca5cd0f9657c571780874598..ece84e176e2f462ca1788d0caeac741812fa28f9 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeaders.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeaders.java @@ -22,6 +22,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Component; +import com.google.api.client.util.Strings; import java.util.HashMap; import java.util.Map; @@ -34,12 +35,14 @@ public class ThreadDpsHeaders extends DpsHeaders { @Autowired private IServiceAccountJwtClient serviceAccountJwtClient; - public void setThreadContext(String dataPartitionId, String correlationId) { + public void setThreadContext(String dataPartitionId, String correlationId, String collaborationId) { Map<String, String> headers = new HashMap<>(); headers.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); headers.put(DpsHeaders.CORRELATION_ID, correlationId); String authToken = this.serviceAccountJwtClient.getIdToken(dataPartitionId); headers.put(DpsHeaders.AUTHORIZATION, authToken); + if (!Strings.isNullOrEmpty(collaborationId)) + headers.put("x-collaboration", collaborationId); this.addFromMap(headers); } diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/models/NotificationRecordsChangedData.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/models/NotificationRecordsChangedData.java index 4d6b9e6c92ab0d23a5a9b843837e043691c07469..0f9b964487573745316d0a068f0367079f9a4a12 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/models/NotificationRecordsChangedData.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/models/NotificationRecordsChangedData.java @@ -39,4 +39,7 @@ public class NotificationRecordsChangedData { @SerializedName("data-partition-id") private String dataPartitionId; + + @SerializedName("x-collaboration") + private String collaborationDirectives; } \ No newline at end of file diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMap.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMap.java index 57c08cb18613784974dc7260041b3a44e693d6d2..82874ec4b59d8368d2814f287da31e4fd516dafb 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMap.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMap.java @@ -14,6 +14,7 @@ package org.opengroup.osdu.notification.provider.azure.util; +import com.google.api.client.util.Strings; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import java.util.HashMap; @@ -21,10 +22,12 @@ import java.util.Map; public class MDCContextMap { - public Map<String, String> getContextMap(String correlationId, String dataPartitionId) { + public Map<String, String> getContextMap(String correlationId, String dataPartitionId, String collaborationId) { final Map<String, String> contextMap = new HashMap<>(); contextMap.put(DpsHeaders.CORRELATION_ID, correlationId); contextMap.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); + if (!Strings.isNullOrEmpty(collaborationId)) + contextMap.put("x-collaboration", collaborationId); return contextMap; } } diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/ProcessNotificationTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/ProcessNotificationTest.java index 789d76697846e64a8bd3b334b258903cc2ed8378..95852d80abb3dbb4b7d8f6b7111b13156cac58d8 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/ProcessNotificationTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/ProcessNotificationTest.java @@ -70,8 +70,8 @@ public class ProcessNotificationTest { public void init() { requestAttributes.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId); requestAttributes.put(DpsHeaders.CORRELATION_ID, correlationId); - lenient().doNothing().when(dpsHeaders).setThreadContext(dataPartitionId, correlationId); - lenient().when(mdcContextMap.getContextMap(dataPartitionId, correlationId)).thenReturn(new HashMap<>()); + lenient().doNothing().when(dpsHeaders).setThreadContext(dataPartitionId, correlationId, null); + lenient().when(mdcContextMap.getContextMap(dataPartitionId, correlationId, null)).thenReturn(new HashMap<>()); lenient().when(dpsHeaders.getHeaders()).thenReturn(requestAttributes); when(notificationContent.getExtractAttributes()).thenReturn(requestAttributes); when(notificationContent.getNotificationId()).thenReturn(notificationId); diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/ServiceBusRequestBodyExtractorTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/ServiceBusRequestBodyExtractorTest.java index 6f9729ecd25dabd2118d8adf33643928587e1c96..13810317a2181737a4c4a97c30a6787d5f044eb5 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/ServiceBusRequestBodyExtractorTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/ServiceBusRequestBodyExtractorTest.java @@ -38,6 +38,7 @@ public class ServiceBusRequestBodyExtractorTest { private static final String dataPartitionId = "opendes"; private static final String correlationId = "908fcf8d-30c5-4c74-a0ae-ab47b48b7a85"; private static final String accountId = "ab47b48b7a85-30c5"; + private static final String collaborationDirectives = "id=9e1c4e74-3b9b-4b17-a0d5-67766558ec65,application=Test App"; @Test public void should_throwWhenAttributesAreMissing_extractDataFromRequestBody() { @@ -65,6 +66,7 @@ public class ServiceBusRequestBodyExtractorTest { Assert.assertEquals(attributes.get("account-id"), accountId); Assert.assertEquals(attributes.get("correlation-id"), correlationId); Assert.assertEquals(attributes.get("data-partition-id"), dataPartitionId); + Assert.assertEquals(attributes.get("x-collaboration"), null); } catch (Exception exception) { fail("Should not Throw AppException"); @@ -72,6 +74,38 @@ public class ServiceBusRequestBodyExtractorTest { } + @Test + public void shouldReturnNotificationDataAndAttributesWhenValidRequestBodyWithCollaborationDirectivesProvided() { + IMessage message = getValidMessageWithCollaborationDirectives(); + try { + sut.InitializeExtractor(message); + String notificationData = sut.extractDataFromRequestBody(); + Assert.assertEquals(notificationData, validData); + Map<String, String> attributes = sut.extractAttributesFromRequestBody(); + Assert.assertEquals(attributes.get("account-id"), accountId); + Assert.assertEquals(attributes.get("correlation-id"), correlationId); + Assert.assertEquals(attributes.get("data-partition-id"), dataPartitionId); + Assert.assertEquals(attributes.get("x-collaboration"), collaborationDirectives); + } catch (Exception exception) { + fail("Should not Throw AppException"); + } + } + + private Message getValidMessageWithCollaborationDirectives() { + String body = + " {\n" + + " \"message\": {\n" + + " \"data\":" + validData + ",\n" + + " \"account-id\": \"" + accountId + "\",\n" + + " \"correlation-id\": \"" + correlationId + "\",\n" + + " \"data-partition-id\": \"" + dataPartitionId + "\",\n" + + " \"x-collaboration\": \"" + collaborationDirectives + "\"\n" + + " }\n" + + " }"; + return new Message(body); + } + + private Message getValidMessage() { String body = diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeadersTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeadersTest.java index 019bd18063d18b46bcb594ca809ba8ee987af5f7..a066b8f5cbc6fc4175f9ea9641b92d7b74653198 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeadersTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/thread/ThreadDpsHeadersTest.java @@ -28,7 +28,7 @@ public class ThreadDpsHeadersTest { @Test public void setThreadContextTest() { try { - threadDpsHeaders.setThreadContext("opendes", "ut"); + threadDpsHeaders.setThreadContext("opendes", "ut", null); assertEquals(threadDpsHeaders.getHeaders().get("data-partition-id"),"opendes"); assertEquals(threadDpsHeaders.getHeaders().get("correlation-id"),"ut"); } catch (Exception e) { diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMapTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMapTest.java index a0449810c6d928eaf3ea0ba96df115c4ff0c6352..53f7fe8cf064de034a6b8f5855dae9df1e173d3e 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMapTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/util/MDCContextMapTest.java @@ -17,7 +17,7 @@ public class MDCContextMapTest { @Test public void getContextMapTest(){ - Map<String, String> contextMap = mdcContextMap.getContextMap("ut","opendes"); + Map<String, String> contextMap = mdcContextMap.getContextMap("ut","opendes", null); assertNotNull(contextMap); } }