@Override public void clickAt(String locator, String coordString) { if (locator.contains("x:")) { String url = getHtmlNodeHref(locator); open(url); } else { WebElement webElement = getWebElement(locator); if (coordString.contains(",")) { WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); String[] coords = coordString.split(","); int x = GetterUtil.getInteger(coords[0]); int y = GetterUtil.getInteger(coords[1]); actions.moveToElement(webElement, x, y); actions.click(); Action action = actions.build(); action.perform(); } else { webElement.click(); } } }
public static String getLockUuid(HttpServletRequest request) throws WebDAVException { String token = StringPool.BLANK; String value = GetterUtil.getString(request.getHeader("If")); if (_log.isDebugEnabled()) { _log.debug("\"If\" header is " + value); } if (value.contains("(<DAV:no-lock>)")) { if (_log.isWarnEnabled()) { _log.warn("Lock tokens can never be <DAV:no-lock>"); } throw new WebDAVException(); } int beg = value.indexOf(TOKEN_PREFIX); if (beg >= 0) { beg += TOKEN_PREFIX.length(); if (beg < value.length()) { int end = value.indexOf(CharPool.GREATER_THAN, beg); token = GetterUtil.getString(value.substring(beg, end)); } } return token; }
protected void importServicePortletPreferences( PortletDataContext portletDataContext, Element serviceElement) throws PortalException { long ownerId = GetterUtil.getLong(serviceElement.attributeValue("owner-id")); int ownerType = GetterUtil.getInteger(serviceElement.attributeValue("owner-type")); String serviceName = serviceElement.attributeValue("service-name"); PortletPreferences portletPreferences = getPortletPreferences( portletDataContext.getCompanyId(), ownerId, ownerType, LayoutConstants.DEFAULT_PLID, serviceName); for (Attribute attribute : serviceElement.attributes()) { serviceElement.remove(attribute); } String xml = serviceElement.asXML(); portletPreferences.setPreferences(xml); _portletPreferencesLocalService.updatePortletPreferences(portletPreferences); }
protected void initVideoFrameRate(Properties videoProperties) { int numerator = GetterUtil.getInteger( videoProperties.getProperty( PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_FRAME_RATE_NUMERATOR + "[" + _videoContainer + "]")); int denominator = GetterUtil.getInteger( videoProperties.getProperty( PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_FRAME_RATE_DENOMINATOR + StringPool.OPEN_BRACKET + _videoContainer + StringPool.CLOSE_BRACKET)); if ((numerator > 0) && (denominator > 0)) { _videoFrameRate = IRational.make(numerator, denominator); if (_log.isInfoEnabled()) { _log.info( "Default frame rate for " + _videoContainer + " configured to " + _videoFrameRate.getNumerator() + "/" + _videoFrameRate.getDenominator()); } } }
public LiferayVideoConverter( String inputURL, String outputURL, String tempFileName, Properties videoProperties, Properties ffpresetProperties) { _inputURL = inputURL; _outputURL = outputURL; _tempFileName = tempFileName; _ffpresetProperties = ffpresetProperties; _height = GetterUtil.getInteger( videoProperties.getProperty(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_HEIGHT), _height); _width = GetterUtil.getInteger( videoProperties.getProperty(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_WIDTH), _width); _previewVideoContainers = StringUtil.split( videoProperties.getProperty(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_CONTAINERS)); initVideoBitRateMap(videoProperties); initVideoFrameRateMap(videoProperties); }
protected void updateFileVersionFileNames() throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("select fileVersionId, extension, title from DLFileVersion"); rs = ps.executeQuery(); while (rs.next()) { long fileVersionId = rs.getLong("fileVersionId"); String extension = GetterUtil.getString(rs.getString("extension")); String title = GetterUtil.getString(rs.getString("title")); String fileName = DLUtil.getSanitizedFileName(title, extension); updateFileVersionFileName(fileVersionId, fileName); } } finally { DataAccess.cleanUp(con, ps, rs); } }
@Override public boolean validateReference( PortletDataContext portletDataContext, Element referenceElement) { validateMissingGroupReference(portletDataContext, referenceElement); String uuid = referenceElement.attributeValue("uuid"); Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id")); groupId = MapUtil.getLong(groupIds, groupId); boolean privateLayout = GetterUtil.getBoolean(referenceElement.attributeValue("private-layout")); Layout existingLayout = fetchMissingReference(uuid, groupId, privateLayout); if (existingLayout == null) { return false; } return true; }
@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()); }
protected Field createField( DDMStructure ddmStructure, String fieldName, List<Serializable> fieldValues, ServiceContext serviceContext) { Field field = new Field(); field.setDDMStructureId(ddmStructure.getStructureId()); String languageId = GetterUtil.getString( serviceContext.getAttribute("languageId"), serviceContext.getLanguageId()); Locale locale = LocaleUtil.fromLanguageId(languageId); String defaultLanguageId = GetterUtil.getString(serviceContext.getAttribute("defaultLanguageId")); Locale defaultLocale = LocaleUtil.fromLanguageId(defaultLanguageId); if (fieldName.startsWith(StringPool.UNDERLINE)) { locale = LocaleUtil.getSiteDefault(); defaultLocale = LocaleUtil.getSiteDefault(); } field.setDefaultLocale(defaultLocale); field.setName(fieldName); field.setValues(locale, fieldValues); return field; }
protected void deleteInstance(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long workflowInstanceId = ParamUtil.getLong(actionRequest, "workflowInstanceId"); WorkflowInstance workflowInstance = WorkflowInstanceManagerUtil.getWorkflowInstance( themeDisplay.getCompanyId(), workflowInstanceId); Map<String, Serializable> workflowContext = workflowInstance.getWorkflowContext(); long companyId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID)); long groupId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_GROUP_ID)); String className = GetterUtil.getString(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME)); long classPK = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK)); WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className); workflowHandler.updateStatus(WorkflowConstants.STATUS_DRAFT, workflowContext); WorkflowInstanceLinkLocalServiceUtil.deleteWorkflowInstanceLink( companyId, groupId, className, classPK); }
/** * Returns <code>true</code> if the string contains a valid number according to the Luhn * algorithm, commonly used to validate credit card numbers. * * @param number the string to check * @return <code>true</code> if the string contains a valid number according to the Luhn * algorithm; <code>false</code> otherwise */ public static boolean isLUHN(String number) { if (number == null) { return false; } number = StringUtil.reverse(number); int total = 0; for (int i = 0; i < number.length(); i++) { int x = 0; if (((i + 1) % 2) == 0) { x = GetterUtil.getInteger(number.substring(i, i + 1)) * 2; if (x >= 10) { String s = String.valueOf(x); x = GetterUtil.getInteger(s.substring(0, 1)) + GetterUtil.getInteger(s.substring(1, 2)); } } else { x = GetterUtil.getInteger(number.substring(i, i + 1)); } total = total + x; } if ((total % 10) == 0) { return true; } else { return false; } }
@Override public List<AssetCategory> getCategories(Hits hits) throws PortalException { List<Document> documents = hits.toList(); List<AssetCategory> categories = new ArrayList<>(documents.size()); for (Document document : documents) { long categoryId = GetterUtil.getLong(document.get(Field.ASSET_CATEGORY_ID)); AssetCategory category = fetchCategory(categoryId); if (category == null) { categories = null; Indexer<AssetCategory> indexer = IndexerRegistryUtil.getIndexer(AssetCategory.class); long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); indexer.delete(companyId, document.getUID()); } else if (categories != null) { categories.add(category); } } return categories; }
/** @author Shuyang Zhou */ public class IntrabandFactoryUtil { public static Intraband createIntraband() throws IOException { if (Validator.isNotNull(_INTRABAND_IMPL)) { try { Class<? extends Intraband> intraBandClass = (Class<? extends Intraband>) Class.forName(_INTRABAND_IMPL); Constructor<? extends Intraband> constructor = intraBandClass.getConstructor(long.class); return constructor.newInstance(_INTRABAND_TIMEOUT_DEFAULT); } catch (Exception e) { throw new RuntimeException("Unable to instantiate " + _INTRABAND_IMPL, e); } } else { Class<? extends Welder> welderClass = WelderFactoryUtil.getWelderClass(); if (welderClass.equals(SocketWelder.class)) { return new SelectorIntraband(_INTRABAND_TIMEOUT_DEFAULT); } else { return new ExecutorIntraband(_INTRABAND_TIMEOUT_DEFAULT); } } } private static final String _INTRABAND_IMPL = GetterUtil.getString(System.getProperty(PropsKeys.INTRABAND_IMPL)); private static final long _INTRABAND_TIMEOUT_DEFAULT = GetterUtil.getLong(System.getProperty(PropsKeys.INTRABAND_TIMEOUT_DEFAULT)); }
@Override public void mouseMoveAt(String locator, String coordString) { WebElement webElement = getWebElement(locator); WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); if (coordString.contains(",")) { String[] coords = coordString.split(","); int x = GetterUtil.getInteger(coords[0]); int y = GetterUtil.getInteger(coords[1]); actions.moveToElement(webElement, x, y); actions.clickAndHold(webElement); } else { actions.moveToElement(webElement); actions.clickAndHold(webElement); } Action action = actions.build(); action.perform(); }
protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); PortletPreferences portletPreferences = actionRequest.getPreferences(); String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null)); if (Validator.isNull(scopeType)) { return null; } String scopeName = null; if (scopeType.equals("company")) { scopeName = themeDisplay.translate("global"); } else if (scopeType.equals("layout")) { String scopeLayoutUuid = GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null)); Layout scopeLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId( scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout()); if (scopeLayout != null) { scopeName = scopeLayout.getName(themeDisplay.getLocale()); } } else { throw new IllegalArgumentException("Scope type " + scopeType + " is invalid"); } return scopeName; }
@Override public void importMissingReference( PortletDataContext portletDataContext, Element referenceElement) throws PortletDataException { importMissingGroupReference(portletDataContext, referenceElement); String uuid = referenceElement.attributeValue("uuid"); Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id")); groupId = MapUtil.getLong(groupIds, groupId); String fileEntryTypeKey = referenceElement.attributeValue("file-entry-type-key"); boolean preloaded = GetterUtil.getBoolean(referenceElement.attributeValue("preloaded")); DLFileEntryType existingFileEntryType = null; existingFileEntryType = fetchExistingFileEntryType(uuid, groupId, fileEntryTypeKey, preloaded); Map<Long, Long> fileEntryTypeIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DLFileEntryType.class); long fileEntryTypeId = GetterUtil.getLong(referenceElement.attributeValue("class-pk")); fileEntryTypeIds.put(fileEntryTypeId, existingFileEntryType.getFileEntryTypeId()); }
@Override protected void processTemplates(List<TemplateResource> templateResources, Writer writer) throws Exception { try { String namespace = GetterUtil.getString(get(TemplateConstants.NAMESPACE)); if (Validator.isNull(namespace)) { throw new TemplateException("No namespace specified."); } SoyFileSet soyFileSet = getSoyFileSet(templateResources); SoyTofu soyTofu = soyFileSet.compileToTofu(); Renderer renderer = soyTofu.newRenderer(namespace); renderer.setData(getSoyMapData()); boolean renderStrict = GetterUtil.getBoolean(get(TemplateConstants.RENDER_STRICT), true); if (renderStrict) { SanitizedContent sanitizedContent = renderer.renderStrict(); writer.write(sanitizedContent.stringValue()); } else { writer.write(renderer.render()); } } catch (PrivilegedActionException pae) { throw pae.getException(); } }
@Override public boolean validateReference( PortletDataContext portletDataContext, Element referenceElement) { validateMissingGroupReference(portletDataContext, referenceElement); String uuid = referenceElement.attributeValue("uuid"); Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id")); groupId = MapUtil.getLong(groupIds, groupId); String fileEntryTypeKey = referenceElement.attributeValue("file-entry-type-key"); boolean preloaded = GetterUtil.getBoolean(referenceElement.attributeValue("preloaded")); DLFileEntryType existingFileEntryType = fetchExistingFileEntryType(uuid, groupId, fileEntryTypeKey, preloaded); if (existingFileEntryType == null) { return false; } return true; }
@Override public void init(FilterConfig filterConfig) { super.init(filterConfig); _basicAuthEnabled = GetterUtil.getBoolean(filterConfig.getInitParameter("basic_auth")); _digestAuthEnabled = GetterUtil.getBoolean(filterConfig.getInitParameter("digest_auth")); String propertyPrefix = filterConfig.getInitParameter("portal_property_prefix"); String[] hostsAllowed = null; if (Validator.isNull(propertyPrefix)) { hostsAllowed = StringUtil.split(filterConfig.getInitParameter("hosts.allowed")); _httpsRequired = GetterUtil.getBoolean(filterConfig.getInitParameter("https.required")); } else { hostsAllowed = PropsUtil.getArray(propertyPrefix + "hosts.allowed"); _httpsRequired = GetterUtil.getBoolean(PropsUtil.get(propertyPrefix + "https.required")); } for (String hostAllowed : hostsAllowed) { _hostsAllowed.add(hostAllowed); } _usePermissionChecker = GetterUtil.getBoolean(filterConfig.getInitParameter("use_permission_checker")); }
private static void _checkFileEntry(String[] pathArray) throws Exception { if (pathArray.length == 1) { long dlFileShortcutId = GetterUtil.getLong(pathArray[0]); DLFileShortcut dlFileShortcut = DLAppLocalServiceUtil.getFileShortcut(dlFileShortcutId); DLAppLocalServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId()); } else if (pathArray.length == 2) { // Unable to check with UUID because of multiple repositories } else if (pathArray.length == 3) { long groupId = GetterUtil.getLong(pathArray[0]); long folderId = GetterUtil.getLong(pathArray[1]); String fileName = pathArray[2]; try { DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName); } catch (RepositoryException re) { } } else { long groupId = GetterUtil.getLong(pathArray[0]); String uuid = pathArray[3]; try { DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); } catch (RepositoryException re) { } } }
public void execute() throws BuildException { try { InetAddress localHost = InetAddress.getLocalHost(); if (Validator.isNotNull(_hostAddressProperty)) { getProject().setUserProperty(_hostAddressProperty, localHost.getHostAddress()); } if (Validator.isNotNull(_hostNameProperty)) { getProject().setUserProperty(_hostNameProperty, localHost.getHostName()); } if (Validator.isNotNull(_vmId1Property)) { int id = GetterUtil.getInteger(StringUtil.extractDigits(localHost.getHostName())); getProject().setUserProperty(_vmId1Property, String.valueOf((id * 2) - 1)); } if (Validator.isNotNull(_vmId2Property)) { int id = GetterUtil.getInteger(StringUtil.extractDigits(localHost.getHostName())); getProject().setUserProperty(_vmId2Property, String.valueOf((id * 2))); } } catch (UnknownHostException uhe) { throw new BuildException(uhe); } }
protected FileEntry getFileEntry(String[] pathArray) throws Exception { if (pathArray.length == 1) { long dlFileShortcutId = GetterUtil.getLong(pathArray[0]); DLFileShortcut dlFileShortcut = DLAppServiceUtil.getFileShortcut(dlFileShortcutId); return DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId()); } else if (pathArray.length == 2) { long groupId = GetterUtil.getLong(pathArray[0]); return DLAppServiceUtil.getFileEntryByUuidAndGroupId(pathArray[1], groupId); } else if (pathArray.length == 3) { long groupId = GetterUtil.getLong(pathArray[0]); long folderId = GetterUtil.getLong(pathArray[1]); String fileName = pathArray[2]; if (fileName.contains(StringPool.QUESTION)) { fileName = fileName.substring(0, fileName.indexOf(StringPool.QUESTION)); } return DLAppServiceUtil.getFileEntry(groupId, folderId, fileName); } else { long groupId = GetterUtil.getLong(pathArray[0]); String uuid = pathArray[3]; return DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); } }
public static List<Calendar> getSelectedCalendars(long userId) throws PortalException, SystemException { ArrayList<Calendar> calendars = new ArrayList<Calendar>(); String otherCalendarPreferences = "calendar-portlet-other-calendars"; if (_calendarVersion == 0) { Portlet calendarPortlet = PortletLocalServiceUtil.getPortletById(PortletKeys.CALENDAR); String calendarVersionStr = calendarPortlet.getPluginPackage().getVersion(); Version calendarVersion = Version.getInstance(calendarVersionStr); _calendarVersion = GetterUtil.getInteger(calendarVersion.getBuildNumber(), 1); } if (_calendarVersion < 10) { otherCalendarPreferences = "otherCalendars"; } long[] calendarIds = GetterUtil.getLongValues( StringUtil.split( PortletPreferencesFactoryUtil.getPortalPreferences(userId, true) .getValue(SessionClicks.class.getName(), otherCalendarPreferences))); for (long calendarId : calendarIds) { calendars.add(CalendarServiceUtil.getCalendar(calendarId)); } return calendars; }
protected void sendDDMRecordFile( HttpServletRequest request, HttpServletResponse response, String[] pathArray) throws Exception { if (pathArray.length == 4) { String className = GetterUtil.getString(pathArray[1]); long classPK = GetterUtil.getLong(pathArray[2]); String fieldName = GetterUtil.getString(pathArray[3]); Field field = null; if (className.equals(DDLRecord.class.getName())) { DDLRecord ddlRecord = DDLRecordLocalServiceUtil.getRecord(classPK); field = ddlRecord.getField(fieldName); } else if (className.equals(DLFileEntryMetadata.class.getName())) { DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getDLFileEntryMetadata(classPK); Fields fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId()); field = fields.get(fieldName); } DDMUtil.sendFieldFile(request, response, field); } }
@Override public List<AssetVocabulary> getVocabularies(Hits hits) throws PortalException { List<Document> documents = hits.toList(); List<AssetVocabulary> vocabularies = new ArrayList<>(documents.size()); for (Document document : documents) { long vocabularyId = GetterUtil.getLong(document.get(Field.ASSET_VOCABULARY_ID)); AssetVocabulary vocabulary = fetchAssetVocabulary(vocabularyId); if (vocabulary == null) { vocabularies = null; Indexer indexer = IndexerRegistryUtil.getIndexer(AssetVocabulary.class); long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); indexer.delete(companyId, document.getUID()); } else if (vocabularies != null) { vocabularies.add(vocabulary); } } return vocabularies; }
public void applyAction( MDRAction mdrAction, HttpServletRequest request, HttpServletResponse response) { long companyId = PortalUtil.getCompanyId(request); UnicodeProperties typeSettingsProperties = mdrAction.getTypeSettingsProperties(); String themeId = GetterUtil.getString(typeSettingsProperties.getProperty("themeId")); Theme theme = _themeLocalService.fetchTheme(companyId, themeId); if (theme == null) { return; } request.setAttribute(WebKeys.THEME, theme); String colorSchemeId = GetterUtil.getString(typeSettingsProperties.getProperty("colorSchemeId")); ColorScheme colorScheme = _themeLocalService.fetchColorScheme(companyId, themeId, colorSchemeId); if (colorScheme == null) { colorScheme = ColorSchemeImpl.getNullColorScheme(); } request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String contextPath = PortalUtil.getPathContext(); themeDisplay.setLookAndFeel(contextPath, theme, colorScheme); }
private static void _populateThreadLocalsFromContext(Map<String, Serializable> context) { long companyId = GetterUtil.getLong(context.get("companyId")); if (companyId > 0) { CompanyThreadLocal.setCompanyId(companyId); } Locale defaultLocale = (Locale) context.get("defaultLocale"); if (defaultLocale != null) { LocaleThreadLocal.setDefaultLocale(defaultLocale); } long groupId = GetterUtil.getLong(context.get("groupId")); if (groupId > 0) { GroupThreadLocal.setGroupId(groupId); } String principalName = GetterUtil.getString(context.get("principalName")); if (Validator.isNotNull(principalName)) { PrincipalThreadLocal.setName(principalName); } PermissionChecker permissionChecker = null; if (Validator.isNotNull(principalName)) { try { User user = UserLocalServiceUtil.fetchUser(PrincipalThreadLocal.getUserId()); permissionChecker = PermissionCheckerFactoryUtil.create(user); } catch (Exception e) { throw new RuntimeException(e); } } if (permissionChecker != null) { PermissionThreadLocal.setPermissionChecker(permissionChecker); } String principalPassword = GetterUtil.getString(context.get("principalPassword")); if (Validator.isNotNull(principalPassword)) { PrincipalThreadLocal.setPassword(principalPassword); } Locale siteDefaultLocale = (Locale) context.get("siteDefaultLocale"); if (siteDefaultLocale != null) { LocaleThreadLocal.setSiteDefaultLocale(siteDefaultLocale); } Locale themeDisplayLocale = (Locale) context.get("themeDisplayLocale"); if (themeDisplayLocale != null) { LocaleThreadLocal.setThemeDisplayLocale(themeDisplayLocale); } }
@Test public void testSearchAndVerifyDocs() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); BookmarksFolder folder = BookmarksTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString()); BookmarksEntry entry = BookmarksTestUtil.addEntry(folder.getFolderId(), true, serviceContext); SearchContext searchContext = BookmarksTestUtil.getSearchContext( entry.getCompanyId(), entry.getGroupId(), entry.getFolderId(), "test"); Indexer indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class); Hits hits = indexer.search(searchContext); Assert.assertEquals(1, hits.getLength()); List<Document> results = hits.toList(); for (Document doc : results) { Assert.assertEquals(entry.getCompanyId(), GetterUtil.getLong(doc.get(Field.COMPANY_ID))); Assert.assertEquals(BookmarksEntry.class.getName(), doc.get(Field.ENTRY_CLASS_NAME)); Assert.assertEquals(entry.getEntryId(), GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK))); AssertUtils.assertEqualsIgnoreCase(entry.getName(), doc.get(Field.TITLE)); Assert.assertEquals(entry.getUrl(), doc.get(Field.URL)); } }
protected void readExpandoTables(PortletDataContext portletDataContext) throws Exception { String xml = portletDataContext.getZipEntryAsString( ExportImportPathUtil.getSourceRootPath(portletDataContext) + "/expando-tables.xml"); if (xml == null) { return; } Document document = SAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); List<Element> expandoTableElements = rootElement.elements("expando-table"); for (Element expandoTableElement : expandoTableElements) { String className = expandoTableElement.attributeValue("class-name"); ExpandoTable expandoTable = null; try { expandoTable = _expandoTableLocalService.getDefaultTable(portletDataContext.getCompanyId(), className); } catch (NoSuchTableException nste) { expandoTable = _expandoTableLocalService.addDefaultTable(portletDataContext.getCompanyId(), className); } List<Element> expandoColumnElements = expandoTableElement.elements("expando-column"); for (Element expandoColumnElement : expandoColumnElements) { long columnId = GetterUtil.getLong(expandoColumnElement.attributeValue("column-id")); String name = expandoColumnElement.attributeValue("name"); int type = GetterUtil.getInteger(expandoColumnElement.attributeValue("type")); String defaultData = expandoColumnElement.elementText("default-data"); String typeSettings = expandoColumnElement.elementText("type-settings"); Serializable defaultDataObject = ExpandoConverterUtil.getAttributeFromString(type, defaultData); ExpandoColumn expandoColumn = _expandoColumnLocalService.getColumn(expandoTable.getTableId(), name); if (expandoColumn != null) { _expandoColumnLocalService.updateColumn( expandoColumn.getColumnId(), name, type, defaultDataObject); } else { expandoColumn = _expandoColumnLocalService.addColumn( expandoTable.getTableId(), name, type, defaultDataObject); } _expandoColumnLocalService.updateTypeSettings(expandoColumn.getColumnId(), typeSettings); portletDataContext.importPermissions( ExpandoColumn.class, columnId, expandoColumn.getColumnId()); } } }
public void importServicePortletPreferences( PortletDataContext portletDataContext, Element serviceElement) throws PortalException { long ownerId = GetterUtil.getLong(serviceElement.attributeValue("owner-id")); int ownerType = GetterUtil.getInteger(serviceElement.attributeValue("owner-type")); String serviceName = serviceElement.attributeValue("service-name"); if (ownerType == PortletKeys.PREFS_OWNER_TYPE_GROUP) { ownerId = portletDataContext.getGroupId(); } else if (ownerType == PortletKeys.PREFS_OWNER_TYPE_COMPANY) { ownerId = portletDataContext.getCompanyId(); } PortletPreferences portletPreferences = getPortletPreferences( portletDataContext.getCompanyId(), ownerId, ownerType, LayoutConstants.DEFAULT_PLID, serviceName); for (Attribute attribute : serviceElement.attributes()) { serviceElement.remove(attribute); } String xml = serviceElement.asXML(); portletPreferences.setPreferences(xml); _portletPreferencesLocalService.updatePortletPreferences(portletPreferences); }