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

Commit 6e3e7fa

Browse files
committed
Updates to Notification Handling
1 parent 304fd41 commit 6e3e7fa

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

src/main/java/org/energyos/espi/common/domain/Authorization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
@NamedQuery(name = Authorization.QUERY_FIND_BY_REFRESH_TOKEN,
136136
query = "SELECT authorization from Authorization authorization WHERE authorization.refreshToken = :refreshToken"),
137137
@NamedQuery(name = Authorization.QUERY_FIND_BY_RESOURCE_URI,
138-
query = "SELECT authorization FROM Authorization authorization WHERE authorization.resourceURI = :uri"),
138+
query = "SELECT authorization FROM Authorization authorization WHERE authorization.resourceURI LIKE :uri"),
139139
@NamedQuery(name = Authorization.QUERY_FIND_ALL_IDS_BY_BULK_ID,
140140
query = "SELECT authorization.id FROM Authorization authorization WHERE authorization.thirdParty = :thirdParty AND authorization.scope LIKE :bulkId")
141141

src/main/java/org/energyos/espi/common/service/impl/NotificationServiceImpl.java

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package org.energyos.espi.common.service.impl;
1818

19+
import java.util.HashMap;
1920
import java.util.Iterator;
2021
import java.util.List;
22+
import java.util.Map;
23+
import java.util.Map.Entry;
2124

2225
import javax.xml.datatype.XMLGregorianCalendar;
2326

@@ -26,7 +29,6 @@
2629
import org.energyos.espi.common.domain.BatchList;
2730
import org.energyos.espi.common.domain.RetailCustomer;
2831
import org.energyos.espi.common.domain.Subscription;
29-
import org.energyos.espi.common.service.ApplicationInformationService;
3032
import org.energyos.espi.common.service.AuthorizationService;
3133
import org.energyos.espi.common.service.NotificationService;
3234
import org.energyos.espi.common.service.ResourceService;
@@ -37,7 +39,7 @@
3739
import org.springframework.web.client.RestTemplate;
3840

3941
/**
40-
* @author steph
42+
* @author John Teeter
4143
*
4244
*/
4345
@Service
@@ -128,15 +130,69 @@ public void notifyAllNeed() {
128130

129131
List <Long> authList = resourceService.findAllIds(Authorization.class);
130132

133+
Map<Long, BatchList> notifyList = new HashMap<Long, BatchList> ();
134+
131135
for (Long id : authList) {
136+
132137
Authorization authorization = resourceService.findById(id, Authorization.class);
133138

134-
if(authorization.getSubscription() != null) {
135-
notify(authorization.getSubscription(), null, null);
139+
String tempResourceUri = authorization.getResourceURI();
140+
141+
resourceService.findByResourceUri(tempResourceUri, Authorization.class);
142+
143+
System.out.println("resourceURI: " + tempResourceUri);
144+
145+
String thirdParty = authorization.getThirdParty();
146+
147+
// do not do any of the local authorizations
148+
//
149+
if (!((thirdParty.equals("data_custodian_admin")) || (thirdParty.equals("upload_admin")))) {
150+
151+
// if this is the first time we have seen this third party, add it to the notification list.
152+
if (!(notifyList.containsKey(thirdParty))) {
153+
notifyList.put(id, new BatchList ());
154+
}
155+
156+
// and now add the appropriate resource URIs to the batchList of this third party
157+
//
158+
String resourceUri = authorization.getResourceURI();
159+
160+
// resouceUri's that are just /Batch/Bulk ==> client-access-token and will be ignored here with the
161+
// actual Batch/Bulk ids will be picked up by looking at the scope strings of the individual
162+
// authorization/subscription pairs
163+
if (!(resourceUri.contains("/Batch/Bulk"))) {
164+
String scope = authorization.getScope();
165+
for (String term : scope.split(";")) {
166+
if (term.contains("BR=")) {
167+
// we have a bulkId to deal with
168+
term = term.substring(scope.indexOf("=") + 1);
169+
// TODO the following getResourceURI() should be changed to getBulkRequestURI when the seed tables
170+
// have non-null values for that attribute.
171+
String bulkResourceUri = authorization.getResourceURI() + "/Batch/Bulk/" + term;
172+
if (!(notifyList.get(id).getResources().contains(bulkResourceUri))) {
173+
notifyList.get(id).getResources().add(bulkResourceUri);
174+
}
175+
} else {
176+
// just add the resourceUri
177+
notifyList.get(id).getResources().add(resourceUri);
178+
}
179+
}
180+
}
181+
182+
}
183+
}
184+
185+
// now notify each ThirdParty
186+
for (Entry<Long, BatchList> entry : notifyList.entrySet() ) {
187+
String notifyUri = resourceService.findById(entry.getKey(), Authorization.class).getApplicationInformation().getThirdPartyNotifyUri();
188+
BatchList batchList = entry.getValue();
189+
if (!(batchList.getResources().isEmpty())) {
190+
notifyInternal(notifyUri, batchList);
136191
}
137-
}
192+
}
138193
}
139-
public void setRestTemplate(RestTemplate restTemplate) {
194+
195+
public void setRestTemplate(RestTemplate restTemplate) {
140196
this.restTemplate = restTemplate;
141197
}
142198

0 commit comments

Comments
 (0)