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

License:Open Source License

@Test
public void testUpdateFolderRestrictions() throws Exception {
    JournalFolder folder = JournalTestUtil.addFolder(_group.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 1");

    String xml = DDMStructureTestUtil.getSampleStructuredContent("Test Article");

    DDMStructure ddmStructure1 = DDMStructureTestUtil.addStructure(_group.getGroupId(),
            JournalArticle.class.getName());

    DDMTemplate ddmTemplate1 = DDMTemplateTestUtil.addTemplate(_group.getGroupId(),
            ddmStructure1.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class),
            LocaleUtil.getDefault());/*from w ww .  j  a va 2 s.c  o m*/

    JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(), folder.getFolderId(),
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, xml, ddmStructure1.getStructureKey(),
            ddmTemplate1.getTemplateKey());

    DDMStructure ddmStructure2 = DDMStructureTestUtil.addStructure(_group.getGroupId(),
            JournalArticle.class.getName());

    long[] ddmStructureIds = new long[] { ddmStructure2.getStructureId() };

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    try {
        JournalFolderLocalServiceUtil.updateFolder(TestPropsValues.getUserId(),
                serviceContext.getScopeGroupId(), folder.getFolderId(), folder.getParentFolderId(),
                folder.getName(), folder.getDescription(), ddmStructureIds,
                JournalFolderConstants.RESTRICTION_TYPE_DDM_STRUCTURES_AND_WORKFLOW, false, serviceContext);

        Assert.fail();
    } catch (InvalidDDMStructureException iddmse) {
    }

    JournalFolder subfolder = JournalTestUtil.addFolder(_group.getGroupId(), folder.getFolderId(), "Test 1.1");

    JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(), subfolder.getFolderId(),
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, xml, ddmStructure1.getStructureKey(),
            ddmTemplate1.getTemplateKey());

    try {
        JournalFolderLocalServiceUtil.updateFolder(TestPropsValues.getUserId(),
                serviceContext.getScopeGroupId(), folder.getFolderId(), folder.getParentFolderId(),
                folder.getName(), folder.getDescription(), ddmStructureIds,
                JournalFolderConstants.RESTRICTION_TYPE_DDM_STRUCTURES_AND_WORKFLOW, false, serviceContext);

        Assert.fail();
    } catch (InvalidDDMStructureException iddmse) {
    }
}

From source file:com.liferay.journal.subscriptions.test.JournalSubscriptionClassTypeTest.java

License:Open Source License

@Override
protected long addClassType() throws Exception {
    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(group.getGroupId(),
            JournalArticle.class.getName());

    DDMTemplateTestUtil.addTemplate(group.getGroupId(), ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class));

    return ddmStructure.getStructureId();
}

From source file:com.liferay.journal.subscriptions.test.JournalSubscriptionClassTypeTest.java

License:Open Source License

@Override
protected Long getDefaultClassTypeId() throws Exception {
    Company company = CompanyLocalServiceUtil.getCompany(group.getCompanyId());

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(company.getGroupId(),
            PortalUtil.getClassNameId(JournalArticle.class), "BASIC-WEB-CONTENT");

    return ddmStructure.getStructureId();
}

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

License:Open Source License

public static JournalArticle addArticle(long groupId, long folderId, long classNameId, String articleId,
        boolean autoArticleId, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
        Map<Locale, String> contentMap, String layoutUuid, Locale defaultLocale, Date expirationDate,
        boolean workflowEnabled, boolean approved, ServiceContext serviceContext) throws Exception {

    String content = DDMStructureTestUtil.getSampleStructuredContent(contentMap,
            LocaleUtil.toLanguageId(defaultLocale));

    DDMForm ddmForm = DDMStructureTestUtil.getSampleDDMForm(_locales, defaultLocale);

    long ddmGroupId = GetterUtil.getLong(serviceContext.getAttribute("ddmGroupId"), groupId);

    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(ddmGroupId, JournalArticle.class.getName(),
            ddmForm, defaultLocale);/*from   ww w .  java 2s  . c o m*/

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(ddmGroupId, ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class));

    boolean neverExpire = true;

    int expirationDateDay = 0;
    int expirationDateMonth = 0;
    int expirationDateYear = 0;
    int expirationDateHour = 0;
    int expirationDateMinute = 0;

    if (expirationDate != null) {
        neverExpire = false;

        Calendar expirationCal = CalendarFactoryUtil.getCalendar(TestPropsValues.getUser().getTimeZone());

        expirationCal.setTime(expirationDate);

        expirationDateMonth = expirationCal.get(Calendar.MONTH);
        expirationDateDay = expirationCal.get(Calendar.DATE);
        expirationDateYear = expirationCal.get(Calendar.YEAR);
        expirationDateHour = expirationCal.get(Calendar.HOUR_OF_DAY);
        expirationDateMinute = expirationCal.get(Calendar.MINUTE);
    }

    Calendar displayCal = CalendarFactoryUtil.getCalendar(TestPropsValues.getUser().getTimeZone());

    int displayDateDay = displayCal.get(Calendar.DATE);
    int displayDateMonth = displayCal.get(Calendar.MONTH);
    int displayDateYear = displayCal.get(Calendar.YEAR);
    int displayDateHour = displayCal.get(Calendar.HOUR_OF_DAY);
    int displayDateMinute = displayCal.get(Calendar.MINUTE);

    if (workflowEnabled) {
        serviceContext = (ServiceContext) serviceContext.clone();

        if (approved) {
            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
        } else {
            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
        }
    }

    return JournalArticleLocalServiceUtil.addArticle(serviceContext.getUserId(), groupId, folderId, classNameId,
            0, articleId, autoArticleId, JournalArticleConstants.VERSION_DEFAULT, titleMap, descriptionMap,
            content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), layoutUuid, displayDateMonth,
            displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth,
            expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, 0, 0,
            0, 0, 0, true, true, false, null, null, null, null, serviceContext);
}

From source file:com.liferay.journal.transformer.test.JournalTransformerTest.java

License:Open Source License

@Test
public void testContentTransformerListener() throws Exception {
    DDMForm ddmForm = new DDMForm();

    ddmForm.addAvailableLocale(LocaleUtil.US);
    ddmForm.addDDMFormField(DDMFormTestUtil.createTextDDMFormField("link", false, false, false));
    ddmForm.addDDMFormField(DDMFormTestUtil.createTextDDMFormField("name", false, false, false));
    ddmForm.setDefaultLocale(LocaleUtil.US);

    _ddmStructure = DDMStructureTestUtil.addStructure(JournalArticle.class.getName(), ddmForm);

    String xsl = "$name.getData()";

    _ddmTemplate = DDMTemplateTestUtil.addTemplate(_ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class), TemplateConstants.LANG_TYPE_VM, xsl);

    String xml = DDMStructureTestUtil.getSampleStructuredContent("Joe Bloggs");

    _article = JournalTestUtil.addArticleWithXMLContent(xml, _ddmStructure.getStructureKey(),
            _ddmTemplate.getTemplateKey());

    Map<String, String> tokens = getTokens();

    String content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US",
            UnsecureSAXReaderUtil.read(xml), null, xsl, TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joe Bloggs", content);

    Document document = UnsecureSAXReaderUtil.read(xml);

    Element element = (Element) document.selectSingleNode("//dynamic-content");

    element.setText("[@" + _article.getArticleId() + ";name@]");

    content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US", document, null, xsl,
            TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joe Bloggs", content);
}

From source file:com.liferay.journal.transformer.test.JournalTransformerTest.java

License:Open Source License

@Test
public void testVMTransformation() throws Exception {
    Map<String, String> tokens = getTokens();

    _ddmStructure = DDMStructureTestUtil.addStructure(TestPropsValues.getGroupId(),
            JournalArticle.class.getName());

    _ddmTemplate = DDMTemplateTestUtil.addTemplate(_ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class), TemplateConstants.LANG_TYPE_VM, "$name.getData()");

    String xml = DDMStructureTestUtil.getSampleStructuredContent("name", "Joe Bloggs");

    String content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US",
            UnsecureSAXReaderUtil.read(xml), null,
            "#parse(\"$templatesPath/" + _ddmTemplate.getTemplateKey() + "\")", TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joe Bloggs", content);

    content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US", UnsecureSAXReaderUtil.read(xml),
            null, "#parse(\"$journalTemplatesPath/" + _ddmTemplate.getTemplateKey() + "\")",
            TemplateConstants.LANG_TYPE_VM);

    Assert.assertEquals("Joe Bloggs", content);
}

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

License:Open Source License

@Test
public void testArticleImages() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    Class<?> clazz = getClass();

    ClassLoader classLoader = clazz.getClassLoader();

    String definition = StringUtil.read(classLoader,
            "com/liferay/journal/dependencies" + "/test-ddm-structure-image-field.xml");

    DDMForm ddmForm = _ddmFormXSDDeserializer.deserialize(definition);

    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(serviceContext.getScopeGroupId(),
            JournalArticle.class.getName(), ddmForm);

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(serviceContext.getScopeGroupId(),
            ddmStructure.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class));

    InputStream inputStream = classLoader.getResourceAsStream("/com/liferay/journal/dependencies/liferay.png");

    FileEntry tempFileEntry = TempFileEntryUtil.addTempFileEntry(group.getGroupId(),
            TestPropsValues.getUserId(), JournalArticle.class.getName(), "liferay.png", inputStream,
            ContentTypes.IMAGE_PNG);/*from w w w .j a  v a 2s. co  m*/

    String content = StringUtil.read(classLoader,
            "com/liferay/journal/dependencies/test-journal-content-image-" + "field.xml");

    Document document = SAXReaderUtil.read(content);

    Element dynamicContent = (Element) document.selectSingleNode("//dynamic-content");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("groupId", group.getGroupId());
    jsonObject.put("name", "liferay.png");
    jsonObject.put("tempFile", Boolean.TRUE.toString());
    jsonObject.put("title", "liferay.png");
    jsonObject.put("type", "journal");
    jsonObject.put("uuid", tempFileEntry.getUuid());

    dynamicContent.setText(jsonObject.toString());

    baseModel = JournalTestUtil.addArticleWithXMLContent(JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            document.asXML(), ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), serviceContext);

    JournalArticle article = (JournalArticle) baseModel;

    long folderId = article.getImagesFolderId();

    Assert.assertEquals(1, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId));

    moveBaseModelToTrash((Long) baseModel.getPrimaryKeyObj());

    Assert.assertEquals(0, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId,
            WorkflowConstants.STATUS_APPROVED));
    Assert.assertEquals(1, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId,
            WorkflowConstants.STATUS_IN_TRASH));

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(getBaseModelClassName());

    trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel));

    Assert.assertEquals(0, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId));
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

public static String getTemplateScript(long groupId, String ddmTemplateKey, Map<String, String> tokens,
        String languageId, boolean transform) throws PortalException {

    DDMTemplate ddmTemplate = DDMTemplateLocalServiceUtil.getTemplate(groupId,
            PortalUtil.getClassNameId(DDMStructure.class), ddmTemplateKey, true);

    return getTemplateScript(ddmTemplate, tokens, languageId, transform);
}

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

License:Open Source License

@Before
public void setUp() throws Exception {
    setUpDDMFormJSONDeserializer();/*from   w  w w.j a  va  2 s .c  o  m*/
    setUpDDMFormXSDDeserializer();
    setUpDDMXML();

    _group = GroupTestUtil.addGroup();

    _ddmStructureTestHelper = new DDMStructureTestHelper(PortalUtil.getClassNameId(JournalArticle.class),
            _group);

    _classNameId = PortalUtil.getClassNameId(JournalArticle.class);

    String definition = read("test-ddm-structure-all-fields.xml");

    DDMForm ddmForm = _ddmFormXSDDeserializer.deserialize(definition);

    _ddmStructure = _ddmStructureTestHelper.addStructure(_classNameId, null, "Test Structure", ddmForm,
            StorageType.JSON.getValue(), DDMStructureConstants.TYPE_DEFAULT);

    Registry registry = RegistryUtil.getRegistry();

    _ddmXML = registry.getService(DDMXML.class);
    _journalConverter = registry.getService(JournalConverter.class);
}

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

License:Open Source License

@Test
public void testAddArticleWithDDMStructureAndDDMTemplate() throws Exception {

    String content = DDMStructureTestUtil.getSampleStructuredContent();

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

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class), TemplateConstants.LANG_TYPE_VM,
            JournalTestUtil.getSampleTemplateXSL());

    Assert.assertNotNull(JournalTestUtil.addArticleWithXMLContent(content, ddmStructure.getStructureKey(),
            ddmTemplate.getTemplateKey()));
}