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.inkwell.internet.productregistration.registration.portlet.ActionUtil.java
License:Open Source License
/** * Creates a PRUser object out of fields from the request. * * @param request/*from w ww. ja v a 2s. c om*/ * @return */ public static PRUser prUserFromRequest(ActionRequest request) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PRUser prUser = new PRUserImpl(); prUser.setCompanyId(themeDisplay.getCompanyId()); prUser.setGroupId(themeDisplay.getScopeGroupId()); prUser.setFirstName(ParamUtil.getString(request, "firstName")); prUser.setLastName(ParamUtil.getString(request, "lastName")); prUser.setAddress1(ParamUtil.getString(request, "address1")); prUser.setAddress2(ParamUtil.getString(request, "address2")); prUser.setCity(ParamUtil.getString(request, "city")); prUser.setState(ParamUtil.getString(request, "state")); prUser.setPostalCode(ParamUtil.getString(request, "postalCode")); prUser.setPhoneNumber(ParamUtil.getString(request, "phoneNumber")); prUser.setCountry(ParamUtil.getString(request, "country")); prUser.setEmail(ParamUtil.getString(request, "emailAddress")); String gender = ParamUtil.getString(request, "gender"); int birthDateMonth = ParamUtil.getInteger(request, "birthDateMonth"); int birthDateDay = ParamUtil.getInteger(request, "birthDateDay"); int birthDateYear = ParamUtil.getInteger(request, "birthDateYear"); try { prUser.setBirthDate( PortalUtil.getDate(birthDateMonth, birthDateDay, birthDateYear, new PortalException())); } catch (PortalException ex) { prUser.setBirthDate(new Date()); } if (!gender.equals("")) { if (gender.equalsIgnoreCase("male")) { prUser.setMale(true); prUser.setGender("male"); } else { prUser.setMale(false); prUser.setGender("female"); } } else { prUser.setGender(null); } return prUser; }
From source file:com.inkwell.internet.productregistration.registration.portlet.ActionUtil.java
License:Open Source License
/** * Creates a PRRegistration object out of values from the request. * @param request//from ww w .j a va2 s. c o m * @return */ public static PRRegistration prRegistrationFromRequest(ActionRequest request) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PRRegistration registration = new PRRegistrationImpl(); registration.setCompanyId(themeDisplay.getCompanyId()); registration.setGroupId(themeDisplay.getScopeGroupId()); int datePurchasedMonth = ParamUtil.getInteger(request, "datePurchasedMonth"); int datePurchasedDay = ParamUtil.getInteger(request, "datePurchasedDay"); int datePurchasedYear = ParamUtil.getInteger(request, "datePurchasedYear"); try { registration.setDatePurchased(PortalUtil.getDate(datePurchasedMonth, datePurchasedDay, datePurchasedYear, new PortalException())); } catch (PortalException ex) { registration.setDatePurchased(new Date()); } registration.setHowHear(ParamUtil.getString(request, "howHear")); registration.setProductId(Long.parseLong(ParamUtil.getString(request, "productType"))); registration.setPrUserId(ParamUtil.getLong(request, "regUserId")); registration.setSerialNumber(ParamUtil.getString(request, "productSerialNumber")); registration.setWherePurchased(ParamUtil.getString(request, "wherePurchase")); return registration; }
From source file:com.inkwell.internet.productregistration.registration.portlet.ActionUtil.java
License:Open Source License
/** * Creates a PRProduct object out of values from the request. * @param request//from w ww .j a v a 2 s.c o m * @return */ public static PRProduct productFromRequest(ActionRequest request) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PRProduct product = new PRProductImpl(); product.setCompanyId(themeDisplay.getCompanyId()); product.setGroupId(themeDisplay.getScopeGroupId()); product.setProductName(ParamUtil.getString(request, "productName")); product.setSerialNumber(ParamUtil.getString(request, "productSerial")); return product; }
From source file:com.inkwell.internet.productregistration.registration.portlet.ProductAdminPortlet.java
License:Open Source License
/** * This Action adds a product to the database. * * @param request//from w ww . j a va 2 s. c o m * @param response * @throws java.lang.Exception */ public void addProduct(ActionRequest request, ActionResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PRProduct product = ActionUtil.productFromRequest(request); ArrayList<String> errors = new ArrayList<String>(); if (ProdRegValidator.validateProduct(product, errors)) { PRProductLocalServiceUtil.addProduct(product, themeDisplay.getUserId()); SessionMessages.add(request, "product-saved-successfully"); } else { SessionErrors.add(request, "fields-required"); } }
From source file:com.inkwell.internet.productregistration.registration.portlet.ProductAdminPortlet.java
License:Open Source License
/** * Gets all the registrations and puts them in the request. * * @param request/*from w w w . j a va 2s . co m*/ * @param response * @throws PortletException * @throws IOException */ public void editDisplayRegistrations(ActionRequest request, ActionResponse response) throws PortletException, IOException { List<PRRegistration> tempResults = Collections.EMPTY_LIST; ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long groupId = themeDisplay.getLayout().getGroupId(); try { tempResults = PRRegistrationLocalServiceUtil.getAllRegistrations(groupId); } catch (SystemException ex) { _log.debug(ex); } request.setAttribute("registrations", tempResults); response.setRenderParameter("jspPage", displayRegistrationsJSP); }
From source file:com.inkwell.internet.productregistration.registration.portlet.ProductRegistrationPortlet.java
License:Open Source License
/** * Navigate to the Register Product page. * * @param request/*from w w w. j a v a 2 s . c om*/ * @param response */ public void addRegistration(ActionRequest request, ActionResponse response) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PRRegistration registration = new PRRegistrationImpl(); PRUser prUser = new PRUserImpl(); if (themeDisplay.isSignedIn()) { User user = themeDisplay.getUser(); // Now that we have a user, let's see if the portal // knows anything about him or her that we can use on the form List<Address> addresses = Collections.EMPTY_LIST; Address homeAddr = null; try { addresses = AddressLocalServiceUtil.getAddresses(user.getCompanyId(), User.class.getName(), user.getUserId()); } catch (SystemException ex) { // No addresses available; do nothing } if (addresses.size() > 0) { // simple flow; just grab the first one homeAddr = addresses.get(0); } // populate what we can of our registration prUser.setFirstName(user.getFirstName()); prUser.setLastName(user.getLastName()); prUser.setEmail(user.getEmailAddress()); try { prUser.setBirthDate(user.getBirthday()); boolean male = user.getMale(); if (male) { prUser.setGender("male"); } else { prUser.setGender("female"); } prUser.setMale(male); } catch (PortalException e) { prUser.setBirthDate(new Date()); } catch (SystemException e) { prUser.setMale(true); } if (homeAddr != null) { prUser.setAddress1(homeAddr.getStreet1()); prUser.setAddress2(homeAddr.getStreet2()); prUser.setCity(homeAddr.getCity()); prUser.setPostalCode(homeAddr.getZip()); prUser.setCountry(homeAddr.getCountry().toString()); } // Our regUser might have stuff in it now registration.setDatePurchased(new Date()); } else { // user isn't logged in registration.setDatePurchased(new Date()); Calendar dob = CalendarFactoryUtil.getCalendar(); dob.set(Calendar.YEAR, 1970); prUser.setBirthDate(dob.getTime()); prUser.setGender(""); } request.setAttribute("regUser", prUser); request.setAttribute("registration", registration); response.setRenderParameter("jspPage", viewAddRegistrationJSP); }
From source file:com.inkwell.internet.productregistration.registration.portlet.ProductRegistrationPortlet.java
License:Open Source License
/** * Takes a submitted registration and adds it to the database if it passes * validation.//from ww w .j a va 2 s. c om * * @param request * @param response */ public void registerProduct(ActionRequest request, ActionResponse response) throws Exception { PRUser regUser = ActionUtil.prUserFromRequest(request); PRRegistration registration = ActionUtil.prRegistrationFromRequest(request); ArrayList<String> errors = new ArrayList<String>(); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long userId = themeDisplay.getUserId(); User liferayUser = UserLocalServiceUtil.getUser(userId); boolean userValid = ProdRegValidator.validateUser(regUser, errors); boolean regValid = ProdRegValidator.validateRegistration(registration, errors); if (userValid && regValid) { // TODO: Logic needs to change here for multiple registrations and // to check for logged-in users PRUser user = null; // check to see if user is a guest if (liferayUser.isDefaultUser()) { userId = 0; user = PRUserLocalServiceUtil.addPRUser(regUser, userId); } else { // Check to see if we have a PR User from the Liferay user ID user = PRUserLocalServiceUtil.getPRUser(themeDisplay.getScopeGroupId(), userId); if (user == null) { // Create a new mapping regUser.setUserId(userId); user = PRUserLocalServiceUtil.addPRUser(regUser, userId); } } registration.setPrUserId(user.getPrUserId()); PRRegistrationLocalServiceUtil.addRegistration(registration); SessionMessages.add(request, "registration-saved-successfully"); response.setRenderParameter("jspPage", viewThankYouJSP); } else { for (String error : errors) { SessionErrors.add(request, error); } SessionErrors.add(request, "error-saving-registration"); response.setRenderParameter("jspPage", viewAddRegistrationJSP); request.setAttribute("regUser", regUser); request.setAttribute("registration", registration); } }
From source file:com.inkwell.internet.slogan.util.ActionUtil.java
License:Open Source License
/** * Gets slogans out of the service layer. * * @param request//from ww w . j a v a 2 s .c o m * @return List<Slogans> */ @SuppressWarnings("unchecked") public static List<Slogan> getSlogans(RenderRequest request, int start, int end, OrderByComparator obc) { List<Slogan> slogans; ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long groupId = themeDisplay.getScopeGroupId(); try { slogans = SloganLocalServiceUtil.getSlogans(groupId, WorkflowConstants.STATUS_APPROVED, start, end, obc); } catch (SystemException e) { slogans = Collections.EMPTY_LIST; } return slogans; }
From source file:com.inkwell.internet.slogan.util.ActionUtil.java
License:Open Source License
public static List<Slogan> getSlogans(RenderRequest request, int start, int end) { List<Slogan> slogans;/* w w w . j a v a 2s. c om*/ ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long groupId = themeDisplay.getScopeGroupId(); try { slogans = SloganLocalServiceUtil.getSlogans(groupId, WorkflowConstants.STATUS_APPROVED, start, end); } catch (SystemException e) { slogans = Collections.EMPTY_LIST; } return slogans; }
From source file:com.inkwell.internet.slogan.util.ActionUtil.java
License:Open Source License
public static int getSlogansCount(RenderRequest request) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long groupId = themeDisplay.getScopeGroupId(); try {/* w w w .jav a 2s. c o m*/ return SloganLocalServiceUtil.getSlogansCount(groupId, WorkflowConstants.STATUS_APPROVED); } catch (SystemException e) { return 0; } }