Search in sources :

Example 1 with MailContainerModel

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;
        });
    }
}
Also used : MailContainerModel(org.datatransferproject.types.common.models.mail.MailContainerModel)

Example 2 with MailContainerModel

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);
}
Also used : ContainerResource(org.datatransferproject.types.common.models.ContainerResource) MailContainerResource(org.datatransferproject.types.common.models.mail.MailContainerResource) MailContainerModel(org.datatransferproject.types.common.models.mail.MailContainerModel) MailContainerResource(org.datatransferproject.types.common.models.mail.MailContainerResource) MailMessageModel(org.datatransferproject.types.common.models.mail.MailMessageModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

MailContainerModel (org.datatransferproject.types.common.models.mail.MailContainerModel)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)1 MailContainerResource (org.datatransferproject.types.common.models.mail.MailContainerResource)1 MailMessageModel (org.datatransferproject.types.common.models.mail.MailMessageModel)1 Test (org.junit.Test)1