List of usage examples for com.liferay.portal.kernel.language LanguageUtil format
public static String format(ResourceBundle resourceBundle, String pattern, Object[] arguments)
From source file:com.liferay.lms.service.impl.LearningActivityLocalServiceImpl.java
License:Open Source License
public LearningActivity addLearningActivity(long userId, long groupId, int status, Map<Locale, String> title, Map<Locale, String> description, int typeId, Date startdate, Date enddate, long precedence, long tries, int passpuntuation, long moduleId, String extracontent, String feedbackCorrect, String feedbackNoCorrect, long weightinmodule, long teamId, ServiceContext serviceContext) throws PortalException, SystemException { User user = userLocalService.getUser(userId); String titleAux = title.get(user.getLocale()); Date now = new Date(); LearningActivity learningActivity = learningActivityPersistence .create(counterLocalService.increment(LearningActivity.class.getName())); learningActivity.setCompanyId(user.getCompanyId()); learningActivity.setGroupId(groupId); learningActivity.setUserId(user.getUserId()); learningActivity.setUserName(user.getFullName()); learningActivity.setCreateDate(serviceContext.getCreateDate(now)); learningActivity.setModifiedDate(serviceContext.getModifiedDate(now)); learningActivity.setStatus(status);//from w ww . jav a 2 s . c om learningActivity.setStatusByUserId(user.getUserId()); learningActivity.setStatusByUserName(user.getFullName()); learningActivity.setStatusDate(serviceContext.getModifiedDate(now)); learningActivity.setTitleMap(title, serviceContext.getLocale()); learningActivity.setDescriptionMap(description, serviceContext.getLocale()); learningActivity.setTypeId(typeId); learningActivity.setStartdate(startdate); learningActivity.setEnddate(enddate); learningActivity.setPrecedence(precedence); learningActivity.setTries(tries); learningActivity.setPasspuntuation(passpuntuation); learningActivity.setPriority(learningActivity.getActId()); learningActivity.setModuleId(moduleId); learningActivity.setExtracontent(extracontent); learningActivity.setFeedbackCorrect(feedbackCorrect); learningActivity.setFeedbackNoCorrect(feedbackNoCorrect); learningActivity.setWeightinmodule(weightinmodule); learningActivity.setExpandoBridgeAttributes(serviceContext); learningActivity = LmsLocaleUtil.checkDefaultLocale(LearningActivity.class, learningActivity, "title"); learningActivity = LmsLocaleUtil.checkDefaultLocale(LearningActivity.class, learningActivity, "description"); learningActivityPersistence.update(learningActivity, true); resourceLocalService.addModelResources(learningActivity, serviceContext); assetEntryLocalService.updateEntry(userId, learningActivity.getGroupId(), LearningActivity.class.getName(), learningActivity.getActId(), learningActivity.getUuid(), typeId, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), true, null, null, new java.util.Date(System.currentTimeMillis()), null, ContentTypes.TEXT_HTML, learningActivity.getTitle().length() < 255 ? learningActivity.getTitle() : learningActivity.getTitle(Locale.getDefault()), null, learningActivity.getDescription(serviceContext.getLocale()), null, null, 0, 0, null, false); socialActivityLocalService.addUniqueActivity(learningActivity.getUserId(), learningActivity.getGroupId(), LearningActivity.class.getName(), learningActivity.getActId(), 0, StringPool.BLANK, 0); Role siteMemberRole = RoleLocalServiceUtil.getRole(serviceContext.getCompanyId(), RoleConstants.SITE_MEMBER); if (Validator.isNull(teamId)) { if ((moduleId != 0) && (GetterUtil.getBoolean( PrefsPropsUtil.getString("learningactivity.default.hidenewactivity", StringPool.FALSE)))) { resourcePermissionLocalService.removeResourcePermission(siteMemberRole.getCompanyId(), LearningActivity.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(learningActivity.getActId()), siteMemberRole.getRoleId(), ActionKeys.VIEW); } else { resourcePermissionLocalService.setResourcePermissions(siteMemberRole.getCompanyId(), LearningActivity.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(learningActivity.getActId()), siteMemberRole.getRoleId(), new String[] { ActionKeys.VIEW }); } } else { Team team = teamLocalService.getTeam(teamId); Role teamMemberRole = roleLocalService.getTeamRole(team.getCompanyId(), team.getTeamId()); if ((moduleId != 0) && (GetterUtil.getBoolean( PrefsPropsUtil.getString("learningactivity.default.hidenewactivity", StringPool.FALSE)))) { resourcePermissionLocalService.removeResourcePermission(team.getCompanyId(), LearningActivity.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(learningActivity.getActId()), teamMemberRole.getRoleId(), ActionKeys.VIEW); } else { resourcePermissionLocalService.setResourcePermissions(team.getCompanyId(), LearningActivity.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(learningActivity.getActId()), teamMemberRole.getRoleId(), new String[] { ActionKeys.VIEW }); } } //auditing AuditingLogFactory.audit(learningActivity.getCompanyId(), learningActivity.getGroupId(), LearningActivity.class.getName(), learningActivity.getPrimaryKey(), serviceContext.getUserId(), AuditConstants.ADD, null); boolean isNotificationActivated = PrefsPropsUtil.getBoolean(learningActivity.getCompanyId(), "lms.notifications.active"); if (isNotificationActivated && learningActivity.getTypeId() != 8) { List<User> listaUsuarios = userService.getGroupUsers(learningActivity.getGroupId()); Iterator<User> it = listaUsuarios.iterator(); while (it.hasNext()) { User u = it.next(); try { if (u.isActive() && !(PermissionCheckerFactoryUtil.create(u)).hasPermission( learningActivity.getGroupId(), "com.liferay.lms.model", learningActivity.getGroupId(), "VIEW_RESULTS") && !learningActivity.isInactive() && !learningActivity.isExpired() && !moduleService.isLocked(learningActivity.getModuleId()) && !courseLocalService.getCourseByGroupCreatedId(learningActivity.getGroupId()) .isInactive() && !courseLocalService.getCourseByGroupCreatedId(learningActivity.getGroupId()) .isExpired() && !courseLocalService.getCourseByGroupCreatedId(learningActivity.getGroupId()) .isClosed()) { String courseTitle = courseLocalService .getCourseByGroupCreatedId(learningActivity.getGroupId()).getTitle(u.getLocale()); String subject = LanguageUtil.format(u.getLocale(), "notif.modification.new.title", null); String body = LanguageUtil.format(u.getLocale(), "notif.modification.new.body", new String[] { titleAux, courseTitle }); sendNotification(subject, body, "", "announcements.type.general", 1, serviceContext, startdate, enddate, u.getUserId()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return learningActivity; }
From source file:com.liferay.lms.service.impl.LearningActivityLocalServiceImpl.java
License:Open Source License
public LearningActivity modLearningActivity(long actId, String title, String description, java.util.Date createDate, java.util.Date startDate, java.util.Date endDate, int typeId, long tries, int passpuntuation, long moduleId, String extracontent, String feedbackCorrect, String feedbackNoCorrect, ServiceContext serviceContext) throws SystemException, PortalException { long userId = serviceContext.getUserId(); LearningActivity larn = this.getLearningActivity(actId); String titleAux = larn.getTitle(serviceContext.getLocale()); larn.setCompanyId(serviceContext.getCompanyId()); larn.setGroupId(serviceContext.getScopeGroupId()); larn.setUserId(userId);/*w w w . jav a 2 s .c o m*/ larn.setDescription(description); larn.setTitle(title); larn.setStartdate(startDate); larn.setEnddate(endDate); larn.setTries(tries); larn.setPasspuntuation(passpuntuation); larn.setStatus(WorkflowConstants.STATUS_APPROVED); larn.setModuleId(moduleId); larn.setExtracontent(extracontent); larn.setFeedbackCorrect(feedbackCorrect); larn.setFeedbackNoCorrect(feedbackNoCorrect); larn = LmsLocaleUtil.checkDefaultLocale(LearningActivity.class, larn, "title"); larn = LmsLocaleUtil.checkDefaultLocale(LearningActivity.class, larn, "description"); learningActivityPersistence.update(larn, true); try { assetEntryLocalService.updateEntry(userId, larn.getGroupId(), LearningActivity.class.getName(), larn.getActId(), larn.getUuid(), larn.getTypeId(), serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), true, null, null, new java.util.Date(System.currentTimeMillis()), null, ContentTypes.TEXT_HTML, larn.getTitle(), null, larn.getDescription(serviceContext.getLocale()), null, null, 0, 0, null, false); SocialActivityLocalServiceUtil.addActivity(larn.getUserId(), larn.getGroupId(), LearningActivity.class.getName(), larn.getActId(), 1, StringPool.BLANK, 0); } catch (Exception e) { } //auditing AuditingLogFactory.audit(larn.getCompanyId(), larn.getGroupId(), LearningActivity.class.getName(), larn.getPrimaryKey(), serviceContext.getUserId(), AuditConstants.UPDATE, null); boolean isNotificationActivated = PrefsPropsUtil.getBoolean(larn.getCompanyId(), "lms.notifications.active"); if (isNotificationActivated && larn.getTypeId() != 8) { List<User> listaUsuarios = userService.getGroupUsers(larn.getGroupId()); Iterator<User> it = listaUsuarios.iterator(); while (it.hasNext()) { User u = it.next(); try { if (u.isActive() && !(PermissionCheckerFactoryUtil.create(u)).hasPermission(larn.getGroupId(), "com.liferay.lms.model", larn.getGroupId(), "VIEW_RESULTS") && !larn.isInactive() && !larn.isExpired() && !moduleService.isLocked(larn.getModuleId()) && !courseLocalService.getCourseByGroupCreatedId(larn.getGroupId()).isInactive() && !courseLocalService.getCourseByGroupCreatedId(larn.getGroupId()).isExpired() && !courseLocalService.getCourseByGroupCreatedId(larn.getGroupId()).isClosed()) { String courseTitle = courseLocalService.getCourseByGroupCreatedId(larn.getGroupId()) .getTitle(u.getLocale()); String subject = LanguageUtil.format(u.getLocale(), "notif.modification.larn.title", null); String body = LanguageUtil.format(u.getLocale(), "notif.modification.larn.body", new String[] { titleAux, courseTitle }); sendNotification(subject, body, "", "announcements.type.general", 1, serviceContext, startDate, endDate, u.getUserId()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return larn; }
From source file:com.liferay.mail.vaadin.Lang.java
License:Open Source License
public static String get(String key, String... arguments) { return LanguageUtil.format(Controller.get().getUserLocale(), Lang.get(key), arguments); }
From source file:com.liferay.portlet.dynamicdatalists.asset.DDLRecordAssetRenderer.java
License:Open Source License
public String getTitle(Locale locale) { String name = _recordSet.getName(locale); return LanguageUtil.format(locale, "new-record-for-list-x", name); }
From source file:com.liferay.portlet.dynamicdatalists.service.impl.DDLRecordLocalServiceImpl.java
License:Open Source License
public void updateAsset(long userId, DDLRecord record, DDLRecordVersion recordVersion, long[] assetCategoryIds, String[] assetTagNames, Locale locale) throws PortalException, SystemException { boolean addDraftAssetEntry = false; if ((recordVersion != null) && !recordVersion.isApproved()) { String version = recordVersion.getVersion(); if (!version.equals(DDLRecordConstants.VERSION_DEFAULT)) { int approvedRecordVersionsCount = ddlRecordVersionPersistence.countByR_S(record.getRecordId(), WorkflowConstants.STATUS_APPROVED); if (approvedRecordVersionsCount > 0) { addDraftAssetEntry = true; }// www . j a va 2s .c o m } } boolean visible = false; if ((recordVersion != null) && !recordVersion.isApproved()) { visible = false; } DDLRecordSet recordSet = record.getRecordSet(); String title = LanguageUtil.format(locale, "new-record-for-list-x", recordSet.getName(locale)); if (addDraftAssetEntry) { assetEntryLocalService.updateEntry(userId, record.getGroupId(), DDLRecordConstants.getClassName(), recordVersion.getRecordVersionId(), record.getUuid(), 0, assetCategoryIds, assetTagNames, false, null, null, null, null, ContentTypes.TEXT_HTML, title, null, StringPool.BLANK, null, null, 0, 0, null, false); } else { assetEntryLocalService.updateEntry(userId, record.getGroupId(), DDLRecordConstants.getClassName(), record.getRecordId(), record.getUuid(), 0, assetCategoryIds, assetTagNames, visible, null, null, null, null, ContentTypes.TEXT_HTML, title, null, StringPool.BLANK, null, null, 0, 0, null, false); } }
From source file:com.liferay.portlet.dynamicdatamapping.storage.DocumentLibraryFieldRenderer.java
License:Open Source License
@Override protected String doRender(ThemeDisplay themeDisplay, Field field) { Serializable fieldValue = field.getValue(); if (Validator.isNull(fieldValue) || fieldValue.equals(JSONFactoryUtil.getNullJSON())) { return StringPool.BLANK; }/*from w w w .java 2 s. c om*/ JSONObject fieldValueJSONObject = null; try { fieldValueJSONObject = JSONFactoryUtil.createJSONObject(String.valueOf(fieldValue)); } catch (JSONException jsone) { if (_log.isDebugEnabled()) { _log.debug("Unable to parse JSON", jsone); } return StringPool.BLANK; } long fileEntryGroupId = fieldValueJSONObject.getLong("groupId"); String fileEntryUUID = fieldValueJSONObject.getString("uuid"); try { FileEntry fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(fileEntryUUID, fileEntryGroupId); return fileEntry.getTitle(); } catch (Exception e) { if (e instanceof NoSuchFileEntryException || e instanceof PrincipalException) { return LanguageUtil.format(themeDisplay.getLocale(), "is-temporarily-unavailable", "content"); } } return StringPool.BLANK; }
From source file:com.liferay.product.navigation.site.administration.internal.display.context.SiteAdministrationPanelCategoryDisplayContext.java
License:Open Source License
public String getGroupName() throws PortalException { if (_groupName != null) { return _groupName; }/*from ww w . ja v a2s .co m*/ Group group = getGroup(); if (group == null) { _groupName = StringPool.BLANK; } else { if (group.isUser()) { if (group.getClassPK() == _themeDisplay.getUserId()) { _groupName = LanguageUtil.get(_themeDisplay.getRequest(), "my-site"); } else { User user = UserLocalServiceUtil.getUser(group.getClassPK()); _groupName = LanguageUtil.format(getResourceBundle(), "x-site", user.getFullName()); } } else { _groupName = group.getDescriptiveName(_themeDisplay.getLocale()); } } return _groupName; }
From source file:com.liferay.subscription.web.internal.portlet.action.UnsubscribeMVCActionCommand.java
License:Open Source License
private String _getTitle(Locale locale, Subscription subscription) throws PortalException { Group group = _groupLocalService.fetchGroup(subscription.getClassPK()); ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", locale, getClass()); return LanguageUtil.format(resourceBundle, "blog-at-x", group.getDescriptiveName(locale)); }
From source file:com.liferay.taglib.faces.validator.EmailAddressValidator.java
License:Open Source License
public void validate(FacesContext facesContext, UIComponent uiComponent, Object obj) throws ValidatorException { ExternalContext externalContext = facesContext.getExternalContext(); Locale locale = externalContext.getRequestLocale(); if (obj instanceof String) { String emailAddress = (String) obj; if (Validator.isNotNull(emailAddress)) { if (!EmailValidator.getInstance().isValid(emailAddress)) { String summary = LanguageUtil.get(locale, "please-enter-a-valid-email-address"); FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, null); throw new ValidatorException(facesMessage); }//from ww w. ja v a2 s .c o m } } else { String summary = LanguageUtil.format(locale, "validator-expected-type-string,-but-instead-received-type-x", obj.getClass().getName()); FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, null); throw new ValidatorException(facesMessage); } }
From source file:com.liferay.util.bridges.jsf.common.FacesMessageUtil.java
License:Open Source License
private static void _addMessage(String clientId, FacesContext facesContext, Severity severity, String key, Object argument) {//from w w w. ja v a 2 s . co m Locale locale = JSFPortletUtil.getLocale(facesContext); String message = LanguageUtil.format(locale, key, argument); FacesMessage facesMessage = new FacesMessage(severity, message, null); facesContext.addMessage(clientId, facesMessage); }