Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 97b6ecc

Browse files
committed
Added Notification Support for /Batch/Bulk/** and /Authorization/**
1 parent 8c88125 commit 97b6ecc

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/main/java/org/energyos/espi/thirdparty/web/NotificationController.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ private void doImportAsynchronously(String subscriptionUri) {
9393
System.out.printf("Start Asynchronous Input: %s: %s\n ", threadName, subscriptionUri);
9494

9595
String resourceUri = subscriptionUri;
96+
String accessToken = "";
97+
Authorization authorization = null;
98+
RetailCustomer retailCustomer = null;
9699

97100
if (subscriptionUri.indexOf("?") > -1) { // Does message contain a query element
98101
resourceUri = subscriptionUri.substring(0, subscriptionUri.indexOf("?")); // Yes, remove the query element
@@ -118,12 +121,22 @@ private void doImportAsynchronously(String subscriptionUri) {
118121

119122
} else {
120123
try {
121-
Authorization authorization = resourceService.findByResourceUri(resourceUri, Authorization.class);
122-
123-
RetailCustomer retailCustomer = authorization.getRetailCustomer();
124-
125-
String accessToken = authorization.getAccessToken();
126-
124+
if ((resourceUri.contains("/Batch/Bulk")) || (resourceUri.contains("/Authorization"))) {
125+
// mutate the resourceUri to be of the form .../Batch/Bulk
126+
resourceUri = (resourceUri.substring(0, resourceUri.indexOf("/resource/") + "/resource/".length()).concat("Batch/Bulk"));
127+
128+
} else {
129+
// mutate the resourceUri for the form /Subscription/{subscriptionId}/**
130+
String temp = resourceUri.substring(resourceUri.indexOf("/Subscription/") + "/Subscription/".length());
131+
if (temp.contains("/")) {
132+
resourceUri = resourceUri.substring(0, resourceUri.indexOf("/Subscription") + "/Subscription".length()).concat(temp.substring(0, temp.indexOf("/")));
133+
}
134+
}
135+
136+
authorization = resourceService.findByResourceUri(resourceUri, Authorization.class);
137+
retailCustomer = authorization.getRetailCustomer();
138+
accessToken = authorization.getAccessToken();
139+
127140
try {
128141

129142
HttpHeaders requestHeaders = new HttpHeaders();

0 commit comments

Comments
 (0)