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