Example usage for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_APPROVED

List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_APPROVED

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_APPROVED.

Prototype

int STATUS_APPROVED

To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_APPROVED.

Click Source Link

Usage

From source file:com.liferay.message.boards.web.internal.portlet.action.RSSAction.java

License:Open Source License

@Override
protected byte[] getRSS(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    long plid = ParamUtil.getLong(request, "p_l_id");

    if (plid == LayoutConstants.DEFAULT_PLID) {
        plid = themeDisplay.getPlid();/* w ww.j a  v a  2s . com*/
    }

    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    long userId = ParamUtil.getLong(request, "userId");
    long categoryId = ParamUtil.getLong(request, "mbCategoryId");
    long threadId = ParamUtil.getLong(request, "threadId");
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.FORMAT_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);

    String entryURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
            + "/message_boards/find_message?p_l_id=" + plid;

    String rss = StringPool.BLANK;

    if (companyId > 0) {
        String feedURL = StringPool.BLANK;

        rss = _mbMessageService.getCompanyMessagesRSS(companyId, WorkflowConstants.STATUS_APPROVED, max, type,
                version, displayStyle, feedURL, entryURL, themeDisplay);
    } else if (groupId > 0) {
        String mvcRenderCommandName = ParamUtil.getString(request, "mvcRenderCommandName");

        String feedURL = null;

        if (mvcRenderCommandName.equals("/message_boards/view_recent_posts")) {

            feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
                    + "/message_boards/find_recent_posts?p_l_id=" + plid;
        } else {
            feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
                    + "/message_boards/find_category?p_l_id=" + plid + "&mbCategoryId=" + categoryId;
        }

        if (userId > 0) {
            rss = _mbMessageService.getGroupMessagesRSS(groupId, userId, WorkflowConstants.STATUS_APPROVED, max,
                    type, version, displayStyle, feedURL, entryURL, themeDisplay);
        } else {
            rss = _mbMessageService.getGroupMessagesRSS(groupId, WorkflowConstants.STATUS_APPROVED, max, type,
                    version, displayStyle, feedURL, entryURL, themeDisplay);
        }
    } else if (categoryId > 0) {
        String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
                + "/message_boards/find_category?p_l_id=" + plid + "&mbCategoryId=" + categoryId;

        rss = _mbMessageService.getCategoryMessagesRSS(groupId, categoryId, WorkflowConstants.STATUS_APPROVED,
                max, type, version, displayStyle, feedURL, entryURL, themeDisplay);
    } else if (threadId > 0) {
        String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
                + "/message_boards/find_thread?p_l_id=" + plid + "&threadId=" + threadId;

        rss = _mbMessageService.getThreadMessagesRSS(threadId, WorkflowConstants.STATUS_APPROVED, max, type,
                version, displayStyle, feedURL, entryURL, themeDisplay);
    }

    return rss.getBytes(StringPool.UTF8);
}

From source file:com.liferay.portlet.announcements.service.impl.AnnouncementsEntryLocalServiceImpl.java

License:Open Source License

protected void notifyUsers(AnnouncementsEntry entry) throws PortalException, SystemException {

    Company company = companyPersistence.findByPrimaryKey(entry.getCompanyId());

    String className = entry.getClassName();
    long classPK = entry.getClassPK();

    String fromName = PrefsPropsUtil.getStringFromNames(entry.getCompanyId(),
            PropsKeys.ANNOUNCEMENTS_EMAIL_FROM_NAME, PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getStringFromNames(entry.getCompanyId(),
            PropsKeys.ANNOUNCEMENTS_EMAIL_FROM_ADDRESS, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String toName = PropsValues.ANNOUNCEMENTS_EMAIL_TO_NAME;
    String toAddress = PropsValues.ANNOUNCEMENTS_EMAIL_TO_ADDRESS;

    LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();

    params.put("announcementsDeliveryEmailOrSms", entry.getType());

    if (classPK > 0) {
        if (className.equals(Group.class.getName())) {
            Group group = groupPersistence.findByPrimaryKey(classPK);

            toName = group.getName();//from w ww  . j ava 2  s  . com

            params.put("usersGroups", classPK);
        } else if (className.equals(Organization.class.getName())) {
            Organization organization = organizationPersistence.findByPrimaryKey(classPK);

            toName = organization.getName();

            params.put("usersOrgs", classPK);
        } else if (className.equals(Role.class.getName())) {
            Role role = rolePersistence.findByPrimaryKey(classPK);

            toName = role.getName();

            params.put("usersRoles", classPK);
        } else if (className.equals(UserGroup.class.getName())) {
            UserGroup userGroup = userGroupPersistence.findByPrimaryKey(classPK);

            toName = userGroup.getName();

            params.put("usersUserGroups", classPK);
        }
    }

    List<User> users = null;

    if (className.equals(User.class.getName())) {
        User user = userPersistence.findByPrimaryKey(classPK);

        toName = user.getFullName();
        toAddress = user.getEmailAddress();

        users = new ArrayList<User>();

        if (Validator.isNotNull(toAddress)) {
            users.add(user);
        }
    } else {
        users = userLocalService.search(company.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED, params,
                QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator) null);
    }

    if (_log.isDebugEnabled()) {
        _log.debug("Notifying " + users.size() + " users");
    }

    boolean notifyUsers = false;

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    for (User user : users) {
        AnnouncementsDelivery announcementsDelivery = announcementsDeliveryLocalService
                .getUserDelivery(user.getUserId(), entry.getType());

        if (announcementsDelivery.isEmail()) {
            subscriptionSender.addRuntimeSubscribers(user.getEmailAddress(), user.getFullName());

            notifyUsers = true;
        }

        if (announcementsDelivery.isSms()) {
            String smsSn = user.getContact().getSmsSn();

            subscriptionSender.addRuntimeSubscribers(smsSn, user.getFullName());

            notifyUsers = true;
        }
    }

    if (!notifyUsers) {
        return;
    }

    String subject = ContentUtil.get(PropsValues.ANNOUNCEMENTS_EMAIL_SUBJECT);
    String body = ContentUtil.get(PropsValues.ANNOUNCEMENTS_EMAIL_BODY);

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttributes("[$ENTRY_CONTENT$]", entry.getContent(), "[$ENTRY_ID$]",
            entry.getEntryId(), "[$ENTRY_TITLE$]", entry.getTitle(), "[$ENTRY_TYPE$]",
            LanguageUtil.get(company.getLocale(), entry.getType()), "[$ENTRY_URL$]", entry.getUrl(),
            "[$PORTLET_NAME$]",
            LanguageUtil.get(company.getLocale(), (entry.isAlert() ? "alert" : "announcement")));
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("announcements_entry", entry.getEntryId());
    subscriptionSender.setPortletId(PortletKeys.ANNOUNCEMENTS);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(entry.getUserId());

    subscriptionSender.addRuntimeSubscribers(toAddress, toName);

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.portlet.blogs.action.RSSAction.java

License:Open Source License

protected byte[] getRSS(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    long plid = ParamUtil.getLong(request, "p_l_id");
    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    long organizationId = ParamUtil.getLong(request, "organizationId");
    int status = WorkflowConstants.STATUS_APPROVED;
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.TYPE_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);

    String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/blogs/find_entry?";

    String entryURL = feedURL;/*from www.  j av a  2s.com*/

    String rss = StringPool.BLANK;

    if (companyId > 0) {
        feedURL = StringPool.BLANK;

        rss = BlogsEntryServiceUtil.getCompanyEntriesRSS(companyId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    } else if (groupId > 0) {
        feedURL += "p_l_id=" + plid;

        entryURL = feedURL;

        rss = BlogsEntryServiceUtil.getGroupEntriesRSS(groupId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    } else if (organizationId > 0) {
        feedURL = StringPool.BLANK;

        rss = BlogsEntryServiceUtil.getOrganizationEntriesRSS(organizationId, new Date(), status, max, type,
                version, displayStyle, feedURL, entryURL, themeDisplay);
    } else if (layout != null) {
        groupId = themeDisplay.getScopeGroupId();

        feedURL = PortalUtil.getLayoutFullURL(themeDisplay) + Portal.FRIENDLY_URL_SEPARATOR + "blogs/rss";

        entryURL = feedURL;

        rss = BlogsEntryServiceUtil.getGroupEntriesRSS(groupId, new Date(), status, max, type, version,
                displayStyle, feedURL, entryURL, themeDisplay);
    }

    return rss.getBytes(StringPool.UTF8);
}

From source file:com.liferay.portlet.blogs.action.TrackbackAction.java

License:Open Source License

protected void addTrackback(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String title = ParamUtil.getString(actionRequest, "title");
    String excerpt = ParamUtil.getString(actionRequest, "excerpt");
    String url = ParamUtil.getString(actionRequest, "url");
    String blogName = ParamUtil.getString(actionRequest, "blog_name");

    if (!isCommentsEnabled(actionRequest)) {
        sendError(actionRequest, actionResponse, "Comments have been disabled for this blog entry.");

        return;//from   w  w  w . j a  v a2 s.  c  om
    }

    if (Validator.isNull(url)) {
        sendError(actionRequest, actionResponse, "Trackback requires a valid permanent URL.");

        return;
    }

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    String remoteIp = request.getRemoteAddr();

    String trackbackIp = HttpUtil.getIpAddress(url);

    if (!remoteIp.equals(trackbackIp)) {
        sendError(actionRequest, actionResponse,
                "Remote IP " + remoteIp + " does not match trackback URL's IP " + trackbackIp + ".");

        return;
    }

    try {
        ActionUtil.getEntry(actionRequest);
    } catch (PrincipalException pe) {
        sendError(actionRequest, actionResponse,
                "Blog entry must have guest view permissions to enable " + "trackbacks.");

        return;
    }

    BlogsEntry entry = (BlogsEntry) actionRequest.getAttribute(WebKeys.BLOGS_ENTRY);

    if (!entry.isAllowTrackbacks()) {
        sendError(actionRequest, actionResponse, "Trackbacks are not enabled on this blog entry.");

        return;
    }

    long userId = UserLocalServiceUtil.getDefaultUserId(themeDisplay.getCompanyId());
    long groupId = entry.getGroupId();
    String className = BlogsEntry.class.getName();
    long classPK = entry.getEntryId();

    MBMessageDisplay messageDisplay = MBMessageLocalServiceUtil.getDiscussionMessageDisplay(userId, groupId,
            className, classPK, WorkflowConstants.STATUS_APPROVED);

    MBThread thread = messageDisplay.getThread();

    long threadId = thread.getThreadId();
    long parentMessageId = thread.getRootMessageId();
    String body = "[...] " + excerpt + " [...] [url=" + url + "]" + themeDisplay.translate("read-more")
            + "[/url]";

    ServiceContext serviceContext = ServiceContextFactory.getInstance(MBMessage.class.getName(), actionRequest);

    MBMessage message = MBMessageLocalServiceUtil.addDiscussionMessage(userId, blogName, groupId, className,
            classPK, threadId, parentMessageId, title, body, serviceContext);

    String entryURL = PortalUtil.getLayoutFullURL(themeDisplay) + Portal.FRIENDLY_URL_SEPARATOR + "blogs/"
            + entry.getUrlTitle();

    LinkbackConsumerUtil.addNewTrackback(message.getMessageId(), url, entryURL);

    sendSuccess(actionRequest, actionResponse);
}

From source file:com.liferay.portlet.blogs.atom.BlogsEntryAtomCollectionAdapter.java

License:Open Source License

@Override
protected Iterable<BlogsEntry> doGetFeedEntries(AtomRequestContext atomRequestContext) throws Exception {

    long groupId = atomRequestContext.getLongParameter("groupId");
    int status = WorkflowConstants.STATUS_APPROVED;

    int max = atomRequestContext.getIntParameter("max", SearchContainer.DEFAULT_DELTA);

    if (groupId > 0) {
        int page = atomRequestContext.getIntParameter("page");

        if (page == 0) {
            return BlogsEntryServiceUtil.getGroupEntries(groupId, status, max);
        }/*from   w w  w  . j a  va2s . c o  m*/

        int count = BlogsEntryServiceUtil.getGroupEntriesCount(groupId, new Date(), status);

        AtomPager atomPager = new AtomPager(page, max, count);

        AtomUtil.saveAtomPagerInRequest(atomRequestContext, atomPager);

        return BlogsEntryServiceUtil.getGroupEntries(groupId, new Date(), status, atomPager.getStart(),
                atomPager.getEnd() + 1);
    }

    long organizationId = atomRequestContext.getLongParameter("organizationId");

    if (organizationId > 0) {
        return BlogsEntryServiceUtil.getOrganizationEntries(organizationId, new Date(), status, max);
    }

    long companyId = CompanyThreadLocal.getCompanyId();

    if (companyId > 0) {
        return BlogsEntryServiceUtil.getCompanyEntries(companyId, new Date(), status, max);
    }

    return Collections.emptyList();
}

From source file:com.liferay.portlet.blogs.lar.BlogsPortletDataHandlerImpl.java

License:Open Source License

protected void exportEntry(PortletDataContext portletDataContext, Element entriesElement,
        Element dlFileEntryTypesElement, Element dlFoldersElement, Element dlFileEntriesElement,
        Element dlFileRanksElement, BlogsEntry entry) throws Exception {

    if (!portletDataContext.isWithinDateRange(entry.getModifiedDate())) {
        return;/*  w  ww  .j av  a  2 s . c o m*/
    }

    if (entry.getStatus() != WorkflowConstants.STATUS_APPROVED) {
        return;
    }

    String path = getEntryPath(portletDataContext, entry);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;
    }

    // Clone this entry to make sure changes to its content are never
    // persisted

    entry = (BlogsEntry) entry.clone();

    Element entryElement = (Element) entriesElement
            .selectSingleNode("//page[@path='".concat(path).concat("']"));

    if (entryElement == null) {
        entryElement = entriesElement.addElement("entry");
    }

    String content = JournalPortletDataHandlerImpl.exportReferencedContent(portletDataContext,
            dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement, entryElement,
            entry.getContent());

    entry.setContent(content);

    String imagePath = getEntryImagePath(portletDataContext, entry);

    entryElement.addAttribute("image-path", imagePath);

    Image smallImage = ImageUtil.fetchByPrimaryKey(entry.getSmallImageId());

    if (entry.isSmallImage() && (smallImage != null)) {
        String smallImagePath = getEntrySmallImagePath(portletDataContext, entry);

        entryElement.addAttribute("small-image-path", smallImagePath);

        entry.setSmallImageType(smallImage.getType());

        portletDataContext.addZipEntry(smallImagePath, smallImage.getTextObj());
    }

    portletDataContext.addClassedModel(entryElement, path, entry, _NAMESPACE);
}

From source file:com.liferay.portlet.blogs.lar.BlogsPortletDataHandlerImpl.java

License:Open Source License

protected void importEntry(PortletDataContext portletDataContext, Element entryElement, BlogsEntry entry)
        throws Exception {

    long userId = portletDataContext.getUserId(entry.getUserUuid());

    String content = JournalPortletDataHandlerImpl.importReferencedContent(portletDataContext, entryElement,
            entry.getContent());/*from   w  w w  .  ja v a 2s . co  m*/

    entry.setContent(content);

    Calendar displayDateCal = CalendarFactoryUtil.getCalendar();

    displayDateCal.setTime(entry.getDisplayDate());

    int displayDateMonth = displayDateCal.get(Calendar.MONTH);
    int displayDateDay = displayDateCal.get(Calendar.DATE);
    int displayDateYear = displayDateCal.get(Calendar.YEAR);
    int displayDateHour = displayDateCal.get(Calendar.HOUR);
    int displayDateMinute = displayDateCal.get(Calendar.MINUTE);

    if (displayDateCal.get(Calendar.AM_PM) == Calendar.PM) {
        displayDateHour += 12;
    }

    boolean allowPingbacks = entry.isAllowPingbacks();
    boolean allowTrackbacks = entry.isAllowTrackbacks();
    String[] trackbacks = StringUtil.split(entry.getTrackbacks());
    int status = entry.getStatus();

    ServiceContext serviceContext = portletDataContext.createServiceContext(entryElement, entry, _NAMESPACE);

    if (status != WorkflowConstants.STATUS_APPROVED) {
        serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
    }

    String smallImageFileName = null;
    InputStream smallImageInputStream = null;

    try {
        String smallImagePath = entryElement.attributeValue("small-image-path");

        if (entry.isSmallImage() && Validator.isNotNull(smallImagePath)) {
            smallImageFileName = String.valueOf(entry.getSmallImageId()).concat(StringPool.PERIOD)
                    .concat(entry.getSmallImageType());
            smallImageInputStream = portletDataContext.getZipEntryAsInputStream(smallImagePath);
        }

        BlogsEntry importedEntry = null;

        if (portletDataContext.isDataStrategyMirror()) {
            BlogsEntry existingEntry = BlogsEntryUtil.fetchByUUID_G(entry.getUuid(),
                    portletDataContext.getScopeGroupId());

            if (existingEntry == null) {
                serviceContext.setUuid(entry.getUuid());

                importedEntry = BlogsEntryLocalServiceUtil.addEntry(userId, entry.getTitle(),
                        entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay,
                        displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks,
                        trackbacks, entry.isSmallImage(), entry.getSmallImageURL(), smallImageFileName,
                        smallImageInputStream, serviceContext);
            } else {
                importedEntry = BlogsEntryLocalServiceUtil.updateEntry(userId, existingEntry.getEntryId(),
                        entry.getTitle(), entry.getDescription(), entry.getContent(), displayDateMonth,
                        displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks,
                        allowTrackbacks, trackbacks, entry.getSmallImage(), entry.getSmallImageURL(),
                        smallImageFileName, smallImageInputStream, serviceContext);
            }
        } else {
            importedEntry = BlogsEntryLocalServiceUtil.addEntry(userId, entry.getTitle(),
                    entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay,
                    displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks,
                    trackbacks, entry.getSmallImage(), entry.getSmallImageURL(), smallImageFileName,
                    smallImageInputStream, serviceContext);
        }

        portletDataContext.importClassedModel(entry, importedEntry, _NAMESPACE);
    } finally {
        StreamUtil.cleanUp(smallImageInputStream);
    }

}

From source file:com.liferay.portlet.blogs.lar.WordPressImporter.java

License:Open Source License

protected static void importEntry(PortletDataContext context, User defaultUser, Map<String, Long> userMap,
        DateFormat dateFormat, Element entryEl) throws PortalException, SystemException {

    String creator = entryEl.elementText(SAXReaderUtil.createQName("creator", _NS_DC));

    Long userId = userMap.get(creator);

    if (userId == null) {
        userId = context.getUserId(null);
    }/*from w w w  .j av a  2 s .co  m*/

    String title = entryEl.elementTextTrim("title");

    if (Validator.isNull(title)) {
        title = entryEl.elementTextTrim(SAXReaderUtil.createQName("post_name", _NS_WP));
    }

    String content = entryEl.elementText(SAXReaderUtil.createQName("encoded", _NS_CONTENT));

    content = content.replaceAll("\\n", "\n<br />");

    // LPS-1425

    if (Validator.isNull(content)) {
        content = "<br />";
    }

    String dateText = entryEl.elementTextTrim(SAXReaderUtil.createQName("post_date_gmt", _NS_WP));

    Date postDate = new Date();

    try {
        postDate = dateFormat.parse(dateText);
    } catch (ParseException pe) {
        _log.warn("Parse " + dateText, pe);
    }

    Calendar cal = Calendar.getInstance();

    cal.setTime(postDate);

    int displayDateMonth = cal.get(Calendar.MONTH);
    int displayDateDay = cal.get(Calendar.DAY_OF_MONTH);
    int displayDateYear = cal.get(Calendar.YEAR);
    int displayDateHour = cal.get(Calendar.HOUR_OF_DAY);
    int displayDateMinute = cal.get(Calendar.MINUTE);

    String pingStatusText = entryEl.elementTextTrim(SAXReaderUtil.createQName("ping_status", _NS_WP));

    boolean allowPingbacks = pingStatusText.equalsIgnoreCase("open");
    boolean allowTrackbacks = allowPingbacks;

    String statusText = entryEl.elementTextTrim(SAXReaderUtil.createQName("status", _NS_WP));

    int workflowAction = WorkflowConstants.ACTION_PUBLISH;

    if (statusText.equalsIgnoreCase("draft")) {
        workflowAction = WorkflowConstants.ACTION_SAVE_DRAFT;
    }

    String[] assetTagNames = null;

    String categoryText = entryEl.elementTextTrim("category");

    if (Validator.isNotNull(categoryText)) {
        assetTagNames = new String[] { categoryText };
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setAssetTagNames(assetTagNames);
    serviceContext.setScopeGroupId(context.getGroupId());
    serviceContext.setWorkflowAction(workflowAction);

    BlogsEntry entry = null;

    try {
        entry = BlogsEntryLocalServiceUtil.addEntry(userId, title, StringPool.BLANK, content, displayDateMonth,
                displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks,
                allowTrackbacks, null, false, null, null, null, serviceContext);
    } catch (Exception e) {
        _log.error("Add entry " + title, e);

        return;
    }

    MBMessageDisplay messageDisplay = MBMessageLocalServiceUtil.getDiscussionMessageDisplay(userId,
            context.getGroupId(), BlogsEntry.class.getName(), entry.getEntryId(),
            WorkflowConstants.STATUS_APPROVED);

    Map<Long, Long> messageIdMap = new HashMap<Long, Long>();

    List<Node> commentNodes = entryEl.selectNodes("wp:comment", "wp:comment_parent/text()");

    for (Node commentNode : commentNodes) {
        Element commentEl = (Element) commentNode;

        importComment(context, defaultUser, messageDisplay, messageIdMap, entry, commentEl);
    }
}

From source file:com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

public BlogsEntry[] getEntriesPrevAndNext(long entryId) throws PortalException, SystemException {

    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);

    return blogsEntryPersistence.findByG_S_PrevAndNext(entry.getEntryId(), entry.getGroupId(),
            WorkflowConstants.STATUS_APPROVED, new EntryDisplayDateComparator(true));
}

From source file:com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

public BlogsEntry updateStatus(long userId, long entryId, int status, ServiceContext serviceContext)
        throws PortalException, SystemException {

    // Entry//  ww  w  .j a v a 2s  .c o m

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);

    int oldStatus = entry.getStatus();
    long oldStatusByUserId = entry.getStatusByUserId();

    entry.setModifiedDate(serviceContext.getModifiedDate(now));
    entry.setStatus(status);
    entry.setStatusByUserId(user.getUserId());
    entry.setStatusByUserName(user.getFullName());
    entry.setStatusDate(serviceContext.getModifiedDate(now));

    blogsEntryPersistence.update(entry, false);

    Indexer indexer = IndexerRegistryUtil.getIndexer(BlogsEntry.class);

    if (status == WorkflowConstants.STATUS_APPROVED) {

        // Statistics

        blogsStatsUserLocalService.updateStatsUser(entry.getGroupId(), user.getUserId(),
                entry.getDisplayDate());

        if (oldStatus != WorkflowConstants.STATUS_APPROVED) {

            // Asset

            assetEntryLocalService.updateVisible(BlogsEntry.class.getName(), entryId, true);

            // Social

            if (oldStatusByUserId == 0) {
                socialActivityLocalService.addUniqueActivity(user.getUserId(), entry.getGroupId(),
                        BlogsEntry.class.getName(), entryId, BlogsActivityKeys.ADD_ENTRY, StringPool.BLANK, 0);
            } else {
                socialActivityLocalService.addActivity(user.getUserId(), entry.getGroupId(),
                        BlogsEntry.class.getName(), entryId, BlogsActivityKeys.UPDATE_ENTRY, StringPool.BLANK,
                        0);
            }
        }

        // Indexer

        indexer.reindex(entry);

        // Subscriptions

        notifySubscribers(entry, serviceContext);

        // Ping

        String[] trackbacks = (String[]) serviceContext.getAttribute("trackbacks");
        Boolean pingOldTrackbacks = GetterUtil
                .getBoolean((String) serviceContext.getAttribute("pingOldTrackbacks"));

        pingGoogle(entry, serviceContext);
        pingPingback(entry, serviceContext);
        pingTrackbacks(entry, trackbacks, pingOldTrackbacks, serviceContext);
    } else if (status != WorkflowConstants.STATUS_APPROVED) {

        // Asset

        assetEntryLocalService.updateVisible(BlogsEntry.class.getName(), entryId, false);

        // Indexer

        indexer.delete(entry);
    }

    return entry;
}