Search in sources :

Example 1 with Place

use of com.google.api.services.plus.model.Place in project data-transfer-project by google.

the class GooglePlusExporter method postToActivityModel.

private SocialActivityModel postToActivityModel(Activity activity) {
    String contentString = activity.getObject().getOriginalContent();
    List<SocialActivityAttachment> activityAttachments = new ArrayList<>();
    switch(activity.getVerb()) {
        case "post":
            for (Attachments attachment : activity.getObject().getAttachments()) {
                if (attachment.getObjectType().equals("article")) {
                    activityAttachments.add(new SocialActivityAttachment(SocialActivityAttachmentType.LINK, attachment.getUrl(), attachment.getDisplayName(), attachment.getContent()));
                } else if (attachment.getObjectType().equals("photo")) {
                    activityAttachments.add(new SocialActivityAttachment(SocialActivityAttachmentType.IMAGE, attachment.getFullImage().getUrl(), attachment.getDisplayName(), attachment.getContent()));
                } else if (attachment.getObjectType().equals("album")) {
                    // all the images.
                    for (Thumbnails image : attachment.getThumbnails()) {
                        activityAttachments.add(new SocialActivityAttachment(SocialActivityAttachmentType.IMAGE, // This is just a thumbnail image
                        image.getImage().getUrl(), image.getDescription(), // but instead a hosted page of the image.
                        "Original G+ Image: " + image.getUrl() + " from album: " + attachment.getUrl()));
                    }
                } else {
                    throw new IllegalArgumentException("Don't know how to export attachment " + attachment.getObjectType());
                }
            }
            return new SocialActivityModel(activity.getId(), Instant.ofEpochMilli(activity.getPublished().getValue()), SocialActivityType.POST, activityAttachments, null, activity.getTitle(), contentString, activity.getUrl());
        case "checkin":
            Place location = activity.getLocation();
            return new SocialActivityModel(activity.getId(), Instant.ofEpochMilli(activity.getPublished().getValue()), SocialActivityType.CHECKIN, null, new SocialActivityLocation(location.getDisplayName(), location.getPosition().getLongitude(), location.getPosition().getLatitude()), activity.getPlaceName(), contentString, null);
        default:
            throw new IllegalArgumentException("Don't know how to export " + activity);
    }
}
Also used : SocialActivityLocation(org.datatransferproject.types.common.models.social.SocialActivityLocation) ArrayList(java.util.ArrayList) SocialActivityModel(org.datatransferproject.types.common.models.social.SocialActivityModel) SocialActivityAttachment(org.datatransferproject.types.common.models.social.SocialActivityAttachment) Thumbnails(com.google.api.services.plus.model.Activity.PlusObject.Attachments.Thumbnails) Attachments(com.google.api.services.plus.model.Activity.PlusObject.Attachments) Place(com.google.api.services.plus.model.Place)

Aggregations

Attachments (com.google.api.services.plus.model.Activity.PlusObject.Attachments)1 Thumbnails (com.google.api.services.plus.model.Activity.PlusObject.Attachments.Thumbnails)1 Place (com.google.api.services.plus.model.Place)1 ArrayList (java.util.ArrayList)1 SocialActivityAttachment (org.datatransferproject.types.common.models.social.SocialActivityAttachment)1 SocialActivityLocation (org.datatransferproject.types.common.models.social.SocialActivityLocation)1 SocialActivityModel (org.datatransferproject.types.common.models.social.SocialActivityModel)1