/** * Find {@link IDeviceElementMapping} for the given nested device token. * * @param device * @param nestedDeviceToken * @return */ public static IDeviceElementMapping findMappingFor(IDevice device, String nestedDeviceToken) { if (device.getDeviceElementMappings() != null) { for (IDeviceElementMapping mapping : device.getDeviceElementMappings()) { if (mapping.getDeviceToken().equals(nestedDeviceToken)) { return mapping; } } } return null; } }
/** * Find {@link IDeviceElementMapping} for the given nested device hardware * id. * * @param device * @param nestedHardwareId * @return */ public static IDeviceElementMapping findMappingFor(IDevice device, String nestedHardwareId) { if (device.getDeviceElementMappings() != null) { for (IDeviceElementMapping mapping : device.getDeviceElementMappings()) { if (mapping.getHardwareId().equals(nestedHardwareId)) { return mapping; } } } return null; } }
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); }
List<IDeviceElementMapping> existing = device.getDeviceElementMappings(); List<DeviceElementMapping> newMappings = new ArrayList<DeviceElementMapping>(); IDeviceElementMapping match = null;
List<IDeviceElementMapping> existing = device.getDeviceElementMappings(); List<DeviceElementMapping> newMappings = new ArrayList<DeviceElementMapping>(); IDeviceElementMapping match = null;
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IDevice source, Document target) { target.append(PROP_HARDWARE_ID, source.getHardwareId()); target.append(PROP_SITE_TOKEN, source.getSiteToken()); target.append(PROP_SPECIFICATION_TOKEN, source.getSpecificationToken()); target.append(PROP_PARENT_HARDWARE_ID, source.getParentHardwareId()); target.append(PROP_COMMENTS, source.getComments()); target.append(PROP_ASSIGNMENT_TOKEN, source.getAssignmentToken()); // 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); MongoSiteWhereEntity.toDocument(source, target); MongoMetadataProvider.toDocument(source, target); }
List<IDeviceElementMapping> existing = device.getDeviceElementMappings(); List<DeviceElementMapping> newMappings = new ArrayList<DeviceElementMapping>(); for (IDeviceElementMapping mapping : existing) {
List<IDeviceElementMapping> existing = device.getDeviceElementMappings(); List<DeviceElementMapping> newMappings = new ArrayList<DeviceElementMapping>(); for (IDeviceElementMapping mapping : existing) {
builder.setParentHardwareId(device.getParentHardwareId()); for (IDeviceElementMapping mapping : device.getDeviceElementMappings()) { ProtobufMarshaler.DeviceElementMapping.Builder ebuilder = ProtobufMarshaler.DeviceElementMapping .newBuilder();
for (IDeviceElementMapping mapping : source.getDeviceElementMappings()) { DeviceElementMapping cnvMapping = DeviceElementMapping.copy(mapping); if (isIncludeNested()) {
/** * 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(); }
for (IDeviceElementMapping mapping : source.getDeviceElementMappings()) { DeviceElementMapping cnvMapping = DeviceElementMapping.copy(mapping); if (isIncludeNested()) {