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

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

Introduction

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

Prototype

int ACTION_PUBLISH

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

Click Source Link

Usage

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 a  v a2  s  .  c o 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 addEntry(long userId, String title, String description, String content, int displayDateMonth,
        int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute,
        boolean allowPingbacks, boolean allowTrackbacks, String[] trackbacks, boolean smallImage,
        String smallImageURL, String smallImageFileName, InputStream smallImageInputStream,
        ServiceContext serviceContext) throws PortalException, SystemException {

    // Entry/*  w ww.  j a va 2 s .com*/

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();

    Date displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
            displayDateMinute, user.getTimeZone(), new EntryDisplayDateException());

    byte[] smallImageBytes = null;

    try {
        if ((smallImageInputStream != null) && smallImage) {
            smallImageBytes = FileUtil.getBytes(smallImageInputStream);
        }
    } catch (IOException ioe) {
    }

    Date now = new Date();

    validate(title, content, smallImage, smallImageURL, smallImageFileName, smallImageBytes);

    long entryId = counterLocalService.increment();

    BlogsEntry entry = blogsEntryPersistence.create(entryId);

    entry.setUuid(serviceContext.getUuid());
    entry.setGroupId(groupId);
    entry.setCompanyId(user.getCompanyId());
    entry.setUserId(user.getUserId());
    entry.setUserName(user.getFullName());
    entry.setCreateDate(serviceContext.getCreateDate(now));
    entry.setModifiedDate(serviceContext.getModifiedDate(now));
    entry.setTitle(title);
    entry.setUrlTitle(getUniqueUrlTitle(entryId, groupId, title));
    entry.setDescription(description);
    entry.setContent(content);
    entry.setDisplayDate(displayDate);
    entry.setAllowPingbacks(allowPingbacks);
    entry.setAllowTrackbacks(allowTrackbacks);
    entry.setSmallImage(smallImage);
    entry.setSmallImageId(counterLocalService.increment());
    entry.setSmallImageURL(smallImageURL);
    entry.setStatus(WorkflowConstants.STATUS_DRAFT);
    entry.setStatusDate(serviceContext.getModifiedDate(now));
    entry.setExpandoBridgeAttributes(serviceContext);

    blogsEntryPersistence.update(entry, false);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addEntryResources(entry, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addEntryResources(entry, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Small image

    saveImages(smallImage, entry.getSmallImageId(), smallImageBytes);

    // Asset

    updateAsset(userId, entry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds());

    // Message boards

    if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
        mbMessageLocalService.addDiscussionMessage(userId, entry.getUserName(), groupId,
                BlogsEntry.class.getName(), entryId, WorkflowConstants.ACTION_PUBLISH);
    }

    // Workflow

    if ((trackbacks != null) && (trackbacks.length > 0)) {
        serviceContext.setAttribute("trackbacks", trackbacks);
    } else {
        serviceContext.setAttribute("trackbacks", null);
    }

    WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId,
            BlogsEntry.class.getName(), entry.getEntryId(), entry, serviceContext);

    return entry;
}

From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppHelperLocalServiceImpl.java

License:Open Source License

public void addFileEntry(long userId, FileEntry fileEntry, FileVersion fileVersion,
        ServiceContext serviceContext) throws PortalException, SystemException {

    updateAsset(userId, fileEntry, fileVersion, serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());

    if (PropsValues.DL_FILE_ENTRY_COMMENTS_ENABLED) {
        mbMessageLocalService.addDiscussionMessage(fileEntry.getUserId(), fileEntry.getUserName(),
                fileEntry.getGroupId(), DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId(),
                WorkflowConstants.ACTION_PUBLISH);
    }/*from w w  w . j a v  a  2  s.com*/

    if (fileVersion instanceof LiferayFileVersion) {
        DLFileVersion dlFileVersion = (DLFileVersion) fileVersion.getModel();

        Map<String, Serializable> workflowContext = new HashMap<String, Serializable>();

        workflowContext.put("event", DLSyncConstants.EVENT_ADD);

        WorkflowHandlerRegistryUtil.startWorkflowInstance(dlFileVersion.getCompanyId(),
                dlFileVersion.getGroupId(), userId, DLFileEntry.class.getName(),
                dlFileVersion.getFileVersionId(), dlFileVersion, serviceContext, workflowContext);
    }

    registerDLProcessorCallback(fileEntry);
}

From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppServiceImpl.java

License:Open Source License

/**
 * Cancels the check out of the file entry. If a user has not checked out
 * the specified file entry, invoking this method will result in no changes.
 *
 * <p>// w  w  w.  j ava 2s .co m
 * When a file entry is checked out, a PWC (private working copy) is created
 * and the original file entry is locked. A client can make as many changes
 * to the PWC as he desires without those changes being visible to other
 * users. If the user is satisfied with the changes, he may elect to check
 * in his changes, resulting in a new file version based on the PWC; the PWC
 * will be removed and the file entry will be unlocked. If the user is not
 * satisfied with the changes, he may elect to cancel his check out; this
 * results in the deletion of the PWC and unlocking of the file entry.
 * </p>
 *
 * @param  fileEntryId the primary key of the file entry to cancel the
 *         checkout
 * @throws PortalException if the file entry could not be found
 * @throws SystemException if a system exception occurred
 * @see    #checkInFileEntry(long, boolean, String, ServiceContext)
 * @see    #checkOutFileEntry(long)
 */
public void cancelCheckOut(long fileEntryId) throws PortalException, SystemException {

    Repository repository = getRepository(0, fileEntryId, 0);

    FileEntry fileEntry = repository.getFileEntry(fileEntryId);

    DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());

    repository.cancelCheckOut(fileEntryId);

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    dlAppHelperLocalService.updateFileEntry(getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
}

From source file:com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.java

License:Open Source License

public void checkInFileEntry(long userId, long fileEntryId, boolean majorVersion, String changeLog,
        ServiceContext serviceContext) throws PortalException, SystemException {

    if (!isFileEntryCheckedOut(fileEntryId)) {
        return;/*from  www  .  j  a  va 2  s.com*/
    }

    if (!hasFileEntryLock(userId, fileEntryId)) {
        lockFileEntry(userId, fileEntryId);
    }

    User user = userPersistence.findByPrimaryKey(userId);
    DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(fileEntryId);

    String version = getNextVersion(dlFileEntry, majorVersion, serviceContext.getWorkflowAction());

    DLFileVersion dlFileVersion = dlFileVersionLocalService.getLatestFileVersion(fileEntryId, false);

    dlFileVersion.setVersion(version);
    dlFileVersion.setChangeLog(changeLog);

    dlFileVersionPersistence.update(dlFileVersion, false);

    // Folder

    if (dlFileEntry.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        dlFolderLocalService.updateLastPostDate(dlFileEntry.getFolderId(), dlFileEntry.getModifiedDate());
    }

    // File

    DLStoreUtil.updateFileVersion(user.getCompanyId(), dlFileEntry.getDataRepositoryId(), dlFileEntry.getName(),
            DLFileEntryConstants.PRIVATE_WORKING_COPY_VERSION, version);

    if (serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_PUBLISH) {

        startWorkflowInstance(userId, serviceContext, dlFileVersion, DLSyncConstants.EVENT_UPDATE);
    }

    lockLocalService.unlock(DLFileEntry.class.getName(), fileEntryId);
}

From source file:com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.java

License:Open Source License

protected DLFileEntry updateFileEntry(long userId, long fileEntryId, String sourceFileName, String extension,
        String mimeType, String title, String description, String changeLog, boolean majorVersion,
        String extraSettings, long fileEntryTypeId, Map<String, Fields> fieldsMap, File file, InputStream is,
        long size, ServiceContext serviceContext) throws PortalException, SystemException {

    User user = userPersistence.findByPrimaryKey(userId);
    DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(fileEntryId);

    boolean checkedOut = dlFileEntry.isCheckedOut();

    DLFileVersion dlFileVersion = dlFileVersionLocalService.getLatestFileVersion(fileEntryId, !checkedOut);

    boolean autoCheckIn = !checkedOut && dlFileVersion.isApproved();

    if (autoCheckIn) {
        dlFileEntry = checkOutFileEntry(userId, fileEntryId);
    } else if (!checkedOut) {
        lockFileEntry(userId, fileEntryId);
    }//from  www.  ja v  a  2 s .  c o  m

    if (!hasFileEntryLock(userId, fileEntryId)) {
        lockFileEntry(userId, fileEntryId);
    }

    if (checkedOut || autoCheckIn) {
        dlFileVersion = dlFileVersionLocalService.getLatestFileVersion(fileEntryId, false);
    }

    try {
        if (Validator.isNull(extension)) {
            extension = dlFileEntry.getExtension();
        }

        if (Validator.isNull(mimeType)) {
            mimeType = dlFileEntry.getMimeType();
        }

        if (Validator.isNull(title)) {
            title = sourceFileName;

            if (Validator.isNull(title)) {
                title = dlFileEntry.getTitle();
            }
        }

        Date now = new Date();

        validateFile(dlFileEntry.getGroupId(), dlFileEntry.getFolderId(), dlFileEntry.getFileEntryId(),
                extension, title, sourceFileName, file, is);

        // File version

        String version = dlFileVersion.getVersion();

        if (size == 0) {
            size = dlFileVersion.getSize();
        }

        updateFileVersion(user, dlFileVersion, sourceFileName, extension, mimeType, title, description,
                changeLog, extraSettings, fileEntryTypeId, fieldsMap, version, size, dlFileVersion.getStatus(),
                serviceContext.getModifiedDate(now), serviceContext);

        // App helper

        dlAppHelperLocalService.updateAsset(userId, new LiferayFileEntry(dlFileEntry),
                new LiferayFileVersion(dlFileVersion), serviceContext.getAssetCategoryIds(),
                serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());

        // File

        if ((file != null) || (is != null)) {
            try {
                DLStoreUtil.deleteFile(user.getCompanyId(), dlFileEntry.getDataRepositoryId(),
                        dlFileEntry.getName(), version);
            } catch (NoSuchFileException nsfe) {
            }

            if (file != null) {
                DLStoreUtil.updateFile(user.getCompanyId(), dlFileEntry.getDataRepositoryId(),
                        dlFileEntry.getName(), dlFileEntry.getExtension(), false, version, sourceFileName,
                        file);
            } else {
                DLStoreUtil.updateFile(user.getCompanyId(), dlFileEntry.getDataRepositoryId(),
                        dlFileEntry.getName(), dlFileEntry.getExtension(), false, version, sourceFileName, is);
            }
        }

        if (autoCheckIn) {
            checkInFileEntry(userId, fileEntryId, majorVersion, changeLog, serviceContext);
        } else if (serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_PUBLISH) {

            String syncEvent = DLSyncConstants.EVENT_UPDATE;

            if (dlFileVersion.getVersion().equals(DLFileEntryConstants.VERSION_DEFAULT)) {

                syncEvent = DLSyncConstants.EVENT_ADD;
            }

            startWorkflowInstance(userId, serviceContext, dlFileVersion, syncEvent);
        }
    } catch (PortalException pe) {
        if (autoCheckIn) {
            cancelCheckOut(userId, fileEntryId);
        }

        throw pe;
    } catch (SystemException se) {
        if (autoCheckIn) {
            cancelCheckOut(userId, fileEntryId);
        }

        throw se;
    } finally {
        if (!autoCheckIn && !checkedOut) {
            unlockFileEntry(fileEntryId);
        }
    }

    return dlFileEntryPersistence.findByPrimaryKey(fileEntryId);
}

From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

public JournalArticle addArticle(long userId, long groupId, long classNameId, long classPK, String articleId,
        boolean autoArticleId, double version, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
        String content, String type, String structureId, String templateId, String layoutUuid,
        int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour,
        int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear,
        int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
        int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview,
        boolean indexable, boolean smallImage, String smallImageURL, File smallImageFile,
        Map<String, byte[]> images, String articleURL, ServiceContext serviceContext)
        throws PortalException, SystemException {

    // Article/*  w  w w  . j ava 2  s.  c o m*/

    User user = userPersistence.findByPrimaryKey(userId);
    articleId = articleId.trim().toUpperCase();

    Date displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
            displayDateMinute, user.getTimeZone(), new ArticleDisplayDateException());

    Date expirationDate = null;

    if (!neverExpire) {
        expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear,
                expirationDateHour, expirationDateMinute, user.getTimeZone(),
                new ArticleExpirationDateException());
    }

    Date reviewDate = null;

    if (!neverReview) {
        reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
                reviewDateMinute, user.getTimeZone(), new ArticleReviewDateException());
    }

    byte[] smallImageBytes = null;

    try {
        smallImageBytes = FileUtil.getBytes(smallImageFile);
    } catch (IOException ioe) {
    }

    Date now = new Date();

    validate(user.getCompanyId(), groupId, classNameId, articleId, autoArticleId, version, titleMap, content,
            type, structureId, templateId, smallImage, smallImageURL, smallImageFile, smallImageBytes);

    if (autoArticleId) {
        articleId = String.valueOf(counterLocalService.increment());
    }

    long id = counterLocalService.increment();

    long resourcePrimKey = journalArticleResourceLocalService
            .getArticleResourcePrimKey(serviceContext.getUuid(), groupId, articleId);

    JournalArticle article = journalArticlePersistence.create(id);

    Locale locale = LocaleUtil.getDefault();

    String defaultLanguageId = GetterUtil.getString(serviceContext.getAttribute("defaultLanguageId"));

    if (Validator.isNotNull(defaultLanguageId)) {
        locale = LocaleUtil.fromLanguageId(defaultLanguageId);
    }

    String title = titleMap.get(locale);

    content = format(user, groupId, articleId, version, false, content, structureId, images);

    article.setResourcePrimKey(resourcePrimKey);
    article.setGroupId(groupId);
    article.setCompanyId(user.getCompanyId());
    article.setUserId(user.getUserId());
    article.setUserName(user.getFullName());
    article.setCreateDate(serviceContext.getCreateDate(now));
    article.setModifiedDate(serviceContext.getModifiedDate(now));
    article.setClassNameId(classNameId);
    article.setClassPK(classPK);
    article.setArticleId(articleId);
    article.setVersion(version);
    article.setTitleMap(titleMap, locale);
    article.setUrlTitle(getUniqueUrlTitle(id, groupId, articleId, title));
    article.setDescriptionMap(descriptionMap, locale);
    article.setContent(content);
    article.setType(type);
    article.setStructureId(structureId);
    article.setTemplateId(templateId);
    article.setLayoutUuid(layoutUuid);
    article.setDisplayDate(displayDate);
    article.setExpirationDate(expirationDate);
    article.setReviewDate(reviewDate);
    article.setIndexable(indexable);
    article.setSmallImage(smallImage);
    article.setSmallImageId(counterLocalService.increment());
    article.setSmallImageURL(smallImageURL);

    if ((expirationDate == null) || expirationDate.after(now)) {
        article.setStatus(WorkflowConstants.STATUS_DRAFT);
    } else {
        article.setStatus(WorkflowConstants.STATUS_EXPIRED);
    }

    journalArticlePersistence.update(article, false);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addArticleResources(article, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addArticleResources(article, serviceContext.getGroupPermissions(),
                serviceContext.getGuestPermissions());
    }

    // Expando

    ExpandoBridge expandoBridge = article.getExpandoBridge();

    expandoBridge.setAttributes(serviceContext);

    // Small image

    saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes);

    // Asset

    updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds());

    // Message boards

    if (PropsValues.JOURNAL_ARTICLE_COMMENTS_ENABLED) {
        mbMessageLocalService.addDiscussionMessage(userId, article.getUserName(), groupId,
                JournalArticle.class.getName(), resourcePrimKey, WorkflowConstants.ACTION_PUBLISH);
    }

    // Email

    PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

    sendEmail(article, articleURL, preferences, "requested", serviceContext);

    // Workflow

    if (classNameId == 0) {
        WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId,
                JournalArticle.class.getName(), article.getId(), article, serviceContext);

        if (serviceContext.getWorkflowAction() != WorkflowConstants.ACTION_PUBLISH) {

            // Indexer

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

            indexer.reindex(article);
        }
    } else {
        updateStatus(userId, article, WorkflowConstants.STATUS_APPROVED, null, serviceContext);
    }

    return article;
}

From source file:com.liferay.portlet.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

public JournalArticle updateArticle(long userId, long groupId, String articleId, double version,
        Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String type,
        String structureId, String templateId, String layoutUuid, int displayDateMonth, int displayDateDay,
        int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth,
        int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute,
        boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour,
        int reviewDateMinute, boolean neverReview, boolean indexable, boolean smallImage, String smallImageURL,
        File smallImageFile, Map<String, byte[]> images, String articleURL, ServiceContext serviceContext)
        throws PortalException, SystemException {

    // Article//from   w  w w. j  av  a2 s.  c o  m

    User user = userPersistence.findByPrimaryKey(userId);
    articleId = articleId.trim().toUpperCase();

    Date displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
            displayDateMinute, user.getTimeZone(), new ArticleDisplayDateException());

    Date expirationDate = null;

    if (!neverExpire) {
        expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear,
                expirationDateHour, expirationDateMinute, user.getTimeZone(),
                new ArticleExpirationDateException());
    }

    Date now = new Date();

    boolean expired = false;

    if ((expirationDate != null) && expirationDate.before(now)) {
        expired = true;
    }

    Date reviewDate = null;

    if (!neverReview) {
        reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
                reviewDateMinute, user.getTimeZone(), new ArticleReviewDateException());
    }

    byte[] smallImageBytes = null;

    try {
        smallImageBytes = FileUtil.getBytes(smallImageFile);
    } catch (IOException ioe) {
    }

    JournalArticle oldArticle = null;
    double oldVersion = 0;

    boolean incrementVersion = false;

    boolean imported = GetterUtil.getBoolean(serviceContext.getAttribute("imported"));

    if (imported) {
        oldArticle = getArticle(groupId, articleId, version);
        oldVersion = version;

        if (!expired) {
            incrementVersion = true;
        } else {
            return expireArticle(userId, groupId, articleId, version, articleURL, serviceContext);
        }
    } else {
        oldArticle = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY);

        oldVersion = oldArticle.getVersion();

        if ((version > 0) && (version != oldVersion)) {
            throw new ArticleVersionException();
        }

        if (oldArticle.isApproved() || oldArticle.isExpired()) {
            incrementVersion = true;
        }
    }

    validate(user.getCompanyId(), groupId, oldArticle.getClassNameId(), titleMap, content, type, structureId,
            templateId, smallImage, smallImageURL, smallImageFile, smallImageBytes);

    JournalArticle article = null;

    if (incrementVersion) {
        double newVersion = MathUtil.format(oldVersion + 0.1, 1, 1);

        long id = counterLocalService.increment();

        article = journalArticlePersistence.create(id);

        article.setResourcePrimKey(oldArticle.getResourcePrimKey());
        article.setGroupId(oldArticle.getGroupId());
        article.setCompanyId(oldArticle.getCompanyId());
        article.setUserId(user.getUserId());
        article.setUserName(user.getFullName());
        article.setCreateDate(serviceContext.getModifiedDate(now));
        article.setClassNameId(oldArticle.getClassNameId());
        article.setClassPK(oldArticle.getClassPK());
        article.setArticleId(articleId);
        article.setVersion(newVersion);
        article.setSmallImageId(oldArticle.getSmallImageId());
    } else {
        article = oldArticle;
    }

    Locale locale = LocaleUtil.getDefault();

    String defaultLanguageId = GetterUtil.getString(serviceContext.getAttribute("defaultLanguageId"));

    if (Validator.isNotNull(defaultLanguageId)) {
        locale = LocaleUtil.fromLanguageId(defaultLanguageId);
    }

    String title = titleMap.get(locale);

    content = format(user, groupId, articleId, article.getVersion(), incrementVersion, content, structureId,
            images);

    article.setModifiedDate(serviceContext.getModifiedDate(now));
    article.setTitleMap(titleMap, locale);
    article.setUrlTitle(getUniqueUrlTitle(article.getId(), groupId, articleId, title));
    article.setDescriptionMap(descriptionMap, locale);
    article.setContent(content);
    article.setType(type);
    article.setStructureId(structureId);
    article.setTemplateId(templateId);
    article.setLayoutUuid(layoutUuid);
    article.setDisplayDate(displayDate);
    article.setExpirationDate(expirationDate);
    article.setReviewDate(reviewDate);
    article.setIndexable(indexable);
    article.setSmallImage(smallImage);

    if (article.getSmallImageId() == 0) {
        article.setSmallImageId(counterLocalService.increment());
    }

    article.setSmallImageURL(smallImageURL);

    if (oldArticle.isPending()) {
        article.setStatus(oldArticle.getStatus());
    } else if (!expired) {
        article.setStatus(WorkflowConstants.STATUS_DRAFT);
    } else {
        article.setStatus(WorkflowConstants.STATUS_EXPIRED);
    }

    journalArticlePersistence.update(article, false);

    // Asset

    updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds());

    // Expando

    ExpandoBridge expandoBridge = article.getExpandoBridge();

    expandoBridge.setAttributes(serviceContext);

    // Small image

    saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes);

    // Email

    PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

    // Workflow

    if (serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_PUBLISH) {

        sendEmail(article, articleURL, preferences, "requested", serviceContext);

        WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId,
                JournalArticle.class.getName(), article.getId(), article, serviceContext);
    } else if (article.getVersion() == JournalArticleConstants.VERSION_DEFAULT) {

        // Indexer

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

        indexer.reindex(article);
    }

    return article;
}

From source file:com.liferay.portlet.shopping.service.impl.ShoppingOrderLocalServiceImpl.java

License:Open Source License

public ShoppingOrder addLatestOrder(long userId, long groupId) throws PortalException, SystemException {

    // Order/*  w w w. ja v a 2 s. c o  m*/

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

    String number = getNumber();

    ShoppingOrder order = null;

    long orderId = counterLocalService.increment();

    List<ShoppingOrder> pastOrders = shoppingOrderPersistence.findByG_U_PPPS(groupId, userId,
            ShoppingOrderConstants.STATUS_CHECKOUT, 0, 1);

    if (pastOrders.size() > 0) {
        ShoppingOrder pastOrder = pastOrders.get(0);

        order = shoppingOrderPersistence.create(orderId);

        order.setBillingCompany(pastOrder.getBillingCompany());
        order.setBillingStreet(pastOrder.getBillingStreet());
        order.setBillingCity(pastOrder.getBillingCity());
        order.setBillingState(pastOrder.getBillingState());
        order.setBillingZip(pastOrder.getBillingZip());
        order.setBillingCountry(pastOrder.getBillingCountry());
        order.setBillingPhone(pastOrder.getBillingPhone());
        order.setShipToBilling(pastOrder.isShipToBilling());
        order.setShippingCompany(pastOrder.getShippingCompany());
        order.setShippingStreet(pastOrder.getShippingStreet());
        order.setShippingCity(pastOrder.getShippingCity());
        order.setShippingState(pastOrder.getShippingState());
        order.setShippingZip(pastOrder.getShippingZip());
        order.setShippingCountry(pastOrder.getShippingCountry());
        order.setShippingPhone(pastOrder.getShippingPhone());
    } else {
        order = shoppingOrderPersistence.create(orderId);
    }

    order.setGroupId(groupId);
    order.setCompanyId(user.getCompanyId());
    order.setUserId(user.getUserId());
    order.setUserName(user.getFullName());
    order.setCreateDate(now);
    order.setModifiedDate(now);
    order.setNumber(number);
    order.setBillingFirstName(user.getFirstName());
    order.setBillingLastName(user.getLastName());
    order.setBillingEmailAddress(user.getEmailAddress());
    order.setShippingFirstName(user.getFirstName());
    order.setShippingLastName(user.getLastName());
    order.setShippingEmailAddress(user.getEmailAddress());
    order.setCcName(user.getFullName());
    order.setPpPaymentStatus(ShoppingOrderConstants.STATUS_LATEST);
    order.setSendOrderEmail(true);
    order.setSendShippingEmail(true);

    shoppingOrderPersistence.update(order, false);

    // Message boards

    if (PropsValues.SHOPPING_ORDER_COMMENTS_ENABLED) {
        mbMessageLocalService.addDiscussionMessage(userId, order.getUserName(), groupId,
                ShoppingOrder.class.getName(), orderId, WorkflowConstants.ACTION_PUBLISH);
    }

    return order;
}

From source file:com.liferay.portlet.softwarecatalog.service.impl.SCProductEntryLocalServiceImpl.java

License:Open Source License

public SCProductEntry addProductEntry(long userId, String name, String type, String tags,
        String shortDescription, String longDescription, String pageURL, String author, String repoGroupId,
        String repoArtifactId, long[] licenseIds, List<byte[]> thumbnails, List<byte[]> fullImages,
        ServiceContext serviceContext) throws PortalException, SystemException {

    // Product entry

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();
    tags = getTags(tags);//from w  w w.  j  a  v  a2 s .  c o  m
    repoGroupId = repoGroupId.trim().toLowerCase();
    repoArtifactId = repoArtifactId.trim().toLowerCase();
    Date now = new Date();

    validate(0, name, type, shortDescription, pageURL, author, repoGroupId, repoArtifactId, licenseIds,
            thumbnails, fullImages);

    long productEntryId = counterLocalService.increment();

    SCProductEntry productEntry = scProductEntryPersistence.create(productEntryId);

    productEntry.setGroupId(groupId);
    productEntry.setCompanyId(user.getCompanyId());
    productEntry.setUserId(user.getUserId());
    productEntry.setUserName(user.getFullName());
    productEntry.setCreateDate(now);
    productEntry.setModifiedDate(now);
    productEntry.setName(name);
    productEntry.setType(type);
    productEntry.setTags(tags);
    productEntry.setShortDescription(shortDescription);
    productEntry.setLongDescription(longDescription);
    productEntry.setPageURL(pageURL);
    productEntry.setAuthor(author);
    productEntry.setRepoGroupId(repoGroupId);
    productEntry.setRepoArtifactId(repoArtifactId);

    scProductEntryPersistence.update(productEntry, false);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addProductEntryResources(productEntry, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addProductEntryResources(productEntry, serviceContext.getGroupPermissions(),
                serviceContext.getGuestPermissions());
    }

    // Licenses

    scProductEntryPersistence.setSCLicenses(productEntryId, licenseIds);

    // Product screenshots

    saveProductScreenshots(productEntry, thumbnails, fullImages);

    // Message boards

    if (PropsValues.SC_PRODUCT_COMMENTS_ENABLED) {
        mbMessageLocalService.addDiscussionMessage(userId, productEntry.getUserName(), groupId,
                SCProductEntry.class.getName(), productEntryId, WorkflowConstants.ACTION_PUBLISH);
    }

    // Indexer

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

    indexer.reindex(productEntry);

    return productEntry;
}