Skip to content
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

Add FavoriteInfo to Photo and Video models #1362

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
154e8ec
First changelist description
aksingh737 Apr 21, 2023
1ab1f67
Merge remote-tracking branch 'origin/master' into master-dtp
aksingh737 Sep 6, 2023
13fcba5
Merge remote-tracking branch 'upstream/master' into master-dtp
aksingh737 Sep 7, 2023
7dd9fc8
Merge remote-tracking branch 'upstream/master' into master-dtp
aksingh737 Sep 29, 2023
debf243
Merge remote-tracking branch 'upstream/master' into master-dtp
aksingh737 Oct 24, 2023
36bfb5f
Merge remote-tracking branch 'upstream/master' into master-dtp
aksingh737 Nov 15, 2023
09bb4d9
Merge remote-tracking branch 'upstream/master' into master-dtp
aksingh737 Nov 27, 2023
9be9ff9
Fixes upload time bug. Upload time wasn't being populated
aksingh737 Nov 28, 2023
df1de36
Merge branch 'master' of https://github.com/google/data-transfer-project
aksingh737 Nov 28, 2023
7671b3e
Merge branch 'master' of github.com:aksingh737/data-transfer-project …
aksingh737 Nov 28, 2023
330465f
remove unused code
aksingh737 Nov 28, 2023
ec8d12f
remove en secrets
aksingh737 Nov 28, 2023
b70332d
remove useless changelist
aksingh737 Nov 28, 2023
5dc41e7
Merge pull request #1 from aksingh737/uploadTimeBug
aksingh737 Nov 28, 2023
d450001
adressed the comments on the changelist
aksingh737 Nov 29, 2023
b1feaa9
Merge pull request #2 from aksingh737/uploadTimeBug
aksingh737 Nov 29, 2023
c66c0ae
fix tests
aksingh737 Nov 29, 2023
67fe6f9
Merge pull request #3 from aksingh737/uploadTimeBug
aksingh737 Nov 29, 2023
ff50623
Merge remote-tracking branch 'origin/master'
aksingh737 Jan 3, 2024
d355dae
Merge remote-tracking branch 'origin/master'
aksingh737 Jan 9, 2024
d8470ec
Merge remote-tracking branch 'origin/master'
aksingh737 Feb 1, 2024
6f9fead
Merge remote-tracking branch 'origin/master'
aksingh737 Mar 14, 2024
754a5e9
Correct the idempotentId for videos which prevented the duplicated vi…
aksingh737 Mar 21, 2024
b7562c8
Merge pull request #4 from aksingh737/dupe_fix
aksingh737 Mar 21, 2024
8f1755c
refactor the test to verify that the correct idempotent id is set
aksingh737 Mar 21, 2024
9bbe992
Merge pull request #5 from aksingh737/dupe_fix
aksingh737 Mar 21, 2024
f1dee9f
Merge branch 'master' into master
kateyeo Mar 21, 2024
58b1a55
Merge branch 'google:master' into dupe_fix
aksingh737 Mar 21, 2024
4d5cc63
Return dataID for VideoModels when getDataID is called
aksingh737 Mar 21, 2024
f7b2efd
Merge pull request #6 from aksingh737/dupe_fix
aksingh737 Mar 21, 2024
9b3b78b
Refactor test to check for idempotentId in the executor
aksingh737 Mar 21, 2024
6e8cf1e
Merge branch 'google:master' into master
aksingh737 Mar 21, 2024
9c94db2
Merge pull request #7 from aksingh737/dupe_fix
aksingh737 Mar 21, 2024
d23ba66
Refactor AppleVideosImporterTest to use idempotentId for videos asser…
aksingh737 Mar 21, 2024
ab404fb
Merge pull request #8 from aksingh737/dupe_fix
aksingh737 Mar 21, 2024
e34709f
nitfix:indent
aksingh737 Mar 21, 2024
06eec44
Merge pull request #9 from aksingh737/dupe_fix
aksingh737 Mar 21, 2024
1ec9508
Merge branch 'google:master' into master
aksingh737 Apr 30, 2024
102c092
Merge branch 'google:master' into master
aksingh737 May 20, 2024
990bcd2
Merge branch 'google:master' into master
aksingh737 May 31, 2024
adf07d5
Add FavoriteInfo To Photo and Video models
aksingh737 Jun 3, 2024
80df12f
Add a default constructor for FavoriteInfo
aksingh737 Jun 5, 2024
4cdb116
Add methods to clarify favoriteInfo population for when the informati…
aksingh737 Jun 10, 2024
088f313
Use the correct method to populate favorite info. Use unfavoritedAt m…
aksingh737 Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Optional;
import org.datatransferproject.types.common.models.photos.PhotoModel;
import org.datatransferproject.types.common.models.videos.VideoModel;
import org.datatransferproject.types.common.models.FavoriteInfo;
import org.apache.tika.Tika;
import com.google.common.base.Strings;

Expand Down Expand Up @@ -68,6 +69,9 @@ public class GoogleMediaItem implements Serializable {
// services use to display the photos timeline, instead of uploadTime.
private Date uploadedTime;

@JsonProperty("favoriteInfo")
private FavoriteInfo favoriteInfo;

public boolean isPhoto() {
return this.getMediaMetadata().getPhoto() != null;
}
Expand Down Expand Up @@ -99,7 +103,8 @@ public static VideoModel convertToVideoModel(
mediaItem.getId(),
albumId.orElse(null),
false /*inTempStore*/,
getCreationTime(mediaItem));
getCreationTime(mediaItem),
new FavoriteInfo(getFavorite(mediaItem), getLastUpdateTime(mediaItem)));
}

public static PhotoModel convertToPhotoModel (
Expand All @@ -115,7 +120,8 @@ public static PhotoModel convertToPhotoModel (
albumId.orElse(null),
false /*inTempStore*/,
null /*sha1*/,
getCreationTime(mediaItem));
getCreationTime(mediaItem),
new FavoriteInfo(getFavorite(mediaItem), getLastUpdateTime(mediaItem)));
}

/**
Expand Down Expand Up @@ -235,4 +241,16 @@ public Date getUploadedTime() {
public void setUploadedTime(Date date) {
this.uploadedTime = date;
}
}

public void setFavoriteInfo(FavoriteInfo favoriteInfo) {
this.favoriteInfo = favoriteInfo;
}
public static boolean getFavorite(GoogleMediaItem mediaItem) {
return mediaItem.favoriteInfo != null && mediaItem.favoriteInfo.getFavorited();
}

public static Date getLastUpdateTime(GoogleMediaItem mediaItem) throws ParseException {
return (mediaItem.favoriteInfo == null || mediaItem.favoriteInfo.getLastUpdateTime() == null)
? getCreationTime(mediaItem) : mediaItem.favoriteInfo.getLastUpdateTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import org.datatransferproject.types.common.models.FavoriteInfo;
import org.datatransferproject.types.common.models.photos.PhotoModel;
import org.datatransferproject.types.common.models.videos.VideoModel;
import org.junit.Test;
Expand Down Expand Up @@ -188,6 +189,75 @@ public void getUploadTime_photoModel() throws ParseException {
photoModel.getUploadedTime(), GoogleMediaItem.parseIso8601DateTime(fakePhotosApiTimestamp));
}

@Test
public void getFavoriteStateAndTime_favoriteInfoUnset_videoModel() throws ParseException {
String fakePhotosApiTimestamp = "2023-10-02T22:33:38Z";
GoogleMediaItem videoMediaItem = getVideoMediaItem();
MediaMetadata metadata = new MediaMetadata();
metadata.setVideo(new Video());
// CreationTime in GoogleMediaItem is populated as uploadTime in our common models.
metadata.setCreationTime(fakePhotosApiTimestamp);
videoMediaItem.setMediaMetadata(metadata);

VideoModel videoModel = GoogleMediaItem.convertToVideoModel(Optional.empty(), videoMediaItem);

assertEquals(
videoModel.getUploadedTime(), GoogleMediaItem.parseIso8601DateTime(fakePhotosApiTimestamp));
}

@Test
public void getFavoriteStateAndTime_favoriteInfoUnset_photoModel() throws ParseException {
String fakePhotosApiTimestamp = "2014-10-02T15:01:23.045123456Z";

GoogleMediaItem photoMediaItem = getPhotoMediaItem();
MediaMetadata metadata = new MediaMetadata();
metadata.setPhoto(new Photo());
// CreationTime in GoogleMediaItem is populated as uploadTime in our common models.
metadata.setCreationTime(fakePhotosApiTimestamp);
photoMediaItem.setMediaMetadata(metadata);

PhotoModel photoModel = GoogleMediaItem.convertToPhotoModel(Optional.empty(), photoMediaItem);

assertEquals(
photoModel.getUploadedTime(), GoogleMediaItem.parseIso8601DateTime(fakePhotosApiTimestamp));
}

@Test
public void getFavoriteStateAndTime_favoriteInfoset_videoModel() throws ParseException {
Date favoriteTimestamp = GoogleMediaItem.parseIso8601DateTime("2023-10-02T22:33:38Z");
GoogleMediaItem videoMediaItem = getVideoMediaItem();
MediaMetadata metadata = new MediaMetadata();
metadata.setVideo(new Video());
metadata.setCreationTime("2022-10-02T22:33:38Z");
videoMediaItem.setMediaMetadata(metadata);
videoMediaItem.setFavoriteInfo(new FavoriteInfo(true, favoriteTimestamp));
VideoModel videoModel = GoogleMediaItem.convertToVideoModel(Optional.empty(), videoMediaItem);

assertEquals(
videoModel.getFavoriteInfo().getLastUpdateTime(), favoriteTimestamp);
assertEquals(
videoModel.getFavoriteInfo().getFavorited(), true);
}

@Test
public void getFavoriteStateAndTime_favoriteInfoSet_photoModel() throws ParseException {
Date favoriteTimestamp = GoogleMediaItem.parseIso8601DateTime("2023-10-02T22:33:38Z");

GoogleMediaItem photoMediaItem = getPhotoMediaItem();
MediaMetadata metadata = new MediaMetadata();
metadata.setPhoto(new Photo());
metadata.setCreationTime("2022-10-02T22:33:38Z");
photoMediaItem.setFavoriteInfo(new FavoriteInfo(true, favoriteTimestamp));
photoMediaItem.setMediaMetadata(metadata);

PhotoModel photoModel = GoogleMediaItem.convertToPhotoModel(Optional.empty(), photoMediaItem);

assertEquals(
photoModel.getFavoriteInfo().getLastUpdateTime(), favoriteTimestamp);
assertEquals(
photoModel.getFavoriteInfo().getFavorited(), true);
}

public static GoogleMediaItem getPhotoMediaItem() {
MediaMetadata photoMetadata = new MediaMetadata();
photoMetadata.setPhoto(new Photo());
Expand Down Expand Up @@ -217,4 +287,4 @@ public static GoogleMediaItem getVideoMediaItem() {
videoMediaItem.setMediaMetadata(videoMetadata);
return videoMediaItem;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.datatransferproject.types.common.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.util.Date;

/** FavoriteInfo about a {@code MediaItem}. */
public class FavoriteInfo implements Serializable {

@JsonProperty("favorite")
private boolean favorited;

/* the most recent time when the favorite state was changed or set. For new items, this field
* might be set to the item creation time.
*/
@JsonProperty("lastUpdateTime")
private Date lastUpdateTime;

public FavoriteInfo(){
}

public FavoriteInfo(boolean favorited, Date lastUpdateTime)
{
this.favorited = favorited;
this.lastUpdateTime = lastUpdateTime;
}

/* Expected possibly true IFF lastUpdatedTime field is populated. */
public boolean getFavorited() {
return favorited;
}

public Date getLastUpdateTime() {
return lastUpdateTime;
}

public void setFavorited(boolean favorited) {
this.favorited = favorited;
}

public void setLastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}

public static FavoriteInfo unknown() {
return new FavoriteInfo(false /*favorited*/, null /*lastUpdateTime*/);
}

public static FavoriteInfo unfavoritedAt(Date lastUpdateTime) {
return new FavoriteInfo(false /*favorited*/, lastUpdateTime );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.datatransferproject.types.common.DownloadableFile;
import org.datatransferproject.types.common.models.FavoriteInfo;

public class PhotoModel implements DownloadableFile {

Expand All @@ -42,6 +43,8 @@ public class PhotoModel implements DownloadableFile {
// services use to display the photos timeline, instead of uploadTime.
private Date uploadedTime;

private FavoriteInfo favoriteInfo;

@JsonCreator
public PhotoModel(
@JsonProperty("title") String title,
Expand All @@ -52,7 +55,8 @@ public PhotoModel(
@JsonProperty("albumId") String albumId,
@JsonProperty("inTempStore") boolean inTempStore,
@Nullable @JsonProperty("sha1") String sha1,
@JsonProperty("uploadedTime") Date uploadedTime) {
@JsonProperty("uploadedTime") Date uploadedTime,
@JsonProperty("favoriteInfo") FavoriteInfo favoriteInfo) {
this.title = title;
this.fetchableUrl = fetchableUrl;
this.description = description;
Expand All @@ -65,6 +69,7 @@ public PhotoModel(
this.inTempStore = inTempStore;
this.sha1 = sha1;
this.uploadedTime = uploadedTime;
this.favoriteInfo = favoriteInfo;
}

public PhotoModel(
Expand All @@ -85,7 +90,8 @@ public PhotoModel(
albumId,
inTempStore,
/* sha1= */ null,
uploadedTime);
uploadedTime,
FavoriteInfo.unfavoritedAt(uploadedTime));
}

public PhotoModel(
Expand All @@ -95,7 +101,7 @@ public PhotoModel(
String mediaType,
String dataId,
String albumId,
boolean inTempStore) {
boolean inTempStore){
this(
title,
fetchableUrl,
Expand All @@ -105,7 +111,9 @@ public PhotoModel(
albumId,
inTempStore,
/* sha1= */ null,
/* uploadedTime= */ null);
/* uploadedTime= */ null,
FavoriteInfo.unknown());

}

public PhotoModel(
Expand All @@ -126,9 +134,34 @@ public PhotoModel(
albumId,
inTempStore,
sha1,
/*uploadedTime=*/ null);
/*uploadedTime=*/ null,
FavoriteInfo.unknown());
}

public PhotoModel(
String title,
String fetchableUrl,
String description,
String mediaType,
String dataId,
String albumId,
boolean inTempStore,
String sha1,
Date uploadedTime){
this(
title,
fetchableUrl,
description,
mediaType,
dataId,
albumId,
inTempStore,
sha1,
uploadedTime,
FavoriteInfo.unfavoritedAt(uploadedTime));
}


// TODO(zacsh) convert all callers to ImportableItem#getName() which is an interface guarantee of this class's
// being a DownloadableItem. Then delete this method.
public String getTitle() {
Expand Down Expand Up @@ -179,6 +212,11 @@ public String getSha1() {
return sha1;
}

public FavoriteInfo getFavoriteInfo()
{
return favoriteInfo;
}

// remove all forbidden characters
public void cleanTitle(String forbiddenCharacters, char replacementCharacter, int maxLength) {
title = title.chars()
Expand Down Expand Up @@ -216,13 +254,13 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
PhotoModel that = (PhotoModel) o;
return Objects.equal(getTitle(), that.getTitle()) &&
Objects.equal(getFetchableUrl(), that.getFetchableUrl()) &&
Objects.equal(getDescription(), that.getDescription()) &&
Objects.equal(getMediaType(), that.getMediaType()) &&
Objects.equal(getDataId(), that.getDataId()) &&
Objects.equal(getAlbumId(), that.getAlbumId()) &&
Objects.equal(getSha1(), that.getSha1()) &&
Objects.equal(getUploadedTime(), that.getUploadedTime());
Objects.equal(getFetchableUrl(), that.getFetchableUrl()) &&
Objects.equal(getDescription(), that.getDescription()) &&
Objects.equal(getMediaType(), that.getMediaType()) &&
Objects.equal(getDataId(), that.getDataId()) &&
Objects.equal(getAlbumId(), that.getAlbumId()) &&
Objects.equal(getSha1(), that.getSha1()) &&
Objects.equal(getUploadedTime(), that.getUploadedTime());
}

@Override
Expand All @@ -249,4 +287,4 @@ public String getIdempotentId() {
public String getName() {
return getTitle();
}
}
}
Loading
Loading