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.portlet.blogs.service.impl.BlogsStatsUserLocalServiceImpl.java

License:Open Source License

public void updateStatsUser(long groupId, long userId, Date displayDate)
        throws PortalException, SystemException {

    Date now = new Date();

    int entryCount = blogsEntryPersistence.countByG_U_LtD_S(groupId, userId, now,
            WorkflowConstants.STATUS_APPROVED);

    if (entryCount == 0) {
        try {/*from w w  w.j  ava 2  s.  c  om*/
            blogsStatsUserPersistence.removeByG_U(groupId, userId);
        } catch (NoSuchStatsUserException nssue) {
        }

        return;
    }

    BlogsStatsUser statsUser = getStatsUser(groupId, userId);

    statsUser.setEntryCount(entryCount);

    BlogsEntry blogsEntry = blogsEntryPersistence.findByG_U_LtD_S_First(groupId, userId, now,
            WorkflowConstants.STATUS_APPROVED, new EntryDisplayDateComparator());

    Date lastDisplayDate = blogsEntry.getDisplayDate();

    Date lastPostDate = statsUser.getLastPostDate();

    if ((displayDate != null) && displayDate.before(now)) {
        if (lastPostDate == null) {
            statsUser.setLastPostDate(displayDate);
        } else if (displayDate.after(lastPostDate)) {
            statsUser.setLastPostDate(displayDate);
        } else if (lastDisplayDate.before(lastPostDate)) {
            statsUser.setLastPostDate(lastDisplayDate);
        }
    } else if (lastDisplayDate.before(lastPostDate)) {
        statsUser.setLastPostDate(lastDisplayDate);
    }

    blogsStatsUserPersistence.update(statsUser, false);
}

From source file:com.liferay.portlet.blogs.util.BlogsIndexer.java

License:Open Source License

protected void reindexEntries(long companyId) throws Exception {
    int count = BlogsEntryLocalServiceUtil.getCompanyEntriesCount(companyId, new Date(),
            WorkflowConstants.STATUS_APPROVED);

    int pages = count / Indexer.DEFAULT_INTERVAL;

    for (int i = 0; i <= pages; i++) {
        int start = (i * Indexer.DEFAULT_INTERVAL);
        int end = start + Indexer.DEFAULT_INTERVAL;

        reindexEntries(companyId, start, end);
    }/*from   w  w  w .java2  s  .  co  m*/
}

From source file:com.liferay.portlet.blogs.util.BlogsIndexer.java

License:Open Source License

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

    List<BlogsEntry> entries = BlogsEntryLocalServiceUtil.getCompanyEntries(companyId, new Date(),
            WorkflowConstants.STATUS_APPROVED, start, end);

    if (entries.isEmpty()) {
        return;//  w  ww .  ja va 2 s. c  o m
    }

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

    for (BlogsEntry entry : entries) {
        Document document = getDocument(entry);

        documents.add(document);
    }

    SearchEngineUtil.updateDocuments(companyId, documents);
}

From source file:com.liferay.portlet.blogs.util.PingbackMethodImpl.java

License:Open Source License

public Response execute(long companyId) {
    if (!PropsValues.BLOGS_PINGBACK_ENABLED) {
        return XmlRpcUtil.createFault(XmlRpcConstants.REQUESTED_METHOD_NOT_FOUND, "Pingbacks are disabled");
    }/* w  ww  . java 2 s.c o  m*/

    Response response = validateSource();

    if (response != null) {
        return response;
    }

    try {
        BlogsEntry entry = getBlogsEntry(companyId);

        if (!entry.isAllowPingbacks()) {
            return XmlRpcUtil.createFault(XmlRpcConstants.REQUESTED_METHOD_NOT_FOUND, "Pingbacks are disabled");
        }

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

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

        MBThread thread = messageDisplay.getThread();

        long threadId = thread.getThreadId();
        long parentMessageId = thread.getRootMessageId();
        String body = "[...] " + getExcerpt() + " [...] [url=" + _sourceUri + "]"
                + LanguageUtil.get(LocaleUtil.getDefault(), "read-more") + "[/url]";

        List<MBMessage> messages = MBMessageLocalServiceUtil.getThreadMessages(threadId,
                WorkflowConstants.STATUS_APPROVED);

        for (MBMessage message : messages) {
            if (message.getBody().equals(body)) {
                return XmlRpcUtil.createFault(PINGBACK_ALREADY_REGISTERED, "Pingback previously registered");
            }
        }

        ServiceContext serviceContext = new ServiceContext();

        String pingbackUserName = LanguageUtil.get(LocaleUtil.getDefault(), "pingback");

        serviceContext.setAttribute("pingbackUserName", pingbackUserName);

        StringBundler sb = new StringBundler(5);

        String layoutFullURL = PortalUtil.getLayoutFullURL(groupId, PortletKeys.BLOGS);

        sb.append(layoutFullURL);

        sb.append(Portal.FRIENDLY_URL_SEPARATOR);

        Portlet portlet = PortletLocalServiceUtil.getPortletById(companyId, PortletKeys.BLOGS);

        sb.append(portlet.getFriendlyURLMapping());
        sb.append(StringPool.SLASH);
        sb.append(entry.getUrlTitle());

        serviceContext.setAttribute("redirect", sb.toString());

        serviceContext.setLayoutFullURL(layoutFullURL);

        MBMessageLocalServiceUtil.addDiscussionMessage(userId, StringPool.BLANK, groupId, className, classPK,
                threadId, parentMessageId, StringPool.BLANK, body, serviceContext);

        return XmlRpcUtil.createSuccess("Pingback accepted");
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug(e, e);
        }

        return XmlRpcUtil.createFault(TARGET_URI_INVALID, "Error parsing target URI");
    }
}

From source file:com.liferay.portlet.css.service.impl.CSSEntryLocalServiceImpl.java

License:Open Source License

public CSSEntry addEntry(long classNameId, long classPK, double version, String css,
        ServiceContext serviceContext) throws SystemException {

    Date now = new Date();

    CSSEntry cssEntry = cssEntryPersistence.create(counterLocalService.increment());

    cssEntry.setCreateDate(serviceContext.getCreateDate(now));
    cssEntry.setUuid(serviceContext.getUuid());
    cssEntry.setModifiedDate(serviceContext.getModifiedDate(now));
    cssEntry.setClassNameId(classNameId);
    cssEntry.setClassPK(classPK);// w ww . ja  v  a  2  s  .c  o  m
    cssEntry.setVersion(version);
    if (classNameId != PortalUtil.getClassNameId(Company.class)) {
        cssEntry.setGroupId(serviceContext.getScopeGroupId());
    }
    cssEntry.setCss(css);
    cssEntry.setStatus(WorkflowConstants.STATUS_APPROVED);
    cssEntry.setStatusDate(serviceContext.getModifiedDate(now));
    cssEntry.setExpandoBridgeAttributes(serviceContext);

    return cssEntryPersistence.update(cssEntry, false);
}

From source file:com.liferay.portlet.css.service.impl.CSSEntryLocalServiceImpl.java

License:Open Source License

public CSSEntry updateEntry(long classNameId, long classPK, double version, String css,
        ServiceContext serviceContext) throws SystemException, PortalException {

    return updateEntry(classNameId, classPK, version, css, WorkflowConstants.STATUS_APPROVED, serviceContext);
}

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 ww  w . j av a2 s  .  c  om

    return UserLocalServiceUtil.updateStatus(userId, status);
}

From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java

License:Open Source License

public static void exportFileEntry(PortletDataContext portletDataContext, Element fileEntryTypesElement,
        Element foldersElement, Element fileEntriesElement, Element fileRanksElement,
        Element repositoriesElement, Element repositoryEntriesElement, FileEntry fileEntry,
        boolean checkDateRange) throws Exception {

    if (checkDateRange && !portletDataContext.isWithinDateRange(fileEntry.getModifiedDate())) {

        return;//www  .  j  av a  2s  .com
    }

    if (!fileEntry.isDefaultRepository()) {
        Repository repository = RepositoryUtil.findByPrimaryKey(fileEntry.getRepositoryId());

        exportRepository(portletDataContext, repositoriesElement, repositoryEntriesElement, repository);

        return;
    }

    FileVersion fileVersion = fileEntry.getFileVersion();

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

    String path = getFileEntryPath(portletDataContext, fileEntry);

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

    Element fileEntryElement = fileEntriesElement.addElement("file-entry");

    if (foldersElement != null) {
        exportParentFolder(portletDataContext, fileEntryTypesElement, foldersElement, repositoriesElement,
                repositoryEntriesElement, fileEntry.getFolderId());
    }

    if (!portletDataContext.isPerformDirectBinaryImport()) {
        InputStream is = null;

        try {
            is = FileEntryUtil.getContentStream(fileEntry);
        } catch (NoSuchFileException nsfe) {
        }

        if (is == null) {
            if (_log.isWarnEnabled()) {
                _log.warn("No file found for file entry " + fileEntry.getFileEntryId());
            }

            fileEntryElement.detach();

            return;
        }

        try {
            String binPath = getFileEntryBinPath(portletDataContext, fileEntry);

            portletDataContext.addZipEntry(binPath, is);

            fileEntryElement.addAttribute("bin-path", binPath);
        } finally {
            try {
                is.close();
            } catch (IOException ioe) {
                _log.error(ioe, ioe);
            }
        }
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "ranks")) {
        List<DLFileRank> fileRanks = DLFileRankUtil.findByFileEntryId(fileEntry.getFileEntryId());

        for (DLFileRank fileRank : fileRanks) {
            exportFileRank(portletDataContext, fileRanksElement, fileRank);
        }
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "previews-and-thumbnails")) {

        DLProcessorRegistryUtil.exportGeneratedFiles(portletDataContext, fileEntry, fileEntryElement);
    }

    exportMetaData(portletDataContext, fileEntryTypesElement, fileEntryElement, fileEntry);

    portletDataContext.addClassedModel(fileEntryElement, path, fileEntry, _NAMESPACE);
}

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

License:Open Source License

public void updateStatus(long userId, FileEntry fileEntry, FileVersion latestFileVersion, int status,
        Map<String, Serializable> workflowContext) throws PortalException, SystemException {

    if (status == WorkflowConstants.STATUS_APPROVED) {

        // Asset/* w w w.j  ava  2s .  c  om*/

        String latestFileVersionVersion = latestFileVersion.getVersion();

        if (latestFileVersionVersion.equals(fileEntry.getVersion())) {
            if (!latestFileVersionVersion.equals(DLFileEntryConstants.VERSION_DEFAULT)) {

                AssetEntry draftAssetEntry = null;

                try {
                    long fileEntryTypeId = getFileEntryTypeId(fileEntry);

                    draftAssetEntry = assetEntryLocalService.getEntry(DLFileEntryConstants.getClassName(),
                            latestFileVersion.getPrimaryKey());

                    long[] assetCategoryIds = draftAssetEntry.getCategoryIds();
                    String[] assetTagNames = draftAssetEntry.getTagNames();

                    List<AssetLink> assetLinks = assetLinkLocalService
                            .getDirectLinks(draftAssetEntry.getEntryId(), AssetLinkConstants.TYPE_RELATED);

                    long[] assetLinkEntryIds = StringUtil
                            .split(ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);

                    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, fileEntry.getGroupId(),
                            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId(),
                            fileEntry.getUuid(), fileEntryTypeId, assetCategoryIds, assetTagNames, true, null,
                            null, null, null, draftAssetEntry.getMimeType(), fileEntry.getTitle(),
                            fileEntry.getDescription(), null, null, null, 0, 0, null, false);

                    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), assetLinkEntryIds,
                            AssetLinkConstants.TYPE_RELATED);

                    assetEntryLocalService.deleteEntry(draftAssetEntry.getEntryId());
                } catch (NoSuchEntryException nsee) {
                }
            }

            assetEntryLocalService.updateVisible(DLFileEntryConstants.getClassName(),
                    fileEntry.getFileEntryId(), true);
        }

        // Sync

        String event = (String) workflowContext.get("event");

        if (!isStagingGroup(fileEntry.getGroupId()) && Validator.isNotNull(event)) {

            if (event.equals(DLSyncConstants.EVENT_ADD)) {
                dlSyncLocalService.addSync(fileEntry.getFileEntryId(), fileEntry.getUuid(),
                        fileEntry.getCompanyId(), fileEntry.getRepositoryId(), fileEntry.getFolderId(),
                        fileEntry.getTitle(), DLSyncConstants.TYPE_FILE, fileEntry.getVersion());
            } else if (event.equals(DLSyncConstants.EVENT_UPDATE)) {
                dlSyncLocalService.updateSync(fileEntry.getFileEntryId(), fileEntry.getFolderId(),
                        fileEntry.getTitle(), DLSyncConstants.EVENT_UPDATE, fileEntry.getVersion());
            }
        }

        // Social

        int activityType = DLActivityKeys.UPDATE_FILE_ENTRY;

        if (latestFileVersionVersion.equals(DLFileEntryConstants.VERSION_DEFAULT)) {

            activityType = DLActivityKeys.ADD_FILE_ENTRY;
        }

        socialActivityLocalService.addUniqueActivity(latestFileVersion.getStatusByUserId(),
                fileEntry.getGroupId(), latestFileVersion.getCreateDate(), DLFileEntryConstants.getClassName(),
                fileEntry.getFileEntryId(), activityType, StringPool.BLANK, 0);
    } else {

        // Asset

        if (Validator.isNull(fileEntry.getVersion())) {
            assetEntryLocalService.updateVisible(DLFileEntryConstants.getClassName(),
                    fileEntry.getFileEntryId(), false);
        }
    }
}

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

License:Open Source License

public DLFileEntry updateStatus(long userId, long fileVersionId, int status,
        Map<String, Serializable> workflowContext, ServiceContext serviceContext)
        throws PortalException, SystemException {

    // File version

    User user = userPersistence.findByPrimaryKey(userId);

    DLFileVersion dlFileVersion = dlFileVersionPersistence.findByPrimaryKey(fileVersionId);

    dlFileVersion.setStatus(status);/*  w ww .  j  a va2 s .  c o  m*/
    dlFileVersion.setStatusByUserId(user.getUserId());
    dlFileVersion.setStatusByUserName(user.getFullName());
    dlFileVersion.setStatusDate(new Date());

    dlFileVersionPersistence.update(dlFileVersion, false);

    // File entry

    DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(dlFileVersion.getFileEntryId());

    if (status == WorkflowConstants.STATUS_APPROVED) {
        if (DLUtil.compareVersions(dlFileEntry.getVersion(), dlFileVersion.getVersion()) <= 0) {

            dlFileEntry.setExtension(dlFileVersion.getExtension());
            dlFileEntry.setTitle(dlFileVersion.getTitle());
            dlFileEntry.setDescription(dlFileVersion.getDescription());
            dlFileEntry.setExtraSettings(dlFileVersion.getExtraSettings());
            dlFileEntry.setFileEntryTypeId(dlFileVersion.getFileEntryTypeId());
            dlFileEntry.setVersion(dlFileVersion.getVersion());
            dlFileEntry.setVersionUserId(dlFileVersion.getUserId());
            dlFileEntry.setVersionUserName(dlFileVersion.getUserName());
            dlFileEntry.setModifiedDate(dlFileVersion.getCreateDate());
            dlFileEntry.setSize(dlFileVersion.getSize());

            dlFileEntryPersistence.update(dlFileEntry, false);
        }
    } else {

        // File entry

        if (dlFileEntry.getVersion().equals(dlFileVersion.getVersion())) {
            String newVersion = DLFileEntryConstants.VERSION_DEFAULT;

            List<DLFileVersion> approvedFileVersions = dlFileVersionPersistence
                    .findByF_S(dlFileEntry.getFileEntryId(), WorkflowConstants.STATUS_APPROVED);

            if (!approvedFileVersions.isEmpty()) {
                newVersion = approvedFileVersions.get(0).getVersion();
            }

            dlFileEntry.setVersion(newVersion);

            dlFileEntryPersistence.update(dlFileEntry, false);
        }

        // Indexer

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

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

            indexer.delete(dlFileEntry);
        }
    }

    // App helper

    dlAppHelperLocalService.updateStatus(userId, new LiferayFileEntry(dlFileEntry),
            new LiferayFileVersion(dlFileVersion), status, workflowContext);

    // Indexer

    if (status == WorkflowConstants.STATUS_APPROVED) {
        reindex(dlFileEntry);
    }

    return dlFileEntry;
}