List of usage examples for com.liferay.portal.kernel.service PortletLocalServiceUtil getPortletById
public static com.liferay.portal.kernel.model.Portlet getPortletById(String portletId)
From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java
License:Open Source License
@JSONWebService(value = "/set-portlet-configuration") public JSONObject setPortletConfiguration(long companyId, long plid, String portletId, String preferences) { JSONObject returnobject = JSONFactoryUtil.createJSONObject(); System.out.println("-------------------------"); System.out.println("PortletConfiguration"); System.out.println("companyId:" + companyId + " plid:" + plid + " portletId:" + portletId + " preferences:" + preferences);//w w w. j ava 2s . c o m returnobject.put("companyId", companyId); returnobject.put("plid", plid); returnobject.put("portletId", portletId); returnobject.put("preferences", preferences); Layout layout; try { layout = LayoutLocalServiceUtil.getLayout(plid); System.out.println("ModelClassName" + layout.getModelClassName()); } catch (PortalException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<PortletPreferences> portletpreferences = PortletPreferencesLocalServiceUtil.getPortletPreferences(plid, portletId); System.out.println(portletpreferences.size()); if (portletpreferences.size() == 0) { long ownerId = 0; Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId); PortletPreferencesLocalServiceUtil.addPortletPreferences(companyId, ownerId, PortletKeys.PREFS_OWNER_TYPE_LAYOUT, plid, portletId, portlet, preferences); } else { for (PortletPreferences portletpreference : portletpreferences) { portletpreference.setPreferences(preferences); PortletPreferencesLocalServiceUtil.updatePortletPreferences(portletpreference); } } System.out.println("PortletConfiguration ... end"); return returnobject; }
From source file:com.liferay.exportimport.internal.background.task.display.PortletExportImportBackgroundTaskDisplay.java
License:Open Source License
public PortletExportImportBackgroundTaskDisplay(BackgroundTask backgroundTask) { super(backgroundTask); try {/*from w w w. j av a2s . co m*/ Map<String, Serializable> taskContextMap = backgroundTask.getTaskContextMap(); ExportImportConfiguration exportImportConfiguration = ExportImportConfigurationLocalServiceUtil .getExportImportConfiguration(MapUtil.getLong(taskContextMap, "exportImportConfigurationId")); if ((exportImportConfiguration.getType() != ExportImportConfigurationConstants.TYPE_EXPORT_PORTLET) && (exportImportConfiguration .getType() != ExportImportConfigurationConstants.TYPE_IMPORT_PORTLET) && (exportImportConfiguration .getType() != ExportImportConfigurationConstants.TYPE_PUBLISH_PORTLET)) { throw new PortalException( "Invalid export import configuration type: " + exportImportConfiguration.getType()); } portlet = PortletLocalServiceUtil.getPortletById(backgroundTask.getName()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.liferay.exportimport.test.PortletDataContextReferencesTest.java
License:Open Source License
@Test public void testCleanUpMissingReferences() throws Exception { _portletDataContext.setPortletId(JournalContentPortletKeys.JOURNAL_CONTENT); Portlet portlet = PortletLocalServiceUtil.getPortletById(JournalContentPortletKeys.JOURNAL_CONTENT); AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(_group.getGroupId()); AssetCategory assetCategory = AssetTestUtil.addCategory(_group.getGroupId(), assetVocabulary.getVocabularyId()); _portletDataContext.addReferenceElement(portlet, _portletDataContext.getExportDataRootElement(), assetCategory, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); Element missingReferencesElement = _portletDataContext.getMissingReferencesElement(); List<Element> missingReferenceElements = missingReferencesElement.elements(); Assert.assertFalse(missingReferenceElements.toString(), missingReferenceElements.isEmpty()); Assert.assertEquals(missingReferenceElements.toString(), 1, missingReferenceElements.size()); StagedModelDataHandlerUtil.exportStagedModel(_portletDataContext, assetCategory); missingReferenceElements = missingReferencesElement.elements(); Assert.assertFalse(missingReferenceElements.toString(), missingReferenceElements.isEmpty()); Assert.assertEquals(missingReferenceElements.toString(), 1, missingReferenceElements.size()); Element missingReferenceElement = missingReferenceElements.get(0); Assert.assertNull(missingReferenceElement.attribute("missing")); Assert.assertFalse(Validator.isBlank(missingReferenceElement.attributeValue("element-path"))); }
From source file:com.liferay.exportimport.test.PortletDataContextReferencesTest.java
License:Open Source License
@Test public void testMultipleMissingReferences() throws Exception { Portlet portlet = PortletLocalServiceUtil.getPortletById(JournalContentPortletKeys.JOURNAL_CONTENT); _portletDataContext.addReferenceElement(portlet, _portletDataContext.getExportDataRootElement(), _bookmarksEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); _portletDataContext.addReferenceElement(portlet, _portletDataContext.getExportDataRootElement(), _bookmarksEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); Element missingReferencesElement = _portletDataContext.getMissingReferencesElement(); List<Element> missingReferenceElements = missingReferencesElement.elements(); Assert.assertFalse(missingReferenceElements.toString(), missingReferenceElements.isEmpty()); Assert.assertEquals(missingReferenceElements.toString(), 1, missingReferenceElements.size()); Element missingReferenceElement = missingReferenceElements.get(0); Assert.assertEquals(BookmarksEntry.class.getName(), missingReferenceElement.attributeValue("class-name")); Assert.assertEquals(String.valueOf(_bookmarksEntry.getPrimaryKeyObj()), missingReferenceElement.attributeValue("class-pk")); }
From source file:com.liferay.exportimport.test.PortletPreferencesExportImportTest.java
License:Open Source License
@Test public void testExportImportGroupEmbeddedPortletPreferences() throws Exception { String portletInstanceId = PortletIdCodec.encode(JournalContentPortletKeys.JOURNAL_CONTENT, "1234"); Portlet portlet = PortletLocalServiceUtil.getPortletById(JournalContentPortletKeys.JOURNAL_CONTENT); String portletPreferencesXML = _getPortletPreferencesXML("name", new String[] { "value" }); _addGroupEmbeddedPortlet(portletInstanceId, portlet, portletPreferencesXML); exportImportLayouts(new long[] { layout.getLayoutId() }, getImportParameterMap()); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getLayoutPortletSetup( importedGroup.getCompanyId(), importedGroup.getGroupId(), PortletKeys.PREFS_OWNER_TYPE_LAYOUT, PortletKeys.PREFS_PLID_SHARED, portletInstanceId, PortletConstants.DEFAULT_PREFERENCES); Assert.assertEquals("value", portletPreferences.getValue("name", StringPool.BLANK)); }