use of org.dataportabilityproject.spi.transfer.types.TempCalendarData in project data-transfer-project by google.
the class GoogleCalendarImporter method importSingleCalendar.
@VisibleForTesting
void importSingleCalendar(UUID jobId, AuthData authData, CalendarModel calendarModel) throws IOException {
com.google.api.services.calendar.model.Calendar toInsert = convertToGoogleCalendar(calendarModel);
com.google.api.services.calendar.model.Calendar calendarResult = getOrCreateCalendarInterface(authData).calendars().insert(toInsert).execute();
TempCalendarData calendarMappings = jobStore.findData(TempCalendarData.class, jobId);
if (calendarMappings == null) {
calendarMappings = new TempCalendarData(jobId);
jobStore.create(jobId, calendarMappings);
}
calendarMappings.addIdMapping(calendarModel.getId(), calendarResult.getId());
jobStore.update(jobId, calendarMappings);
}
use of org.dataportabilityproject.spi.transfer.types.TempCalendarData in project data-transfer-project by google.
the class MicrosoftCalendarImporter method importItem.
@SuppressWarnings("unchecked")
@Override
public ImportResult importItem(UUID jobId, TokenAuthData authData, CalendarContainerResource data) {
TempCalendarData calendarMappings = jobStore.findData(TempCalendarData.class, jobId);
if (calendarMappings == null) {
calendarMappings = new TempCalendarData(jobId);
jobStore.create(jobId, calendarMappings);
}
Map<String, String> requestIdToExportedId = new HashMap<>();
List<String> problems = new ArrayList<>();
int requestId = 1;
List<Map<String, Object>> calendarRequests = new ArrayList<>();
for (CalendarModel calendar : data.getCalendars()) {
Map<String, Object> request = createRequestItem(calendar, requestId, CALENDAR_SUBPATH, problems);
requestIdToExportedId.put(String.valueOf(requestId), calendar.getId());
requestId++;
calendarRequests.add(request);
}
if (!problems.isEmpty()) {
// TODO log problems
}
RequestHelper.BatchResponse calendarResponse = RequestHelper.batchRequest(authData, calendarRequests, baseUrl, client, objectMapper);
if (ImportResult.ResultType.OK != calendarResponse.getResult().getType()) {
// TODO log problems
return calendarResponse.getResult();
}
List<Map<String, Object>> batchResponses = calendarResponse.getBatchResponse();
for (Map<String, Object> batchResponse : batchResponses) {
String batchRequestId = (String) batchResponse.get("id");
if (batchRequestId == null) {
problems.add("Null request id returned by batch response");
continue;
}
Integer status = (Integer) batchResponse.get("status");
if (status == null || 201 != status) {
problems.add("Error creating calendar: " + batchRequestId);
continue;
}
Map<String, Object> body = (Map<String, Object>) batchResponse.get("body");
if (body == null) {
problems.add("Invalid body returned from batch calendar create: " + batchRequestId);
continue;
}
calendarMappings.addIdMapping(requestIdToExportedId.get(batchRequestId), (String) body.get("id"));
}
jobStore.update(jobId, calendarMappings);
List<Map<String, Object>> eventRequests = new ArrayList<>();
requestId = 1;
for (CalendarEventModel event : data.getEvents()) {
String importedId = calendarMappings.getImportedId(event.getCalendarId());
Map<String, Object> request = createRequestItem(event, requestId, String.format(EVENT_SUBPATH, importedId), problems);
requestId++;
eventRequests.add(request);
}
if (!problems.isEmpty()) {
// TODO log problems
}
RequestHelper.BatchResponse eventResponse = RequestHelper.batchRequest(authData, eventRequests, baseUrl, client, objectMapper);
if (ImportResult.ResultType.OK != eventResponse.getResult().getType()) {
// TODO log problems
return eventResponse.getResult();
}
return eventResponse.getResult();
}
use of org.dataportabilityproject.spi.transfer.types.TempCalendarData in project data-transfer-project by google.
the class TempCalendarDataTest method verifySerializeDeserialize.
@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
TempCalendarData calendarData = new TempCalendarData(JOB_ID, Collections.singletonMap("old1", "new1"));
String serialized = objectMapper.writeValueAsString(calendarData);
TempCalendarData deserialized = objectMapper.readValue(serialized, TempCalendarData.class);
Assert.assertEquals(JOB_ID, deserialized.getJobId());
Assert.assertEquals("new1", deserialized.getImportedId("old1"));
}
use of org.dataportabilityproject.spi.transfer.types.TempCalendarData in project data-transfer-project by google.
the class GoogleCalendarImporter method importSingleEvent.
@VisibleForTesting
void importSingleEvent(UUID jobId, AuthData authData, CalendarEventModel eventModel) throws IOException {
Event event = convertToGoogleCalendarEvent(eventModel);
// calendarMappings better not be null!
TempCalendarData calendarMappings = jobStore.findData(TempCalendarData.class, jobId);
String newCalendarId = calendarMappings.getImportedId(eventModel.getCalendarId());
getOrCreateCalendarInterface(authData).events().insert(newCalendarId, event).execute();
}
Aggregations