List of usage examples for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY
String THEME_DISPLAY
To view the source code for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY.
Click Source Link
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
public void updateEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String redirect = ParamUtil.getString(actionRequest, "redirect"); long entryId = ParamUtil.getLong(actionRequest, "entryId"); String fullName = ParamUtil.getString(actionRequest, "fullName"); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); String comments = ParamUtil.getString(actionRequest, "comments"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); String message = null;//w w w . jav a 2 s . c o m try { Entry entry = null; if (entryId > 0) { entry = EntryLocalServiceUtil.getEntry(entryId); if (entry.getUserId() == themeDisplay.getUserId()) { entry = EntryLocalServiceUtil.updateEntry(entryId, fullName, emailAddress, comments); message = "you-have-successfully-updated-the-contact"; } } else { entry = EntryLocalServiceUtil.addEntry(themeDisplay.getUserId(), fullName, emailAddress, comments); message = "you-have-successfully-added-a-new-contact"; } jsonObject.put("contact", getEntryJSONObject(actionResponse, themeDisplay, entry, redirect)); JSONObject contactsJSONObject = getContactsJSONObject(actionRequest, actionResponse); jsonObject.put("contactList", contactsJSONObject); jsonObject.put("success", Boolean.TRUE); } catch (Exception e) { if (e instanceof ContactFullNameException) { message = "full-name-cannot-be-empty"; } else if (e instanceof DuplicateEntryEmailAddressException) { message = "there-is-already-a-contact-with-this-email-address"; } else if (e instanceof EntryEmailAddressException) { message = "please-enter-a-valid-email-address"; } else { message = "an-error-occurred-while-processing-the-requested-resource"; } jsonObject.put("success", Boolean.FALSE); } jsonObject.put("message", translate(actionRequest, message)); writeJSON(actionRequest, actionResponse, jsonObject); }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
public void updateFieldGroup(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try {//from w w w. j a va 2 s . c o m String fieldGroup = ParamUtil.getString(actionRequest, "fieldGroup"); if (fieldGroup.equals("additionalEmailAddresses")) { updateAdditionalEmailAddresses(actionRequest); } else if (fieldGroup.equals("addresses")) { updateAddresses(actionRequest); } else if (fieldGroup.equals("categorization")) { updateAsset(actionRequest); } else if (fieldGroup.equals("comments") || fieldGroup.equals("details") || fieldGroup.equals("instantMessenger") || fieldGroup.equals("sms") || fieldGroup.equals("socialNetwork")) { updateProfile(actionRequest); } else if (fieldGroup.equals("phoneNumbers")) { updatePhoneNumbers(actionRequest); } else if (fieldGroup.equals("websites")) { updateWebsites(actionRequest); } String redirect = ParamUtil.getString(actionRequest, "redirect"); jsonObject.put("redirect", redirect); jsonObject.put("success", Boolean.TRUE); } catch (Exception e) { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String message = "your-request-failed-to-complete"; if (e instanceof AddressCityException) { message = "please-enter-a-valid-city"; } else if (e instanceof AddressStreetException) { message = "please-enter-a-valid-street"; } else if (e instanceof AddressZipException) { message = "please-enter-a-valid-postal-code"; } else if (e instanceof ContactFirstNameException) { message = "please-enter-a-valid-first-name"; } else if (e instanceof ContactFullNameException) { message = "please-enter-a-valid-first-middle-and-last-name"; } else if (e instanceof ContactLastNameException) { message = "please-enter-a-valid-last-name"; } else if (e instanceof DuplicateUserEmailAddressException) { message = "the-email-address-you-requested-is-already-taken"; } else if (e instanceof EmailAddressException) { message = "please-enter-a-valid-email-address"; } else if (e instanceof NoSuchCountryException) { message = "please-select-a-country"; } else if (e instanceof NoSuchListTypeException) { message = "please-select-a-type"; } else if (e instanceof NoSuchRegionException) { message = "please-select-a-region"; } else if (e instanceof PhoneNumberException) { message = "please-enter-a-valid-phone-number"; } else if (e instanceof ReservedUserEmailAddressException) { message = "the-email-address-you-requested-is-reserveds"; } else if (e instanceof ReservedUserScreenNameException) { message = "the-screen-name-you-requested-is-reserved"; } else if (e instanceof UserEmailAddressException) { message = "please-enter-a-valid-email-address"; } else if (e instanceof UserScreenNameException) { message = "please-enter-a-valid-screen-name"; } else if (e instanceof UserSmsException) { message = "please-enter-a-sms-id-that-is-a-valid-email-address"; } else if (e instanceof WebsiteURLException) { message = "please-enter-a-valid-url"; } jsonObject.put("message", translate(actionRequest, message)); jsonObject.put("success", Boolean.FALSE); } writeJSON(actionRequest, actionResponse, jsonObject); }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
public void updateSocialRequest(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long socialRequestId = ParamUtil.getLong(actionRequest, "socialRequestId"); int status = ParamUtil.getInteger(actionRequest, "status"); long userNotificationEventId = ParamUtil.getLong(actionRequest, "userNotificationEventId"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try {/* w w w . jav a 2s . c o m*/ SocialRequest socialRequest = SocialRequestLocalServiceUtil.getSocialRequest(socialRequestId); if (SocialRelationLocalServiceUtil.hasRelation(socialRequest.getReceiverUserId(), socialRequest.getUserId(), SocialRelationConstants.TYPE_UNI_ENEMY)) { status = SocialRequestConstants.STATUS_IGNORE; } SocialRequestLocalServiceUtil.updateRequest(socialRequestId, status, themeDisplay); if (status == SocialRequestConstants.STATUS_CONFIRM) { SocialRelationLocalServiceUtil.addRelation(socialRequest.getUserId(), socialRequest.getReceiverUserId(), socialRequest.getType()); } jsonObject.put("success", Boolean.TRUE); } catch (Exception e) { jsonObject.put("success", Boolean.FALSE); } writeJSON(actionRequest, actionResponse, jsonObject); }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
protected void deleteEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long entryId = ParamUtil.getLong(actionRequest, "entryId"); if (entryId > 0) { Entry entry = EntryLocalServiceUtil.getEntry(entryId); if (entry.getUserId() == themeDisplay.getUserId()) { EntryLocalServiceUtil.deleteEntry(entryId); }/* w w w .j ava 2s .com*/ } }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
protected JSONObject getContactsDisplayJSONObject(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long[] userIds = StringUtil.split(ParamUtil.getString(actionRequest, "userIds"), 0L); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); JSONObject contactListJSONObject = getContactsJSONObject(actionRequest, actionResponse); jsonObject.put("contactList", contactListJSONObject); JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (long userId : userIds) { JSONObject userJSONObject = JSONFactoryUtil.createJSONObject(); userJSONObject.put("success", Boolean.TRUE); userJSONObject.put("user", getUserJSONObject(actionResponse, themeDisplay, userId)); jsonArray.put(userJSONObject);/* w w w. ja va 2s .c o m*/ } jsonObject.put("contacts", jsonArray); String message = getRelationMessage(actionRequest); jsonObject.put("message", translate(actionRequest, message)); return jsonObject; }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
protected JSONObject getContactsJSONObject(PortletRequest portletRequest, PortletResponse portletResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); String redirect = ParamUtil.getString(portletRequest, "redirect"); String filterBy = ParamUtil.getString(portletRequest, "filterBy"); String keywords = ParamUtil.getString(portletRequest, "keywords"); int start = ParamUtil.getInteger(portletRequest, "start"); int end = ParamUtil.getInteger(portletRequest, "end"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); JSONObject optionsJSONObject = JSONFactoryUtil.createJSONObject(); optionsJSONObject.put("end", end); optionsJSONObject.put("filterBy", filterBy); optionsJSONObject.put("keywords", keywords); optionsJSONObject.put("start", start); jsonObject.put("options", optionsJSONObject); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); String portletId = portletDisplay.getId(); JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); if (filterBy.equals(ContactsConstants.FILTER_BY_DEFAULT) && !portletId.equals(PortletKeys.MEMBERS)) { List<BaseModel<?>> contacts = EntryLocalServiceUtil.searchUsersAndContacts(themeDisplay.getCompanyId(), themeDisplay.getUserId(), keywords, start, end); int contactsCount = EntryLocalServiceUtil.searchUsersAndContactsCount(themeDisplay.getCompanyId(), themeDisplay.getUserId(), keywords); jsonObject.put("count", contactsCount); for (BaseModel<?> contact : contacts) { JSONObject contactJSONObject = null; if (contact instanceof User) { contactJSONObject = getUserJSONObject(portletResponse, themeDisplay, (User) contact); } else { contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, (Entry) contact, redirect);//w w w . j a va2 s. co m } jsonArray.put(contactJSONObject); } } else if (filterBy.equals(ContactsConstants.FILTER_BY_FOLLOWERS) && !portletId.equals(PortletKeys.MEMBERS)) { List<SocialRelation> socialRelations = SocialRelationLocalServiceUtil.getInverseRelations( themeDisplay.getUserId(), SocialRelationConstants.TYPE_UNI_FOLLOWER, start, end); for (SocialRelation socialRelation : socialRelations) { jsonArray.put(getUserJSONObject(portletResponse, themeDisplay, socialRelation.getUserId1())); } } else if (filterBy.equals(ContactsConstants.FILTER_BY_TYPE_MY_CONTACTS) && !portletId.equals(PortletKeys.MEMBERS)) { List<Entry> entries = EntryLocalServiceUtil.search(themeDisplay.getUserId(), keywords, start, end); int entriesCount = EntryLocalServiceUtil.searchCount(themeDisplay.getUserId(), keywords); jsonObject.put("count", entriesCount); for (Entry entry : entries) { JSONObject contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, entry, redirect); jsonArray.put(contactJSONObject); } } else { LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); params.put("inherit", Boolean.TRUE); Group group = themeDisplay.getScopeGroup(); Layout layout = themeDisplay.getLayout(); if (group.isUser() && layout.isPublicLayout()) { params.put("socialRelationType", new Long[] { group.getClassPK(), (long) SocialRelationConstants.TYPE_BI_CONNECTION }); } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_TYPE)) { params.put("socialRelationType", new Long[] { themeDisplay.getUserId(), ContactsUtil.getSocialRelationType(filterBy) }); } if (portletId.equals(PortletKeys.MEMBERS)) { params.put("usersGroups", group.getGroupId()); } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_GROUP)) { params.put("usersGroups", ContactsUtil.getGroupId(filterBy)); } List<User> usersList = null; if (filterBy.equals(ContactsConstants.FILTER_BY_ADMINS)) { Role siteAdministratorRole = RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.SITE_ADMINISTRATOR); params.put("userGroupRole", new Long[] { new Long(group.getGroupId()), new Long(siteAdministratorRole.getRoleId()) }); Set<User> users = new HashSet<User>(); users.addAll(UserLocalServiceUtil.search(themeDisplay.getCompanyId(), keywords, WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator) null)); Role siteOwnerRole = RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.SITE_OWNER); params.put("userGroupRole", new Long[] { new Long(group.getGroupId()), new Long(siteOwnerRole.getRoleId()) }); users.addAll(UserLocalServiceUtil.search(themeDisplay.getCompanyId(), keywords, WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator) null)); usersList = new ArrayList<User>(users); ListUtil.sort(usersList, new UserLastNameComparator(true)); } else { int usersCount = UserLocalServiceUtil.searchCount(themeDisplay.getCompanyId(), keywords, WorkflowConstants.STATUS_APPROVED, params); jsonObject.put("count", usersCount); usersList = UserLocalServiceUtil.search(themeDisplay.getCompanyId(), keywords, WorkflowConstants.STATUS_APPROVED, params, start, end, new UserLastNameComparator(true)); } for (User user : usersList) { JSONObject userJSONObject = getUserJSONObject(portletResponse, themeDisplay, user); jsonArray.put(userJSONObject); } } jsonObject.put("users", jsonArray); return jsonObject; }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
protected void updateAdditionalEmailAddresses(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser();//from w w w.ja v a2 s . c o m List<EmailAddress> emailAddresses = UsersAdminUtil.getEmailAddresses(actionRequest); UsersAdminUtil.updateEmailAddresses(Contact.class.getName(), user.getContactId(), emailAddresses); }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
protected void updateAddresses(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser();/*from w w w . jav a 2s .c o m*/ List<Address> addresses = UsersAdminUtil.getAddresses(actionRequest); UsersAdminUtil.updateAddresses(Contact.class.getName(), user.getContactId(), addresses); }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
protected void updateAsset(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser();/*from w w w .j av a 2 s .c om*/ long[] assetCategoryIds = StringUtil.split(ParamUtil.getString(actionRequest, "assetCategoryNames"), 0L); String[] assetTagNames = StringUtil.split(ParamUtil.getString(actionRequest, "assetTagNames")); UserLocalServiceUtil.updateAsset(user.getUserId(), user, assetCategoryIds, assetTagNames); }
From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java
License:Open Source License
protected void updatePhoneNumbers(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser();/* w ww. ja v a2s.c o m*/ List<Phone> phones = UsersAdminUtil.getPhones(actionRequest); UsersAdminUtil.updatePhones(Contact.class.getName(), user.getContactId(), phones); }