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.getScopeGroupId()) {
60 return userName;
61 }
62
63 String userDisplayURL = user.getDisplayURL(themeDisplay);
64
65 userName =
66 "<a href=\"" + userDisplayURL + "\">" + userName + "</a>";
67
68 return userName;
69 }
70 catch (Exception e) {
71 return StringPool.BLANK;
72 }
73 }
74
75 public SocialRequestFeedEntry interpret(
76 SocialRequest request, ThemeDisplay themeDisplay) {
77
78 try {
79 return doInterpret(request, themeDisplay);
80 }
81 catch (Exception e) {
82 _log.error("Unable to interpret request", e);
83 }
84
85 return null;
86 }
87
88 public boolean processConfirmation(
89 SocialRequest request, ThemeDisplay themeDisplay) {
90
91 try {
92 return doProcessConfirmation(request, themeDisplay);
93 }
94 catch (Exception e) {
95 _log.error("Unable to process confirmation", e);
96 }
97
98 return false;
99 }
100
101 public boolean processRejection(
102 SocialRequest request, ThemeDisplay themeDisplay) {
103
104 try {
105 return doProcessRejection(request, themeDisplay);
106 }
107 catch (Exception e) {
108 _log.error("Unable to process rejection", e);
109 }
110
111 return false;
112 }
113
114 protected abstract SocialRequestFeedEntry doInterpret(
115 SocialRequest request, ThemeDisplay themeDisplay)
116 throws Exception;
117
118 protected abstract boolean doProcessConfirmation(
119 SocialRequest request, ThemeDisplay themeDisplay)
120 throws Exception;
121
122 protected boolean doProcessRejection(
123 SocialRequest request, ThemeDisplay themeDisplay)
124 throws Exception {
125
126 return true;
127 }
128
129 private static Log _log =
130 LogFactoryUtil.getLog(BaseSocialRequestInterpreter.class);
131
132 }