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

Commit ac511e6

Browse files
committed
Merge pull request #168 from jateeter/master
Notifications; Serialization
2 parents ee8048f + ed435c7 commit ac511e6

File tree

5 files changed

+83
-11
lines changed

5 files changed

+83
-11
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,11 @@ public java.lang.Object getRegistrationAccessToken() {
12621262
}
12631263

12641264
private void setRegistrationAccessToken(java.lang.Object registrationAccessToken) {
1265-
this.registrationAccessToken = registrationAccessToken.toString();
1265+
if (registrationAccessToken != null) {
1266+
this.registrationAccessToken = registrationAccessToken.toString();
1267+
} else {
1268+
this.registrationAccessToken = null;
1269+
}
12661270
}
12671271

12681272
/**

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/domain/IdentifiedObject.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.energyos.espi.common.domain;
2626

27+
import java.io.Serializable;
2728
import java.util.ArrayList;
2829
import java.util.GregorianCalendar;
2930
import java.util.List;
@@ -82,8 +83,11 @@
8283
ReadingType.class
8384
})
8485
@MappedSuperclass
85-
public class IdentifiedObject extends Resource implements Linkable {
86+
public class IdentifiedObject extends Resource implements Linkable, Serializable {
8687

88+
@XmlTransient
89+
private static final long serialVersionUID = -5263186855332223773L;
90+
8791
public interface ResourceEnumClass {
8892
ResourceEnum getEnumType();
8993
}

src/main/java/org/energyos/espi/common/models/atom/LinkType.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424

2525
package org.energyos.espi.common.models.atom;
2626

27+
import java.io.Serializable;
28+
2729
import javax.persistence.Embeddable;
2830
import javax.xml.bind.annotation.XmlAccessType;
2931
import javax.xml.bind.annotation.XmlAccessorType;
3032
import javax.xml.bind.annotation.XmlAttribute;
3133
import javax.xml.bind.annotation.XmlSchemaType;
34+
import javax.xml.bind.annotation.XmlTransient;
3235

3336

3437
/**
@@ -58,9 +61,12 @@
5861
*/
5962
@XmlAccessorType(XmlAccessType.FIELD)
6063
@Embeddable
61-
public class LinkType {
64+
public class LinkType implements Serializable {
6265

63-
public static final String SELF = "self";
66+
@XmlTransient
67+
private static final long serialVersionUID = 528461832553643471L;
68+
69+
public static final String SELF = "self";
6470
public static final String UP = "up";
6571
public static final String RELATED = "related";
6672
public static final String HREF = "href";

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

Lines changed: 64 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,71 @@ 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+
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);
136193
}
137-
}
194+
}
138195
}
139-
public void setRestTemplate(RestTemplate restTemplate) {
196+
197+
public void setRestTemplate(RestTemplate restTemplate) {
140198
this.restTemplate = restTemplate;
141199
}
142200

0 commit comments

Comments
 (0)