protected Map<String, String> getPortletPreferencesMap() throws PortalException { Map<String, String> portletPreferencesMap = new HashMap<>(); User user = getUser(); int maxConnections = PrefsPropsUtil.getInteger( user.getCompanyId(), PortletPropsKeys.SYNC_CLIENT_MAX_CONNECTIONS, PortletPropsValues.SYNC_CLIENT_MAX_CONNECTIONS); portletPreferencesMap.put( PortletPropsKeys.SYNC_CLIENT_MAX_CONNECTIONS, String.valueOf(maxConnections)); int pollInterval = PrefsPropsUtil.getInteger( user.getCompanyId(), PortletPropsKeys.SYNC_CLIENT_POLL_INTERVAL, PortletPropsValues.SYNC_CLIENT_POLL_INTERVAL); portletPreferencesMap.put( PortletPropsKeys.SYNC_CLIENT_POLL_INTERVAL, String.valueOf(pollInterval)); return portletPreferencesMap; }
@Override public long getMaximumUploadSize() { long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if (fileMaxSize == 0) { fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE); } return fileMaxSize; }
public static String getThumbnailStyle() throws Exception { StringBundler sb = new StringBundler(5); sb.append("max-height: "); sb.append(PrefsPropsUtil.getLong(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_HEIGHT)); sb.append("px; max-width: "); sb.append(PrefsPropsUtil.getLong(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_WIDTH)); sb.append("px;"); return sb.toString(); }
protected GoogleDriveSession buildGoogleDriveSession() throws IOException, PortalException { long userId = PrincipalThreadLocal.getUserId(); User user = UserLocalServiceUtil.getUser(userId); if (user.isDefaultUser()) { throw new PrincipalException("User is not authenticated"); } GoogleCredential.Builder builder = new GoogleCredential.Builder(); String googleClientId = PrefsPropsUtil.getString(user.getCompanyId(), "google-client-id"); String googleClientSecret = PrefsPropsUtil.getString(user.getCompanyId(), "google-client-secret"); builder.setClientSecrets(googleClientId, googleClientSecret); JacksonFactory jsonFactory = new JacksonFactory(); builder.setJsonFactory(jsonFactory); HttpTransport httpTransport = new NetHttpTransport(); builder.setTransport(httpTransport); GoogleCredential googleCredential = builder.build(); ExpandoBridge expandoBridge = user.getExpandoBridge(); String googleAccessToken = GetterUtil.getString(expandoBridge.getAttribute("googleAccessToken", false)); googleCredential.setAccessToken(googleAccessToken); String googleRefreshToken = GetterUtil.getString(expandoBridge.getAttribute("googleRefreshToken", false)); googleCredential.setRefreshToken(googleRefreshToken); Drive.Builder driveBuilder = new Drive.Builder(httpTransport, jsonFactory, googleCredential); Drive drive = driveBuilder.build(); Drive.About driveAbout = drive.about(); Drive.About.Get driveAboutGet = driveAbout.get(); About about = driveAboutGet.execute(); return new GoogleDriveSession(drive, about.getRootFolderId()); }
/** * Save CSV or XML file with the storage component * * @expects "GEMO portal wide params" in portal-ext.properties: * gemo.storage.upload.url=http://?????????/service/storage/upload * gemo.storage.search.query.url=http://?????????/service/storage/ search?query= * @param csvXmlFile the file * @return the url * @throws SystemException the system exception * @throws URISyntaxException the uRI syntax exception * @throws IOException * @throws PortalException */ public static String uploadToStorage(UploadedFile csvXmlFile) throws SystemException, URISyntaxException, IOException, PortalException, NullPointerException { // grab props from constants final String storage_uri = PrefsPropsUtil.getString(PortalProperties.GEMO_STORAGE_URL, "http://localhost/storage"); final String upload_uri = PrefsPropsUtil.getString( PortalProperties.GEMO_STORAGE_UPLOAD_URL, "http://localhost/storage/upload"); final String upload_base64_uri = PrefsPropsUtil.getString( PortalProperties.GEMO_STORAGE_UPLOADBASE64_URL, "http://localhost:8080/storage/uploadbase64"); final String query_uri = PrefsPropsUtil.getString( PortalProperties.GEMO_STORAGE_SEARCH_QUERY_URL, "http://localhost/storage/search?query="); final String tableName = NameUtils.UsersUsableUniqueNamefromFile(csvXmlFile); try { byte[] bytes = csvXmlFile.getBytes(); String theBase64Bytes = Base64.encodeBytes(bytes); ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyWebTarget target = client.target(upload_base64_uri); MultipartFormDataOutput mdo = new MultipartFormDataOutput(); mdo.addFormData("tableName", tableName, MediaType.TEXT_PLAIN_TYPE); mdo.addFormData("fileName", csvXmlFile.getName(), MediaType.TEXT_PLAIN_TYPE); mdo.addFormData("fileBase64", theBase64Bytes, MediaType.TEXT_PLAIN_TYPE.withCharset("utf-8")); GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(mdo) {}; Response r = target.request().post(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE)); String obj = r.readEntity(String.class); LOG.debug("Storage returned: " + obj); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { // httpclient.getConnectionManager().shutdown(); } return query_uri + "select * from " + tableName + " LIMIT 10"; }
protected void addTrigger( SchedulerEntry schedulerEntry, ServiceReference<SchedulerEntry> serviceReference) { String propertyKey = schedulerEntry.getPropertyKey(); if (Validator.isNull(propertyKey)) { return; } long bundleId = GetterUtil.getLong(serviceReference.getProperty("bundle.id"), -1); String triggerValue = null; if (bundleId != 0) { Class<?> clazz = schedulerEntry.getClass(); ClassLoader classloader = clazz.getClassLoader(); triggerValue = getPluginPropertyValue(classloader, propertyKey); } else { triggerValue = PrefsPropsUtil.getString(propertyKey); } if (_log.isDebugEnabled()) { _log.debug("Scheduler property key " + propertyKey + " has trigger value " + triggerValue); } if (Validator.isNotNull(triggerValue)) { schedulerEntry.setTriggerValue(triggerValue); } }
@Override public String getAuthSearchFilter( long ldapServerId, long companyId, String emailAddress, String screenName, String userId) throws Exception { String postfix = getPropertyPostfix(ldapServerId); String filter = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_AUTH_SEARCH_FILTER + postfix); if (_log.isDebugEnabled()) { _log.debug("Search filter before transformation " + filter); } filter = StringUtil.replace( filter, new String[] {"@company_id@", "@email_address@", "@screen_name@", "@user_id@"}, new String[] {String.valueOf(companyId), emailAddress, screenName, userId}); LDAPUtil.validateFilter(filter); if (_log.isDebugEnabled()) { _log.debug("Search filter after transformation " + filter); } return filter; }
protected NtlmManager getNtlmManager(long companyId) { String domain = PrefsPropsUtil.getString(companyId, PropsKeys.NTLM_DOMAIN, _ntlmConfiguration.domain()); String domainController = PrefsPropsUtil.getString( companyId, PropsKeys.NTLM_DOMAIN_CONTROLLER, _ntlmConfiguration.domainController()); String domainControllerName = PrefsPropsUtil.getString( companyId, PropsKeys.NTLM_DOMAIN_CONTROLLER_NAME, _ntlmConfiguration.domainControllerName()); String serviceAccount = PrefsPropsUtil.getString( companyId, PropsKeys.NTLM_SERVICE_ACCOUNT, _ntlmConfiguration.serviceAccount()); String servicePassword = PrefsPropsUtil.getString( companyId, PropsKeys.NTLM_SERVICE_PASSWORD, _ntlmConfiguration.servicePassword()); NtlmManager ntlmManager = _ntlmManagers.get(companyId); if (ntlmManager == null) { ntlmManager = new NtlmManager( _netlogonConnectionManager, domain, domainController, domainControllerName, serviceAccount, servicePassword); _ntlmManagers.put(companyId, ntlmManager); } else { if (!Validator.equals(ntlmManager.getDomain(), domain) || !Validator.equals(ntlmManager.getDomainController(), domainController) || !Validator.equals(ntlmManager.getDomainControllerName(), domainControllerName) || !Validator.equals(ntlmManager.getServiceAccount(), serviceAccount) || !Validator.equals(ntlmManager.getServicePassword(), servicePassword)) { ntlmManager.setConfiguration( domain, domainController, domainControllerName, serviceAccount, servicePassword); } } return ntlmManager; }
public boolean isOpenOfficeServerEnabled() { if (_openOfficeServerEnabled == null) { _openOfficeServerEnabled = PrefsPropsUtil.getBoolean( PropsKeys.OPENOFFICE_SERVER_ENABLED, PropsValues.OPENOFFICE_SERVER_ENABLED); } return _openOfficeServerEnabled; }
protected void storeThumbnailmage(FileVersion fileVersion, RenderedImage renderedImage, int index) throws Exception { if (!isThumbnailEnabled(index) || hasThumbnail(fileVersion, index)) { return; } String type = getThumbnailType(fileVersion); String maxHeightPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_HEIGHT; String maxWidthPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_WIDTH; if (index == THUMBNAIL_INDEX_CUSTOM_1) { maxHeightPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_1_MAX_HEIGHT; maxWidthPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_1_MAX_WIDTH; } else if (index == THUMBNAIL_INDEX_CUSTOM_2) { maxHeightPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_2_MAX_HEIGHT; maxWidthPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_2_MAX_WIDTH; } RenderedImage thumbnailRenderedImage = ImageToolUtil.scale( renderedImage, PrefsPropsUtil.getInteger(maxHeightPropsKey), PrefsPropsUtil.getInteger(maxWidthPropsKey)); byte[] bytes = ImageToolUtil.getBytes(thumbnailRenderedImage, type); File file = null; try { file = FileUtil.createTempFile(bytes); addFileToStore( fileVersion.getCompanyId(), THUMBNAIL_PATH, getThumbnailFilePath(fileVersion, type, index), file); } finally { FileUtil.delete(file); } }
@Override public int getMaxAge(Group group) { int trashEntriesMaxAge = PrefsPropsUtil.getInteger( group.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE, PropsValues.TRASH_ENTRIES_MAX_AGE); UnicodeProperties typeSettingsProperties = group.getParentLiveGroupTypeSettingsProperties(); return GetterUtil.getInteger( typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAge); }
@Override public boolean isTrashEnabled(Group group) { boolean companyTrashEnabled = PrefsPropsUtil.getBoolean(group.getCompanyId(), PropsKeys.TRASH_ENABLED); if (!companyTrashEnabled) { return false; } UnicodeProperties typeSettingsProperties = group.getParentLiveGroupTypeSettingsProperties(); return GetterUtil.getBoolean(typeSettingsProperties.getProperty("trashEnabled"), true); }
@Override public Properties getUserExpandoMappings(long ldapServerId, long companyId) throws Exception { String postfix = getPropertyPostfix(ldapServerId); Properties userExpandoMappings = PropertiesUtil.load( PrefsPropsUtil.getString( companyId, PropsKeys.LDAP_USER_CUSTOM_MAPPINGS + postfix, StringPool.BLANK)); LogUtil.debug(_log, userExpandoMappings); return userExpandoMappings; }
@Override public String getThumbnailStyle(boolean max, int margin) throws Exception { StringBundler sb = new StringBundler(5); if (max) { sb.append("max-height: "); } else { sb.append("height: "); } sb.append(PrefsPropsUtil.getLong(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_HEIGHT) + 2 * margin); if (max) { sb.append("px; max-width: "); } else { sb.append("px; width: "); } sb.append(PrefsPropsUtil.getLong(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_WIDTH) + 2 * margin); sb.append("px;"); return sb.toString(); }
@Override public Properties getContactMappings(long ldapServerId, long companyId) throws Exception { String postfix = getPropertyPostfix(ldapServerId); Properties contactMappings = PropertiesUtil.load( PrefsPropsUtil.getString( companyId, PropsKeys.LDAP_CONTACT_MAPPINGS + postfix, StringPool.BLANK)); LogUtil.debug(_log, contactMappings); return contactMappings; }
@Override public boolean isVisible(User user, Group group) { if (group == null) { return false; } boolean trashEnabled = PrefsPropsUtil.getBoolean(group.getCompanyId(), PropsKeys.TRASH_ENABLED); if (!trashEnabled) { return false; } return true; }
public boolean isTrashEnabled(long groupId) throws PortalException, SystemException { Group group = GroupLocalServiceUtil.getGroup(groupId); UnicodeProperties typeSettingsProperties = group.getParentLiveGroupTypeSettingsProperties(); boolean companyTrashEnabled = PrefsPropsUtil.getBoolean(group.getCompanyId(), PropsKeys.TRASH_ENABLED); if (!companyTrashEnabled) { return false; } return GetterUtil.getBoolean(typeSettingsProperties.getProperty("trashEnabled"), true); }
protected boolean isThumbnailEnabled(int index) throws Exception { if (index == THUMBNAIL_INDEX_DEFAULT) { if (GetterUtil.getBoolean(PropsUtil.get(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_ENABLED))) { return true; } } else if (index == THUMBNAIL_INDEX_CUSTOM_1) { if ((PrefsPropsUtil.getInteger(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_1_MAX_HEIGHT) > 0) || (PrefsPropsUtil.getInteger(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_1_MAX_WIDTH) > 0)) { return true; } } else if (index == THUMBNAIL_INDEX_CUSTOM_2) { if ((PrefsPropsUtil.getInteger(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_2_MAX_HEIGHT) > 0) || (PrefsPropsUtil.getInteger(PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_2_MAX_WIDTH) > 0)) { return true; } } return false; }
public int getMaxAge(Group group) throws PortalException, SystemException { if (group.isLayout()) { group = group.getParentGroup(); } int trashEntriesMaxAge = PrefsPropsUtil.getInteger( group.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE, GetterUtil.getInteger(PropsUtil.get(PropsKeys.TRASH_ENTRIES_MAX_AGE))); UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties(); return GetterUtil.getInteger( typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAge); }
@Override public boolean isFilterEnabled(HttpServletRequest request, HttpServletResponse response) { try { long companyId = PortalInstances.getCompanyId(request); if (BrowserSnifferUtil.isIe(request) && PrefsPropsUtil.getBoolean( companyId, PropsKeys.NTLM_AUTH_ENABLED, _ntlmConfiguration.enabled())) { return true; } } catch (Exception e) { _log.error(e, e); } return false; }
private DLUtil() { _allMediaGalleryMimeTypes.addAll( SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_AUDIO_MIME_TYPES))); _allMediaGalleryMimeTypes.addAll( SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_MIME_TYPES))); _allMediaGalleryMimeTypes.addAll( SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_IMAGE_MIME_TYPES))); _allMediaGalleryMimeTypesString = StringUtil.merge(_allMediaGalleryMimeTypes); String[] fileIcons = null; try { fileIcons = PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_ICONS, StringPool.COMMA); } catch (Exception e) { _log.error(e, e); fileIcons = new String[] {StringPool.BLANK}; } for (int i = 0; i < fileIcons.length; i++) { // Only process non wildcard extensions if (!StringPool.STAR.equals(fileIcons[i])) { // Strip starting period String extension = fileIcons[i]; extension = extension.substring(1, extension.length()); _fileIcons.add(extension); } } String[] genericNames = PropsUtil.getArray(PropsKeys.DL_FILE_GENERIC_NAMES); for (String genericName : genericNames) { _populateGenericNamesMap(genericName); } }
@Override public boolean isScopeIdSelectable( PermissionChecker permissionChecker, String scopeId, long companyGroupId, Layout layout) throws PortalException, SystemException { long groupId = getGroupIdFromScopeId(scopeId, layout.getGroupId(), layout.isPrivateLayout()); if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) { Group group = GroupLocalServiceUtil.getGroup(groupId); if (!group.hasAncestor(layout.getGroupId())) { return false; } } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) { Group siteGroup = layout.getGroup(); if (!siteGroup.hasAncestor(groupId)) { return false; } if (SitesUtil.isContentSharingWithChildrenEnabled(siteGroup)) { return true; } if (!PrefsPropsUtil.getBoolean( layout.getCompanyId(), PropsKeys.SITES_CONTENT_SHARING_THROUGH_ADMINISTRATORS_ENABLED)) { return false; } return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE); } else if (groupId != companyGroupId) { return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE); } return true; }
protected void sendEmail( String emailAddress, MemberRequest memberRequest, ThemeDisplay themeDisplay) throws Exception { long companyId = memberRequest.getCompanyId(); Group group = groupLocalService.getGroup(memberRequest.getGroupId()); User user = userLocalService.getUser(memberRequest.getUserId()); User receiverUser = null; if (memberRequest.getReceiverUserId() > 0) { receiverUser = userLocalService.getUser(memberRequest.getReceiverUserId()); } String fromName = PrefsPropsUtil.getString(companyId, "admin.email.from.name"); String fromAddress = PrefsPropsUtil.getString(companyId, "admin.email.from.address"); String toName = StringPool.BLANK; String toAddress = emailAddress; if (receiverUser != null) { toName = receiverUser.getFullName(); } ClassLoader classLoader = getClass().getClassLoader(); String subject = StringUtil.read(classLoader, "com/liferay/so/invitemembers/dependencies/subject.tmpl"); String body = StringPool.BLANK; if (memberRequest.getReceiverUserId() > 0) { body = StringUtil.read( classLoader, "com/liferay/so/invitemembers/dependencies/" + "existing_user_body.tmpl"); } else { body = StringUtil.read( classLoader, "com/liferay/so/invitemembers/dependencies/" + "new_user_body.tmpl"); } String createAccountURL = getCreateAccountURL(memberRequest.getKey(), themeDisplay); String loginURL = getLoginURL(memberRequest.getKey(), themeDisplay); subject = StringUtil.replace( subject, new String[] {"[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_USER$]"}, new String[] {group.getDescriptiveName(), user.getFullName()}); body = StringUtil.replace( body, new String[] { "[$ADMIN_ADDRESS$]", "[$ADMIN_NAME$]", "[$MEMBER_REQUEST_CREATE_ACCOUNT_URL$]", "[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_LOGIN_URL$]", "[$MEMBER_REQUEST_USER$]" }, new String[] { fromAddress, fromName, createAccountURL, group.getDescriptiveName(), loginURL, user.getFullName() }); InternetAddress from = new InternetAddress(fromAddress, fromName); InternetAddress to = new InternetAddress(toAddress, toName); MailMessage mailMessage = new MailMessage(from, to, subject, body, true); MailServiceUtil.sendEmail(mailMessage); }
/** TODO: Remove. This should extend from EditFileEntryAction once it is modularized. */ protected void handleUploadException( PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse, String cmd, Exception e) throws Exception { if (e instanceof AssetCategoryException || e instanceof AssetTagException) { SessionErrors.add(actionRequest, e.getClass(), e); } else if (e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException || e instanceof DuplicateFolderNameException || e instanceof FileExtensionException || e instanceof FileMimeTypeException || e instanceof FileNameException || e instanceof FileSizeException || e instanceof LiferayFileItemException || e instanceof NoSuchFolderException || e instanceof SourceFileNameException || e instanceof StorageFieldRequiredException) { if (!cmd.equals(Constants.ADD_DYNAMIC) && !cmd.equals(Constants.ADD_MULTIPLE) && !cmd.equals(Constants.ADD_TEMP)) { if (e instanceof AntivirusScannerException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { SessionErrors.add(actionRequest, e.getClass()); } return; } else if (cmd.equals(Constants.ADD_TEMP)) { hideDefaultErrorMessage(actionRequest); } if (e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException || e instanceof FileExtensionException || e instanceof FileNameException || e instanceof FileSizeException) { HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); response.setContentType(ContentTypes.TEXT_HTML); response.setStatus(HttpServletResponse.SC_OK); String errorMessage = StringPool.BLANK; int errorType = 0; ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); if (e instanceof AntivirusScannerException) { AntivirusScannerException ase = (AntivirusScannerException) e; errorMessage = themeDisplay.translate(ase.getMessageKey()); errorType = ServletResponseConstants.SC_FILE_ANTIVIRUS_EXCEPTION; } if (e instanceof DuplicateFileEntryException) { errorMessage = themeDisplay.translate("please-enter-a-unique-document-name"); errorType = ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION; } else if (e instanceof FileExtensionException) { errorMessage = themeDisplay.translate( "please-enter-a-file-with-a-valid-extension-x", StringUtil.merge( getAllowedFileExtensions(portletConfig, actionRequest, actionResponse))); errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION; } else if (e instanceof FileNameException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name"); errorType = ServletResponseConstants.SC_FILE_NAME_EXCEPTION; } else if (e instanceof FileSizeException) { long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if (fileMaxSize == 0) { fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE); } errorMessage = themeDisplay.translate( "please-enter-a-file-with-a-valid-file-size-no-larger" + "-than-x", TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale())); errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION; } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("message", errorMessage); jsonObject.put("status", errorType); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } if (e instanceof AntivirusScannerException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { SessionErrors.add(actionRequest, e.getClass()); } } else if (e instanceof DuplicateLockException || e instanceof InvalidFileVersionException || e instanceof NoSuchFileEntryException || e instanceof PrincipalException) { if (e instanceof DuplicateLockException) { DuplicateLockException dle = (DuplicateLockException) e; SessionErrors.add(actionRequest, dle.getClass(), dle.getLock()); } else { SessionErrors.add(actionRequest, e.getClass()); } actionResponse.setRenderParameter("mvcPath", "/html/porltet/document_library/error.jsp"); } else { Throwable cause = e.getCause(); if (cause instanceof DuplicateFileEntryException) { SessionErrors.add(actionRequest, DuplicateFileEntryException.class); } else { throw e; } } }
@Override public List<Group> getUserSitesGroups() throws PortalException { try { User user = getUser(); List<Group> groups = new ArrayList<>(); LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>(); groupParams.put("active", true); groupParams.put("usersGroups", user.getUserId()); List<Group> userSiteGroups = groupLocalService.search( user.getCompanyId(), null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (Group userSiteGroup : userSiteGroups) { if (SyncUtil.isSyncEnabled(userSiteGroup)) { userSiteGroup.setName(userSiteGroup.getDescriptiveName()); groups.add(userSiteGroup); } } List<Organization> organizations = organizationLocalService.getOrganizations( user.getUserId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); for (Organization organization : organizations) { Group userOrganizationGroup = organization.getGroup(); if (SyncUtil.isSyncEnabled(userOrganizationGroup)) { groups.add(userOrganizationGroup); } if (!GetterUtil.getBoolean(PropsUtil.get(PropsKeys.ORGANIZATIONS_MEMBERSHIP_STRICT))) { for (Organization ancestorOrganization : organization.getAncestors()) { Group userAncestorOrganizationGroup = ancestorOrganization.getGroup(); if (SyncUtil.isSyncEnabled(userAncestorOrganizationGroup)) { groups.add(userAncestorOrganizationGroup); } } } } if (PrefsPropsUtil.getBoolean( user.getCompanyId(), PortletPropsKeys.SYNC_ALLOW_USER_PERSONAL_SITES, PortletPropsValues.SYNC_ALLOW_USER_PERSONAL_SITES)) { groups.add(user.getGroup()); } Collections.sort(groups, new GroupNameComparator()); return ListUtil.unique(groups); } catch (PortalException pe) { throw new PortalException(pe.getClass().getName(), pe); } }
/** TODO: Remove. This should extend from EditFileEntryAction once it is modularized. */ protected String[] getAllowedFileExtensions( PortletConfig portletConfig, PortletRequest portletRequest, PortletResponse portletResponse) throws PortalException { return PrefsPropsUtil.getStringArray(PropsKeys.DL_FILE_EXTENSIONS, StringPool.COMMA); }
/** TODO: Remove. This should extend from EditFileEntryAction once it is modularized. */ protected String getAddMultipleFileEntriesErrorMessage( PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse, Exception e) throws Exception { String errorMessage = null; ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); if (e instanceof AntivirusScannerException) { AntivirusScannerException ase = (AntivirusScannerException) e; errorMessage = themeDisplay.translate(ase.getMessageKey()); } else if (e instanceof AssetCategoryException) { AssetCategoryException ace = (AssetCategoryException) e; AssetVocabulary assetVocabulary = ace.getVocabulary(); String vocabularyTitle = StringPool.BLANK; if (assetVocabulary != null) { vocabularyTitle = assetVocabulary.getTitle(themeDisplay.getLocale()); } if (ace.getType() == AssetCategoryException.AT_LEAST_ONE_CATEGORY) { errorMessage = themeDisplay.translate("please-select-at-least-one-category-for-x", vocabularyTitle); } else if (ace.getType() == AssetCategoryException.TOO_MANY_CATEGORIES) { errorMessage = themeDisplay.translate( "you-cannot-select-more-than-one-category-for-x", vocabularyTitle); } } else if (e instanceof DuplicateFileEntryException) { errorMessage = themeDisplay.translate( "the-folder-you-selected-already-has-an-entry-with-this-name." + "-please-select-a-different-folder"); } else if (e instanceof FileExtensionException) { errorMessage = themeDisplay.translate( "please-enter-a-file-with-a-valid-extension-x", StringUtil.merge( getAllowedFileExtensions(portletConfig, actionRequest, actionResponse))); } else if (e instanceof FileNameException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name"); } else if (e instanceof FileSizeException) { long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if (fileMaxSize == 0) { fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE); } errorMessage = themeDisplay.translate( "please-enter-a-file-with-a-valid-file-size-no-larger-than-x", TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale())); } else if (e instanceof InvalidFileEntryTypeException) { errorMessage = themeDisplay.translate("the-document-type-you-selected-is-not-valid-for-this-folder"); } else { errorMessage = themeDisplay.translate("an-unexpected-error-occurred-while-saving-your-document"); } return errorMessage; }
protected Object[] updateGroup(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long userId = PortalUtil.getUserId(actionRequest); long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId"); long parentGroupId = ParamUtil.getLong( actionRequest, "parentGroupSearchContainerPrimaryKeys", GroupConstants.DEFAULT_PARENT_GROUP_ID); String name = null; String description = null; int type = 0; String friendlyURL = null; boolean active = false; ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest); Group liveGroup = null; String oldFriendlyURL = null; String oldStagingFriendlyURL = null; if (liveGroupId <= 0) { // Add group name = ParamUtil.getString(actionRequest, "name"); description = ParamUtil.getString(actionRequest, "description"); type = ParamUtil.getInteger(actionRequest, "type"); friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL"); active = ParamUtil.getBoolean(actionRequest, "active"); liveGroup = GroupServiceUtil.addGroup( parentGroupId, GroupConstants.DEFAULT_LIVE_GROUP_ID, name, description, type, friendlyURL, true, active, serviceContext); LiveUsers.joinGroup(themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId); } else { // Update group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId); oldFriendlyURL = liveGroup.getFriendlyURL(); name = ParamUtil.getString(actionRequest, "name", liveGroup.getName()); description = ParamUtil.getString(actionRequest, "description", liveGroup.getDescription()); type = ParamUtil.getInteger(actionRequest, "type", liveGroup.getType()); friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL", liveGroup.getFriendlyURL()); active = ParamUtil.getBoolean(actionRequest, "active", liveGroup.getActive()); liveGroup = GroupServiceUtil.updateGroup( liveGroupId, parentGroupId, name, description, type, friendlyURL, active, serviceContext); if (type == GroupConstants.TYPE_SITE_OPEN) { List<MembershipRequest> membershipRequests = MembershipRequestLocalServiceUtil.search( liveGroupId, MembershipRequestConstants.STATUS_PENDING, QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (MembershipRequest membershipRequest : membershipRequests) { MembershipRequestServiceUtil.updateStatus( membershipRequest.getMembershipRequestId(), themeDisplay.translate("your-membership-has-been-approved"), MembershipRequestConstants.STATUS_APPROVED, serviceContext); LiveUsers.joinGroup( themeDisplay.getCompanyId(), membershipRequest.getGroupId(), new long[] {membershipRequest.getUserId()}); } } } // Settings UnicodeProperties typeSettingsProperties = liveGroup.getTypeSettingsProperties(); String customJspServletContextName = ParamUtil.getString( actionRequest, "customJspServletContextName", typeSettingsProperties.getProperty("customJspServletContextName")); typeSettingsProperties.setProperty("customJspServletContextName", customJspServletContextName); typeSettingsProperties.setProperty( "defaultSiteRoleIds", ListUtil.toString(getRoles(actionRequest), Role.ROLE_ID_ACCESSOR, StringPool.COMMA)); typeSettingsProperties.setProperty( "defaultTeamIds", ListUtil.toString(getTeams(actionRequest), Team.TEAM_ID_ACCESSOR, StringPool.COMMA)); String[] analyticsTypes = PrefsPropsUtil.getStringArray( themeDisplay.getCompanyId(), PropsKeys.ADMIN_ANALYTICS_TYPES, StringPool.NEW_LINE); for (String analyticsType : analyticsTypes) { if (analyticsType.equalsIgnoreCase("google")) { String googleAnalyticsId = ParamUtil.getString( actionRequest, "googleAnalyticsId", typeSettingsProperties.getProperty("googleAnalyticsId")); typeSettingsProperties.setProperty("googleAnalyticsId", googleAnalyticsId); } else { String analyticsScript = ParamUtil.getString( actionRequest, SitesUtil.ANALYTICS_PREFIX + analyticsType, typeSettingsProperties.getProperty(analyticsType)); typeSettingsProperties.setProperty( SitesUtil.ANALYTICS_PREFIX + analyticsType, analyticsScript); } } String publicRobots = ParamUtil.getString( actionRequest, "publicRobots", liveGroup.getTypeSettingsProperty("false-robots.txt")); String privateRobots = ParamUtil.getString( actionRequest, "privateRobots", liveGroup.getTypeSettingsProperty("true-robots.txt")); typeSettingsProperties.setProperty("false-robots.txt", publicRobots); typeSettingsProperties.setProperty("true-robots.txt", privateRobots); int trashEnabled = ParamUtil.getInteger( actionRequest, "trashEnabled", GetterUtil.getInteger(typeSettingsProperties.getProperty("trashEnabled"))); typeSettingsProperties.setProperty("trashEnabled", String.valueOf(trashEnabled)); int trashEntriesMaxAgeCompany = PrefsPropsUtil.getInteger(themeDisplay.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE); int defaultTrashEntriesMaxAgeGroup = GetterUtil.getInteger( typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAgeCompany); int trashEntriesMaxAgeGroup = ParamUtil.getInteger(actionRequest, "trashEntriesMaxAge", defaultTrashEntriesMaxAgeGroup); if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) { typeSettingsProperties.setProperty( "trashEntriesMaxAge", String.valueOf(trashEntriesMaxAgeGroup)); } else { typeSettingsProperties.remove("trashEntriesMaxAge"); } // Virtual hosts LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet(); String publicVirtualHost = ParamUtil.getString( actionRequest, "publicVirtualHost", publicLayoutSet.getVirtualHostname()); LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), false, publicVirtualHost); LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet(); String privateVirtualHost = ParamUtil.getString( actionRequest, "privateVirtualHost", privateLayoutSet.getVirtualHostname()); LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), true, privateVirtualHost); // Staging if (liveGroup.hasStagingGroup()) { Group stagingGroup = liveGroup.getStagingGroup(); oldStagingFriendlyURL = stagingGroup.getFriendlyURL(); friendlyURL = ParamUtil.getString(actionRequest, "stagingFriendlyURL", stagingGroup.getFriendlyURL()); GroupServiceUtil.updateFriendlyURL(stagingGroup.getGroupId(), friendlyURL); LayoutSet stagingPublicLayoutSet = stagingGroup.getPublicLayoutSet(); publicVirtualHost = ParamUtil.getString( actionRequest, "stagingPublicVirtualHost", stagingPublicLayoutSet.getVirtualHostname()); LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), false, publicVirtualHost); LayoutSet stagingPrivateLayoutSet = stagingGroup.getPrivateLayoutSet(); privateVirtualHost = ParamUtil.getString( actionRequest, "stagingPrivateVirtualHost", stagingPrivateLayoutSet.getVirtualHostname()); LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), true, privateVirtualHost); } liveGroup = GroupServiceUtil.updateGroup(liveGroup.getGroupId(), typeSettingsProperties.toString()); // Layout set prototypes if (!liveGroup.isStaged()) { long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId"); long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId"); boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean( actionRequest, "privateLayoutSetPrototypeLinkEnabled", privateLayoutSet.isLayoutSetPrototypeLinkEnabled()); boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean( actionRequest, "publicLayoutSetPrototypeLinkEnabled", publicLayoutSet.isLayoutSetPrototypeLinkEnabled()); if ((privateLayoutSetPrototypeId == 0) && (publicLayoutSetPrototypeId == 0) && !privateLayoutSetPrototypeLinkEnabled && !publicLayoutSetPrototypeLinkEnabled) { long layoutSetPrototypeId = ParamUtil.getLong(actionRequest, "layoutSetPrototypeId"); int layoutSetVisibility = ParamUtil.getInteger(actionRequest, "layoutSetVisibility"); boolean layoutSetPrototypeLinkEnabled = ParamUtil.getBoolean( actionRequest, "layoutSetPrototypeLinkEnabled", (layoutSetPrototypeId > 0)); if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) { privateLayoutSetPrototypeId = layoutSetPrototypeId; privateLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled; } else { publicLayoutSetPrototypeId = layoutSetPrototypeId; publicLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled; } } SitesUtil.updateLayoutSetPrototypesLinks( liveGroup, publicLayoutSetPrototypeId, privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled, privateLayoutSetPrototypeLinkEnabled); } // Staging String redirect = ParamUtil.getString(actionRequest, "redirect"); long refererPlid = GetterUtil.getLong(HttpUtil.getParameter(redirect, "refererPlid", false)); if (!privateLayoutSet.isLayoutSetPrototypeLinkActive() && !publicLayoutSet.isLayoutSetPrototypeLinkActive()) { if ((refererPlid > 0) && liveGroup.hasStagingGroup() && (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) { Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout( liveGroup.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); if (firstLayout == null) { firstLayout = LayoutLocalServiceUtil.fetchFirstLayout( liveGroup.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); } if (firstLayout != null) { refererPlid = firstLayout.getPlid(); } else { refererPlid = 0; } } StagingUtil.updateStaging(actionRequest, liveGroup); } return new Object[] {liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid}; }
protected void sendEmail( String emailAddress, MemberRequest memberRequest, ServiceContext serviceContext) throws Exception { long companyId = memberRequest.getCompanyId(); Group group = groupLocalService.getGroup(memberRequest.getGroupId()); User user = userLocalService.getUser(memberRequest.getUserId()); User receiverUser = null; if (memberRequest.getReceiverUserId() > 0) { receiverUser = userLocalService.getUser(memberRequest.getReceiverUserId()); } String fromName = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_NAME); String fromAddress = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS); String toName = StringPool.BLANK; String toAddress = emailAddress; if (receiverUser != null) { toName = receiverUser.getFullName(); } String subject = StringUtil.read(getClassLoader(), "com/liferay/so/invitemembers/dependencies/subject.tmpl"); String body = StringPool.BLANK; if (memberRequest.getReceiverUserId() > 0) { body = StringUtil.read( getClassLoader(), "com/liferay/so/invitemembers/dependencies/" + "existing_user_body.tmpl"); } else { body = StringUtil.read( getClassLoader(), "com/liferay/so/invitemembers/dependencies/" + "new_user_body.tmpl"); } subject = StringUtil.replace( subject, new String[] {"[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_USER$]"}, new String[] { group.getDescriptiveName(serviceContext.getLocale()), user.getFullName() }); String createAccountURL = (String) serviceContext.getAttribute("createAccountURL"); if (Validator.isNull(createAccountURL)) { createAccountURL = serviceContext.getPortalURL(); } createAccountURL = HttpUtil.addParameter(createAccountURL, "key", memberRequest.getKey()); String loginURL = (String) serviceContext.getAttribute("loginURL"); if (Validator.isNull(loginURL)) { loginURL = serviceContext.getPortalURL(); } loginURL = HttpUtil.addParameter(loginURL, "key", memberRequest.getKey()); body = StringUtil.replace( body, new String[] { "[$ADMIN_ADDRESS$]", "[$ADMIN_NAME$]", "[$MEMBER_REQUEST_CREATE_ACCOUNT_URL$]", "[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_LOGIN_URL$]", "[$MEMBER_REQUEST_USER$]" }, new String[] { fromAddress, fromName, createAccountURL, group.getDescriptiveName(serviceContext.getLocale()), loginURL, user.getFullName() }); InternetAddress from = new InternetAddress(fromAddress, fromName); InternetAddress to = new InternetAddress(toAddress, toName); MailMessage mailMessage = new MailMessage(from, to, subject, body, true); MailServiceUtil.sendEmail(mailMessage); }
protected void sendEmail(WallEntry wallEntry, ThemeDisplay themeDisplay) throws Exception { long companyId = wallEntry.getCompanyId(); String portalURL = PortalUtil.getPortalURL(themeDisplay); String layoutURL = PortalUtil.getLayoutURL(themeDisplay); String wallEntryURL = portalURL + layoutURL; Group group = GroupLocalServiceUtil.getGroup(wallEntry.getGroupId()); User user = userLocalService.getUserById(group.getClassPK()); User wallEntryUser = userLocalService.getUserById(wallEntry.getUserId()); String fromName = PrefsPropsUtil.getString(companyId, "admin.email.from.name"); String fromAddress = PrefsPropsUtil.getString(companyId, "admin.email.from.address"); String toName = user.getFullName(); String toAddress = user.getEmailAddress(); ClassLoader classLoader = getClass().getClassLoader(); String subject = StringUtil.read( classLoader, "com/liferay/socialnetworking/wall/dependencies/" + "wall_entry_added_subject.tmpl"); String body = StringUtil.read( classLoader, "com/liferay/socialnetworking/wall/dependencies/" + "wall_entry_added_body.tmpl"); subject = StringUtil.replace( subject, new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$TO_ADDRESS$]", "[$TO_NAME$]", "[$WALL_ENTRY_URL$]", "[$WALL_ENTRY_USER_ADDRESS$]", "[$WALL_ENTRY_USER_NAME$]" }, new String[] { fromAddress, fromName, toAddress, toName, wallEntryURL, wallEntryUser.getEmailAddress(), wallEntryUser.getFullName() }); body = StringUtil.replace( body, new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$TO_ADDRESS$]", "[$TO_NAME$]", "[$WALL_ENTRY_URL$]", "[$WALL_ENTRY_USER_ADDRESS$]", "[$WALL_ENTRY_USER_NAME$]" }, new String[] { fromAddress, fromName, toAddress, toName, wallEntryURL, wallEntryUser.getEmailAddress(), wallEntryUser.getFullName() }); InternetAddress from = new InternetAddress(fromAddress, fromName); InternetAddress to = new InternetAddress(toAddress, toName); MailMessage mailMessage = new MailMessage(from, to, subject, body, true); MailServiceUtil.sendEmail(mailMessage); }