@Override
public void doView(GadgletRequestWrapper request, GadgletResponse response)
throws RequestException {
DiscussionsList discussion = null;
List<Replys> replays = null;
PersistenceManager pm = null;
;
try {
pm = PMF.get().getPersistenceManager();
discussion = (DiscussionsList) helper.getSingleItemByKeyForAction(
pm, request, DiscussionsList.class);
if (discussion == null)
throw new RequestException(ReqErrorTypes.ITEM_NOT_FOUND);
if (discussion.getReply() != null) {
replays = discussion.getReply();
for (Replys replay : replays);
}
} catch (RequestException e) {
// TODO Auto-generated catch block
throw e;
} catch (Exception e) {
log.warning(e.getMessage());
throw new RequestException(ReqErrorTypes.REQUEST_FAILED);
} finally {
pm.close();
}
ContentRecord item = response.newItem();
SimpleDateFormat df = new SimpleDateFormat("MMM/dd/yy hh:mm");
String formatedDate = null;
item.addItemKeyField(discussion.getContentItemKey());
item.addItemField(Params.DISCUSSION_TEXT.getParamName(),
discussion.getDiscussion());
formatedDate = df.format(discussion.getCreation());
if (formatedDate != null)
item.addItemField(Params.DISCUSSION_MSD_DATE.getParamName(),
formatedDate);
else
item.addItemField(Params.DISCUSSION_MSD_DATE.getParamName(), "");
item.addItemField(Params.DISCUSSION_LEVEL.getParamName(), "0");
item.setContentName(Params.DISCUSSION_TEXT.getParamName());
DomainUser writer = DomainUserUtils.getDomainUserByUniqueId(discussion
.getOwnerId(), request.getCurrentDomainUser().getAccount());
item.addItemField(ProfileFields.PROFILE_NICKNAME.getParamName(),
writer.getNickName());
item.addItemField(ProfileFields.PROFILE_TITLE.getParamName(),
writer.getTitle());
if (writer.getPhotoUrl() != null && writer.getPhotoUrl().length() > 0)
item.addItemField(
ProfileFields.PROFILE_THUMBNAILURL.getParamName(),
writer.getPhotoUrl());
item.setGadgetPermissions(discussion.isUserEdit(request),
discussion.isOwnedByMe(request),
discussion.isOwnedByMe(request));
if (replays != null) {
for (Replys replay : replays) {
int level = 0;
item = response.newItem();
item.addItemKeyField(replay.getId());
item.addItemField(Params.DISCUSSION_TEXT.getParamName(),
replay.getReply());
formatedDate = df.format(replay.getCdate());
if (formatedDate != null)
item.addItemField(
Params.DISCUSSION_MSD_DATE.getParamName(),
formatedDate);
else
item.addItemField(
Params.DISCUSSION_MSD_DATE.getParamName(), "");
if (replay.getReplyOrder() != null)
level = replay.getReplyOrder().split("\\*").length - 1;
// this will be used to create UI message indentation
item.addItemField(Params.DISCUSSION_LEVEL.getParamName(),
new Integer(level).toString());
item.setContentName(Params.DICUSSION_REPLY.getParamName());
writer = DomainUserUtils.getDomainUserByUniqueId(replay
.getUserName(), request.getCurrentDomainUser()
.getAccount());
item.addItemField(
ProfileFields.PROFILE_NICKNAME.getParamName(),
writer.getNickName());
item.addItemField(ProfileFields.PROFILE_TITLE.getParamName(),
writer.getTitle());
if (writer.getPhotoUrl() != null
&& writer.getPhotoUrl().length() > 0)
item.addItemField(
ProfileFields.PROFILE_THUMBNAILURL.getParamName(),
writer.getPhotoUrl());
item.setGadgetPermissions(discussion.isUserEdit(request),
false, false);
}
}