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.journal.service.test.JournalArticleServiceTest.java

License:Open Source License

@Test
public void testGetGroupArticlesWhenUserNotNullAndStatusApproved() throws Exception {

    List<JournalArticle> expectedArticles = addArticles(2, RandomTestUtil.randomString());

    expectedArticles.add(0, _article);/*from   w  w  w .  ja  v a 2s .c  o m*/

    _article = updateArticleStatus(_article, WorkflowConstants.STATUS_DRAFT);

    int count = JournalArticleServiceUtil.getGroupArticlesCount(_group.getGroupId(), _article.getUserId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, WorkflowConstants.STATUS_APPROVED);

    Assert.assertEquals(3, count);

    List<JournalArticle> articles = JournalArticleServiceUtil.getGroupArticles(_group.getGroupId(),
            _article.getUserId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            WorkflowConstants.STATUS_APPROVED, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    Assert.assertEquals(expectedArticles, articles);
}

From source file:com.liferay.journal.service.test.JournalArticleServiceTest.java

License:Open Source License

@Test
public void testGetGroupArticlesWhenUserNullAndStatusAny() throws Exception {

    List<JournalArticle> expectedArticles = addArticles(2, RandomTestUtil.randomString());

    _article = updateArticleStatus(_article, WorkflowConstants.STATUS_DRAFT);

    expectedArticles.add(_article);/*from  w ww .  j  a  v a  2s. co m*/

    int count = JournalArticleServiceUtil.getGroupArticlesCount(_group.getGroupId(), 0,
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    Assert.assertEquals(3, count);

    List<JournalArticle> articles = JournalArticleServiceUtil.getGroupArticles(_group.getGroupId(), 0,
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    Assert.assertEquals(expectedArticles, articles);
}

From source file:com.liferay.journal.service.test.JournalArticleServiceTest.java

License:Open Source License

@Test
public void testGetGroupArticlesWhenUserNullAndStatusApproved() throws Exception {

    List<JournalArticle> expectedArticles = addArticles(2, RandomTestUtil.randomString());

    expectedArticles.add(0, _article);/*from ww  w . jav a 2 s .  c o m*/

    _article = updateArticleStatus(_article, WorkflowConstants.STATUS_DRAFT);

    int count = JournalArticleServiceUtil.getGroupArticlesCount(_group.getGroupId(), 0,
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, WorkflowConstants.STATUS_APPROVED);

    Assert.assertEquals(3, count);

    List<JournalArticle> articles = JournalArticleServiceUtil.getGroupArticles(_group.getGroupId(), 0,
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, WorkflowConstants.STATUS_APPROVED,
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    Assert.assertEquals(expectedArticles, articles);
}

From source file:com.liferay.journal.service.test.JournalArticleServiceTest.java

License:Open Source License

@Test
public void testSearchArticlesByKeywordAndStatus() throws Exception {
    List<JournalArticle> initialArticles = createArticlesWithKeyword(2);

    updateArticleStatus(initialArticles.get(0), WorkflowConstants.STATUS_DRAFT);

    int count = countArticlesByKeyword(_keyword, WorkflowConstants.STATUS_APPROVED);

    Assert.assertEquals(2, count);//  w w w .  j av a2s  . c  o m

    List<JournalArticle> articles = searchArticlesByKeyword(_keyword, WorkflowConstants.STATUS_APPROVED);

    Assert.assertEquals(initialArticles, articles);
}

From source file:com.liferay.journal.service.test.JournalArticleServiceTest.java

License:Open Source License

protected JournalArticle updateArticleStatus(JournalArticle article, int status) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    if (status == WorkflowConstants.STATUS_DRAFT) {
        serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
    } else {//  w ww  .  j a  v a 2 s .  co m
        serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
    }

    return JournalTestUtil.updateArticle(article, "Version 2", article.getContent(), false, true,
            serviceContext);
}

From source file:com.liferay.journal.trash.test.JournalFolderTrashHandlerTest.java

License:Open Source License

@Override
public BaseModel<?> updateBaseModel(long primaryKey, ServiceContext serviceContext) throws Exception {

    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(primaryKey);

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

        folder = JournalFolderLocalServiceUtil.updateStatus(TestPropsValues.getUserId(), folder,
                WorkflowConstants.STATUS_DRAFT);
    }/*ww  w.j  av  a2s. co  m*/

    return folder;
}

From source file:com.liferay.journal.verify.JournalServiceVerifyProcess.java

License:Open Source License

protected void verifyArticleAssets() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer()) {
        List<JournalArticle> journalArticles = _journalArticleLocalService.getNoAssetArticles();

        if (_log.isDebugEnabled()) {
            _log.debug("Processing " + journalArticles.size() + " articles with no asset");
        }/*from  w w w .  j  a v a 2 s  .  co  m*/

        for (JournalArticle journalArticle : journalArticles) {
            try {
                _journalArticleLocalService.updateAsset(journalArticle.getUserId(), journalArticle, null, null,
                        null, null);
            } catch (Exception e) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Unable to update asset for article " + journalArticle.getId() + ": "
                            + e.getMessage());
                }
            }
        }

        ActionableDynamicQuery actionableDynamicQuery = _journalArticleLocalService.getActionableDynamicQuery();

        actionableDynamicQuery.setAddCriteriaMethod(new ActionableDynamicQuery.AddCriteriaMethod() {

            @Override
            public void addCriteria(DynamicQuery dynamicQuery) {
                Property versionProperty = PropertyFactoryUtil.forName("version");

                dynamicQuery.add(versionProperty.eq(JournalArticleConstants.VERSION_DEFAULT));

                Property statusProperty = PropertyFactoryUtil.forName("status");

                dynamicQuery.add(statusProperty.eq(WorkflowConstants.STATUS_DRAFT));
            }

        });

        if (_log.isDebugEnabled()) {
            long count = actionableDynamicQuery.performCount();

            _log.debug("Processing " + count + " default article versions in draft mode");
        }

        actionableDynamicQuery
                .setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<JournalArticle>() {

                    @Override
                    public void performAction(JournalArticle article) throws PortalException {

                        AssetEntry assetEntry = _assetEntryLocalService
                                .fetchEntry(JournalArticle.class.getName(), article.getResourcePrimKey());

                        boolean listable = _journalArticleLocalService.isListable(article);

                        _assetEntryLocalService.updateEntry(assetEntry.getClassName(), assetEntry.getClassPK(),
                                null, null, listable, assetEntry.isVisible());
                    }

                });

        actionableDynamicQuery.performActions();

        if (_log.isDebugEnabled()) {
            _log.debug("Assets verified for articles");
        }

        updateCreateAndModifiedDates();
        updateResourcePrimKey();
    }
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public List<ManagementBarFilterItem> getManagementBarStatusFilterItems()
        throws PortalException, PortletException {

    List<ManagementBarFilterItem> managementBarFilterItems = new ArrayList<>();

    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_ANY));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_DRAFT));

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

    int workflowDefinitionLinksCount = WorkflowDefinitionLinkLocalServiceUtil.getWorkflowDefinitionLinksCount(
            themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), JournalFolder.class.getName());

    if (workflowDefinitionLinksCount > 0) {
        managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_PENDING));
        managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_DENIED));
    }//from   ww  w. java  2 s  . com

    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_SCHEDULED));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_APPROVED));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_EXPIRED));

    return managementBarFilterItems;
}

From source file:com.liferay.knowledgebase.service.impl.KBArticleLocalServiceImpl.java

License:Open Source License

@Override
public KBArticle addKBArticle(long userId, long parentResourceClassNameId, long parentResourcePrimKey,
        String title, String urlTitle, String content, String description, String sourceURL, String[] sections,
        String[] selectedFileNames, ServiceContext serviceContext) throws PortalException {

    // KB article

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();
    double priority = getPriority(groupId, parentResourcePrimKey);
    Date now = new Date();

    validate(title, content, sourceURL);
    validateParent(parentResourceClassNameId, parentResourcePrimKey);

    long kbFolderId = KnowledgeBaseUtil.getKBFolderId(parentResourceClassNameId, parentResourcePrimKey);

    validateUrlTitle(groupId, kbFolderId, urlTitle);

    long kbArticleId = counterLocalService.increment();

    long resourcePrimKey = counterLocalService.increment();

    long rootResourcePrimKey = getRootResourcePrimKey(resourcePrimKey, parentResourceClassNameId,
            parentResourcePrimKey);/*w  w  w.j  ava2  s . c  o  m*/

    KBArticle kbArticle = kbArticlePersistence.create(kbArticleId);

    kbArticle.setUuid(serviceContext.getUuid());
    kbArticle.setResourcePrimKey(resourcePrimKey);
    kbArticle.setGroupId(groupId);
    kbArticle.setCompanyId(user.getCompanyId());
    kbArticle.setUserId(user.getUserId());
    kbArticle.setUserName(user.getFullName());
    kbArticle.setCreateDate(serviceContext.getCreateDate(now));
    kbArticle.setModifiedDate(serviceContext.getModifiedDate(now));
    kbArticle.setRootResourcePrimKey(rootResourcePrimKey);
    kbArticle.setParentResourceClassNameId(parentResourceClassNameId);
    kbArticle.setParentResourcePrimKey(parentResourcePrimKey);
    kbArticle.setKbFolderId(kbFolderId);
    kbArticle.setVersion(KBArticleConstants.DEFAULT_VERSION);
    kbArticle.setTitle(title);
    kbArticle.setUrlTitle(getUniqueUrlTitle(groupId, kbFolderId, kbArticleId, title, urlTitle));
    kbArticle.setContent(content);
    kbArticle.setDescription(description);
    kbArticle.setPriority(priority);
    kbArticle.setSections(StringUtil.merge(AdminUtil.escapeSections(sections)));
    kbArticle.setViewCount(0);
    kbArticle.setLatest(true);
    kbArticle.setMain(false);
    kbArticle.setStatus(WorkflowConstants.STATUS_DRAFT);
    kbArticle.setSourceURL(sourceURL);

    kbArticlePersistence.update(kbArticle);

    // Resources

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

        addKBArticleResources(kbArticle, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addKBArticleResources(kbArticle, serviceContext.getGroupPermissions(),
                serviceContext.getGuestPermissions());
    }

    // Asset

    updateKBArticleAsset(userId, kbArticle, serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());

    // Attachments

    addKBArticleAttachments(userId, kbArticle, selectedFileNames);

    // Workflow

    WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId,
            KBArticle.class.getName(), resourcePrimKey, kbArticle, serviceContext);

    return kbArticle;
}

From source file:com.liferay.knowledgebase.service.impl.KBArticleLocalServiceImpl.java

License:Open Source License

@Override
public KBArticle updateKBArticle(long userId, long resourcePrimKey, String title, String content,
        String description, String sourceURL, String[] sections, String[] selectedFileNames,
        long[] removeFileEntryIds, ServiceContext serviceContext) throws PortalException {

    // KB article

    User user = userPersistence.findByPrimaryKey(userId);

    validate(title, content, sourceURL);

    KBArticle oldKBArticle = getLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);

    int oldVersion = oldKBArticle.getVersion();

    KBArticle kbArticle = null;//from   w  w  w .j a  v  a  2  s  . c  o  m

    if (oldKBArticle.isApproved()) {
        long kbArticleId = counterLocalService.increment();

        kbArticle = kbArticlePersistence.create(kbArticleId);

        kbArticle.setUuid(serviceContext.getUuid());
        kbArticle.setResourcePrimKey(oldKBArticle.getResourcePrimKey());
        kbArticle.setGroupId(oldKBArticle.getGroupId());
        kbArticle.setCompanyId(user.getCompanyId());
        kbArticle.setUserId(user.getUserId());
        kbArticle.setUserName(user.getFullName());
        kbArticle.setCreateDate(oldKBArticle.getCreateDate());
        kbArticle.setRootResourcePrimKey(oldKBArticle.getRootResourcePrimKey());
        kbArticle.setParentResourceClassNameId(oldKBArticle.getParentResourceClassNameId());
        kbArticle.setParentResourcePrimKey(oldKBArticle.getParentResourcePrimKey());
        kbArticle.setKbFolderId(oldKBArticle.getKbFolderId());
        kbArticle.setVersion(oldVersion + 1);
        kbArticle.setUrlTitle(oldKBArticle.getUrlTitle());
        kbArticle.setPriority(oldKBArticle.getPriority());
        kbArticle.setViewCount(oldKBArticle.getViewCount());
    } else {
        kbArticle = oldKBArticle;
    }

    if (oldKBArticle.isPending()) {
        kbArticle.setStatus(WorkflowConstants.STATUS_PENDING);
    } else {
        kbArticle.setStatus(WorkflowConstants.STATUS_DRAFT);
    }

    kbArticle.setModifiedDate(serviceContext.getModifiedDate(null));
    kbArticle.setTitle(title);
    kbArticle.setContent(content);
    kbArticle.setDescription(description);
    kbArticle.setSourceURL(sourceURL);
    kbArticle.setSections(StringUtil.merge(AdminUtil.escapeSections(sections)));
    kbArticle.setLatest(true);
    kbArticle.setMain(false);

    kbArticlePersistence.update(kbArticle);

    if (oldKBArticle.isApproved()) {
        oldKBArticle.setLatest(false);

        kbArticlePersistence.update(oldKBArticle);
    }

    // Resources

    if ((serviceContext.getGroupPermissions() != null) || (serviceContext.getGuestPermissions() != null)) {

        updateKBArticleResources(kbArticle, serviceContext.getGroupPermissions(),
                serviceContext.getGuestPermissions());
    }

    // Asset

    updateKBArticleAsset(userId, kbArticle, serviceContext.getAssetCategoryIds(),
            serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());

    // Attachments

    addKBArticleAttachments(userId, kbArticle, selectedFileNames);

    removeKBArticleAttachments(removeFileEntryIds);

    // Workflow

    WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), kbArticle.getGroupId(), userId,
            KBArticle.class.getName(), resourcePrimKey, kbArticle, serviceContext);

    return kbArticle;
}