IDeviceUnit unit = deviceType.getDeviceElementSchema(); if (unit == null) { return null;
/** * Copy information from SPI into Mongo DBObject. * * @param source * @param target */ public static void toDocument(IDeviceType source, Document target) { target.append(PROP_NAME, source.getName()); target.append(PROP_DESCRIPTION, source.getDescription()); target.append(PROP_CONTAINER_POLICY, source.getContainerPolicy().name()); MongoBrandedEntity.toDocument(source, target); // Marshal device element schema as JSON. if (source.getDeviceElementSchema() != null) { ObjectMapper mapper = new ObjectMapper(); try { byte[] schemaJson = mapper.writeValueAsBytes(source.getDeviceElementSchema()); target.append(PROP_DEVICE_ELEMENT_SCHEMA, new Binary(schemaJson)); } catch (JsonProcessingException e) { LOGGER.error("Unable to marshal device element schema for MongoDB persistence.", e); } } }
/** * Convert device type from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GDeviceType asGrpcDeviceType(IDeviceType api) throws SiteWhereException { GDeviceType.Builder grpc = GDeviceType.newBuilder(); grpc.setName(api.getName()); grpc.setDescription(api.getDescription()); grpc.setContainerPolicy(DeviceModelConverter.asGrpcDeviceContainerPolicy(api.getContainerPolicy())); if (api.getDeviceElementSchema() != null) { grpc.setDeviceElementSchema(DeviceModelConverter.asGrpcDeviceElementSchema(api.getDeviceElementSchema())); } grpc.setEntityInformation(CommonModelConverter.asGrpcEntityInformation(api)); grpc.setBranding(CommonModelConverter.asGrpcBrandingInformation(api)); return grpc.build(); }
/** * Convert a device type for marshaling. * * @param source * @return * @throws SiteWhereException */ public DeviceType convert(IDeviceType source) throws SiteWhereException { DeviceType deviceType = new DeviceType(); deviceType.setName(source.getName()); deviceType.setDescription(source.getDescription()); deviceType.setContainerPolicy(source.getContainerPolicy()); deviceType.setDeviceElementSchema((DeviceElementSchema) source.getDeviceElementSchema()); BrandedEntity.copy(source, deviceType); return deviceType; }