1
22
23 package com.liferay.portlet.social.model;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.util.StringPool;
28 import com.liferay.portal.model.Group;
29 import com.liferay.portal.model.User;
30 import com.liferay.portal.service.UserLocalServiceUtil;
31 import com.liferay.portal.theme.ThemeDisplay;
32
33
40 public abstract class BaseSocialRequestInterpreter
41 implements SocialRequestInterpreter {
42
43 public String getUserName(long userId, ThemeDisplay themeDisplay) {
44 try {
45 if (userId <= 0) {
46 return StringPool.BLANK;
47 }
48
49 User user = UserLocalServiceUtil.getUserById(userId);
50
51 if (user.getUserId() == themeDisplay.getUserId()) {
52 return user.getFirstName();
53 }
54
55 String userName = user.getFullName();
56
57 Group group = user.getGroup();
58
59 if (group.getGroupId() == themeDisplay.getPortletGroupId()) {
60 return userName;
61 }
62
63 String userDisplayURL = user.getDisplayURL(
64 themeDisplay.getURLPortal());
65
66 userName =
67 "<a href=\"" + userDisplayURL + "\">" + userName + "</a>";
68
69 return userName;
70 }
71 catch (Exception e) {
72 return StringPool.BLANK;
73 }
74 }
75
76 public SocialRequestFeedEntry interpret(
77 SocialRequest request, ThemeDisplay themeDisplay) {
78
79 try {
80 return doInterpret(request, themeDisplay);
81 }
82 catch (Exception e) {
83 _log.error(e);
84 }
85
86 return null;
87 }
88
89 public boolean processConfirmation(
90 SocialRequest request, ThemeDisplay themeDisplay) {
91
92 try {
93 return doProcessConfirmation(request, themeDisplay);
94 }
95 catch (Exception e) {
96 _log.error(e);
97 }
98
99 return false;
100 }
101
102 public boolean processRejection(
103 SocialRequest request, ThemeDisplay themeDisplay) {
104
105 try {
106 return doProcessRejection(request, themeDisplay);
107 }
108 catch (Exception e) {
109 _log.error(e);
110 }
111
112 return false;
113 }
114
115 protected abstract SocialRequestFeedEntry doInterpret(
116 SocialRequest request, ThemeDisplay themeDisplay)
117 throws Exception;
118
119 protected abstract boolean doProcessConfirmation(
120 SocialRequest request, ThemeDisplay themeDisplay)
121 throws Exception;
122
123 protected boolean doProcessRejection(
124 SocialRequest request, ThemeDisplay themeDisplay)
125 throws Exception {
126
127 return true;
128 }
129
130 private static Log _log =
131 LogFactoryUtil.getLog(BaseSocialRequestInterpreter.class);
132
133 }