Skip to content

Commit

Permalink
video data saved even with null title
Browse files Browse the repository at this point in the history
  • Loading branch information
YitziG committed May 7, 2020
1 parent 718ec99 commit ca50f83
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface VideoClient {

Status getStatus(String videoId) throws ResponseException;

UploadedVideo create(Video videoInput) throws ResponseException;
UploadedVideo createVideoContainer(Video video) throws ResponseException;

UploadedVideo upload(File file) throws ResponseException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,11 @@ public Status getStatus(String videoId) throws ResponseException {
return statusDeserializer.deserialize(responseBody.getObject());
}

public UploadedVideo create(Video videoInput) throws ResponseException {
if (videoInput.title == null) {
videoInput.title = "";
}

public UploadedVideo createVideoContainer(Video video) throws ResponseException {
RequestBuilder request = requestBuilderFactory
.create(POST, "/videos")
.withJson(serializer.serialize(videoInput));

.withJson(serializer.serialize(video));
JsonNode responseBody = requestExecutor.executeJson(request);

return deserializer.deserialize(responseBody.getObject());
}

Expand All @@ -77,29 +71,24 @@ public UploadedVideo upload(File file, UploadProgressListener listener) throws R
return upload(file, new Video(), listener);
}

public UploadedVideo upload(File file, Video videoInput) throws ResponseException {
if (videoInput.title == null) {
return upload(file);
}
public UploadedVideo upload(File file, Video video) throws ResponseException {

return upload(file, videoInput, null);
return upload(file, video, null);
}

public UploadedVideo upload(File file, Video videoInput, UploadProgressListener listener) throws ResponseException {
public UploadedVideo upload(File file, Video video, UploadProgressListener listener) throws ResponseException {
if (!file.exists() || !file.isFile()) {
throw new IllegalArgumentException("Can't open file.");
}
String videoId;
if (videoInput instanceof UploadedVideo) {
videoId = ((UploadedVideo) videoInput).videoId;
}
else {
if (videoInput.title == null) {
videoInput.title = file.getName();

if (isNewVideo(video)) {
if (video.title == null) {
video.title = file.getName();
}
videoId = create(videoInput).videoId;
video = createVideoContainer(video);
}

String videoId = ((UploadedVideo) video).videoId;
int fileLength = (int) file.length();

try {
Expand Down Expand Up @@ -181,6 +170,10 @@ public Iterable<UploadedVideo> list(QueryParams queryParams) throws ResponseExce
), new PageQuery()));
}

private boolean isNewVideo(Video video) {
return !(video instanceof UploadedVideo);
}

/////////////////////////Iterators//////////////////////////////

private JsonNode uploadMultipleRequests(File file, UploadProgressListener listener, String videoId, int fileLength) throws IOException, ResponseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void create() throws ResponseException {
Video videoInput = new Video();
videoInput.title = "foo";

client.create(videoInput);
client.createVideoContainer(videoInput);

HttpRequest request = inspector.buildRequest();

Expand Down

0 comments on commit ca50f83

Please sign in to comment.