/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IDevice source, Document target) { target.append(PROP_DEVICE_TYPE_ID, source.getDeviceTypeId()); target.append(PROP_PARENT_DEVICE_ID, source.getParentDeviceId()); target.append(PROP_STATUS, source.getStatus()); target.append(PROP_COMMENTS, source.getComments()); target.append(PROP_ASSIGNMENT_ID, source.getDeviceAssignmentId()); // 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); MongoPersistentEntity.toDocument(source, target); }
if (target.getParentDeviceId() == null) { nested.setGateway(target); return nested; IDevice parent = getDeviceManagement(tenant).getDevice(target.getParentDeviceId()); if (parent == null) { throw new SiteWhereException("Parent device reference points to device that does not exist.");
if (mapped.getParentDeviceId() != null) { throw new SiteWhereSystemException(ErrorCode.DeviceParentMappingExists, ErrorLevel.ERROR);
/** * Convert device from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GDevice asGrpcDevice(IDevice api) throws SiteWhereException { GDevice.Builder grpc = GDevice.newBuilder(); if (api.getParentDeviceId() != null) { grpc.setParentDeviceId(CommonModelConverter.asGrpcUuid(api.getParentDeviceId())); } grpc.setDeviceTypeId(CommonModelConverter.asGrpcUuid(api.getDeviceTypeId())); if (api.getStatus() != null) { grpc.setStatus(GOptionalString.newBuilder().setValue(api.getStatus()).build()); } if (api.getDeviceAssignmentId() != null) { grpc.setDeviceAssignmentId(CommonModelConverter.asGrpcUuid(api.getDeviceAssignmentId())); } if (api.getComments() != null) { grpc.setComments(GOptionalString.newBuilder().setValue(api.getComments()).build()); } grpc.addAllDeviceElementMappings( DeviceModelConverter.asGrpcDeviceElementMappings(api.getDeviceElementMappings())); grpc.setEntityInformation(CommonModelConverter.asGrpcEntityInformation(api)); return grpc.build(); }
result.setDeviceTypeId(source.getDeviceTypeId()); result.setDeviceAssignmentId(source.getDeviceAssignmentId()); result.setParentDeviceId(source.getParentDeviceId()); result.setStatus(source.getStatus()); result.setComments(source.getComments());
context.setDeviceId(device.getId()); context.setDeviceTypeId(device.getDeviceTypeId()); context.setParentDeviceId(device.getParentDeviceId()); context.setDeviceStatus(device.getStatus()); context.setDeviceMetadata(device.getMetadata());