I hope I correctly understood the question - do you want to embed the news feed in your application and allow users to follow each other. New members should be able to see user actions. I'm sure there are several other ways to solve this problem, but I will try to help you by providing a solution that uses JAVA JDO to access the data store.
First, I developed entity relationships in JDO as follows:
1 User to many actions. 1 User to many followers (User). 1 User to many following (User).
Here are the simple JDO classes:
User Class:
@PersistenceCapable(identityType=IdentityType.APPLICATION) public class User { @PrimaryKey @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY) private Key key; @Persistent private String userId; // Google unique user ID, could also store user email. @Persistent private Set<Key> actions; @Persistent private Set<Key> followers; @Persistent private List<Key> following; public User(Key key, String userId) { this.key = key; this.userId = userId; this.actions = new HashSet<Key>(); this.followers = new HashSet<Key>(); this.following = new HashSet<Key>(); } public Key getKey() { return this.key; } public void addAction(Key actionKey) { this.actions.add(actionKey); } public void addActions(Set<Key> actionKeys) { this.actions.addAll(actionKeys); } public Set<Key> getActions() { return this.actions; } public void addFollower(Key followerKey) { this.followers.add(followerKey); } public void addFollowers(Set<Key> followerKeys) { this.followers.addAll(followerKeys); } public Set<Key> getFollowers() { return this.followers; } public void addFollowing(Key followingKey) { this.following.add(followingKey); } public void addAllFollowing(Set<Key> followingKeys) { this.following.addAll(followingKeys); } public Set<Key> getFollowing() { return this.following; } }
Action class:
@PersistenceCapable(identityType=IdentityType.APPLICATION) public class Action { @PrimaryKey @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY) private Key key; @Persistent Date date; @Persistent private String title; public Action(Key key, String title) { this.key = key; this.title = title; this.date = new Date();
The Action class uses the Date property; you can refer to the documentation for the corresponding data types in the data warehouse. When an action is created, the Date object is allocated and initialized so that it represents the time at which it was assigned, measured to the nearest millisecond .
In my example above, I linked the objects with my keys, instead you could bind them according to your classes as follows:
List<Action> actions;
The relationship in my example is one of the many-to-one relationship that is irrelevant, perhaps it should be one-to-many. Read more here so you can look and possibly decide which one is best for your solution.
Once the relationships are defined, you can create your endpoint classes around the JDO model classes . This will create the basic api methods. You might want to change the methods of the endpoint class to suit your needs, for example, change the way you create an action. A basic example would be to create a key from an action name as follows (ActionEnpoint.java):
... @ApiMethod(name = "insertAction") public Action insertAction( @Named("title") String title ) { PersistenceManager pm = getPersistenceManager(); Key key = KeyFactory.createKey(Action.class.getSimpleName(), title); Action action = null; try { action = new Action(key, title); pm.makePersistent(action); } finally { pm.close(); } return action; } ...
If you want, you can add a method to your UserEndpoint class to query the data warehouse and return all the actions that belong to this user and per day using the data warehouse query objects .
You need to add a method to your UserEndpoint class that allows you to add an action to this user, here is a simple example:
... @ApiMethod(name = "addActionToUser") public Achiever addActionToUser( @Named("userId") String userId, @Named("actionTitle") String actionTitle) { PersistenceManager pm = getPersistenceManager(); Key userKey = KeyFactory.createKey(User.class.getSimpleName(), userId); Key actionKey = KeyFactory.createKey(Action.class.getSimpleName(), actionTitle); User user = null; try { user = (User) pm.getObjectById(User.class, userKey); user.addAction(actionKey); pm.makePersistent(user); } catch (Exception e) { } return user; } ...
Once all of the above is completed, you can easily get a list of actions for each user by calling the getUser method in your UserEndpoint class, which returns a User object. Then you can call [ReturnedUserObject] .getActions (). The new follower can now view all the followees actions by simply calling the api method to get the followees object and get his / her actions. Then you can simply sort the actions by date or as you imagine it.
I hope I understood your question correctly, I was not sure about the first component that you mentioned, but it seemed that you messed up your relationship. Hope this solution will point you in the right direction, at least :).
If you need further help or clarification, or my answer was completely incompatible with what you were looking for, please let me know.
Regards, Miki