Example usage for com.liferay.portal.kernel.util PortalUtil getClassNameId

List of usage examples for com.liferay.portal.kernel.util PortalUtil getClassNameId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PortalUtil getClassNameId.

Prototype

public static long getClassNameId(String value) 

Source Link

Document

Returns the ID of the class from its fully qualified name.

Usage

From source file:com.liferay.journal.util.test.JournalTestUtilTest.java

License:Open Source License

@Test
public void testAddDDMTemplateToDDMStructure() throws Exception {
    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(JournalArticle.class.getName());

    Assert.assertNotNull(DDMTemplateTestUtil.addTemplate(ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class)));
}

From source file:com.liferay.journal.util.test.JournalTestUtilTest.java

License:Open Source License

@Test
public void testAddDDMTemplateToDDMStructureWithXSLAndLanguage() throws Exception {

    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(JournalArticle.class.getName());

    Assert.assertNotNull(DDMTemplateTestUtil.addTemplate(ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class), TemplateConstants.LANG_TYPE_VM,
            JournalTestUtil.getSampleTemplateXSL()));
}

From source file:com.liferay.journal.util.test.JournalTestUtilTest.java

License:Open Source License

@Test
public void testDeleteDDMStructure() throws Exception {
    String content = DDMStructureTestUtil.getSampleStructuredContent();

    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(JournalArticle.class.getName());

    Assert.assertNotNull(JournalTestUtil.addArticleWithXMLContent(TestPropsValues.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, PortalUtil.getClassNameId(DDMStructure.class),
            ddmStructure.getStructureId(), content, ddmStructure.getStructureKey(), null,
            LocaleUtil.getSiteDefault()));

    DDMStructureLocalServiceUtil.deleteDDMStructure(ddmStructure);

    try {/*from  w  ww .  ja  v  a  2  s .  c  o m*/
        Assert.assertNull(JournalArticleLocalServiceUtil.getArticle(ddmStructure.getGroupId(),
                DDMStructure.class.getName(), ddmStructure.getStructureId()));
    } catch (NoSuchArticleException nsae) {
    }
}

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

License:Open Source License

protected void verifyJournalArticleDeleteSystemEvents() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer()) {
        DynamicQuery dynamicQuery = _systemEventLocalService.dynamicQuery();

        Property classNameIdProperty = PropertyFactoryUtil.forName("classNameId");

        dynamicQuery.add(classNameIdProperty.eq(PortalUtil.getClassNameId(JournalArticle.class)));

        Property typeProperty = PropertyFactoryUtil.forName("type");

        dynamicQuery.add(typeProperty.eq(SystemEventConstants.TYPE_DELETE));

        List<SystemEvent> systemEvents = _systemEventLocalService.dynamicQuery(dynamicQuery);

        if (_log.isDebugEnabled()) {
            _log.debug("Processing " + systemEvents.size() + " delete system " + "events for journal articles");
        }// w  ww  .  j  a va 2 s. co m

        for (SystemEvent systemEvent : systemEvents) {
            JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(systemEvent.getExtraData());

            if (extraDataJSONObject.has("uuid") || !extraDataJSONObject.has("version")) {

                continue;
            }

            JournalArticleResource journalArticleResource = _journalArticleResourceLocalService
                    .fetchJournalArticleResourceByUuidAndGroupId(systemEvent.getClassUuid(),
                            systemEvent.getGroupId());

            if (journalArticleResource == null) {
                continue;
            }

            JournalArticle journalArticle = _journalArticleLocalService.fetchArticle(systemEvent.getGroupId(),
                    journalArticleResource.getArticleId(), extraDataJSONObject.getDouble("version"));

            if ((journalArticle == null) || journalArticle.isInTrash()) {
                continue;
            }

            _systemEventLocalService.deleteSystemEvent(systemEvent);
        }

        if (_log.isDebugEnabled()) {
            _log.debug("Delete system events verified for journal articles");
        }
    }
}

From source file:com.liferay.journal.web.asset.JournalArticleDDMFormValuesReader.java

License:Open Source License

@Override
public DDMFormValues getDDMFormValues() throws PortalException {
    try {/*from w  ww . ja va2s.c o m*/
        DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(
                PortalUtil.getSiteGroupId(_article.getGroupId()),
                PortalUtil.getClassNameId(JournalArticle.class), _article.getDDMStructureKey(), true);

        Fields fields = _journalConverter.getDDMFields(ddmStructure, _article.getContent());

        return DDMBeanTranslatorUtil.translate(_fieldsToDDMFormValuesConverter.convert(ddmStructure, fields));
    } catch (Exception e) {
        throw new PortalException("Unable to read fields for article " + _article.getId(), e);
    }
}

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

License:Open Source License

public SearchContainer<MBMessage> getCommentsSearchContainer() throws PortalException {

    SearchContainer<MBMessage> searchContainer = new SearchContainer(_liferayPortletRequest,
            _liferayPortletResponse.createRenderURL(), null, null);

    SearchContext searchContext = SearchContextFactory
            .getInstance(_liferayPortletRequest.getHttpServletRequest());

    searchContext.setAttribute(Field.CLASS_NAME_ID, PortalUtil.getClassNameId(JournalArticle.class));

    searchContext.setAttribute("discussion", Boolean.TRUE);

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

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

    Hits hits = indexer.search(searchContext);

    for (Document document : hits.getDocs()) {
        long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(entryClassPK);

        mbMessages.add(mbMessage);/*from ww  w.  j  a  v  a 2s  . c o m*/
    }

    searchContainer.setResults(mbMessages);

    searchContainer.setTotal(hits.getLength());

    return searchContainer;
}

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

License:Open Source License

public String getDDMStructureName() throws PortalException {
    if (_ddmStructureName != null) {
        return _ddmStructureName;
    }//w w w . j a va2  s.  c  om

    _ddmStructureName = LanguageUtil.get(_request, "basic-web-content");

    if (Validator.isNull(getDDMStructureKey())) {
        return _ddmStructureName;
    }

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

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(themeDisplay.getSiteGroupId(),
            PortalUtil.getClassNameId(JournalArticle.class), getDDMStructureKey(), true);

    if (ddmStructure != null) {
        _ddmStructureName = ddmStructure.getName(themeDisplay.getLocale());
    }

    return _ddmStructureName;
}

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

License:Open Source License

public long getDDMStructurePrimaryKey() throws PortalException {
    String ddmStructureKey = getDDMStructureKey();

    if (Validator.isNull(ddmStructureKey)) {
        return 0;
    }//ww w.j ava  2  s.  co m

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

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(themeDisplay.getSiteGroupId(),
            PortalUtil.getClassNameId(JournalArticle.class), getDDMStructureKey(), true);

    if (ddmStructure == null) {
        return 0;
    }

    return ddmStructure.getPrimaryKey();
}

From source file:com.liferay.journal.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static JournalArticle getArticle(HttpServletRequest request) throws PortalException {

    String actionName = ParamUtil.getString(request, ActionRequest.ACTION_NAME);

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

    long resourcePrimKey = ParamUtil.getLong(request, "resourcePrimKey");
    long groupId = ParamUtil.getLong(request, "groupId", themeDisplay.getScopeGroupId());
    long classNameId = ParamUtil.getLong(request, "classNameId");
    long classPK = ParamUtil.getLong(request, "classPK");
    String articleId = ParamUtil.getString(request, "articleId");
    String ddmStructureKey = ParamUtil.getString(request, "ddmStructureKey");
    int status = ParamUtil.getInteger(request, "status", WorkflowConstants.STATUS_ANY);

    JournalArticle article = null;//from   w w  w.  j  ava2 s . c o m

    if (actionName.equals("addArticle") && (resourcePrimKey != 0)) {
        article = JournalArticleLocalServiceUtil.getLatestArticle(resourcePrimKey, status, false);
    } else if (!actionName.equals("addArticle") && Validator.isNotNull(articleId)) {

        article = JournalArticleServiceUtil.getLatestArticle(groupId, articleId, status);
    } else if ((classNameId > 0) && (classPK > JournalArticleConstants.CLASSNAME_ID_DEFAULT)) {

        String className = PortalUtil.getClassName(classNameId);

        try {
            article = JournalArticleServiceUtil.getLatestArticle(groupId, className, classPK);
        } catch (NoSuchArticleException nsae) {
            return null;
        }
    } else {
        DDMStructure ddmStructure = DDMStructureServiceUtil.fetchStructure(groupId,
                PortalUtil.getClassNameId(JournalArticle.class), ddmStructureKey, true);

        if (ddmStructure == null) {
            return null;
        }

        try {
            article = JournalArticleServiceUtil.getArticle(ddmStructure.getGroupId(),
                    DDMStructure.class.getName(), ddmStructure.getStructureId());

            article.setNew(true);

            article.setId(0);
            article.setGroupId(groupId);
            article.setClassNameId(JournalArticleConstants.CLASSNAME_ID_DEFAULT);
            article.setClassPK(0);
            article.setArticleId(null);
            article.setVersion(0);
        } catch (NoSuchArticleException nsae) {
            return null;
        }
    }

    return article;
}

From source file:com.liferay.maven.test.sb.model.impl.AssignmentModelImpl.java

License:Open Source License

@Override
public StagedModelType getStagedModelType() {
    return new StagedModelType(PortalUtil.getClassNameId(Assignment.class.getName()));
}