Skip to content

Commit

Permalink
add DataVertical enum to replace string data types
Browse files Browse the repository at this point in the history
  • Loading branch information
incjo committed Aug 30, 2022
1 parent 4d2dba2 commit 962c7fa
Show file tree
Hide file tree
Showing 78 changed files with 676 additions and 449 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,12 +30,12 @@ public String getTokenUrl() {
}

@Override
public Map<String, Set<String>> getExportScopes() {
return ImmutableMap.of("PHOTOS", ImmutableSet.of("db.read"));
public Map<DataVertical, Set<String>> getExportScopes() {
return ImmutableMap.of(PHOTOS, ImmutableSet.of("db.read"));
}

@Override
public Map<String, Set<String>> getImportScopes() {
return ImmutableMap.of("PHOTOS", ImmutableSet.of("db.write"));
public Map<DataVertical, Set<String>> getImportScopes() {
return ImmutableMap.of(PHOTOS, ImmutableSet.of("db.write"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -56,16 +55,16 @@ public String getTokenUrl() {

// For descriptions of scopes see: https://developers.deezer.com/api/permissions
@Override
public Map<String, Set<String>> getExportScopes() {
return ImmutableMap.<String, Set<String>>builder()
.put("PLAYLISTS", ImmutableSet.of("offline_access,manage_library"))
public Map<DataVertical, Set<String>> getExportScopes() {
return ImmutableMap.<DataVertical, Set<String>>builder()
.put(PLAYLISTS, ImmutableSet.of("offline_access,manage_library"))
.build();
}

@Override
public Map<String, Set<String>> getImportScopes() {
return ImmutableMap.<String, Set<String>>builder()
.put("PLAYLISTS", ImmutableSet.of("offline_access,manage_library"))
public Map<DataVertical, Set<String>> getImportScopes() {
return ImmutableMap.<DataVertical, Set<String>>builder()
.put(PLAYLISTS, ImmutableSet.of("offline_access,manage_library"))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,18 +55,18 @@ public String getTokenUrl() {
}

@Override
public Map<String, Set<String>> getExportScopes() {
return ImmutableMap.<String, Set<String>>builder()
.put("PHOTOS", ImmutableSet.of("user_photos"))
.put("VIDEOS", ImmutableSet.of("user_videos"))
public Map<DataVertical, Set<String>> getExportScopes() {
return ImmutableMap.<DataVertical, Set<String>>builder()
.put(PHOTOS, ImmutableSet.of("user_photos"))
.put(VIDEOS, ImmutableSet.of("user_videos"))
.build();
}

@Override
public Map<String, Set<String>> getImportScopes() {
return ImmutableMap.<String, Set<String>>builder()
.put("PHOTOS", ImmutableSet.of("user_photos"))
.put("VIDEOS", ImmutableSet.of("user_videos"))
public Map<DataVertical, Set<String>> getImportScopes() {
return ImmutableMap.<DataVertical, Set<String>>builder()
.put(PHOTOS, ImmutableSet.of("user_photos"))
.put(VIDEOS, ImmutableSet.of("user_videos"))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

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;
import java.util.List;
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
Expand Down Expand Up @@ -53,19 +56,19 @@ public String getAccessTokenUrl() {
}

@Override
public List<String> getExportTypes() {
return ImmutableList.of("PHOTOS");
public List<DataVertical> getExportTypes() {
return ImmutableList.of(PHOTOS);
}

@Override
public List<String> getImportTypes() {
return ImmutableList.of("PHOTOS");
public List<DataVertical> getImportTypes() {
return ImmutableList.of(PHOTOS);
}

public Map<String, String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,22 +39,22 @@ public String getServiceName() {

// See https://developers.google.com/identity/protocols/googlescopes
@Override
public Map<String, Set<String>> getExportScopes() {
return ImmutableMap.<String, Set<String>>builder()
.put("SOCIAL-POSTS", ImmutableSet.of("https://www.googleapis.com/auth/blogger.readonly"))
public Map<DataVertical, Set<String>> getExportScopes() {
return ImmutableMap.<DataVertical, Set<String>>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<String, Set<String>> getImportScopes() {
return ImmutableMap.<String, Set<String>>builder()
.put("SOCIAL-POSTS", ImmutableSet.of(
public Map<DataVertical, Set<String>> getImportScopes() {
return ImmutableMap.<DataVertical, Set<String>>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
"https://www.googleapis.com/auth/drive.file"
))
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,31 +58,31 @@ public String getTokenUrl() {

// See https://developers.google.com/identity/protocols/googlescopes
@Override
public Map<String, Set<String>> getExportScopes() {
return ImmutableMap.<String, Set<String>>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<DataVertical, Set<String>> getExportScopes() {
return ImmutableMap.<DataVertical, Set<String>>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<String, Set<String>> getImportScopes() {
return ImmutableMap.<String, Set<String>>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<DataVertical, Set<String>> getImportScopes() {
return ImmutableMap.<DataVertical, Set<String>>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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/** */
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,12 +48,12 @@ public String getTokenUrl() {

// Imgur doesn't require scopes
@Override
public Map<String, Set<String>> getExportScopes() {
return ImmutableMap.of("PHOTOS", ImmutableSet.of(""));
public Map<DataVertical, Set<String>> getExportScopes() {
return ImmutableMap.of(PHOTOS, ImmutableSet.of(""));
}

@Override
public Map<String, Set<String>> getImportScopes() {
return ImmutableMap.of("PHOTOS", ImmutableSet.of(""));
public Map<DataVertical, Set<String>> getImportScopes() {
return ImmutableMap.of(PHOTOS, ImmutableSet.of(""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,13 +49,13 @@ public String getTokenUrl() {

// See https://www.instagram.com/developer/authorization/
@Override
public Map<String, Set<String>> getExportScopes() {
return ImmutableMap.of("PHOTOS", ImmutableSet.of("basic"));
public Map<DataVertical, Set<String>> getExportScopes() {
return ImmutableMap.of(PHOTOS, ImmutableSet.of("basic"));
}

// Instagram does not provide an API for import; https://help.instagram.com/442418472487929
@Override
public Map<String, Set<String>> getImportScopes() {
public Map<DataVertical, Set<String>> getImportScopes() {
return ImmutableMap.of();
}
}
Loading

0 comments on commit 962c7fa

Please sign in to comment.