@Override public IDevice getDeviceForAssignment(IDeviceAssignment assignment) throws SiteWhereException { return getDeviceByHardwareId(assignment.getDeviceHardwareId()); }
@Override public IDevice getDeviceForAssignment(IDeviceAssignment assignment) throws SiteWhereException { return getDeviceByHardwareId(assignment.getDeviceHardwareId()); }
public IDevice getDeviceForAssignment(IDeviceAssignment assignment) throws SiteWhereException { return HBaseDevice.getDeviceByHardwareId(context, assignment.getDeviceHardwareId()); }
public Builder(IDeviceAssignment api) { request.setToken(api.getToken()); request.setDeviceHardwareId(api.getDeviceHardwareId()); request.setAssetModuleId(api.getAssetModuleId()); request.setAssetId(api.getAssetId()); request.setAssignmentType(api.getAssignmentType()); if (api.getMetadata() != null) { request.setMetadata(new HashMap<String, String>()); request.getMetadata().putAll(api.getMetadata()); } }
/** * Indicates if an event is filtered. * * @param event * @return * @throws SiteWhereException */ protected boolean isFiltered(IDeviceEvent event) throws SiteWhereException { IDeviceAssignment assignment = deviceManagement.getDeviceAssignmentByToken(event.getDeviceAssignmentToken()); if (assignment == null) { throw new SiteWhereException("Device assignment for event not found."); } IDevice device = deviceManagement.getDeviceByHardwareId(assignment.getDeviceHardwareId()); if (device == null) { throw new SiteWhereException("Device assignment references unknown device."); } for (IDeviceEventFilter filter : filters) { if (filter.isFiltered(event, device, assignment)) { return true; } } return false; }
assignment.getDeviceHardwareId(), null, create); inbound.processDeviceStateChange(decoded);
@Override public byte[] encodeDeviceAssignment(IDeviceAssignment assignment) throws SiteWhereException { ProtobufMarshaler.DeviceAssignment.Builder builder = ProtobufMarshaler.DeviceAssignment.newBuilder(); builder.setToken(assignment.getToken()); builder.setDeviceHardwareId(assignment.getDeviceHardwareId()); builder.setSiteToken(assignment.getSiteToken()); builder.setAssignmentType(marshalAssignmentType(assignment.getAssignmentType())); if (assignment.getAssetModuleId() != null) { builder.setAssetModuleId(assignment.getAssetModuleId()); } if (assignment.getAssetId() != null) { builder.setAssetId(assignment.getAssetId()); } builder.setStatus(assignment.getStatus().name()); if (assignment.getActiveDate() != null) { builder.setActiveDate(assignment.getActiveDate().getTime()); } if (assignment.getReleasedDate() != null) { builder.setReleasedDate(assignment.getReleasedDate().getTime()); } builder.setEntityData(createEntityData(assignment)); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); builder.build().writeTo(out); return out.toByteArray(); } catch (IOException e) { throw new SiteWhereException("Unable to marshal device assignment.", e); } }
/** * Send an {@link IDeviceEvent} to the configured topic. * * @param event * @throws SiteWhereException */ protected void sendEvent(IDeviceEvent event) throws SiteWhereException { IDeviceManagement dm = SiteWhere.getServer().getDeviceManagement(getTenant()); IDeviceAssignment assignment = dm.getDeviceAssignmentByToken(event.getDeviceAssignmentToken()); IDevice device = dm.getDeviceByHardwareId(assignment.getDeviceHardwareId()); if (getMulticaster() != null) { List<String> routes = getMulticaster().calculateRoutes(event, device, assignment); for (String route : routes) { publish(event, route); } } else { if (getRouteBuilder() != null) { publish(event, getRouteBuilder().build(event, device, assignment)); } else { publish(event, getTopic()); } } }
/** * Send an {@link IDeviceEvent} to the configured topic. * * @param event * @throws SiteWhereException */ protected void sendEvent(IDeviceEvent event) throws SiteWhereException { IDeviceManagement dm = SiteWhere.getServer().getDeviceManagement(getTenant()); IDeviceAssignment assignment = dm.getDeviceAssignmentByToken(event.getDeviceAssignmentToken()); IDevice device = dm.getDeviceByHardwareId(assignment.getDeviceHardwareId()); if (getMulticaster() != null) { List<String> routes = getMulticaster().calculateRoutes(event, device, assignment); for (String route : routes) { publish(event, route); } } else { if (getRouteBuilder() != null) { publish(event, getRouteBuilder().build(event, device, assignment)); } else { publish(event, getTopic()); } } }
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IDeviceAssignment source, Document target) { if (source.getActiveDate() != null) { target.append(PROP_ACTIVE_DATE, source.getActiveDate()); } target.append(PROP_ASSET_MODULE_ID, source.getAssetModuleId()); target.append(PROP_ASSET_ID, source.getAssetId()); if (source.getAssignmentType() != null) { target.append(PROP_ASSIGNMENT_TYPE, source.getAssignmentType().name()); } if (source.getReleasedDate() != null) { target.append(PROP_RELEASED_DATE, source.getReleasedDate()); } if (source.getStatus() != null) { target.append(PROP_STATUS, source.getStatus().name()); } target.append(PROP_TOKEN, source.getToken()); target.append(PROP_DEVICE_HARDWARE_ID, source.getDeviceHardwareId()); target.append(PROP_SITE_TOKEN, source.getSiteToken()); if (source.getState() != null) { setState(source.getState(), target); } MongoSiteWhereEntity.toDocument(source, target); MongoMetadataProvider.toDocument(source, target); }
result.setSite(Site.copy(site)); result.setDeviceHardwareId(source.getDeviceHardwareId()); if (isIncludeDevice()) { IDevice device = getDeviceManagement().getDeviceForAssignment(source);