List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add
public static void add(PortletRequest portletRequest, String key)
From source file:com.evolveum.liferay.usercreatehook.CustomCreateAccountAction.java
License:Apache License
@Override public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { LOG.debug("Before call of original action"); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); // reserved screennames validation part START String screenName = ParamUtil.getString(actionRequest, "screenName"); Set<String> reservedScreennamesSet = new HashSet<String>(); List<String> reservedScreennames = WSConfig.getReservedScreennames(); if (reservedScreennames != null) { reservedScreennamesSet.addAll(reservedScreennames); }//from ww w . j a v a2 s .c o m if (screenName != null && reservedScreennamesSet.contains(screenName.trim())) { SessionErrors.add(actionRequest.getPortletSession(), ReservedUserScreenNameException.class.getName()); return; } // reserved screennames validation part END // custom email validation part START long parentOrganizationId = ParamUtil.getLong(actionRequest, "parentOrganizationId"); long subOrganizationId = ParamUtil.getLong(actionRequest, "organizationId"); long organizationId = -1; if (parentOrganizationId > 0l || subOrganizationId > 0l) { organizationId = subOrganizationId > 0l ? subOrganizationId : parentOrganizationId; Set<String> permittedDomainsSet = new HashSet<String>(); // get addition email addresses of organization List<EmailAddress> organizationEmailAddresses = EmailAddressLocalServiceUtil .getEmailAddresses(company.getCompanyId(), Organization.class.getName(), organizationId); if (organizationEmailAddresses != null) { for (EmailAddress emailAddress : organizationEmailAddresses) { String domain = EmailUtil.getEmailDomain(emailAddress.getAddress()); permittedDomainsSet.add(domain); } } List<String> allwaysPermittedDomains = WSConfig.getAllwaysPermittedEmailDomains(); if (allwaysPermittedDomains != null) { permittedDomainsSet.addAll(allwaysPermittedDomains); } String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); String emailDomain = null; if (emailAddress != null) { emailAddress = emailAddress.trim().toLowerCase(); emailDomain = EmailUtil.getEmailDomain(emailAddress); } if (emailDomain == null || !permittedDomainsSet.contains(emailDomain)) { SessionErrors.add(actionRequest.getPortletSession(), "notPermittedEmailDomainError"); return; } } // custom email validation part END originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse); LOG.debug("After call of original action"); String cmd = ParamUtil.getString(actionRequest, Constants.CMD); if (cmd.equals(Constants.ADD)) { // XXX [mso] hack to get redirect location with created user's login in pattern '...&_58_login=<user-login>' LOG.debug("Trying to get redirect location..."); Class<?> actionResponseImplClass = actionResponse.getClass(); // com.liferay.portlet.ActionResponseImpl Class<?> stateAwareResponseImplClass = actionResponseImplClass.getSuperclass(); // com.liferay.portlet.StateAwareResponseImpl Method redirectLocationMethod = stateAwareResponseImplClass .getDeclaredMethod(METHOD_GET_REDIRECT_LOCATION); String redirectLocation = (String) redirectLocationMethod.invoke(actionResponse, (Object[]) null); LOG.debug("Redirect location: '" + redirectLocation + "'"); if (!StringUtils.isBlank(redirectLocation)) { // user was created // redirect location example for login 'a3': // 'http://localhost:8080/web/guest/what-we-do?p_p_id=58&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin&_58_login=a3' // 1) get his login // 2) update his organizations if any // 1) LOG.debug("Trying to get new user's login from redirect location..."); String login = getLoginFromRedirectUrl(redirectLocation); LOG.debug("User's login: '" + login + "'"); if (!StringUtils.isBlank(login)) { User user = loadUser(company, login); if (user != null) { // 2) if (organizationId > 0l) { LOG.info("Setting organization/suborganization: '" + organizationId + "' to user: '" + login + "'"); UserLocalServiceUtil.addOrganizationUsers(organizationId, new long[] { user.getUserId() }); LOG.debug("Organization/suborganization set successfully"); } } else { LOG.error("Unable to load user for login '" + login + "'"); } } else { LOG.error("Unable to get login from redirect location: '" + redirectLocation + "'"); } } } }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean hasUserAdministrationFieldsValid(ActionRequest actionRequest) { boolean isValid = true; boolean isContractDetailsValid = isContractDetailsValid(actionRequest); if (!isContractDetailsValid) { SessionErrors.add(actionRequest, "hasContractDetailsErrors"); isValid = false;//from ww w. j a v a 2s .c o m logger.error("Contract details are not valid, abort user action."); } boolean isSitesValid = isSitesValid(actionRequest); if (!isSitesValid) { SessionErrors.add(actionRequest, "hasSitesErrors"); isValid = false; logger.error("User departments are not valid, abort user action."); } return isValid; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean hasUserUpdatableFieldsValid(ActionRequest actionRequest, UserFamilyHandler familyManager) { boolean isValid = true; boolean isPersonalDetailsValid = isPersonalDetailsValid(actionRequest); if (!isPersonalDetailsValid) { SessionErrors.add(actionRequest, "hasPersonalDetailsErrors"); isValid = false;//from w w w . jav a 2 s. c om logger.error("Personal details are not valid, abort user creation."); } boolean isFamilyValid = isFamilyValid(actionRequest, familyManager); if (!isFamilyValid) { isValid = false; SessionErrors.add(actionRequest, "hasFamilyErrors"); PortletSession portletSession = actionRequest.getPortletSession(); portletSession.setAttribute("oldFamily", familyManager.getOldModel()); portletSession.setAttribute("newFamily", familyManager.getNewModel()); logger.error("Family is not valid, abort user action."); } return isValid; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean isBirthdayAfterDateHired(ActionRequest actionRequest) { boolean isBirthdayAfterDateHired = true; Calendar birthdayCal = MyAccountUtil .getCalendarFromDate(MyAccountRequestUtil.getBirthdayFromRequest(actionRequest)); Calendar newHiredCal = MyAccountUtil.getCalendarFromDate(MyAccountRequestUtil.getDateHired(actionRequest)); if ((birthdayCal != null) && (newHiredCal != null) && (birthdayCal.compareTo(newHiredCal) >= 0)) { String userId = ParamUtil.getString(actionRequest, "userId"); SessionErrors.add(actionRequest, "birthday-after-hire"); isBirthdayAfterDateHired = false; logger.error("Date hired cannot be BEFORE user's birthday: " + userId); }/*from w w w . jav a2s. co m*/ return isBirthdayAfterDateHired; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean verifyPhoneNumber(ActionRequest actionRequest) { String phoneNumber = ParamUtil.getString(actionRequest, "phoneNumber", StringPool.BLANK); phoneNumber = phoneNumber.replace(",", StringPool.BLANK); phoneNumber = phoneNumber.replace("-", StringPool.BLANK); phoneNumber = phoneNumber.replace(";", StringPool.BLANK); phoneNumber = phoneNumber.replace("/", StringPool.BLANK); phoneNumber = phoneNumber.replace(".", StringPool.BLANK); phoneNumber = phoneNumber.replace(" ", StringPool.BLANK); if (!isNumericInput(phoneNumber)) { SessionErrors.add(actionRequest, "invalid-phone-number"); return false; }// www . java 2s . co m return true; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean verifyFunctieCIM(ActionRequest actionRequest) { boolean isValid = true; String functieCIM = ParamUtil.getString(actionRequest, MyAccountConstants.EXPANDO_JOB_ATTRIBUTE); if (functieCIM.equals(LIFERAY_NEW_LINE)) { isValid = false;/* w w w. j a v a 2s .c o m*/ SessionErrors.add(actionRequest, "please-specify-functiecim"); } else { SessionMessages.add(actionRequest, "previousFunctieCIM", functieCIM); } return isValid; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean verifyLicensePlate(ActionRequest actionRequest) { boolean isValid = true; String licensePlate = ParamUtil.getString(actionRequest, MyAccountConstants.EXPANDO_LICENSE_PLATE); if (isInputLengthValid(licensePlate, MAX_LICENSE_PLATE_LENGTH)) { SessionErrors.add(actionRequest, "license-plate-invalid-length-error"); isValid = false;//from www .j a v a 2 s . co m } // accepted characters licensePlate = licensePlate.replaceAll("-", StringUtils.EMPTY); licensePlate = licensePlate.replaceAll(",", StringUtils.EMPTY); licensePlate = licensePlate.replaceAll(" ", StringUtils.EMPTY); if (!isAlphaNumericInput(licensePlate)) { SessionErrors.add(actionRequest, "license-plate-invalid-characters-error"); isValid = false; } return isValid; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean isCNPContentValid(ActionRequest actionRequest) { boolean isValid = true; String cnp = ParamUtil.getString(actionRequest, MyAccountConstants.USER_CNP); if (StringUtils.length(cnp) != CNP_LENGTH) { SessionErrors.add(actionRequest, "cnp-invalid-length-error"); isValid = false;/*w w w. ja va 2 s . co m*/ } if (!isNumericInput(cnp)) { SessionErrors.add(actionRequest, "cnp-invalid-characters-error"); isValid = false; } return isValid; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
public boolean isSitesValid(ActionRequest actionRequest) { boolean hasValidSites = true; try {//from ww w. j a v a 2 s . co m long[] groupIdSplit = ParamUtil.getLongValues(actionRequest, "groupsSearchContainerPrimaryKeys", new long[] {}); if (groupIdSplit.length > 0) { Set<Long> asSet = SetUtil.fromArray(groupIdSplit); long guestGroupId = GroupLocalServiceUtil .getGroup(PortalUtil.getCompanyId(actionRequest), GroupConstants.GUEST).getGroupId(); if (asSet.contains(guestGroupId)) { asSet.remove(guestGroupId); } if (asSet.isEmpty()) { // the user has to be on EvoPortal and at least another // department logger.warn("At least one department has to be specified besides Evoportal."); hasValidSites = false; } } else { logger.debug("No departments are specified."); hasValidSites = false; } } catch (Exception e) { logger.error("Error getting new user sites.", e); } if (!hasValidSites) { SessionErrors.add(actionRequest, NO_DEPARTMENT_DETECTED); } return hasValidSites; }
From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java
private boolean verifyJobTitle(ActionRequest actionRequest) { boolean isValid = true; String jobTitle = ParamUtil.getString(actionRequest, "jobTitle", StringPool.BLANK); jobTitle = jobTitle.replace(StringPool.PERIOD, StringPool.BLANK).replace(StringPool.MINUS, StringPool.BLANK);/*from w w w. j av a2 s . c o m*/ if (isInputLengthValid(jobTitle)) { SessionErrors.add(actionRequest, "job-title-invalid-length-error"); isValid = false; } if (!isAlphaSpaceStringInput(jobTitle)) { SessionErrors.add(actionRequest, "job-title-invalid-characters-error"); isValid = false; } return isValid; }