public Builder(IDeviceAssignment api) { request.setToken(api.getToken()); request.setDeviceHardwareId(api.getDeviceHardwareId()); request.setAssetModuleId(api.getAssetModuleId()); request.setAssetId(api.getAssetId()); request.setAssignmentType(api.getAssignmentType()); if (api.getMetadata() != null) { request.setMetadata(new HashMap<String, String>()); request.getMetadata().putAll(api.getMetadata()); } }
@Override public byte[] encodeDeviceAssignment(IDeviceAssignment assignment) throws SiteWhereException { ProtobufMarshaler.DeviceAssignment.Builder builder = ProtobufMarshaler.DeviceAssignment.newBuilder(); builder.setToken(assignment.getToken()); builder.setDeviceHardwareId(assignment.getDeviceHardwareId()); builder.setSiteToken(assignment.getSiteToken()); builder.setAssignmentType(marshalAssignmentType(assignment.getAssignmentType())); if (assignment.getAssetModuleId() != null) { builder.setAssetModuleId(assignment.getAssetModuleId()); } if (assignment.getAssetId() != null) { builder.setAssetId(assignment.getAssetId()); } builder.setStatus(assignment.getStatus().name()); if (assignment.getActiveDate() != null) { builder.setActiveDate(assignment.getActiveDate().getTime()); } if (assignment.getReleasedDate() != null) { builder.setReleasedDate(assignment.getReleasedDate().getTime()); } builder.setEntityData(createEntityData(assignment)); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); builder.build().writeTo(out); return out.toByteArray(); } catch (IOException e) { throw new SiteWhereException("Unable to marshal device assignment.", e); } }
/** * Common creation logic for all device events. * * @param request * @param assignment * @param target * @throws SiteWhereException */ public static void deviceEventCreateLogic(IDeviceEventCreateRequest request, IDeviceAssignment assignment, DeviceEvent target) throws SiteWhereException { target.setId(UUID.randomUUID()); target.setAlternateId(request.getAlternateId()); target.setDeviceId(assignment.getDeviceId()); target.setDeviceAssignmentId(assignment.getId()); target.setCustomerId(assignment.getCustomerId()); target.setAreaId(assignment.getAreaId()); target.setAssetId(assignment.getAssetId()); if (request.getEventDate() != null) { target.setEventDate(request.getEventDate()); } else { target.setEventDate(new Date()); } target.setReceivedDate(new Date()); MetadataProvider.copy(request.getMetadata(), target); }
.getMarshaler(payloadType).decode(payload, DeviceAssignment.class); boolean sameAssetModule = assetModuleId.equals(assignment.getAssetModuleId()); boolean sameAssetId = assetId.equals(assignment.getAssetId()); boolean matchingStatus = (criteria.getStatus() == null) || (criteria.getStatus() == assignment.getStatus());
/** * Common creation logic for all device events. * * @param request * @param assignment * @param target * @throws SiteWhereException */ public static void deviceEventCreateLogic(IDeviceEventCreateRequest request, IDeviceAssignment assignment, DeviceEvent target) throws SiteWhereException { target.setAlternateId(request.getAlternateId()); target.setSiteToken(assignment.getSiteToken()); target.setDeviceAssignmentToken(assignment.getToken()); target.setAssignmentType(assignment.getAssignmentType()); target.setAssetModuleId(assignment.getAssetModuleId()); target.setAssetId(assignment.getAssetId()); if (request.getEventDate() != null) { target.setEventDate(request.getEventDate()); } else { target.setEventDate(new Date()); } target.setReceivedDate(new Date()); MetadataProvider.copy(request.getMetadata(), target); }
/** * Convert a device assignment from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GDeviceAssignment asGrpcDeviceAssignment(IDeviceAssignment api) throws SiteWhereException { GDeviceAssignment.Builder grpc = GDeviceAssignment.newBuilder(); grpc.setStatus(CommonModelConverter.asGrpcDeviceAssignmentStatus(api.getStatus())); grpc.setDeviceId(CommonModelConverter.asGrpcUuid(api.getDeviceId())); grpc.setDeviceTypeId(CommonModelConverter.asGrpcUuid(api.getDeviceTypeId())); if (api.getAreaId() != null) { grpc.setAreaId(CommonModelConverter.asGrpcUuid(api.getAreaId())); } if (api.getAssetId() != null) { grpc.setAssetId(CommonModelConverter.asGrpcUuid(api.getAssetId())); } grpc.setActiveDate(CommonModelConverter.asGrpcDate(api.getActiveDate())); grpc.setReleasedDate(CommonModelConverter.asGrpcDate(api.getReleasedDate())); grpc.setEntityInformation(CommonModelConverter.asGrpcEntityInformation(api)); return grpc.build(); }
result.setAssetId(source.getAssetId()); if (source.getAssetId() != null) { IAsset asset = assetManagement.getAsset(source.getAssetId()); if (asset == null) { LOGGER.warn("Device assignment has reference to non-existent asset.");
/** * Common logic for creating a device alarm. * * @param assignment * @param request * @return * @throws SiteWhereException */ public static DeviceAlarm deviceAlarmCreateLogic(IDeviceAssignment assignment, IDeviceAlarmCreateRequest request) throws SiteWhereException { DeviceAlarm alarm = new DeviceAlarm(); alarm.setId(UUID.randomUUID()); alarm.setDeviceId(assignment.getDeviceId()); alarm.setDeviceAssignmentId(assignment.getId()); alarm.setCustomerId(assignment.getCustomerId()); alarm.setAreaId(assignment.getAreaId()); alarm.setAssetId(assignment.getAssetId()); require("Alarm message", request.getAlarmMessage()); alarm.setAlarmMessage(request.getAlarmMessage()); alarm.setTriggeringEventId(request.getTriggeringEventId()); alarm.setState(request.getState() != null ? request.getState() : DeviceAlarmState.Triggered); alarm.setTriggeredDate(request.getTriggeredDate() != null ? request.getTriggeredDate() : new Date()); alarm.setAcknowledgedDate(request.getAcknowledgedDate()); alarm.setResolvedDate(request.getResolvedDate()); MetadataProvider.copy(request.getMetadata(), alarm); return alarm; }
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IDeviceAssignment source, Document target) { target.append(PROP_DEVICE_ID, source.getDeviceId()); target.append(PROP_DEVICE_TYPE_ID, source.getDeviceTypeId()); target.append(PROP_CUSTOMER_ID, source.getCustomerId()); target.append(PROP_AREA_ID, source.getAreaId()); target.append(PROP_ASSET_ID, source.getAssetId()); if (source.getActiveDate() != null) { target.append(PROP_ACTIVE_DATE, source.getActiveDate()); } if (source.getReleasedDate() != null) { target.append(PROP_RELEASED_DATE, source.getReleasedDate()); } if (source.getStatus() != null) { target.append(PROP_STATUS, source.getStatus().name()); } MongoPersistentEntity.toDocument(source, target); }
target.setCustomerId(assignment.getCustomerId()); target.setAreaId(assignment.getAreaId()); target.setAssetId(assignment.getAssetId());
result.setAssignmentType(source.getAssignmentType()); result.setAssetModuleId(source.getAssetModuleId()); result.setAssetId(source.getAssetId()); MetadataProviderEntity.copy(source, result); if (source.getState() != null) { IAsset asset = manager.getAssetById(source.getAssetModuleId(), source.getAssetId()); if (asset != null) { result.setAssetName(asset.getName());
if (assignment.getAssetId() != null) { BoundStatement eventByAsset = getCassandraEventManagementClient().getInsertDeviceEventByAsset().bind(); binder.bind(getCassandraEventManagementClient(), eventByAsset, event);
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IDeviceAssignment source, Document target) { if (source.getActiveDate() != null) { target.append(PROP_ACTIVE_DATE, source.getActiveDate()); } target.append(PROP_ASSET_MODULE_ID, source.getAssetModuleId()); target.append(PROP_ASSET_ID, source.getAssetId()); if (source.getAssignmentType() != null) { target.append(PROP_ASSIGNMENT_TYPE, source.getAssignmentType().name()); } if (source.getReleasedDate() != null) { target.append(PROP_RELEASED_DATE, source.getReleasedDate()); } if (source.getStatus() != null) { target.append(PROP_STATUS, source.getStatus().name()); } target.append(PROP_TOKEN, source.getToken()); target.append(PROP_DEVICE_HARDWARE_ID, source.getDeviceHardwareId()); target.append(PROP_SITE_TOKEN, source.getSiteToken()); if (source.getState() != null) { setState(source.getState(), target); } MongoSiteWhereEntity.toDocument(source, target); MongoMetadataProvider.toDocument(source, target); }