mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
Fix JDO so it returns blank not null strings. All unregistration to prune multiple devices (in case duplicates were accidentally introduced inan unorthodox upgrade. Misc cleanups.
This commit is contained in:
@@ -97,6 +97,24 @@ public class DeviceInfo {
|
|||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Key getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(Key key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accessor methods for properties added later (hence can be null)
|
||||||
|
|
||||||
|
public String getDeviceRegistrationID() {
|
||||||
|
return deviceRegistrationID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceRegistrationID(String deviceRegistrationID) {
|
||||||
|
this.deviceRegistrationID = deviceRegistrationID;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getDebug() {
|
public boolean getDebug() {
|
||||||
return (debug != null ? debug.booleanValue() : false);
|
return (debug != null ? debug.booleanValue() : false);
|
||||||
}
|
}
|
||||||
@@ -114,28 +132,12 @@ public class DeviceInfo {
|
|||||||
this.phoneToChromeExperimentEnabled = new Boolean(phoneToChromeExperimentEnabled);
|
this.phoneToChromeExperimentEnabled = new Boolean(phoneToChromeExperimentEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Key getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKey(Key key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceRegistrationID() {
|
|
||||||
return deviceRegistrationID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceRegistrationID(String deviceRegistrationID) {
|
|
||||||
this.deviceRegistrationID = deviceRegistrationID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type != null ? type : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
@@ -143,7 +145,7 @@ public class DeviceInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name != null ? name : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRegistrationTimestamp(Date registrationTimestamp) {
|
public void setRegistrationTimestamp(Date registrationTimestamp) {
|
||||||
@@ -165,7 +167,7 @@ public class DeviceInfo {
|
|||||||
List<DeviceInfo> qresult = (List<DeviceInfo>) query.execute();
|
List<DeviceInfo> qresult = (List<DeviceInfo>) query.execute();
|
||||||
// Copy to array - we need to close the query
|
// Copy to array - we need to close the query
|
||||||
List<DeviceInfo> result = new ArrayList<DeviceInfo>();
|
List<DeviceInfo> result = new ArrayList<DeviceInfo>();
|
||||||
for (DeviceInfo di: qresult) {
|
for (DeviceInfo di : qresult) {
|
||||||
result.add(di);
|
result.add(di);
|
||||||
}
|
}
|
||||||
query.closeAll();
|
query.closeAll();
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ public class RegisterServlet extends HttpServlet {
|
|||||||
|
|
||||||
device.setName(deviceName); // update display name
|
device.setName(deviceName); // update display name
|
||||||
|
|
||||||
if (device.getType() != null && device.getType().equals(DeviceInfo.TYPE_CHROME)) {
|
if (device.getType().equals(DeviceInfo.TYPE_CHROME)) {
|
||||||
if (device.getPhoneToChromeExperimentEnabled()) {
|
if (device.getPhoneToChromeExperimentEnabled()) {
|
||||||
String channelId =
|
String channelId =
|
||||||
ChannelServiceFactory.getChannelService().createChannel(deviceRegistrationId);
|
ChannelServiceFactory.getChannelService().createChannel(deviceRegistrationId);
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ public class SendServlet extends HttpServlet {
|
|||||||
|
|
||||||
String deviceName = req.getParameter("deviceName");
|
String deviceName = req.getParameter("deviceName");
|
||||||
String deviceType = req.getParameter("deviceType");
|
String deviceType = req.getParameter("deviceType");
|
||||||
if (deviceType == null) deviceType = DeviceInfo.TYPE_AC2DM; // default
|
|
||||||
|
|
||||||
User user = RegisterServlet.checkUser(req, resp, false);
|
User user = RegisterServlet.checkUser(req, resp, false);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@@ -82,7 +81,7 @@ public class SendServlet extends HttpServlet {
|
|||||||
private boolean doSendToDevice(String url, String title, String sel, String userAccount,
|
private boolean doSendToDevice(String url, String title, String sel, String userAccount,
|
||||||
String deviceName, String deviceType, HttpServletResponse resp) throws IOException {
|
String deviceName, String deviceType, HttpServletResponse resp) throws IOException {
|
||||||
|
|
||||||
// ok = we sent to at least one phone.
|
// ok = we sent to at least one device.
|
||||||
boolean ok = false;
|
boolean ok = false;
|
||||||
|
|
||||||
// Send push message to phone
|
// Send push message to phone
|
||||||
@@ -101,29 +100,22 @@ public class SendServlet extends HttpServlet {
|
|||||||
pm.close();
|
pm.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (registrations.size() == 0) {
|
int numSendAttempts = 0;
|
||||||
log.warning("Device not registered " + userAccount);
|
|
||||||
resp.getWriter().println(DEVICE_NOT_REGISTERED_STATUS);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (DeviceInfo deviceInfo : registrations) {
|
for (DeviceInfo deviceInfo : registrations) {
|
||||||
if (deviceName != null && deviceInfo.getName() != null &&
|
if (deviceName != null && !deviceName.equals(deviceInfo.getName())) {
|
||||||
!deviceName.equals(deviceInfo.getName())) {
|
|
||||||
continue; // user-specified device name
|
continue; // user-specified device name
|
||||||
}
|
}
|
||||||
if (deviceType != null && deviceInfo.getType() != null &&
|
if (deviceType != null && !deviceType.equals(deviceInfo.getType())) {
|
||||||
!deviceType.equals(deviceInfo.getType())) {
|
|
||||||
continue; // user-specified device type
|
continue; // user-specified device type
|
||||||
}
|
}
|
||||||
|
|
||||||
// if name or value are null - they'll be skipped
|
|
||||||
try {
|
try {
|
||||||
if (deviceInfo.getType() != null && deviceInfo.getType().equals(DeviceInfo.TYPE_CHROME)) {
|
if (deviceInfo.getType().equals(DeviceInfo.TYPE_CHROME)) {
|
||||||
res = doSendViaBrowserChannel(url, deviceInfo);
|
res = doSendViaBrowserChannel(url, deviceInfo);
|
||||||
} else {
|
} else {
|
||||||
res = doSendViaC2dm(url, title, sel, push, collapseKey, deviceInfo);
|
res = doSendViaC2dm(url, title, sel, push, collapseKey, deviceInfo);
|
||||||
}
|
}
|
||||||
|
numSendAttempts++;
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
log.info("Link sent to phone! collapse_key:" + collapseKey);
|
log.info("Link sent to phone! collapse_key:" + collapseKey);
|
||||||
@@ -134,8 +126,8 @@ public class SendServlet extends HttpServlet {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if ("NotRegistered".equals(ex.getMessage()) ||
|
if ("NotRegistered".equals(ex.getMessage()) ||
|
||||||
"InvalidRegistration".equals(ex.getMessage())) {
|
"InvalidRegistration".equals(ex.getMessage())) {
|
||||||
// remove registrations, it no longer works
|
// Prune device, it no longer works
|
||||||
pm.deletePersistent(deviceInfo);
|
pruneDevice(deviceInfo);
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
@@ -145,6 +137,10 @@ public class SendServlet extends HttpServlet {
|
|||||||
if (ok) {
|
if (ok) {
|
||||||
resp.getWriter().println(OK_STATUS);
|
resp.getWriter().println(OK_STATUS);
|
||||||
return true;
|
return true;
|
||||||
|
} else if (numSendAttempts == 0) {
|
||||||
|
log.warning("Device not registered " + userAccount);
|
||||||
|
resp.getWriter().println(DEVICE_NOT_REGISTERED_STATUS);
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
resp.setStatus(500);
|
resp.setStatus(500);
|
||||||
resp.getWriter().println(ERROR_STATUS + " (Unable to send link)");
|
resp.getWriter().println(ERROR_STATUS + " (Unable to send link)");
|
||||||
@@ -152,6 +148,13 @@ public class SendServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void pruneDevice(DeviceInfo deviceInfo) {
|
||||||
|
PersistenceManager pm =
|
||||||
|
C2DMessaging.getPMF(getServletContext()).getPersistenceManager();
|
||||||
|
pm.deletePersistent(deviceInfo);
|
||||||
|
pm.close();
|
||||||
|
}
|
||||||
|
|
||||||
boolean doSendViaC2dm(String url, String title, String sel, C2DMessaging push,
|
boolean doSendViaC2dm(String url, String title, String sel, C2DMessaging push,
|
||||||
String collapseKey, DeviceInfo deviceInfo) throws IOException {
|
String collapseKey, DeviceInfo deviceInfo) throws IOException {
|
||||||
|
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ public class UnregisterServlet extends HttpServlet {
|
|||||||
DeviceInfo deviceInfo = registrations.get(i);
|
DeviceInfo deviceInfo = registrations.get(i);
|
||||||
if (deviceInfo.getDeviceRegistrationID().equals(deviceRegistrationID)) {
|
if (deviceInfo.getDeviceRegistrationID().equals(deviceRegistrationID)) {
|
||||||
pm.deletePersistent(deviceInfo);
|
pm.deletePersistent(deviceInfo);
|
||||||
registrations.remove(i);
|
// Keep looping in case of duplicates
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
-->
|
-->
|
||||||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
|
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
|
||||||
<application>chrometophone</application>
|
<application>chrometophone</application>
|
||||||
<version>6</version>
|
<version>7</version>
|
||||||
<system-properties>
|
<system-properties>
|
||||||
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
|
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
|
||||||
</system-properties>
|
</system-properties>
|
||||||
|
|||||||
Reference in New Issue
Block a user