public String getOs() { DeviceAttribute osAttr = this.readAttribute("os"); if(osAttr != null) { return osAttr.getValue(); } return null; }
public DeviceAttribute readAttribute(String name) { return this.find(new DeviceAttribute(name, null)); }
DeviceController deviceController = DeviceController.getInstance(); Device device = deviceController.read(deviceId); Identity identity = device.getIdentity(); if(identity == null) this.identityController.update(identity); device.updateAttribute(new DeviceAttribute("nonce", authenticationHash)); this.deviceController.update(device);
public String[] scanForUpdates(Device device, Date lastScanTimestamp) { String[] returnValue = null; List<String> ids = updateHistory.get(device.getIdentifier()); if(ids != null) { returnValue = ids.toArray(new String[0]); updateHistory.get(device.getIdentifier()).clear(); } return returnValue; }
public Device getDevice() { if(this.subscription == null || this.subscription.getClientId() == null) { return null; } return DeviceController.getInstance().read(this.subscription.getClientId()); }
private void sendSyncNotification(String deviceId, String channel) throws Exception { //Get the Device Token of the device that should receive the push notification Device device = this.deviceController.read(deviceId); //Find PushApps on this device List<PushApp> pushApps = this.findDevicePushApps(deviceId); //Remove Apps that are not interested in this channel/notification this.disqualifyApps(pushApps, channel); //actually send the push this.push(device, pushApps, "You have new information", null); }
private DeviceAttribute find(DeviceAttribute attribute) { DeviceAttribute cour = null; Set<DeviceAttribute> attributes = this.getAttributes(); for(DeviceAttribute loop: attributes) { if(loop.getName().equals(attribute.getName())) { return loop; } } return cour; } }
public void removeAttribute(DeviceAttribute attribute) { DeviceAttribute cour = this.find(attribute); if(cour != null) { this.getAttributes().remove(cour); } }
private List<PushApp> findDevicePushApps(String deviceId) { List<PushApp> apps = new ArrayList<PushApp>(); List<PushApp> all = this.pushAppController.readAll(); for(PushApp local:all) { boolean deviceFound = local.getDevices().contains(deviceId); if(deviceFound) { apps.add(local); } } return apps; }
public void addAttribute(DeviceAttribute attribute) { this.getAttributes().add(attribute); }
private void disqualifyApps(List<PushApp> apps, String channel) { List<PushApp> remove = new ArrayList<PushApp>(); for(PushApp local:apps) { if(!local.getChannels().contains(channel)) { remove.add(local); } } apps.removeAll(remove); }
public String[] scanForDeletions(Device device, Date lastScanTimestamp) { String[] returnValue = null; List<String> ids = deleteHistory.get(device.getIdentifier()); if(ids != null) { returnValue = ids.toArray(new String[0]); deleteHistory.get(device.getIdentifier()).clear(); } return returnValue; } //-------------------------------------------------------------------------------------------------------
public String getDeviceToken() { DeviceAttribute attr = this.readAttribute("device-token"); if(attr != null) { return attr.getValue(); } return null; } //-------------------------------------------------------------------------------------------------------
public static Notification createDeviceManagementNotification(Device device, String action) { if(action == null || action.trim().length()==0) { new IllegalArgumentException("Action cannot be null"); } Notification notification = new Notification(NotificationType.DM); notification.setMetaData(Constants.device, device.getIdentifier()); notification.setMetaData(Constants.action,action); return notification; }
public static Notification createSyncNotification(Device device, String service) { Notification syncNotification = new Notification(NotificationType.SYNC); syncNotification.setMetaData(Constants.device, device.getIdentifier()); syncNotification.setMetaData(Constants.service, service); return syncNotification; }
public static Notification createPushRPCNotification(Device device, String service) { Notification notification = new Notification(NotificationType.RPC); notification.setMetaData(Constants.device, device.getIdentifier()); notification.setMetaData(Constants.service, service); return notification; }
public static Notification createPushNotification(Device device, String message, Map<String,String> extras) { if(extras == null || extras.isEmpty()) { new IllegalArgumentException("Extras cannot be null"); } Notification notification = new Notification(NotificationType.PUSH); notification.setMetaData(Constants.device, device.getIdentifier()); notification.setMetaData(Constants.message,message); notification.setMetaData(Constants.extras,extras); return notification; }
private LastScanTimestamp findScanTimestamp(Device device) throws Exception { LastScanTimestamp scanTimestamp = null; scanTimestamp = this.read(this.channelRegistration.getUri(),device.getIdentifier()); if(scanTimestamp == null) { scanTimestamp = new LastScanTimestamp(); scanTimestamp.setTimestamp(new Date()); scanTimestamp.setChannel(this.channelRegistration.getUri()); scanTimestamp.setClientId(device.getIdentifier()); } return scanTimestamp; }