List of usage examples for com.liferay.portal.kernel.servlet SessionMessages add
public static void add(PortletRequest portletRequest, String key)
From source file:org.opencps.usermgt.portlet.UserMgtPortlet.java
License:Open Source License
public void deleteWorkingUnit(ActionRequest actionRequest, ActionResponse actionResponse) throws SystemException, PortalException, IOException { long workingUnitId = ParamUtil.getLong(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_ID); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); List<JobPos> jobPoses = JobPosLocalServiceUtil.getJobPoss(workingUnitId); List<Employee> employees = EmployeeLocalServiceUtil.getEmployees(serviceContext.getScopeGroupId(), workingUnitId);//from www. j av a2s .c o m String returnURL = ParamUtil.getString(actionRequest, "returnURL"); SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); WorkingUnit unit = WorkingUnitLocalServiceUtil.getWorkingUnit(workingUnitId); if (workingUnitId <= 0) { SessionErrors.add(actionRequest, MessageKeys.USERMGT_WORKINGUNIT_DELETE_ERROR_EXIST); } else if (!jobPoses.isEmpty() || !employees.isEmpty()) { SessionErrors.add(actionRequest, MessageKeys.USERMGT_WORKINGUNIT_DELETE_ERROR); } else if (!OrganizationLocalServiceUtil .getOrganizations(unit.getCompanyId(), unit.getMappingOrganisationId()).isEmpty()) { SessionErrors.add(actionRequest, MessageKeys.USERMGT_WORKINGUNIT_DELETE_ERROR); } else { WorkingUnitLocalServiceUtil.deleteWorkingUnitByWorkingUnitId(workingUnitId); SessionMessages.add(actionRequest, MessageKeys.USERMGT_WORKINGUNIT_DELETE_SUCCESS); } if (Validator.isNotNull(returnURL)) { actionResponse.sendRedirect(returnURL); } }
From source file:org.opencps.usermgt.portlet.UserMgtPortlet.java
License:Open Source License
public void updateJobPos(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException, SystemException, IOException { long jobPosId = ParamUtil.getLong(actionRequest, JobPosDisplayTerms.ID_JOBPOS); long[] rowIds = ParamUtil.getLongValues(actionRequest, "rowIds"); int leader = ParamUtil.getInteger(actionRequest, JobPosDisplayTerms.LEADER_JOBPOS); String title = ParamUtil.getString(actionRequest, JobPosDisplayTerms.TITLE_JOBPOS); String returnURL = ParamUtil.getString(actionRequest, "returnURL"); SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); JobPos jobPos = null;//w ww . j a va 2 s . com if (jobPosId > 0) { jobPos = JobPosLocalServiceUtil.fetchJobPos(jobPosId); jobPos = JobPosLocalServiceUtil.updateJobPos(jobPosId, serviceContext.getUserId(), title, StringPool.BLANK, jobPos.getWorkingUnitId(), leader, rowIds, serviceContext); SessionMessages.add(actionRequest, MessageKeys.USERMGT_JOBPOS_UPDATE_SUCESS); if (Validator.isNotNull(returnURL)) { actionResponse.sendRedirect(returnURL); } } else { SessionErrors.add(actionRequest, MessageKeys.USERMGT_JOBPOS_UPDATE_ERROR); if (Validator.isNotNull(returnURL)) { actionResponse.sendRedirect(returnURL); } } }
From source file:org.opencps.usermgt.portlet.UserMgtPortlet.java
License:Open Source License
/** * @param actionRequest//from w w w . ja va 2 s . c om * @param actionResponse * @throws IOException */ public void updateEmployee(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException { long employeeId = ParamUtil.getLong(actionRequest, EmployeeDisplayTerm.EMPLOYEE_ID); long workingUnitId = ParamUtil.getLong(actionRequest, EmployeeDisplayTerm.WORKING_UNIT_ID); long mainJobPosId = ParamUtil.getLong(actionRequest, EmployeeDisplayTerm.MAIN_JOBPOS_ID); long companyId = ParamUtil.getLong(actionRequest, EmployeeDisplayTerm.COMPANY_ID); long groupId = ParamUtil.getLong(actionRequest, EmployeeDisplayTerm.GROUP_ID); String email = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.EMAIL); String userAccountEmail = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.USER_EMAIL); String employeeNo = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.EMPLOYEE_NO); String fullName = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.FULL_NAME); String mobile = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.MOBILE); String telNo = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.TEL_NO); String screenName = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.SCREEN_NAME); String passWord = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.PASS_WORD); String rePassWord = ParamUtil.getString(actionRequest, EmployeeDisplayTerm.RE_PASS_WORD); int gender = ParamUtil.getInteger(actionRequest, EmployeeDisplayTerm.GENDER); int birthDateDay = ParamUtil.getInteger(actionRequest, EmployeeDisplayTerm.BIRTH_DATE_DAY); int birthDateMonth = ParamUtil.getInteger(actionRequest, EmployeeDisplayTerm.BIRTH_DATE_MONTH); int birthDateYear = ParamUtil.getInteger(actionRequest, EmployeeDisplayTerm.BIRTH_DATE_YEAR); int workingStatus = ParamUtil.getBoolean(actionRequest, EmployeeDisplayTerm.WORKING_STATUS, false) == true ? 1 : 0; String redirectURL = ParamUtil.getString(actionRequest, "redirectURL"); int[] jobPosIndexes = StringUtil.split(ParamUtil.getString(actionRequest, "jobPosIndexes"), -1); UserGroup userGroup = null; List<Long> jobPosIds = new ArrayList<Long>(); if (jobPosIndexes != null && jobPosIndexes.length > 0) { for (int i = 0; i < jobPosIndexes.length; i++) { if (jobPosIndexes[i] >= 0) { long jobPosIdTemp = ParamUtil.getLong(actionRequest, EmployeeDisplayTerm.JOBPOS_ID + jobPosIndexes[i]); jobPosIds.add(jobPosIdTemp); } } } try { userGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, PortletPropsValues.USERMGT_USERGROUP_NAME_EMPLOYEE); } catch (Exception e) { _log.warn(e); } try { ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); // Add site for user. Default current site long[] groupIds = new long[] { groupId }; // Add user group if (userGroup == null) { userGroup = UserGroupLocalServiceUtil.addUserGroup(serviceContext.getUserId(), companyId, PortletPropsValues.USERMGT_USERGROUP_NAME_EMPLOYEE, StringPool.BLANK, serviceContext); } long[] userGroupIds = new long[] { userGroup.getUserGroupId() }; // Validate before update validateEmployee(employeeId, fullName, email, employeeNo, mobile, telNo, workingUnitId, mainJobPosId, serviceContext); boolean isAddUser = false; if (Validator.isNotNull(screenName) && Validator.isNotNull(userAccountEmail) && Validator.isNotNull(passWord) && Validator.isNotNull(rePassWord)) { isAddUser = true; } if (employeeId == 0) { EmployeeLocalServiceUtil.addEmployee(serviceContext.getUserId(), employeeNo, fullName, gender, telNo, mobile, email, workingUnitId, workingStatus, mainJobPosId, ArrayUtil.toLongArray(jobPosIds), isAddUser, userAccountEmail, screenName, birthDateDay, birthDateMonth, birthDateYear, passWord, rePassWord, groupIds, userGroupIds, serviceContext); SessionMessages.add(actionRequest, MessageKeys.USERMGT_ADD_SUCCESS); } else { boolean isResetPassWord = (!isAddUser && Validator.isNotNull(passWord) && Validator.isNotNull(rePassWord) && passWord.equals(rePassWord)); EmployeeLocalServiceUtil.updateEmployee(serviceContext.getUserId(), employeeId, employeeNo, fullName, gender, telNo, mobile, email, workingUnitId, workingStatus, mainJobPosId, ArrayUtil.toLongArray(jobPosIds), isAddUser, isResetPassWord, userAccountEmail, screenName, birthDateDay, birthDateMonth, birthDateYear, passWord, rePassWord, groupIds, userGroupIds, serviceContext); SessionMessages.add(actionRequest, MessageKeys.USERMGT_UPDATE_SUCCESS); } if (Validator.isNotNull(redirectURL)) { actionResponse.sendRedirect(redirectURL); } } catch (Exception e) { // PortalUtil.copyRequestParameters(actionRequest, actionResponse); String returnURL = ParamUtil.getString(actionRequest, "returnURL"); if (e instanceof EmptyEmployeeEmailException) { SessionErrors.add(actionRequest, EmptyEmployeeEmailException.class); } else if (e instanceof OutOfLengthEmployeeEmailException) { SessionErrors.add(actionRequest, OutOfLengthEmployeeEmailException.class); } else if (e instanceof EmptyEmployeeNoException) { SessionErrors.add(actionRequest, EmptyEmployeeNoException.class); } else if (e instanceof EmptyEmployeeNameException) { SessionErrors.add(actionRequest, EmptyEmployeeNameException.class); } else if (e instanceof OutOfLengthFullNameException) { SessionErrors.add(actionRequest, OutOfLengthFullNameException.class); } else if (e instanceof NoSuchWorkingUnitException) { SessionErrors.add(actionRequest, NoSuchWorkingUnitException.class); } else if (e instanceof NoSuchJobPosException) { SessionErrors.add(actionRequest, NoSuchJobPosException.class); } else if (e instanceof DuplicateEmployeeEmailException) { SessionErrors.add(actionRequest, DuplicateEmployeeEmailException.class); } else if (e instanceof NoSuchEmployeeException) { SessionErrors.add(actionRequest, NoSuchEmployeeException.class); } else if (e instanceof PortalException) { SessionErrors.add(actionRequest, PortalException.class); } else if (e instanceof SystemException) { SessionErrors.add(actionRequest, SystemException.class); } else if (e instanceof DuplicateUserScreenNameException) { SessionErrors.add(actionRequest, DuplicateUserScreenNameException.class); } else if (e instanceof DuplicateUserEmailAddressException) { SessionErrors.add(actionRequest, DuplicateUserEmailAddressException.class); } else { SessionErrors.add(actionRequest, MessageKeys.USERMGT_SYSTEM_EXCEPTION_OCCURRED); } _log.error(e); actionResponse.setRenderParameter("mvcPath", "/html/portlets/usermgt/admin/edit_employee.jsp"); actionResponse.setRenderParameter("backURL", returnURL); } }
From source file:org.opencps.usermgt.portlet.UserMgtPortlet.java
License:Open Source License
/** * @param actionRequest//www . j av a2 s . co m * @param actionResponse * @throws IOException */ public void updateEmployeeWorkingStatus(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException { long employeeId = ParamUtil.getLong(actionRequest, EmployeeDisplayTerm.EMPLOYEE_ID); int workingStatus = ParamUtil.getInteger(actionRequest, EmployeeDisplayTerm.WORKING_STATUS); String redirectURL = ParamUtil.getString(actionRequest, "redirectURL"); try { ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); EmployeeLocalServiceUtil.updateEmployee(employeeId, workingStatus, serviceContext); SessionMessages.add(actionRequest, MessageKeys.USERMGT_EMPLOYEE_DELETE_SUCCESS); } catch (Exception e) { SessionErrors.add(actionRequest, MessageKeys.USERMGT_EMPLOYEE_DELETE_ERROR); _log.error(e); } finally { if (Validator.isNotNull(redirectURL)) { actionResponse.sendRedirect(redirectURL); } } }
From source file:org.opencps.usermgt.portlet.UserMgtPortlet.java
License:Open Source License
public void updateJobPoses(ActionRequest actionRequest, ActionResponse actionResponse) throws NumberFormatException, PortalException, IOException { String rowIndexes = actionRequest.getParameter("rowIndexes"); long[] rowIds = ParamUtil.getLongValues(actionRequest, "rowIds"); String[] indexOfRows = rowIndexes.split(","); String redirectURL = ParamUtil.getString(actionRequest, "redirectURL"); String returnURL = ParamUtil.getString(actionRequest, "returnURL"); SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); long workingUnitId = ParamUtil.getLong(actionRequest, "workingUnitId"); try {//from w w w . j a v a 2s . c o m int count = 0; ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); for (int index = 0; index < indexOfRows.length; index++) { String title = actionRequest .getParameter(JobPosSearchTerms.TITLE_JOBPOS + indexOfRows[index].trim()); int leader = ParamUtil.getInteger(actionRequest, JobPosSearchTerms.LEADER_JOBPOS + indexOfRows[index].trim()); JobPos jobPos = null; try { jobPos = JobPosLocalServiceUtil.getJobPosByTitle(serviceContext.getScopeGroupId(), title); if (Validator.isNotNull(jobPos)) { count++; } } catch (Exception e) { // TODO: handle exception } JobPosLocalServiceUtil.addJobPos(serviceContext.getUserId(), title, StringPool.BLANK, workingUnitId, leader, rowIds, serviceContext); } if (count == 0) { SessionMessages.add(actionRequest, MessageKeys.USERMGT_JOBPOS_UPDATE_SUCESS); } else { SessionErrors.add(actionRequest, "jobpos-existed-title"); } if (Validator.isNotNull(redirectURL)) { actionResponse.sendRedirect(redirectURL); } } catch (Exception e) { if (e instanceof SystemException) SessionErrors.add(actionRequest, MessageKeys.USERMGT_JOBPOS_UPDATE_ERROR); if (Validator.isNotNull(returnURL)) { actionResponse.sendRedirect(returnURL); } } }
From source file:org.opencps.usermgt.portlet.UserMgtPortlet.java
License:Open Source License
public void updateWorkingUnit(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException { long managerWorkingUnitId = ParamUtil.getLong(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_MANAGERWORKINGUNITID); long workingUnitId = ParamUtil.getLong(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_ID); long parentWorkingUnitId = ParamUtil.getLong(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_PARENTWORKINGUNITID); String name = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_NAME); String enName = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_ENNAME); String address = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_ADDRESS); String telNo = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_TELNO); String faxNo = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_FAXNO); String email = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_EMAIL); String website = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_WEBSITE); String govAgencyCode = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_GOVAGENCYCODE); String cityCode = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_CITYCODE); String districtCode = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_DISTRICTCODE); String wardCode = ParamUtil.getString(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_WARDCODE); ServiceContext serviceContext; boolean isEmployer = ParamUtil.getBoolean(actionRequest, WorkingUnitDisplayTerms.WORKINGUNIT_ISEMPLOYER); String redirectURL = ParamUtil.getString(actionRequest, "redirectURL"); String returnURL = ParamUtil.getString(actionRequest, "returnURL"); String isAddChild = ParamUtil.getString(actionRequest, "isAddChild"); SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); try {/*from w w w. ja v a2 s . c o m*/ serviceContext = ServiceContextFactory.getInstance(actionRequest); validateWorkingUnit(workingUnitId, name, govAgencyCode, enName, address, faxNo, email, website, serviceContext.getScopeGroupId(), parentWorkingUnitId, isEmployer); if (workingUnitId == 0) { WorkingUnitLocalServiceUtil.addWorkingUnit(serviceContext.getUserId(), name, enName, govAgencyCode, parentWorkingUnitId, address, cityCode, districtCode, wardCode, telNo, faxNo, email, website, isEmployer, managerWorkingUnitId, serviceContext); SessionMessages.add(actionRequest, MessageKeys.USERMGT_WORKINGUNIT_UPDATE_SUCESS); } else { if (Validator.isNotNull(isAddChild)) { WorkingUnitLocalServiceUtil.addWorkingUnit(serviceContext.getUserId(), name, enName, govAgencyCode, parentWorkingUnitId, address, cityCode, districtCode, wardCode, telNo, faxNo, email, website, isEmployer, managerWorkingUnitId, serviceContext); SessionMessages.add(actionRequest, MessageKeys.USERMGT_WORKINGUNIT_UPDATE_SUCESS); } else { WorkingUnitLocalServiceUtil.updateWorkingUnit(workingUnitId, serviceContext.getUserId(), name, enName, govAgencyCode, parentWorkingUnitId, address, cityCode, districtCode, wardCode, telNo, faxNo, email, website, isEmployer, managerWorkingUnitId, serviceContext); SessionMessages.add(actionRequest, MessageKeys.USERMGT_WORKINGUNIT_UPDATE_SUCESS); } } if (Validator.isNotNull(redirectURL)) { actionResponse.sendRedirect(redirectURL); } } catch (Exception e) { if (e instanceof OutOfLengthUnitNameException) { SessionErrors.add(actionRequest, OutOfLengthUnitNameException.class); } else if (e instanceof OutOfLengthUnitEnNameException) { SessionErrors.add(actionRequest, OutOfLengthUnitEnNameException.class); } else if (e instanceof DuplicatEgovAgencyCodeException) { SessionErrors.add(actionRequest, DuplicatEgovAgencyCodeException.class); } else if (e instanceof OutOfScopeException) { SessionErrors.add(actionRequest, OutOfScopeException.class); } else if (e instanceof DuplicatWorkingUnitEmailException) { SessionErrors.add(actionRequest, DuplicatWorkingUnitEmailException.class); } else if (e instanceof OutOfLengthUnitEmailException) { SessionErrors.add(actionRequest, OutOfLengthUnitEmailException.class); } if (Validator.isNotNull(returnURL)) { actionResponse.sendRedirect(returnURL); } } }
From source file:org.opencps.usermgt.portlet.UserMgtPortlet.java
License:Open Source License
public void deletePermissionAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException { long permissionId = ParamUtil.getLong(actionRequest, "permissionId"); long bitwide = ParamUtil.getLong(actionRequest, "bitwide"); String returnURL = ParamUtil.getString(actionRequest, "returnURL"); ResourcePermission resourcePermission = null; try {//w w w .j a va2s . c om resourcePermission = ResourcePermissionLocalServiceUtil.getResourcePermission(permissionId); if (resourcePermission != null) { resourcePermission.setActionIds(resourcePermission.getActionIds() - bitwide); ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission); SessionMessages.add(actionRequest, "DELETE_PERMISSION_SUCCESS"); if (Validator.isNotNull(returnURL)) { actionResponse.sendRedirect(returnURL); } } } catch (Exception e) { SessionErrors.add(actionRequest, "DELETE_PERMISSION_ERROR"); if (Validator.isNotNull(returnURL)) { actionResponse.sendRedirect(returnURL); } } }
From source file:org.xcolab.portlets.massmessaging.action.EditMessagingMessageAction.java
License:Open Source License
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String name = ParamUtil.getString(actionRequest, "name"); String description = ParamUtil.getString(actionRequest, "description"); String replyTo = ParamUtil.getString(actionRequest, "replyto"); String subject = ParamUtil.getString(actionRequest, "subject"); String body = ParamUtil.getString(actionRequest, "body"); String recipientsStr = ParamUtil.getString(actionRequest, "recipients"); String messageSenderName = ParamUtil.getString(actionRequest, "messageSenderName"); boolean sendToAll = ParamUtil.getBoolean(actionRequest, "sendtoall"); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Long companyId = themeDisplay.getCompanyId(); if (isNullOrEmpty(name) || isNullOrEmpty(replyTo) || isNullOrEmpty(subject) || isNullOrEmpty(body)) { SessionErrors.add(actionRequest, "Input validation error"); }/*ww w. j a v a 2 s. c om*/ // get ignored recipients List<MessagingIgnoredRecipients> ignoredRecipients = MessagingIgnoredRecipientsLocalServiceUtil .getMessagingIgnoredRecipientses(0, Integer.MAX_VALUE); Set<String> doNotSendSet = new HashSet<String>(); for (MessagingIgnoredRecipients recipient : ignoredRecipients) { doNotSendSet.add(recipient.getEmail()); if (recipient.getName() != null) { doNotSendSet.add(recipient.getName()); } } // validate recipients String[] recipientsArray = recipientsStr.split(MessagingConstants.RECIPIENT_DELIMITER); List<MessagingMessageRecipient> recipients = new ArrayList<MessagingMessageRecipient>(); try { for (String recipientName : recipientsArray) { if (doNotSendSet.contains(recipientName)) { continue; } if (recipientName.trim().equals("")) { continue; } Long recipientId = CounterLocalServiceUtil.increment(MessagingMessageRecipient.class.getName()); MessagingMessageRecipient msgRecipient = MessagingMessageRecipientLocalServiceUtil .createMessagingMessageRecipient(recipientId); if (recipientName.lastIndexOf('@') > 0) { // we have an email if (!recipientName.matches(emailValidationRegexp)) { throw new InvalidMessageRecipientException("Provided email is invalid: " + recipientName); } msgRecipient.setEmailAddress(recipientName); } else if (!sendToAll) { try { User user = UserLocalServiceUtil.getUserByScreenName(companyId, recipientName); if (!doNotSendSet.contains(user.getEmailAddress()) && !doNotSendSet.contains(user.getScreenName())) { msgRecipient.setUserId(user.getUserId()); msgRecipient.setEmailAddress(user.getEmailAddress()); } } catch (NoSuchUserException e) { throw new InvalidMessageRecipientException( "User with screen name: " + recipientName + " doesn't exist", e); } } recipients.add(msgRecipient); } } catch (Exception e) { if (e instanceof InvalidMessageRecipientException) { SessionErrors.add(actionRequest, e.getClass().getName()); } return; } if (recipients.size() == 0 && !sendToAll) { SessionErrors.add(actionRequest, "No recipients given."); return; } // validation complete save Date now = new Date(); Long messageId = CounterLocalServiceUtil.increment(MessagingMessage.class.getName()); MessagingMessage message = MessagingMessageLocalServiceUtil.createMessagingMessage(messageId); StringBuilder messageBody = new StringBuilder(); // rewrite all links to track if they are clicked Matcher linkMatcher = linkSearchRegexp.matcher(body); StringBuilder modifiedBody = new StringBuilder(); int lastAppendIndex = 0; Map<String, String> linkParameters = new HashMap<String, String>(); linkParameters.put(MessagingConstants.PARAMETER_ACTION, MessagingConstants.ACTION_REDIRECT); linkParameters.put(MessagingConstants.PARAMETER_MESSAGE_ID, String.valueOf(messageId)); while (linkMatcher.find()) { int linkEndIndex = body.indexOf('"', linkMatcher.end() + 1); String linkURL = body.substring(linkMatcher.end(), linkEndIndex); Long redirectId = CounterLocalServiceUtil.increment(MessagingRedirectLink.class.getName()); MessagingRedirectLink redirectLink = MessagingRedirectLinkLocalServiceUtil .createMessagingRedirectLink(redirectId); redirectLink.setLink(linkURL); redirectLink.setCreateDate(now); redirectLink.setMessageId(messageId); MessagingRedirectLinkLocalServiceUtil.addMessagingRedirectLink(redirectLink); linkParameters.put(MessagingConstants.PARAMETER_REDIRECT_ID, String.valueOf(redirectId)); linkParameters.put(MessagingConstants.PARAMETER_RECIPIENT_ID, MessagingConstants.RECIPIENT_ID_PLACEHOLDER); String newLink = MessagingUtils.createConvertionLink(linkParameters, actionRequest); modifiedBody.append(body.substring(lastAppendIndex, linkMatcher.end())); modifiedBody.append(newLink); lastAppendIndex = linkEndIndex; } modifiedBody.append(body.substring(lastAppendIndex)); // add link to image to trace mail opening linkParameters.clear(); linkParameters.put(MessagingConstants.PARAMETER_ACTION, MessagingConstants.ACTION_IMAGE); linkParameters.put(MessagingConstants.PARAMETER_MESSAGE_ID, String.valueOf(messageId)); String imgStr = " <img src=\"" + MessagingUtils.createConvertionLink(linkParameters, actionRequest) + "\" />"; messageBody.append(HTML_HEADER); messageBody.append(modifiedBody); messageBody.append(imgStr); messageBody.append(HTML_FOOTER); body = messageBody.toString(); if (sendToAll) { List<User> users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); for (User user : users) { if (!isNullOrEmpty(user.getEmailAddress()) && !doNotSendSet.contains(user.getScreenName()) && !doNotSendSet.contains(user.getEmailAddress())) { Long recipientId = CounterLocalServiceUtil.increment(MessagingMessageRecipient.class.getName()); MessagingMessageRecipient msgRecipient = MessagingMessageRecipientLocalServiceUtil .createMessagingMessageRecipient(recipientId); msgRecipient.setEmailAddress(user.getEmailAddress()); msgRecipient.setUserId(user.getUserId()); recipients.add(msgRecipient); } } } if (recipients.size() == 0) { SessionErrors.add(actionRequest, "No recipients given."); return; } // save all recipients for (MessagingMessageRecipient rec : recipients) { rec.setMessageId(messageId); MessagingMessageRecipientLocalServiceUtil.addMessagingMessageRecipient(rec); } message.setName(name); message.setDescription(description); message.setReplyTo(replyTo); message.setSubject(subject); message.setBody(body.replaceAll(MessagingConstants.RECIPIENT_ID_PLACEHOLDER, String.valueOf(recipients.get(0).getRecipientId()))); message.setConversionCount(0L); message.setCreatorId(themeDisplay.getUserId()); message.setCreateDate(now); message.setModifiedDate(now); message.setSendToAll(sendToAll); MessagingMessageLocalServiceUtil.addMessagingMessage(message); InternetAddress from = new InternetAddress(replyTo); if (!isNullOrEmpty(messageSenderName)) { from.setPersonal(messageSenderName); } for (MessagingMessageRecipient rec : recipients) { InternetAddress to = new InternetAddress(rec.getEmailAddress()); MailEngine.send(from, to, subject, body.replaceAll(MessagingConstants.RECIPIENT_ID_PLACEHOLDER, String.valueOf(rec.getRecipientId())), true); } SessionMessages.add(actionRequest, "Message was sent"); actionResponse.sendRedirect(MessagingConstants.VIEW_MESSAGE_DETAILS + messageId); }
From source file:org.xmlportletfactory.olafk.customer.CustomerPortlet.java
License:Open Source License
@ProcessAction(name = "addCustomer") public void addCustomer(ActionRequest request, ActionResponse response) throws Exception { Customer customer = CustomerFromRequest(request); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (!CustomerPermission.contains(permissionChecker, themeDisplay.getScopeGroupId(), "ADD_CUSTOMER")) { CustomerUtil.addParametersForDefaultView(response); SessionErrors.add(request, "permission-error"); return;//from w ww.j ava 2 s . c o m } ArrayList<String> errors = CustomerValidator.validateCustomer(customer, request); if (errors.isEmpty()) { try { ServiceContext serviceContext = ServiceContextFactory.getInstance(Customer.class.getName(), request); CustomerLocalServiceUtil.addCustomer(customer, serviceContext); CustomerUtil.addParametersForDefaultView(response); SessionMessages.add(request, "customers-added-successfully"); response.setRenderParameter("customerId", "0"); QName qNameCustomer = new QName("http://liferay.com/events", "Customer.customerId"); response.setEvent(qNameCustomer, ParamUtil.getString(request, "customerId")); } catch (Exception cvex) { SessionErrors.add(request, "please-enter-a-unique-code"); PortalUtil.copyRequestParameters(request, response); CustomerUtil.addParametersForAddWithErrors(response); } } else { for (String error : errors) { SessionErrors.add(request, error); } PortalUtil.copyRequestParameters(request, response); CustomerUtil.addParametersForAddWithErrors(response); } }
From source file:org.xmlportletfactory.olafk.customer.CustomerPortlet.java
License:Open Source License
@ProcessAction(name = "deleteCustomer") public void deleteCustomer(ActionRequest request, ActionResponse response) throws Exception { long id = ParamUtil.getLong(request, "resourcePrimKey"); if (Validator.isNotNull(id)) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (!CustomerEntryPermission.contains(permissionChecker, id, ActionKeys.DELETE)) { CustomerUtil.addParametersForDefaultView(response); SessionErrors.add(request, "permission-error"); return; }//w w w .j a v a 2 s . c om Customer customer = CustomerLocalServiceUtil.getCustomer(id); CustomerLocalServiceUtil.deleteCustomerEntry(customer); SessionMessages.add(request, "customers-deleted-successfully"); response.setRenderParameter("customerId", "0"); QName qNameCustomer = new QName("http://liferay.com/events", "Customer.customerId"); response.setEvent(qNameCustomer, ParamUtil.getString(request, "customerId")); } else { SessionErrors.add(request, "customers-error-deleting"); } }