Example usage for twitter4j Status getId

List of usage examples for twitter4j Status getId

Introduction

In this page you can find the example usage for twitter4j Status getId.

Prototype

long getId();

Source Link

Document

Returns the id of the status

Usage

From source file:org.gabrielebaldassarre.twitter.tweet.TalendFlowTweetBehaviour.java

License:Open Source License

/**
 * Visit a target {@link TalendFlow} for parsed or raw json output.
 * //from  w ww .  j a  v  a2s  .  com
 * @param target the data flow to fill
 */
public void visit(TalendFlow target) {
    ResourceBundle rb = ResourceBundle.getBundle("tTwitterInput", Locale.getDefault());

    TalendRowFactory rowFactory = target.getModel().getRowFactory();
    valid = false;

    @SuppressWarnings("unchecked")
    List<Status> tweets = (List<Status>) resultSet.getValue();
    for (int i = 0; i < tweets.size(); i++) {
        Status tweet = tweets.get(i);
        TalendRow current = rowFactory.newRow(target);

        Iterator<Entry<TalendColumn, TweetField>> col = associations.entrySet().iterator();
        while (col.hasNext()) {
            List<String> h;
            List<Long> l;

            Map.Entry<TalendColumn, TweetField> row = (Map.Entry<TalendColumn, TweetField>) col.next();

            if (target != null && !row.getKey().getFlow().equals(target)) {
                throw new IllegalArgumentException(String.format(rb.getString("exception.columnNotInFlow"),
                        row.getKey().getName(), target.getName()));
            }

            switch (row.getValue()) {
            case CREATION_DATE:
                String literalDate = (new StringBuilder(
                        TalendFlowTweetBehaviour.DATEFORMAT.format(tweet.getCreatedAt()))).toString();

                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(literalDate));
                case LONG:
                    current.setValue(row.getKey(), Long.parseLong(literalDate));
                case DOUBLE:
                    current.setValue(row.getKey(), Double.parseDouble(literalDate));
                case FLOAT:
                    current.setValue(row.getKey(), Float.parseFloat(literalDate));
                case INTEGER:
                    current.setValue(row.getKey(), Integer.parseInt(literalDate));
                case DATE:
                    current.setValue(row.getKey(), tweet.getCreatedAt());
                    break;
                case STRING:
                    current.setValue(row.getKey(), literalDate);
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getUser().getName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_USERID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getUser().getId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getUser().getId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getUser().getId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getUser().getId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getUser().getId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_SCREEN_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getUser().getScreenName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case HASHTAGS:
                List<HashtagEntity> hashtags = Arrays.asList(tweet.getHashtagEntities());
                h = new ArrayList<String>(hashtags.size());

                for (HashtagEntity hashtag : hashtags) {
                    h.add((includeHash() ? "#" : "") + hashtag.getText());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case IS_FAVORITED:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isFavorited() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isFavorited());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isFavorited() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isFavorited() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isFavorited() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isFavorited() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(), (short) (tweet.isFavorited() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));

                }
                break;
            case IS_POSSIBLY_SENSITIVE:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isPossiblySensitive());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isPossiblySensitive() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isPossiblySensitive() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isPossiblySensitive() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(),
                            (short) (tweet.isPossiblySensitive() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case IS_RETWEET:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isRetweet() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isRetweet());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isRetweet() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isRetweet() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isRetweet() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isRetweet() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(), (short) (tweet.isRetweet() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                current.setValue(row.getKey(), tweet.isRetweet());
                break;
            case LOCATION:
                GeoLocation g = tweet.getGeoLocation();
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(),
                            g != null
                                    ? String.valueOf(g.getLatitude()) + getEntitiesSeparator()
                                            + String.valueOf(g.getLongitude())
                                    : null);
                    break;
                case OBJECT:
                    current.setValue(row.getKey(), g);
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_SCREEN_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getInReplyToScreenName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_STATUSID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getInReplyToStatusId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getInReplyToStatusId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getInReplyToStatusId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getInReplyToStatusId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getInReplyToStatusId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_USERID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getInReplyToUserId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getInReplyToUserId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getInReplyToUserId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getInReplyToUserId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getInReplyToUserId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case RETWEET_COUNT:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getRetweetCount()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getRetweetCount()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getRetweetCount()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getRetweetCount()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getRetweetCount())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case SOURCE:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getSource());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case STATUS_ID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case TEXT:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getText());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case URL_ENTITIES:
            case URL_ENTITIES_STRING:
                List<URLEntity> urlEntities = Arrays.asList(tweet.getURLEntities());
                h = new ArrayList<String>(urlEntities.size());

                for (URLEntity urlEntity : urlEntities) {
                    h.add(urlEntity.getExpandedURL());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case USER_MENTIONS:
                List<UserMentionEntity> userMentionsEntities = Arrays.asList(tweet.getUserMentionEntities());
                l = new ArrayList<Long>(userMentionsEntities.size());

                for (UserMentionEntity userMention : userMentionsEntities) {
                    l.add(userMention.getId());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? l
                            : Joiner.on(getEntitiesSeparator()).join(l));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case USER_MENTIONS_SCREEN_NAME:
                List<UserMentionEntity> userMentionsScreen = Arrays.asList(tweet.getUserMentionEntities());
                h = new ArrayList<String>(userMentionsScreen.size());

                for (UserMentionEntity userMention : userMentionsScreen) {
                    h.add((includeHash() ? "@" : "") + userMention.getScreenName());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case JSON:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), DataObjectFactory.getRawJSON(tweet));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            default:
                throw new IllegalArgumentException(
                        String.format(rb.getString("exception.unparseableColumn"), row.getKey().getName()));

            }

        }

    }
    valid = true;
}

From source file:org.getlantern.firetweet.loader.support.StatusRepliesLoader.java

License:Open Source License

@NonNull
@Override//ww w. ja  v  a  2 s  . c om
public List<Status> getStatuses(@NonNull final Twitter twitter, final Paging paging) throws TwitterException {
    final Context context = getContext();
    final List<Status> result = new ArrayList<>();
    if (shouldForceUsingPrivateAPIs(context) || isOfficialTwitterInstance(context, twitter)) {
        final List<Status> statuses = twitter.showConversation(mInReplyToStatusId, paging);
        for (final Status status : statuses) {
            if (status.getId() > mInReplyToStatusId) {
                result.add(status);
            }
        }
    } else {
        final List<Status> statuses = super.getStatuses(twitter, paging);
        // TODO null check
        for (final Status status : statuses) {
            if (status.getInReplyToStatusId() == mInReplyToStatusId) {
                result.add(status);
            }
        }
    }
    return result;
}

From source file:org.getlantern.firetweet.loader.support.TwitterAPIStatusesLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  w w  .  jav  a  2 s  .co  m
public final List<ParcelableStatus> loadInBackground() {
    final File serializationFile = getSerializationFile();
    final List<ParcelableStatus> data = getData();
    if (isFirstLoad() && getTabPosition() >= 0 && serializationFile != null) {
        final List<ParcelableStatus> cached = getCachedData(serializationFile);
        if (cached != null) {
            data.addAll(cached);
            if (mComparator != null) {
                Collections.sort(data, mComparator);
            } else {
                Collections.sort(data);
            }
            return new CopyOnWriteArrayList<>(data);
        }
    }
    if (!isFromUser())
        return data;
    final List<Status> statuses;
    final boolean truncated;
    final Context context = getContext();
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
    try {
        final Paging paging = new Paging();
        paging.setCount(loadItemLimit);
        if (mMaxId > 0) {
            paging.setMaxId(mMaxId);
        }
        if (mSinceId > 0) {
            paging.setSinceId(mSinceId - 1);
        }
        statuses = new ArrayList<>();
        final Twitter twitter = getTwitter();
        if (twitter == null) {
            throw new TwitterException("Account is null");
        }
        truncated = truncateStatuses(getStatuses(twitter, paging), statuses, mSinceId);
    } catch (final TwitterException e) {
        // mHandler.post(new ShowErrorRunnable(e));
        Log.w(LOGTAG, e);
        return new CopyOnWriteArrayList<>(data);
    }
    final long minStatusId = statuses.isEmpty() ? -1 : Collections.min(statuses).getId();
    final boolean insertGap = minStatusId > 0 && statuses.size() > 1 && !data.isEmpty() && !truncated;
    for (final Status status : statuses) {
        final long id = status.getId();
        final boolean deleted = deleteStatus(data, id);
        data.add(new ParcelableStatus(status, mAccountId, minStatusId == id && insertGap && !deleted));
    }
    final ParcelableStatus[] array = data.toArray(new ParcelableStatus[data.size()]);
    for (int i = 0, size = array.length; i < size; i++) {
        final ParcelableStatus status = array[i];
        if (shouldFilterStatus(mDatabase, status) && !status.is_gap && i != size - 1) {
            deleteStatus(data, status.id);
        }
    }
    if (mComparator != null) {
        Collections.sort(data, mComparator);
    } else {
        Collections.sort(data);
    }
    saveCachedData(serializationFile, data);
    return new CopyOnWriteArrayList<>(data);
}

From source file:org.getlantern.firetweet.model.ParcelableStatus.java

License:Open Source License

public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) {
    this.is_gap = is_gap;
    this.account_id = account_id;
    id = orig.getId();
    timestamp = getTime(orig.getCreatedAt());

    final Status retweeted = orig.getRetweetedStatus();
    final User retweet_user = retweeted != null ? orig.getUser() : null;
    is_retweet = orig.isRetweet();//from   ww w.j  a  v a 2 s . c om
    retweet_id = retweeted != null ? retweeted.getId() : -1;
    retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1;
    retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1;
    retweeted_by_name = retweet_user != null ? retweet_user.getName() : null;
    retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null;
    retweeted_by_profile_image = retweet_user != null ? retweet_user.getProfileImageUrlHttps() : null;

    final Status quoted = orig.getQuotedStatus();
    final User quote_user = quoted != null ? orig.getUser() : null;
    is_quote = orig.isQuote();
    quote_id = quoted != null ? quoted.getId() : -1;
    quote_text_html = TwitterContentUtils.formatStatusText(orig);
    quote_text_plain = orig.getText();
    quote_text_unescaped = HtmlEscapeHelper.toPlainText(quote_text_html);
    quote_timestamp = orig.getCreatedAt().getTime();
    quote_source = orig.getSource();

    quoted_by_user_id = quote_user != null ? quote_user.getId() : -1;
    quoted_by_user_name = quote_user != null ? quote_user.getName() : null;
    quoted_by_user_screen_name = quote_user != null ? quote_user.getScreenName() : null;
    quoted_by_user_profile_image = quote_user != null ? quote_user.getProfileImageUrlHttps() : null;
    quoted_by_user_is_protected = quote_user != null && quote_user.isProtected();
    quoted_by_user_is_verified = quote_user != null && quote_user.isVerified();

    final Status status;
    if (quoted != null) {
        status = quoted;
    } else if (retweeted != null) {
        status = retweeted;
    } else {
        status = orig;
    }
    final User user = status.getUser();
    user_id = user.getId();
    user_name = user.getName();
    user_screen_name = user.getScreenName();
    user_profile_image_url = user.getProfileImageUrlHttps();
    user_is_protected = user.isProtected();
    user_is_verified = user.isVerified();
    user_is_following = user.isFollowing();
    text_html = TwitterContentUtils.formatStatusText(status);
    media = ParcelableMedia.fromEntities(status);
    text_plain = status.getText();
    retweet_count = status.getRetweetCount();
    favorite_count = status.getFavoriteCount();
    reply_count = status.getReplyCount();
    descendent_reply_count = status.getDescendentReplyCount();
    in_reply_to_name = TwitterContentUtils.getInReplyToName(status);
    in_reply_to_screen_name = status.getInReplyToScreenName();
    in_reply_to_status_id = status.getInReplyToStatusId();
    in_reply_to_user_id = status.getInReplyToUserId();
    source = status.getSource();
    location = ParcelableLocation.fromGeoLocation(status.getGeoLocation());
    is_favorite = status.isFavorited();
    text_unescaped = HtmlEscapeHelper.toPlainText(text_html);
    my_retweet_id = retweeted_by_id == account_id ? id : status.getCurrentUserRetweet();
    is_possibly_sensitive = status.isPossiblySensitive();
    mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities());
    card = ParcelableCardEntity.fromCardEntity(status.getCard(), account_id);
    place_full_name = getPlaceFullName(status.getPlace());
    card_name = card != null ? card.name : null;
}

From source file:org.getlantern.firetweet.task.CacheUsersStatusesTask.java

License:Open Source License

@SafeVarargs
@Override//  w  ww .j a  va  2s. c  om
protected final Object doInBackground(final TwitterListResponse<twitter4j.Status>... args) {
    if (args == null || args.length == 0)
        return null;
    final ContentResolver resolver = context.getContentResolver();
    final Extractor extractor = new Extractor();

    for (final TwitterListResponse<twitter4j.Status> response : args) {
        if (response == null || response.list == null) {
            continue;
        }
        final List<twitter4j.Status> list = response.list;
        for (int bulkIdx = 0, totalSize = list.size(); bulkIdx < totalSize; bulkIdx += 100) {
            for (int idx = bulkIdx, end = Math.min(totalSize,
                    bulkIdx + ContentResolverUtils.MAX_BULK_COUNT); idx < end; idx++) {
                final twitter4j.Status status = list.get(idx);
                if (status == null || status.getId() <= 0) {
                    continue;
                }

                final Set<ContentValues> usersValues = new HashSet<>();
                final Set<ContentValues> statusesValues = new HashSet<>();
                final Set<ContentValues> hashTagValues = new HashSet<>();

                statusesValues.add(createStatus(status, response.accountId));
                for (final String hashtag : extractor.extractHashtags(status.getText())) {
                    final ContentValues values = new ContentValues();
                    values.put(CachedHashtags.NAME, hashtag);
                    hashTagValues.add(values);
                }
                usersValues.add(createCachedUser(status.getUser()));
                if (status.isRetweet()) {
                    usersValues.add(createCachedUser(status.getRetweetedStatus().getUser()));
                }

                bulkInsert(resolver, CachedStatuses.CONTENT_URI, statusesValues);
                bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashTagValues);
                bulkInsert(resolver, CachedUsers.CONTENT_URI, usersValues);
            }
        }
    }

    return null;
}

From source file:org.getlantern.firetweet.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues createStatus(final Status orig, final long accountId) {
    if (orig == null || orig.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    values.put(Statuses.ACCOUNT_ID, accountId);
    values.put(Statuses.STATUS_ID, orig.getId());
    values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime());
    final Status status;
    if (orig.isRetweet()) {
        final Status retweetedStatus = orig.getRetweetedStatus();
        final User retweetUser = orig.getUser();
        final long retweetedById = retweetUser.getId();
        values.put(Statuses.RETWEET_ID, retweetedStatus.getId());
        values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime());
        values.put(Statuses.RETWEETED_BY_USER_ID, retweetedById);
        values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName());
        values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName());
        values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE, (retweetUser.getProfileImageUrlHttps()));
        values.put(Statuses.IS_RETWEET, true);
        if (retweetedById == accountId) {
            values.put(Statuses.MY_RETWEET_ID, orig.getId());
        } else {//from  ww w  .  j av  a2  s  .c  om
            values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet());
        }
        status = retweetedStatus;
    } else if (orig.isQuote()) {
        final Status quotedStatus = orig.getQuotedStatus();
        final User quoteUser = orig.getUser();
        final long quotedById = quoteUser.getId();
        values.put(Statuses.QUOTE_ID, quotedStatus.getId());
        final String textHtml = TwitterContentUtils.formatStatusText(orig);
        values.put(Statuses.QUOTE_TEXT_HTML, textHtml);
        values.put(Statuses.QUOTE_TEXT_PLAIN, orig.getText());
        values.put(Statuses.QUOTE_TEXT_UNESCAPED, toPlainText(textHtml));
        values.put(Statuses.QUOTE_TIMESTAMP, orig.getCreatedAt().getTime());
        values.put(Statuses.QUOTE_SOURCE, orig.getSource());

        values.put(Statuses.QUOTED_BY_USER_ID, quotedById);
        values.put(Statuses.QUOTED_BY_USER_NAME, quoteUser.getName());
        values.put(Statuses.QUOTED_BY_USER_SCREEN_NAME, quoteUser.getScreenName());
        values.put(Statuses.QUOTED_BY_USER_PROFILE_IMAGE, quoteUser.getProfileImageUrlHttps());
        values.put(Statuses.QUOTED_BY_USER_IS_VERIFIED, quoteUser.isVerified());
        values.put(Statuses.QUOTED_BY_USER_IS_PROTECTED, quoteUser.isProtected());
        values.put(Statuses.IS_QUOTE, true);
        if (quotedById == accountId) {
            values.put(Statuses.MY_QUOTE_ID, orig.getId());
            //            } else {
            //                values.put(Statuses.MY_QUOTE_ID, orig.getCurrentUserRetweet());
        }
        status = quotedStatus;
    } else {
        values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet());
        status = orig;
    }
    final User user = status.getUser();
    final long userId = user.getId();
    final String profileImageUrl = (user.getProfileImageUrlHttps());
    final String name = user.getName(), screenName = user.getScreenName();
    values.put(Statuses.USER_ID, userId);
    values.put(Statuses.USER_NAME, name);
    values.put(Statuses.USER_SCREEN_NAME, screenName);
    values.put(Statuses.IS_PROTECTED, user.isProtected());
    values.put(Statuses.IS_VERIFIED, user.isVerified());
    values.put(Statuses.USER_PROFILE_IMAGE_URL, profileImageUrl);
    values.put(CachedUsers.IS_FOLLOWING, user.isFollowing());
    final String textHtml = TwitterContentUtils.formatStatusText(status);
    values.put(Statuses.TEXT_HTML, textHtml);
    values.put(Statuses.TEXT_PLAIN, status.getText());
    values.put(Statuses.TEXT_UNESCAPED, toPlainText(textHtml));
    values.put(Statuses.RETWEET_COUNT, status.getRetweetCount());
    values.put(Statuses.REPLY_COUNT, status.getReplyCount());
    values.put(Statuses.FAVORITE_COUNT, status.getFavoriteCount());
    values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount());
    values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
    values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId());
    values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(status));
    values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName());
    values.put(Statuses.SOURCE, status.getSource());
    values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive());
    final GeoLocation location = status.getGeoLocation();
    if (location != null) {
        values.put(Statuses.LOCATION,
                ParcelableLocation.toString(location.getLatitude(), location.getLongitude()));
    }
    final Place place = status.getPlace();
    if (place != null) {
        values.put(Statuses.PLACE_FULL_NAME, place.getFullName());
    }
    values.put(Statuses.IS_FAVORITE, status.isFavorited());
    final ParcelableMedia[] media = ParcelableMedia.fromEntities(status);
    if (media != null) {
        values.put(Statuses.MEDIA_LIST, SimpleValueSerializer.toSerializedString(media));
    }
    final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status);
    if (mentions != null) {
        values.put(Statuses.MENTIONS_LIST, SimpleValueSerializer.toSerializedString(mentions));
    }
    final ParcelableCardEntity card = ParcelableCardEntity.fromCardEntity(status.getCard(), accountId);
    if (card != null) {
        values.put(Statuses.CARD_NAME, card.name);
        values.put(Statuses.CARD, JSONSerializer.toJSONObjectString(card));
    }
    return values;
}

From source file:org.graylog2.inputs.twitter.TwitterCodec.java

License:Open Source License

private Message createMessageFromStatus(final Status status) {
    final Message message = new Message(status.getText(), "twitter.com", new DateTime(status.getCreatedAt()));

    message.addField("facility", "Tweets");
    message.addField("level", 6);
    message.addField("tweet_id", status.getId());
    message.addField("tweet_is_retweet", Boolean.toString(status.isRetweet()));
    message.addField("tweet_favorite_count", status.getFavoriteCount());
    message.addField("tweet_retweet_count", status.getRetweetCount());
    message.addField("tweet_language", status.getLang());

    final GeoLocation geoLocation = status.getGeoLocation();
    if (geoLocation != null) {
        message.addField("tweet_geo_long", geoLocation.getLongitude());
        message.addField("tweet_geo_lat", geoLocation.getLatitude());
    }/*from   w w w  .  j av  a2s.c om*/

    final User user = status.getUser();
    if (user != null) {
        message.addField("tweet_url",
                "https://twitter.com/" + user.getScreenName() + "/status/" + status.getId());
        message.addField("user_id", user.getId());
        message.addField("user_name", user.getScreenName());
        message.addField("user_description", user.getDescription());
        message.addField("user_timezone", user.getTimeZone());
        message.addField("user_utc_offset", user.getUtcOffset());
        message.addField("user_location", user.getLocation());
        message.addField("user_language", user.getLang());
        message.addField("user_url", user.getURL());
        message.addField("user_followers", user.getFollowersCount());
        message.addField("user_tweets", user.getStatusesCount());
        message.addField("user_favorites", user.getFavouritesCount());
    }
    return message;
}

From source file:org.hornetq.integration.twitter.impl.IncomingTweetsHandler.java

License:Apache License

private void putTweetIntoMessage(final Status status, final ServerMessage msg) {
    msg.getBodyBuffer().writeString(status.getText());
    msg.putLongProperty(TwitterConstants.KEY_ID, status.getId());
    msg.putStringProperty(TwitterConstants.KEY_SOURCE, status.getSource());

    msg.putLongProperty(TwitterConstants.KEY_CREATED_AT, status.getCreatedAt().getTime());
    msg.putBooleanProperty(TwitterConstants.KEY_IS_TRUNCATED, status.isTruncated());
    msg.putLongProperty(TwitterConstants.KEY_IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
    msg.putIntProperty(TwitterConstants.KEY_IN_REPLY_TO_USER_ID, status.getInReplyToUserId());
    msg.putBooleanProperty(TwitterConstants.KEY_IS_FAVORITED, status.isFavorited());
    msg.putBooleanProperty(TwitterConstants.KEY_IS_RETWEET, status.isRetweet());
    msg.putObjectProperty(TwitterConstants.KEY_CONTRIBUTORS, status.getContributors());
    GeoLocation gl;// ww w .  j  a  v a 2 s . c om
    if ((gl = status.getGeoLocation()) != null) {
        msg.putDoubleProperty(TwitterConstants.KEY_GEO_LOCATION_LATITUDE, gl.getLatitude());
        msg.putDoubleProperty(TwitterConstants.KEY_GEO_LOCATION_LONGITUDE, gl.getLongitude());
    }
    Place place;
    if ((place = status.getPlace()) != null) {
        msg.putStringProperty(TwitterConstants.KEY_PLACE_ID, place.getId());
    }
}

From source file:org.hubiquitus.hubotsdk.adapters.HTwitterAdapterInbox.java

License:Open Source License

/**
 * Function for transforming Tweet to HMessage
 * @param tweet from twitter4j/*from w w w.j a  v a  2s  . com*/
 * @return HMessage of type hTweet
 */
private HMessage transformtweet(Status tweet) {
    HMessage message = new HMessage();

    HTweet htweet = new HTweet();
    if (("complete").equalsIgnoreCase(content)) {
        HTweetAuthor hauthortweet = new HTweetAuthor();

        //Construct the location 
        HLocation location = new HLocation();
        if (tweet.getGeoLocation() != null) {
            HGeo geo = new HGeo(tweet.getGeoLocation().getLatitude(), tweet.getGeoLocation().getLongitude());
            location.setPos(geo);
            message.setLocation(location);
        }

        //Construct the Place
        if (tweet.getPlace() != null) {
            if (tweet.getPlace().getStreetAddress() != null) {
                location.setAddr(tweet.getPlace().getStreetAddress());
            }
            if (tweet.getPlace().getCountryCode() != null) {
                location.setCountryCode(tweet.getPlace().getCountryCode());
            }
            if ((tweet.getPlace().getPlaceType() != null)
                    && ("city".equalsIgnoreCase(tweet.getPlace().getPlaceType()))) {
                location.setCity(tweet.getPlace().getName());
            }
        }

        //Construct the Authortweet JSONObject
        hauthortweet.setStatus(tweet.getUser().getStatusesCount());
        hauthortweet.setFollowers(tweet.getUser().getFollowersCount());
        hauthortweet.setFriends(tweet.getUser().getFriendsCount());
        hauthortweet.setLocation(tweet.getUser().getLocation());
        hauthortweet.setDescription(tweet.getUser().getDescription());
        hauthortweet.setProfileImg(tweet.getUser().getProfileImageURL().toString());
        hauthortweet.setUrl(tweet.getUser().getURL());
        hauthortweet.setCreatedAt(tweet.getUser().getCreatedAt());
        hauthortweet.setLang(tweet.getUser().getLang());
        hauthortweet.setListeds(tweet.getUser().getListedCount());
        hauthortweet.setGeo(tweet.getUser().isGeoEnabled());
        hauthortweet.setVerified(tweet.getUser().isVerified());
        hauthortweet.setName(tweet.getUser().getName());

        //Construct the tweet JSONObject      
        htweet.setId(tweet.getId());
        try {
            htweet.setSource(tweet.getSource());
            htweet.setAuthor(hauthortweet);
        } catch (MissingAttrException e) {
            log.error("message: ", e);
        }

    }
    // now manage the minimal list of attributes to get from twitter
    try {
        htweet.setText(tweet.getText());
    } catch (MissingAttrException e) {
        log.error("message: ", e);
    }
    message.setPayload(htweet);
    message.setType("hTweet");
    message.setAuthor(tweet.getUser().getScreenName() + "@twitter.com");
    Date createdAt = tweet.getCreatedAt();
    message.setPublished(createdAt);

    if (log.isDebugEnabled()) {
        log.debug("tweet(" + tweet + ") -> hMessage :" + message);
    }

    return message;
}

From source file:org.ipccenter.newsagg.impl.twitterapi.TwitterPuller.java

public void parsePost(Status status) {
    News post = new News();
    post.setSource("Twitter");
    post.setStatus(0);/* w  w w  . j  a  v a 2s .  c om*/
    post.setContent(status.getText());
    StringBuilder url = new StringBuilder();
    url.append("http://twitter.com/").append(status.getUser().getScreenName()).append("/statuses/")
            .append(String.valueOf(status.getId()));
    post.setUrl(url.toString());
    post.setDate(status.getCreatedAt());
    //post.setAuthor(status.getUser().getName());
    postsList.add(post);
}