List of usage examples for com.liferay.portal.kernel.json JSONObject getInt
public int getInt(String key);
From source file:com.evozon.evoportal.my_account.wrapper.UserExpandoWrapper.java
public int getStatusWorkflowStatus() { int workflowStatus = -1; JSONObject currentStatus = getCurrentStatus(); if (currentStatus != null) { workflowStatus = currentStatus.getInt("status"); }//ww w . j a va2s . com return workflowStatus; }
From source file:com.evozon.evoportal.my_account.wrapper.UserExpandoWrapper.java
public int getRemainingFreeDaysFromYear(int year) { int remainingFromYear = 0; try {/* w w w . j av a 2s .co m*/ String remDaysFromLastStr = user.getExpandoBridge() .getAttribute(MyAccountConstants.REMAINING_FREE_DAYS_LAST, false).toString(); if (!remDaysFromLastStr.isEmpty()) { JSONObject yearsSituation = JSONFactoryUtil.createJSONObject(remDaysFromLastStr); String pastYearStr = String.valueOf(year); if (yearsSituation.has(pastYearStr)) { JSONObject yearJSON = yearsSituation.getJSONObject(pastYearStr); remainingFromYear = yearJSON.getInt(MyAccountConstants.DAYS_LEFT); } } } catch (JSONException e) { log.error("Couldn't retrieve remaining free days from last year for user: " + user.getFullName()); } return remainingFromYear; }
From source file:com.liferay.announcements.uad.exporter.test.AnnouncementsEntryUADEntityExporterTest.java
License:Open Source License
private void _verifyFileEntry(FileEntry fileEntry, AnnouncementsEntry announcementsEntry) throws Exception { InputStream is = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion());//from ww w . ja v a 2 s . c o m StringWriter stringWriter = new StringWriter(); IOUtils.copy(is, stringWriter, StringPool.UTF8); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(stringWriter.toString()); Assert.assertEquals(announcementsEntry.getEntryId(), jsonObject.getInt("entryId")); }
From source file:com.liferay.announcements.uad.exporter.test.AnnouncementsFlagUADEntityExporterTest.java
License:Open Source License
private void _verifyFileEntry(FileEntry fileEntry, AnnouncementsFlag announcementsFlag) throws Exception { InputStream is = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion());//from w w w .j a v a2 s .co m StringWriter stringWriter = new StringWriter(); IOUtils.copy(is, stringWriter, StringPool.UTF8); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(stringWriter.toString()); Assert.assertEquals(announcementsFlag.getFlagId(), jsonObject.getInt("flagId")); }
From source file:com.liferay.bookmarks.uad.exporter.test.BookmarksEntryUADEntityExporterTest.java
License:Open Source License
private void _verifyFileEntry(FileEntry fileEntry, BookmarksEntry bookmarksEntry) throws Exception { InputStream is = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(), fileEntry.getVersion());//w ww . j a v a2s . com StringWriter stringWriter = new StringWriter(); IOUtils.copy(is, stringWriter, StringPool.UTF8); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(stringWriter.toString()); Assert.assertEquals(bookmarksEntry.getEntryId(), jsonObject.getInt("entryId")); }
From source file:com.liferay.comment.web.internal.notifications.CommentUserNotificationHandler.java
License:Open Source License
@Override protected String getTitle(JSONObject jsonObject, AssetRenderer assetRenderer, ServiceContext serviceContext) { MBDiscussion mbDiscussion = fetchDiscussion(jsonObject); if (mbDiscussion == null) { return null; }//from ww w . j ava 2s . c om String message = StringPool.BLANK; int notificationType = jsonObject.getInt("notificationType"); if (notificationType == UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY) { if (assetRenderer != null) { message = "x-added-a-new-comment-to-x"; } else { message = "x-added-a-new-comment"; } } else if (notificationType == UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY) { if (assetRenderer != null) { message = "x-updated-a-comment-to-x"; } else { message = "x-updated-a-comment"; } } if (assetRenderer != null) { message = LanguageUtil.format(serviceContext.getLocale(), message, new String[] { HtmlUtil.escape(_portal.getUserName(jsonObject.getLong("userId"), StringPool.BLANK)), HtmlUtil.escape(assetRenderer.getTitle(serviceContext.getLocale())) }, false); } else { message = LanguageUtil.format(serviceContext.getLocale(), message, new String[] { HtmlUtil.escape(_portal.getUserName(jsonObject.getLong("userId"), StringPool.BLANK)) }, false); } return message; }
From source file:com.liferay.content.targeting.rule.age.AgeRule.java
License:Open Source License
@Override public boolean evaluate(HttpServletRequest request, RuleInstance ruleInstance, AnonymousUser anonymousUser) throws Exception { User user = anonymousUser.getUser(); if (user == null) { return false; }/*from w w w . j a v a 2 s. c om*/ JSONObject jsonObj = JSONFactoryUtil.createJSONObject(ruleInstance.getTypeSettings()); int youngerThan = jsonObj.getInt("youngerThan"); int olderThan = jsonObj.getInt("olderThan"); int age = getAge(user.getBirthday()); if ((age > olderThan) && (age < youngerThan)) { return true; } return false; }
From source file:com.liferay.content.targeting.rule.age.AgeRule.java
License:Open Source License
@Override public String getSummary(RuleInstance ruleInstance, Locale locale) { String typeSettings = ruleInstance.getTypeSettings(); String summary = StringPool.BLANK; try {/*from w ww.j a v a 2s .c o m*/ JSONObject jsonObj = JSONFactoryUtil.createJSONObject(typeSettings); int youngerThan = jsonObj.getInt("youngerThan"); int olderThan = jsonObj.getInt("olderThan"); if ((youngerThan > 0) && (olderThan > 0)) { summary = LanguageUtil.format(locale, "users-between-x-and-x-years-old", new Object[] { olderThan, youngerThan }); } else if (youngerThan > 0) { summary = LanguageUtil.format(locale, "users-younger-than-x-years-old", youngerThan); } else if (olderThan > 0) { summary = LanguageUtil.format(locale, "users-older-than-x-years-old", olderThan); } } catch (JSONException jse) { } return summary; }
From source file:com.liferay.content.targeting.rule.age.AgeRule.java
License:Open Source License
@Override protected void populateContext(RuleInstance ruleInstance, Map<String, Object> context, Map<String, String> values) { int youngerThan = 100; int olderThan = 0; if (!values.isEmpty()) { youngerThan = GetterUtil.getInteger(values.get("youngerThan")); olderThan = GetterUtil.getInteger(values.get("olderThan")); } else if (ruleInstance != null) { String typeSettings = ruleInstance.getTypeSettings(); try {// ww w . j a v a2 s. com JSONObject jsonObj = JSONFactoryUtil.createJSONObject(typeSettings); youngerThan = jsonObj.getInt("youngerThan"); olderThan = jsonObj.getInt("olderThan"); } catch (JSONException jse) { } } context.put("youngerThan", youngerThan); context.put("olderThan", olderThan); boolean birthdayEnabled = false; Company company = (Company) context.get("company"); try { birthdayEnabled = PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.FIELD_ENABLE_COM_LIFERAY_PORTAL_MODEL_CONTACT_BIRTHDAY); } catch (SystemException se) { } context.put("birthdayEnabled", birthdayEnabled); if (!birthdayEnabled) { boolean hasPortalSettingsViewPermission = ContentTargetingContextUtil .hasControlPanelPortletViewPermission(context, PortletKeys.PORTAL_SETTINGS); if (hasPortalSettingsViewPermission) { Map<String, String> params = new HashMap<String, String>(); params.put("historyKey", "_130_users"); context.put("portalSettingsURL", ContentTargetingContextUtil.getControlPanelPortletURL(context, PortletKeys.PORTAL_SETTINGS, params)); } } }
From source file:com.liferay.content.targeting.rule.device.DeviceRule.java
License:Open Source License
@Override protected void populateContext(RuleInstance ruleInstance, Map<String, Object> context, Map<String, String> values) { long mdrRuleGroupId = 0; if (!values.isEmpty()) { mdrRuleGroupId = GetterUtil.getInteger(values.get("mdrRuleGroupId")); } else if (ruleInstance != null) { String typeSettings = ruleInstance.getTypeSettings(); try {//from w w w . j a v a2 s. c om JSONObject jsonObj = JSONFactoryUtil.createJSONObject(typeSettings); mdrRuleGroupId = jsonObj.getInt("mdrRuleGroupId"); } catch (JSONException jse) { } } context.put("mdrRuleGroupId", mdrRuleGroupId); LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); params.put("includeGlobalScope", Boolean.TRUE); long groupId = GetterUtil.getLong(context.get("scopeGroupId")); List<MDRRuleGroup> mdrRuleGroups = new ArrayList<MDRRuleGroup>(); try { mdrRuleGroups = MDRRuleGroupLocalServiceUtil.searchByKeywords(groupId, null, params, false, QueryUtil.ALL_POS, QueryUtil.ALL_POS); } catch (SystemException se) { _log.error(se); } context.put("mdrRuleGroups", mdrRuleGroups); boolean hasMDRViewPermission = ContentTargetingContextUtil.hasControlPanelPortletViewPermission(context, PortletKeys.MOBILE_DEVICE_SITE_ADMIN); if (hasMDRViewPermission) { context.put("mDRURL", ContentTargetingContextUtil.getSiteAdministrationPortletURL(context, PortletKeys.MOBILE_DEVICE_SITE_ADMIN, null)); } }