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.JournalArticleLocalServiceTest.java

License:Open Source License

@Test
public void testUpdateDDMStructurePredefinedValues() throws Exception {
    Set<Locale> availableLocales = DDMFormTestUtil.createAvailableLocales(LocaleUtil.BRAZIL, LocaleUtil.FRENCH,
            LocaleUtil.ITALY, LocaleUtil.US);

    DDMForm ddmForm = DDMFormTestUtil.createDDMForm(availableLocales, LocaleUtil.US);

    DDMFormField ddmFormField = DDMFormTestUtil.createLocalizableTextDDMFormField("name");

    LocalizedValue label = new LocalizedValue(LocaleUtil.US);

    label.addString(LocaleUtil.BRAZIL, "rtulo");
    label.addString(LocaleUtil.FRENCH, "tiquette");
    label.addString(LocaleUtil.ITALY, "etichetta");
    label.addString(LocaleUtil.US, "label");

    ddmFormField.setLabel(label);/*from ww w. j  a  v  a 2  s.  c o  m*/

    ddmForm.addDDMFormField(ddmFormField);

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

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

    Map<Locale, String> values = new HashMap<>();

    values.put(LocaleUtil.BRAZIL, "Valor Predefinido");
    values.put(LocaleUtil.FRENCH, "Valeur Prdfinie");
    values.put(LocaleUtil.ITALY, "Valore Predefinito");
    values.put(LocaleUtil.US, "Predefined Value");

    String content = DDMStructureTestUtil.getSampleStructuredContent(values, LocaleUtil.US.toString());

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

    Map<Locale, String> titleMap = new HashMap<>();

    titleMap.put(LocaleUtil.US, "Test Article");

    JournalArticle journalArticle = JournalArticleLocalServiceUtil.addArticle(serviceContext.getUserId(),
            serviceContext.getScopeGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            ClassNameLocalServiceUtil.getClassNameId(DDMStructure.class), ddmStructure.getStructureId(),
            StringPool.BLANK, true, 0, titleMap, null, content, ddmStructure.getStructureKey(),
            ddmTemplate.getTemplateKey(), null, 1, 1, 1965, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true,
            true, false, null, null, null, null, serviceContext);

    DDMStructure actualDDMStrucure = journalArticle.getDDMStructure();

    Assert.assertEquals(actualDDMStrucure.getStructureId(), ddmStructure.getStructureId());

    DDMFormField actualDDMFormField = actualDDMStrucure.getDDMFormField("name");

    Assert.assertNotNull(actualDDMFormField);

    LocalizedValue actualDDMFormFieldPredefinedValue = actualDDMFormField.getPredefinedValue();

    Assert.assertEquals("Valor Predefinido", actualDDMFormFieldPredefinedValue.getString(LocaleUtil.BRAZIL));
    Assert.assertEquals("Valeur Prdfinie", actualDDMFormFieldPredefinedValue.getString(LocaleUtil.FRENCH));
    Assert.assertEquals("Valore Predefinito", actualDDMFormFieldPredefinedValue.getString(LocaleUtil.ITALY));
    Assert.assertEquals("Predefined Value", actualDDMFormFieldPredefinedValue.getString(LocaleUtil.US));
}

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

License:Open Source License

protected JournalArticle addArticle(long groupId, Date displayDate, int when, boolean approved)
        throws Exception {

    Map<Locale, String> titleMap = new HashMap<>();

    titleMap.put(LocaleUtil.getDefault(), RandomTestUtil.randomString());

    Map<Locale, String> descriptionMap = new HashMap<>();

    descriptionMap.put(LocaleUtil.getDefault(), RandomTestUtil.randomString());

    String content = DDMStructureTestUtil.getSampleStructuredContent();

    DDMForm ddmForm = DDMStructureTestUtil.getSampleDDMForm();

    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(groupId, JournalArticle.class.getName(),
            ddmForm);/*from w w  w .  ja  v a2  s.co  m*/

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

    Calendar displayDateCalendar = getCalendar(displayDate, when);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId);

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

    return JournalArticleLocalServiceUtil.addArticle(TestPropsValues.getUserId(), groupId,
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, JournalArticleConstants.CLASSNAME_ID_DEFAULT, 0,
            StringPool.BLANK, true, JournalArticleConstants.VERSION_DEFAULT, titleMap, descriptionMap, content,
            ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), null,
            displayDateCalendar.get(Calendar.MONTH), displayDateCalendar.get(Calendar.DAY_OF_MONTH),
            displayDateCalendar.get(Calendar.YEAR), displayDateCalendar.get(Calendar.HOUR_OF_DAY),
            displayDateCalendar.get(Calendar.MINUTE), 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false,
            null, null, null, null, serviceContext);
}

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

License:Open Source License

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

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

    String content = "<?xml version=\"1.0\"?><root></root>";

    JournalArticle article = JournalTestUtil.addArticleWithXMLContent(content, ddmStructure.getStructureKey(),
            ddmTemplate.getTemplateKey());

    checkArticleMatchesStructure(article, ddmStructure);
}

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

License:Open Source License

@Test
public void testDeleteTemplateReferencedByJournalArticles() throws Exception {

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

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

    JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(), "<title>Test Article</title>",
            ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey());

    try {/*from  w w w. j av a2  s  . com*/
        DDMTemplateLocalServiceUtil.deleteTemplate(ddmTemplate.getTemplateId());

        Assert.fail();
    } catch (RequiredTemplateException rte) {
    }
}

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

License:Open Source License

protected void testAddArticleRequiredFields(String ddmStructureDefinition, String journalArticleContent,
        Map<String, String> requiredFields) throws Exception {

    String definition = readText(ddmStructureDefinition);

    DDMForm ddmForm = _ddmFormXSDDeserializer.deserialize(definition);

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

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

    String xmlContent = readText(journalArticleContent);

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

    for (Map.Entry<String, String> entry : requiredFields.entrySet()) {
        Assert.assertTrue(ddmStructure.getFieldRequired(entry.getKey()));

        serviceContext.setAttribute(entry.getKey(), entry.getValue());
    }/*ww w .  j  a  v a2 s.c  om*/

    JournalTestUtil.addArticleWithXMLContent(JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, xmlContent, ddmStructure.getStructureKey(),
            ddmTemplate.getTemplateKey(), LocaleUtil.fromLanguageId(ddmStructure.getDefaultLanguageId()),
            serviceContext);
}

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

License:Open Source License

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

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

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

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

    JournalFolderLocalServiceUtil.updateFolder(TestPropsValues.getUserId(), serviceContext.getScopeGroupId(),
            folder.getFolderId(), folder.getParentFolderId(), folder.getName(), folder.getDescription(),
            ddmStructureIds, JournalFolderConstants.RESTRICTION_TYPE_DDM_STRUCTURES_AND_WORKFLOW, false,
            serviceContext);//from  ww  w. j av  a2 s .c  om

    List<DDMStructure> ddmStructures = JournalFolderLocalServiceUtil.getDDMStructures(
            PortalUtil.getCurrentAndAncestorSiteGroupIds(_group.getGroupId()), folder.getFolderId(),
            JournalFolderConstants.RESTRICTION_TYPE_DDM_STRUCTURES_AND_WORKFLOW);

    Assert.assertFalse(ddmStructures.isEmpty());

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

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

    DDMTemplate ddmTemplate2 = DDMTemplateTestUtil.addTemplate(_group.getGroupId(),
            ddmStructure2.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class),
            LocaleUtil.getDefault());

    try {
        JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(), folder.getFolderId(),
                JournalArticleConstants.CLASSNAME_ID_DEFAULT, xml, ddmStructure2.getStructureKey(),
                ddmTemplate2.getTemplateKey());

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

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

    try {
        JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(), subfolder.getFolderId(),
                JournalArticleConstants.CLASSNAME_ID_DEFAULT, xml, ddmStructure2.getStructureKey(),
                ddmTemplate2.getTemplateKey());

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

    JournalFolderLocalServiceUtil.deleteFolder(folder.getFolderId());

    ddmStructures = JournalFolderLocalServiceUtil.getDDMStructures(
            PortalUtil.getCurrentAndAncestorSiteGroupIds(_group.getGroupId()), folder.getFolderId(),
            JournalFolderConstants.RESTRICTION_TYPE_DDM_STRUCTURES_AND_WORKFLOW);

    Assert.assertTrue(ddmStructures.isEmpty());
}

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

License:Open Source License

@Test
public void testMoveArticleFromTrashToFolder() throws Exception {
    JournalFolder folder1 = 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());/* w w w.j  a  v  a  2 s  .  c o  m*/

    JournalArticle article = JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(),
            folder1.getFolderId(), JournalArticleConstants.CLASSNAME_ID_DEFAULT, xml,
            ddmStructure1.getStructureKey(), ddmTemplate1.getTemplateKey());

    JournalFolderLocalServiceUtil.moveFolderToTrash(TestPropsValues.getUserId(), folder1.getFolderId());

    JournalFolder folder2 = JournalTestUtil.addFolder(_group.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 2");

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

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

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

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

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(JournalArticle.class.getName());

    try {
        trashHandler.checkRestorableEntry(article.getResourcePrimKey(), folder2.getFolderId(), null);

        Assert.fail();
    } catch (RestoreEntryException ree) {
    }

    JournalFolder subfolder = JournalTestUtil.addFolder(_group.getGroupId(), folder2.getFolderId(), "Test 2.1");

    try {
        trashHandler.checkRestorableEntry(article.getResourcePrimKey(), subfolder.getFolderId(), null);

        Assert.fail();
    } catch (RestoreEntryException ree) {
    }
}

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

License:Open Source License

@Test
public void testMoveArticleToRestrictedFolder() throws Exception {
    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  w w . j a  v a  2  s  .  c  om*/

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

    JournalArticle article = JournalTestUtil.addArticleWithXMLContent(_group.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, JournalArticleConstants.CLASSNAME_ID_DEFAULT, xml,
            ddmStructure1.getStructureKey(), ddmTemplate1.getTemplateKey());

    JournalFolder folder = JournalTestUtil.addFolder(_group.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 1");

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

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

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

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

    try {
        JournalArticleLocalServiceUtil.moveArticle(_group.getGroupId(), article.getArticleId(),
                folder.getFolderId(), serviceContext);

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

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

    try {
        JournalArticleLocalServiceUtil.moveArticle(_group.getGroupId(), article.getArticleId(),
                subfolder.getFolderId(), serviceContext);

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

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

License:Open Source License

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

    JournalFolder folder2 = JournalTestUtil.addFolder(_group.getGroupId(), folder1.getFolderId(), "Test 2");

    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  w w. j a  va 2  s .c o  m

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

    JournalFolderLocalServiceUtil.moveFolderToTrash(TestPropsValues.getUserId(), folder1.getFolderId());

    JournalFolder folder3 = JournalTestUtil.addFolder(_group.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 3");

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

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

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

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

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(JournalFolder.class.getName());

    try {
        trashHandler.checkRestorableEntry(folder2.getFolderId(), folder3.getFolderId(), null);

        Assert.fail();
    } catch (RestoreEntryException ree) {
    }

    JournalFolder subfolder = JournalTestUtil.addFolder(_group.getGroupId(), folder3.getFolderId(), "Test 3.1");

    try {
        trashHandler.checkRestorableEntry(folder2.getFolderId(), subfolder.getFolderId(), null);

        Assert.fail();
    } catch (RestoreEntryException ree) {
    }
}

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

License:Open Source License

@Test
public void testMoveFolderWithAnArticleToFolder() throws Exception {
    JournalFolder folder1 = 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());//  w  ww  . ja  v  a  2s . com

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

    JournalFolder folder2 = JournalTestUtil.addFolder(_group.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test 2");

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

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

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

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

    try {
        JournalFolderLocalServiceUtil.moveFolder(folder1.getFolderId(), folder2.getFolderId(), serviceContext);

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

    JournalFolder subfolder = JournalTestUtil.addFolder(_group.getGroupId(), folder2.getFolderId(), "Test 2.1");

    try {
        JournalFolderLocalServiceUtil.moveFolder(folder1.getFolderId(), subfolder.getFolderId(),
                serviceContext);

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