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

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

Introduction

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

Prototype

int STATUS_ANY

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

Click Source Link

Usage

From source file:com.liferay.portlet.usersadmin.util.UserIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS),
            WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }/*from   w ww . j av a2  s. c o  m*/

    LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();

            if (value == null) {
                continue;
            }

            addContextQueryParams(contextQuery, searchContext, key, value);
        }
    }
}

From source file:com.liferay.portlet.wiki.util.WikiIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_ANY);

    if (status != WorkflowConstants.STATUS_ANY) {
        contextQuery.addRequiredTerm(Field.STATUS, status);
    }/* w w  w. j av  a2 s  .  com*/

    long[] nodeIds = searchContext.getNodeIds();

    if ((nodeIds != null) && (nodeIds.length > 0)) {
        BooleanQuery nodeIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long nodeId : nodeIds) {
            try {
                WikiNodeServiceUtil.getNode(nodeId);
            } catch (Exception e) {
                continue;
            }

            nodeIdsQuery.addTerm(Field.NODE_ID, nodeId);
        }

        contextQuery.add(nodeIdsQuery, BooleanClauseOccur.MUST);
    }
}

From source file:com.liferay.privatemessaging.service.impl.UserThreadLocalServiceImpl.java

License:Open Source License

public MBMessage addPrivateMessage(long userId, long mbThreadId, String to, String subject, String body,
        List<ObjectValuePair<String, InputStream>> inputStreamOVPs, ThemeDisplay themeDisplay)
        throws PortalException {

    long parentMBMessageId = MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID;

    List<User> recipients = null;

    if (mbThreadId != 0) {
        List<MBMessage> mbMessages = MBMessageLocalServiceUtil.getThreadMessages(mbThreadId,
                WorkflowConstants.STATUS_ANY);

        MBMessage lastMBMessage = mbMessages.get(mbMessages.size() - 1);

        parentMBMessageId = lastMBMessage.getMessageId();
        subject = lastMBMessage.getSubject();
    } else {//from   w w  w  .j a  va2  s . c o  m
        recipients = parseRecipients(userId, to);

        if (recipients.isEmpty()) {
            return null;
        }
    }

    return addPrivateMessage(userId, mbThreadId, parentMBMessageId, recipients, subject, body, inputStreamOVPs,
            themeDisplay);
}

From source file:com.liferay.privatemessaging.service.impl.UserThreadServiceImpl.java

License:Open Source License

public List<MBMessage> getThreadMessages(long mbThreadId, int start, int end, boolean ascending)
        throws PortalException {

    UserThread userThread = userThreadLocalService.getUserThread(getUserId(), mbThreadId);

    MBMessage topMBMessage = MBMessageLocalServiceUtil.getMBMessage(userThread.getTopMBMessageId());

    List<MBMessage> mbMessages = MBMessageLocalServiceUtil.getThreadMessages(mbThreadId,
            WorkflowConstants.STATUS_ANY, new MessageCreateDateComparator(ascending));

    List<MBMessage> filteredMBMessages = new ArrayList<MBMessage>();

    for (MBMessage mbMessage : mbMessages) {
        int compareTo = DateUtil.compareTo(topMBMessage.getCreateDate(), mbMessage.getCreateDate());

        if (compareTo <= 0) {
            filteredMBMessages.add(mbMessage);
        }/*from w  w  w .ja va  2 s.  c  om*/
    }

    if (filteredMBMessages.isEmpty()) {
        return filteredMBMessages;
    } else if ((start == QueryUtil.ALL_POS) || (end == QueryUtil.ALL_POS)) {
        return filteredMBMessages;
    } else if (end > filteredMBMessages.size()) {
        end = filteredMBMessages.size();
    }

    return filteredMBMessages.subList(start, end);
}

From source file:com.liferay.privatemessaging.util.PrivateMessagingUtil.java

License:Open Source License

/**
 * Each thread has a user that represents that thread. This person is either
 * the last user to post on that thread (exluding himself), or if he is the
 * only person to have posted on the thread, then he will the represenative.
 *///  w  w  w . ja  v  a 2  s  .co  m
public static long getThreadRepresentativeUserId(long userId, long mbThreadId) {

    List<MBMessage> mbMessages = MBMessageLocalServiceUtil.getThreadMessages(mbThreadId,
            WorkflowConstants.STATUS_ANY, new MessageCreateDateComparator(false));

    for (MBMessage mbMessage : mbMessages) {
        if (userId != mbMessage.getUserId()) {
            return mbMessage.getUserId();
        }
    }

    List<UserThread> userThreads = UserThreadLocalServiceUtil.getMBThreadUserThreads(mbThreadId);

    for (UserThread userThread : userThreads) {
        if (userId != userThread.getUserId()) {
            return userThread.getUserId();
        }
    }

    return userId;
}

From source file:com.liferay.privatemessaging.util.PrivateMessagingUtil.java

License:Open Source License

public static String getThreadSubject(long mbThreadId) {
    List<MBMessage> mbMessages = MBMessageLocalServiceUtil.getThreadMessages(mbThreadId,
            WorkflowConstants.STATUS_ANY, 0, 1);

    return mbMessages.get(0).getSubject();
}

From source file:com.liferay.repository.external.model.ExtRepositoryFileEntryAdapter.java

License:Open Source License

@Override
@SuppressWarnings({ "rawtypes" })
public List<FileVersion> getFileVersions(int status) {
    if ((status == WorkflowConstants.STATUS_ANY) || (status == WorkflowConstants.STATUS_APPROVED)) {

        try {//  w ww .j  av  a  2  s  .c om
            return (List) _getExtRepositoryFileVersionAdapters();
        } catch (PortalException pe) {
            throw new SystemException(pe);
        }
    } else {
        return Collections.emptyList();
    }
}

From source file:com.liferay.resourcesimporter.util.FileSystemImporter.java

License:Open Source License

protected void addJournalArticles(String ddmStructureKey, String ddmTemplateKey, String fileName,
        InputStream inputStream) throws Exception {

    String title = FileUtil.stripExtension(fileName);

    JSONObject assetJSONObject = _assetJSONObjectMap.get(fileName);

    Map<Locale, String> descriptionMap = null;

    boolean indexable = true;

    if (assetJSONObject != null) {
        String abstractSummary = assetJSONObject.getString("abstractSummary");

        descriptionMap = getMap(abstractSummary);

        indexable = GetterUtil.getBoolean(assetJSONObject.getString("indexable"), true);
    }/*from ww w . j av  a 2  s  .c  om*/

    String content = StringUtil.read(inputStream);

    content = replaceFileEntryURL(content);

    Locale articleDefaultLocale = LocaleUtil.fromLanguageId(LocalizationUtil.getDefaultLanguageId(content));

    boolean smallImage = false;
    String smallImageURL = StringPool.BLANK;

    if (assetJSONObject != null) {
        String smallImageFileName = assetJSONObject.getString("smallImage");

        if (Validator.isNotNull(smallImageFileName)) {
            smallImage = true;

            FileEntry fileEntry = _fileEntries.get(smallImageFileName);

            if (fileEntry != null) {
                smallImageURL = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null,
                        StringPool.BLANK);
            }
        }
    }

    setServiceContext(fileName);

    String journalArticleId = getJournalId(fileName);

    JournalArticle journalArticle = JournalArticleLocalServiceUtil.fetchLatestArticle(groupId, journalArticleId,
            WorkflowConstants.STATUS_ANY);

    try {
        if (journalArticle == null) {
            journalArticle = JournalArticleLocalServiceUtil.addArticle(userId, groupId, 0, 0, 0,
                    journalArticleId, false, JournalArticleConstants.VERSION_DEFAULT,
                    getMap(articleDefaultLocale, title), descriptionMap, content, ddmStructureKey,
                    ddmTemplateKey, StringPool.BLANK, 1, 1, 2010, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0,
                    true, indexable, smallImage, smallImageURL, null, new HashMap<String, byte[]>(),
                    StringPool.BLANK, serviceContext);
        } else {
            journalArticle = JournalArticleLocalServiceUtil.updateArticle(userId, groupId, 0, journalArticleId,
                    journalArticle.getVersion(), getMap(articleDefaultLocale, title), descriptionMap, content,
                    ddmStructureKey, ddmTemplateKey, StringPool.BLANK, 1, 1, 2010, 0, 0, 0, 0, 0, 0, 0, true, 0,
                    0, 0, 0, 0, true, indexable, smallImage, smallImageURL, null, new HashMap<String, byte[]>(),
                    StringPool.BLANK, serviceContext);
        }

        JournalArticleLocalServiceUtil.updateStatus(userId, groupId, journalArticle.getArticleId(),
                journalArticle.getVersion(), WorkflowConstants.STATUS_APPROVED, StringPool.BLANK,
                new HashMap<String, Serializable>(), serviceContext);
    } catch (PortalException e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to import journal article " + fileName, e);
        }

        throw e;
    }

    addPrimaryKey(JournalArticle.class.getName(), journalArticle.getPrimaryKey());
}

From source file:com.liferay.sevencogs.hook.upgrade.v1_0_0.UpgradeCompany.java

License:Open Source License

protected void clearData(long companyId) throws Exception {

    // Users/*from  ww w  .  j av  a  2  s  .  c om*/

    List<User> users = UserLocalServiceUtil.search(companyId, null, WorkflowConstants.STATUS_ANY, null,
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator) null);

    for (User user : users) {
        String screenName = user.getScreenName();

        String defaultAdminScreenName = PropsUtil.get(PropsKeys.DEFAULT_ADMIN_SCREEN_NAME);

        if (screenName.equals("joebloggs") || screenName.equals("test")
                || screenName.equals(defaultAdminScreenName)) {

            continue;
        }

        UserLocalServiceUtil.deleteUser(user.getUserId());
    }

    // Organizations

    deleteOrganizations(companyId, OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID);

    // Groups

    List<Group> groups = GroupLocalServiceUtil.search(companyId, null, null, null, QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);

    for (Group group : groups) {
        if (!PortalUtil.isSystemGroup(group.getName())) {
            GroupLocalServiceUtil.deleteGroup(group.getGroupId());
        } else {
            ServiceContext serviceContext = new ServiceContext();

            DLAppLocalServiceUtil.deleteAll(group.getGroupId());

            JournalArticleLocalServiceUtil.deleteArticles(group.getGroupId());
            JournalTemplateLocalServiceUtil.deleteTemplates(group.getGroupId());
            JournalStructureLocalServiceUtil.deleteStructures(group.getGroupId());

            LayoutLocalServiceUtil.deleteLayouts(group.getGroupId(), false, serviceContext);
            LayoutLocalServiceUtil.deleteLayouts(group.getGroupId(), true, serviceContext);
        }
    }
}

From source file:com.liferay.staging.test.StagingLocalizationTest.java

License:Open Source License

protected void testUpdateLocales(String defaultLanguageId, String languageIds, String defaultContentLanguageId)
        throws Exception {

    GroupTestUtil.enableLocalStaging(_sourceGroup);

    JournalArticle article = JournalTestUtil.addArticle(_sourceGroup.getGroupId(), "Title", "content",
            LocaleUtil.fromLanguageId(defaultContentLanguageId));

    User user = TestPropsValues.getUser();

    Map<String, String[]> parameterMap = ExportImportConfigurationParameterMapFactory.buildParameterMap();

    Map<String, Serializable> publishLayoutLocalSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildPublishLayoutLocalSettingsMap(user, _sourceGroup.getGroupId(), _targetGroup.getGroupId(),
                    false, ExportImportHelperUtil.getAllLayoutIds(_sourceGroup.getGroupId(), false),
                    parameterMap);/*from ww w .  ja  va2 s  .  c  o  m*/

    ExportImportConfiguration exportImportConfiguration = ExportImportConfigurationLocalServiceUtil
            .addDraftExportImportConfiguration(user.getUserId(),
                    ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_LOCAL,
                    publishLayoutLocalSettingsMap);

    File file = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportImportConfiguration);

    CompanyTestUtil.resetCompanyLocales(TestPropsValues.getCompanyId(), languageIds, defaultLanguageId);

    ExportImportLocalServiceUtil.importLayouts(exportImportConfiguration, file);

    JournalArticleResource articleResource = JournalArticleResourceLocalServiceUtil
            .fetchJournalArticleResourceByUuidAndGroupId(article.getArticleResourceUuid(),
                    _targetGroup.getGroupId());

    Assert.assertNotNull(articleResource);

    JournalArticle stagingArticle = JournalArticleLocalServiceUtil
            .getLatestArticle(articleResource.getResourcePrimKey(), WorkflowConstants.STATUS_ANY, false);

    if (languageIds.contains(defaultContentLanguageId)) {
        Assert.assertEquals(article.getDefaultLanguageId(), stagingArticle.getDefaultLanguageId());
    } else {
        Assert.assertEquals(defaultLanguageId, stagingArticle.getDefaultLanguageId());
    }

    for (Locale locale : _locales) {
        if (languageIds.contains(LocaleUtil.toLanguageId(locale))
                || languageIds.contains(defaultContentLanguageId)) {

            Assert.assertEquals(article.getTitle(locale), stagingArticle.getTitle(locale));
        } else {
            Assert.assertEquals(article.getTitle(defaultLanguageId), stagingArticle.getTitle(locale));
        }
    }
}