Skip to content
Snippets Groups Projects
Commit e2b4f08a authored by Alok Joshi's avatar Alok Joshi
Browse files

Merge branch 'xcollab-header' into 'master'

added x-collaboration property to the message header.

See merge request !336
parents 81b25366 5fc62fab
No related branches found
No related tags found
1 merge request!336added x-collaboration property to the message header.
Pipeline #162873 failed
...@@ -705,9 +705,8 @@ properties: ...@@ -705,9 +705,8 @@ properties:
[Back to Table of Contents](#TOC) [Back to Table of Contents](#TOC)
## Support for Collaboration Context <a name="collaboration-support"></a> ## Support for Collaboration Context <a name="collaboration-support"></a>
Register service and Notification service are collaboration aware. For now, to enable collaboration context support you have to enable collaboration feature flag in the services. Refer to this [Wiki](https://community.opengroup.org/groups/osdu/platform/system/-/wikis/Feature-Flag) for more details on how to do that. Register service and Notification service are collaboration aware. For now, to enable collaboration context support you have to enable collaboration feature flag in the services. Refer to this [Wiki](https://community.opengroup.org/groups/osdu/platform/system/-/wikis/Feature-Flag) for more details on how to do that.
That means when the consumer provides the "x-collaboration" header the list of topics returned will have a new topic "recordstopic-v2" which will receive notifications when "x-collaboration" header is provided. That means when the collaboration context feature flag is enabled the list of topics returned will have a new topic "recordstopic-v2" which will receive notifications when "x-collaboration" header is provided in the request.
<details><summary>curl for a collaboration context header provided request</summary> <details><summary>curl for a collaboration context header provided request</summary>
...@@ -721,7 +720,7 @@ curl --request GET \ ...@@ -721,7 +720,7 @@ curl --request GET \
``` ```
</details> </details>
A sample output is shown below when the collaboration context header is provided. A sample output is shown below when the collaboration context feature flag is set to true.
<details><summary>Sample response</summary> <details><summary>Sample response</summary>
...@@ -827,3 +826,26 @@ A sample output is shown below when the collaboration context header is provided ...@@ -827,3 +826,26 @@ A sample output is shown below when the collaboration context header is provided
``` ```
</details> </details>
When the feature flag is set to true and the consumer provides "x-collaboration" header in the request for creating, updating, and deleting a record. the message sent will contain the collaboration context header as an attribute.
#### Example of a message when the x-collaboration header is provided:
```json
{
"message": {
"data": [
{
"id": "<message-id>",
"kind": "common:welldb:wellbore:1.0.0",
"op": "create"
}
],
"account-id": "opendes",
"data-partition-id": "opendes",
"correlation-id": "<corrilation-id>",
"x-collaboration": "id=<collaboration-id>,application=<app-name>"
}
}
```
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
package org.opengroup.osdu.notification.service; package org.opengroup.osdu.notification.service;
import com.google.common.base.Strings;
import org.opengroup.osdu.core.common.http.HttpClient; import org.opengroup.osdu.core.common.http.HttpClient;
import org.opengroup.osdu.core.common.http.HttpRequest; import org.opengroup.osdu.core.common.http.HttpRequest;
import org.opengroup.osdu.core.common.http.HttpResponse; import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.notification.*; import org.opengroup.osdu.core.common.model.notification.*;
import org.opengroup.osdu.notification.auth.factory.AuthFactory; import org.opengroup.osdu.notification.auth.factory.AuthFactory;
...@@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory; ...@@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -37,6 +36,7 @@ import java.util.Map; ...@@ -37,6 +36,7 @@ import java.util.Map;
@Component @Component
public class NotificationHandler { public class NotificationHandler {
private final static Logger LOGGER = LoggerFactory.getLogger(NotificationHandler.class); private final static Logger LOGGER = LoggerFactory.getLogger(NotificationHandler.class);
private static final String X_COLLABORATION_HEADER = "x-collaboration";
@Autowired @Autowired
private HttpClient httpClient; private HttpClient httpClient;
@Autowired @Autowired
...@@ -52,6 +52,7 @@ public class NotificationHandler { ...@@ -52,6 +52,7 @@ public class NotificationHandler {
String endpoint = subscription.getPushEndpoint(); String endpoint = subscription.getPushEndpoint();
String secretType = secret.getSecretType(); String secretType = secret.getSecretType();
String pushUrl = ""; String pushUrl = "";
String collaborationContext = "";
Map<String, String> requestHeader = new HashMap<String, String>(); Map<String, String> requestHeader = new HashMap<String, String>();
// Authentication Secret // Authentication Secret
...@@ -60,13 +61,21 @@ public class NotificationHandler { ...@@ -60,13 +61,21 @@ public class NotificationHandler {
pushUrl = secretAuth.getPushUrl(endpoint); pushUrl = secretAuth.getPushUrl(endpoint);
requestHeader = secretAuth.getRequestHeaders(); requestHeader = secretAuth.getRequestHeaders();
if (headerAttributes.containsKey(X_COLLABORATION_HEADER))
collaborationContext = headerAttributes.get(X_COLLABORATION_HEADER);
requestHeader.put(DpsHeaders.CONTENT_TYPE, "application/json"); requestHeader.put(DpsHeaders.CONTENT_TYPE, "application/json");
requestHeader.put(DpsHeaders.CORRELATION_ID, headerAttributes.get(DpsHeaders.CORRELATION_ID)); requestHeader.put(DpsHeaders.CORRELATION_ID, headerAttributes.get(DpsHeaders.CORRELATION_ID));
requestHeader.put(DpsHeaders.DATA_PARTITION_ID, headerAttributes.get(DpsHeaders.DATA_PARTITION_ID)); requestHeader.put(DpsHeaders.DATA_PARTITION_ID, headerAttributes.get(DpsHeaders.DATA_PARTITION_ID));
if (!Strings.isNullOrEmpty(collaborationContext)) {
requestHeader.put(X_COLLABORATION_HEADER, headerAttributes.get(X_COLLABORATION_HEADER));
}
HttpRequest request = HttpRequest.post().url(pushUrl).headers(requestHeader).body(pubsubMessage).connectionTimeout(WAITING_TIME).build(); HttpRequest request = HttpRequest.post().url(pushUrl).headers(requestHeader).body(pubsubMessage).connectionTimeout(WAITING_TIME).build();
HttpResponse response = httpClient.send(request);
this.LOGGER.debug("Sending out notification to endpoint: " + endpoint); this.LOGGER.debug("Sending out notification to endpoint: " + endpoint);
HttpResponse response = httpClient.send(request);
return response; return response;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment