/** * 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); } } }
/** * Generate the '.proto' information. * * @param deviceType * @param commands * @param buffer * @throws SiteWhereException */ protected static void generateProto(IDeviceType deviceType, List<IDeviceCommand> commands, StringBuffer buffer) throws SiteWhereException { int indent = 0; SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z"); String typeName = ProtobufNaming.getDeviceTypeIdentifier(deviceType); println("option optimize_for = LITE_RUNTIME;", indent, buffer); newline(buffer); println("// Google Protocol Buffer for '" + deviceType.getName() + "'.", indent, buffer); println("// Generated on " + formatter.format(new Date()), indent, buffer); println("message " + typeName + " {", indent, buffer); newline(buffer); addCommandsEnum(deviceType, commands, buffer, indent + 1); newline(buffer); addHeader(buffer, indent + 1); newline(buffer); int index = 2; for (IDeviceCommand command : commands) { addCommand(command, index++, buffer, indent + 1); newline(buffer); } println("}", indent, buffer); }
/** * 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; }
+ deviceType.getName() + "</a>"; if (!StringUtils.isEmpty(criteria.getGroupToken())) { IDeviceGroup group = devices.getDeviceGroupByToken(criteria.getGroupToken());
IDeviceType nestedType = deviceManagement.getDeviceType(nested.getNested().getDeviceTypeId()); LOGGER.debug( "Targeting nested device with type: " + nestedType.getName() + " at path " + nested.getPath()); headBuilder.setField(header.findFieldByName(ProtobufNaming.HEADER_NESTED_PATH_FIELD_NAME), nested.getPath());
/** * 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(); }