public boolean accept(String from, String recipient, Message message) { try { String messageId = getMessageId(recipient, message); if ((messageId == null) || (!messageId.startsWith(MBUtil.MESSAGE_POP_PORTLET_PREFIX, getOffset()))) { return false; } Company company = getCompany(messageId); long categoryId = getCategoryId(messageId); MBCategory category = MBCategoryLocalServiceUtil.getCategory(categoryId); if (category.getCompanyId() != company.getCompanyId()) { return false; } if (_log.isDebugEnabled()) { _log.debug("Check to see if user " + from + " exists"); } UserLocalServiceUtil.getUserByEmailAddress(company.getCompanyId(), from); return true; } catch (Exception e) { if (_log.isErrorEnabled()) { _log.error("Unable to process message: " + message, e); } return false; } }
public static String getAbsolutePath(PortletRequest portletRequest, long mbCategoryId) throws PortalException, SystemException { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); if (mbCategoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) { return themeDisplay.translate("home"); } MBCategory mbCategory = MBCategoryLocalServiceUtil.fetchMBCategory(mbCategoryId); List<MBCategory> categories = mbCategory.getAncestors(); Collections.reverse(categories); StringBundler sb = new StringBundler((categories.size() * 3) + 5); sb.append(themeDisplay.translate("home")); sb.append(StringPool.SPACE); for (MBCategory curCategory : categories) { sb.append(StringPool.RAQUO); sb.append(StringPool.SPACE); sb.append(curCategory.getName()); } sb.append(StringPool.RAQUO); sb.append(StringPool.SPACE); sb.append(mbCategory.getName()); return sb.toString(); }
public MBCategoryActionableDynamicQuery() throws SystemException { setBaseLocalService(MBCategoryLocalServiceUtil.getService()); setClass(MBCategory.class); setClassLoader(PortalClassLoaderUtil.getClassLoader()); setPrimaryKeyPropertyName("categoryId"); }
@Override public int getContainerModelsCount(long classPK, long parentContainerModelId) throws PortalException, SystemException { MBThread thread = MBThreadLocalServiceUtil.getThread(classPK); return MBCategoryLocalServiceUtil.getCategoriesCount( thread.getGroupId(), parentContainerModelId, WorkflowConstants.STATUS_APPROVED); }
public static void addPortletBreadcrumbEntries( long categoryId, HttpServletRequest request, RenderResponse renderResponse) throws Exception { if ((categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) || (categoryId == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) { return; } MBCategory category = MBCategoryLocalServiceUtil.getCategory(categoryId); addPortletBreadcrumbEntries(category, request, renderResponse); }
@Override public boolean isRestorable(long classPK) throws PortalException, SystemException { MBThread thread = MBThreadLocalServiceUtil.getThread(classPK); if ((thread.getCategoryId() > 0) && (MBCategoryLocalServiceUtil.fetchMBCategory(thread.getCategoryId()) == null)) { return false; } return !thread.isInTrashContainer(); }
@Override protected long addContainerModel(long userId, long containerModelId) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(), userId); MBTestUtil.populateNotificationsServiceContext(serviceContext, Constants.ADD); MBCategory category = MBCategoryLocalServiceUtil.addCategory( userId, containerModelId, RandomTestUtil.randomString(), StringPool.BLANK, serviceContext); return category.getCategoryId(); }
@Override public List<ContainerModel> getContainerModels( long classPK, long parentContainerModelId, int start, int end) throws PortalException, SystemException { List<ContainerModel> containerModels = new ArrayList<ContainerModel>(); MBThread thread = MBThreadLocalServiceUtil.getThread(classPK); List<MBCategory> categories = MBCategoryLocalServiceUtil.getCategories( thread.getGroupId(), parentContainerModelId, WorkflowConstants.STATUS_APPROVED, start, end); for (MBCategory category : categories) { containerModels.add(category); } return containerModels; }
public static List<Object> getEntries(Hits hits) { List<Object> entries = new ArrayList<Object>(); for (Document document : hits.getDocs()) { long categoryId = GetterUtil.getLong(document.get(Field.CATEGORY_ID)); try { MBCategoryLocalServiceUtil.getCategory(categoryId); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn( "Message boards search index is stale and contains " + "category " + categoryId); } continue; } long threadId = GetterUtil.getLong(document.get("threadId")); try { MBThreadLocalServiceUtil.getThread(threadId); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Message boards search index is stale and contains " + "thread " + threadId); } continue; } String entryClassName = document.get(Field.ENTRY_CLASS_NAME); long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); Object obj = null; try { if (entryClassName.equals(DLFileEntry.class.getName())) { long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK)); MBMessageLocalServiceUtil.getMessage(classPK); obj = DLFileEntryLocalServiceUtil.getDLFileEntry(entryClassPK); } else if (entryClassName.equals(MBMessage.class.getName())) { obj = MBMessageLocalServiceUtil.getMessage(entryClassPK); } entries.add(obj); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn( "Message boards search index is stale and contains " + "entry {className=" + entryClassName + ", " + "classPK=" + entryClassPK + "}"); } continue; } } return entries; }
@Override protected void addSubscriptionContainerModel(long containerModelId) throws Exception { MBCategoryLocalServiceUtil.subscribeCategory( user.getUserId(), group.getGroupId(), containerModelId); }
@Override public MBCategory getCategory() throws PortalException, SystemException { return MBCategoryLocalServiceUtil.getCategory(getCategoryId()); }
public void deliver(String from, String recipient, Message message) throws MessageListenerException { try { StopWatch stopWatch = null; if (_log.isDebugEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); _log.debug("Deliver message from " + from + " to " + recipient); } String messageId = getMessageId(recipient, message); Company company = getCompany(messageId); if (_log.isDebugEnabled()) { _log.debug("Message id " + messageId); } long groupId = 0; long categoryId = getCategoryId(messageId); try { MBCategory category = MBCategoryLocalServiceUtil.getCategory(categoryId); groupId = category.getGroupId(); } catch (NoSuchCategoryException nsce) { groupId = categoryId; categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID; } if (_log.isDebugEnabled()) { _log.debug("Group id " + groupId); _log.debug("Category id " + categoryId); } User user = UserLocalServiceUtil.getUserByEmailAddress(company.getCompanyId(), from); long parentMessageId = getParentMessageId(recipient, message); if (_log.isDebugEnabled()) { _log.debug("Parent message id " + parentMessageId); } MBMessage parentMessage = null; try { if (parentMessageId > 0) { parentMessage = MBMessageLocalServiceUtil.getMessage(parentMessageId); } } catch (NoSuchMessageException nsme) { // If the parent message does not exist we ignore it and post // the message as a new thread. } if (_log.isDebugEnabled()) { _log.debug("Parent message " + parentMessage); } String subject = MBUtil.getSubjectWithoutMessageId(message); MBMailMessage collector = new MBMailMessage(); MBUtil.collectPartContent(message, collector); PermissionCheckerUtil.setThreadValues(user); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setLayoutFullURL( PortalUtil.getLayoutFullURL(groupId, PortletKeys.MESSAGE_BOARDS)); serviceContext.setScopeGroupId(groupId); if (parentMessage == null) { MBMessageServiceUtil.addMessage( groupId, categoryId, subject, collector.getBody(), MBMessageConstants.DEFAULT_FORMAT, collector.getFiles(), false, 0.0, true, serviceContext); } else { MBMessageServiceUtil.addMessage( groupId, categoryId, parentMessage.getThreadId(), parentMessage.getMessageId(), subject, collector.getBody(), MBMessageConstants.DEFAULT_FORMAT, collector.getFiles(), false, 0.0, true, serviceContext); } if (_log.isDebugEnabled()) { _log.debug("Delivering message takes " + stopWatch.getTime() + " ms"); } } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug("Prevented unauthorized post from " + from); } throw new MessageListenerException(pe); } catch (Exception e) { _log.error(e, e); throw new MessageListenerException(e); } finally { PermissionCheckerUtil.setThreadValues(null); } }