/** * Returns the ID of the class from its class object. * * @param clazz the class object * @return the ID of the class */ public static long getClassNameId(Class<?> clazz) { return getPortal().getClassNameId(clazz); }
/** * Returns the ID of the class from its fully qualified name. * * @param value the fully qualified name of the class * @return the ID of the class */ public static long getClassNameId(String value) { return getPortal().getClassNameId(value); }
protected synchronized void removeTemplateHandler( TemplateHandler templateHandler) { String className = templateHandler.getClassName(); _classNameTemplateHandlers.remove(className); if (_portal != null) { _classNameIdTemplateHandlers.remove( _portal.getClassNameId(className)); } ServiceRegistration<?> serviceRegistration = _serviceRegistrations.remove(className); if (serviceRegistration != null) { serviceRegistration.unregister(); } }
@Activate protected synchronized void activate(BundleContext bundleContext) { _bundleContext = bundleContext; for (Map.Entry<String, TemplateHandler> entry : _classNameTemplateHandlers.entrySet()) { String className = entry.getKey(); TemplateHandler templateHandler = entry.getValue(); _classNameIdTemplateHandlers.put( _portal.getClassNameId(className), templateHandler); if (_serviceRegistrations.containsKey(className)) { continue; } registerPortalInstanceLifecycleListener(templateHandler); } }
@Reference( cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY ) protected synchronized void addTemplateHandler( TemplateHandler templateHandler) { String className = templateHandler.getClassName(); _classNameTemplateHandlers.put(className, templateHandler); if (_bundleContext == null) { return; } _classNameIdTemplateHandlers.put( _portal.getClassNameId(className), templateHandler); registerPortalInstanceLifecycleListener(templateHandler); }
@Override protected boolean countStagedModel( PortletDataContext portletDataContext, JournalArticle article) { if (article.getClassNameId() == _portal.getClassNameId( DDMStructure.class)) { return false; } return !portletDataContext.isModelCounted( JournalArticleResource.class.getName(), article.getResourcePrimKey()); }
@Override public DDMStructure fetchStructure(DDMTemplate template) { try { long classNameId = _portal.getClassNameId(DDMStructure.class); if (template.getClassNameId() == classNameId) { return _ddmStructureLocalService.fetchDDMStructure( template.getClassPK()); } } catch (Exception e) { } return null; }
@Override public DDMForm getDDMForm(long classNameId, long classPK) throws PortalException { if ((classNameId <= 0) || (classPK <= 0)) { return null; } long ddmStructureClassNameId = _portal.getClassNameId( DDMStructure.class); long ddmTemplateClassNameId = _portal.getClassNameId(DDMTemplate.class); if (classNameId == ddmStructureClassNameId) { DDMStructure structure = DDMStructureLocalServiceUtil.getStructure( classPK); DDMForm ddmForm = structure.getFullHierarchyDDMForm(); return ddmForm; } else if (classNameId == ddmTemplateClassNameId) { DDMTemplate template = DDMTemplateLocalServiceUtil.getTemplate( classPK); return _ddmFormJSONDeserializer.deserialize(template.getScript()); } return null; }
private void _exportAssetDisplayPage( PortletDataContext portletDataContext, JournalArticle article) throws PortletDataException { AssetDisplayPageEntry assetDisplayPageEntry = _assetDisplayPageEntryLocalService.fetchAssetDisplayPageEntry( article.getGroupId(), _portal.getClassNameId(JournalArticle.class), article.getResourcePrimKey()); if (assetDisplayPageEntry != null) { StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, article, assetDisplayPageEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY); } }
@Override public String getTemplateScript( long groupId, String ddmTemplateKey, Map<String, String> tokens, String languageId) throws PortalException { DDMTemplate ddmTemplate = _ddmTemplateLocalService.getTemplate( groupId, _portal.getClassNameId(DDMStructure.class), ddmTemplateKey, true); String script = ddmTemplate.getScript(); for (TransformerListener transformerListener : JournalTransformerListenerRegistryUtil. getTransformerListeners()) { script = transformerListener.onScript( script, null, languageId, tokens); } return script; }
private void _exportFriendlyURLEntries( PortletDataContext portletDataContext, JournalArticle article) throws PortletDataException { long classNameId = _portal.getClassNameId(JournalArticle.class); List<FriendlyURLEntry> friendlyURLEntries = _friendlyURLEntryLocalService.getFriendlyURLEntries( article.getGroupId(), classNameId, article.getResourcePrimKey()); for (FriendlyURLEntry friendlyURLEntry : friendlyURLEntries) { StagedModelDataHandlerUtil.exportStagedModel( portletDataContext, friendlyURLEntry); StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, friendlyURLEntry, article, PortletDataContext.REFERENCE_TYPE_DEPENDENCY); } }
@Override protected PortletPreferences doDeleteData( PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception { if (portletDataContext.addPrimaryKey( JournalPortletDataHandler.class, "deleteData")) { return portletPreferences; } _journalArticleLocalService.deleteArticles( portletDataContext.getScopeGroupId()); _journalFolderLocalService.deleteFolders( portletDataContext.getGroupId()); _ddmTemplateLocalService.deleteTemplates( portletDataContext.getScopeGroupId(), _portal.getClassNameId(DDMStructure.class)); _ddmStructureLocalService.deleteStructures( portletDataContext.getScopeGroupId(), _portal.getClassNameId(JournalArticle.class)); return portletPreferences; }
protected ActionableDynamicQuery getDDMStructureActionableDynamicQuery( final PortletDataContext portletDataContext) { ExportActionableDynamicQuery exportActionableDynamicQuery = _ddmStructureLocalService.getExportActionableDynamicQuery( portletDataContext); final ActionableDynamicQuery.AddCriteriaMethod addCriteriaMethod = exportActionableDynamicQuery.getAddCriteriaMethod(); exportActionableDynamicQuery.setAddCriteriaMethod( dynamicQuery -> { addCriteriaMethod.addCriteria(dynamicQuery); Property classNameIdProperty = PropertyFactoryUtil.forName( "classNameId"); long classNameId = _portal.getClassNameId(JournalArticle.class); dynamicQuery.add(classNameIdProperty.eq(classNameId)); }); exportActionableDynamicQuery.setStagedModelType( new StagedModelType( DDMStructure.class.getName(), JournalArticle.class.getName())); return exportActionableDynamicQuery; }
@Override protected void doReindex(JournalArticle article) throws Exception { if (_portal.getClassNameId(DDMStructure.class) == article.getClassNameId()) { Document document = getDocument(article); _indexWriterHelper.deleteDocument( getSearchEngineId(), article.getCompanyId(), document.get(Field.UID), isCommitImmediately()); return; } reindexArticleVersions(article); }
@Override public long doCreate( long companyId, long ddmStructureId, DDMFormValues ddmFormValues, ServiceContext serviceContext) throws Exception { validate(ddmFormValues, serviceContext); long classNameId = _portal.getClassNameId(DDMContent.class.getName()); String serializedDDMFormValues = _ddmFormValuesJSONSerializer.serialize( ddmFormValues); DDMContent ddmContent = _ddmContentLocalService.addContent( serviceContext.getUserId(), serviceContext.getScopeGroupId(), DDMStorageLink.class.getName(), null, serializedDDMFormValues, serviceContext); DDMStructure ddmStructure = _ddmStructureLocalService.getDDMStructure( ddmStructureId); DDMStructureVersion ddmStructureVersion = ddmStructure.getLatestStructureVersion(); _ddmStorageLinkLocalService.addStorageLink( classNameId, ddmContent.getPrimaryKey(), ddmStructureVersion.getStructureVersionId(), serviceContext); return ddmContent.getPrimaryKey(); }
@Override public void contribute(Document document, BaseModel baseModel) { String className = document.get(Field.ENTRY_CLASS_NAME); long classNameId = portal.getClassNameId(className); long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); List<AssetTag> assetTags = assetTagLocalService.getTags( classNameId, classPK); if (ListUtil.isEmpty(assetTags)) { return; } contributeAssetTagIds(document, assetTags); contributeAssetTagNamesLocalized(document, assetTags, baseModel); contributeAssetTagNamesRaw(document, assetTags); }
@Override public void portalInstanceRegistered(Company company) throws Exception { if (!_journalServiceConfiguration.addDefaultStructures()) { return; } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGuestPermissions(true); serviceContext.setAddGroupPermissions(true); Group group = _groupLocalService.getCompanyGroup( company.getCompanyId()); serviceContext.setScopeGroupId(group.getGroupId()); long defaultUserId = _userLocalService.getDefaultUserId( company.getCompanyId()); serviceContext.setUserId(defaultUserId); Class<?> clazz = getClass(); _defaultDDMStructureHelper.addDDMStructures( defaultUserId, group.getGroupId(), _portal.getClassNameId(JournalArticle.class), clazz.getClassLoader(), "com/liferay/journal/internal/upgrade/v1_0_0/dependencies" + "/basic-web-content-structure.xml", serviceContext); }
protected String extractDDMContent( JournalArticle article, String languageId) throws Exception { DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure( _portal.getSiteGroupId(article.getGroupId()), _portal.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); if (ddmStructure == null) { return StringPool.BLANK; } DDMFormValues ddmFormValues = null; try { Fields fields = _journalConverter.getDDMFields( ddmStructure, article.getDocument()); ddmFormValues = _fieldsToDDMFormValuesConverter.convert( ddmStructure, fields); } catch (Exception e) { return StringPool.BLANK; } if (ddmFormValues == null) { return StringPool.BLANK; } return _ddmIndexer.extractIndexableAttributes( ddmStructure, ddmFormValues, LocaleUtil.fromLanguageId(languageId)); }
protected String getLockPath( PortletDataContext portletDataContext, String className, String key, Lock lock) { StringBundler sb = new StringBundler(8); sb.append(ExportImportPathUtil.getRootPath(portletDataContext)); sb.append("/locks/"); sb.append(_portal.getClassNameId(className)); sb.append(CharPool.FORWARD_SLASH); sb.append(key); sb.append(CharPool.FORWARD_SLASH); sb.append(lock.getLockId()); sb.append(".xml"); return sb.toString(); }
protected void checkValidContainer(long classPK, long containerModelId) throws PortalException { JournalArticle article = _journalArticleLocalService.getLatestArticle( classPK); DDMStructure ddmStructure = _ddmStructureLocalService.getStructure( _portal.getSiteGroupId(article.getGroupId()), _portal.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); if (containerModelId == TrashEntryConstants.DEFAULT_CONTAINER_ID) { containerModelId = article.getFolderId(); } int restrictionType = _journalHelper.getRestrictionType( containerModelId); List<DDMStructure> folderDDMStructures = _journalFolderLocalService.getDDMStructures( _portal.getCurrentAndAncestorSiteGroupIds(article.getGroupId()), containerModelId, restrictionType); for (DDMStructure folderDDMStructure : folderDDMStructures) { if (folderDDMStructure.getStructureId() == ddmStructure.getStructureId()) { return; } } throw new RestoreEntryException( RestoreEntryException.INVALID_CONTAINER); }