throws SiteWhereException { GDeviceRegistrationRequest.Builder grpc = GDeviceRegistrationRequest.newBuilder(); if (api.getToken() != null) { grpc.setToken(GOptionalString.newBuilder().setValue(api.getToken())); if (api.getParentDeviceToken() != null) { grpc.setParentDeviceToken(GOptionalString.newBuilder().setValue(api.getParentDeviceToken())); if (api.getDeviceTypeToken() != null) { grpc.setDeviceTypeToken(GOptionalString.newBuilder().setValue(api.getDeviceTypeToken())); if (api.getStatus() != null) { grpc.setStatus(GOptionalString.newBuilder().setValue(api.getStatus())); if (api.getComments() != null) { grpc.setComments(GOptionalString.newBuilder().setValue(api.getComments())); DeviceModelConverter.asGrpcDeviceElementMappings(api.getDeviceElementMappings())); if (api.getMetadata() != null) { grpc.putAllMetadata(api.getMetadata()); if (api.getCustomerToken() != null) { grpc.setCustomerToken(GOptionalString.newBuilder().setValue(api.getCustomerToken())); if (api.getAreaToken() != null) { grpc.setAreaToken(GOptionalString.newBuilder().setValue(api.getAreaToken()));
LOGGER.debug("Handling device registration request."); IDevice device = SiteWhere.getServer().getDeviceManagement(getTenant()) .getDeviceByHardwareId(request.getHardwareId()); IDeviceSpecification specification = SiteWhere.getServer().getDeviceManagement(getTenant()) .getDeviceSpecificationByToken(request.getSpecificationToken()); if (request.getSiteToken() != null) { if (SiteWhere.getServer().getDeviceManagement(getTenant()).getSiteByToken(request.getSiteToken()) == null) { LOGGER.warn("Ignoring device registration request because of invalid site token."); return; sendInvalidSpecification(request.getHardwareId()); return; if ((!isAutoAssignSite()) && (request.getSiteToken() == null)) { sendSiteTokenRequired(request.getHardwareId()); return; String siteToken = (request.getSiteToken() != null) ? request.getSiteToken() : getAutoAssignSiteToken(); LOGGER.debug("Creating new device as part of registration."); DeviceCreateRequest deviceCreate = new DeviceCreateRequest(); deviceCreate.setHardwareId(request.getHardwareId()); deviceCreate.setSpecificationToken(request.getSpecificationToken()); deviceCreate.setSiteToken(siteToken); deviceCreate.setComments("Device created by on-demand registration."); deviceCreate.setMetadata(request.getMetadata()); device = SiteWhere.getServer().getDeviceManagement(getTenant()).createDevice(deviceCreate); } else if (!device.getSpecificationToken().equals(request.getSpecificationToken())) { LOGGER.info("Found existing device registration, but specification does not match.");
payloadBuilder.setAreaToken(GOptionalString.newBuilder().setValue(request.getAreaToken())); payloadBuilder.setDeviceTypeToken(GOptionalString.newBuilder().setValue(request.getDeviceTypeToken())); payloadBuilder.setCustomerToken(GOptionalString.newBuilder().setValue(request.getCustomerToken())); if (request.getMetadata() != null) { payloadBuilder.putAllMetadata(request.getMetadata());
IDeviceRegistrationRequest request = (IDeviceRegistrationRequest) decoded.getRequest(); SiteWhere.RegisterDevice.Builder register = SiteWhere.RegisterDevice.newBuilder(); register.setHardwareId(request.getHardwareId()); register.setSiteToken(request.getSiteToken()); register.setSpecificationToken(request.getSpecificationToken());
/** * Get area that should be used for the given request. * * @param registration * @return * @throws SiteWhereException */ protected IArea getAreaFor(IDeviceRegistrationPayload registration) throws SiteWhereException { String areaToken = registration.getDeviceRegistrationRequest().getAreaToken(); if (areaToken != null) { IArea override = getDeviceManagement().getAreaByToken(areaToken); if (override == null) { throw new SiteWhereException("Registration request specified invalid area token."); } return override; } else if (isUseDefaultArea()) { return getDefaultArea(); } return null; }
/** * Get customer that should be used for the given request. * * @param registration * @return * @throws SiteWhereException */ protected ICustomer getCustomerFor(IDeviceRegistrationPayload registration) throws SiteWhereException { String customerToken = registration.getDeviceRegistrationRequest().getCustomerToken(); if (customerToken != null) { ICustomer override = getDeviceManagement().getCustomerByToken(customerToken); if (override == null) { throw new SiteWhereException("Registration request specified invalid customer token."); } return override; } else if (isUseDefaultCustomer()) { return getDefaultCustomer(); } return null; }
/** * Get device type that should be used for the given request. * * @param registration * @return * @throws SiteWhereException */ protected IDeviceType getDeviceTypeFor(IDeviceRegistrationPayload registration) throws SiteWhereException { String deviceTypeToken = registration.getDeviceRegistrationRequest().getDeviceTypeToken(); if (deviceTypeToken != null) { IDeviceType override = getDeviceManagement().getDeviceTypeByToken(deviceTypeToken); if (override == null) { throw new SiteWhereException("Registration request specified invalid device type token."); } return override; } else if (isUseDefaultDeviceType()) { return getDefaultDeviceType(); } throw new SiteWhereException("Device type not passed and no default provided."); }