-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(iot-dev): Deprecate existing upload to blob APIs in favor of more granular APIs #808
Changes from 3 commits
5b4902a
9bcf8ef
f9a4799
961d67b
6dc9f68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
package com.microsoft.azure.sdk.iot.deps.serializer; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.annotations.Expose; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** | ||
* The request payload to send to IoT Hub to notify it when a file upload is completed, whether successful or not. | ||
* Must set {@link #setSuccess(Boolean)} and {@link #setCorrelationId(String)}, but all other fields are optional. | ||
*/ | ||
public class FileUploadCompletionNotification | ||
{ | ||
private static final String CORRELATION_ID_TAG = "correlationId"; | ||
@Expose(serialize = true, deserialize = true) | ||
@SerializedName(CORRELATION_ID_TAG) | ||
private String correlationId = null; | ||
|
||
private static final String IS_SUCCESS_TAG = "isSuccess"; | ||
@Expose(serialize = true, deserialize = true) | ||
@SerializedName(IS_SUCCESS_TAG) | ||
private Boolean isSuccess = null; | ||
|
||
private static final String STATUS_CODE_TAG = "statusCode"; | ||
@Expose(serialize = true, deserialize = true) | ||
@SerializedName(STATUS_CODE_TAG) | ||
private Integer statusCode = null; | ||
|
||
private static final String STATUS_DESCRIPTION_TAG = "statusDescription"; | ||
@Expose(serialize = true, deserialize = true) | ||
@SerializedName(STATUS_DESCRIPTION_TAG) | ||
private String statusDescription = null; | ||
|
||
/** | ||
* Create an instance of the FileUploadCompletionNotification for a single file upload operation using Azure Storage. | ||
* | ||
* @param correlationId the correlationId that correlates this FileUploadCompletionNotification to the earlier request to get the SAS URI | ||
* for this upload from IoT Hub. This field is mandatory. Must equal {@link FileUploadSasUriResponse#getCorrelationId()}. | ||
* @param isSuccess whether the file was uploaded successfully. This field is mandatory. | ||
* @throws IllegalArgumentException if one of the parameters is null, empty, or not valid. | ||
*/ | ||
public FileUploadCompletionNotification(String correlationId, Boolean isSuccess) | ||
throws IllegalArgumentException | ||
{ | ||
setCorrelationId(correlationId); | ||
updateStatus(isSuccess, statusCode, statusDescription); | ||
} | ||
|
||
/** | ||
* Create an instance of the FileUploadCompletionNotification for a single file upload operation using Azure Storage. | ||
* | ||
* @param correlationId the correlationId that correlates this FileUploadCompletionNotification to the earlier request to get the SAS URI | ||
* for this upload from IoT Hub. This field is mandatory. Must equal {@link FileUploadSasUriResponse#getCorrelationId()}. | ||
* @param isSuccess whether the file was uploaded successfully. This field is mandatory. | ||
* @param statusCode is the status for the upload of the file to storage. | ||
* @param statusDescription is the description of the status code. | ||
* @throws IllegalArgumentException if one of the parameters is null, empty, or not valid. | ||
*/ | ||
public FileUploadCompletionNotification(String correlationId, Boolean isSuccess, Integer statusCode, String statusDescription) | ||
throws IllegalArgumentException | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this 'throws' needed since the method doesn't throw anything? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, there is nothing thrown here anymore so I'll update the method signature and the javadocs |
||
{ | ||
setCorrelationId(correlationId); | ||
updateStatus(isSuccess, statusCode, statusDescription); | ||
} | ||
|
||
/** | ||
* Construct this notification with json | ||
* @param json the json to parse. | ||
*/ | ||
public FileUploadCompletionNotification(String json) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because IllegalArgumentException is a runtime exception, so java methods don't need to declare them. https://www.tutorialspoint.com/how-to-handle-the-runtime-exception-in-java |
||
Gson gson = new GsonBuilder().disableHtmlEscaping().serializeNulls().create(); | ||
FileUploadCompletionNotification fileUploadCompletionNotification; | ||
|
||
try | ||
{ | ||
fileUploadCompletionNotification = gson.fromJson(json, FileUploadCompletionNotification.class); | ||
} | ||
catch (Exception malformed) | ||
{ | ||
throw new IllegalArgumentException("Malformed json:" + malformed); | ||
} | ||
|
||
this.correlationId = fileUploadCompletionNotification.getCorrelationId(); | ||
this.isSuccess = fileUploadCompletionNotification.getSuccess(); | ||
this.statusCode = fileUploadCompletionNotification.getStatusCode(); | ||
this.statusDescription = fileUploadCompletionNotification.getStatusDescription(); | ||
} | ||
|
||
/** | ||
* Update the status information in the collection, and return the new json. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment says the method return the new job. Method signature does not not return anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why we had javadoc for a private method, so I'll just delete the whole thing |
||
* | ||
* @param isSuccess is a Boolean representing whether the file was uploaded successfully. | ||
* @param statusCode is the status for the upload of the file to storage. | ||
* @param statusDescription is the description of the status code. | ||
* @throws IllegalArgumentException if one of the parameters is null, empty, or not valid. | ||
*/ | ||
private void updateStatus(Boolean isSuccess, Integer statusCode, String statusDescription) throws IllegalArgumentException | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing is thrown in this method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above, I'll delete this javadoc |
||
{ | ||
this.isSuccess = isSuccess; | ||
this.statusCode = statusCode; | ||
this.statusDescription = statusDescription; | ||
} | ||
|
||
/** | ||
* Convert this class in a valid json. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'to' a valid json. |
||
* | ||
* @return a valid json that represents the content of this class. | ||
*/ | ||
public String toJson() | ||
{ | ||
Gson gson = new GsonBuilder().disableHtmlEscaping().serializeNulls().create(); | ||
|
||
return gson.toJson(this); | ||
} | ||
|
||
/** | ||
* Set the correlationId that correlates this FileUploadCompletionNotification to the earlier request to get the SAS URI | ||
* for this upload from IoT Hub. Must equal {@link FileUploadSasUriResponse#getCorrelationId()}. | ||
* @param correlationId the unique identifier that correlates this file upload status to a SAS URI that IoT Hub retreived from Azure Storage earlier. | ||
*/ | ||
public void setCorrelationId(String correlationId) | ||
{ | ||
this.correlationId = correlationId; | ||
} | ||
|
||
/** | ||
* @return Get the correlationId that correlates this FileUploadCompletionNotification to the earlier request to get the SAS URI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this description describes the API and not the return value. Maybe remove the 'Get'? |
||
*/ | ||
public String getCorrelationId() | ||
{ | ||
return this.correlationId; | ||
} | ||
|
||
/** | ||
* @return Get if the file upload was successful | ||
*/ | ||
public Boolean getSuccess() | ||
{ | ||
return this.isSuccess; | ||
} | ||
|
||
/** | ||
* Set if the file upload was a success | ||
* @param success true if the file upload was a success. False otherwise. | ||
*/ | ||
public void setSuccess(Boolean success) | ||
{ | ||
this.isSuccess = success; | ||
} | ||
|
||
/** | ||
* @return get the status code associated with this file upload. | ||
*/ | ||
public Integer getStatusCode() | ||
{ | ||
return this.statusCode; | ||
} | ||
|
||
/** | ||
* Set the status code associated with this file upload request | ||
* @param statusCode The status code associated with this file upload request | ||
*/ | ||
public void setStatusCode(Integer statusCode) | ||
{ | ||
this.statusCode = statusCode; | ||
} | ||
|
||
/** | ||
* @return get the status description associated with this file upload. | ||
*/ | ||
public String getStatusDescription() | ||
{ | ||
return this.statusDescription; | ||
} | ||
|
||
/** | ||
* Set the status description associated with this file upload request | ||
* @param statusDescription The status description associated with this file upload request | ||
*/ | ||
public void setStatusDescription(String statusDescription) | ||
{ | ||
this.statusDescription = statusDescription; | ||
} | ||
|
||
/** | ||
* Empty constructor: Used only to keep GSON happy. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you need a @SuppressWarnings("unused") for this constructor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This repo doesn't really pay much attention to warnings, so no |
||
public FileUploadCompletionNotification() | ||
{ | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this 'throws' needed since the method doesn't throw anything?