Search in sources :

Example 1 with SocialActivityContainerResource

use of org.datatransferproject.types.common.models.social.SocialActivityContainerResource in project data-transfer-project by google.

the class GooglePlusExporter method export.

@Override
public ExportResult<SocialActivityContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws IOException {
    Plus plus = getOrCreatePeopleService(authData);
    Plus.Activities.List listActivities = plus.activities().list("me", "public");
    if (exportInformation.isPresent()) {
        StringPaginationToken pageToken = (StringPaginationToken) exportInformation.get().getPaginationData();
        listActivities.setPageToken(pageToken.getToken());
    }
    ActivityFeed activityFeed = listActivities.execute();
    List<Activity> activities = activityFeed.getItems();
    ContinuationData continuationData = null;
    SocialActivityContainerResource results = null;
    if (activities != null && !activities.isEmpty()) {
        List<SocialActivityModel> activityModels = new ArrayList<>();
        Activity.Actor actor = activities.get(0).getActor();
        SocialActivityActor parsedActor = new SocialActivityActor(actor.getUrl(), actor.getDisplayName(), actor.getUrl());
        if (!Strings.isNullOrEmpty(activityFeed.getNextPageToken())) {
            continuationData = new ContinuationData(new StringPaginationToken(activityFeed.getNextPageToken()));
        }
        for (Activity activity : activities) {
            try {
                activityModels.add(postToActivityModel(activity));
            } catch (RuntimeException e) {
                throw new IOException("Problem exporting: " + activity, e);
            }
        }
        results = new SocialActivityContainerResource(jobId.toString(), parsedActor, activityModels);
    }
    return new ExportResult<>(continuationData == null ? ResultType.END : ResultType.CONTINUE, results, continuationData);
}
Also used : SocialActivityContainerResource(org.datatransferproject.types.common.models.social.SocialActivityContainerResource) ArrayList(java.util.ArrayList) Activity(com.google.api.services.plus.model.Activity) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) IOException(java.io.IOException) ActivityFeed(com.google.api.services.plus.model.ActivityFeed) SocialActivityModel(org.datatransferproject.types.common.models.social.SocialActivityModel) Plus(com.google.api.services.plus.Plus) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) SocialActivityActor(org.datatransferproject.types.common.models.social.SocialActivityActor) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 2 with SocialActivityContainerResource

use of org.datatransferproject.types.common.models.social.SocialActivityContainerResource in project data-transfer-project by google.

the class MastodonActivityExport method export.

@Override
public ExportResult<SocialActivityContainerResource> export(UUID jobId, CookiesAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws Exception {
    checkState(authData.getCookies().size() == 1, "Exactly 1 cookie expected: %s", authData.getCookies());
    String maxId = null;
    if (exportInformation.isPresent()) {
        StringPaginationToken pageData = (StringPaginationToken) exportInformation.get().getPaginationData();
        if (!Strings.isNullOrEmpty(pageData.getToken())) {
            maxId = pageData.getToken();
        }
    }
    MastodonHttpUtilities utilities = new MastodonHttpUtilities(authData.getCookies().get(0), authData.getUrl());
    Account account = utilities.getAccount();
    Status[] statuses = utilities.getStatuses(maxId);
    List<SocialActivityModel> activityList = new ArrayList<>(statuses.length);
    SocialActivityActor actor = new SocialActivityActor("acct:" + account.getUsername() + "@" + utilities.getHostName(), account.getDisplayName(), account.getUrl());
    ContinuationData continuationData = null;
    if (statuses.length > 0) {
        String lastId = null;
        for (Status status : statuses) {
            activityList.add(statusToActivity(account, status, utilities));
            lastId = status.getId();
        }
        continuationData = new ContinuationData(new StringPaginationToken(lastId));
    }
    return new ExportResult<>(continuationData == null ? ResultType.END : ResultType.CONTINUE, new SocialActivityContainerResource(account.getId() + maxId, actor, activityList), continuationData);
}
Also used : Status(org.datatransferproject.transfer.mastodon.model.Status) Account(org.datatransferproject.transfer.mastodon.model.Account) SocialActivityContainerResource(org.datatransferproject.types.common.models.social.SocialActivityContainerResource) ArrayList(java.util.ArrayList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) SocialActivityModel(org.datatransferproject.types.common.models.social.SocialActivityModel) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) SocialActivityActor(org.datatransferproject.types.common.models.social.SocialActivityActor) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 3 with SocialActivityContainerResource

use of org.datatransferproject.types.common.models.social.SocialActivityContainerResource in project data-transfer-project by google.

the class ManualTest method main.

public static void main(String[] args) throws Exception {
    MastodonActivityExport exporter = new MastodonActivityExport();
    UUID jobId = UUID.randomUUID();
    CookiesAndUrlAuthData authData = new CookiesAndUrlAuthData(ImmutableList.of(ACCESS_TOKEN), HOST_URL);
    ExportResult<SocialActivityContainerResource> result = exporter.export(jobId, authData, Optional.empty());
    MastodonActivityImport mastodonActivityImport = new MastodonActivityImport();
    mastodonActivityImport.importItem(jobId, EXECUTOR, authData, result.getExportedData());
}
Also used : MastodonActivityImport(org.datatransferproject.transfer.mastodon.social.MastodonActivityImport) CookiesAndUrlAuthData(org.datatransferproject.types.transfer.auth.CookiesAndUrlAuthData) SocialActivityContainerResource(org.datatransferproject.types.common.models.social.SocialActivityContainerResource) MastodonActivityExport(org.datatransferproject.transfer.mastodon.social.MastodonActivityExport) UUID(java.util.UUID)

Aggregations

SocialActivityContainerResource (org.datatransferproject.types.common.models.social.SocialActivityContainerResource)3 ArrayList (java.util.ArrayList)2 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)2 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)2 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)2 SocialActivityActor (org.datatransferproject.types.common.models.social.SocialActivityActor)2 SocialActivityModel (org.datatransferproject.types.common.models.social.SocialActivityModel)2 Plus (com.google.api.services.plus.Plus)1 Activity (com.google.api.services.plus.model.Activity)1 ActivityFeed (com.google.api.services.plus.model.ActivityFeed)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1 Account (org.datatransferproject.transfer.mastodon.model.Account)1 Status (org.datatransferproject.transfer.mastodon.model.Status)1 MastodonActivityExport (org.datatransferproject.transfer.mastodon.social.MastodonActivityExport)1 MastodonActivityImport (org.datatransferproject.transfer.mastodon.social.MastodonActivityImport)1 CookiesAndUrlAuthData (org.datatransferproject.types.transfer.auth.CookiesAndUrlAuthData)1