use of org.datatransferproject.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class AuthTestDriver method getOAuthTokenCode.
/**
* Performs an OAuth flow using the general AuthDataGenerator, returning a token.
*
* @return the token
*/
public TokenAuthData getOAuthTokenCode() throws Exception {
OkHttpClient client = TestHelper.createTestBuilder(callbackHost).build();
AuthDataGenerator authDataGenerator = new MicrosoftAuthServiceExtension().getAuthDataGenerator("CONTACTS", AuthMode.EXPORT);
AuthFlowConfiguration configuration = authDataGenerator.generateConfiguration(callbackBase, "1");
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI(configuration.getAuthUrl()));
// Execute the request and retrieve the auth code.
String authCode = retrieveAuthCode(client);
// get the token
TokenAuthData tokenData = (TokenAuthData) authDataGenerator.generateAuthData(callbackBase, authCode, "1", configuration.getInitialAuthData(), null);
// System.out.println("TOKEN: " + tokenData.getToken());
return tokenData;
}
use of org.datatransferproject.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class LocalImportTestRunner method main.
@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
AuthTestDriver authTestDriver = new AuthTestDriver();
MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
TokenAuthData token = authTestDriver.getOAuthTokenCode();
Importer<TokenAuthData, ContactsModelWrapper> contacts = (Importer<TokenAuthData, ContactsModelWrapper>) serviceProvider.getImporter("CONTACTS");
ContactsModelWrapper wrapper = new ContactsModelWrapper(createCards());
FakeIdempotentImportExecutor executor = new FakeIdempotentImportExecutor();
ImportResult result = contacts.importItem(UUID.randomUUID(), executor, token, wrapper);
}
use of org.datatransferproject.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class MicrosoftContactsImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokenAuthData authData, ContactsModelWrapper wrapper) {
JCardReader reader = new JCardReader(wrapper.getVCards());
try {
List<VCard> cards = reader.readAll();
List<String> problems = new ArrayList<>();
int[] id = new int[] { 1 };
List<Map<String, Object>> requests = cards.stream().map(card -> {
TransformResult<LinkedHashMap> result = transformerService.transform(LinkedHashMap.class, card);
problems.addAll(result.getProblems());
LinkedHashMap contact = result.getTransformed();
Map<String, Object> request = createRequest(id[0], CONTACTS_URL, contact);
id[0]++;
return request;
}).collect(toList());
if (!problems.isEmpty()) {
// TODO log problems
}
return batchRequest(authData, requests, baseUrl, client, objectMapper).getResult();
} catch (IOException e) {
// TODO log
e.printStackTrace();
return new ImportResult(e);
}
}
use of org.datatransferproject.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class MicrosoftCalendarImportTest method setUp.
@Before
public void setUp() {
client = new OkHttpClient.Builder().build();
mapper = new ObjectMapper();
transformerService = new TransformerServiceImpl();
token = new TokenAuthData("token456");
server = new MockWebServer();
}
use of org.datatransferproject.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class LocalExportTestRunner method main.
@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
AuthTestDriver authTestDriver = new AuthTestDriver();
MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
TokenAuthData token = authTestDriver.getOAuthTokenCode();
Exporter<TokenAuthData, ContactsModelWrapper> contacts = (Exporter<TokenAuthData, ContactsModelWrapper>) serviceProvider.getExporter("CONTACTS");
ExportResult<ContactsModelWrapper> wrapper = contacts.export(UUID.randomUUID(), token, Optional.empty());
}
Aggregations