use of org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore in project data-transfer-project by google.
the class MicrosoftTransferExtension method initialize.
@Override
public void initialize(ExtensionContext context) {
// times.
if (initialized)
return;
TemporaryPerJobDataStore jobStore = context.getService(TemporaryPerJobDataStore.class);
HttpTransport httpTransport = context.getService(HttpTransport.class);
JsonFactory jsonFactory = context.getService(JsonFactory.class);
TransformerService transformerService = new TransformerServiceImpl();
OkHttpClient client = new OkHttpClient.Builder().build();
ObjectMapper mapper = new ObjectMapper();
AppCredentials appCredentials;
try {
appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("MICROSOFT_KEY", "MICROSOFT_SECRET");
} catch (IOException e) {
Monitor monitor = context.getMonitor();
monitor.info(() -> "Unable to retrieve Microsoft AppCredentials. Did you set MICROSOFT_KEY and MICROSOFT_SECRET?");
return;
}
// Create the MicrosoftCredentialFactory with the given {@link AppCredentials}.
MicrosoftCredentialFactory credentialFactory = new MicrosoftCredentialFactory(httpTransport, jsonFactory, appCredentials);
Monitor monitor = context.getMonitor();
ImmutableMap.Builder<String, Importer> importBuilder = ImmutableMap.builder();
importBuilder.put(CONTACTS, new MicrosoftContactsImporter(BASE_GRAPH_URL, client, mapper, transformerService));
importBuilder.put(CALENDAR, new MicrosoftCalendarImporter(BASE_GRAPH_URL, client, mapper, transformerService));
importBuilder.put(PHOTOS, new MicrosoftPhotosImporter(BASE_GRAPH_URL, client, mapper, jobStore, monitor, credentialFactory));
importerMap = importBuilder.build();
ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
exporterBuilder.put(CONTACTS, new MicrosoftContactsExporter(BASE_GRAPH_URL, client, mapper, transformerService));
exporterBuilder.put(CALENDAR, new MicrosoftCalendarExporter(BASE_GRAPH_URL, client, mapper, transformerService));
exporterBuilder.put(PHOTOS, new MicrosoftPhotosExporter(credentialFactory, jsonFactory, monitor));
exporterBuilder.put(OFFLINE_DATA, new MicrosoftOfflineDataExporter(BASE_GRAPH_URL, client, mapper));
exporterMap = exporterBuilder.build();
initialized = true;
}
use of org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore in project data-transfer-project by google.
the class FacebookPhotosExporterTest method setUp.
@Before
public void setUp() throws IOException {
FacebookPhotosInterface photosInterface = mock(FacebookPhotosInterface.class);
// Set up example album
Album album = new Album();
album.setId(ALBUM_ID);
album.setName(ALBUM_NAME);
album.setDescription(ALBUM_DESCRIPTION);
ArrayList<Album> albums = new ArrayList<>();
albums.add(album);
@SuppressWarnings("unchecked") Connection<Album> albumConnection = mock(Connection.class);
when(photosInterface.getAlbums(Mockito.any())).thenReturn(albumConnection);
when(albumConnection.getData()).thenReturn(albums);
// Set up example photo
Photo photo = new Photo();
photo.setId(PHOTO_ID);
photo.setCreatedTime(PHOTO_TIME);
Photo.Image image = new Photo.Image();
image.setSource(PHOTO_SOURCE);
photo.addImage(image);
photo.setName(PHOTO_NAME);
ArrayList<Photo> photos = new ArrayList<>();
photos.add(photo);
@SuppressWarnings("unchecked") Connection<Photo> photoConnection = mock(Connection.class);
when(photosInterface.getPhotos(ALBUM_ID, Optional.empty())).thenReturn(photoConnection);
when(photoConnection.getData()).thenReturn(photos);
final ImageStreamProvider imageStreamProvider = mock(ImageStreamProvider.class);
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("test.jpeg");
HttpURLConnection connection = mock(HttpURLConnection.class);
when(imageStreamProvider.getConnection(ArgumentMatchers.anyString())).thenReturn(connection);
when(connection.getInputStream()).thenReturn(inputStream);
final TemporaryPerJobDataStore store = mock(TemporaryPerJobDataStore.class);
facebookPhotosExporter = new FacebookPhotosExporter(new AppCredentials("key", "secret"), photosInterface, null, store, imageStreamProvider);
}
Aggregations