public Builder(IDevice api) { request.setSiteToken(api.getSiteToken()); request.setSpecificationToken(api.getSpecificationToken()); request.setHardwareId(api.getHardwareId()); request.setStatus(api.getStatus()); request.setComments(api.getComments()); request.setParentHardwareId(api.getParentHardwareId()); if (api.getDeviceElementMappings() != null) { request.setDeviceElementMappings(new ArrayList<DeviceElementMapping>()); request.getDeviceElementMappings().addAll(api.getDeviceElementMappings()); } if (api.getMetadata() != null) { request.setMetadata(new HashMap<String, String>()); request.getMetadata().putAll(api.getMetadata()); } }
/** * 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); }
/** * 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.setDeviceAssignmentId(source.getDeviceAssignmentId()); result.setParentDeviceId(source.getParentDeviceId()); result.setStatus(source.getStatus()); result.setComments(source.getComments()); PersistentEntity.copy(source, result);
context.setDeviceTypeId(device.getDeviceTypeId()); context.setParentDeviceId(device.getParentDeviceId()); context.setDeviceStatus(device.getStatus()); context.setDeviceMetadata(device.getMetadata()); context.setAssignmentStatus(assignment.getStatus());