@Override public IDeviceAssignment getCurrentDeviceAssignment(IDevice device) throws SiteWhereException { if (device.getAssignmentToken() == null) { return null; } return assertApiDeviceAssignment(device.getAssignmentToken()); }
@Override public IDeviceAssignment getCurrentDeviceAssignment(IDevice device) throws SiteWhereException { return getDeviceAssignmentByToken(device.getAssignmentToken()); }
/** * Get the current assignment or throw errors if it can not be resolved. * * @param hardwareId * @return * @throws SiteWhereException */ protected IDeviceAssignment getCurrentAssignment(String hardwareId) throws SiteWhereException { IDevice device = getDeviceManagement().getDeviceByHardwareId(hardwareId); if (device == null) { throw new SiteWhereSystemException(ErrorCode.InvalidHardwareId, ErrorLevel.ERROR); } if (device.getAssignmentToken() == null) { // If no assignment exists, add an unassociated assignment. return createUnassociatedAssignmentFor(hardwareId); } return getDeviceManagement().getDeviceAssignmentByToken(device.getAssignmentToken()); }
/** * Get the current assignment or throw errors if it can not be resolved. * * @param hardwareId * @return * @throws SiteWhereException */ protected IDeviceAssignment getCurrentAssignment(String hardwareId) throws SiteWhereException { IDevice device = SiteWhere.getServer().getDeviceManagement(getTenant()).getDeviceByHardwareId(hardwareId); if (device == null) { throw new SiteWhereSystemException(ErrorCode.InvalidHardwareId, ErrorLevel.ERROR); } if (device.getAssignmentToken() == null) { throw new SiteWhereSystemException(ErrorCode.DeviceNotAssigned, ErrorLevel.ERROR); } return SiteWhere.getServer().getDeviceManagement(getTenant()) .getDeviceAssignmentByToken(device.getAssignmentToken()); } }
if (getScriptPath() != null) { IDeviceAssignment targetAssignment = dm.getDeviceAssignmentByToken(targetDevice.getAssignmentToken()); Binding binding = new Binding(); binding.setVariable("logger", getLogger()); binding.setVariable("device", device); binding.setVariable("assignment", assignment); if (device.getAssignmentToken() != null) { binding.setVariable("targetAssignment", targetAssignment); binding.setVariable("targetDevice", targetDevice);
if (criteria.isExcludeAssigned() && (device.getAssignmentToken() != null)) { continue;
for (IDevice targetDevice : matches) { if (getScriptPath() != null) { IDeviceAssignment targetAssignment = dm.getDeviceAssignmentByToken(targetDevice.getAssignmentToken()); Binding binding = new Binding(); binding.setVariable("logger", getLogger()); binding.setVariable("device", device); binding.setVariable("assignment", assignment); if (device.getAssignmentToken() != null) { binding.setVariable("targetAssignment", targetAssignment); binding.setVariable("targetDevice", targetDevice);
try { IDevice device = assertDeviceByHardwareId(hardwareId, servletRequest); if (device.getAssignmentToken() == null) { throw new SiteWhereSystemException(ErrorCode.DeviceNotAssigned, ErrorLevel.ERROR); .addDeviceEventBatch(device.getAssignmentToken(), batch); } finally { Tracer.stop(LOGGER);
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IDevice source, Document target) { target.append(PROP_HARDWARE_ID, source.getHardwareId()); target.append(PROP_SITE_TOKEN, source.getSiteToken()); target.append(PROP_SPECIFICATION_TOKEN, source.getSpecificationToken()); target.append(PROP_PARENT_HARDWARE_ID, source.getParentHardwareId()); target.append(PROP_COMMENTS, source.getComments()); target.append(PROP_ASSIGNMENT_TOKEN, source.getAssignmentToken()); // Save nested list of mappings. List<Document> mappings = new ArrayList<Document>(); for (IDeviceElementMapping mapping : source.getDeviceElementMappings()) { mappings.add(MongoDeviceElementMapping.toDocument(mapping)); } target.append(PROP_DEVICE_ELEMENT_MAPPINGS, mappings); MongoSiteWhereEntity.toDocument(source, target); MongoMetadataProvider.toDocument(source, target); }
builder.addDeviceElementMappings(ebuilder.build()); if (device.getAssignmentToken() != null) { builder.setAssignmentToken(device.getAssignmentToken());
if (result != null) { Tracer.info("Returning cached device assignment token.", LOGGER); return result.getAssignmentToken();
if (device.getAssignmentToken() == null) { LOGGER.debug("Handling unassigned device for registration."); DeviceAssignmentCreateRequest assnCreate = new DeviceAssignmentCreateRequest();
if (source.getAssignmentToken() != null) { if (includeAssignment) { try { result.setAssignmentToken(source.getAssignmentToken());