|
16 | 16 |
|
17 | 17 | package org.energyos.espi.common.service.impl; |
18 | 18 |
|
| 19 | +import java.util.HashMap; |
19 | 20 | import java.util.Iterator; |
20 | 21 | import java.util.List; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.Map.Entry; |
21 | 24 |
|
22 | 25 | import javax.xml.datatype.XMLGregorianCalendar; |
23 | 26 |
|
|
26 | 29 | import org.energyos.espi.common.domain.BatchList; |
27 | 30 | import org.energyos.espi.common.domain.RetailCustomer; |
28 | 31 | import org.energyos.espi.common.domain.Subscription; |
29 | | -import org.energyos.espi.common.service.ApplicationInformationService; |
30 | 32 | import org.energyos.espi.common.service.AuthorizationService; |
31 | 33 | import org.energyos.espi.common.service.NotificationService; |
32 | 34 | import org.energyos.espi.common.service.ResourceService; |
|
37 | 39 | import org.springframework.web.client.RestTemplate; |
38 | 40 |
|
39 | 41 | /** |
40 | | - * @author steph |
| 42 | + * @author John Teeter |
41 | 43 | * |
42 | 44 | */ |
43 | 45 | @Service |
@@ -128,15 +130,71 @@ public void notifyAllNeed() { |
128 | 130 |
|
129 | 131 | List <Long> authList = resourceService.findAllIds(Authorization.class); |
130 | 132 |
|
| 133 | + Map<Long, BatchList> notifyList = new HashMap<Long, BatchList> (); |
| 134 | + |
131 | 135 | for (Long id : authList) { |
| 136 | + |
132 | 137 | Authorization authorization = resourceService.findById(id, Authorization.class); |
133 | 138 |
|
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 | + if (!(notifyList.get(id).getResources().contains(resourceUri))) { |
| 178 | + notifyList.get(id).getResources().add(resourceUri); |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + // now notify each ThirdParty |
| 188 | + for (Entry<Long, BatchList> entry : notifyList.entrySet() ) { |
| 189 | + String notifyUri = resourceService.findById(entry.getKey(), Authorization.class).getApplicationInformation().getThirdPartyNotifyUri(); |
| 190 | + BatchList batchList = entry.getValue(); |
| 191 | + if (!(batchList.getResources().isEmpty())) { |
| 192 | + notifyInternal(notifyUri, batchList); |
136 | 193 | } |
137 | | - } |
| 194 | + } |
138 | 195 | } |
139 | | - public void setRestTemplate(RestTemplate restTemplate) { |
| 196 | + |
| 197 | + public void setRestTemplate(RestTemplate restTemplate) { |
140 | 198 | this.restTemplate = restTemplate; |
141 | 199 | } |
142 | 200 |
|
|
0 commit comments