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

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

Introduction

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

Prototype

int STATUS_DRAFT

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

Click Source Link

Usage

From source file:com.liferay.portlet.directory.workflow.UserWorkflowHandler.java

License:Open Source License

public Object updateStatus(int status, Map<String, Serializable> workflowContext)
        throws PortalException, SystemException {

    long userId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));

    ServiceContext serviceContext = (ServiceContext) workflowContext
            .get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);

    User user = UserLocalServiceUtil.getUser(userId);

    if (((user.getStatus() == WorkflowConstants.STATUS_DRAFT)
            || (user.getStatus() == WorkflowConstants.STATUS_PENDING))
            && (status == WorkflowConstants.STATUS_APPROVED)) {

        UserLocalServiceUtil.completeUserRegistration(user, serviceContext);

        serviceContext.setAttribute("passwordUnencrypted", user.getPasswordUnencrypted());
    }//from   www  . j  ava 2s  .c  om

    return UserLocalServiceUtil.updateStatus(userId, status);
}

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

License:Open Source License

public DLFileEntry addFileEntry(long userId, long groupId, long repositoryId, long folderId,
        String sourceFileName, String mimeType, String title, String description, String changeLog,
        long fileEntryTypeId, Map<String, Fields> fieldsMap, File file, InputStream is, long size,
        ServiceContext serviceContext) throws PortalException, SystemException {

    if ((size == 0) && Validator.isNull(title)) {
        throw new FileNameException();
    }//from  ww w  .j  a  v  a2 s  .c  o  m

    // File entry

    User user = userPersistence.findByPrimaryKey(userId);
    folderId = dlFolderLocalService.getFolderId(user.getCompanyId(), folderId);
    String name = String.valueOf(counterLocalService.increment(DLFileEntry.class.getName()));
    String extension = getExtension(title, sourceFileName);
    fileEntryTypeId = getFileEntryTypeId(DLUtil.getGroupIds(groupId), folderId, fileEntryTypeId);
    Date now = new Date();

    validateFile(groupId, folderId, title, extension, file, is);

    long fileEntryId = counterLocalService.increment();

    DLFileEntry dlFileEntry = dlFileEntryPersistence.create(fileEntryId);

    dlFileEntry.setUuid(serviceContext.getUuid());
    dlFileEntry.setGroupId(groupId);
    dlFileEntry.setCompanyId(user.getCompanyId());
    dlFileEntry.setUserId(user.getUserId());
    dlFileEntry.setUserName(user.getFullName());
    dlFileEntry.setVersionUserId(user.getUserId());
    dlFileEntry.setVersionUserName(user.getFullName());
    dlFileEntry.setCreateDate(serviceContext.getCreateDate(now));
    dlFileEntry.setModifiedDate(serviceContext.getModifiedDate(now));
    dlFileEntry.setRepositoryId(repositoryId);
    dlFileEntry.setFolderId(folderId);
    dlFileEntry.setName(name);
    dlFileEntry.setExtension(extension);
    dlFileEntry.setMimeType(mimeType);
    dlFileEntry.setTitle(title);
    dlFileEntry.setDescription(description);
    dlFileEntry.setFileEntryTypeId(fileEntryTypeId);
    dlFileEntry.setVersion(DLFileEntryConstants.VERSION_DEFAULT);
    dlFileEntry.setSize(size);
    dlFileEntry.setReadCount(DLFileEntryConstants.DEFAULT_READ_COUNT);

    dlFileEntryPersistence.update(dlFileEntry, false);

    // File version

    DLFileVersion dlFileVersion = addFileVersion(user, dlFileEntry, serviceContext.getModifiedDate(now),
            extension, mimeType, title, description, null, StringPool.BLANK, fileEntryTypeId, fieldsMap,
            DLFileEntryConstants.VERSION_DEFAULT, size, WorkflowConstants.STATUS_DRAFT, serviceContext);

    dlFileEntry.setFileVersion(dlFileVersion);

    // Folder

    if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        dlFolderLocalService.updateLastPostDate(dlFileEntry.getFolderId(), dlFileEntry.getModifiedDate());
    }

    // File

    if (file != null) {
        DLStoreUtil.addFile(user.getCompanyId(), dlFileEntry.getDataRepositoryId(), name, false, file);
    } else {
        DLStoreUtil.addFile(user.getCompanyId(), dlFileEntry.getDataRepositoryId(), name, false, is);
    }

    return dlFileEntry;
}

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

License:Open Source License

public DLFileEntry checkOutFileEntry(long userId, long fileEntryId, String owner, long expirationTime)
        throws PortalException, SystemException {

    DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(fileEntryId);

    boolean hasLock = hasFileEntryLock(userId, fileEntryId);

    if (!hasLock) {
        if ((expirationTime <= 0) || (expirationTime > DLFileEntryImpl.LOCK_EXPIRATION_TIME)) {

            expirationTime = DLFileEntryImpl.LOCK_EXPIRATION_TIME;
        }/*w  ww .jav  a  2s.c om*/

        lockLocalService.lock(userId, DLFileEntry.class.getName(), fileEntryId, owner, false, expirationTime);
    }

    User user = userPersistence.findByPrimaryKey(userId);

    dlFileEntryPersistence.update(dlFileEntry, false);

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

    long dlFileVersionId = dlFileVersion.getFileVersionId();

    String version = dlFileVersion.getVersion();

    if (!version.equals(DLFileEntryConstants.PRIVATE_WORKING_COPY_VERSION)) {

        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setCompanyId(user.getCompanyId());
        serviceContext.setUserId(userId);

        dlFileVersion = addFileVersion(user, dlFileEntry, new Date(), dlFileVersion.getExtension(),
                dlFileVersion.getMimeType(), dlFileVersion.getTitle(), dlFileVersion.getDescription(),
                dlFileVersion.getChangeLog(), dlFileVersion.getExtraSettings(),
                dlFileVersion.getFileEntryTypeId(), null, DLFileEntryConstants.PRIVATE_WORKING_COPY_VERSION,
                dlFileVersion.getSize(), WorkflowConstants.STATUS_DRAFT, serviceContext);

        try {
            DLStoreUtil.deleteFile(dlFileEntry.getCompanyId(), dlFileEntry.getDataRepositoryId(),
                    dlFileEntry.getName(), DLFileEntryConstants.PRIVATE_WORKING_COPY_VERSION);
        } catch (NoSuchFileException nsfe) {
        }

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

        copyFileEntryMetadata(dlFileEntry.getCompanyId(), dlFileVersion.getFileEntryTypeId(), fileEntryId,
                dlFileVersionId, dlFileVersion.getFileVersionId(), serviceContext);
    }

    return dlFileEntry;
}

From source file:com.liferay.portlet.dynamicdatalists.service.impl.DDLRecordLocalServiceImpl.java

License:Open Source License

public DDLRecord addRecord(long userId, long groupId, long recordSetId, int displayIndex, Fields fields,
        ServiceContext serviceContext) throws PortalException, SystemException {

    // Record/*from  w  w  w  .j a  va2  s. com*/

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

    DDLRecordSet recordSet = ddlRecordSetPersistence.findByPrimaryKey(recordSetId);

    long recordId = counterLocalService.increment();

    DDLRecord record = ddlRecordPersistence.create(recordId);

    record.setUuid(serviceContext.getUuid());
    record.setGroupId(groupId);
    record.setCompanyId(user.getCompanyId());
    record.setUserId(user.getUserId());
    record.setUserName(user.getFullName());
    record.setVersionUserId(user.getUserId());
    record.setVersionUserName(user.getFullName());
    record.setCreateDate(serviceContext.getCreateDate(now));
    record.setModifiedDate(serviceContext.getModifiedDate(now));

    long ddmStorageId = StorageEngineUtil.create(recordSet.getCompanyId(), recordSet.getDDMStructureId(),
            fields, serviceContext);

    record.setDDMStorageId(ddmStorageId);

    record.setRecordSetId(recordSetId);
    record.setVersion(DDLRecordConstants.VERSION_DEFAULT);
    record.setDisplayIndex(displayIndex);

    ddlRecordPersistence.update(record, false);

    // Record version

    DDLRecordVersion recordVersion = addRecordVersion(user, record, ddmStorageId,
            DDLRecordConstants.VERSION_DEFAULT, displayIndex, WorkflowConstants.STATUS_DRAFT);

    // Asset

    Locale locale = serviceContext.getLocale();

    updateAsset(userId, record, recordVersion, serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames(), locale);

    // Workflow

    WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId,
            DDLRecord.class.getName(), recordVersion.getRecordVersionId(), recordVersion, serviceContext);

    return record;
}

From source file:com.liferay.portlet.dynamicdatalists.service.impl.DDLRecordLocalServiceImpl.java

License:Open Source License

public DDLRecord updateRecord(long userId, long recordId, boolean majorVersion, int displayIndex, Fields fields,
        boolean mergeFields, ServiceContext serviceContext) throws PortalException, SystemException {

    // Record/*  w  w  w  .jav a  2  s.c  o m*/

    User user = userPersistence.findByPrimaryKey(userId);

    DDLRecord record = ddlRecordPersistence.findByPrimaryKey(recordId);

    record.setModifiedDate(serviceContext.getModifiedDate(null));

    ddlRecordPersistence.update(record, false);

    // Record version

    DDLRecordVersion recordVersion = record.getLatestRecordVersion();

    if (recordVersion.isApproved()) {
        DDLRecordSet recordSet = record.getRecordSet();

        long ddmStorageId = StorageEngineUtil.create(recordSet.getCompanyId(), recordSet.getDDMStructureId(),
                fields, serviceContext);
        String version = getNextVersion(recordVersion.getVersion(), majorVersion,
                serviceContext.getWorkflowAction());

        recordVersion = addRecordVersion(user, record, ddmStorageId, version, displayIndex,
                WorkflowConstants.STATUS_DRAFT);
    } else {
        StorageEngineUtil.update(recordVersion.getDDMStorageId(), fields, mergeFields, serviceContext);

        String version = recordVersion.getVersion();

        updateRecordVersion(user, recordVersion, version, displayIndex, recordVersion.getStatus(),
                serviceContext);
    }

    // Workflow

    WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), record.getGroupId(), userId,
            DDLRecord.class.getName(), recordVersion.getRecordVersionId(), recordVersion, serviceContext);

    return record;
}

From source file:com.liferay.portlet.journal.search.ArticleSearchTerms.java

License:Open Source License

public int getStatusCode() {
    if (status.equals("approved")) {
        return WorkflowConstants.STATUS_APPROVED;
    } else if (status.equals("draft")) {
        return WorkflowConstants.STATUS_DRAFT;
    } else if (status.equals("expired")) {
        return WorkflowConstants.STATUS_EXPIRED;
    } else if (status.equals("pending")) {
        return WorkflowConstants.STATUS_PENDING;
    } else {/*from  ww w  .j  a v a 2s.com*/
        return WorkflowConstants.STATUS_ANY;
    }
}

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/*from   ww 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  .  ja  v a  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 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.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

public JournalArticle updateArticleTranslation(long groupId, String articleId, double version, Locale locale,
        String title, String description, String content, Map<String, byte[]> images)
        throws PortalException, SystemException {

    validateContent(content);//from ww w . j  ava 2 s.c o  m

    JournalArticle oldArticle = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY);

    double oldVersion = oldArticle.getVersion();

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

    JournalArticle article = null;

    User user = userService.getUserById(oldArticle.getUserId());

    if (!oldArticle.isDraft()) {
        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(oldArticle.getUserId());
        article.setUserName(user.getFullName());
        article.setCreateDate(new Date());
        article.setModifiedDate(new Date());
        article.setClassNameId(oldArticle.getClassNameId());
        article.setClassPK(oldArticle.getClassPK());
        article.setArticleId(articleId);
        article.setVersion(newVersion);
        article.setTitleMap(oldArticle.getTitleMap());
        article.setUrlTitle(getUniqueUrlTitle(article.getId(), groupId, articleId, title));
        article.setDescriptionMap(oldArticle.getDescriptionMap());
        article.setType(oldArticle.getType());
        article.setStructureId(oldArticle.getStructureId());
        article.setTemplateId(oldArticle.getTemplateId());
        article.setLayoutUuid(oldArticle.getLayoutUuid());
        article.setDisplayDate(oldArticle.getDisplayDate());
        article.setExpirationDate(oldArticle.getExpirationDate());
        article.setReviewDate(oldArticle.getReviewDate());
        article.setIndexable(oldArticle.getIndexable());
        article.setSmallImage(oldArticle.getSmallImage());
        article.setSmallImageId(oldArticle.getSmallImageId());

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

        article.setSmallImageURL(oldArticle.getSmallImageURL());

        article.setStatus(WorkflowConstants.STATUS_DRAFT);
        article.setStatusDate(new Date());
    } else {
        article = oldArticle;
    }

    Map<Locale, String> titleMap = article.getTitleMap();

    titleMap.put(locale, title);

    article.setTitleMap(titleMap);

    Map<Locale, String> descriptionMap = article.getDescriptionMap();

    descriptionMap.put(locale, description);

    article.setDescriptionMap(descriptionMap);

    content = format(user, groupId, articleId, version, !oldArticle.isDraft(), content,
            oldArticle.getStructureId(), images);

    article.setContent(content);

    journalArticlePersistence.update(article, false);

    return article;
}

From source file:com.liferay.portlet.journal.util.JournalIndexer.java

License:Open Source License

protected void reindexArticles(long companyId, int start, int end) throws Exception {

    List<JournalArticle> articles = new ArrayList<JournalArticle>();

    List<JournalArticle> approvedArticles = JournalArticleLocalServiceUtil.getCompanyArticles(companyId,
            WorkflowConstants.STATUS_APPROVED, start, end);

    articles.addAll(approvedArticles);//from   www  .  j  a  va  2s.c  o  m

    List<JournalArticle> draftArticles = JournalArticleLocalServiceUtil.getCompanyArticles(companyId,
            JournalArticleConstants.VERSION_DEFAULT, WorkflowConstants.STATUS_DRAFT, start, end);

    articles.addAll(draftArticles);

    if (articles.isEmpty()) {
        return;
    }

    Collection<Document> documents = new ArrayList<Document>();

    for (JournalArticle article : articles) {
        if (!article.isIndexable()) {
            continue;
        }

        if (article.isApproved()) {
            JournalArticle latestArticle = JournalArticleLocalServiceUtil
                    .getLatestArticle(article.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);

            if (!latestArticle.isIndexable()) {
                continue;
            }
        }

        Document document = getDocument(article);

        documents.add(document);
    }

    SearchEngineUtil.updateDocuments(companyId, documents);
}