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.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

@Override
public List<JournalFolder> getFolders(long groupId, long parentFolderId) {
    return getFolders(groupId, parentFolderId, WorkflowConstants.STATUS_APPROVED);
}

From source file:com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

@Override
public List<JournalFolder> getFolders(long groupId, long parentFolderId, int start, int end) {

    return getFolders(groupId, parentFolderId, WorkflowConstants.STATUS_APPROVED, start, end);
}

From source file:com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

@Override
public JournalFolder moveFolderFromTrash(long userId, long folderId, long parentFolderId,
        ServiceContext serviceContext) throws PortalException {

    JournalFolder folder = journalFolderPersistence.findByPrimaryKey(folderId);

    if (!folder.isInTrash()) {
        throw new RestoreEntryException(RestoreEntryException.INVALID_STATUS);
    }/*  w ww  .j av  a  2s .  c o m*/

    if (folder.isInTrashExplicitly()) {
        restoreFolderFromTrash(userId, folderId);
    } else {

        // Folder

        TrashVersion trashVersion = trashVersionLocalService.fetchVersion(JournalFolder.class.getName(),
                folderId);

        int status = WorkflowConstants.STATUS_APPROVED;

        if (trashVersion != null) {
            status = trashVersion.getStatus();
        }

        updateStatus(userId, folder, status);

        // Trash

        if (trashVersion != null) {
            trashVersionLocalService.deleteTrashVersion(trashVersion);
        }

        // Folders and articles

        List<Object> foldersAndArticles = journalFolderLocalService.getFoldersAndArticles(folder.getGroupId(),
                folder.getFolderId(), WorkflowConstants.STATUS_IN_TRASH);

        restoreDependentsFromTrash(foldersAndArticles);
    }

    return journalFolderLocalService.moveFolder(folderId, parentFolderId, serviceContext);
}

From source file:com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override/*from   www  .  j  a v a2  s .co m*/
public JournalFolder moveFolderToTrash(long userId, long folderId) throws PortalException {

    // Folder

    JournalFolder folder = journalFolderPersistence.findByPrimaryKey(folderId);

    if (folder.isInTrash()) {
        throw new TrashEntryException();
    }

    String title = folder.getName();

    folder = updateStatus(userId, folder, WorkflowConstants.STATUS_IN_TRASH);

    // Trash

    UnicodeProperties typeSettingsProperties = new UnicodeProperties();

    typeSettingsProperties.put("title", folder.getName());

    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, folder.getGroupId(),
            JournalFolder.class.getName(), folder.getFolderId(), folder.getUuid(), null,
            WorkflowConstants.STATUS_APPROVED, null, typeSettingsProperties);

    folder.setName(TrashUtil.getTrashTitle(trashEntry.getEntryId()));

    journalFolderPersistence.update(folder);

    // Folders and articles

    List<Object> foldersAndArticles = journalFolderLocalService.getFoldersAndArticles(folder.getGroupId(),
            folder.getFolderId());

    moveDependentsToTrash(foldersAndArticles, trashEntry.getEntryId());

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", title);

    SocialActivityManagerUtil.addActivity(userId, folder, SocialActivityConstants.TYPE_MOVE_TO_TRASH,
            extraDataJSONObject.toString(), 0);

    return folder;
}

From source file:com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

@Override
public JournalFolder updateStatus(long userId, JournalFolder folder, int status) throws PortalException {

    // Folder//from  w  w w  .  j av  a2 s. c om

    User user = userLocalService.getUser(userId);

    folder.setStatus(status);
    folder.setStatusByUserId(userId);
    folder.setStatusByUserName(user.getFullName());
    folder.setStatusDate(new Date());

    journalFolderPersistence.update(folder);

    // Asset

    if (status == WorkflowConstants.STATUS_APPROVED) {
        assetEntryLocalService.updateVisible(JournalFolder.class.getName(), folder.getFolderId(), true);
    } else if (status == WorkflowConstants.STATUS_IN_TRASH) {
        assetEntryLocalService.updateVisible(JournalFolder.class.getName(), folder.getFolderId(), false);
    }

    // Indexer

    Indexer<JournalFolder> indexer = IndexerRegistryUtil.nullSafeGetIndexer(JournalFolder.class);

    indexer.reindex(folder);

    return folder;
}

From source file:com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

protected void moveDependentsToTrash(List<Object> foldersAndArticles, long trashEntryId)
        throws PortalException {

    for (Object object : foldersAndArticles) {
        if (object instanceof JournalArticle) {

            // Article

            JournalArticle article = (JournalArticle) object;

            if (article.getStatus() == WorkflowConstants.STATUS_IN_TRASH) {
                continue;
            }// ww  w  .  jav a  2  s  .  c o  m

            // Articles

            List<JournalArticle> articles = journalArticlePersistence.findByG_A(article.getGroupId(),
                    article.getArticleId());

            for (JournalArticle curArticle : articles) {

                // Article

                int curArticleOldStatus = curArticle.getStatus();

                curArticle.setStatus(WorkflowConstants.STATUS_IN_TRASH);

                journalArticlePersistence.update(curArticle);

                // Trash

                int status = curArticleOldStatus;

                if (curArticleOldStatus == WorkflowConstants.STATUS_PENDING) {

                    status = WorkflowConstants.STATUS_DRAFT;
                }

                if (curArticleOldStatus != WorkflowConstants.STATUS_APPROVED) {

                    trashVersionLocalService.addTrashVersion(trashEntryId, JournalArticle.class.getName(),
                            curArticle.getId(), status, null);
                }

                // Workflow

                if (curArticleOldStatus == WorkflowConstants.STATUS_PENDING) {

                    workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(curArticle.getCompanyId(),
                            curArticle.getGroupId(), JournalArticle.class.getName(), curArticle.getId());
                }
            }

            // Asset

            assetEntryLocalService.updateVisible(JournalArticle.class.getName(), article.getResourcePrimKey(),
                    false);

            // Indexer

            Indexer<JournalArticle> indexer = IndexerRegistryUtil.nullSafeGetIndexer(JournalArticle.class);

            indexer.reindex(article);
        } else if (object instanceof JournalFolder) {

            // Folder

            JournalFolder folder = (JournalFolder) object;

            if (folder.isInTrashExplicitly()) {
                continue;
            }

            int oldStatus = folder.getStatus();

            folder.setStatus(WorkflowConstants.STATUS_IN_TRASH);

            journalFolderPersistence.update(folder);

            // Trash

            if (oldStatus != WorkflowConstants.STATUS_APPROVED) {
                trashVersionLocalService.addTrashVersion(trashEntryId, JournalFolder.class.getName(),
                        folder.getFolderId(), oldStatus, null);
            }

            // Folders and articles

            List<Object> curFoldersAndArticles = getFoldersAndArticles(folder.getGroupId(),
                    folder.getFolderId());

            moveDependentsToTrash(curFoldersAndArticles, trashEntryId);

            // Asset

            assetEntryLocalService.updateVisible(JournalFolder.class.getName(), folder.getFolderId(), false);

            // Indexer

            Indexer<JournalFolder> indexer = IndexerRegistryUtil.nullSafeGetIndexer(JournalFolder.class);

            indexer.reindex(folder);
        }
    }
}

From source file:com.liferay.journal.service.impl.JournalFolderLocalServiceImpl.java

License:Open Source License

protected void restoreDependentsFromTrash(List<Object> foldersAndArticles) throws PortalException {

    for (Object object : foldersAndArticles) {
        if (object instanceof JournalArticle) {

            // Article

            JournalArticle article = (JournalArticle) object;

            if (!article.isInTrashImplicitly()) {
                continue;
            }//from   w w  w.  ja v a  2s .co m

            TrashVersion trashVersion = trashVersionLocalService.fetchVersion(JournalArticle.class.getName(),
                    article.getId());

            int oldStatus = WorkflowConstants.STATUS_APPROVED;

            if (trashVersion != null) {
                oldStatus = trashVersion.getStatus();
            }

            // Articles

            List<JournalArticle> articles = journalArticlePersistence.findByG_A(article.getGroupId(),
                    article.getArticleId());

            for (JournalArticle curArticle : articles) {

                // Article

                trashVersion = trashVersionLocalService.fetchVersion(JournalArticle.class.getName(),
                        curArticle.getId());

                int curArticleOldStatus = WorkflowConstants.STATUS_APPROVED;

                if (trashVersion != null) {
                    curArticleOldStatus = trashVersion.getStatus();
                }

                curArticle.setStatus(curArticleOldStatus);

                journalArticlePersistence.update(curArticle);

                // Trash

                if (trashVersion != null) {
                    trashVersionLocalService.deleteTrashVersion(trashVersion);
                }
            }

            // Asset

            if (oldStatus == WorkflowConstants.STATUS_APPROVED) {
                assetEntryLocalService.updateVisible(JournalArticle.class.getName(),
                        article.getResourcePrimKey(), true);
            }

            // Indexer

            Indexer<JournalArticle> indexer = IndexerRegistryUtil.nullSafeGetIndexer(JournalArticle.class);

            indexer.reindex(article);
        } else if (object instanceof JournalFolder) {

            // Folder

            JournalFolder folder = (JournalFolder) object;

            if (!folder.isInTrashImplicitly()) {
                continue;
            }

            TrashVersion trashVersion = trashVersionLocalService.fetchVersion(JournalFolder.class.getName(),
                    folder.getFolderId());

            int oldStatus = WorkflowConstants.STATUS_APPROVED;

            if (trashVersion != null) {
                oldStatus = trashVersion.getStatus();
            }

            folder.setStatus(oldStatus);

            journalFolderPersistence.update(folder);

            // Folders and articles

            List<Object> curFoldersAndArticles = getFoldersAndArticles(folder.getGroupId(),
                    folder.getFolderId(), WorkflowConstants.STATUS_IN_TRASH);

            restoreDependentsFromTrash(curFoldersAndArticles);

            // Trash

            if (trashVersion != null) {
                trashVersionLocalService.deleteTrashVersion(trashVersion);
            }

            // Asset

            assetEntryLocalService.updateVisible(JournalFolder.class.getName(), folder.getFolderId(), true);

            // Indexer

            Indexer<JournalFolder> indexer = IndexerRegistryUtil.nullSafeGetIndexer(JournalFolder.class);

            indexer.reindex(folder);
        }
    }
}

From source file:com.liferay.journal.service.persistence.test.JournalArticleFinderTest.java

License:Open Source License

@Test
public void testDraftArticles() throws Exception {
    QueryDefinition<JournalArticle> queryDefinition = new QueryDefinition<>(WorkflowConstants.STATUS_ANY);

    testQueryByG_C(_group.getGroupId(), Collections.<Long>emptyList(),
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, queryDefinition, 2);

    queryDefinition.setOwnerUserId(TestPropsValues.getUserId());

    JournalArticle article = JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(),
            _folder.getFolderId(), JournalArticleConstants.CLASSNAME_ID_DEFAULT, "<title>Article 1</title>",
            _basicWebContentDDMStructure.getStructureKey(), _basicWebContentDDMTemplate.getTemplateKey());

    article.setUserId(_USER_ID);//w w  w .  j  av a2  s. c  o m
    article.setStatus(WorkflowConstants.STATUS_DRAFT);

    JournalArticleLocalServiceUtil.updateJournalArticle(article);

    _articles.add(article);

    queryDefinition.setIncludeOwner(true);
    queryDefinition.setOwnerUserId(_USER_ID);
    queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED);

    testQueryByG_C(_group.getGroupId(), Collections.<Long>emptyList(),
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, queryDefinition, 3);

    queryDefinition.setIncludeOwner(false);

    testQueryByG_C(_group.getGroupId(), Collections.<Long>emptyList(),
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, queryDefinition, 0);
}

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

License:Open Source License

@Test
public void testFetchLatestArticleByApprovedStatusWhenArticleApproved() throws Exception {

    _article = JournalTestUtil.updateArticle(_article, "Version 2");

    _latestArticle = fetchLatestArticle(WorkflowConstants.STATUS_APPROVED);

    Assert.assertEquals("Version 2", _latestArticle.getTitle(LocaleUtil.getDefault()));
    Assert.assertTrue(_latestArticle.isApproved());
    Assert.assertTrue(_latestArticle.getVersion() == 1.1);
}

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

License:Open Source License

@Test
public void testFetchLatestArticleByApprovedStatusWhenArticleExpired() throws Exception {

    updateAndExpireArticle();/*from ww  w .j  av a2  s . co m*/

    _latestArticle = fetchLatestArticle(WorkflowConstants.STATUS_APPROVED);

    Assert.assertNull(_latestArticle);
}