Example usage for com.liferay.portal.kernel.service LayoutLocalServiceUtil fetchLayoutByUuidAndGroupId

List of usage examples for com.liferay.portal.kernel.service LayoutLocalServiceUtil fetchLayoutByUuidAndGroupId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service LayoutLocalServiceUtil fetchLayoutByUuidAndGroupId.

Prototype

public static com.liferay.portal.kernel.model.Layout fetchLayoutByUuidAndGroupId(String uuid, long groupId,
        boolean privateLayout) 

Source Link

Document

Returns the layout matching the UUID, group, and privacy.

Usage

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

@Test
public void testSeveralLayoutScopeIds() throws Exception {
    Company company = CompanyLocalServiceUtil.getCompany(layout.getCompanyId());

    Layout secondLayout = LayoutTestUtil.addLayout(group);

    GroupTestUtil.addGroup(TestPropsValues.getUserId(), secondLayout);

    Map<String, String[]> preferenceMap = new HashMap<>();

    GroupTestUtil.addGroup(TestPropsValues.getUserId(), layout);

    Group companyGroup = company.getGroup();

    preferenceMap.put("scopeIds",
            new String[] { AssetPublisherHelper.SCOPE_ID_GROUP_PREFIX + companyGroup.getGroupId(),
                    AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX + layout.getUuid(),
                    AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX + secondLayout.getUuid() });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    Layout importedSecondLayout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(secondLayout.getUuid(),
            importedGroup.getGroupId(), importedLayout.isPrivateLayout());

    Assert.assertEquals(null, portletPreferences.getValue("scopeId", null));

    StringBundler sb = new StringBundler(8);

    sb.append(AssetPublisherHelper.SCOPE_ID_GROUP_PREFIX);
    sb.append(companyGroup.getGroupId());
    sb.append(StringPool.COMMA);//w w  w  .  j  a  v  a2 s .c o m
    sb.append(AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX);
    sb.append(importedLayout.getUuid());
    sb.append(StringPool.COMMA);
    sb.append(AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX);
    sb.append(importedSecondLayout.getUuid());

    Assert.assertEquals(sb.toString(), StringUtil.merge(portletPreferences.getValues("scopeIds", null)));
}

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

@Test
public void testSeveralLegacyLayoutScopeIds() throws Exception {
    Layout secondLayout = LayoutTestUtil.addLayout(group);

    GroupTestUtil.addGroup(TestPropsValues.getUserId(), secondLayout);

    Map<String, String[]> preferenceMap = new HashMap<>();

    GroupTestUtil.addGroup(TestPropsValues.getUserId(), layout);

    preferenceMap.put("scopeIds",
            new String[] { AssetPublisherHelper.SCOPE_ID_LAYOUT_PREFIX + layout.getLayoutId(),
                    AssetPublisherHelper.SCOPE_ID_LAYOUT_PREFIX + secondLayout.getLayoutId() });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    Layout importedSecondLayout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(secondLayout.getUuid(),
            importedGroup.getGroupId(), importedLayout.isPrivateLayout());

    Assert.assertEquals(null, portletPreferences.getValue("scopeId", null));

    StringBundler sb = new StringBundler(5);

    sb.append(AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX);
    sb.append(importedLayout.getUuid());
    sb.append(StringPool.COMMA);/* w w w.  j  a v a2  s. c  o  m*/
    sb.append(AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX);
    sb.append(importedSecondLayout.getUuid());

    Assert.assertEquals(sb.toString(), StringUtil.merge(portletPreferences.getValues("scopeIds", null)));
}

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

@Override
protected void exportImportPortlet(String portletId) throws Exception {
    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(layout.getGroupId(), layout.isPrivateLayout());

    User user = TestPropsValues.getUser();

    Map<String, Serializable> exportLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildExportLayoutSettingsMap(user, layout.getGroupId(), layout.isPrivateLayout(),
                    ExportImportHelperUtil.getLayoutIds(layouts), getExportParameterMap());

    ExportImportConfiguration exportConfiguration = ExportImportConfigurationLocalServiceUtil
            .addDraftExportImportConfiguration(user.getUserId(),
                    ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT, exportLayoutSettingsMap);

    larFile = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportConfiguration);

    // Import site LAR

    Map<String, Serializable> importLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildImportLayoutSettingsMap(user, importedGroup.getGroupId(), layout.isPrivateLayout(), null,
                    getImportParameterMap());

    ExportImportConfiguration importConfiguration = ExportImportConfigurationLocalServiceUtil
            .addDraftExportImportConfiguration(user.getUserId(),
                    ExportImportConfigurationConstants.TYPE_IMPORT_LAYOUT, importLayoutSettingsMap);

    ExportImportLocalServiceUtil.importLayouts(importConfiguration, larFile);

    importedLayout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout.getUuid(),
            importedGroup.getGroupId(), layout.isPrivateLayout());

    Assert.assertNotNull(importedLayout);
}

From source file:com.liferay.exportimport.internal.content.processor.test.DefaultExportImportContentProcessorTest.java

License:Open Source License

@Test
public void testImportLinksToLayoutsIdsReplacement() throws Exception {
    LayoutTestUtil.addLayout(_liveGroup, true);
    LayoutTestUtil.addLayout(_liveGroup, false);

    exportImportLayouts(true);//from w ww. j  a v a  2s.com
    exportImportLayouts(false);

    Layout importedPrivateLayout = LayoutLocalServiceUtil
            .fetchLayoutByUuidAndGroupId(_stagingPrivateLayout.getUuid(), _liveGroup.getGroupId(), true);
    Layout importedPublicLayout = LayoutLocalServiceUtil
            .fetchLayoutByUuidAndGroupId(_stagingPublicLayout.getUuid(), _liveGroup.getGroupId(), false);

    Map<Long, Long> layoutPlids = (Map<Long, Long>) _portletDataContextImport
            .getNewPrimaryKeysMap(Layout.class);

    layoutPlids.put(_stagingPrivateLayout.getPlid(), importedPrivateLayout.getPlid());
    layoutPlids.put(_stagingPublicLayout.getPlid(), importedPublicLayout.getPlid());

    String content = getContent("layout_links_ids_replacement.txt");

    String expectedContent = replaceLinksToLayoutsParameters(content, importedPrivateLayout,
            importedPublicLayout);

    content = replaceLinksToLayoutsParameters(content, _stagingPrivateLayout, _stagingPublicLayout);

    content = _exportImportContentProcessor.replaceExportContentReferences(_portletDataContextExport,
            _referrerStagedModel, content, true, true);

    String importedContent = _exportImportContentProcessor
            .replaceImportContentReferences(_portletDataContextImport, _referrerStagedModel, content);

    Assert.assertEquals(expectedContent, importedContent);
}

From source file:com.liferay.exportimport.test.LayoutExportImportTest.java

License:Open Source License

@Test
public void testDeleteMissingLayouts() throws Exception {
    Layout layout1 = LayoutTestUtil.addLayout(group);
    Layout layout2 = LayoutTestUtil.addLayout(group);

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false);

    long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layouts);

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(LayoutLocalServiceUtil.getLayoutsCount(group, false),
            LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    LayoutTestUtil.addLayout(importedGroup);

    Map<String, String[]> parameterMap = getImportParameterMap();

    parameterMap.put(PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS, new String[] { Boolean.TRUE.toString() });

    layoutIds = new long[] { layout1.getLayoutId() };

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(LayoutLocalServiceUtil.getLayoutsCount(group, false),
            LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    Layout importedLayout1 = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout1.getUuid(),
            importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout1);

    Layout importedLayout2 = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout2.getUuid(),
            importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout2);
}

From source file:com.liferay.exportimport.test.LayoutExportImportTest.java

License:Open Source License

@Test
public void testExportImportLayoutsPriorities() throws Exception {
    Layout layout1 = LayoutTestUtil.addLayout(group);
    Layout layout2 = LayoutTestUtil.addLayout(group);
    Layout layout3 = LayoutTestUtil.addLayout(group);

    int priority = layout1.getPriority();

    layout1.setPriority(layout3.getPriority());
    layout3.setPriority(priority);//from w ww.j a  va 2s .  c o  m

    layout1 = LayoutLocalServiceUtil.updateLayout(layout1);
    layout3 = LayoutLocalServiceUtil.updateLayout(layout3);

    long[] layoutIds = { layout1.getLayoutId(), layout2.getLayoutId() };

    exportImportLayouts(layoutIds, getImportParameterMap());

    Layout importedLayout1 = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout1.getUuid(),
            importedGroup.getGroupId(), false);

    Assert.assertNotEquals(layout1.getPriority(), importedLayout1.getPriority());

    Layout importedLayout2 = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout2.getUuid(),
            importedGroup.getGroupId(), false);

    Assert.assertNotEquals(layout2.getPriority(), importedLayout2.getPriority());

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false);

    layoutIds = ExportImportHelperUtil.getLayoutIds(layouts);

    exportImportLayouts(layoutIds, getImportParameterMap());

    importedLayout1 = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout1.getUuid(),
            importedGroup.getGroupId(), false);

    Assert.assertEquals(layout1.getPriority(), importedLayout1.getPriority());

    importedLayout2 = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout2.getUuid(),
            importedGroup.getGroupId(), false);

    Assert.assertEquals(layout2.getPriority(), importedLayout2.getPriority());

    Layout importedLayout3 = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout3.getUuid(),
            importedGroup.getGroupId(), false);

    Assert.assertEquals(layout3.getPriority(), importedLayout3.getPriority());
}

From source file:com.liferay.exportimport.test.LayoutExportImportTest.java

License:Open Source License

@Test
public void testExportImportSelectedLayouts() throws Exception {
    Layout layout = LayoutTestUtil.addLayout(group);

    long[] layoutIds = { layout.getLayoutId() };

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(layoutIds.length, LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    importedLayout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout.getUuid(),
            importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout);
}

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

License:Open Source License

public static Layout getArticleLayout(String layoutUuid, long groupId) {
    if (Validator.isNull(layoutUuid)) {
        return null;
    }/*from   w  ww . j  a  v a 2  s .com*/

    // The target page and the article must belong to the same group

    Layout layout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layoutUuid, groupId, false);

    if (layout == null) {
        layout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layoutUuid, groupId, true);
    }

    return layout;
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.test.LayoutStagedModelDataHandlerTest.java

License:Open Source License

@Override
protected StagedModel getStagedModel(String uuid, Group group) {
    try {//from w  ww  .  j  a  v a  2  s  .c  om
        return LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(uuid, group.getGroupId(), false);
    } catch (Exception e) {
        return null;
    }
}

From source file:com.liferay.layout.prototype.internal.exportimport.data.handler.test.LayoutPrototypeStagedModelDataHandlerTest.java

License:Open Source License

@Override
protected void validateImport(StagedModel stagedModel, StagedModelAssets stagedModelAssets,
        Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception {

    LayoutPrototype importedLayoutPrototype = (LayoutPrototype) getStagedModel(stagedModel.getUuid(), group);

    Assert.assertNotNull(importedLayoutPrototype);

    List<StagedModel> layoutDependentStagedModels = dependentStagedModelsMap.get(Layout.class.getSimpleName());

    Assert.assertEquals(layoutDependentStagedModels.toString(), 1, layoutDependentStagedModels.size());

    Layout layout = (Layout) layoutDependentStagedModels.get(0);

    Layout importedLayout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layout.getUuid(),
            importedLayoutPrototype.getGroupId(), layout.isPrivateLayout());

    Assert.assertNotNull(importedLayout);
    Assert.assertEquals(/*from   ww  w . j ava  2  s.  c om*/
            layout.getTypeSettingsProperty(LayoutPrototypeStagedModelDataHandlerTest.class.getName()),
            importedLayout.getTypeSettingsProperty(LayoutPrototypeStagedModelDataHandlerTest.class.getName()));

    List<StagedModel> layoutFriendlyURLDependentStagedModels = dependentStagedModelsMap
            .get(LayoutFriendlyURL.class.getSimpleName());

    LayoutFriendlyURL layoutFriendlyURL = (LayoutFriendlyURL) layoutFriendlyURLDependentStagedModels.get(0);

    LayoutFriendlyURL importedLayoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil
            .fetchLayoutFriendlyURLByUuidAndGroupId(layoutFriendlyURL.getUuid(), importedLayout.getGroupId());

    Assert.assertNotNull(importedLayoutFriendlyURL);
    Assert.assertEquals(layoutFriendlyURL.getFriendlyURL(), importedLayoutFriendlyURL.getFriendlyURL());
}