diff --git a/extensions/auth/portability-auth-daybook/src/main/java/org/datatransferproject/auth/daybook/DaybookOAuthConfig.java b/extensions/auth/portability-auth-daybook/src/main/java/org/datatransferproject/auth/daybook/DaybookOAuthConfig.java index 412fa6fa1..e0390a3d8 100644 --- a/extensions/auth/portability-auth-daybook/src/main/java/org/datatransferproject/auth/daybook/DaybookOAuthConfig.java +++ b/extensions/auth/portability-auth-daybook/src/main/java/org/datatransferproject/auth/daybook/DaybookOAuthConfig.java @@ -1,10 +1,13 @@ package org.datatransferproject.auth.daybook; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; import org.datatransferproject.auth.OAuth2Config; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that provides Daybook-specific information for OAuth2 @@ -27,12 +30,12 @@ public String getTokenUrl() { } @Override - public Map> getExportScopes() { - return ImmutableMap.of("PHOTOS", ImmutableSet.of("db.read")); + public Map> getExportScopes() { + return ImmutableMap.of(PHOTOS, ImmutableSet.of("db.read")); } @Override - public Map> getImportScopes() { - return ImmutableMap.of("PHOTOS", ImmutableSet.of("db.write")); + public Map> getImportScopes() { + return ImmutableMap.of(PHOTOS, ImmutableSet.of("db.write")); } -} \ No newline at end of file +} diff --git a/extensions/auth/portability-auth-deezer/src/main/java/org/datatransferproject/auth/deezer/DeezerOAuthConfig.java b/extensions/auth/portability-auth-deezer/src/main/java/org/datatransferproject/auth/deezer/DeezerOAuthConfig.java index 219a61df5..fcafd636b 100644 --- a/extensions/auth/portability-auth-deezer/src/main/java/org/datatransferproject/auth/deezer/DeezerOAuthConfig.java +++ b/extensions/auth/portability-auth-deezer/src/main/java/org/datatransferproject/auth/deezer/DeezerOAuthConfig.java @@ -16,9 +16,8 @@ package org.datatransferproject.auth.deezer; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; +import static org.datatransferproject.types.common.models.DataVertical.PLAYLISTS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.io.IOException; @@ -27,7 +26,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.datatransferproject.auth.OAuth2Config; -import org.datatransferproject.auth.OAuth2TokenResponse; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData; /** @@ -56,16 +55,16 @@ public String getTokenUrl() { // For descriptions of scopes see: https://developers.deezer.com/api/permissions @Override - public Map> getExportScopes() { - return ImmutableMap.>builder() - .put("PLAYLISTS", ImmutableSet.of("offline_access,manage_library")) + public Map> getExportScopes() { + return ImmutableMap.>builder() + .put(PLAYLISTS, ImmutableSet.of("offline_access,manage_library")) .build(); } @Override - public Map> getImportScopes() { - return ImmutableMap.>builder() - .put("PLAYLISTS", ImmutableSet.of("offline_access,manage_library")) + public Map> getImportScopes() { + return ImmutableMap.>builder() + .put(PLAYLISTS, ImmutableSet.of("offline_access,manage_library")) .build(); } diff --git a/extensions/auth/portability-auth-facebook/src/main/java/org/datatransferproject/auth/facebook/FacebookOAuthConfig.java b/extensions/auth/portability-auth-facebook/src/main/java/org/datatransferproject/auth/facebook/FacebookOAuthConfig.java index 735a73a8f..2839a8395 100644 --- a/extensions/auth/portability-auth-facebook/src/main/java/org/datatransferproject/auth/facebook/FacebookOAuthConfig.java +++ b/extensions/auth/portability-auth-facebook/src/main/java/org/datatransferproject/auth/facebook/FacebookOAuthConfig.java @@ -16,12 +16,16 @@ package org.datatransferproject.auth.facebook; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import org.datatransferproject.auth.OAuth2Config; import java.util.Map; import java.util.Set; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that supplies Facebook-specific OAuth2 info @@ -51,18 +55,18 @@ public String getTokenUrl() { } @Override - public Map> getExportScopes() { - return ImmutableMap.>builder() - .put("PHOTOS", ImmutableSet.of("user_photos")) - .put("VIDEOS", ImmutableSet.of("user_videos")) + public Map> getExportScopes() { + return ImmutableMap.>builder() + .put(PHOTOS, ImmutableSet.of("user_photos")) + .put(VIDEOS, ImmutableSet.of("user_videos")) .build(); } @Override - public Map> getImportScopes() { - return ImmutableMap.>builder() - .put("PHOTOS", ImmutableSet.of("user_photos")) - .put("VIDEOS", ImmutableSet.of("user_videos")) + public Map> getImportScopes() { + return ImmutableMap.>builder() + .put(PHOTOS, ImmutableSet.of("user_photos")) + .put(VIDEOS, ImmutableSet.of("user_videos")) .build(); } } diff --git a/extensions/auth/portability-auth-flickr/src/main/java/org/datatransferproject/auth/flickr/FlickrOAuthConfig.java b/extensions/auth/portability-auth-flickr/src/main/java/org/datatransferproject/auth/flickr/FlickrOAuthConfig.java index c6fd4dd31..b93938074 100644 --- a/extensions/auth/portability-auth-flickr/src/main/java/org/datatransferproject/auth/flickr/FlickrOAuthConfig.java +++ b/extensions/auth/portability-auth-flickr/src/main/java/org/datatransferproject/auth/flickr/FlickrOAuthConfig.java @@ -16,6 +16,8 @@ package org.datatransferproject.auth.flickr; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Collections; @@ -23,6 +25,7 @@ import java.util.Map; import org.datatransferproject.auth.OAuth1Config; import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that supplies Flickr-specific OAuth1 info @@ -53,19 +56,19 @@ public String getAccessTokenUrl() { } @Override - public List getExportTypes() { - return ImmutableList.of("PHOTOS"); + public List getExportTypes() { + return ImmutableList.of(PHOTOS); } @Override - public List getImportTypes() { - return ImmutableList.of("PHOTOS"); + public List getImportTypes() { + return ImmutableList.of(PHOTOS); } public Map getAdditionalUrlParameters( - String dataType, AuthMode mode, OAuth1Step step) { + DataVertical dataType, AuthMode mode, OAuth1Step step) { - if (dataType.equals("PHOTOS") && step == OAuth1Step.AUTHORIZATION) { + if (dataType.equals(PHOTOS) && step == OAuth1Step.AUTHORIZATION) { return (mode == AuthMode.EXPORT) ? ImmutableMap.of(PERMS, "read") : ImmutableMap.of(PERMS, "write"); diff --git a/extensions/auth/portability-auth-google/src/main/java/org/datatransferproject/auth/google/BloggerOAuthConfig.java b/extensions/auth/portability-auth-google/src/main/java/org/datatransferproject/auth/google/BloggerOAuthConfig.java index fb24466d6..c56ec801d 100644 --- a/extensions/auth/portability-auth-google/src/main/java/org/datatransferproject/auth/google/BloggerOAuthConfig.java +++ b/extensions/auth/portability-auth-google/src/main/java/org/datatransferproject/auth/google/BloggerOAuthConfig.java @@ -16,10 +16,13 @@ package org.datatransferproject.auth.google; +import static org.datatransferproject.types.common.models.DataVertical.SOCIAL_POSTS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that supplies Google Blogger-specific OAuth2 info, this is needed so because multiple @@ -36,17 +39,17 @@ public String getServiceName() { // See https://developers.google.com/identity/protocols/googlescopes @Override - public Map> getExportScopes() { - return ImmutableMap.>builder() - .put("SOCIAL-POSTS", ImmutableSet.of("https://www.googleapis.com/auth/blogger.readonly")) + public Map> getExportScopes() { + return ImmutableMap.>builder() + .put(SOCIAL_POSTS, ImmutableSet.of("https://www.googleapis.com/auth/blogger.readonly")) .build(); } // See https://developers.google.com/identity/protocols/googlescopes @Override - public Map> getImportScopes() { - return ImmutableMap.>builder() - .put("SOCIAL-POSTS", ImmutableSet.of( + public Map> getImportScopes() { + return ImmutableMap.>builder() + .put(SOCIAL_POSTS, ImmutableSet.of( "https://www.googleapis.com/auth/blogger", // Any photos associated with the blog are stored in Drive. // This permission only grants access to files created by this app @@ -54,4 +57,4 @@ public Map> getImportScopes() { )) .build(); } -} \ No newline at end of file +} diff --git a/extensions/auth/portability-auth-google/src/main/java/org/datatransferproject/auth/google/GoogleOAuthConfig.java b/extensions/auth/portability-auth-google/src/main/java/org/datatransferproject/auth/google/GoogleOAuthConfig.java index 829c5d83a..0626fdb54 100644 --- a/extensions/auth/portability-auth-google/src/main/java/org/datatransferproject/auth/google/GoogleOAuthConfig.java +++ b/extensions/auth/portability-auth-google/src/main/java/org/datatransferproject/auth/google/GoogleOAuthConfig.java @@ -16,11 +16,21 @@ package org.datatransferproject.auth.google; +import static org.datatransferproject.types.common.models.DataVertical.BLOBS; +import static org.datatransferproject.types.common.models.DataVertical.CALENDAR; +import static org.datatransferproject.types.common.models.DataVertical.CONTACTS; +import static org.datatransferproject.types.common.models.DataVertical.MAIL; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.SOCIAL_POSTS; +import static org.datatransferproject.types.common.models.DataVertical.TASKS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; import org.datatransferproject.auth.OAuth2Config; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that supplies Google-specific OAuth2 info @@ -48,31 +58,31 @@ public String getTokenUrl() { // See https://developers.google.com/identity/protocols/googlescopes @Override - public Map> getExportScopes() { - return ImmutableMap.>builder() - .put("BLOBS", ImmutableSet.of("https://www.googleapis.com/auth/drive.readonly")) - .put("CALENDAR", ImmutableSet.of("https://www.googleapis.com/auth/calendar.readonly")) - .put("CONTACTS", ImmutableSet.of("https://www.googleapis.com/auth/contacts.readonly")) - .put("MAIL", ImmutableSet.of("https://www.googleapis.com/auth/gmail.readonly")) - .put("PHOTOS", ImmutableSet.of("https://www.googleapis.com/auth/photoslibrary.readonly")) + public Map> getExportScopes() { + return ImmutableMap.>builder() + .put(BLOBS, ImmutableSet.of("https://www.googleapis.com/auth/drive.readonly")) + .put(CALENDAR, ImmutableSet.of("https://www.googleapis.com/auth/calendar.readonly")) + .put(CONTACTS, ImmutableSet.of("https://www.googleapis.com/auth/contacts.readonly")) + .put(MAIL, ImmutableSet.of("https://www.googleapis.com/auth/gmail.readonly")) + .put(PHOTOS, ImmutableSet.of("https://www.googleapis.com/auth/photoslibrary.readonly")) // For G+ - .put("SOCIAL-POSTS", ImmutableSet.of("https://www.googleapis.com/auth/plus.login")) - .put("TASKS", ImmutableSet.of("https://www.googleapis.com/auth/tasks.readonly")) - .put("VIDEOS", ImmutableSet.of("https://www.googleapis.com/auth/photoslibrary.readonly")) + .put(SOCIAL_POSTS, ImmutableSet.of("https://www.googleapis.com/auth/plus.login")) + .put(TASKS, ImmutableSet.of("https://www.googleapis.com/auth/tasks.readonly")) + .put(VIDEOS, ImmutableSet.of("https://www.googleapis.com/auth/photoslibrary.readonly")) .build(); } // See https://developers.google.com/identity/protocols/googlescopes @Override - public Map> getImportScopes() { - return ImmutableMap.>builder() - .put("BLOBS", ImmutableSet.of("https://www.googleapis.com/auth/drive")) - .put("CALENDAR", ImmutableSet.of("https://www.googleapis.com/auth/calendar")) - .put("CONTACTS", ImmutableSet.of("https://www.googleapis.com/auth/contacts")) - .put("MAIL", ImmutableSet.of("https://www.googleapis.com/auth/gmail.modify")) - .put("PHOTOS", ImmutableSet.of("https://www.googleapis.com/auth/photoslibrary.appendonly")) - .put("TASKS", ImmutableSet.of("https://www.googleapis.com/auth/tasks")) - .put("VIDEOS", ImmutableSet.of("https://www.googleapis.com/auth/photoslibrary")) + public Map> getImportScopes() { + return ImmutableMap.>builder() + .put(BLOBS, ImmutableSet.of("https://www.googleapis.com/auth/drive")) + .put(CALENDAR, ImmutableSet.of("https://www.googleapis.com/auth/calendar")) + .put(CONTACTS, ImmutableSet.of("https://www.googleapis.com/auth/contacts")) + .put(MAIL, ImmutableSet.of("https://www.googleapis.com/auth/gmail.modify")) + .put(PHOTOS, ImmutableSet.of("https://www.googleapis.com/auth/photoslibrary.appendonly")) + .put(TASKS, ImmutableSet.of("https://www.googleapis.com/auth/tasks")) + .put(VIDEOS, ImmutableSet.of("https://www.googleapis.com/auth/photoslibrary")) .build(); } diff --git a/extensions/auth/portability-auth-harness-microsoft/src/main/java/org/datatransferproject/auth/microsoft/harness/AuthTestDriver.java b/extensions/auth/portability-auth-harness-microsoft/src/main/java/org/datatransferproject/auth/microsoft/harness/AuthTestDriver.java index f782a235d..93e6cbd28 100644 --- a/extensions/auth/portability-auth-harness-microsoft/src/main/java/org/datatransferproject/auth/microsoft/harness/AuthTestDriver.java +++ b/extensions/auth/portability-auth-harness-microsoft/src/main/java/org/datatransferproject/auth/microsoft/harness/AuthTestDriver.java @@ -14,6 +14,7 @@ import org.datatransferproject.spi.api.auth.AuthDataGenerator; import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; import org.datatransferproject.spi.api.types.AuthFlowConfiguration; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.transfer.auth.TokenAuthData; /** */ @@ -51,7 +52,7 @@ public TokenAuthData getOAuthTokenCode() throws Exception { OkHttpClient client = TestHelper.createTestBuilder(callbackHost).build(); AuthDataGenerator authDataGenerator = new MicrosoftAuthServiceExtension() - .getAuthDataGenerator("CONTACTS", AuthMode.EXPORT); + .getAuthDataGenerator(DataVertical.CONTACTS, AuthMode.EXPORT); AuthFlowConfiguration configuration = authDataGenerator .generateConfiguration(callbackBase, "1"); diff --git a/extensions/auth/portability-auth-imgur/src/main/java/org.datatransferproject.auth.imgur/ImgurOAuthConfig.java b/extensions/auth/portability-auth-imgur/src/main/java/org.datatransferproject.auth.imgur/ImgurOAuthConfig.java index c1ec4c448..94a761806 100644 --- a/extensions/auth/portability-auth-imgur/src/main/java/org.datatransferproject.auth.imgur/ImgurOAuthConfig.java +++ b/extensions/auth/portability-auth-imgur/src/main/java/org.datatransferproject.auth.imgur/ImgurOAuthConfig.java @@ -16,11 +16,14 @@ package org.datatransferproject.auth.imgur; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; import org.datatransferproject.auth.OAuth2Config; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that provides Imgur-specific information for OAuth2 @@ -45,12 +48,12 @@ public String getTokenUrl() { // Imgur doesn't require scopes @Override - public Map> getExportScopes() { - return ImmutableMap.of("PHOTOS", ImmutableSet.of("")); + public Map> getExportScopes() { + return ImmutableMap.of(PHOTOS, ImmutableSet.of("")); } @Override - public Map> getImportScopes() { - return ImmutableMap.of("PHOTOS", ImmutableSet.of("")); + public Map> getImportScopes() { + return ImmutableMap.of(PHOTOS, ImmutableSet.of("")); } } diff --git a/extensions/auth/portability-auth-instagram/src/main/java/org/datatransferproject/auth/instagram/InstagramOAuthConfig.java b/extensions/auth/portability-auth-instagram/src/main/java/org/datatransferproject/auth/instagram/InstagramOAuthConfig.java index 8a1587379..9ca4ca348 100644 --- a/extensions/auth/portability-auth-instagram/src/main/java/org/datatransferproject/auth/instagram/InstagramOAuthConfig.java +++ b/extensions/auth/portability-auth-instagram/src/main/java/org/datatransferproject/auth/instagram/InstagramOAuthConfig.java @@ -16,11 +16,14 @@ package org.datatransferproject.auth.instagram; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; import org.datatransferproject.auth.OAuth2Config; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that provides Instagram-specific information for OAuth2 @@ -46,13 +49,13 @@ public String getTokenUrl() { // See https://www.instagram.com/developer/authorization/ @Override - public Map> getExportScopes() { - return ImmutableMap.of("PHOTOS", ImmutableSet.of("basic")); + public Map> getExportScopes() { + return ImmutableMap.of(PHOTOS, ImmutableSet.of("basic")); } // Instagram does not provide an API for import; https://help.instagram.com/442418472487929 @Override - public Map> getImportScopes() { + public Map> getImportScopes() { return ImmutableMap.of(); } } diff --git a/extensions/auth/portability-auth-koofr/src/main/java/org/datatransferproject/auth/koofr/KoofrOAuthConfig.java b/extensions/auth/portability-auth-koofr/src/main/java/org/datatransferproject/auth/koofr/KoofrOAuthConfig.java index 9ef7621c2..e154e0aa3 100644 --- a/extensions/auth/portability-auth-koofr/src/main/java/org/datatransferproject/auth/koofr/KoofrOAuthConfig.java +++ b/extensions/auth/portability-auth-koofr/src/main/java/org/datatransferproject/auth/koofr/KoofrOAuthConfig.java @@ -16,11 +16,15 @@ package org.datatransferproject.auth.koofr; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; import org.datatransferproject.auth.OAuth2Config; +import org.datatransferproject.types.common.models.DataVertical; public class KoofrOAuthConfig implements OAuth2Config { @@ -40,19 +44,19 @@ public String getTokenUrl() { } @Override - public Map> getExportScopes() { + public Map> getExportScopes() { // NOTE: KoofrTransferExtension does not implement export at the moment - return ImmutableMap.>builder() - .put("PHOTOS", ImmutableSet.of("files.read")) - .put("VIDEOS", ImmutableSet.of("files.read")) + return ImmutableMap.>builder() + .put(PHOTOS, ImmutableSet.of("files.read")) + .put(VIDEOS, ImmutableSet.of("files.read")) .build(); } @Override - public Map> getImportScopes() { - return ImmutableMap.>builder() - .put("PHOTOS", ImmutableSet.of("files.import")) - .put("VIDEOS", ImmutableSet.of("files.import")) + public Map> getImportScopes() { + return ImmutableMap.>builder() + .put(PHOTOS, ImmutableSet.of("files.import")) + .put(VIDEOS, ImmutableSet.of("files.import")) .build(); } } diff --git a/extensions/auth/portability-auth-microsoft/src/main/java/org/datatransferproject/auth/microsoft/MicrosoftOAuthConfig.java b/extensions/auth/portability-auth-microsoft/src/main/java/org/datatransferproject/auth/microsoft/MicrosoftOAuthConfig.java index 7dcbab2dc..1e534412b 100644 --- a/extensions/auth/portability-auth-microsoft/src/main/java/org/datatransferproject/auth/microsoft/MicrosoftOAuthConfig.java +++ b/extensions/auth/portability-auth-microsoft/src/main/java/org/datatransferproject/auth/microsoft/MicrosoftOAuthConfig.java @@ -16,11 +16,17 @@ package org.datatransferproject.auth.microsoft; +import static org.datatransferproject.types.common.models.DataVertical.CALENDAR; +import static org.datatransferproject.types.common.models.DataVertical.CONTACTS; +import static org.datatransferproject.types.common.models.DataVertical.MAIL; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; import org.datatransferproject.auth.OAuth2Config; +import org.datatransferproject.types.common.models.DataVertical; public class MicrosoftOAuthConfig implements OAuth2Config { @@ -40,22 +46,22 @@ public String getTokenUrl() { } @Override - public Map> getExportScopes() { - return ImmutableMap.>builder() - .put("MAIL", ImmutableSet.of("user.read", "Mail.Read")) - .put("CONTACTS", ImmutableSet.of("user.read", "Contacts.Read")) - .put("CALENDAR", ImmutableSet.of("user.read", "Calendars.Read")) - .put("PHOTOS", ImmutableSet.of("user.read", "Files.Read")) + public Map> getExportScopes() { + return ImmutableMap.>builder() + .put(MAIL, ImmutableSet.of("user.read", "Mail.Read")) + .put(CONTACTS, ImmutableSet.of("user.read", "Contacts.Read")) + .put(CALENDAR, ImmutableSet.of("user.read", "Calendars.Read")) + .put(PHOTOS, ImmutableSet.of("user.read", "Files.Read")) .build(); } @Override - public Map> getImportScopes() { - return ImmutableMap.>builder() - .put("MAIL", ImmutableSet.of("user.read", "Mail.ReadWrite")) - .put("CONTACTS", ImmutableSet.of("user.read", "Contacts.ReadWrite")) - .put("CALENDAR", ImmutableSet.of("user.read", "Calendars.ReadWrite")) - .put("PHOTOS", ImmutableSet.of("user.read", "Files.ReadWrite")) + public Map> getImportScopes() { + return ImmutableMap.>builder() + .put(MAIL, ImmutableSet.of("user.read", "Mail.ReadWrite")) + .put(CONTACTS, ImmutableSet.of("user.read", "Contacts.ReadWrite")) + .put(CALENDAR, ImmutableSet.of("user.read", "Calendars.ReadWrite")) + .put(PHOTOS, ImmutableSet.of("user.read", "Files.ReadWrite")) .build(); } } diff --git a/extensions/auth/portability-auth-offline-demo/src/main/java/org/datatransferproject/auth/offline/OfflineDemoAuthServiceExtension.java b/extensions/auth/portability-auth-offline-demo/src/main/java/org/datatransferproject/auth/offline/OfflineDemoAuthServiceExtension.java index aed8f1a4d..614e635fe 100644 --- a/extensions/auth/portability-auth-offline-demo/src/main/java/org/datatransferproject/auth/offline/OfflineDemoAuthServiceExtension.java +++ b/extensions/auth/portability-auth-offline-demo/src/main/java/org/datatransferproject/auth/offline/OfflineDemoAuthServiceExtension.java @@ -15,13 +15,16 @@ */ package org.datatransferproject.auth.offline; +import static org.datatransferproject.types.common.models.DataVertical.OFFLINE_DATA; + import org.datatransferproject.api.launcher.ExtensionContext; import org.datatransferproject.spi.api.auth.AuthDataGenerator; -import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry; +import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension; import java.util.Collections; import java.util.List; +import org.datatransferproject.types.common.models.DataVertical; /** * Provides an extension that demonstrates how import of offline data can be implemented. @@ -32,7 +35,7 @@ public class OfflineDemoAuthServiceExtension implements AuthServiceExtension { private static final String SERVICE_ID = "OFFLINE-DEMO"; - private static final List SUPPORTED_SERVICES = Collections.singletonList("OFFLINE-DATA"); + private static final List SUPPORTED_SERVICES = Collections.singletonList(OFFLINE_DATA); @Override public String getServiceId() { @@ -41,17 +44,17 @@ public String getServiceId() { @Override public AuthDataGenerator getAuthDataGenerator( - String type, AuthServiceProviderRegistry.AuthMode mode) { + DataVertical type, AuthMode mode) { return new OfflineDemoAuthDataGenerator(); } @Override - public List getImportTypes() { + public List getImportTypes() { return SUPPORTED_SERVICES; } @Override - public List getExportTypes() { + public List getExportTypes() { return SUPPORTED_SERVICES; } diff --git a/extensions/auth/portability-auth-rememberthemilk/src/main/java/org/datatransferproject/auth/rememberthemilk/RememberTheMilkAuthServiceExtension.java b/extensions/auth/portability-auth-rememberthemilk/src/main/java/org/datatransferproject/auth/rememberthemilk/RememberTheMilkAuthServiceExtension.java index 8fd7b69a2..e11e6e697 100644 --- a/extensions/auth/portability-auth-rememberthemilk/src/main/java/org/datatransferproject/auth/rememberthemilk/RememberTheMilkAuthServiceExtension.java +++ b/extensions/auth/portability-auth-rememberthemilk/src/main/java/org/datatransferproject/auth/rememberthemilk/RememberTheMilkAuthServiceExtension.java @@ -24,19 +24,21 @@ import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.transfer.auth.AppCredentials; import java.io.IOException; import java.util.List; import static java.lang.String.format; +import static org.datatransferproject.types.common.models.DataVertical.TASKS; public class RememberTheMilkAuthServiceExtension implements AuthServiceExtension { private static final String RTM_KEY = "RTM_KEY"; private static final String RTM_SECRET = "RTM_SECRET"; private static final String SERVICE_ID = "REMEMBER_THE_MILK"; - private final List supportedServices = ImmutableList.of("TASKS"); + private final List supportedServices = ImmutableList.of(TASKS); private RememberTheMilkAuthDataGenerator importAuthDataGenerator; private RememberTheMilkAuthDataGenerator exportAuthDataGenerator; private boolean initialized = false; @@ -47,7 +49,7 @@ public String getServiceId() { } @Override - public AuthDataGenerator getAuthDataGenerator(String transferDataType, AuthMode mode) { + public AuthDataGenerator getAuthDataGenerator(DataVertical transferDataType, AuthMode mode) { Preconditions.checkArgument( initialized, "RememberTheMilkAuthServiceExtension is not initialized! Unable to retrieve AuthDataGenerator"); @@ -58,12 +60,12 @@ public AuthDataGenerator getAuthDataGenerator(String transferDataType, AuthMode } @Override - public List getImportTypes() { + public List getImportTypes() { return supportedServices; } @Override - public List getExportTypes() { + public List getExportTypes() { return supportedServices; } diff --git a/extensions/auth/portability-auth-smugmug/src/main/java/org/datatransferproject/auth/smugmug/SmugMugOAuthConfig.java b/extensions/auth/portability-auth-smugmug/src/main/java/org/datatransferproject/auth/smugmug/SmugMugOAuthConfig.java index 89b3bae50..25b9ad88e 100644 --- a/extensions/auth/portability-auth-smugmug/src/main/java/org/datatransferproject/auth/smugmug/SmugMugOAuthConfig.java +++ b/extensions/auth/portability-auth-smugmug/src/main/java/org/datatransferproject/auth/smugmug/SmugMugOAuthConfig.java @@ -16,6 +16,8 @@ package org.datatransferproject.auth.smugmug; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Collections; @@ -23,6 +25,7 @@ import java.util.Map; import org.datatransferproject.auth.OAuth1Config; import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that supplies SmugMug-specific OAuth1 info @@ -54,19 +57,19 @@ public String getAccessTokenUrl() { } @Override - public List getExportTypes() { - return ImmutableList.of("PHOTOS"); + public List getExportTypes() { + return ImmutableList.of(PHOTOS); } @Override - public List getImportTypes() { - return ImmutableList.of("PHOTOS"); + public List getImportTypes() { + return ImmutableList.of(PHOTOS); } public Map getAdditionalUrlParameters( - String dataType, AuthMode mode, OAuth1Step step) { + DataVertical dataType, AuthMode mode, OAuth1Step step) { - if (dataType.equals("PHOTOS") && step == OAuth1Step.AUTHORIZATION) { + if (dataType.equals(PHOTOS) && step == OAuth1Step.AUTHORIZATION) { return (mode == AuthMode.EXPORT) ? ImmutableMap.of(ACCESS, "Full", PERMISSIONS, "Read") : ImmutableMap.of(ACCESS, "Full", PERMISSIONS, "Add"); diff --git a/extensions/auth/portability-auth-spotify/src/main/java/org/datatransferproject/auth/spotify/SpotifyOAuthConfig.java b/extensions/auth/portability-auth-spotify/src/main/java/org/datatransferproject/auth/spotify/SpotifyOAuthConfig.java index e8e0e541c..05505bf1a 100644 --- a/extensions/auth/portability-auth-spotify/src/main/java/org/datatransferproject/auth/spotify/SpotifyOAuthConfig.java +++ b/extensions/auth/portability-auth-spotify/src/main/java/org/datatransferproject/auth/spotify/SpotifyOAuthConfig.java @@ -16,11 +16,14 @@ package org.datatransferproject.auth.spotify; +import static org.datatransferproject.types.common.models.DataVertical.PLAYLISTS; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; import org.datatransferproject.auth.OAuth2Config; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that supplies Spotify-specific OAuth2 info @@ -45,16 +48,16 @@ public String getTokenUrl() { } @Override - public Map> getExportScopes() { - return ImmutableMap.>builder() - .put("PLAYLISTS", ImmutableSet.of("playlist-read-private")) + public Map> getExportScopes() { + return ImmutableMap.>builder() + .put(PLAYLISTS, ImmutableSet.of("playlist-read-private")) .build(); } @Override - public Map> getImportScopes() { - return ImmutableMap.>builder() - .put("PLAYLISTS", ImmutableSet.of("playlist-modify-private")) + public Map> getImportScopes() { + return ImmutableMap.>builder() + .put(PLAYLISTS, ImmutableSet.of("playlist-modify-private")) .build(); } diff --git a/extensions/auth/portability-auth-twitter/src/main/java/org/datatransferproject/auth/twitter/TwitterOAuthConfig.java b/extensions/auth/portability-auth-twitter/src/main/java/org/datatransferproject/auth/twitter/TwitterOAuthConfig.java index 8a5712729..d5dc428d7 100644 --- a/extensions/auth/portability-auth-twitter/src/main/java/org/datatransferproject/auth/twitter/TwitterOAuthConfig.java +++ b/extensions/auth/portability-auth-twitter/src/main/java/org/datatransferproject/auth/twitter/TwitterOAuthConfig.java @@ -16,6 +16,8 @@ package org.datatransferproject.auth.twitter; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.Collections; @@ -23,6 +25,7 @@ import java.util.Map; import org.datatransferproject.auth.OAuth1Config; import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; +import org.datatransferproject.types.common.models.DataVertical; /** * Class that supplies Twitter-specific OAuth1 info @@ -54,19 +57,19 @@ public String getAccessTokenUrl() { } @Override - public List getExportTypes() { - return ImmutableList.of("PHOTOS"); + public List getExportTypes() { + return ImmutableList.of(PHOTOS); } @Override - public List getImportTypes() { - return ImmutableList.of("PHOTOS"); + public List getImportTypes() { + return ImmutableList.of(PHOTOS); } public Map getAdditionalUrlParameters( - String dataType, AuthMode mode, OAuth1Step step) { + DataVertical dataType, AuthMode mode, OAuth1Step step) { - if (dataType.equals("PHOTOS") && step == OAuth1Step.REQUEST_TOKEN) { + if (dataType.equals(PHOTOS) && step == OAuth1Step.REQUEST_TOKEN) { return (mode == AuthMode.EXPORT) ? ImmutableMap.of(X_AUTH_ACCESS_TYPE, "read") : ImmutableMap.of(X_AUTH_ACCESS_TYPE, "write"); diff --git a/extensions/cloud/portability-cloud-google/src/main/java/org/datatransferproject/cloud/google/GoogleDtpInternalMetricRecorder.java b/extensions/cloud/portability-cloud-google/src/main/java/org/datatransferproject/cloud/google/GoogleDtpInternalMetricRecorder.java index 58792d9f4..f3e6649ad 100644 --- a/extensions/cloud/portability-cloud-google/src/main/java/org/datatransferproject/cloud/google/GoogleDtpInternalMetricRecorder.java +++ b/extensions/cloud/portability-cloud-google/src/main/java/org/datatransferproject/cloud/google/GoogleDtpInternalMetricRecorder.java @@ -36,6 +36,7 @@ import java.io.IOException; import java.time.Duration; +import org.datatransferproject.types.common.models.DataVertical; /** * A {@link DtpInternalMetricRecorder} that writes metrics to Stackdriver. @@ -211,9 +212,9 @@ private void setupView(Measure measure, TagKey... keys) { } @Override - public void startedJob(String dataType, String exportService, String importService) { + public void startedJob(DataVertical dataType, String exportService, String importService) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_EXPORT_SERVICE, TagValue.create(exportService), TAG_METADATA) .put(KEY_IMPORT_SERVICE, TagValue.create(importService), TAG_METADATA) .build(); @@ -224,12 +225,12 @@ public void startedJob(String dataType, String exportService, String importServi @Override public void exportPageAttemptFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_EXPORT_SERVICE, TagValue.create(service), TAG_METADATA) .put(KEY_SUCCESS, TagValue.create(Boolean.toString(success)), TAG_METADATA) .build(); @@ -243,12 +244,12 @@ public void exportPageAttemptFinished( @Override public void exportPageFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_EXPORT_SERVICE, TagValue.create(service), TAG_METADATA) .put(KEY_SUCCESS, TagValue.create(Boolean.toString(success)), TAG_METADATA) .build(); @@ -262,12 +263,12 @@ public void exportPageFinished( @Override public void importPageAttemptFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_IMPORT_SERVICE, TagValue.create(service), TAG_METADATA) .put(KEY_SUCCESS, TagValue.create(Boolean.toString(success)), TAG_METADATA) .build(); @@ -281,12 +282,12 @@ public void importPageAttemptFinished( @Override public void importPageFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_IMPORT_SERVICE, TagValue.create(service), TAG_METADATA) .put(KEY_SUCCESS, TagValue.create(Boolean.toString(success)), TAG_METADATA) .build(); @@ -300,13 +301,13 @@ public void importPageFinished( @Override public void finishedJob( - String dataType, + DataVertical dataType, String exportService, String importService, boolean success, Duration duration) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_EXPORT_SERVICE, TagValue.create(exportService), TAG_METADATA) .put(KEY_IMPORT_SERVICE, TagValue.create(importService), TAG_METADATA) .put(KEY_SUCCESS, TagValue.create(Boolean.toString(success)), TAG_METADATA) @@ -320,19 +321,19 @@ public void finishedJob( } @Override - public void cancelledJob(String dataType, String exportService, String importService, Duration duration) { + public void cancelledJob(DataVertical dataType, String exportService, String importService, Duration duration) { // Need Google folks to implement the necessary changes here. } @Override - public void recordGenericMetric(String dataType, String service, String tag) { + public void recordGenericMetric(DataVertical dataType, String service, String tag) { recordGenericMetric(dataType, service, tag, 1); } @Override - public void recordGenericMetric(String dataType, String service, String tag, boolean bool) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, boolean bool) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_GENERIC_SERVICE, TagValue.create(service), TAG_METADATA) .put(KEY_GENERIC_TAG, TagValue.create(tag), TAG_METADATA) .put(KEY_GENERIC_BOOL, TagValue.create(Boolean.toString(bool)), TAG_METADATA) @@ -345,9 +346,9 @@ public void recordGenericMetric(String dataType, String service, String tag, boo } @Override - public void recordGenericMetric(String dataType, String service, String tag, Duration duration) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, Duration duration) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_GENERIC_SERVICE, TagValue.create(service), TAG_METADATA) .put(KEY_GENERIC_TAG, TagValue.create(tag), TAG_METADATA) .build(); @@ -359,9 +360,9 @@ public void recordGenericMetric(String dataType, String service, String tag, Dur } @Override - public void recordGenericMetric(String dataType, String service, String tag, int value) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, int value) { TagContext tctx = tagger.emptyBuilder() - .put(KEY_DATA_TYPE, TagValue.create(dataType), TAG_METADATA) + .put(KEY_DATA_TYPE, TagValue.create(dataType.getDataType()), TAG_METADATA) .put(KEY_GENERIC_SERVICE, TagValue.create(service), TAG_METADATA) .put(KEY_GENERIC_TAG, TagValue.create(tag), TAG_METADATA) .build(); diff --git a/extensions/cloud/portability-cloud-microsoft/src/main/java/org/datatransferproject/cloud/microsoft/cosmos/AzureDtpInternalMetricRecorder.java b/extensions/cloud/portability-cloud-microsoft/src/main/java/org/datatransferproject/cloud/microsoft/cosmos/AzureDtpInternalMetricRecorder.java index 0373bedd4..bdf714b9c 100644 --- a/extensions/cloud/portability-cloud-microsoft/src/main/java/org/datatransferproject/cloud/microsoft/cosmos/AzureDtpInternalMetricRecorder.java +++ b/extensions/cloud/portability-cloud-microsoft/src/main/java/org/datatransferproject/cloud/microsoft/cosmos/AzureDtpInternalMetricRecorder.java @@ -21,6 +21,7 @@ import org.datatransferproject.api.launcher.Monitor; import java.time.Duration; +import org.datatransferproject.types.common.models.DataVertical; /** * A placeholder {@link DtpInternalMetricRecorder} that simply logs metrics @@ -35,7 +36,7 @@ class AzureDtpInternalMetricRecorder implements DtpInternalMetricRecorder { } @Override - public void startedJob(String dataType, String exportService, String importService) { + public void startedJob(DataVertical dataType, String exportService, String importService) { monitor.debug( () -> format( @@ -45,7 +46,7 @@ public void startedJob(String dataType, String exportService, String importServi @Override public void exportPageAttemptFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { @@ -59,7 +60,7 @@ public void exportPageAttemptFinished( @Override public void exportPageFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { @@ -72,7 +73,7 @@ public void exportPageFinished( @Override public void importPageAttemptFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { @@ -86,7 +87,7 @@ public void importPageAttemptFinished( @Override public void importPageFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { @@ -99,7 +100,7 @@ public void importPageFinished( @Override public void finishedJob( - String dataType, + DataVertical dataType, String exportService, String importService, boolean success, @@ -112,7 +113,7 @@ public void finishedJob( } @Override - public void cancelledJob(String dataType, String exportService, String importService, Duration duration) { + public void cancelledJob(DataVertical dataType, String exportService, String importService, Duration duration) { monitor.debug( () -> format("Metric: cancelledJob, data type: %s, from: %s, to: %s, duration: %s", @@ -121,14 +122,14 @@ public void cancelledJob(String dataType, String exportService, String importSer } @Override - public void recordGenericMetric(String dataType, String service, String tag) { + public void recordGenericMetric(DataVertical dataType, String service, String tag) { monitor.debug( () -> format("Metric: Generic, data type: %s, service: %s, tag: %s", dataType, service, tag)); } @Override - public void recordGenericMetric(String dataType, String service, String tag, boolean bool) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, boolean bool) { monitor.debug( () -> format( @@ -137,7 +138,7 @@ public void recordGenericMetric(String dataType, String service, String tag, boo } @Override - public void recordGenericMetric(String dataType, String service, String tag, Duration duration) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, Duration duration) { monitor.debug( () -> format( @@ -146,7 +147,7 @@ public void recordGenericMetric(String dataType, String service, String tag, Dur } @Override - public void recordGenericMetric(String dataType, String service, String tag, int value) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, int value) { monitor.debug( () -> format( diff --git a/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/BackblazeTransferExtension.java b/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/BackblazeTransferExtension.java index f793d12dd..46d3d5a69 100644 --- a/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/BackblazeTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/BackblazeTransferExtension.java @@ -16,6 +16,9 @@ package org.datatransferproject.datatransfer.backblaze; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; + import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -26,6 +29,7 @@ import org.datatransferproject.datatransfer.backblaze.photos.BackblazePhotosImporter; import org.datatransferproject.datatransfer.backblaze.videos.BackblazeVideosImporter; import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -33,9 +37,9 @@ public class BackblazeTransferExtension implements TransferExtension { public static final String SERVICE_ID = "Backblaze"; - private static final List SUPPORTED_TYPES = ImmutableList.of("PHOTOS", "VIDEOS"); + private static final List SUPPORTED_TYPES = ImmutableList.of(PHOTOS, VIDEOS); - private ImmutableMap importerMap; + private ImmutableMap importerMap; private boolean initialized = false; @Override @@ -44,13 +48,13 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { //TODO: Implement exporters as per https://github.com/google/data-transfer-project/issues/960 throw new IllegalArgumentException(); } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "Trying to call getImporter before initalizing BackblazeTransferExtension"); Preconditions.checkArgument( @@ -70,17 +74,17 @@ public void initialize(ExtensionContext context) { TemporaryPerJobDataStore jobStore = context.getService(TemporaryPerJobDataStore.class); - ImmutableMap.Builder importerBuilder = ImmutableMap.builder(); + ImmutableMap.Builder importerBuilder = ImmutableMap.builder(); BackblazeDataTransferClientFactory backblazeDataTransferClientFactory = new BackblazeDataTransferClientFactory(monitor); ImageStreamProvider isProvider = new ImageStreamProvider(); importerBuilder.put( - "PHOTOS", + PHOTOS, new BackblazePhotosImporter( monitor, jobStore, isProvider, backblazeDataTransferClientFactory)); importerBuilder.put( - "VIDEOS", + VIDEOS, new BackblazeVideosImporter( monitor, jobStore, isProvider, backblazeDataTransferClientFactory)); importerMap = importerBuilder.build(); diff --git a/extensions/data-transfer/portability-data-transfer-daybook/src/main/java/org/datatransferproject/transfer/daybook/DaybookTransferExtension.java b/extensions/data-transfer/portability-data-transfer-daybook/src/main/java/org/datatransferproject/transfer/daybook/DaybookTransferExtension.java index 127892b8f..7cabc35e5 100644 --- a/extensions/data-transfer/portability-data-transfer-daybook/src/main/java/org/datatransferproject/transfer/daybook/DaybookTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-daybook/src/main/java/org/datatransferproject/transfer/daybook/DaybookTransferExtension.java @@ -16,6 +16,9 @@ package org.datatransferproject.transfer.daybook; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.SOCIAL_POSTS; + import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Preconditions; @@ -25,6 +28,7 @@ import org.datatransferproject.api.launcher.ExtensionContext; import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -37,11 +41,11 @@ public class DaybookTransferExtension implements TransferExtension { private static final String SERVICE_ID = "Daybook"; private static final String BASE_URL = "https://us-central1-diary-a77f6.cloudfunctions.net/post-daybook-dtp"; - private static final ImmutableList SUPPORTED_DATA_TYPES = - ImmutableList.of("PHOTOS", "SOCIAL-POSTS"); + private static final ImmutableList SUPPORTED_DATA_TYPES = + ImmutableList.of(PHOTOS, SOCIAL_POSTS); private boolean initialized = false; - private ImmutableMap> importerMap; + private ImmutableMap> importerMap; @Override public void initialize(ExtensionContext context) { @@ -56,12 +60,12 @@ public void initialize(ExtensionContext context) { OkHttpClient client = context.getService(OkHttpClient.class); TemporaryPerJobDataStore jobStore = context.getService(TemporaryPerJobDataStore.class); - ImmutableMap.Builder> importerBuilder = ImmutableMap.builder(); + ImmutableMap.Builder> importerBuilder = ImmutableMap.builder(); String exportService = JobMetadata.getExportService(); importerBuilder.put( - "PHOTOS", new DaybookPhotosImporter(monitor, client, jobStore, BASE_URL, exportService)); + PHOTOS, new DaybookPhotosImporter(monitor, client, jobStore, BASE_URL, exportService)); importerBuilder.put( - "SOCIAL-POSTS", new DaybookPostsImporter(monitor, client, mapper, BASE_URL, exportService)); + SOCIAL_POSTS, new DaybookPostsImporter(monitor, client, mapper, BASE_URL, exportService)); importerMap = importerBuilder.build(); initialized = true; } @@ -72,7 +76,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "DaybookTransferExtension is not initialized. Unable to get Importer"); Preconditions.checkArgument( @@ -82,7 +86,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { throw new IllegalArgumentException(); } } diff --git a/extensions/data-transfer/portability-data-transfer-deezer/src/main/java/org/datatransferproject/transfer/deezer/DeezerTransferExtension.java b/extensions/data-transfer/portability-data-transfer-deezer/src/main/java/org/datatransferproject/transfer/deezer/DeezerTransferExtension.java index c6a6e6c8a..376fdb1ed 100644 --- a/extensions/data-transfer/portability-data-transfer-deezer/src/main/java/org/datatransferproject/transfer/deezer/DeezerTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-deezer/src/main/java/org/datatransferproject/transfer/deezer/DeezerTransferExtension.java @@ -15,11 +15,14 @@ */ package org.datatransferproject.transfer.deezer; +import static org.datatransferproject.types.common.models.DataVertical.PLAYLISTS; + import com.google.api.client.http.HttpTransport; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.datatransferproject.api.launcher.ExtensionContext; import org.datatransferproject.api.launcher.Monitor; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -31,7 +34,7 @@ public class DeezerTransferExtension implements TransferExtension { - private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of("PLAYLISTS"); + private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of(PLAYLISTS); private Exporter exporter; private Importer importer; @@ -44,7 +47,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "DeezerTransferExtension not initialized. Unable to get Exporter"); Preconditions.checkArgument(SUPPORTED_DATA_TYPES.contains(transferDataType)); @@ -52,7 +55,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "DeezerTransferExtension not initialized. Unable to get Importer"); Preconditions.checkArgument(SUPPORTED_DATA_TYPES.contains(transferDataType)); diff --git a/extensions/data-transfer/portability-data-transfer-facebook/src/main/java/org/datatransferproject/transfer/facebook/FacebookTransferExtension.java b/extensions/data-transfer/portability-data-transfer-facebook/src/main/java/org/datatransferproject/transfer/facebook/FacebookTransferExtension.java index 114882f74..4746946a6 100644 --- a/extensions/data-transfer/portability-data-transfer-facebook/src/main/java/org/datatransferproject/transfer/facebook/FacebookTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-facebook/src/main/java/org/datatransferproject/transfer/facebook/FacebookTransferExtension.java @@ -16,6 +16,9 @@ package org.datatransferproject.transfer.facebook; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; + import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -24,6 +27,7 @@ import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -36,10 +40,10 @@ public class FacebookTransferExtension implements TransferExtension { private static final String SERVICE_ID = "Facebook"; private boolean initialized = false; - private static final ImmutableList SUPPORTED_SERVICES = - ImmutableList.of("PHOTOS", "VIDEOS"); - private ImmutableMap importerMap; - private ImmutableMap exporterMap; + private static final ImmutableList SUPPORTED_SERVICES = + ImmutableList.of(PHOTOS, VIDEOS); + private ImmutableMap importerMap; + private ImmutableMap exporterMap; @Override public String getServiceId() { @@ -47,14 +51,14 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument(initialized); Preconditions.checkArgument(SUPPORTED_SERVICES.contains(transferDataType)); return exporterMap.get(transferDataType); } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument(initialized); Preconditions.checkArgument(SUPPORTED_SERVICES.contains(transferDataType)); return importerMap.get(transferDataType); @@ -79,16 +83,16 @@ public void initialize(ExtensionContext context) { return; } - ImmutableMap.Builder importerBuilder = ImmutableMap.builder(); - importerBuilder.put("VIDEOS", new FacebookVideosImporter(appCredentials)); + ImmutableMap.Builder importerBuilder = ImmutableMap.builder(); + importerBuilder.put(VIDEOS, new FacebookVideosImporter(appCredentials)); importerMap = importerBuilder.build(); - ImmutableMap.Builder exporterBuilder = ImmutableMap.builder(); + ImmutableMap.Builder exporterBuilder = ImmutableMap.builder(); exporterBuilder.put( - "PHOTOS", + PHOTOS, new FacebookPhotosExporter( appCredentials, monitor, context.getService(TemporaryPerJobDataStore.class))); - exporterBuilder.put("VIDEOS", new FacebookVideosExporter(appCredentials, monitor)); + exporterBuilder.put(VIDEOS, new FacebookVideosExporter(appCredentials, monitor)); exporterMap = exporterBuilder.build(); initialized = true; diff --git a/extensions/data-transfer/portability-data-transfer-flickr/src/main/java/org/datatransferproject/datatransfer/flickr/FlickrTransferExtension.java b/extensions/data-transfer/portability-data-transfer-flickr/src/main/java/org/datatransferproject/datatransfer/flickr/FlickrTransferExtension.java index de6cd5d80..b524a00e7 100644 --- a/extensions/data-transfer/portability-data-transfer-flickr/src/main/java/org/datatransferproject/datatransfer/flickr/FlickrTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-flickr/src/main/java/org/datatransferproject/datatransfer/flickr/FlickrTransferExtension.java @@ -17,6 +17,7 @@ package org.datatransferproject.datatransfer.flickr; import static java.lang.String.format; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; @@ -27,6 +28,7 @@ import org.datatransferproject.datatransfer.flickr.photos.FlickrPhotosImporter; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -38,7 +40,7 @@ public class FlickrTransferExtension implements TransferExtension { private static final String FLICKR_KEY = "FLICKR_KEY"; private static final String FLICKR_SECRET = "FLICKR_SECRET"; - private final Set supportedServices = ImmutableSet.of("PHOTOS"); + private final Set supportedServices = ImmutableSet.of(PHOTOS); private Importer importer; private Exporter exporter; @@ -52,14 +54,14 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument(initialized); Preconditions.checkArgument(supportedServices.contains(transferDataType)); return exporter; } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument(initialized); Preconditions.checkArgument(supportedServices.contains(transferDataType)); return importer; diff --git a/extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/BloggerTransferExtension.java b/extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/BloggerTransferExtension.java index 1c3d44c3a..6f1d84de7 100644 --- a/extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/BloggerTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/BloggerTransferExtension.java @@ -16,6 +16,8 @@ package org.datatransferproject.datatransfer.google; +import static org.datatransferproject.types.common.models.DataVertical.SOCIAL_POSTS; + import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; import com.google.common.base.Preconditions; @@ -27,6 +29,7 @@ import org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter; import org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -43,10 +46,10 @@ public class BloggerTransferExtension implements TransferExtension { private static final String SERVICE_ID = "GoogleBlogger"; // TODO: centralized place, or enum type for these - private static final ImmutableList SUPPORTED_SERVICES = - ImmutableList.of("SOCIAL-POSTS"); - private ImmutableMap importerMap; - private ImmutableMap exporterMap; + private static final ImmutableList SUPPORTED_SERVICES = + ImmutableList.of(SOCIAL_POSTS); + private ImmutableMap importerMap; + private ImmutableMap exporterMap; private boolean initialized = false; @Override @@ -55,14 +58,14 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument(initialized); Preconditions.checkArgument(SUPPORTED_SERVICES.contains(transferDataType)); return exporterMap.get(transferDataType); } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument(initialized); Preconditions.checkArgument(SUPPORTED_SERVICES.contains(transferDataType)); return importerMap.get(transferDataType); @@ -98,13 +101,13 @@ public void initialize(ExtensionContext context) { GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor); - ImmutableMap.Builder importerBuilder = ImmutableMap.builder(); + ImmutableMap.Builder importerBuilder = ImmutableMap.builder(); - importerBuilder.put("SOCIAL-POSTS", new GoogleBloggerImporter(credentialFactory)); + importerBuilder.put(SOCIAL_POSTS, new GoogleBloggerImporter(credentialFactory)); importerMap = importerBuilder.build(); - ImmutableMap.Builder exporterBuilder = ImmutableMap.builder(); + ImmutableMap.Builder exporterBuilder = ImmutableMap.builder(); exporterMap = exporterBuilder.build(); diff --git a/extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/GoogleTransferExtension.java b/extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/GoogleTransferExtension.java index 4c6b61d8e..6ab47e0ea 100644 --- a/extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/GoogleTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/GoogleTransferExtension.java @@ -1,5 +1,14 @@ package org.datatransferproject.datatransfer.google; +import static org.datatransferproject.types.common.models.DataVertical.BLOBS; +import static org.datatransferproject.types.common.models.DataVertical.CALENDAR; +import static org.datatransferproject.types.common.models.DataVertical.CONTACTS; +import static org.datatransferproject.types.common.models.DataVertical.MAIL; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.SOCIAL_POSTS; +import static org.datatransferproject.types.common.models.DataVertical.TASKS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; + import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; import com.google.common.base.Preconditions; @@ -26,6 +35,7 @@ import org.datatransferproject.datatransfer.google.videos.GoogleVideosImporter; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; import org.datatransferproject.spi.cloud.storage.JobStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -38,11 +48,11 @@ public class GoogleTransferExtension implements TransferExtension { public static final String SERVICE_ID = "google"; // TODO: centralized place, or enum type for these - private static final ImmutableList SUPPORTED_SERVICES = + private static final ImmutableList SUPPORTED_SERVICES = ImmutableList.of( - "BLOBS", "CALENDAR", "CONTACTS", "MAIL", "PHOTOS", "SOCIAL-POSTS", "TASKS", "VIDEOS"); - private ImmutableMap importerMap; - private ImmutableMap exporterMap; + BLOBS, CALENDAR, CONTACTS, MAIL, PHOTOS, SOCIAL_POSTS, TASKS, VIDEOS); + private ImmutableMap importerMap; + private ImmutableMap exporterMap; private boolean initialized = false; @Override @@ -51,14 +61,14 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument(initialized); Preconditions.checkArgument(SUPPORTED_SERVICES.contains(transferDataType)); return exporterMap.get(transferDataType); } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument(initialized); Preconditions.checkArgument(SUPPORTED_SERVICES.contains(transferDataType)); return importerMap.get(transferDataType); @@ -95,33 +105,33 @@ public void initialize(ExtensionContext context) { GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor); - ImmutableMap.Builder importerBuilder = ImmutableMap.builder(); - importerBuilder.put("BLOBS", new DriveImporter(credentialFactory, jobStore, monitor)); - importerBuilder.put("CONTACTS", new GoogleContactsImporter(credentialFactory)); - importerBuilder.put("CALENDAR", new GoogleCalendarImporter(credentialFactory)); - importerBuilder.put("MAIL", new GoogleMailImporter(credentialFactory, monitor)); - importerBuilder.put("TASKS", new GoogleTasksImporter(credentialFactory)); + ImmutableMap.Builder importerBuilder = ImmutableMap.builder(); + importerBuilder.put(BLOBS, new DriveImporter(credentialFactory, jobStore, monitor)); + importerBuilder.put(CONTACTS, new GoogleContactsImporter(credentialFactory)); + importerBuilder.put(CALENDAR, new GoogleCalendarImporter(credentialFactory)); + importerBuilder.put(MAIL, new GoogleMailImporter(credentialFactory, monitor)); + importerBuilder.put(TASKS, new GoogleTasksImporter(credentialFactory)); importerBuilder.put( - "PHOTOS", + PHOTOS, new GooglePhotosImporter( credentialFactory, jobStore, jsonFactory, monitor, context.getSetting("googleWritesPerSecond", 1.0))); - importerBuilder.put("VIDEOS", new GoogleVideosImporter(appCredentials, jobStore, monitor)); + importerBuilder.put(VIDEOS, new GoogleVideosImporter(appCredentials, jobStore, monitor)); importerMap = importerBuilder.build(); - ImmutableMap.Builder exporterBuilder = ImmutableMap.builder(); - exporterBuilder.put("BLOBS", new DriveExporter(credentialFactory, jobStore, monitor)); - exporterBuilder.put("CONTACTS", new GoogleContactsExporter(credentialFactory)); - exporterBuilder.put("CALENDAR", new GoogleCalendarExporter(credentialFactory)); - exporterBuilder.put("MAIL", new GoogleMailExporter(credentialFactory)); - exporterBuilder.put("SOCIAL-POSTS", new GooglePlusExporter(credentialFactory)); - exporterBuilder.put("TASKS", new GoogleTasksExporter(credentialFactory, monitor)); + ImmutableMap.Builder exporterBuilder = ImmutableMap.builder(); + exporterBuilder.put(BLOBS, new DriveExporter(credentialFactory, jobStore, monitor)); + exporterBuilder.put(CONTACTS, new GoogleContactsExporter(credentialFactory)); + exporterBuilder.put(CALENDAR, new GoogleCalendarExporter(credentialFactory)); + exporterBuilder.put(MAIL, new GoogleMailExporter(credentialFactory)); + exporterBuilder.put(SOCIAL_POSTS, new GooglePlusExporter(credentialFactory)); + exporterBuilder.put(TASKS, new GoogleTasksExporter(credentialFactory, monitor)); exporterBuilder.put( - "PHOTOS", new GooglePhotosExporter(credentialFactory, jobStore, jsonFactory, monitor)); - exporterBuilder.put("VIDEOS", new GoogleVideosExporter(credentialFactory, jsonFactory)); + PHOTOS, new GooglePhotosExporter(credentialFactory, jobStore, jsonFactory, monitor)); + exporterBuilder.put(VIDEOS, new GoogleVideosExporter(credentialFactory, jsonFactory)); exporterMap = exporterBuilder.build(); diff --git a/extensions/data-transfer/portability-data-transfer-imgur/src/main/java/org/datatransferproject/datatransfer/imgur/ImgurTransferExtension.java b/extensions/data-transfer/portability-data-transfer-imgur/src/main/java/org/datatransferproject/datatransfer/imgur/ImgurTransferExtension.java index 784b2592d..1b514e7f0 100644 --- a/extensions/data-transfer/portability-data-transfer-imgur/src/main/java/org/datatransferproject/datatransfer/imgur/ImgurTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-imgur/src/main/java/org/datatransferproject/datatransfer/imgur/ImgurTransferExtension.java @@ -16,6 +16,8 @@ package org.datatransferproject.datatransfer.imgur; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Preconditions; @@ -26,6 +28,7 @@ import org.datatransferproject.datatransfer.imgur.photos.ImgurPhotosExporter; import org.datatransferproject.datatransfer.imgur.photos.ImgurPhotosImporter; import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -37,7 +40,7 @@ public class ImgurTransferExtension implements TransferExtension { private boolean initialized = false; - private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of("PHOTOS"); + private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of(PHOTOS); private ImgurPhotosExporter exporter; private ImgurPhotosImporter importer; @@ -67,7 +70,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "ImgurTransferExtension is not initialized. Unable to get Exporter"); Preconditions.checkArgument( @@ -77,7 +80,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "ImgurTransferExtension is not initialized. Unable to get Importer"); Preconditions.checkArgument( diff --git a/extensions/data-transfer/portability-data-transfer-instagram/src/main/java/org/datatransferproject/transfer/instagram/InstagramTransferExtension.java b/extensions/data-transfer/portability-data-transfer-instagram/src/main/java/org/datatransferproject/transfer/instagram/InstagramTransferExtension.java index 3958156d0..e18de3132 100644 --- a/extensions/data-transfer/portability-data-transfer-instagram/src/main/java/org/datatransferproject/transfer/instagram/InstagramTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-instagram/src/main/java/org/datatransferproject/transfer/instagram/InstagramTransferExtension.java @@ -15,6 +15,8 @@ */ package org.datatransferproject.transfer.instagram; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.api.client.http.HttpTransport; @@ -22,6 +24,7 @@ import com.google.common.collect.ImmutableList; import org.datatransferproject.api.launcher.ExtensionContext; import org.datatransferproject.api.launcher.Monitor; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -31,7 +34,7 @@ public class InstagramTransferExtension implements TransferExtension { - private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of("PHOTOS"); + private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of(PHOTOS); private Exporter exporter; @@ -43,7 +46,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "InstagramTransferExtension not initialized. Unable to get Exporter"); Preconditions.checkArgument(SUPPORTED_DATA_TYPES.contains(transferDataType)); @@ -51,7 +54,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "InstagramTransferExtension not initialized. Unable to get Importer"); Preconditions.checkArgument(false, "Instagram does not support import"); diff --git a/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/KoofrTransferExtension.java b/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/KoofrTransferExtension.java index 9febd8398..350efcc8b 100644 --- a/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/KoofrTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/KoofrTransferExtension.java @@ -1,6 +1,8 @@ package org.datatransferproject.transfer.koofr; import static java.lang.String.format; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.api.client.http.HttpTransport; @@ -15,6 +17,7 @@ import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; import org.datatransferproject.spi.cloud.storage.JobStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -29,15 +32,13 @@ /** Bootstraps the Koofr data transfer services. */ public class KoofrTransferExtension implements TransferExtension { public static final String SERVICE_ID = "koofr"; - private static final String PHOTOS = "PHOTOS"; - private static final String VIDEOS = "VIDEOS"; - private static final ImmutableList SUPPORTED_IMPORT_SERVICES = + private static final ImmutableList SUPPORTED_IMPORT_SERVICES = ImmutableList.of(PHOTOS, VIDEOS); - private static final ImmutableList SUPPORTED_EXPORT_SERVICES = + private static final ImmutableList SUPPORTED_EXPORT_SERVICES = ImmutableList.of(PHOTOS, VIDEOS); private static final String BASE_API_URL = "https://app.koofr.net"; - private ImmutableMap importerMap; - private ImmutableMap exporterMap; + private ImmutableMap importerMap; + private ImmutableMap exporterMap; private boolean initialized = false; // Needed for ServiceLoader to load this class. @@ -49,14 +50,14 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkState(initialized); Preconditions.checkArgument(SUPPORTED_EXPORT_SERVICES.contains(transferDataType)); return exporterMap.get(transferDataType); } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkState(initialized); Preconditions.checkArgument(SUPPORTED_IMPORT_SERVICES.contains(transferDataType)); return importerMap.get(transferDataType); @@ -114,12 +115,12 @@ public void initialize(ExtensionContext context) { new KoofrClientFactory( BASE_API_URL, client, fileUploadClient, mapper, monitor, credentialFactory); - ImmutableMap.Builder importBuilder = ImmutableMap.builder(); + ImmutableMap.Builder importBuilder = ImmutableMap.builder(); importBuilder.put(PHOTOS, new KoofrPhotosImporter(koofrClientFactory, monitor, jobStore)); importBuilder.put(VIDEOS, new KoofrVideosImporter(koofrClientFactory, monitor)); importerMap = importBuilder.build(); - ImmutableMap.Builder exportBuilder = ImmutableMap.builder(); + ImmutableMap.Builder exportBuilder = ImmutableMap.builder(); exportBuilder.put(PHOTOS, new KoofrPhotosExporter(koofrClientFactory, monitor)); exportBuilder.put(VIDEOS, new KoofrVideosExporter(koofrClientFactory, monitor)); exporterMap = exportBuilder.build(); diff --git a/extensions/data-transfer/portability-data-transfer-microsoft/src/main/java/org/datatransferproject/transfer/microsoft/MicrosoftTransferExtension.java b/extensions/data-transfer/portability-data-transfer-microsoft/src/main/java/org/datatransferproject/transfer/microsoft/MicrosoftTransferExtension.java index 0dee8bbe7..0ce3092fb 100644 --- a/extensions/data-transfer/portability-data-transfer-microsoft/src/main/java/org/datatransferproject/transfer/microsoft/MicrosoftTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-microsoft/src/main/java/org/datatransferproject/transfer/microsoft/MicrosoftTransferExtension.java @@ -1,5 +1,11 @@ package org.datatransferproject.transfer.microsoft; +import static org.datatransferproject.types.common.models.DataVertical.CALENDAR; +import static org.datatransferproject.types.common.models.DataVertical.CONTACTS; +import static org.datatransferproject.types.common.models.DataVertical.MEDIA; +import static org.datatransferproject.types.common.models.DataVertical.OFFLINE_DATA; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; @@ -10,8 +16,8 @@ import org.datatransferproject.api.launcher.ExtensionContext; import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; -import org.datatransferproject.spi.cloud.storage.JobStore; import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -34,22 +40,16 @@ /** Bootstraps the Microsoft data transfer services. */ public class MicrosoftTransferExtension implements TransferExtension { public static final String SERVICE_ID = "microsoft"; - // TODO(#1065) centralized place, or enum type for these? - private static final String CONTACTS = "CONTACTS"; - private static final String CALENDAR = "CALENDAR"; - private static final String PHOTOS = "PHOTOS"; - private static final String MEDIA = "MEDIA"; - private static final String OFFLINE_DATA = "OFFLINE-DATA"; // TODO(#1065) don't keep adding here - just have the converters invoked automatically when Media // isn't supported on one or the other side of this equation; this is just a WIP prototype to show // the concept of converters at play. - private static final ImmutableList SUPPORTED_IMPORT_SERVICES = + private static final ImmutableList SUPPORTED_IMPORT_SERVICES = ImmutableList.of(CALENDAR, CONTACTS, PHOTOS); - private static final ImmutableList SUPPORTED_EXPORT_SERVICES = + private static final ImmutableList SUPPORTED_EXPORT_SERVICES = ImmutableList.of(CALENDAR, CONTACTS, PHOTOS, MEDIA, OFFLINE_DATA); - private ImmutableMap importerMap; - private ImmutableMap exporterMap; + private ImmutableMap importerMap; + private ImmutableMap exporterMap; private static final String BASE_GRAPH_URL = "https://graph.microsoft.com"; @@ -68,7 +68,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkState(initialized); if (!offlineData && transferDataType.equals(OFFLINE_DATA)) { @@ -83,7 +83,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkState(initialized); Preconditions.checkArgument(SUPPORTED_IMPORT_SERVICES.contains(transferDataType)); return importerMap.get(transferDataType); @@ -123,7 +123,7 @@ public void initialize(ExtensionContext context) { Monitor monitor = context.getMonitor(); - ImmutableMap.Builder importBuilder = ImmutableMap.builder(); + ImmutableMap.Builder importBuilder = ImmutableMap.builder(); importBuilder.put( CONTACTS, new MicrosoftContactsImporter(BASE_GRAPH_URL, client, mapper, transformerService)); @@ -137,7 +137,7 @@ PHOTOS, new MicrosoftPhotosImporter(BASE_GRAPH_URL, client, mapper, jobStore, mo credentialFactory)); importerMap = importBuilder.build(); - ImmutableMap.Builder exporterBuilder = ImmutableMap.builder(); + ImmutableMap.Builder exporterBuilder = ImmutableMap.builder(); exporterBuilder.put( CONTACTS, new MicrosoftContactsExporter(BASE_GRAPH_URL, client, mapper, transformerService)); diff --git a/extensions/data-transfer/portability-data-transfer-microsoft/src/test/java/org/datatransferproject/transfer/microsoft/integration/LocalExportTestRunner.java b/extensions/data-transfer/portability-data-transfer-microsoft/src/test/java/org/datatransferproject/transfer/microsoft/integration/LocalExportTestRunner.java index 8568d8641..2e7d8357a 100644 --- a/extensions/data-transfer/portability-data-transfer-microsoft/src/test/java/org/datatransferproject/transfer/microsoft/integration/LocalExportTestRunner.java +++ b/extensions/data-transfer/portability-data-transfer-microsoft/src/test/java/org/datatransferproject/transfer/microsoft/integration/LocalExportTestRunner.java @@ -1,5 +1,7 @@ package org.datatransferproject.transfer.microsoft.integration; +import static org.datatransferproject.types.common.models.DataVertical.CONTACTS; + import java.util.Optional; import org.datatransferproject.auth.microsoft.harness.AuthTestDriver; import org.datatransferproject.spi.transfer.provider.ExportResult; @@ -22,7 +24,7 @@ public static void main(String... args) throws Exception { TokenAuthData token = authTestDriver.getOAuthTokenCode(); Exporter contacts = - (Exporter) serviceProvider.getExporter("CONTACTS"); + (Exporter) serviceProvider.getExporter(CONTACTS); ExportResult wrapper = contacts.export(UUID.randomUUID(), token, Optional.empty()); } diff --git a/extensions/data-transfer/portability-data-transfer-microsoft/src/test/java/org/datatransferproject/transfer/microsoft/integration/LocalImportTestRunner.java b/extensions/data-transfer/portability-data-transfer-microsoft/src/test/java/org/datatransferproject/transfer/microsoft/integration/LocalImportTestRunner.java index e0919384f..c39019747 100644 --- a/extensions/data-transfer/portability-data-transfer-microsoft/src/test/java/org/datatransferproject/transfer/microsoft/integration/LocalImportTestRunner.java +++ b/extensions/data-transfer/portability-data-transfer-microsoft/src/test/java/org/datatransferproject/transfer/microsoft/integration/LocalImportTestRunner.java @@ -15,6 +15,8 @@ */ package org.datatransferproject.transfer.microsoft.integration; +import static org.datatransferproject.types.common.models.DataVertical.CONTACTS; + import ezvcard.VCard; import ezvcard.io.json.JCardWriter; import ezvcard.property.StructuredName; @@ -40,7 +42,7 @@ public static void main(String... args) throws Exception { TokenAuthData token = authTestDriver.getOAuthTokenCode(); Importer contacts = - (Importer) serviceProvider.getImporter("CONTACTS"); + (Importer) serviceProvider.getImporter(CONTACTS); ContactsModelWrapper wrapper = new ContactsModelWrapper(createCards()); FakeIdempotentImportExecutor executor = new FakeIdempotentImportExecutor(); diff --git a/extensions/data-transfer/portability-data-transfer-offline-demo/src/main/java/org/datatransferproject/transfer/offline/OfflineDemoTransferExtension.java b/extensions/data-transfer/portability-data-transfer-offline-demo/src/main/java/org/datatransferproject/transfer/offline/OfflineDemoTransferExtension.java index a4adcaf63..b2c2d3596 100644 --- a/extensions/data-transfer/portability-data-transfer-offline-demo/src/main/java/org/datatransferproject/transfer/offline/OfflineDemoTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-offline-demo/src/main/java/org/datatransferproject/transfer/offline/OfflineDemoTransferExtension.java @@ -1,6 +1,7 @@ package org.datatransferproject.transfer.offline; import org.datatransferproject.api.launcher.ExtensionContext; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -19,12 +20,12 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { return null; } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { return new OfflineDemoImporter(); } diff --git a/extensions/data-transfer/portability-data-transfer-rememberthemilk/src/main/java/org/datatransferproject/transfer/rememberthemilk/RememberTheMilkTransferExtension.java b/extensions/data-transfer/portability-data-transfer-rememberthemilk/src/main/java/org/datatransferproject/transfer/rememberthemilk/RememberTheMilkTransferExtension.java index b8a2b3fff..fa1d400d2 100644 --- a/extensions/data-transfer/portability-data-transfer-rememberthemilk/src/main/java/org/datatransferproject/transfer/rememberthemilk/RememberTheMilkTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-rememberthemilk/src/main/java/org/datatransferproject/transfer/rememberthemilk/RememberTheMilkTransferExtension.java @@ -21,6 +21,7 @@ import org.datatransferproject.api.launcher.ExtensionContext; import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -31,9 +32,10 @@ import java.io.IOException; import static java.lang.String.format; +import static org.datatransferproject.types.common.models.DataVertical.TASKS; public class RememberTheMilkTransferExtension implements TransferExtension { - private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of("TASKS"); + private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of(TASKS); private static final String RTM_KEY = "RTM_KEY"; private static final String RTM_SECRET = "RTM_SECRET"; private RememberTheMilkTasksExporter exporter; @@ -46,7 +48,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "RememberTheMilkTransferExtension not initialized. Unable to get Exporter"); Preconditions.checkArgument(SUPPORTED_DATA_TYPES.contains(transferDataType)); @@ -54,7 +56,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "RememberTheMilkTransferExtension not initialized. Unable to get Importer"); Preconditions.checkArgument(SUPPORTED_DATA_TYPES.contains(transferDataType)); diff --git a/extensions/data-transfer/portability-data-transfer-smugmug/src/main/java/org/datatransferproject/transfer/smugmug/SmugMugTransferExtension.java b/extensions/data-transfer/portability-data-transfer-smugmug/src/main/java/org/datatransferproject/transfer/smugmug/SmugMugTransferExtension.java index e0a2e39e2..50e6e637f 100644 --- a/extensions/data-transfer/portability-data-transfer-smugmug/src/main/java/org/datatransferproject/transfer/smugmug/SmugMugTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-smugmug/src/main/java/org/datatransferproject/transfer/smugmug/SmugMugTransferExtension.java @@ -17,7 +17,6 @@ package org.datatransferproject.transfer.smugmug; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.api.client.http.HttpTransport; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import org.datatransferproject.api.launcher.ExtensionContext; @@ -25,6 +24,7 @@ import org.datatransferproject.api.launcher.TypeManager; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -35,10 +35,11 @@ import java.io.IOException; import static java.lang.String.format; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; public class SmugMugTransferExtension implements TransferExtension { - private static final ImmutableList SUPPORTED_TYPES = ImmutableList.of("PHOTOS"); + private static final ImmutableList SUPPORTED_TYPES = ImmutableList.of(PHOTOS); private static final String SMUGMUG_KEY = "SMUGMUG_KEY"; private static final String SMUGMUG_SECRET = "SMUGMUG_SECRET"; @@ -52,7 +53,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "Trying to call getExporter before initalizing SmugMugTransferExtension"); Preconditions.checkArgument( @@ -62,7 +63,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "Trying to call getImporter before initalizing SmugMugTransferExtension"); Preconditions.checkArgument( diff --git a/extensions/data-transfer/portability-data-transfer-spotify/src/main/java/org/datatransferproject/transfer/spotify/SpotifyTransferExtension.java b/extensions/data-transfer/portability-data-transfer-spotify/src/main/java/org/datatransferproject/transfer/spotify/SpotifyTransferExtension.java index f642efeca..98b1211f8 100644 --- a/extensions/data-transfer/portability-data-transfer-spotify/src/main/java/org/datatransferproject/transfer/spotify/SpotifyTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-spotify/src/main/java/org/datatransferproject/transfer/spotify/SpotifyTransferExtension.java @@ -15,6 +15,8 @@ */ package org.datatransferproject.transfer.spotify; +import static org.datatransferproject.types.common.models.DataVertical.PLAYLISTS; + import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.wrapper.spotify.SpotifyApi; @@ -22,6 +24,7 @@ import org.datatransferproject.api.launcher.ExtensionContext; import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -33,7 +36,7 @@ public class SpotifyTransferExtension implements TransferExtension { - private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of("PLAYLISTS"); + private static final ImmutableList SUPPORTED_DATA_TYPES = ImmutableList.of(PLAYLISTS); private Exporter exporter; private Importer importer; @@ -46,7 +49,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "SpotifyTransferExtension not initialized. Unable to get Exporter"); Preconditions.checkArgument(SUPPORTED_DATA_TYPES.contains(transferDataType)); @@ -54,7 +57,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "SpotifyTransferExtension not initialized. Unable to get Importer"); Preconditions.checkArgument(SUPPORTED_DATA_TYPES.contains(transferDataType)); diff --git a/extensions/data-transfer/portability-data-transfer-twitter/src/main/java/org/datatransferproject/transfer/twitter/TwitterTransferExtension.java b/extensions/data-transfer/portability-data-transfer-twitter/src/main/java/org/datatransferproject/transfer/twitter/TwitterTransferExtension.java index 43245766d..1ea173dfc 100644 --- a/extensions/data-transfer/portability-data-transfer-twitter/src/main/java/org/datatransferproject/transfer/twitter/TwitterTransferExtension.java +++ b/extensions/data-transfer/portability-data-transfer-twitter/src/main/java/org/datatransferproject/transfer/twitter/TwitterTransferExtension.java @@ -21,6 +21,7 @@ import org.datatransferproject.api.launcher.ExtensionContext; import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -30,6 +31,7 @@ import java.util.List; import static java.lang.String.format; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; /** * Extension to allow Twitter content to be transferred. @@ -39,7 +41,7 @@ *

In the future if a social vertical gets defined support should be added for that. */ public class TwitterTransferExtension implements TransferExtension { - private static final List SUPPORTED_TYPES = ImmutableList.of("PHOTOS"); + private static final List SUPPORTED_TYPES = ImmutableList.of(PHOTOS); private static final String TWITTER_KEY = "TWITTER_KEY"; private static final String TWITTER_SECRET = "TWITTER_SECRET"; @@ -53,7 +55,7 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "Trying to call getExporter before initalizing TwitterTransferExtension"); Preconditions.checkArgument( @@ -63,7 +65,7 @@ public String getServiceId() { } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { Preconditions.checkArgument( initialized, "Trying to call getImporter before initalizing TwitterTransferExtension"); Preconditions.checkArgument( diff --git a/extensions/transport/portability-transport-jettyrest/src/main/java/org/datatransferproject/transport/jettyrest/rest/TransferServicesController.java b/extensions/transport/portability-transport-jettyrest/src/main/java/org/datatransferproject/transport/jettyrest/rest/TransferServicesController.java index c01afd4fb..b7c9c3fed 100644 --- a/extensions/transport/portability-transport-jettyrest/src/main/java/org/datatransferproject/transport/jettyrest/rest/TransferServicesController.java +++ b/extensions/transport/portability-transport-jettyrest/src/main/java/org/datatransferproject/transport/jettyrest/rest/TransferServicesController.java @@ -25,6 +25,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.datatransferproject.types.common.models.DataVertical; /** Lists services available for export and import for the given type. */ @Consumes({MediaType.APPLICATION_JSON}) @@ -39,7 +40,7 @@ public TransferServicesController(Action @GET() @Path("{dataType}") - public TransferServices transferServices(@PathParam("dataType") String dataType) { + public TransferServices transferServices(@PathParam("dataType") DataVertical dataType) { return action.handle(new GetTransferServices(dataType)); } } diff --git a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1Config.java b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1Config.java index de800bca8..f6464e673 100644 --- a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1Config.java +++ b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1Config.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; +import org.datatransferproject.types.common.models.DataVertical; /** * Interface for providing information necessary to run OAuth1 flow @@ -50,13 +51,15 @@ public interface OAuth1Config { /** * Returns a list of export data types (e.g., PHOTOS, CALENDAR) this config is designed to support. + * @return */ - List getExportTypes(); + List getExportTypes(); /** * Returns a list of import data types (e.g., PHOTOS, CALENDAR) this config is designed to support. + * @return */ - List getImportTypes(); + List getImportTypes(); /** * Return a map of parameters that will be added to the OAuth request. @@ -68,7 +71,7 @@ public interface OAuth1Config { * privilege for the given mode (EXPORT, IMPORT) should be used. */ default Map getAdditionalUrlParameters( - String dataType, AuthMode mode, OAuth1Step step) { + DataVertical dataType, AuthMode mode, OAuth1Step step) { return Collections.emptyMap(); } diff --git a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1DataGenerator.java b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1DataGenerator.java index 8b5938666..f5e6d7e39 100644 --- a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1DataGenerator.java +++ b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1DataGenerator.java @@ -30,6 +30,7 @@ import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; import org.datatransferproject.spi.api.types.AuthFlowConfiguration; import org.datatransferproject.types.common.PortabilityCommon.AuthProtocol; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.transfer.auth.AppCredentials; import org.datatransferproject.types.transfer.auth.AuthData; import org.datatransferproject.types.transfer.auth.TokenSecretAuthData; @@ -41,7 +42,7 @@ public class OAuth1DataGenerator implements AuthDataGenerator { private final OAuth1Config config; private final Monitor monitor; - private final String dataType; + private final DataVertical dataType; private final AuthMode mode; // TODO: handle dynamic updates of client ids and secrets #597 private final String clientId; @@ -52,7 +53,7 @@ public class OAuth1DataGenerator implements AuthDataGenerator { OAuth1Config config, AppCredentials appCredentials, HttpTransport httpTransport, - String datatype, + DataVertical datatype, AuthMode mode, Monitor monitor) { this.config = config; diff --git a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1ServiceExtension.java b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1ServiceExtension.java index d8f201697..d5f9d4030 100644 --- a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1ServiceExtension.java +++ b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth1ServiceExtension.java @@ -30,6 +30,7 @@ import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.transfer.auth.AppCredentials; /** @@ -40,8 +41,8 @@ public class OAuth1ServiceExtension implements AuthServiceExtension { private final OAuth1Config oAuth1Config; - private volatile Map exportAuthDataGenerators; - private volatile Map importAuthDataGenerators; + private volatile Map exportAuthDataGenerators; + private volatile Map importAuthDataGenerators; private AppCredentials appCredentials; private HttpTransport httpTransport; @@ -59,17 +60,17 @@ public String getServiceId() { } @Override - public AuthDataGenerator getAuthDataGenerator(String transferDataType, AuthMode mode) { + public AuthDataGenerator getAuthDataGenerator(DataVertical transferDataType, AuthMode mode) { return getOrCreateAuthDataGenerator(transferDataType, mode); } @Override - public List getImportTypes() { + public List getImportTypes() { return oAuth1Config.getImportTypes(); } @Override - public List getExportTypes() { + public List getExportTypes() { return oAuth1Config.getExportTypes(); } @@ -105,14 +106,14 @@ public void initialize(ExtensionContext context) { } private synchronized OAuth1DataGenerator getOrCreateAuthDataGenerator( - String transferType, AuthMode mode) { + DataVertical transferType, AuthMode mode) { Preconditions.checkState(initialized, "Cannot get OAuth1DataGenerator before initialization"); Preconditions.checkArgument( mode == AuthMode.EXPORT ? getExportTypes().contains(transferType) : getImportTypes().contains(transferType)); - Map generators = + Map generators = mode == AuthMode.EXPORT ? exportAuthDataGenerators : importAuthDataGenerators; if (!generators.containsKey(transferType)) { diff --git a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2Config.java b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2Config.java index 1d6f84c4c..40feafba3 100644 --- a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2Config.java +++ b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2Config.java @@ -18,9 +18,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; -import java.util.List; import java.util.Map; import java.util.Set; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData; /** @@ -46,14 +46,16 @@ public interface OAuth2Config { /** * Returns a map of scopes needed for export, keyed by data type (e.g., PHOTOS, CALENDAR) as * defined in the auth data generator or elsewhere + * @return */ - Map> getExportScopes(); + Map> getExportScopes(); /** * Returns a map of scopes needed for import, keyed by data type (e.g., PHOTOS, CALENDAR) as * defined in the auth data generator or elsewhere + * @return */ - Map> getImportScopes(); + Map> getImportScopes(); /** * Returns a map of any additional parameters necessary for this service diff --git a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2DataGenerator.java b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2DataGenerator.java index 8409aa8ab..5e22f82ed 100644 --- a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2DataGenerator.java +++ b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2DataGenerator.java @@ -35,6 +35,7 @@ import org.datatransferproject.spi.api.auth.AuthDataGenerator; import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; import org.datatransferproject.spi.api.types.AuthFlowConfiguration; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.transfer.auth.AppCredentials; import org.datatransferproject.types.transfer.auth.AuthData; @@ -52,7 +53,7 @@ public class OAuth2DataGenerator implements AuthDataGenerator { OAuth2DataGenerator(OAuth2Config config, AppCredentials appCredentials, HttpTransport httpTransport, - String dataType, AuthMode authMode) { + DataVertical dataType, AuthMode authMode) { this.config = config; validateConfig(); this.clientId = appCredentials.getKey(); @@ -129,4 +130,4 @@ private void validateConfig() { Preconditions .checkArgument(config.getImportScopes() != null, "Config is missing import scopes"); } -} \ No newline at end of file +} diff --git a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2ServiceExtension.java b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2ServiceExtension.java index c8dfb305d..fc0a97523 100644 --- a/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2ServiceExtension.java +++ b/libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2ServiceExtension.java @@ -24,6 +24,7 @@ import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension; import org.datatransferproject.spi.cloud.storage.AppCredentialStore; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.transfer.auth.AppCredentials; import java.io.IOException; @@ -42,8 +43,8 @@ public class OAuth2ServiceExtension implements AuthServiceExtension { private final OAuth2Config oAuth2Config; - private volatile Map exportAuthDataGenerators; - private volatile Map importAuthDataGenerators; + private volatile Map exportAuthDataGenerators; + private volatile Map importAuthDataGenerators; private AppCredentials appCredentials; private HttpTransport httpTransport; @@ -60,17 +61,17 @@ public String getServiceId() { } @Override - public AuthDataGenerator getAuthDataGenerator(String transferDataType, AuthMode mode) { + public AuthDataGenerator getAuthDataGenerator(DataVertical transferDataType, AuthMode mode) { return getOrCreateAuthDataGenerator(transferDataType, mode); } @Override - public List getImportTypes() { + public List getImportTypes() { return new ArrayList<>(oAuth2Config.getImportScopes().keySet()); } @Override - public List getExportTypes() { + public List getExportTypes() { return new ArrayList<>(oAuth2Config.getExportScopes().keySet()); } @@ -106,14 +107,14 @@ public void initialize(ExtensionContext context) { } private synchronized OAuth2DataGenerator getOrCreateAuthDataGenerator( - String transferType, AuthMode mode) { + DataVertical transferType, AuthMode mode) { Preconditions.checkState(initialized, "Cannot get OAuth2DataGenerator before initialization"); Preconditions.checkArgument( mode == AuthMode.EXPORT ? getExportTypes().contains(transferType) : getImportTypes().contains(transferType)); - Map generators = + Map generators = mode == AuthMode.EXPORT ? exportAuthDataGenerators : importAuthDataGenerators; if (!generators.containsKey(transferType)) { diff --git a/portability-api-launcher/build.gradle b/portability-api-launcher/build.gradle index 605aecdbc..1dd327b48 100644 --- a/portability-api-launcher/build.gradle +++ b/portability-api-launcher/build.gradle @@ -9,6 +9,10 @@ plugins { id 'signing' } +dependencies { + compile project(':portability-types-common') +} + configurePublication(project) @@ -25,4 +29,4 @@ task generateGitHash() { propFile.createNewFile(); propFile.write("version=${project.version}\nhash=${project.rootProject.ext.gitVersion}") -} \ No newline at end of file +} diff --git a/portability-api-launcher/src/main/java/org/datatransferproject/api/launcher/DtpInternalMetricRecorder.java b/portability-api-launcher/src/main/java/org/datatransferproject/api/launcher/DtpInternalMetricRecorder.java index 8f9bb6714..2c39c292f 100644 --- a/portability-api-launcher/src/main/java/org/datatransferproject/api/launcher/DtpInternalMetricRecorder.java +++ b/portability-api-launcher/src/main/java/org/datatransferproject/api/launcher/DtpInternalMetricRecorder.java @@ -16,6 +16,7 @@ package org.datatransferproject.api.launcher; import java.time.Duration; +import org.datatransferproject.types.common.models.DataVertical; /** * Interface to log metrics about a DTP job. @@ -30,44 +31,44 @@ public interface DtpInternalMetricRecorder { // Metrics related to DTP internals /** A DTP job started. **/ - void startedJob(String dataType, String exportService, String importService); + void startedJob(DataVertical dataType, String exportService, String importService); /** A DTP job finished **/ void finishedJob( - String dataType, + DataVertical dataType, String exportService, String importService, boolean success, Duration duration); /** A DTP job cancelled **/ void cancelledJob( - String dataType, + DataVertical dataType, String exportService, String importService, Duration duration); /** An single attempt to export a page of data finished. **/ void exportPageAttemptFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration); /** An attempt to export a page of data finished including all retires. **/ - void exportPageFinished(String dataType, String service, boolean success, Duration duration); + void exportPageFinished(DataVertical dataType, String service, boolean success, Duration duration); /** An single attempt to import a page of data finished. **/ void importPageAttemptFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration); /** An attempt to import a page of data finished including all retires. **/ - void importPageFinished(String dataType, String service, boolean success, Duration duration); + void importPageFinished(DataVertical dataType, String service, boolean success, Duration duration); // Metrics from {@link MetricRecorder} - void recordGenericMetric(String dataType, String service, String tag); - void recordGenericMetric(String dataType, String service, String tag, boolean bool); - void recordGenericMetric(String dataType, String service, String tag, Duration duration); - void recordGenericMetric(String dataType, String service, String tag, int value); + void recordGenericMetric(DataVertical dataType, String service, String tag); + void recordGenericMetric(DataVertical dataType, String service, String tag, boolean bool); + void recordGenericMetric(DataVertical dataType, String service, String tag, Duration duration); + void recordGenericMetric(DataVertical dataType, String service, String tag, int value); } diff --git a/portability-api-launcher/src/main/java/org/datatransferproject/api/launcher/MetricRecorder.java b/portability-api-launcher/src/main/java/org/datatransferproject/api/launcher/MetricRecorder.java index 82c66461e..2b4573829 100644 --- a/portability-api-launcher/src/main/java/org/datatransferproject/api/launcher/MetricRecorder.java +++ b/portability-api-launcher/src/main/java/org/datatransferproject/api/launcher/MetricRecorder.java @@ -16,6 +16,7 @@ package org.datatransferproject.api.launcher; import java.time.Duration; +import org.datatransferproject.types.common.models.DataVertical; /** * Interface to allow transfer extensions to record generic metrics/stats about their processing. @@ -26,34 +27,34 @@ public interface MetricRecorder { * Record a generic event metric. * * @param dataType the data type being processed - * @param tag a tag to identify the metric, this should be a low cardinality value + * @param tag a tag to identify the metric, this should be a low cardinality value */ - void recordMetric(String dataType, String tag); + void recordMetric(DataVertical dataType, String tag); /** * Record a generic event metric with a boolean value. * * @param dataType the data type being processed - * @param tag a tag to identify the metric, this should be a low cardinality value - * @param bool a true/false value related to the event + * @param tag a tag to identify the metric, this should be a low cardinality value + * @param bool a true/false value related to the event */ - void recordMetric(String dataType, String tag, boolean bool); + void recordMetric(DataVertical dataType, String tag, boolean bool); /** * Record a generic event metric with a boolean value. * * @param dataType the data type being processed - * @param tag a tag to identify the metric, this should be a low cardinality value + * @param tag a tag to identify the metric, this should be a low cardinality value * @param duration a duration related to the event */ - void recordMetric(String dataType, String tag, Duration duration); + void recordMetric(DataVertical dataType, String tag, Duration duration); /** * Record a generic event metric with a integer value. * * @param dataType the data type being processed - * @param tag a tag to identify the metric, this should be a low cardinality value - * @param value a numeric value related to the event + * @param tag a tag to identify the metric, this should be a low cardinality value + * @param value a numeric value related to the event */ - void recordMetric(String dataType, String tag, int value); + void recordMetric(DataVertical dataType, String tag, int value); } diff --git a/portability-api-launcher/src/main/java/org/datatransferproject/launcher/metrics/LoggingDtpInternalMetricRecorder.java b/portability-api-launcher/src/main/java/org/datatransferproject/launcher/metrics/LoggingDtpInternalMetricRecorder.java index e32a28318..1d40540c1 100644 --- a/portability-api-launcher/src/main/java/org/datatransferproject/launcher/metrics/LoggingDtpInternalMetricRecorder.java +++ b/portability-api-launcher/src/main/java/org/datatransferproject/launcher/metrics/LoggingDtpInternalMetricRecorder.java @@ -22,6 +22,7 @@ import org.datatransferproject.api.launcher.Monitor; import java.time.Duration; +import org.datatransferproject.types.common.models.DataVertical; /** * A default {@link DtpInternalMetricRecorder} that simply logs metrics @@ -47,7 +48,7 @@ private LoggingDtpInternalMetricRecorder(Monitor monitor) { } @Override - public void startedJob(String dataType, String exportService, String importService) { + public void startedJob(DataVertical dataType, String exportService, String importService) { monitor.debug( () -> format( @@ -57,7 +58,7 @@ public void startedJob(String dataType, String exportService, String importServi @Override public void exportPageAttemptFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { @@ -71,7 +72,7 @@ public void exportPageAttemptFinished( @Override public void exportPageFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { @@ -84,7 +85,7 @@ public void exportPageFinished( @Override public void importPageAttemptFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { @@ -98,7 +99,7 @@ public void importPageAttemptFinished( @Override public void importPageFinished( - String dataType, + DataVertical dataType, String service, boolean success, Duration duration) { @@ -111,7 +112,7 @@ public void importPageFinished( @Override public void finishedJob( - String dataType, + DataVertical dataType, String exportService, String importService, boolean success, @@ -125,7 +126,7 @@ public void finishedJob( @Override public void cancelledJob( - String dataType, String exportService, String importService, Duration duration) { + DataVertical dataType, String exportService, String importService, Duration duration) { monitor.debug( () -> format( @@ -134,14 +135,14 @@ public void cancelledJob( } @Override - public void recordGenericMetric(String dataType, String service, String tag) { + public void recordGenericMetric(DataVertical dataType, String service, String tag) { monitor.debug( () -> format("Metric: Generic, data type: %s, service: %s, tag: %s", dataType, service, tag)); } @Override - public void recordGenericMetric(String dataType, String service, String tag, boolean bool) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, boolean bool) { monitor.debug( () -> format( @@ -150,7 +151,7 @@ public void recordGenericMetric(String dataType, String service, String tag, boo } @Override - public void recordGenericMetric(String dataType, String service, String tag, Duration duration) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, Duration duration) { monitor.debug( () -> format( @@ -159,7 +160,7 @@ public void recordGenericMetric(String dataType, String service, String tag, Dur } @Override - public void recordGenericMetric(String dataType, String service, String tag, int value) { + public void recordGenericMetric(DataVertical dataType, String service, String tag, int value) { monitor.debug( () -> format( diff --git a/portability-api-launcher/src/main/java/org/datatransferproject/launcher/metrics/ServiceAwareMetricRecorder.java b/portability-api-launcher/src/main/java/org/datatransferproject/launcher/metrics/ServiceAwareMetricRecorder.java index ec1006bad..7bd75a009 100644 --- a/portability-api-launcher/src/main/java/org/datatransferproject/launcher/metrics/ServiceAwareMetricRecorder.java +++ b/portability-api-launcher/src/main/java/org/datatransferproject/launcher/metrics/ServiceAwareMetricRecorder.java @@ -19,6 +19,7 @@ import org.datatransferproject.api.launcher.MetricRecorder; import java.time.Duration; +import org.datatransferproject.types.common.models.DataVertical; import static com.google.common.base.Preconditions.checkNotNull; @@ -37,22 +38,22 @@ public ServiceAwareMetricRecorder( this.metricRecorder = checkNotNull(metricRecorder, "metricRecorder can't be null"); } @Override - public void recordMetric(String dataType, String tag) { + public void recordMetric(DataVertical dataType, String tag) { metricRecorder.recordGenericMetric(dataType, service, tag); } @Override - public void recordMetric(String dataType, String tag, boolean bool) { + public void recordMetric(DataVertical dataType, String tag, boolean bool) { metricRecorder.recordGenericMetric(dataType, service, tag, bool); } @Override - public void recordMetric(String dataType, String tag, Duration duration) { + public void recordMetric(DataVertical dataType, String tag, Duration duration) { metricRecorder.recordGenericMetric(dataType, service, tag, duration); } @Override - public void recordMetric(String dataType, String tag, int value) { + public void recordMetric(DataVertical dataType, String tag, int value) { metricRecorder.recordGenericMetric(dataType, service, tag, value); } } diff --git a/portability-api/src/main/java/org/datatransferproject/api/action/ActionUtils.java b/portability-api/src/main/java/org/datatransferproject/api/action/ActionUtils.java index c243b7a24..070297616 100644 --- a/portability-api/src/main/java/org/datatransferproject/api/action/ActionUtils.java +++ b/portability-api/src/main/java/org/datatransferproject/api/action/ActionUtils.java @@ -21,6 +21,7 @@ import com.google.common.io.BaseEncoding; import java.util.UUID; +import org.datatransferproject.types.common.models.DataVertical; /** Helper functions for validating action related data. */ public final class ActionUtils { @@ -36,8 +37,9 @@ public static UUID decodeJobId(String encodedJobId) { Charsets.UTF_8)); } - /** Determines whether the current service is a valid service for import. */ - public static boolean isValidTransferDataType(String transferDataType) { - return !Strings.isNullOrEmpty(transferDataType); + /** Determines whether the current service is a valid service for import. + * @param transferDataType*/ + public static boolean isValidTransferDataType(DataVertical transferDataType) { + return transferDataType != null; } } diff --git a/portability-api/src/main/java/org/datatransferproject/api/action/datatype/DataTypesAction.java b/portability-api/src/main/java/org/datatransferproject/api/action/datatype/DataTypesAction.java index 868f5765f..8fa7dbd1d 100644 --- a/portability-api/src/main/java/org/datatransferproject/api/action/datatype/DataTypesAction.java +++ b/portability-api/src/main/java/org/datatransferproject/api/action/datatype/DataTypesAction.java @@ -23,6 +23,7 @@ import org.datatransferproject.types.client.datatype.GetDataTypes; import java.util.Set; +import org.datatransferproject.types.common.models.DataVertical; /** * An {@link Action} that handles listing data types available for export and import for a given @@ -46,7 +47,7 @@ public Class getRequestType() { /** Lists the set of data types that support both import and export. */ @Override public DataTypes handle(GetDataTypes request) { - Set transferDataTypes = registry.getTransferDataTypes(); + Set transferDataTypes = registry.getTransferDataTypes(); if (transferDataTypes.isEmpty()) { monitor.severe( () -> diff --git a/portability-api/src/main/java/org/datatransferproject/api/action/transfer/CreateTransferJobAction.java b/portability-api/src/main/java/org/datatransferproject/api/action/transfer/CreateTransferJobAction.java index 04cdc0053..528546712 100644 --- a/portability-api/src/main/java/org/datatransferproject/api/action/transfer/CreateTransferJobAction.java +++ b/portability-api/src/main/java/org/datatransferproject/api/action/transfer/CreateTransferJobAction.java @@ -27,6 +27,7 @@ import org.datatransferproject.spi.cloud.storage.JobStore; import org.datatransferproject.spi.cloud.types.JobAuthorization; import org.datatransferproject.spi.cloud.types.PortabilityJob; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.client.transfer.CreateTransferJob; import org.datatransferproject.types.client.transfer.TransferJob; import org.datatransferproject.types.common.ExportInformation; @@ -66,7 +67,7 @@ public Class getRequestType() { @Override public TransferJob handle(CreateTransferJob request) { - String dataType = request.getDataType(); + DataVertical dataType = request.getDataType(); String exportService = request.getExportService(); String importService = request.getImportService(); Optional exportInformation = Optional @@ -191,7 +192,7 @@ private PortabilityJob setInitialAuthDataOnJob(SecretKey sessionKey, Portability */ private PortabilityJob createJob( String encodedSessionKey, - String dataType, + DataVertical dataType, String exportService, String importService, Optional exportInformation, diff --git a/portability-api/src/main/java/org/datatransferproject/api/action/transfer/GetTransferServicesAction.java b/portability-api/src/main/java/org/datatransferproject/api/action/transfer/GetTransferServicesAction.java index f0a8b9b78..0c5606ca4 100644 --- a/portability-api/src/main/java/org/datatransferproject/api/action/transfer/GetTransferServicesAction.java +++ b/portability-api/src/main/java/org/datatransferproject/api/action/transfer/GetTransferServicesAction.java @@ -23,6 +23,7 @@ import org.datatransferproject.types.client.transfer.GetTransferServices; import java.util.Set; +import org.datatransferproject.types.common.models.DataVertical; /** Returns the import and export services available for a given data type. */ public final class GetTransferServicesAction @@ -43,7 +44,7 @@ public Class getRequestType() { /** Lists the services available for export and import for a given data type. */ @Override public TransferServices handle(GetTransferServices request) { - String transferDataType = request.getTransferDataType(); + DataVertical transferDataType = request.getTransferDataType(); // Validate incoming data type parameter if (!ActionUtils.isValidTransferDataType(transferDataType)) { throw new IllegalArgumentException("Invalid transferDataType: " + transferDataType); diff --git a/portability-api/src/main/java/org/datatransferproject/api/auth/PortabilityAuthServiceProviderRegistry.java b/portability-api/src/main/java/org/datatransferproject/api/auth/PortabilityAuthServiceProviderRegistry.java index bc25b2e50..a7033d5d7 100644 --- a/portability-api/src/main/java/org/datatransferproject/api/auth/PortabilityAuthServiceProviderRegistry.java +++ b/portability-api/src/main/java/org/datatransferproject/api/auth/PortabilityAuthServiceProviderRegistry.java @@ -29,11 +29,12 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.datatransferproject.types.common.models.DataVertical; public class PortabilityAuthServiceProviderRegistry implements AuthServiceProviderRegistry { private final ImmutableMap authServiceProviderMap; - private final ImmutableSet supportedImportTypes; - private final ImmutableSet supportedExportTypes; + private final ImmutableSet supportedImportTypes; + private final ImmutableSet supportedExportTypes; @Inject public PortabilityAuthServiceProviderRegistry( @@ -41,14 +42,14 @@ public PortabilityAuthServiceProviderRegistry( ImmutableMap.Builder serviceProviderBuilder = ImmutableMap.builder(); - ImmutableSet.Builder supportedImportTypesBuilder = ImmutableSet.builder(); - ImmutableSet.Builder supportedExportTypesBuilder = ImmutableSet.builder(); + ImmutableSet.Builder supportedImportTypesBuilder = ImmutableSet.builder(); + ImmutableSet.Builder supportedExportTypesBuilder = ImmutableSet.builder(); serviceProviderMap.forEach( (service, provider) -> { - List importTypes = provider.getImportTypes(); - List exportTypes = provider.getExportTypes(); - for (String type : importTypes) { + List importTypes = provider.getImportTypes(); + List exportTypes = provider.getExportTypes(); + for (DataVertical type : importTypes) { Preconditions.checkArgument( exportTypes.contains(type), "TransferDataType [%s] is available for import but not export in [%s] AuthServiceExtension", @@ -67,7 +68,7 @@ public PortabilityAuthServiceProviderRegistry( @Override public AuthDataGenerator getAuthDataGenerator( - String serviceId, String transferDataType, AuthMode mode) { + String serviceId, DataVertical transferDataType, AuthMode mode) { AuthServiceExtension provider = authServiceProviderMap.get(serviceId); Preconditions.checkArgument( provider != null, "AuthServiceExtension not found for serviceId [%s]", serviceId); @@ -94,7 +95,7 @@ public AuthDataGenerator getAuthDataGenerator( } @Override - public Set getImportServices(String transferDataType) { + public Set getImportServices(DataVertical transferDataType) { Preconditions.checkArgument( supportedImportTypes.contains(transferDataType), "TransferDataType [%s] is not valid for import", @@ -103,13 +104,13 @@ public Set getImportServices(String transferDataType) { .values() .stream() .filter( - sp -> sp.getImportTypes().stream().anyMatch(e -> e.equalsIgnoreCase(transferDataType))) + sp -> sp.getImportTypes().stream().anyMatch(e -> e == transferDataType)) .map(AuthServiceExtension::getServiceId) .collect(Collectors.toSet()); } @Override - public Set getExportServices(String transferDataType) { + public Set getExportServices(DataVertical transferDataType) { Preconditions.checkArgument( supportedExportTypes.contains(transferDataType), "TransferDataType [%s] is not valid for export", @@ -118,14 +119,14 @@ public Set getExportServices(String transferDataType) { .values() .stream() .filter( - sp -> sp.getExportTypes().stream().anyMatch(e -> e.equalsIgnoreCase(transferDataType))) + sp -> sp.getExportTypes().stream().anyMatch(e -> e == transferDataType)) .map(AuthServiceExtension::getServiceId) .collect(Collectors.toSet()); } /** Returns the set of data types that support both import and export. */ @Override - public Set getTransferDataTypes() { + public Set getTransferDataTypes() { return Sets.intersection(supportedExportTypes, supportedImportTypes); } } diff --git a/portability-api/src/test/java/org/datatransferproject/api/action/datatype/DataTypesActionTest.java b/portability-api/src/test/java/org/datatransferproject/api/action/datatype/DataTypesActionTest.java index 521ebec86..780dd339a 100644 --- a/portability-api/src/test/java/org/datatransferproject/api/action/datatype/DataTypesActionTest.java +++ b/portability-api/src/test/java/org/datatransferproject/api/action/datatype/DataTypesActionTest.java @@ -1,5 +1,7 @@ package org.datatransferproject.api.action.datatype; +import static org.datatransferproject.types.common.models.DataVertical.CONTACTS; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -10,6 +12,7 @@ import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry; import org.datatransferproject.types.client.datatype.DataTypes; import org.datatransferproject.types.client.datatype.GetDataTypes; +import org.datatransferproject.types.common.models.DataVertical; import org.junit.Assert; import org.junit.jupiter.api.Test; @@ -28,7 +31,7 @@ public void testGetRequestType() { @Test public void testHandle() { AuthServiceProviderRegistry registry = mock(AuthServiceProviderRegistry.class); - Set dataTypes = new HashSet<>(Arrays.asList("CONTACTS", "PHOTOS")); + Set dataTypes = new HashSet<>(Arrays.asList(CONTACTS, PHOTOS)); when(registry.getTransferDataTypes()).thenReturn(dataTypes); DataTypesAction dataTypesAction = new DataTypesAction(registry, new Monitor() {}); diff --git a/portability-api/src/test/java/org/datatransferproject/api/auth/PortabilityAuthServiceExtensionRegistryTest.java b/portability-api/src/test/java/org/datatransferproject/api/auth/PortabilityAuthServiceExtensionRegistryTest.java index 7ec07d8ca..547eb4b77 100644 --- a/portability-api/src/test/java/org/datatransferproject/api/auth/PortabilityAuthServiceExtensionRegistryTest.java +++ b/portability-api/src/test/java/org/datatransferproject/api/auth/PortabilityAuthServiceExtensionRegistryTest.java @@ -16,6 +16,8 @@ package org.datatransferproject.api.auth; +import static org.datatransferproject.types.common.models.DataVertical.CONTACTS; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,6 +30,7 @@ import org.datatransferproject.spi.api.auth.AuthDataGenerator; import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry; import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension; +import org.datatransferproject.types.common.models.DataVertical; import org.junit.Assert; import org.junit.Rule; @@ -39,7 +42,7 @@ public class PortabilityAuthServiceExtensionRegistryTest { @Rule public ExpectedException thrown = ExpectedException.none(); private AuthServiceExtension getMockedAuthProvider( - List supportedImportTypes, List supportedExportTypes, String serviceId) { + List supportedImportTypes, List supportedExportTypes, String serviceId) { AuthServiceExtension mockAuthProvider = mock(AuthServiceExtension.class); when(mockAuthProvider.getExportTypes()).thenReturn(supportedExportTypes); @@ -51,8 +54,8 @@ private AuthServiceExtension getMockedAuthProvider( @Test public void requireImportAndExportTest() { - List supportedImportTypes = ImmutableList.of("PHOTOS", "CONTACTS"); - List supportedExportTypes = ImmutableList.of("CONTACTS"); + List supportedImportTypes = ImmutableList.of(PHOTOS, CONTACTS); + List supportedExportTypes = ImmutableList.of(CONTACTS); AuthServiceExtension mockAuthProvider = getMockedAuthProvider( supportedImportTypes, supportedExportTypes, "mockAuthProvider"); @@ -66,7 +69,7 @@ public void requireImportAndExportTest() { @Test public void testGetTransferDataTypes() { - List supportedServiceTypes = ImmutableList.of("PHOTOS", "CONTACTS"); + List supportedServiceTypes = ImmutableList.of(PHOTOS, CONTACTS); AuthServiceExtension mockAuthProvider = getMockedAuthProvider( supportedServiceTypes, supportedServiceTypes, "mockAuthProvider"); @@ -75,18 +78,18 @@ public void testGetTransferDataTypes() { new PortabilityAuthServiceProviderRegistry( ImmutableMap.of("mockServiceProvider", mockAuthProvider)); - Set actual = registry.getTransferDataTypes(); + Set actual = registry.getTransferDataTypes(); - final String services[] = new String[] {"PHOTOS", "CONTACTS"}; - Set expected = new HashSet<>(Arrays.asList(services)); + final DataVertical[] services = new DataVertical[] {PHOTOS, CONTACTS}; + Set expected = new HashSet<>(Arrays.asList(services)); Assert.assertEquals(actual, expected); } @Test public void testGetExportServices1() { - List supportedServiceTypes1 = ImmutableList.of("PHOTOS", "CONTACTS"); - List supportedServiceTypes2 = ImmutableList.of("CONTACTS"); + List supportedServiceTypes1 = ImmutableList.of(PHOTOS, CONTACTS); + List supportedServiceTypes2 = ImmutableList.of(CONTACTS); AuthServiceExtension mockAuthProvider1 = getMockedAuthProvider( supportedServiceTypes1, supportedServiceTypes1, "mockAuthProvider1"); @@ -98,8 +101,8 @@ public void testGetExportServices1() { ImmutableMap.of("mockServiceProvider1", mockAuthProvider1, "mockServiceProvider2", mockAuthProvider2)); - Set actual = registry.getExportServices("CONTACTS"); - final String services[] = new String[]{"mockAuthProvider1", "mockAuthProvider2"}; + Set actual = registry.getExportServices(CONTACTS); + final String[] services = new String[]{"mockAuthProvider1", "mockAuthProvider2"}; Set expected = new HashSet<>(Arrays.asList(services)); Assert.assertEquals(actual, expected); @@ -107,8 +110,8 @@ public void testGetExportServices1() { @Test public void testGetExportServices2() { - List supportedServiceTypes1 = ImmutableList.of("PHOTOS", "CONTACTS"); - List supportedServiceTypes2 = ImmutableList.of("CONTACTS"); + List supportedServiceTypes1 = ImmutableList.of(PHOTOS, CONTACTS); + List supportedServiceTypes2 = ImmutableList.of(CONTACTS); AuthServiceExtension mockAuthProvider1 = getMockedAuthProvider( supportedServiceTypes1, supportedServiceTypes1, "mockAuthProvider1"); @@ -120,8 +123,8 @@ public void testGetExportServices2() { ImmutableMap.of("mockServiceProvider1", mockAuthProvider1, "mockServiceProvider2", mockAuthProvider2)); - Set actual = registry.getExportServices("PHOTOS"); - final String services[] = new String[] {"mockAuthProvider1"}; + Set actual = registry.getExportServices(PHOTOS); + final String[] services = new String[] {"mockAuthProvider1"}; Set expected = new HashSet<>(Arrays.asList(services)); Assert.assertEquals(actual, expected); @@ -129,8 +132,8 @@ public void testGetExportServices2() { @Test public void testGetImportServices1() { - List supportedServiceTypes1 = ImmutableList.of("PHOTOS", "CONTACTS"); - List supportedServiceTypes2 = ImmutableList.of("CONTACTS"); + List supportedServiceTypes1 = ImmutableList.of(PHOTOS, CONTACTS); + List supportedServiceTypes2 = ImmutableList.of(CONTACTS); AuthServiceExtension mockAuthProvider1 = getMockedAuthProvider( supportedServiceTypes1, supportedServiceTypes1, "mockAuthProvider1"); @@ -141,8 +144,8 @@ public void testGetImportServices1() { ImmutableMap.of("mockServiceProvider1", mockAuthProvider1, "mockServiceProvider2", mockAuthProvider2)); - Set actual = registry.getImportServices("CONTACTS"); - final String services[] = new String[]{"mockAuthProvider1", "mockAuthProvider2"}; + Set actual = registry.getImportServices(CONTACTS); + final String[] services = new String[]{"mockAuthProvider1", "mockAuthProvider2"}; Set expected = new HashSet<>(Arrays.asList(services)); Assert.assertEquals(actual, expected); @@ -150,8 +153,8 @@ public void testGetImportServices1() { @Test public void testGetImportServices2() { - List supportedServiceTypes1 = ImmutableList.of("PHOTOS", "CONTACTS"); - List supportedServiceTypes2 = ImmutableList.of("CONTACTS"); + List supportedServiceTypes1 = ImmutableList.of(PHOTOS, CONTACTS); + List supportedServiceTypes2 = ImmutableList.of(CONTACTS); AuthServiceExtension mockAuthProvider1 = getMockedAuthProvider( supportedServiceTypes1, supportedServiceTypes1, "mockAuthProvider1"); @@ -163,8 +166,8 @@ public void testGetImportServices2() { ImmutableMap.of("mockServiceProvider1", mockAuthProvider1, "mockServiceProvider2", mockAuthProvider2)); - Set actual = registry.getImportServices("PHOTOS"); - final String services[] = new String[] {"mockAuthProvider1"}; + Set actual = registry.getImportServices(PHOTOS); + final String[] services = new String[] {"mockAuthProvider1"}; Set expected = new HashSet<>(Arrays.asList(services)); Assert.assertEquals(actual, expected); @@ -172,12 +175,12 @@ public void testGetImportServices2() { @Test public void testGetAuthDataGenerator() { - List supportedServiceTypes = ImmutableList.of("PHOTOS", "CONTACTS"); + List supportedServiceTypes = ImmutableList.of(PHOTOS, CONTACTS); AuthServiceExtension mockAuthProvider = getMockedAuthProvider( supportedServiceTypes, supportedServiceTypes, "mockAuthProvider"); when(mockAuthProvider - .getAuthDataGenerator("CONTACTS", AuthServiceProviderRegistry.AuthMode.EXPORT)) + .getAuthDataGenerator(CONTACTS, AuthServiceProviderRegistry.AuthMode.EXPORT)) .thenReturn(mock(AuthDataGenerator.class)); AuthServiceProviderRegistry registry = @@ -185,7 +188,7 @@ public void testGetAuthDataGenerator() { ImmutableMap.of("mockServiceProvider", mockAuthProvider)); AuthDataGenerator actual = registry.getAuthDataGenerator( - "mockServiceProvider","CONTACTS", AuthServiceProviderRegistry.AuthMode.EXPORT); + "mockServiceProvider", CONTACTS, AuthServiceProviderRegistry.AuthMode.EXPORT); Assert.assertNotNull(actual); } diff --git a/portability-spi-api/src/main/java/org/datatransferproject/spi/api/auth/AuthServiceProviderRegistry.java b/portability-spi-api/src/main/java/org/datatransferproject/spi/api/auth/AuthServiceProviderRegistry.java index cd638c2b2..edd6bad51 100644 --- a/portability-spi-api/src/main/java/org/datatransferproject/spi/api/auth/AuthServiceProviderRegistry.java +++ b/portability-spi-api/src/main/java/org/datatransferproject/spi/api/auth/AuthServiceProviderRegistry.java @@ -2,6 +2,7 @@ import java.util.Set; import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension; +import org.datatransferproject.types.common.models.DataVertical; /** Manages {@link AuthServiceExtension}s registered in the system. */ public interface AuthServiceProviderRegistry { @@ -15,24 +16,25 @@ public interface AuthServiceProviderRegistry { * @return An AuthDataGenerator from the specified AuthServiceExtension for the type and mode * requested. */ - AuthDataGenerator getAuthDataGenerator(String serviceId, String transferDataType, AuthMode mode); + AuthDataGenerator getAuthDataGenerator(String serviceId, DataVertical transferDataType, AuthMode mode); /** * Returns the set of service ids that can import the given {@code transferDataType}. * * @param transferDataType the transfer data type */ - Set getImportServices(String transferDataType); + Set getImportServices(DataVertical transferDataType); /** * Returns the set of service ids that can export the given {@code transferDataType}. * * @param transferDataType the transfer data type */ - Set getExportServices(String transferDataType); + Set getExportServices(DataVertical transferDataType); - /** Returns the set of data types that support both import and export. */ - Set getTransferDataTypes(); + /** Returns the set of data types that support both import and export. + * @return*/ + Set getTransferDataTypes(); /** * The AuthorizationMode to use for lookups. IMPORT specifies an authorization that allows you to diff --git a/portability-spi-api/src/main/java/org/datatransferproject/spi/api/auth/extension/AuthServiceExtension.java b/portability-spi-api/src/main/java/org/datatransferproject/spi/api/auth/extension/AuthServiceExtension.java index afc219d94..263a476d3 100644 --- a/portability-spi-api/src/main/java/org/datatransferproject/spi/api/auth/extension/AuthServiceExtension.java +++ b/portability-spi-api/src/main/java/org/datatransferproject/spi/api/auth/extension/AuthServiceExtension.java @@ -4,6 +4,7 @@ import org.datatransferproject.api.launcher.AbstractExtension; import org.datatransferproject.spi.api.auth.AuthDataGenerator; import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode; +import org.datatransferproject.types.common.models.DataVertical; /** * Factory responsible for providing {@link AuthDataGenerator} implementations. @@ -21,19 +22,19 @@ public interface AuthServiceExtension extends AbstractExtension{ * * @param transferDataType the data type */ - AuthDataGenerator getAuthDataGenerator(String transferDataType, AuthMode mode); + AuthDataGenerator getAuthDataGenerator(DataVertical transferDataType, AuthMode mode); /** * get supported import types * * @return The list of types that are supported for IMPORT AuthMode */ - List getImportTypes(); + List getImportTypes(); /** * get supported export types * * @return The list of types that are supported for EXPORT AuthMode */ - List getExportTypes(); + List getExportTypes(); } diff --git a/portability-spi-cloud/src/main/java/org/datatransferproject/spi/cloud/storage/JobStoreWithValidator.java b/portability-spi-cloud/src/main/java/org/datatransferproject/spi/cloud/storage/JobStoreWithValidator.java index 94788b70e..369bd2ae2 100644 --- a/portability-spi-cloud/src/main/java/org/datatransferproject/spi/cloud/storage/JobStoreWithValidator.java +++ b/portability-spi-cloud/src/main/java/org/datatransferproject/spi/cloud/storage/JobStoreWithValidator.java @@ -11,6 +11,7 @@ import org.datatransferproject.spi.cloud.types.JobAuthorization; import org.datatransferproject.spi.cloud.types.PortabilityJob; import org.datatransferproject.spi.cloud.types.PortabilityJob.State; +import org.datatransferproject.types.common.models.DataVertical; public abstract class JobStoreWithValidator implements JobStore { @@ -35,9 +36,9 @@ public void updateJobAuthStateToCredsAvailable(UUID jobId) throws IOException { } private static void validateForUpdateStateToCredsAvailable(PortabilityJob job) { - String dataType = job.transferDataType(); + DataVertical dataType = job.transferDataType(); Preconditions.checkArgument( - !Strings.isNullOrEmpty(dataType), "Missing valid dataTypeParam: %s", dataType); + dataType != null, "Missing valid dataTypeParam: %s", dataType); String exportService = job.exportService(); Preconditions.checkArgument( diff --git a/portability-spi-cloud/src/main/java/org/datatransferproject/spi/cloud/types/PortabilityJob.java b/portability-spi-cloud/src/main/java/org/datatransferproject/spi/cloud/types/PortabilityJob.java index 319e453ba..8c0d82d2e 100644 --- a/portability-spi-cloud/src/main/java/org/datatransferproject/spi/cloud/types/PortabilityJob.java +++ b/portability-spi-cloud/src/main/java/org/datatransferproject/spi/cloud/types/PortabilityJob.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.TimeZone; import javax.annotation.Nullable; +import org.datatransferproject.types.common.models.DataVertical; /** * A job that will fulfill a transfer request. @@ -100,11 +101,16 @@ public static PortabilityJob fromMap(Map properties) { ? TransferMode.valueOf((String) properties.get(TRANSFER_MODE)) : TransferMode.DATA_TRANSFER; + DataVertical dataType = + properties.containsKey(DATA_TYPE_KEY) + ? DataVertical.fromDataType((String) properties.get(DATA_TYPE_KEY)) + : null; + return PortabilityJob.builder() .setState(state) .setExportService((String) properties.get(EXPORT_SERVICE_KEY)) .setImportService((String) properties.get(IMPORT_SERVICE_KEY)) - .setTransferDataType((String) properties.get(DATA_TYPE_KEY)) + .setTransferDataType(dataType) .setExportInformation((String) properties.get(EXPORT_INFORMATION_KEY)) .setCreatedTimestamp(now) // TODO: get from DB .setLastUpdateTimestamp(now) @@ -151,7 +157,7 @@ private static void isSet(String... strings) { public abstract String importService(); @JsonProperty("transferDataType") - public abstract String transferDataType(); + public abstract DataVertical transferDataType(); @Nullable @JsonProperty("exportInformation") @@ -187,7 +193,7 @@ private static void isSet(String... strings) { public Map toMap() { ImmutableMap.Builder builder = ImmutableMap.builder() - .put(DATA_TYPE_KEY, transferDataType()) + .put(DATA_TYPE_KEY, transferDataType().getDataType()) .put(EXPORT_SERVICE_KEY, exportService()) .put(IMPORT_SERVICE_KEY, importService()) .put(AUTHORIZATION_STATE, jobAuthorization().state().toString()) @@ -289,7 +295,7 @@ private static PortabilityJob.Builder create() { public abstract Builder setImportService(String importService); @JsonProperty("transferDataType") - public abstract Builder setTransferDataType(String transferDataType); + public abstract Builder setTransferDataType(DataVertical transferDataType); @JsonInclude(JsonInclude.Include.NON_NULL) @JsonProperty("exportInformation") diff --git a/portability-spi-cloud/src/test/java/org/datatransferproject/spi/cloud/types/PortabilityJobTest.java b/portability-spi-cloud/src/test/java/org/datatransferproject/spi/cloud/types/PortabilityJobTest.java index 89bed3bf4..a237133e1 100644 --- a/portability-spi-cloud/src/test/java/org/datatransferproject/spi/cloud/types/PortabilityJobTest.java +++ b/portability-spi-cloud/src/test/java/org/datatransferproject/spi/cloud/types/PortabilityJobTest.java @@ -17,6 +17,8 @@ package org.datatransferproject.spi.cloud.types; import static com.google.common.truth.Truth.assertThat; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.SOCIAL_POSTS; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; @@ -29,6 +31,7 @@ import org.datatransferproject.spi.cloud.types.PortabilityJob.TransferMode; import org.datatransferproject.test.types.ObjectMapperFactory; import org.datatransferproject.types.common.ExportInformation; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.common.models.photos.PhotoAlbum; import org.datatransferproject.types.common.models.photos.PhotosContainerResource; import org.junit.jupiter.api.Test; @@ -41,7 +44,7 @@ public class PortabilityJobTest { private static final Map MANDATORY_FIELDS = ImmutableMap.builder() .put("EXPORT_SERVICE", "test") .put("IMPORT_SERVICE", "test") - .put("DATA_TYPE", "test") + .put("DATA_TYPE", "SOCIAL-POSTS") .put("EXPORT_INFORMATION", "test") .put("AUTHORIZATION_STATE", "INITIAL") .build(); @@ -63,7 +66,7 @@ public void verifySerializeDeserialize() throws Exception { .setState(State.NEW) .setExportService("fooService") .setImportService("barService") - .setTransferDataType("PHOTOS") + .setTransferDataType(PHOTOS) .setCreatedTimestamp(date) .setLastUpdateTimestamp(date.plusSeconds(120)) .setJobAuthorization(jobAuthorization) @@ -95,7 +98,7 @@ public void verifySerializeDeserializeWithAlbum() throws IOException { .setState(State.NEW) .setExportService("fooService") .setImportService("barService") - .setTransferDataType("PHOTOS") + .setTransferDataType(PHOTOS) .setExportInformation( objectMapper.writeValueAsString( new ExportInformation( @@ -132,7 +135,7 @@ public void verifySerializeDeserializeUserTimeZone() throws Exception { .setState(State.NEW) .setExportService("fooService") .setImportService("barService") - .setTransferDataType("PHOTOS") + .setTransferDataType(PHOTOS) .setCreatedTimestamp(date) .setLastUpdateTimestamp(date.plusSeconds(120)) .setJobAuthorization(jobAuthorization) @@ -159,7 +162,7 @@ public void verifySerializeDeserializeUserLocale() throws Exception { .setState(State.NEW) .setExportService("fooService") .setImportService("barService") - .setTransferDataType("PHOTOS") + .setTransferDataType(PHOTOS) .setCreatedTimestamp(date) .setLastUpdateTimestamp(date.plusSeconds(120)) .setJobAuthorization(jobAuthorization) diff --git a/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/extension/TransferExtension.java b/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/extension/TransferExtension.java index 5679ce382..ad601e661 100644 --- a/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/extension/TransferExtension.java +++ b/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/extension/TransferExtension.java @@ -16,6 +16,7 @@ package org.datatransferproject.spi.transfer.extension; import org.datatransferproject.api.launcher.AbstractExtension; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -25,9 +26,11 @@ public interface TransferExtension extends AbstractExtension { /** The key associated with this extension's service. */ String getServiceId(); - /** Returns initialized extension exporter. */ - Exporter getExporter(String transferDataType); + /** Returns initialized extension exporter. + * @param transferDataType*/ + Exporter getExporter(DataVertical transferDataType); - /** Returns initialized extension importer. */ - Importer getImporter(String transferDataType); + /** Returns initialized extension importer. + * @param transferDataType*/ + Importer getImporter(DataVertical transferDataType); } diff --git a/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/TransferCompatibilityProvider.java b/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/TransferCompatibilityProvider.java index c7c13f13d..549b82323 100644 --- a/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/TransferCompatibilityProvider.java +++ b/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/TransferCompatibilityProvider.java @@ -1,6 +1,11 @@ package org.datatransferproject.spi.transfer.provider; +import static org.datatransferproject.types.common.models.DataVertical.MEDIA; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; + import java.util.function.Function; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.converter.AnyToAnyExporter; import org.datatransferproject.spi.transfer.provider.converter.AnyToAnyImporter; @@ -18,11 +23,7 @@ */ public class TransferCompatibilityProvider { - private static final String PHOTOS = "PHOTOS"; - private static final String VIDEOS = "VIDEOS"; - private static final String MEDIA = "MEDIA"; - - public Exporter getCompatibleExporter(TransferExtension extension, String jobType) { + public Exporter getCompatibleExporter(TransferExtension extension, DataVertical jobType) { Exporter exporter = getExporterOrNull(extension, jobType); if (exporter != null) { return exporter; @@ -45,7 +46,7 @@ public Exporter getCompatibleExporter(TransferExtension extension, String jobTyp return exporter; } - public Importer getCompatibleImporter(TransferExtension extension, String jobType) { + public Importer getCompatibleImporter(TransferExtension extension, DataVertical jobType) { Importer importer = getImporterOrNull(extension, jobType); if (importer != null) { return importer; @@ -124,7 +125,7 @@ public Importer getCompatibleImporter(TransferExtension extension, String jobTyp return new MediaExporterDecorator(photo, video); } - private Exporter getExporterOrNull(TransferExtension extension, String jobType) { + private Exporter getExporterOrNull(TransferExtension extension, DataVertical jobType) { // TODO: Don't use exceptions for control flow. Have a way to query supported adapters try { return extension.getExporter(jobType); @@ -133,7 +134,7 @@ public Importer getCompatibleImporter(TransferExtension extension, String jobTyp } } - private Importer getImporterOrNull(TransferExtension extension, String jobType) { + private Importer getImporterOrNull(TransferExtension extension, DataVertical jobType) { try { return extension.getImporter(jobType); } catch (Exception e) { diff --git a/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/converter/MediaToPhotoConversionImporter.java b/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/converter/MediaToPhotoConversionImporter.java index a90df4830..a366f5d1a 100644 --- a/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/converter/MediaToPhotoConversionImporter.java +++ b/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/converter/MediaToPhotoConversionImporter.java @@ -21,8 +21,6 @@ * * This is intended for providers who do not support "MEDIA" as a special case. */ -// TODO(#1065) fix primitives-obession causing us to key Providers on "PHOTOS" string rather -// than underlying file types. @Deprecated // prefer AnyToAnyImporter public class MediaToPhotoConversionImporter< A extends AuthData, diff --git a/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/converter/PhotoToMediaConversionExporter.java b/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/converter/PhotoToMediaConversionExporter.java index 26051f49d..781213009 100644 --- a/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/converter/PhotoToMediaConversionExporter.java +++ b/portability-spi-transfer/src/main/java/org/datatransferproject/spi/transfer/provider/converter/PhotoToMediaConversionExporter.java @@ -20,9 +20,7 @@ * * This is intended for providers who do not support "PHOTOS" as a special case. */ -// TODO(#1065) fix primitives-obession causing us to key Providers on "PHOTOS" string rather -// than underlying file types. -@Deprecated // prefer AnyToAnyImporter +@Deprecated // prefer AnyToAnyExporter public class PhotoToMediaConversionExporter< A extends AuthData, PCR extends PhotosContainerResource, diff --git a/portability-spi-transfer/src/test/java/org/datatransferproject/spi/transfer/provider/TransferCompatibilityProviderTest.java b/portability-spi-transfer/src/test/java/org/datatransferproject/spi/transfer/provider/TransferCompatibilityProviderTest.java index 4f7321226..0c6c31dba 100644 --- a/portability-spi-transfer/src/test/java/org/datatransferproject/spi/transfer/provider/TransferCompatibilityProviderTest.java +++ b/portability-spi-transfer/src/test/java/org/datatransferproject/spi/transfer/provider/TransferCompatibilityProviderTest.java @@ -1,6 +1,9 @@ package org.datatransferproject.spi.transfer.provider; import static com.google.common.truth.Truth.assertThat; +import static org.datatransferproject.types.common.models.DataVertical.MEDIA; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; +import static org.datatransferproject.types.common.models.DataVertical.VIDEOS; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -21,66 +24,66 @@ public class TransferCompatibilityProviderTest { public void shouldPreferOriginalAdapterWhenAvailable() { TransferExtension ext = mock(TransferExtension.class); Importer importer = mock(Importer.class); - when(ext.getImporter(eq("MEDIA"))).thenReturn(importer); - when(ext.getImporter(eq("PHOTOS"))).thenReturn(mock(Importer.class)); - when(ext.getImporter(eq("VIDEOS"))).thenReturn(mock(Importer.class)); + when(ext.getImporter(eq(MEDIA))).thenReturn(importer); + when(ext.getImporter(eq(PHOTOS))).thenReturn(mock(Importer.class)); + when(ext.getImporter(eq(VIDEOS))).thenReturn(mock(Importer.class)); Exporter exporter = mock(Exporter.class); - when(ext.getExporter(eq("MEDIA"))).thenReturn(exporter); - when(ext.getExporter(eq("PHOTOS"))).thenReturn(mock(Exporter.class)); - when(ext.getExporter(eq("VIDEOS"))).thenReturn(mock(Exporter.class)); + when(ext.getExporter(eq(MEDIA))).thenReturn(exporter); + when(ext.getExporter(eq(PHOTOS))).thenReturn(mock(Exporter.class)); + when(ext.getExporter(eq(VIDEOS))).thenReturn(mock(Exporter.class)); - assertThat(compatibilityProvider.getCompatibleImporter(ext, "MEDIA")).isSameAs(importer); - assertThat(compatibilityProvider.getCompatibleExporter(ext, "MEDIA")).isSameAs(exporter); + assertThat(compatibilityProvider.getCompatibleImporter(ext, MEDIA)).isSameAs(importer); + assertThat(compatibilityProvider.getCompatibleExporter(ext, MEDIA)).isSameAs(exporter); } @Test public void shouldConstructMediaImporterFromPhotoAndVideo() { TransferExtension ext = mock(TransferExtension.class); - when(ext.getImporter(eq("PHOTOS"))).thenReturn(mock(Importer.class)); - when(ext.getImporter(eq("VIDEOS"))).thenReturn(mock(Importer.class)); - when(ext.getImporter(eq("MEDIA"))).thenReturn(null); + when(ext.getImporter(eq(PHOTOS))).thenReturn(mock(Importer.class)); + when(ext.getImporter(eq(VIDEOS))).thenReturn(mock(Importer.class)); + when(ext.getImporter(eq(MEDIA))).thenReturn(null); - Importer imp = compatibilityProvider.getCompatibleImporter(ext, "MEDIA"); + Importer imp = compatibilityProvider.getCompatibleImporter(ext, MEDIA); assertThat(imp).isInstanceOf(MediaImporterDecorator.class); } @Test public void shouldConstructMediaExporterFromPhotoAndVideo() { TransferExtension ext = mock(TransferExtension.class); - when(ext.getExporter(eq("PHOTOS"))).thenReturn(mock(Exporter.class)); - when(ext.getExporter(eq("VIDEOS"))).thenReturn(mock(Exporter.class)); - when(ext.getExporter(eq("MEDIA"))).thenReturn(null); + when(ext.getExporter(eq(PHOTOS))).thenReturn(mock(Exporter.class)); + when(ext.getExporter(eq(VIDEOS))).thenReturn(mock(Exporter.class)); + when(ext.getExporter(eq(MEDIA))).thenReturn(null); - Exporter exp = compatibilityProvider.getCompatibleExporter(ext, "MEDIA"); + Exporter exp = compatibilityProvider.getCompatibleExporter(ext, MEDIA); assertThat(exp).isInstanceOf(MediaExporterDecorator.class); } @Test public void shouldConstructPhotoAndVideoExportersFromMedia() { TransferExtension ext = mock(TransferExtension.class); - when(ext.getExporter(eq("MEDIA"))).thenReturn(mock(Exporter.class)); + when(ext.getExporter(eq(MEDIA))).thenReturn(mock(Exporter.class)); - assertThat(compatibilityProvider.getCompatibleExporter(ext, "PHOTOS")) + assertThat(compatibilityProvider.getCompatibleExporter(ext, PHOTOS)) .isInstanceOf(AnyToAnyExporter.class); - assertThat(compatibilityProvider.getCompatibleExporter(ext, "VIDEOS")) + assertThat(compatibilityProvider.getCompatibleExporter(ext, VIDEOS)) .isInstanceOf(AnyToAnyExporter.class); } @Test public void shouldConstructPhotoAndVideoImportersFromMedia() { TransferExtension ext = mock(TransferExtension.class); - when(ext.getImporter(eq("MEDIA"))).thenReturn(mock(Importer.class)); + when(ext.getImporter(eq(MEDIA))).thenReturn(mock(Importer.class)); - assertThat(compatibilityProvider.getCompatibleImporter(ext, "PHOTOS")) + assertThat(compatibilityProvider.getCompatibleImporter(ext, PHOTOS)) .isInstanceOf(AnyToAnyImporter.class); - assertThat(compatibilityProvider.getCompatibleImporter(ext, "VIDEOS")) + assertThat(compatibilityProvider.getCompatibleImporter(ext, VIDEOS)) .isInstanceOf(AnyToAnyImporter.class); } @Test public void shouldMaintainOriginalException() { TransferExtension ext = mock(TransferExtension.class); - when(ext.getExporter(eq("MEDIA"))).thenThrow(new RuntimeException()); - assertThrows(Exception.class, () -> compatibilityProvider.getCompatibleExporter(ext, "MEDIA")); + when(ext.getExporter(eq(MEDIA))).thenThrow(new RuntimeException()); + assertThrows(Exception.class, () -> compatibilityProvider.getCompatibleExporter(ext, MEDIA)); } } diff --git a/portability-transfer/src/main/java/org/datatransferproject/transfer/JobMetadata.java b/portability-transfer/src/main/java/org/datatransferproject/transfer/JobMetadata.java index f9463f40a..a8cd41c07 100644 --- a/portability-transfer/src/main/java/org/datatransferproject/transfer/JobMetadata.java +++ b/portability-transfer/src/main/java/org/datatransferproject/transfer/JobMetadata.java @@ -19,6 +19,7 @@ import com.google.common.base.Stopwatch; import java.util.UUID; +import org.datatransferproject.types.common.models.DataVertical; /** * A class that contains metadata for a transfer worker's job. @@ -33,7 +34,7 @@ public final class JobMetadata { private static byte[] encodedPrivateKey = null; private static UUID jobId = null; - private static String dataType = null; + private static DataVertical dataType = null; private static String exportService = null; private static String importService = null; private static Stopwatch stopWatch = null; @@ -50,7 +51,7 @@ public static boolean isInitialized() { static void init( UUID initJobId, byte[] initEncodedPrivateKey, - String initDataType, + DataVertical initDataType, String initExportService, String initImportService, Stopwatch initStopWatch) { @@ -83,7 +84,7 @@ public static UUID getJobId() { return jobId; } - public static String getDataType() { + public static DataVertical getDataType() { Preconditions.checkState(isInitialized(), "JobMetadata must be initialized"); return dataType; } diff --git a/portability-transfer/src/test/java/org/datatransferproject/transfer/JobPollingServiceTest.java b/portability-transfer/src/test/java/org/datatransferproject/transfer/JobPollingServiceTest.java index 53ab99015..2f3113854 100644 --- a/portability-transfer/src/test/java/org/datatransferproject/transfer/JobPollingServiceTest.java +++ b/portability-transfer/src/test/java/org/datatransferproject/transfer/JobPollingServiceTest.java @@ -34,6 +34,7 @@ import org.datatransferproject.spi.transfer.security.TransferKeyGenerator; import org.datatransferproject.spi.transfer.security.TransferKeyGenerator.WorkerKeyPair; +import org.datatransferproject.types.common.models.DataVertical; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -115,7 +116,7 @@ public void pollingLifeCycle() throws Exception { // API inserts an job in initial authorization state job = PortabilityJob.builder() - .setTransferDataType("photo") + .setTransferDataType(DataVertical.PHOTOS) .setExportService("DummyExportService") .setImportService("DummyImportService") .setAndValidateJobAuthorization( diff --git a/portability-transfer/src/test/java/org/datatransferproject/transfer/WorkerModuleTest.java b/portability-transfer/src/test/java/org/datatransferproject/transfer/WorkerModuleTest.java index e58ca50cd..371585b90 100644 --- a/portability-transfer/src/test/java/org/datatransferproject/transfer/WorkerModuleTest.java +++ b/portability-transfer/src/test/java/org/datatransferproject/transfer/WorkerModuleTest.java @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableList; import org.datatransferproject.api.launcher.ExtensionContext; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.spi.transfer.extension.TransferExtension; import org.datatransferproject.spi.transfer.provider.Exporter; import org.datatransferproject.spi.transfer.provider.Importer; @@ -54,12 +55,12 @@ public String getServiceId() { } @Override - public Exporter getExporter(String transferDataType) { + public Exporter getExporter(DataVertical transferDataType) { return null; } @Override - public Importer getImporter(String transferDataType) { + public Importer getImporter(DataVertical transferDataType) { return null; } diff --git a/portability-types-client/src/main/java/org/datatransferproject/types/client/datatype/DataTypes.java b/portability-types-client/src/main/java/org/datatransferproject/types/client/datatype/DataTypes.java index 12c5292c6..b3541b3c7 100644 --- a/portability-types-client/src/main/java/org/datatransferproject/types/client/datatype/DataTypes.java +++ b/portability-types-client/src/main/java/org/datatransferproject/types/client/datatype/DataTypes.java @@ -19,18 +19,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Set; +import org.datatransferproject.types.common.models.DataVertical; /** The result of a request to list data types available for export and import. */ public class DataTypes { - private final Set dataTypes; + private final Set dataTypes; @JsonCreator - public DataTypes(@JsonProperty("transferDataTypes") Set dataTypes) { + public DataTypes(@JsonProperty("transferDataTypes") Set dataTypes) { this.dataTypes = dataTypes; } - public Set getDataTypes() { + public Set getDataTypes() { return dataTypes; } } diff --git a/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/CreateTransferJob.java b/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/CreateTransferJob.java index 0ed2f9102..0765c8355 100644 --- a/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/CreateTransferJob.java +++ b/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/CreateTransferJob.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import org.datatransferproject.types.common.models.DataVertical; import org.datatransferproject.types.common.ExportInformation; import javax.annotation.Nullable; @@ -30,7 +31,7 @@ public class CreateTransferJob { private final String importService; private final String exportCallbackUrl; private final String importCallbackUrl; - private final String dataType; + private final DataVertical dataType; private final ExportInformation exportInformation; private final String encryptionScheme; @@ -40,7 +41,7 @@ public CreateTransferJob( @JsonProperty(value = "importService", required = true) String importService, @JsonProperty(value = "exportCallbackUrl", required = true) String exportCallbackUrl, @JsonProperty(value = "importCallbackUrl", required = true) String importCallbackUrl, - @JsonProperty(value = "dataType", required = true) String dataType, + @JsonProperty(value = "dataType", required = true) DataVertical dataType, @JsonProperty(value = "exportInformation", required = false) ExportInformation exportInformation, @JsonProperty(value = "encryptionScheme", required = true) String encryptionScheme) { this.exportService = exportService; @@ -76,7 +77,7 @@ public String getImportCallbackUrl() { } @ApiModelProperty(value = "The type of data to transfer", dataType = "string", required = true) - public String getDataType() { + public DataVertical getDataType() { return dataType; } diff --git a/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/GetTransferServices.java b/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/GetTransferServices.java index 0cd63b3fe..00dba7cfc 100644 --- a/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/GetTransferServices.java +++ b/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/GetTransferServices.java @@ -16,17 +16,18 @@ package org.datatransferproject.types.client.transfer; import java.util.Objects; +import org.datatransferproject.types.common.models.DataVertical; /** Request to list services available for export and import for the given type. */ public class GetTransferServices { - private final String transferDataType; + private final DataVertical transferDataType; - public GetTransferServices(String transferDataType) { + public GetTransferServices(DataVertical transferDataType) { Objects.requireNonNull(transferDataType); this.transferDataType = transferDataType; } - public String getTransferDataType() { + public DataVertical getTransferDataType() { return transferDataType; } } diff --git a/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/TransferJob.java b/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/TransferJob.java index 3808e90b2..fd794509e 100644 --- a/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/TransferJob.java +++ b/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/TransferJob.java @@ -17,6 +17,8 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import org.datatransferproject.types.common.models.DataVertical; + import static org.datatransferproject.types.common.PortabilityCommon.AuthProtocol; /** @@ -35,7 +37,7 @@ public enum State { private final String id; private final String exportService; private final String importService; - private final String dataType; + private final DataVertical dataType; private final State state = State.CREATED; private final String exportUrl; private final String importUrl; @@ -49,7 +51,7 @@ public TransferJob( @JsonProperty(value = "id", required = true) String id, @JsonProperty(value = "exportService", required = true) String exportService, @JsonProperty(value = "importService", required = true) String importService, - @JsonProperty(value = "dataType", required = true) String dataType, + @JsonProperty(value = "dataType", required = true) DataVertical dataType, @JsonProperty(value = "exportUrl", required = true) String exportUrl, @JsonProperty(value = "importUrl", required = true) String importUrl, @JsonProperty(value = "exportTokenUrl", required = true) String exportTokenUrl, @@ -80,7 +82,7 @@ public String getImportService() { return importService; } - public String getDataType() { + public DataVertical getDataType() { return dataType; } diff --git a/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/TransferServices.java b/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/TransferServices.java index d383e5c53..87056e305 100644 --- a/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/TransferServices.java +++ b/portability-types-client/src/main/java/org/datatransferproject/types/client/transfer/TransferServices.java @@ -21,16 +21,17 @@ import io.swagger.annotations.ApiModelProperty; import java.util.Set; +import org.datatransferproject.types.common.models.DataVertical; /** Export and import services that support the provided data type. */ public class TransferServices { - private final String transferDataType; + private final DataVertical transferDataType; private final Set exportServices; private final Set importServices; @JsonCreator public TransferServices( - @JsonProperty(value = "transferDataType", required = true) String transferDataType, + @JsonProperty(value = "transferDataType", required = true) DataVertical transferDataType, @JsonProperty(value = "exportServices", required = true) Set exportServices, @JsonProperty(value = "importServices", required = true) Set importServices) { this.transferDataType = transferDataType; @@ -49,7 +50,7 @@ public Set getExportServices() { } @ApiModelProperty - public String getTransferDataType() { + public DataVertical getTransferDataType() { return this.transferDataType; } } diff --git a/portability-types-client/src/test/java/org/datatransferproject/types/client/transfer/CreateTransferJobTest.java b/portability-types-client/src/test/java/org/datatransferproject/types/client/transfer/CreateTransferJobTest.java index 03cb7e15e..f62f990a3 100644 --- a/portability-types-client/src/test/java/org/datatransferproject/types/client/transfer/CreateTransferJobTest.java +++ b/portability-types-client/src/test/java/org/datatransferproject/types/client/transfer/CreateTransferJobTest.java @@ -16,7 +16,10 @@ package org.datatransferproject.types.client.transfer; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; + import com.fasterxml.jackson.databind.ObjectMapper; +import org.datatransferproject.types.common.models.DataVertical; import org.junit.Assert; import org.junit.jupiter.api.Test; @@ -34,7 +37,7 @@ public void verifySerializeDeserialize() throws Exception { "testDestination", "https://localhost:3000/callback/testSource", "https://localhost:3000/callback/testDestination", - "PHOTOS", + PHOTOS, null, "cleartext")); @@ -46,6 +49,6 @@ public void verifySerializeDeserialize() throws Exception { "https://localhost:3000/callback/testSource", deserialized.getExportCallbackUrl()); Assert.assertEquals( "https://localhost:3000/callback/testDestination", deserialized.getImportCallbackUrl()); - Assert.assertEquals("PHOTOS", deserialized.getDataType()); + Assert.assertEquals(PHOTOS, deserialized.getDataType()); } } diff --git a/portability-types-client/src/test/java/org/datatransferproject/types/client/transfer/TransferJobTest.java b/portability-types-client/src/test/java/org/datatransferproject/types/client/transfer/TransferJobTest.java index e77caa499..41bd73fcc 100644 --- a/portability-types-client/src/test/java/org/datatransferproject/types/client/transfer/TransferJobTest.java +++ b/portability-types-client/src/test/java/org/datatransferproject/types/client/transfer/TransferJobTest.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test; import static com.google.common.truth.Truth.assertThat; +import static org.datatransferproject.types.common.models.DataVertical.PHOTOS; /* Test for TransferJob */ public class TransferJobTest { @@ -34,7 +35,7 @@ public void verifySerializeDeserialize() throws Exception { "1-2-3", "testExportService", "testImportService", - "PHOTOS", + PHOTOS, "exportUrl", "importUrl", "exportTokenUrl", @@ -49,7 +50,7 @@ public void verifySerializeDeserialize() throws Exception { assertThat("1-2-3").isEqualTo(deserialized.getId()); assertThat("testExportService").isEqualTo(deserialized.getExportService()); assertThat("testImportService").isEqualTo(deserialized.getImportService()); - assertThat("PHOTOS").isEqualTo(deserialized.getDataType()); + assertThat(PHOTOS).isEqualTo(deserialized.getDataType()); assertThat("exportUrl").isEqualTo(deserialized.getExportUrl()); assertThat("importUrl").isEqualTo(deserialized.getImportUrl()); assertThat("exportTokenUrl").isEqualTo(deserialized.getExportTokenUrl()); diff --git a/portability-types-common/src/main/java/org/datatransferproject/types/common/models/DataVertical.java b/portability-types-common/src/main/java/org/datatransferproject/types/common/models/DataVertical.java new file mode 100644 index 000000000..1ac82624b --- /dev/null +++ b/portability-types-common/src/main/java/org/datatransferproject/types/common/models/DataVertical.java @@ -0,0 +1,42 @@ +package org.datatransferproject.types.common.models; + +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.HashMap; +import java.util.Map; + +public enum DataVertical { + BLOBS("BLOBS"), + CALENDAR("CALENDAR"), + CONTACTS("CONTACTS"), + MAIL("MAIL"), + MEDIA("MEDIA"), + NOTES("NOTES"), + OFFLINE_DATA("OFFLINE-DATA"), + PHOTOS("PHOTOS"), + PLAYLISTS("PLAYLISTS"), + SOCIAL_POSTS("SOCIAL-POSTS"), + TASKS("TASKS"), + VIDEOS("VIDEOS"); + + private final String dataType; + + DataVertical(String dataType) { + this.dataType = dataType; + } + + @JsonValue + public String getDataType() { + return dataType; + } + + private static final Map BY_TYPE = new HashMap<>(); + static { + for (DataVertical e: values()) { + BY_TYPE.put(e.dataType, e); + } + } + + public static DataVertical fromDataType(String dataType) { + return BY_TYPE.get(dataType); + } +} diff --git a/portability-types-common/src/test/java/org/datatransferproject/types/common/models/DataVerticalTest.java b/portability-types-common/src/test/java/org/datatransferproject/types/common/models/DataVerticalTest.java new file mode 100644 index 000000000..879b8769a --- /dev/null +++ b/portability-types-common/src/test/java/org/datatransferproject/types/common/models/DataVerticalTest.java @@ -0,0 +1,20 @@ +package org.datatransferproject.types.common.models; + +import static org.datatransferproject.types.common.models.DataVertical.SOCIAL_POSTS; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +class DataVerticalTest { + + @Test + void shouldSerializeSocialPostsCorrectly() throws JsonProcessingException { + ObjectMapper om = new ObjectMapper(); + String json = "\"SOCIAL-POSTS\""; + assertEquals(SOCIAL_POSTS, om.readValue(json, DataVertical.class)); + assertEquals(SOCIAL_POSTS, DataVertical.fromDataType("SOCIAL-POSTS")); + assertEquals(json, om.writeValueAsString(SOCIAL_POSTS)); + } +} diff --git a/portability-types-transfer/src/main/java/org/datatransferproject/types/transfer/retry/RetryingCallable.java b/portability-types-transfer/src/main/java/org/datatransferproject/types/transfer/retry/RetryingCallable.java index 489e63187..ad89f277e 100644 --- a/portability-types-transfer/src/main/java/org/datatransferproject/types/transfer/retry/RetryingCallable.java +++ b/portability-types-transfer/src/main/java/org/datatransferproject/types/transfer/retry/RetryingCallable.java @@ -23,6 +23,7 @@ import java.time.Instant; import java.util.concurrent.Callable; import org.datatransferproject.api.launcher.Monitor; +import org.datatransferproject.types.common.models.DataVertical; /** * Class for retrying a {@link Callable} given a {@link RetryStrategyLibrary}. @@ -35,7 +36,7 @@ public class RetryingCallable implements Callable { private final RetryStrategyLibrary retryStrategyLibrary; private final Clock clock; private final Monitor monitor; - private final String dataType; + private final DataVertical dataType; private final String service; private volatile int attempts; @@ -46,7 +47,7 @@ public RetryingCallable( RetryStrategyLibrary retryStrategyLibrary, Clock clock, Monitor monitor, - String dataType, + DataVertical dataType, String service) { this.callable = callable; this.retryStrategyLibrary = retryStrategyLibrary;