@ApiOperation(value = "Upload binary data via multipart encoding for the current logged in user", response = String.class)
@Deprecated
public String uploadToBodytrack(@ApiParam(value="The device to upload the data for", required=true) @FormParam("dev_nickname") String deviceNickname,
@ApiParam(value="JSON encoded array of channels being uploaded for", required=true) @FormParam("channel_names") String channels,
@ApiParam(value="Multipart form data to be uploaded", required=true) @FormParam("data") String data){
StatusModel status;
try{
long guestId = AuthHelper.getGuestId();
Type channelsType = new TypeToken<Collection<String>>(){}.getType();
List<List<Object>> parsedData = new ArrayList<List<Object>>();
//Gson doesn't seem to be able to handle arrays with mixed types nicely
//This will parse through the array, we don't need much error checking because we want this to fail if the data is malformed
JsonElement element = new JsonParser().parse(data);
for (JsonElement e : element.getAsJsonArray()){
List<Object> currentList = new ArrayList<Object>();
parsedData.add(currentList);
for (JsonElement dataPoint : e.getAsJsonArray()){
if (dataPoint instanceof JsonNull){
currentList.add(null);
}
else{
JsonPrimitive primitive = dataPoint.getAsJsonPrimitive();
if (primitive.isBoolean()){
currentList.add(primitive.getAsBoolean());
}
else if (primitive.isString()){
currentList.add(primitive.getAsString());
}
else{
currentList.add(primitive.getAsDouble());
}
}
}
}
final BodyTrackHelper.BodyTrackUploadResult uploadResult = bodyTrackHelper.uploadToBodyTrack(guestId, deviceNickname, (Collection<String>)gson.fromJson(channels, channelsType), parsedData);
if (uploadResult instanceof BodyTrackHelper.ParsedBodyTrackUploadResult){
BodyTrackHelper.ParsedBodyTrackUploadResult parsedResult = (BodyTrackHelper.ParsedBodyTrackUploadResult) uploadResult;
List<ApiKey> keys = guestService.getApiKeys(guestId,Connector.getConnector("fluxtream_capture"));
long apiKeyId = -1;
if (keys.size() > 0){
apiKeyId = keys.get(0).getId();
}
dataUpdateService.logBodyTrackDataUpdate(guestId,apiKeyId,null,parsedResult);
}
status = createStatusModelFromBodyTrackUploadResult(uploadResult);
}
catch (Exception e){
status = new StatusModel(false,"Upload failed!");
}
return gson.toJson(status);
}