/** * 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); }
/** * 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(); }