use of org.dataportabilityproject.types.transfer.models.calendar.CalendarAttendeeModel in project data-transfer-project by google.
the class ToCalendarEventModelTransformerTest method testTransform.
@SuppressWarnings("unchecked")
@Test
public void testTransform() throws IOException {
context.setProperty(CALENDAR_ID, "123");
Map<String, Object> rawEvent = mapper.readValue(SAMPLE_CALENDAR_EVENT, Map.class);
CalendarEventModel event = transformer.apply(rawEvent, context);
Assert.assertEquals("123", event.getCalendarId());
Assert.assertEquals("Some Place", event.getLocation());
Assert.assertEquals("Test Appointment 1", event.getTitle());
Assert.assertTrue(event.getNotes().length() > 5);
Assert.assertEquals(1, event.getAttendees().size());
CalendarAttendeeModel attendee = event.getAttendees().get(0);
Assert.assertEquals("Test Test1", attendee.getDisplayName());
Assert.assertEquals("foo@foo.com", attendee.getEmail());
Assert.assertFalse(attendee.getOptional());
Assert.assertEquals(18, event.getStartTime().getDateTime().getHour());
Assert.assertEquals(0, event.getStartTime().getDateTime().getMinute());
Assert.assertEquals(18, event.getEndTime().getDateTime().getHour());
Assert.assertEquals(30, event.getEndTime().getDateTime().getMinute());
}
use of org.dataportabilityproject.types.transfer.models.calendar.CalendarAttendeeModel in project data-transfer-project by google.
the class MicrosoftCalendarImportTest method testImport.
@Test
@SuppressWarnings("unchecked")
public void testImport() throws Exception {
server.enqueue(new MockResponse().setBody(BATCH_CALENDAR_RESPONSE));
server.enqueue(new MockResponse().setResponseCode(201).setBody(BATCH_EVENT_RESPONSE));
server.start();
HttpUrl baseUrl = server.url("");
MicrosoftCalendarImporter importer = new MicrosoftCalendarImporter(baseUrl.toString(), client, mapper, transformerService, jobStore);
CalendarModel calendarModel = new CalendarModel("OldId1", "name", "name");
CalendarAttendeeModel attendeeModel = new CalendarAttendeeModel("Test Attendee", "test@test.com", false);
CalendarEventModel.CalendarEventTime start = new CalendarEventModel.CalendarEventTime(ZonedDateTime.now(ZoneId.of("GMT")).toOffsetDateTime(), false);
CalendarEventModel.CalendarEventTime end = new CalendarEventModel.CalendarEventTime(ZonedDateTime.now(ZoneId.of("GMT")).toOffsetDateTime(), false);
CalendarEventModel eventModel = new CalendarEventModel("OldId1", "Event1", "Test Notes", singletonList(attendeeModel), "Location1", start, end);
CalendarContainerResource resource = new CalendarContainerResource(singleton(calendarModel), singleton(eventModel));
ImportResult result = importer.importItem(JOB_ID, token, resource);
Assert.assertEquals(ImportResult.ResultType.OK, result.getType());
// verify the batch calendar request
RecordedRequest calendarBatch = server.takeRequest();
Map<String, Object> calendarBody = (Map<String, Object>) mapper.readValue(calendarBatch.getBody().readUtf8(), Map.class);
List<Map<String, Object>> calendarRequests = (List<Map<String, Object>>) calendarBody.get("requests");
Assert.assertNotNull(calendarRequests);
Assert.assertEquals(1, calendarRequests.size());
Map<String, Object> calendarRequest = calendarRequests.get(0);
Assert.assertNotNull(calendarRequest.get("headers"));
Assert.assertEquals("POST", calendarRequest.get("method"));
Assert.assertEquals("/v1.0/me/calendars", calendarRequest.get("url"));
Map<String, Object> calendarRequestBody = (Map<String, Object>) calendarRequest.get("body");
Assert.assertNotNull(calendarRequestBody);
Assert.assertEquals("name", calendarRequestBody.get("name"));
// verify the calendar id mapping from old id to new id was saved
Assert.assertEquals("NewId1", jobStore.findData(TempCalendarData.class, JOB_ID).getImportedId("OldId1"));
// verify the batch event request
RecordedRequest eventBatch = server.takeRequest();
Map<String, Object> eventRequests = (Map<String, Object>) mapper.readValue(eventBatch.getBody().readUtf8(), Map.class);
Map<String, Object> eventRequest = (Map<String, Object>) ((List<Map<String, Object>>) eventRequests.get("requests")).get(0);
Assert.assertNotNull(eventRequest.get("headers"));
Assert.assertEquals("POST", eventRequest.get("method"));
Assert.assertEquals("/v1.0/me/calendars/NewId1/events", // verify the URL is contructed correctly with NewId
eventRequest.get("url"));
Map<String, Object> eventRequestBody = (Map<String, Object>) eventRequest.get("body");
Assert.assertNotNull(eventRequestBody);
Assert.assertEquals("Event1", eventRequestBody.get("subject"));
Map<String, Object> location = (Map<String, Object>) eventRequestBody.get("location");
Assert.assertEquals("Location1", location.get("displayName"));
Assert.assertEquals("Default", location.get("locationType"));
Map<String, Object> body = (Map<String, Object>) eventRequestBody.get("body");
Assert.assertEquals("Test Notes", body.get("content"));
Assert.assertEquals("HTML", body.get("contentType"));
List<Map<String, Object>> attendees = (List<Map<String, Object>>) eventRequestBody.get("attendees");
Assert.assertEquals(1, attendees.size());
Map<String, Object> attendee = (Map<String, Object>) attendees.get(0);
Assert.assertEquals("required", attendee.get("type"));
Map<String, Object> emailAddress = (Map<String, Object>) attendee.get("emailAddress");
Assert.assertEquals("test@test.com", emailAddress.get("address"));
Assert.assertEquals("Test Attendee", emailAddress.get("name"));
// verify dates
Map<String, Object> startDate = (Map<String, Object>) eventRequestBody.get("start");
Assert.assertNotNull(startDate.get("dateTime"));
Assert.assertEquals("UTC", startDate.get("timeZone"));
Map<String, Object> endDate = (Map<String, Object>) eventRequestBody.get("end");
Assert.assertNotNull(endDate.get("dateTime"));
Assert.assertEquals("UTC", endDate.get("timeZone"));
}
use of org.dataportabilityproject.types.transfer.models.calendar.CalendarAttendeeModel in project data-transfer-project by google.
the class ToCalendarAttendeeModelTransformerTest method testTransform.
@Test
public void testTransform() {
Map<String, Object> attendeeMap = new HashMap<>();
attendeeMap.put("type", "required");
Map<String, String> addressMap = new HashMap<>();
addressMap.put("name", "Test Test1");
addressMap.put("address", "foo@foo.com");
attendeeMap.put("emailAddress", addressMap);
CalendarAttendeeModel attendee = transformer.apply(attendeeMap, new TestTransformerContext());
Assert.assertFalse(attendee.getOptional());
Assert.assertEquals("Test Test1", attendee.getDisplayName());
Assert.assertEquals("foo@foo.com", attendee.getEmail());
}
use of org.dataportabilityproject.types.transfer.models.calendar.CalendarAttendeeModel in project data-transfer-project by google.
the class ToCalendarEventModelTransformer method apply.
@Override
@SuppressWarnings("unchecked")
public CalendarEventModel apply(Map<String, Object> event, TransformerContext context) {
if (!"singleInstance".equals(event.get("type"))) {
// support single instances for now;recurring events later
return null;
}
String calendarId = context.getProperty(CALENDAR_ID);
String title = (String) event.getOrDefault("subject", "");
String location = TransformerHelper.getOrDefault("location", "displayName", event, "");
// Notes is itemBody resource type defined as: { "content": "string", "contentType": "String"}
String notes = TransformerHelper.getOrDefault("body", "content", event, "");
List<Map<String, Object>> rawAttendees = (List<Map<String, Object>>) event.getOrDefault("attendees", emptyList());
List<CalendarAttendeeModel> attendees = new ArrayList<>();
for (Object rawAttendee : rawAttendees) {
CalendarAttendeeModel attendee = context.transform(CalendarAttendeeModel.class, rawAttendee);
if (attendee != null) {
attendees.add(attendee);
}
}
CalendarEventModel.CalendarEventTime startTime = context.transform(CalendarEventModel.CalendarEventTime.class, event.get("start"));
if (startTime == null) {
context.problem("Could not parse start time. Skipping event.");
return null;
}
CalendarEventModel.CalendarEventTime endTime = context.transform(CalendarEventModel.CalendarEventTime.class, event.get("end"));
if (endTime == null) {
context.problem("Could not parse end time. Skipping event.");
return null;
}
return new CalendarEventModel(calendarId, title, notes, attendees, location, startTime, endTime);
}
Aggregations