Database Reference
In-Depth Information
Figure 11-10.
Adding a status update
In the
SocialController
, you will use the
add
method to first check and see if any tags are being added. If so,
the tags are first saved individually through the
saveTags
method in
TagsImpl
(more on Tags in later sections), which
returns a
SET
of tags, which will be added to the
Content
object via
setTags
. Next, you will send the
Content
object to
the
add
method of
ContentImpl
along with a
User
object via
currentuser
.
The
add
method for
ContentImpl
is shown in Listing 11-36. When a new status update is created, in addition to its
graph id, the
save
method also generates a contentId, which is performed using the
uuidGenWithTimeStamp
method.
The save method will also make the status the
CURRENTPOST
, determines whether a previous
CURRENTPOST
exists, and,
if one does, changes its relationship type to
NEXTPOST
.
Listing 11-36.
The
add
Method in
ContentImpl
public Content
add
(Content content, User user) {
content.setContentId(
uuidGenWithTimeStamp()
);
content.setTimestamp(new Date().getTime() / 1000);
content.setTagstr(removeTrailingComma(content.getTagstr()));
//
has the user posted content before?
// if so, then get the
"currentPost"
, remove that REL,
// set this post as
CURRENTPOST
by creating REL with user,
// then make currentPost the "next" post and save it all
Content currentPost = contentRepository.currentpost(user.getNodeId());