protected void doExportStagedModel( PortletDataContext portletDataContext, CalendarResource calendarResource) throws Exception { Element calendarResourceElement = portletDataContext.getExportDataElement(calendarResource); for (Calendar calendar : calendarResource.getCalendars()) { StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, calendarResource, calendar, PortletDataContext.REFERENCE_TYPE_STRONG); } if (calendarResource.getClassNameId() == PortalUtil.getClassNameId(User.class)) { User user = UserLocalServiceUtil.getUser(calendarResource.getClassPK()); portletDataContext.addReferenceElement( calendarResource, calendarResourceElement, user, User.class, PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE, true); } portletDataContext.addClassedModel( calendarResourceElement, ExportImportPathUtil.getModelPath(calendarResource), calendarResource); }
private void replaceClassNameId(PortletPreferences portletPreferences, String name) throws Exception { String[] values = GetterUtil.getStringValues(portletPreferences.getValues(name, null)); ArrayUtil.replace( values, String.valueOf(PortalUtil.getClassNameId(CalEvent.class)), String.valueOf(PortalUtil.getClassNameId(CalendarBooking.class))); portletPreferences.setValues(name, values); }
@Override protected String getUpdatePortletPreferencesWhereClause() { StringBundler sb = new StringBundler(5); sb.append("(preferences like '%classNameIds%"); sb.append(PortalUtil.getClassNameId(CalEvent.class)); sb.append("%') or (preferences like '%anyAssetType%"); sb.append(PortalUtil.getClassNameId(CalEvent.class)); sb.append("%')"); return sb.toString(); }
/** * Adds a role with additional parameters. The user is reindexed after role is added. * * @param userId the primary key of the user * @param companyId the primary key of the company * @param name the role's name * @param titleMap the role's localized titles (optionally <code>null</code>) * @param descriptionMap the role's localized descriptions (optionally <code>null</code>) * @param type the role's type (optionally <code>0</code>) * @param className the name of the class for which the role is created (optionally <code>null * </code>) * @param classPK the primary key of the class for which the role is created (optionally <code>0 * </code>) * @return the role * @throws PortalException if the class name or the role name were invalid, if the role is a * duplicate, or if a user with the primary key could not be found * @throws SystemException if a system exception occurred */ public Role addRole( long userId, long companyId, String name, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, int type, String className, long classPK) throws PortalException, SystemException { // Role className = GetterUtil.getString(className); long classNameId = PortalUtil.getClassNameId(className); long roleId = counterLocalService.increment(); if ((classNameId <= 0) || className.equals(Role.class.getName())) { classNameId = PortalUtil.getClassNameId(Role.class); classPK = roleId; } validate(0, companyId, classNameId, name); Role role = rolePersistence.create(roleId); role.setCompanyId(companyId); role.setClassNameId(classNameId); role.setClassPK(classPK); role.setName(name); role.setTitleMap(titleMap); role.setDescriptionMap(descriptionMap); role.setType(type); rolePersistence.update(role, false); // Resources if (userId > 0) { resourceLocalService.addResources( companyId, 0, userId, Role.class.getName(), role.getRoleId(), false, false, false); if (!ImportExportThreadLocal.isImportInProcess()) { Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class); indexer.reindex(userId); } } return role; }
protected long getClassPK( PortletDataContext portletDataContext, CalendarResource calendarResource, long userId) { long classPK = 0; if (calendarResource.getClassNameId() == PortalUtil.getClassNameId(Group.class)) { classPK = portletDataContext.getScopeGroupId(); } else if (calendarResource.getClassNameId() == PortalUtil.getClassNameId(User.class)) { classPK = userId; } return classPK; }
public Subscription getSubscription(long companyId, long userId, String className, long classPK) throws PortalException, SystemException { long classNameId = PortalUtil.getClassNameId(className); return subscriptionPersistence.findByC_U_C_C(companyId, userId, classNameId, classPK); }
protected long getCompanyGroupId(long companyId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select groupId from Group_ where classNameId = ? and " + "classPK = ?"); ps.setLong(1, PortalUtil.getClassNameId(Company.class.getName())); ps.setLong(2, companyId); rs = ps.executeQuery(); if (rs.next()) { return rs.getLong("groupId"); } return 0; } finally { DataAccess.cleanUp(con, ps, rs); } }
public int countByS_G_U(long groupId, long userId) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(COUNT_BY_S_G_U); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(PortalUtil.getClassNameId(MBCategory.class.getName())); qPos.add(groupId); qPos.add(userId); Iterator<Long> itr = q.list().iterator(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
@Test public void testGetDDMStructure() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm("Text1", "Text2", "Text3"); DDMStructure ddmStructure = DDMStructureTestUtil.addStructure( _group.getGroupId(), DDLRecordSet.class.getName(), ddmForm); DDLRecordSet recordSet = _ddlRecordSetTestHelper.addRecordSet(ddmStructure); ddmForm = DDMFormTestUtil.createDDMForm("Text2", "Text3"); DDMTemplate template = DDMTemplateTestUtil.addTemplate( _group.getGroupId(), ddmStructure.getStructureId(), PortalUtil.getClassNameId(DDLRecordSet.class), "json", DDMFormJSONSerializerUtil.serialize(ddmForm), LocaleUtil.US); Set<String> fieldNames = ddmStructure.getFieldNames(); DDMStructure recordSetDDMStructure = recordSet.getDDMStructure(template.getTemplateId()); if (fieldNames.equals(recordSetDDMStructure.getFieldNames())) { Assert.fail(); } recordSetDDMStructure = recordSet.getDDMStructure(); if (!fieldNames.equals(recordSetDDMStructure.getFieldNames())) { Assert.fail(); } }
public List<Website> getWebsites(long companyId, String className, long classPK) throws SystemException { long classNameId = PortalUtil.getClassNameId(className); return websitePersistence.findByC_C_C(companyId, classNameId, classPK); }
protected void copyTemplates(ActionRequest actionRequest, long structureId, long newStructureId) throws Exception { long classNameId = PortalUtil.getClassNameId(DDMStructure.class); ServiceContext serviceContext = ServiceContextFactory.getInstance(DDMTemplate.class.getName(), actionRequest); boolean copyDisplayTemplates = ParamUtil.getBoolean(actionRequest, "copyDisplayTemplates"); if (copyDisplayTemplates) { DDMTemplateServiceUtil.copyTemplates( classNameId, structureId, newStructureId, DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, serviceContext); } boolean copyFormTemplates = ParamUtil.getBoolean(actionRequest, "copyFormTemplates"); if (copyFormTemplates) { DDMTemplateServiceUtil.copyTemplates( classNameId, structureId, newStructureId, DDMTemplateConstants.TEMPLATE_TYPE_FORM, serviceContext); } }
public String getDDMStructureName() throws PortalException { if (_ddmStructureName != null) { return _ddmStructureName; } _ddmStructureName = LanguageUtil.get(_request, "basic-web-content"); if (Validator.isNull(getDDMStructureKey())) { return _ddmStructureName; } ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure( themeDisplay.getSiteGroupId(), PortalUtil.getClassNameId(JournalArticle.class), getDDMStructureKey(), true); if (ddmStructure != null) { _ddmStructureName = ddmStructure.getName(themeDisplay.getLocale()); } return _ddmStructureName; }
@Override public ExportActionableDynamicQuery getExportActionableDynamicQuery( final PortletDataContext portletDataContext) { final ExportActionableDynamicQuery exportActionableDynamicQuery = new ExportActionableDynamicQuery() { @Override public long performCount() throws PortalException { ManifestSummary manifestSummary = portletDataContext.getManifestSummary(); StagedModelType stagedModelType = getStagedModelType(); long modelAdditionCount = super.performCount(); manifestSummary.addModelAdditionCount(stagedModelType.toString(), modelAdditionCount); long modelDeletionCount = ExportImportHelperUtil.getModelDeletionCount(portletDataContext, stagedModelType); manifestSummary.addModelDeletionCount(stagedModelType.toString(), modelDeletionCount); return modelAdditionCount; } }; initActionableDynamicQuery(exportActionableDynamicQuery); exportActionableDynamicQuery.setAddCriteriaMethod( new ActionableDynamicQuery.AddCriteriaMethod() { @Override public void addCriteria(DynamicQuery dynamicQuery) { portletDataContext.addDateRangeCriteria(dynamicQuery, "modifiedDate"); StagedModelDataHandler<?> stagedModelDataHandler = StagedModelDataHandlerRegistryUtil.getStagedModelDataHandler(Song.class.getName()); Property workflowStatusProperty = PropertyFactoryUtil.forName("status"); dynamicQuery.add( workflowStatusProperty.in(stagedModelDataHandler.getExportableStatuses())); } }); exportActionableDynamicQuery.setCompanyId(portletDataContext.getCompanyId()); exportActionableDynamicQuery.setGroupId(portletDataContext.getScopeGroupId()); exportActionableDynamicQuery.setPerformActionMethod( new ActionableDynamicQuery.PerformActionMethod() { @Override public void performAction(Object object) throws PortalException { Song stagedModel = (Song) object; StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, stagedModel); } }); exportActionableDynamicQuery.setStagedModelType( new StagedModelType(PortalUtil.getClassNameId(Song.class.getName()))); return exportActionableDynamicQuery; }
@Override public String getEditStructureDefaultValuesURL( LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse, DDMStructure structure, String redirectURL, String backURL) throws Exception { PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL( getControlPanelPlid(liferayPortletRequest), PortletKeys.JOURNAL, PortletRequest.RENDER_PHASE); portletURL.setParameter("struts_action", "/journal/edit_article"); portletURL.setParameter("redirect", redirectURL); portletURL.setParameter("backURL", backURL); portletURL.setParameter("groupId", String.valueOf(structure.getGroupId())); portletURL.setParameter( "classNameId", String.valueOf(PortalUtil.getClassNameId(DDMStructure.class))); portletURL.setParameter("classPK", String.valueOf(structure.getStructureId())); portletURL.setParameter("structureId", structure.getStructureKey()); portletURL.setWindowState(LiferayWindowState.POP_UP); return portletURL.toString(); }
protected void updateFileEntryTypeNamesAndDescriptions() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("select companyId, groupId from Group_ where classNameId = ?"); long classNameId = PortalUtil.getClassNameId(Company.class); ps.setLong(1, classNameId); rs = ps.executeQuery(); while (rs.next()) { long companyId = rs.getLong(1); long groupId = rs.getLong(2); updateFileEntryTypeNamesAndDescriptions(companyId, groupId); } } finally { DataAccess.cleanUp(con, ps, rs); } }
@Override public void importCompanyStagedModel(PortletDataContext portletDataContext, Element element) throws PortletDataException { String uuid = element.attributeValue("uuid"); long classNameId = PortalUtil.getClassNameId(element.attributeValue("referenced-class-name")); String structureKey = element.attributeValue("structure-key"); boolean preloaded = GetterUtil.getBoolean(element.attributeValue("preloaded")); DDMStructure existingStructure = null; try { existingStructure = fetchExistingStructure( uuid, portletDataContext.getCompanyGroupId(), classNameId, structureKey, preloaded); } catch (Exception e) { throw new PortletDataException(e); } Map<Long, Long> structureIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DDMStructure.class); long structureId = GetterUtil.getLong(element.attributeValue("class-pk")); structureIds.put(structureId, existingStructure.getStructureId()); Map<String, String> structureKeys = (Map<String, String>) portletDataContext.getNewPrimaryKeysMap(DDMStructure.class + ".ddmStructureKey"); structureKeys.put(structureKey, existingStructure.getStructureKey()); }
@Override public boolean validateReference( PortletDataContext portletDataContext, Element referenceElement) { String uuid = referenceElement.attributeValue("uuid"); long classNameId = PortalUtil.getClassNameId(referenceElement.attributeValue("referenced-class-name")); String structureKey = referenceElement.attributeValue("structure-key"); boolean preloaded = GetterUtil.getBoolean(referenceElement.attributeValue("preloaded")); try { DDMStructure existingStructure = fetchExistingStructure( uuid, portletDataContext.getScopeGroupId(), classNameId, structureKey, preloaded); if (existingStructure == null) { existingStructure = fetchExistingStructure( uuid, portletDataContext.getCompanyGroupId(), classNameId, structureKey, preloaded); } if (existingStructure == null) { return false; } return true; } catch (Exception e) { return false; } }
public List<MBCategory> findByS_G_U(long groupId, long userId, int start, int end) throws SystemException { Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_S_G_U); SQLQuery q = session.createSQLQuery(sql); q.addEntity("MBCategory", MBCategoryImpl.class); QueryPos qPos = QueryPos.getInstance(q); qPos.add(PortalUtil.getClassNameId(MBCategory.class.getName())); qPos.add(groupId); qPos.add(userId); return (List<MBCategory>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
protected void addDDMStructureAttributes(Document document, JournalArticle article) throws Exception { DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure( article.getGroupId(), PortalUtil.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); if (ddmStructure == null) { return; } document.addKeyword(Field.CLASS_TYPE_ID, ddmStructure.getStructureId()); DDMFormValues ddmFormValues = null; try { Fields fields = JournalConverterUtil.getDDMFields(ddmStructure, article.getDocument()); ddmFormValues = FieldsToDDMFormValuesConverterUtil.convert(ddmStructure, fields); } catch (Exception e) { return; } if (ddmFormValues != null) { DDMIndexerUtil.addAttributes(document, ddmStructure, ddmFormValues); } }
protected String extractDDMContent(JournalArticle article, String languageId) throws Exception { DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure( article.getGroupId(), PortalUtil.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); if (ddmStructure == null) { return StringPool.BLANK; } DDMFormValues ddmFormValues = null; try { Fields fields = JournalConverterUtil.getDDMFields(ddmStructure, article.getDocument()); ddmFormValues = FieldsToDDMFormValuesConverterUtil.convert(ddmStructure, fields); } catch (Exception e) { return StringPool.BLANK; } if (ddmFormValues == null) { return StringPool.BLANK; } return DDMIndexerUtil.extractAttributes( ddmStructure, ddmFormValues, LocaleUtil.fromLanguageId(languageId)); }
public SearchContainer<MBMessage> getCommentsSearchContainer() throws PortalException { SearchContainer<MBMessage> searchContainer = new SearchContainer( _liferayPortletRequest, _liferayPortletResponse.createRenderURL(), null, null); SearchContext searchContext = SearchContextFactory.getInstance(_liferayPortletRequest.getHttpServletRequest()); searchContext.setAttribute( Field.CLASS_NAME_ID, PortalUtil.getClassNameId(JournalArticle.class)); searchContext.setAttribute("discussion", true); List<MBMessage> mbMessages = new ArrayList<>(); Indexer indexer = IndexerRegistryUtil.getIndexer(MBMessage.class); Hits hits = indexer.search(searchContext); for (Document document : hits.getDocs()) { long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(entryClassPK); mbMessages.add(mbMessage); } searchContainer.setResults(mbMessages); searchContainer.setTotal(hits.getLength()); return searchContainer; }
public List<Subscription> getSubscriptions(long companyId, String className, long classPK) throws SystemException { long classNameId = PortalUtil.getClassNameId(className); return subscriptionPersistence.findByC_C_C(companyId, classNameId, classPK); }
@Override public ExportActionableDynamicQuery getExportActionableDynamicQuery( final PortletDataContext portletDataContext) { final ExportActionableDynamicQuery exportActionableDynamicQuery = new ExportActionableDynamicQuery() { @Override public long performCount() throws PortalException { ManifestSummary manifestSummary = portletDataContext.getManifestSummary(); StagedModelType stagedModelType = getStagedModelType(); long modelAdditionCount = super.performCount(); manifestSummary.addModelAdditionCount(stagedModelType.toString(), modelAdditionCount); long modelDeletionCount = ExportImportHelperUtil.getModelDeletionCount(portletDataContext, stagedModelType); manifestSummary.addModelDeletionCount(stagedModelType.toString(), modelDeletionCount); return modelAdditionCount; } }; initActionableDynamicQuery(exportActionableDynamicQuery); exportActionableDynamicQuery.setAddCriteriaMethod( new ActionableDynamicQuery.AddCriteriaMethod() { @Override public void addCriteria(DynamicQuery dynamicQuery) { portletDataContext.addDateRangeCriteria(dynamicQuery, "modifiedDate"); StagedModelType stagedModelType = exportActionableDynamicQuery.getStagedModelType(); if (stagedModelType.getReferrerClassNameId() >= 0) { Property classNameIdProperty = PropertyFactoryUtil.forName("classNameId"); dynamicQuery.add(classNameIdProperty.eq(stagedModelType.getReferrerClassNameId())); } } }); exportActionableDynamicQuery.setCompanyId(portletDataContext.getCompanyId()); exportActionableDynamicQuery.setGroupId(portletDataContext.getScopeGroupId()); exportActionableDynamicQuery.setPerformActionMethod( new ActionableDynamicQuery.PerformActionMethod() { @Override public void performAction(Object object) throws PortalException { CalendarResource stagedModel = (CalendarResource) object; StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, stagedModel); } }); exportActionableDynamicQuery.setStagedModelType( new StagedModelType(PortalUtil.getClassNameId(CalendarResource.class.getName()))); return exportActionableDynamicQuery; }
public List<Subscription> getUserSubscriptions(long userId, String className) throws SystemException { long classNameId = PortalUtil.getClassNameId(className); return subscriptionPersistence.findByU_C(userId, classNameId); }
public Website addWebsite( long userId, String className, long classPK, String url, int typeId, boolean primary) throws PortalException, SystemException { User user = userPersistence.findByPrimaryKey(userId); long classNameId = PortalUtil.getClassNameId(className); Date now = new Date(); validate(0, user.getCompanyId(), classNameId, classPK, url, typeId, primary); long websiteId = counterLocalService.increment(); Website website = websitePersistence.create(websiteId); website.setCompanyId(user.getCompanyId()); website.setUserId(user.getUserId()); website.setUserName(user.getFullName()); website.setCreateDate(now); website.setModifiedDate(now); website.setClassNameId(classNameId); website.setClassPK(classPK); website.setUrl(url); website.setTypeId(typeId); website.setPrimary(primary); websitePersistence.update(website); return website; }
public void deleteTable(long companyId, String className, String name) throws PortalException, SystemException { long classNameId = PortalUtil.getClassNameId(className); deleteTable(companyId, classNameId, name); }
public void addComments(Class<?> clazz, long classPK) throws SystemException { long classNameId = PortalUtil.getClassNameId(clazz); MBDiscussion discussion = MBDiscussionUtil.fetchByC_C(classNameId, classPK); if (discussion == null) { return; } List<MBMessage> messages = MBMessageLocalServiceUtil.getThreadMessages( discussion.getThreadId(), WorkflowConstants.STATUS_APPROVED); if (messages.size() == 0) { return; } for (MBMessage message : messages) { message.setUserUuid(message.getUserUuid()); addRatingsEntries(MBDiscussion.class, message.getPrimaryKey()); } _commentsMap.put(getPrimaryKeyString(clazz, classPK), messages); }
public ExpandoTable getDefaultTable(long companyId, String className) throws PortalException, SystemException { long classNameId = PortalUtil.getClassNameId(className); return getTable(companyId, classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME); }
protected String getSaveAndContinueRedirect( PortletConfig portletConfig, ActionRequest actionRequest, DDMStructure structure) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletURLImpl portletURL = new PortletURLImpl( actionRequest, portletConfig.getPortletName(), themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("struts_action", "/dynamic_data_mapping/copy_structure"); long classNameId = PortalUtil.getClassNameId(DDMStructure.class); portletURL.setParameter("classNameId", String.valueOf(classNameId), false); portletURL.setParameter("classPK", String.valueOf(structure.getStructureId()), false); portletURL.setParameter( "copyFormTemplates", ParamUtil.getString(actionRequest, "copyFormTemplates"), false); portletURL.setParameter( "copyDisplayTemplates", ParamUtil.getString(actionRequest, "copyDisplayTemplates"), false); portletURL.setWindowState(actionRequest.getWindowState()); return portletURL.toString(); }
public ExpandoTable addTable(long companyId, String className, String name) throws PortalException, SystemException { long classNameId = PortalUtil.getClassNameId(className); return addTable(companyId, classNameId, name); }