use of org.datatransferproject.types.common.models.mail.MailContainerModel in project data-transfer-project by google.
the class GoogleMailImporter method importLabels.
/**
* Creates a label in the import account, if it doesn't already exist, for all {@code folders} .
*/
private void importLabels(TokensAndUrlAuthData authData, IdempotentImportExecutor idempotentExecutor, Supplier<Map<String, String>> allDestinationLabels, Collection<MailContainerModel> folders) throws Exception {
for (MailContainerModel mailContainerModel : folders) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(mailContainerModel.getName()));
String exportedLabelName = mailContainerModel.getName();
idempotentExecutor.executeAndSwallowIOExceptions(exportedLabelName, "Label - " + exportedLabelName, () -> {
String importerLabelId = allDestinationLabels.get().get(mailContainerModel.getName());
if (importerLabelId == null) {
importerLabelId = createImportedLabelId(authData, mailContainerModel.getName());
}
return importerLabelId;
});
}
}
use of org.datatransferproject.types.common.models.mail.MailContainerModel in project data-transfer-project by google.
the class MailContainerResourceTest method verifySerializeDeserialize.
@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerSubtypes(MailContainerResource.class);
List<MailContainerModel> containers = ImmutableList.of(new MailContainerModel("id1", "container1"), new MailContainerModel("id2", "container2"));
List<MailMessageModel> messages = ImmutableList.of(new MailMessageModel("foo", ImmutableList.of("1")), new MailMessageModel("bar", ImmutableList.of("1", "2'")));
ContainerResource data = new MailContainerResource(containers, messages);
String serialized = objectMapper.writeValueAsString(data);
ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
Truth.assertThat(deserializedModel).isNotNull();
Truth.assertThat(deserializedModel).isInstanceOf(MailContainerResource.class);
MailContainerResource deserialized = (MailContainerResource) deserializedModel;
Truth.assertThat(deserialized.getMessages()).hasSize(2);
Truth.assertThat(deserialized.getFolders()).hasSize(2);
Truth.assertThat(deserialized).isEqualTo(data);
}
Aggregations