001
014
015 package com.liferay.portlet.messageboards.util;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.portlet.LiferayWindowState;
020 import com.liferay.portal.kernel.util.CharPool;
021 import com.liferay.portal.kernel.util.GetterUtil;
022 import com.liferay.portal.kernel.util.Http;
023 import com.liferay.portal.kernel.util.LocaleUtil;
024 import com.liferay.portal.kernel.util.LocalizationUtil;
025 import com.liferay.portal.kernel.util.ParamUtil;
026 import com.liferay.portal.kernel.util.StringBundler;
027 import com.liferay.portal.kernel.util.StringPool;
028 import com.liferay.portal.kernel.util.StringUtil;
029 import com.liferay.portal.kernel.util.Validator;
030 import com.liferay.portal.model.Group;
031 import com.liferay.portal.model.Organization;
032 import com.liferay.portal.model.Role;
033 import com.liferay.portal.model.UserGroup;
034 import com.liferay.portal.service.GroupLocalServiceUtil;
035 import com.liferay.portal.service.OrganizationLocalServiceUtil;
036 import com.liferay.portal.service.RoleLocalServiceUtil;
037 import com.liferay.portal.service.UserGroupLocalServiceUtil;
038 import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
039 import com.liferay.portal.service.UserLocalServiceUtil;
040 import com.liferay.portal.theme.ThemeDisplay;
041 import com.liferay.portal.util.ContentUtil;
042 import com.liferay.portal.util.PortalUtil;
043 import com.liferay.portal.util.PropsValues;
044 import com.liferay.portal.util.WebKeys;
045 import com.liferay.portlet.messageboards.model.MBBan;
046 import com.liferay.portlet.messageboards.model.MBCategory;
047 import com.liferay.portlet.messageboards.model.MBCategoryConstants;
048 import com.liferay.portlet.messageboards.model.MBMailingList;
049 import com.liferay.portlet.messageboards.model.MBMessage;
050 import com.liferay.portlet.messageboards.model.MBStatsUser;
051 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
052 import com.liferay.portlet.messageboards.service.MBMailingListLocalServiceUtil;
053 import com.liferay.util.mail.JavaMailUtil;
054
055 import java.io.InputStream;
056
057 import java.util.Calendar;
058 import java.util.Collections;
059 import java.util.Date;
060 import java.util.List;
061
062 import javax.mail.BodyPart;
063 import javax.mail.Message;
064 import javax.mail.Part;
065 import javax.mail.internet.MimeMessage;
066 import javax.mail.internet.MimeMultipart;
067
068 import javax.portlet.PortletPreferences;
069 import javax.portlet.PortletURL;
070 import javax.portlet.RenderResponse;
071
072 import javax.servlet.http.HttpServletRequest;
073
074
077 public class MBUtil {
078
079 public static final String POP_PORTLET_PREFIX = "mb.";
080
081 public static final int POP_SERVER_SUBDOMAIN_LENGTH =
082 PropsValues.POP_SERVER_SUBDOMAIN.length();
083
084 public static void addPortletBreadcrumbEntries(
085 long categoryId, HttpServletRequest request,
086 RenderResponse renderResponse)
087 throws Exception {
088
089 if (MBUtil.isDefaultParentCategoryId(categoryId) ||
090 MBUtil.isDiscussionCategoryId(categoryId)) {
091
092 return;
093 }
094
095 MBCategory category = MBCategoryLocalServiceUtil.getCategory(
096 categoryId);
097
098 addPortletBreadcrumbEntries(category, request, renderResponse);
099 }
100
101 public static void addPortletBreadcrumbEntries(
102 MBCategory category, HttpServletRequest request,
103 RenderResponse renderResponse)
104 throws Exception {
105
106 String strutsAction = ParamUtil.getString(
107 request, "struts_action");
108
109 boolean selectCategory = strutsAction.equals(
110 "/message_boards/select_category");
111
112 PortletURL portletURL = renderResponse.createRenderURL();
113
114 if (selectCategory) {
115 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
116 WebKeys.THEME_DISPLAY);
117
118 portletURL.setWindowState(LiferayWindowState.POP_UP);
119
120 portletURL.setParameter(
121 "struts_action", "/message_boards/select_category");
122
123 PortalUtil.addPortletBreadcrumbEntry(
124 request, themeDisplay.translate("categories"),
125 portletURL.toString());
126 }
127 else {
128 portletURL.setParameter("struts_action", "/message_boards/view");
129 portletURL.setParameter("tabs1", "categories");
130 }
131
132 List<MBCategory> ancestorCategories = category.getAncestors();
133
134 Collections.reverse(ancestorCategories);
135
136 for (MBCategory curCategory : ancestorCategories) {
137 portletURL.setParameter(
138 "mbCategoryId", String.valueOf(curCategory.getCategoryId()));
139
140 PortalUtil.addPortletBreadcrumbEntry(
141 request, curCategory.getName(), portletURL.toString());
142 }
143
144 portletURL.setParameter(
145 "mbCategoryId", String.valueOf(category.getCategoryId()));
146
147 PortalUtil.addPortletBreadcrumbEntry(
148 request, category.getName(), portletURL.toString());
149 }
150
151 public static void addPortletBreadcrumbEntries(
152 MBMessage message, HttpServletRequest request,
153 RenderResponse renderResponse)
154 throws Exception {
155
156 if (MBUtil.isDefaultParentCategoryId(message.getCategoryId()) ||
157 MBUtil.isDiscussionCategoryId(message.getCategoryId())) {
158
159 return;
160 }
161
162 MBCategory category = message.getCategory();
163
164 addPortletBreadcrumbEntries(category, request, renderResponse);
165
166 PortletURL portletURL = renderResponse.createRenderURL();
167
168 portletURL.setParameter(
169 "struts_action", "/message_boards/view_message");
170 portletURL.setParameter("tabs1", "categories");
171 portletURL.setParameter(
172 "messageId", String.valueOf(message.getMessageId()));
173
174 PortalUtil.addPortletBreadcrumbEntry(
175 request, message.getSubject(), portletURL.toString());
176 }
177
178 public static void collectMultipartContent(
179 MimeMultipart multipart, MBMailMessage collector)
180 throws Exception {
181
182 for (int i = 0; i < multipart.getCount(); i++) {
183 BodyPart part = multipart.getBodyPart(i);
184
185 collectPartContent(part, collector);
186 }
187 }
188
189 public static void collectPartContent(Part part, MBMailMessage collector)
190 throws Exception {
191
192 Object partContent = part.getContent();
193
194 String contentType = part.getContentType().toLowerCase();
195
196 if ((part.getDisposition() != null) &&
197 (part.getDisposition().equalsIgnoreCase(MimeMessage.ATTACHMENT))) {
198
199 if (_log.isDebugEnabled()) {
200 _log.debug("Processing attachment");
201 }
202
203 byte[] bytes = null;
204
205 if (partContent instanceof String) {
206 bytes = ((String)partContent).getBytes();
207 }
208 else if (partContent instanceof InputStream) {
209 bytes = JavaMailUtil.getBytes(part);
210 }
211
212 collector.addFile(part.getFileName(), bytes);
213 }
214 else {
215 if (partContent instanceof MimeMultipart) {
216 collectMultipartContent((MimeMultipart)partContent, collector);
217 }
218 else if (partContent instanceof String) {
219 if (contentType.startsWith("text/html")) {
220 collector.setHtmlBody((String)partContent);
221 }
222 else {
223 collector.setPlainBody((String)partContent);
224 }
225 }
226 }
227 }
228
229 public static long getCategoryId(
230 HttpServletRequest request, MBCategory category) {
231
232 long categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID;
233
234 if (category != null) {
235 categoryId = category.getCategoryId();
236 }
237
238 categoryId = ParamUtil.getLong(request, "mbCategoryId", categoryId);
239
240 return categoryId;
241 }
242
243 public static long getCategoryId(
244 HttpServletRequest request, MBMessage message) {
245
246 long categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID;
247
248 if (message != null) {
249 categoryId = message.getCategoryId();
250 }
251
252 categoryId = ParamUtil.getLong(request, "mbCategoryId", categoryId);
253
254 return categoryId;
255 }
256
257 public static String getEmailFromAddress(PortletPreferences preferences) {
258 String emailFromAddress = PropsValues.MESSAGE_BOARDS_EMAIL_FROM_ADDRESS;
259
260 return preferences.getValue("email-from-address", emailFromAddress);
261 }
262
263 public static String getEmailFromName(PortletPreferences preferences) {
264 String emailFromName = PropsValues.MESSAGE_BOARDS_EMAIL_FROM_NAME;
265
266 return preferences.getValue("email-from-name", emailFromName);
267 }
268
269 public static boolean getEmailHtmlFormat(PortletPreferences preferences) {
270 String emailHtmlFormat = preferences.getValue(
271 "email-html-format", StringPool.BLANK);
272
273 if (Validator.isNotNull(emailHtmlFormat)) {
274 return GetterUtil.getBoolean(emailHtmlFormat);
275 }
276 else {
277 return PropsValues.MESSAGE_BOARDS_EMAIL_HTML_FORMAT;
278 }
279 }
280
281 public static String getEmailMessageAddedBody(
282 PortletPreferences preferences) {
283
284 String emailMessageAddedBody = preferences.getValue(
285 "email-message-added-body", StringPool.BLANK);
286
287 if (Validator.isNotNull(emailMessageAddedBody)) {
288 return emailMessageAddedBody;
289 }
290 else {
291 return ContentUtil.get(
292 PropsValues.MESSAGE_BOARDS_EMAIL_MESSAGE_ADDED_BODY);
293 }
294 }
295
296 public static boolean getEmailMessageAddedEnabled(
297 PortletPreferences preferences) {
298
299 String emailMessageAddedEnabled = preferences.getValue(
300 "email-message-added-enabled", StringPool.BLANK);
301
302 if (Validator.isNotNull(emailMessageAddedEnabled)) {
303 return GetterUtil.getBoolean(emailMessageAddedEnabled);
304 }
305 else {
306 return PropsValues.MESSAGE_BOARDS_EMAIL_MESSAGE_ADDED_ENABLED;
307 }
308 }
309
310 public static String getEmailMessageAddedSignature(
311 PortletPreferences preferences) {
312
313 String emailMessageAddedSignature = preferences.getValue(
314 "email-message-added-signature", StringPool.BLANK);
315
316 if (Validator.isNotNull(emailMessageAddedSignature)) {
317 return emailMessageAddedSignature;
318 }
319 else {
320 return ContentUtil.get(
321 PropsValues.MESSAGE_BOARDS_EMAIL_MESSAGE_ADDED_SIGNATURE);
322 }
323 }
324
325 public static String getEmailMessageAddedSubjectPrefix(
326 PortletPreferences preferences) {
327
328 String emailMessageAddedSubjectPrefix = preferences.getValue(
329 "email-message-added-subject-prefix", StringPool.BLANK);
330
331 if (Validator.isNotNull(emailMessageAddedSubjectPrefix)) {
332 return emailMessageAddedSubjectPrefix;
333 }
334 else {
335 return ContentUtil.get(
336 PropsValues.MESSAGE_BOARDS_EMAIL_MESSAGE_ADDED_SUBJECT_PREFIX);
337 }
338 }
339
340 public static String getEmailMessageUpdatedBody(
341 PortletPreferences preferences) {
342
343 String emailMessageUpdatedBody = preferences.getValue(
344 "email-message-updated-body", StringPool.BLANK);
345
346 if (Validator.isNotNull(emailMessageUpdatedBody)) {
347 return emailMessageUpdatedBody;
348 }
349 else {
350 return ContentUtil.get(
351 PropsValues.MESSAGE_BOARDS_EMAIL_MESSAGE_UPDATED_BODY);
352 }
353 }
354
355 public static boolean getEmailMessageUpdatedEnabled(
356 PortletPreferences preferences) {
357
358 String emailMessageUpdatedEnabled = preferences.getValue(
359 "email-message-updated-enabled", StringPool.BLANK);
360
361 if (Validator.isNotNull(emailMessageUpdatedEnabled)) {
362 return GetterUtil.getBoolean(emailMessageUpdatedEnabled);
363 }
364 else {
365 return PropsValues.MESSAGE_BOARDS_EMAIL_MESSAGE_UPDATED_ENABLED;
366 }
367 }
368
369 public static String getEmailMessageUpdatedSignature(
370 PortletPreferences preferences) {
371
372 String emailMessageUpdatedSignature = preferences.getValue(
373 "email-message-updated-signature", StringPool.BLANK);
374
375 if (Validator.isNotNull(emailMessageUpdatedSignature)) {
376 return emailMessageUpdatedSignature;
377 }
378 else {
379 return ContentUtil.get(
380 PropsValues.MESSAGE_BOARDS_EMAIL_MESSAGE_UPDATED_SIGNATURE);
381 }
382 }
383
384 public static String getEmailMessageUpdatedSubjectPrefix(
385 PortletPreferences preferences) {
386
387 String emailMessageUpdatedSubject = preferences.getValue(
388 "email-message-updated-subject-prefix", StringPool.BLANK);
389
390 if (Validator.isNotNull(emailMessageUpdatedSubject)) {
391 return emailMessageUpdatedSubject;
392 }
393 else {
394 return ContentUtil.get(
395 PropsValues.
396 MESSAGE_BOARDS_EMAIL_MESSAGE_UPDATED_SUBJECT_PREFIX);
397 }
398 }
399
400 public static String getMailId(String mx, long categoryId, long messageId) {
401 StringBundler sb = new StringBundler(10);
402
403 sb.append(StringPool.LESS_THAN);
404 sb.append(POP_PORTLET_PREFIX);
405 sb.append(categoryId);
406 sb.append(StringPool.PERIOD);
407 sb.append(messageId);
408 sb.append(StringPool.AT);
409
410 if (Validator.isNotNull(PropsValues.POP_SERVER_SUBDOMAIN)) {
411 sb.append(PropsValues.POP_SERVER_SUBDOMAIN);
412 sb.append(StringPool.PERIOD);
413 }
414
415 sb.append(mx);
416 sb.append(StringPool.GREATER_THAN);
417
418 return sb.toString();
419 }
420
421 public static String getMailingListAddress(
422 long groupId, long categoryId, long messageId, String mx,
423 String defaultMailingListAddress) {
424
425 if (POP_SERVER_SUBDOMAIN_LENGTH <= 0) {
426 String mailingListAddress = defaultMailingListAddress;
427
428 try {
429 MBMailingList mailingList =
430 MBMailingListLocalServiceUtil.getCategoryMailingList(
431 groupId, categoryId);
432
433 if (mailingList.isActive()) {
434 mailingListAddress = mailingList.getEmailAddress();
435 }
436 }
437 catch (Exception e) {
438 }
439
440 return mailingListAddress;
441 }
442
443 StringBundler sb = new StringBundler(8);
444
445 sb.append(POP_PORTLET_PREFIX);
446 sb.append(categoryId);
447 sb.append(StringPool.PERIOD);
448 sb.append(messageId);
449 sb.append(StringPool.AT);
450 sb.append(PropsValues.POP_SERVER_SUBDOMAIN);
451 sb.append(StringPool.PERIOD);
452 sb.append(mx);
453
454 return sb.toString();
455 }
456
457 public static long getMessageId(String mailId) {
458 int x = mailId.indexOf(CharPool.LESS_THAN) + 1;
459 int y = mailId.indexOf(CharPool.AT);
460
461 long messageId = 0;
462
463 if ((x > 0 ) && (y != -1)) {
464 String temp = mailId.substring(x, y);
465
466 int z = temp.lastIndexOf(CharPool.PERIOD);
467
468 if (z != -1) {
469 messageId = GetterUtil.getLong(temp.substring(z + 1));
470 }
471 }
472
473 return messageId;
474 }
475
476 public static long getParentMessageId(Message message) throws Exception {
477 long parentMessageId = -1;
478
479 String parentHeader = getParentMessageIdString(message);
480
481 if (parentHeader != null) {
482 if (_log.isDebugEnabled()) {
483 _log.debug("Parent header " + parentHeader);
484 }
485
486 parentMessageId = getMessageId(parentHeader);
487
488 if (_log.isDebugEnabled()) {
489 _log.debug("Previous message id " + parentMessageId);
490 }
491 }
492
493 return parentMessageId;
494 }
495
496 public static String getParentMessageIdString(Message message)
497 throws Exception {
498
499
500
501
502
503
504 String parentHeader = null;
505
506 String[] references = message.getHeader("References");
507
508 if ((references != null) && (references.length > 0)) {
509 String reference = references[0];
510
511 int x = reference.lastIndexOf("<mb.");
512
513 if (x > -1) {
514 int y = reference.indexOf(">", x);
515
516 parentHeader = reference.substring(x, y);
517 }
518 }
519
520 if (parentHeader == null) {
521 String[] inReplyToHeaders = message.getHeader("In-Reply-To");
522
523 if ((inReplyToHeaders != null) && (inReplyToHeaders.length > 0)) {
524 parentHeader = inReplyToHeaders[0];
525 }
526 }
527
528 if (Validator.isNull(parentHeader) ||
529 !parentHeader.startsWith(POP_PORTLET_PREFIX, 1)) {
530
531 parentHeader = _getParentMessageIdFromSubject(message);
532 }
533
534 return parentHeader;
535 }
536
537 public static String getSubjectWithoutMessageId(Message message)
538 throws Exception {
539
540 String subject = message.getSubject();
541
542 String parentMessageId = _getParentMessageIdFromSubject(message);
543
544 if (Validator.isNotNull(parentMessageId)) {
545 int pos = subject.indexOf(parentMessageId);
546
547 if (pos != -1) {
548 subject = subject.substring(0, pos);
549 }
550 }
551
552 return subject;
553 }
554
555 public static String[] getThreadPriority(
556 PortletPreferences preferences, String languageId, double value,
557 ThemeDisplay themeDisplay)
558 throws Exception {
559
560 String[] priorities = LocalizationUtil.getPreferencesValues(
561 preferences, "priorities", languageId);
562
563 String[] priorityPair = _findThreadPriority(
564 value, themeDisplay, priorities);
565
566 if (priorityPair == null) {
567 String defaultLanguageId = LocaleUtil.toLanguageId(
568 LocaleUtil.getDefault());
569
570 priorities = LocalizationUtil.getPreferencesValues(
571 preferences, "priorities", defaultLanguageId);
572
573 priorityPair = _findThreadPriority(value, themeDisplay, priorities);
574 }
575
576 return priorityPair;
577 }
578
579 public static Date getUnbanDate(MBBan ban, int expireInterval) {
580 Date banDate = ban.getCreateDate();
581
582 Calendar cal = Calendar.getInstance();
583
584 cal.setTime(banDate);
585
586 cal.add(Calendar.DATE, expireInterval);
587
588 return cal.getTime();
589 }
590
591 public static String getUserRank(
592 PortletPreferences preferences, String languageId, int posts)
593 throws Exception {
594
595 String rank = StringPool.BLANK;
596
597 String[] ranks = LocalizationUtil.getPreferencesValues(
598 preferences, "ranks", languageId);
599
600 for (int i = 0; i < ranks.length; i++) {
601 String[] kvp = StringUtil.split(ranks[i], StringPool.EQUAL);
602
603 String kvpName = kvp[0];
604 int kvpPosts = GetterUtil.getInteger(kvp[1]);
605
606 if (posts >= kvpPosts) {
607 rank = kvpName;
608 }
609 else {
610 break;
611 }
612 }
613
614 return rank;
615 }
616
617 public static String[] getUserRank(
618 PortletPreferences preferences, String languageId,
619 MBStatsUser statsUser)
620 throws Exception {
621
622 String[] rank = {StringPool.BLANK, StringPool.BLANK};
623
624 int maxPosts = 0;
625
626 Group group = GroupLocalServiceUtil.getGroup(
627 statsUser.getGroupId());
628
629 long companyId = group.getCompanyId();
630
631 String[] ranks = LocalizationUtil.getPreferencesValues(
632 preferences, "ranks", languageId);
633
634 for (int i = 0; i < ranks.length; i++) {
635 String[] kvp = StringUtil.split(ranks[i], StringPool.EQUAL);
636
637 String curRank = kvp[0];
638 String curRankValue = kvp[1];
639
640 String[] curRankValueKvp = StringUtil.split(
641 curRankValue, StringPool.COLON);
642
643 if (curRankValueKvp.length <= 1) {
644 int posts = GetterUtil.getInteger(curRankValue);
645
646 if ((posts <= statsUser.getMessageCount()) &&
647 (posts >= maxPosts)) {
648
649 rank[0] = curRank;
650 maxPosts = posts;
651 }
652
653 }
654 else {
655 String entityType = curRankValueKvp[0];
656 String entityValue = curRankValueKvp[1];
657
658 try {
659 if (_isEntityRank(
660 companyId, statsUser, entityType, entityValue)) {
661
662 rank[1] = curRank;
663
664 break;
665 }
666 }
667 catch (Exception e) {
668 if (_log.isWarnEnabled()) {
669 _log.warn(e);
670 }
671 }
672 }
673 }
674
675 return rank;
676 }
677
678 public static boolean hasMailIdHeader(Message message) throws Exception {
679 String[] messageIds = message.getHeader("Message-ID");
680
681 if (messageIds == null) {
682 return false;
683 }
684
685 for (String messageId : messageIds) {
686 if (Validator.isNotNull(PropsValues.POP_SERVER_SUBDOMAIN) &&
687 messageId.contains(PropsValues.POP_SERVER_SUBDOMAIN)) {
688
689 return true;
690 }
691 }
692
693 return false;
694 }
695
696 public static boolean isAllowAnonymousPosting(
697 PortletPreferences preferences) {
698
699 String allowAnonymousPosting = preferences.getValue(
700 "allow-anonymous-posting", StringPool.BLANK);
701
702 if (Validator.isNotNull(allowAnonymousPosting)) {
703 return GetterUtil.getBoolean(allowAnonymousPosting);
704 }
705 else {
706 return PropsValues.MESSAGE_BOARDS_ANONYMOUS_POSTING_ENABLED;
707 }
708 }
709
710 public static boolean isDefaultParentCategoryId(long categoryId) {
711 if (categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
712 return true;
713 }
714
715 return false;
716 }
717
718 public static boolean isDiscussionCategoryId(long categoryId) {
719 if (categoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID) {
720 return true;
721 }
722
723 return false;
724 }
725
726 private static String[] _findThreadPriority(
727 double value, ThemeDisplay themeDisplay, String[] priorities) {
728
729 for (int i = 0; i < priorities.length; i++) {
730 String[] priority = StringUtil.split(priorities[i]);
731
732 try {
733 String priorityName = priority[0];
734 String priorityImage = priority[1];
735 double priorityValue = GetterUtil.getDouble(priority[2]);
736
737 if (value == priorityValue) {
738 if (!priorityImage.startsWith(Http.HTTP)) {
739 priorityImage =
740 themeDisplay.getPathThemeImages() + priorityImage;
741 }
742
743 return new String[] {priorityName, priorityImage};
744 }
745 }
746 catch (Exception e) {
747 _log.error("Unable to determine thread priority", e);
748 }
749 }
750
751 return null;
752 }
753
754 private static String _getParentMessageIdFromSubject(Message message)
755 throws Exception {
756
757 String parentMessageId = null;
758
759 String subject = StringUtil.reverse(message.getSubject());
760
761 int pos = subject.indexOf(CharPool.LESS_THAN);
762
763 if (pos != -1) {
764 parentMessageId = StringUtil.reverse(subject.substring(0, pos + 1));
765 }
766
767 return parentMessageId;
768 }
769
770 private static boolean _isEntityRank(
771 long companyId, MBStatsUser statsUser, String entityType,
772 String entityValue)
773 throws Exception {
774
775 long groupId = statsUser.getGroupId();
776 long userId = statsUser.getUserId();
777
778 if (entityType.equals("community-role") ||
779 entityType.equals("organization-role")) {
780
781 Role role = RoleLocalServiceUtil.getRole(companyId, entityValue);
782
783 if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
784 userId, groupId, role.getRoleId(), true)) {
785
786 return true;
787 }
788 }
789 else if (entityType.equals("organization")) {
790 Organization organization =
791 OrganizationLocalServiceUtil.getOrganization(
792 companyId, entityValue);
793
794 if (OrganizationLocalServiceUtil.hasUserOrganization(
795 userId, organization.getOrganizationId(), false, true,
796 false)) {
797
798 return true;
799 }
800 }
801 else if (entityType.equals("regular-role")) {
802 if (RoleLocalServiceUtil.hasUserRole(
803 userId, companyId, entityValue, true)) {
804
805 return true;
806 }
807 }
808 else if (entityType.equals("user-group")) {
809 UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(
810 companyId, entityValue);
811
812 if (UserLocalServiceUtil.hasUserGroupUser(
813 userGroup.getUserGroupId(), userId)) {
814
815 return true;
816 }
817 }
818
819 return false;
820 }
821
822 private static Log _log = LogFactoryUtil.getLog(MBUtil.class);
823
824 }