Java Code Examples for org.javalite.activejdbc.Model#getLongId()

The following examples show how to use org.javalite.activejdbc.Model#getLongId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Communities.java    From flowchat with GNU General Public License v3.0 5 votes vote down vote up
public static Communities create(List<? extends Model> communities,
                                 List<Tables.CommunityTagView> communityTags,
                                 List<Tables.CommunityUserView> communityUsers,
                                 List<Tables.CommunityRank> communityRanks,
                                 Long count) {

    // Build maps keyed by community_id of the votes, tags, and users
    Map<Long, Integer> votes = (communityRanks != null) ?
            Transformations.convertRankToMap(communityRanks, "community_id") : null;

    Map<Long, List<Tables.CommunityTagView>> tagMap = (communityTags != null) ?
            Transformations.convertRowsToMap(communityTags, "community_id") : null;

    Map<Long, List<Tables.CommunityUserView>> userMap = (communityUsers != null) ?
            Transformations.convertRowsToMap(communityUsers, "community_id") : null;

    // Convert to a list of community objects
    List<Community> cos = new ArrayList<>();

    for (Model view : communities) {
        Long id = view.getLongId();
        Integer vote = (votes != null && votes.get(id) != null) ? votes.get(id) : null;
        List<Tables.CommunityTagView> tags = (tagMap != null && tagMap.get(id) != null) ? tagMap.get(id) : null;
        List<Tables.CommunityUserView> users = (userMap != null && userMap.get(id) != null) ? userMap.get(id) : null;
        Community c = Community.create(view, tags, users, vote);
        cos.add(c);
    }

    return new Communities(cos, count);
}
 
Example 2
Source File: Community.java    From flowchat with GNU General Public License v3.0 4 votes vote down vote up
public static Community create(Model c,
                               List<Tables.CommunityTagView> communityTags,
                               List<Tables.CommunityUserView> communityUsers,
                               Integer vote) {
    // convert the tags
    List<Tag> tags = null;
    if (communityTags != null) {
        tags = new ArrayList<>();
        for (Tables.CommunityTagView dtv : communityTags) {
            tags.add(Tag.create(dtv.getLong("tag_id"), dtv.getString("name")));
        }
    }

    // convert the user community roles
    User creator = null;
    List<User> moderators = new ArrayList<>();
    List<User> privateUsers = new ArrayList<>();
    List<User> blockedUsers = new ArrayList<>();

    if (communityUsers != null) {
        for (Tables.CommunityUserView udv : communityUsers) {

            CommunityRole role = CommunityRole.values()[udv.getLong("community_role_id").intValue() - 1];

            User userObj = User.create(udv.getLong("user_id"), udv.getString("name"));

            switch (role) {
                case CREATOR:
                    creator = userObj;
                    break;
                case MODERATOR:
                    moderators.add(userObj);
                    break;
                case BLOCKED:
                    blockedUsers.add(userObj);
                    break;
                case USER:
                    privateUsers.add(userObj);
                    break;
            }
        }
    }

    // Create the modified by user
    User modifiedByUser = User.create(c.getLong("modified_by_user_id"), c.getString("modified_by_user_name"));

    return new Community(c.getLongId(),
            c.getString("name"),
            c.getString("text_"),
            c.getBoolean("private"),
            c.getBoolean("nsfw"),
            c.getInteger("avg_rank"),
            vote,
            c.getInteger("number_of_votes"),
            tags,
            creator,
            modifiedByUser,
            moderators,
            privateUsers,
            blockedUsers,
            c.getBoolean("deleted"),
            c.getTimestamp("created"),
            c.getTimestamp("modified"));
}
 
Example 3
Source File: Discussions.java    From flowchat with GNU General Public License v3.0 4 votes vote down vote up
public static Discussions create(List<? extends Model> discussions,
                                 List<Tables.CommunityNoTextView> communities,
                                 List<Tables.DiscussionTagView> discussionTags,
                                 List<Tables.DiscussionUserView> discussionUsers,
                                 List<Tables.DiscussionRank> discussionRanks,
                                 Long count) {

    // Build maps keyed by discussion_id of the votes, tags, and users
    Map<Long, Integer> votes = (discussionRanks != null) ?
            Transformations.convertRankToMap(discussionRanks, "discussion_id") : null;

    Map<Long, List<Tables.DiscussionTagView>> tagMap = (discussionTags != null) ?
            Transformations.convertRowsToMap(discussionTags, "discussion_id") : null;

    Map<Long, List<Tables.DiscussionUserView>> userMap = (discussionUsers != null) ?
            Transformations.convertRowsToMap(discussionUsers, "discussion_id") : null;

    // Convert to a list of discussion objects
    Set<Discussion> dos = new LinkedHashSet<>();

    for (Model view : discussions) {
        Long id = view.getLongId();
        Integer vote = (votes != null && votes.get(id) != null) ? votes.get(id) : null;
        List<Tables.DiscussionTagView> tags = (tagMap != null && tagMap.get(id) != null) ? tagMap.get(id) : null;
        List<Tables.DiscussionUserView> users = (userMap != null && userMap.get(id) != null) ? userMap.get(id) : null;
        Tables.CommunityNoTextView community = null;
        if (communities != null) {
            for (Tables.CommunityNoTextView cntv : communities) {
                if (view.getLong("community_id").equals(cntv.getLongId())) {
                    community = cntv;
                    break;
                }
            }
        }

        // TODO should the list of discussions also filter for blocked communities?
        Discussion df = Discussion.create(view, community, tags, users, null, vote);
        dos.add(df);
    }

    return new Discussions(dos, count);
}
 
Example 4
Source File: Discussion.java    From flowchat with GNU General Public License v3.0 4 votes vote down vote up
public static Discussion create(Model d,
                                Tables.CommunityNoTextView cntv,
                                List<Tables.DiscussionTagView> discussionTags,
                                List<Tables.DiscussionUserView> discussionUsers,
                                List<Tables.CommunityUserView> communityUsers,
                                Integer vote) {
    // convert the tags
    List<Tag> tags = null;
    if (discussionTags != null) {
        tags = new ArrayList<>();
        for (Tables.DiscussionTagView dtv : discussionTags) {
            tags.add(Tag.create(dtv.getLong("tag_id"), dtv.getString("name")));
        }
    }

    // convert the user discussion roles
    User creator = null;
    List<User> privateUsers = new ArrayList<>();
    List<User> blockedUsers = new ArrayList<>();

    if (discussionUsers != null) {
        for (Tables.DiscussionUserView udv : discussionUsers) {

            DiscussionRole role = DiscussionRole.values()[udv.getLong("discussion_role_id").intValue() - 1];

            User userObj = User.create(udv.getLong("user_id"), udv.getString("name"));

            switch (role) {
                case BLOCKED:
                    blockedUsers.add(userObj);
                    break;
                case USER:
                    privateUsers.add(userObj);
                    break;
                case CREATOR:
                    creator = userObj;
                    break;
            }
        }
    }

    // Create the community
    Community community = (cntv != null) ? Community.create(cntv, null, communityUsers, null) : null;

    // If the community is NSFW, the discussion must be
    Boolean nsfw = (community != null && community.getNsfw()) ? true :  d.getBoolean("nsfw");

    // Create the modified by user
    User modifiedByUser = User.create(d.getLong("modified_by_user_id"), d.getString("modified_by_user_name"));

    return new Discussion(d.getLongId(),
            d.getString("title"),
            d.getString("link"),
            d.getString("text_"),
            d.getBoolean("private"),
            nsfw,
            d.getBoolean("stickied"),
            d.getInteger("avg_rank"),
            vote,
            d.getInteger("number_of_votes"),
            d.getInteger("number_of_comments"),
            tags,
            creator,
            modifiedByUser,
            privateUsers,
            blockedUsers,
            d.getBoolean("deleted"),
            community,
            d.getTimestamp("created"),
            d.getTimestamp("modified"));
}