Example usage for com.liferay.portal.kernel.servlet SessionMessages add

List of usage examples for com.liferay.portal.kernel.servlet SessionMessages add

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet SessionMessages add.

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:com.stoxx.portlet.controller.RegistrationController.java

@RenderMapping
public String handleRenderRequest(RenderRequest renderRequest, RenderResponse renderResponse, Model model,
        @ModelAttribute(REGISTRATION_BEAN) RegistrationBean registrationBean) {
    log.info("STOXXRegistrationController.handleRenderRequest()");
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    Boolean isExistingUser = Boolean.FALSE;
    Boolean isDeletedUser = Boolean.FALSE;
    try {//from   w w  w . j a  v  a 2  s  .  c  om
        log.info("the action parameter is " + renderRequest.getParameter(ACTION));
        String portalUrl = PortalUtil.getCurrentURL(renderRequest);
        log.info("current Portal url>>>> " + portalUrl);
        String businessEmailAddressEncrypted = null;
        registrationBean = getListDetails(registrationBean, themeDisplay);
        registrationBean.setCompanyId(themeDisplay.getCompanyId());
        registrationBean.setIsExistingUser(isExistingUser);
        registrationBean.setIsDeletedUser(isDeletedUser);
        if (null != renderRequest.getParameter(ACTION)
                && renderRequest.getParameter(ACTION).equalsIgnoreCase("setupProfileTRANSLATOR")) {
            log.info("for Translator and the email address is $$$$" + businessEmailAddress + AND_BEAN_EMAIL_IS
                    + registrationBean.getBusinessEmailAddress());
            if (Validator.isNotNull(businessEmailAddress)) {
                registrationBean.setBusinessEmailAddress(businessEmailAddress);
            }
            log.info("user type is" + registrationBean.getUserType());
            if (registrationBean.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_VENDOR_USER)) {
                registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean);
                log.info("Company Name >>>>> is" + registrationBean.getCompanyName());
                log.info("Translator agency ID >>>>> is" + registrationBean.getTranslatorAgencyId());
            }
            if (registrationBean.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_STAFF_USER)) {
                registrationBean.setCompanyName(RegistrationConstants.STAFF_COMPANY);
                log.info("Company Name >>>>> is" + registrationBean.getCompanyName());
            }
            if (registrationDelegator.checkIfRegistered(registrationBean.getBusinessEmailAddress())) {
                registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean);
                if (null != registrationBean.getUserType() && registrationBean.getUserType()
                        .equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) {
                    String packageDetails = registrationDelegator
                            .getPackageDetails(registrationBean.getSalesEntryId());
                    log.info(THE_PACKAGE_DETAILS + packageDetails);
                    registrationBean.setPackageDetails(packageDetails);
                }
            }
            registrationBean = getListDetails(registrationBean, themeDisplay);
            registrationBean.setIsExistingUser(isExistingUser);
            registrationBean.setIsDeletedUser(isDeletedUser);
            model.addAttribute(REGISTRATION_BEAN, registrationBean);
            return RegistrationConstants.SETUP_PROFILE;
        } else if (null != renderRequest.getParameter(ACTION)
                && renderRequest.getParameter(ACTION).equalsIgnoreCase("userExists")
                || null != renderRequest.getParameter(ACTION)
                        && renderRequest.getParameter(ACTION).equalsIgnoreCase("invalidEmail")
                || null != renderRequest.getParameter(ACTION)
                        && renderRequest.getParameter(ACTION).equalsIgnoreCase("setupProfileGENERALLICENSED")
                || null != renderRequest.getParameter(ACTION)
                        && renderRequest.getParameter(ACTION).equalsIgnoreCase("setupProfileSTAFF")
                || null != renderRequest.getParameter(ACTION)
                        && renderRequest.getParameter(ACTION).equalsIgnoreCase("setupProfileGENERAL")
                || null != renderRequest.getParameter(ACTION)
                        && renderRequest.getParameter(ACTION).equalsIgnoreCase("linkAlreadysent")) {
            log.info("email address is $$$$" + businessEmailAddress + AND_BEAN_EMAIL_IS
                    + registrationBean.getBusinessEmailAddress());
            businessEmailAddress = registrationBean.getBusinessEmailAddress();
            model.addAttribute(REGISTRATION_BEAN, registrationBean);
            return RegistrationConstants.INITIATE_REGISTRATION;
        } else if (null != renderRequest.getParameter(ACTION)
                && renderRequest.getParameter(ACTION).equalsIgnoreCase("CaptchaException")) {
            log.info("email address is $$$$" + businessEmailAddress + AND_BEAN_EMAIL_IS
                    + registrationBean.getBusinessEmailAddress());
            model.addAttribute(REGISTRATION_BEAN, registrationBean);
            return RegistrationConstants.SETUP_PROFILE;
        } else if (portalUrl.contains(StringPool.QUESTION) && portalUrl.contains(StringPool.DOLLAR)) {
            log.info("inside registration link validation with dollar and questionmark");
            getUserTypeandEmalaIdfromEncrptedUrl(model, registrationBean, portalUrl);
            model.addAttribute(REGISTRATION_BEAN, registrationBean);
            if (Validator.isNotNull(businessEmailAddress) && !registrationBean.getIsExistingUser()) {
                log.info("businessEmailAddress>>>>>>>>>>>>>>>>>>>>>>>>>>" + businessEmailAddress);
                log.info("USER_>>>>>>>>>>>>>>>" + registrationDelegator
                        .checkIfUserExistsInLiferayDB(registrationBean, businessEmailAddress));
                registrationBean.setCompanyId(themeDisplay.getCompanyId());
                boolean isUserExistInCustomDB = registrationDelegator
                        .checkIfUserExistsInLiferay(registrationBean, businessEmailAddress);
                log.info("STOXX_USER" + isUserExistInCustomDB);
                if (registrationDelegator.checkIfUserExistsInLiferayDB(registrationBean, businessEmailAddress)
                        && registrationDelegator.checkIfUserExistsInLiferay(registrationBean,
                                businessEmailAddress)
                        && Validator.isNotNull(registrationBean.getIsDeletedUser())
                        && !registrationBean.getIsDeletedUser()) {
                    log.info("inside dupplicate registration block with dollar an questionmark");
                    SessionErrors.add(renderRequest, USER_EXISTS_KEY);
                } else {
                    if (Validator.isNotNull(registrationBean.getIsDeletedUser())
                            && registrationBean.getIsDeletedUser()) {
                        return RegistrationConstants.INITIATE_REGISTRATION;
                    }
                    if (!isUserExistInCustomDB) {
                        SessionErrors.add(renderRequest, USER_DELETED_KEY);
                    } else {
                        log.info("inside registration block for new registration with dollar an questionmark");
                        if (fetchActivationLinkCreateDateDiff(registrationBean.getBusinessEmailAddress())) {
                            SessionErrors.add(renderRequest, RegistrationConstants.REGISTRATION_LINK_EXPIRED);
                        }
                        if (registrationDelegator.checkIfUserExistsInLiferay(registrationBean)
                                && registrationBean.getUserType()
                                        .equalsIgnoreCase(STOXXConstants.STOXX_STAFF_USER)
                                && registrationBean.getUserType()
                                        .equalsIgnoreCase(STOXXConstants.STOXX_GENERAL_USER)) {
                            SessionMessages.add(renderRequest, "user-activation-link-already-sent");
                        }
                    }
                }
            }
            SessionMessages.add(renderRequest, "user-validation-done");
            return RegistrationConstants.INITIATE_REGISTRATION;
        } else if (null != renderRequest.getParameter(ACTION)
                && renderRequest.getParameter(ACTION).equalsIgnoreCase(EXISTING_USER)) {
            log.info("FOR EXISTING USER STEO 1 >>>>> email address is $$$$" + businessEmailAddress
                    + AND_BEAN_EMAIL_IS + registrationBean.getBusinessEmailAddress());
            registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean);
            if (Validator.isNotNull(registrationBean) && Validator.isNotNull(registrationBean.getStatus())
                    && registrationBean.getStatus() == 3) {
                isExistingUser = Boolean.TRUE;
                registrationBean.setIsExistingUser(isExistingUser);
                registrationBean.setIsDeletedUser(isDeletedUser);
            }
            model.addAttribute(REGISTRATION_BEAN, registrationBean);
            SessionMessages.add(renderRequest, EXISTING_USER);
            return RegistrationConstants.INITIATE_REGISTRATION;
        }

        else if (null != renderRequest.getParameter(ACTION)
                && renderRequest.getParameter(ACTION).equalsIgnoreCase(CUST_USER_EXCEEDED)) {
            log.info("FOR EXCEEDING CUSTOMER  USER STEO 1 >>>>> email address is $$$$"
                    + registrationBean.getBusinessEmailAddress());

            model.addAttribute(REGISTRATION_BEAN, registrationBean);
            SessionMessages.add(renderRequest, CUST_USER_EXCEEDED);
            return RegistrationConstants.INITIATE_REGISTRATION;
        }

        else if (portalUrl.contains(StringPool.QUESTION + EXISTING)) {
            log.info("new existing logic");
            registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean);
            if (Validator.isNotNull(registrationBean) && Validator.isNotNull(registrationBean.getStatus())
                    && registrationBean.getStatus() == 3) {
                isExistingUser = Boolean.TRUE;
                registrationBean.setIsExistingUser(isExistingUser);
            }
            model.addAttribute(REGISTRATION_BEAN, registrationBean);
            SessionErrors.add(renderRequest, USER_EXISTS_MIGRATION_KEY);
            return RegistrationConstants.INITIATE_REGISTRATION;
        } else if (null != renderRequest.getParameter(ACTION)
                && renderRequest.getParameter(ACTION).equalsIgnoreCase("existingUserStep2")
                || null != renderRequest.getParameter(ACTION)
                        && renderRequest.getParameter(ACTION).equalsIgnoreCase(DELETED_USER)) {
            log.info("FOR EXISTING USER STEP 2 >>>>> email address is $$$$" + businessEmailAddress
                    + AND_BEAN_EMAIL_IS + registrationBean.getBusinessEmailAddress());
            registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean, businessEmailAddress);
            log.info("Sales entry id is >>>>>>>>>" + registrationBean.getSalesEntryId()
                    + " and the usertype is >>>>>>" + registrationBean.getUserType());

            if (Validator.isNotNull(registrationBean.getStatus()) && registrationBean.getStatus() == 4
                    && registrationBean.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)
                    && !Validator.isNotNull(registrationBean.getSalesEntryId())) {
                registrationDelegator.updateUserType(registrationBean.getBusinessEmailAddress(),
                        STOXXConstants.STOXX_GENERAL_USER);
                registrationBean.setUserType(STOXXConstants.STOXX_GENERAL_USER);
            }
            User liferayStoxxUser = UserLocalServiceUtil.fetchUserByEmailAddress(themeDisplay.getCompanyId(),
                    businessEmailAddress);

            if (Validator.isNotNull(registrationBean) && Validator.isNotNull(registrationBean.getStatus())
                    && registrationBean.getStatus() == 3) {
                isExistingUser = Boolean.TRUE;
                registrationBean.setIsExistingUser(isExistingUser);
                registrationBean.setIsDeletedUser(isDeletedUser);
                if (Validator.isNotNull(liferayStoxxUser)) {
                    registrationBean = populateFields(registrationBean, themeDisplay, liferayStoxxUser);
                }
                if (Validator.isNotNull(registrationBean.getSalesEntryId()) && registrationBean.getUserType()
                        .equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) {
                    String packageDetails = registrationDelegator
                            .getPackageDetails(registrationBean.getSalesEntryId());
                    log.info(THE_PACKAGE_DETAILS + packageDetails);
                    registrationBean.setPackageDetails(packageDetails);
                }
                getListDetails(registrationBean, themeDisplay);
            }
            if (Validator.isNotNull(registrationBean) && Validator.isNotNull(registrationBean.getStatus())
                    && registrationBean.getStatus() == 4) {
                isDeletedUser = Boolean.TRUE;
                isExistingUser = Boolean.FALSE;
                registrationBean.setIsDeletedUser(isDeletedUser);
                registrationBean.setIsExistingUser(isExistingUser);
                if (Validator.isNotNull(registrationBean.getSalesEntryId()) && registrationBean.getUserType()
                        .equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) {
                    String packageDetails = registrationDelegator
                            .getPackageDetails(registrationBean.getSalesEntryId());
                    log.info(THE_PACKAGE_DETAILS + packageDetails);
                    registrationBean.setPackageDetails(packageDetails);
                }
                User liferayDeletedUser = UserLocalServiceUtil.fetchUserByEmailAddress(
                        themeDisplay.getCompanyId(), registrationBean.getBusinessEmailAddress());
                if (Validator.isNotNull(liferayDeletedUser)) {
                    registrationBean = populateFields(registrationBean, themeDisplay, liferayStoxxUser);
                }

                registrationBean = getListDetails(registrationBean, themeDisplay);
                registrationBean = registrationDelegator
                        .getUserPreferenceDetails(registrationBean.getBusinessEmailAddress(), registrationBean);

            }

            if (!Validator.isNotNull(registrationBean.getStatus()) && liferayStoxxUser.getStatus() == 1
                    && Validator.isNotNull(registrationBean.getSalesEntryId())) {
                log.info("For customer who are going to add by admin into application after deletion.");
                isDeletedUser = Boolean.TRUE;
                isExistingUser = Boolean.FALSE;
                registrationBean.setIsDeletedUser(isDeletedUser);
                registrationBean.setIsExistingUser(isExistingUser);
                if (Validator.isNotNull(registrationBean.getSalesEntryId()) && registrationBean.getUserType()
                        .equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) {
                    String packageDetails = registrationDelegator
                            .getPackageDetails(registrationBean.getSalesEntryId());
                    log.info(THE_PACKAGE_DETAILS + packageDetails);
                    registrationBean.setPackageDetails(packageDetails);
                }
                getListDetails(registrationBean, themeDisplay);
            }

            registrationBean.setIsExistingUser(isExistingUser);
            registrationBean.setIsDeletedUser(isDeletedUser);
            model.addAttribute(REGISTRATION_BEAN, registrationBean);
            return RegistrationConstants.SETUP_PROFILE;
        }

        else if (portalUrl.contains(StringPool.QUESTION)) {
            SessionMessages.add(renderRequest, "user-validation-done");
            registrationBean = new RegistrationBean();
            businessEmailAddressEncrypted = portalUrl.split(StringPool.BACK_SLASH + StringPool.QUESTION)[1];
            log.info("businessEmailAddress value>>>> " + businessEmailAddressEncrypted);
            businessEmailAddress = STOXXEncrypter.decrypt(businessEmailAddressEncrypted, ENCRYPTION_KEY);
            log.info("decrypted email id is>>> " + businessEmailAddress);
            RegistrationBean registrationBean2 = registrationDelegator.fetchFromStoxxUser(registrationBean,
                    businessEmailAddress);
            if (Validator.isNotNull(registrationBean2) && Validator.isNotNull(registrationBean2.getStatus())
                    && registrationBean2.getStatus() == 3) {
                log.info("<<<<<<<<<the user is an eisting user>>>>>>>>");
                isExistingUser = Boolean.TRUE;
                isDeletedUser = Boolean.FALSE;
            }
            registrationBean.setIsExistingUser(isExistingUser);
            registrationBean.setIsDeletedUser(isDeletedUser);
            log.info("inside registration link validation with questionmark");
            registrationBean.setCompanyId(themeDisplay.getCompanyId());
            if (Validator.isNotNull(registrationBean2) && Validator.isNotNull(registrationBean2.getStatus())
                    && registrationBean2.getStatus() == 4 && registrationDelegator
                            .isInactiveUser(registrationBean.getCompanyId(), businessEmailAddress)) {
                log.info("<<<<<<<<< the user has been  deleted previously >>>>>>>>");
                isDeletedUser = Boolean.TRUE;
                isExistingUser = Boolean.FALSE;
            }
            log.info("registrationBean.getIsDeletedUser() " + isDeletedUser);

            if (Validator.isNotNull(businessEmailAddress) && !registrationBean.getIsExistingUser()) {
                if (registrationDelegator.checkIfUserExistsInLiferayDB(registrationBean, businessEmailAddress)
                        && registrationDelegator.checkIfUserExistsInLiferay(registrationBean,
                                businessEmailAddress)
                        && !isDeletedUser) {
                    log.info("inside dupplicate registration block with questionmark");
                    SessionErrors.add(renderRequest, USER_EXISTS_KEY);
                } else {
                    boolean isUserExistInCustomDB = registrationDelegator
                            .checkIfUserExistsInLiferay(registrationBean, businessEmailAddress);
                    log.info("isUserExistInCustomDB : " + isUserExistInCustomDB);
                    if (!isUserExistInCustomDB && !isDeletedUser) {
                        SessionErrors.add(renderRequest, USER_DELETED_KEY);
                    } else {
                        log.info("inside registration block for new registration with questionmark");
                        registrationBean.setBusinessEmailAddress(businessEmailAddress);
                        registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean);
                        registrationBean.setBusinessEmailAddress(businessEmailAddress);
                        log.info(
                                "registartion bean email address" + registrationBean.getBusinessEmailAddress());
                        log.info("the user type is " + registrationBean.getUserType());
                        if (fetchActivationLinkCreateDateDiff(registrationBean.getBusinessEmailAddress())) {
                            SessionErrors.add(renderRequest, RegistrationConstants.REGISTRATION_LINK_EXPIRED);
                        }
                        if (registrationDelegator.checkIfUserExistsInLiferay(registrationBean)
                                && registrationBean.getUserType()
                                        .equalsIgnoreCase(STOXXConstants.STOXX_STAFF_USER)
                                && registrationBean.getUserType()
                                        .equalsIgnoreCase(STOXXConstants.STOXX_GENERAL_USER)) {
                            SessionMessages.add(renderRequest, "user-activation-link-already-sent");
                        }
                    }
                }
            }
            registrationBean.setIsDeletedUser(isDeletedUser);
        }
        registrationBean.setIsExistingUser(isExistingUser);
        registrationBean.setIsDeletedUser(isDeletedUser);
        log.info("registrationBean.toString() : " + registrationBean.toString());
        model.addAttribute(REGISTRATION_BEAN, registrationBean);

    } catch (STOXXException e) {
        log.error("STOXXException in handleRenderRequest", e);
    } catch (Exception e) {
        log.error("Exception in handleRenderRequest", e);
    }
    registrationBean.setIsExistingUser(isExistingUser);
    registrationBean.setIsDeletedUser(isDeletedUser);
    return RegistrationConstants.INITIATE_REGISTRATION;
}

From source file:com.stoxx.portlet.controller.RegistrationController.java

@ActionMapping(params = "action=reactivateLink")
public void reactivateLink(ActionRequest actionRequest, ActionResponse actionResponse, Model model,
        @ModelAttribute(REGISTRATION_BEAN) RegistrationBean registrationBean, BindingResult bindingResult) {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    try {//from  w ww  . j  a  v  a  2  s.c o m
        log.info("***************************the business email address variable is" + businessEmailAddress);
        registrationBean.setBusinessEmailAddress(businessEmailAddress);
        registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean);
        log.info("the user type is " + registrationBean.getUserType() + " and the activationLink is "
                + registrationBean.getActivationLink());
        sendEmailByTemplate(registrationBean, themeDisplay);

        registrationBean.setActivationLinkCreatedDate(new Date());
        registrationDelegator.addUserRegistration(registrationBean);
        SessionMessages.add(actionRequest, "mail-success-message");
    } catch (STOXXException e) {
        log.error("STOXXException in handleRenderRequest", e);
    } catch (MessagingException e) {
        log.error("MessagingException in handleRenderRequest", e);
    } catch (Exception e) {
        log.error("Exception", e);
    }

}

From source file:com.stoxx.portlet.controller.RegistrationController.java

@ActionMapping(params = "action=addUserRegistrationAction")
public void addUserRegistrationAction(ActionRequest actionRequest, ActionResponse actionResponse, Model model,
        @ModelAttribute(REGISTRATION_BEAN) RegistrationBean registrationBean, BindingResult bindingResult) {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    SessionMessages.add(actionRequest,
            PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
    String actionResponseParameter = null;
    try {/*from w w w  . j  a v a 2 s  . com*/
        log.info("***************************the business email address variable is" + businessEmailAddress);
        log.info("registrationBean.toString() : " + registrationBean.toString());
        log.info("***************************On Linked in click" + registrationBean.getLinkedinReg());
        log.info("registrationBean.getLinkedinReg() is" + registrationBean.getLinkedinReg());
        if (Validator.isNull(registrationBean.getLinkedinReg())) {
            registrationBean.setLinkedinReg(Boolean.FALSE);
        }
        registrationBean.setCompanyId(themeDisplay.getCompanyId());
        if (Validator.isNotNull(registrationBean) && registrationBean.getLinkedinReg()) {

            if (registrationDelegator.checkIfUserExistsInLiferayDB(registrationBean)) {
                SessionErrors.add(actionRequest, USER_EXISTS_KEY);
                actionResponse.setRenderParameter(ACTION, USER_EXISTS);
                return;
            } else {
                registrationBean.setUserType(STOXXConstants.STOXX_GENERAL_USER);
                registrationBean.setIsExistingUser(Boolean.FALSE);
                actionResponseParameter = "setupProfileTRANSLATOR";
                createActivationLink(actionRequest, registrationBean, themeDisplay);
                actionResponse.setRenderParameter(ACTION, actionResponseParameter);
                return;
            }
        }
        if (Validator.isNotNull(registrationBean)) {
            registrationBean.setCompanyId(themeDisplay.getCompanyId());
            log.info("the company id  is" + registrationBean.getCompanyId());
            log.info("registrationBean.getIsDeletedUser() : " + registrationBean.getIsDeletedUser());
            if (Validator.isNotNull(registrationBean.getIsExistingUser())
                    && registrationBean.getIsExistingUser()
                    && !(Validator.isNotNull(registrationBean.getIsDeletedUser())
                            && registrationBean.getIsDeletedUser())) {
                log.info("Return the user back to login page...");
                actionResponse.setRenderParameter(ACTION, "existingUserStep2");
                return;
            }
        }
        if (Validator.isNotNull(registrationBean) && null != registrationBean.getBusinessEmailAddress()) {
            log.info("the EXPECTED  emailAddress id  is" + registrationBean.getBusinessEmailAddress());
            RegistrationBean regBean = registrationDelegator.fetchFromStoxxUser(registrationBean);
            log.info("the status is" + regBean.getStatus());
            if (Validator.isNotNull(regBean) && Validator.isNotNull(regBean.getStatus())
                    && (regBean.getStatus() == 3 || regBean.getStatus() == 4)) {
                log.info("the user with emailAddress id  is" + regBean.getBusinessEmailAddress()
                        + "is an existing user and needs to be migrated");
                try {
                    if (regBean.getStatus() == 4
                            && regBean.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_REGISTERED_USER)) {
                        String emailDomainName = registrationBean.getBusinessEmailAddress()
                                .substring(registrationBean.getBusinessEmailAddress().lastIndexOf("@"));
                        EmailDomain emailDomain = EmailDomainLocalServiceUtil.getEmailDomain(emailDomainName);
                        regBean.setSalesEntryId(emailDomain.getSalesEntryId());
                        SalesEntry salesEntry = SalesEntryLocalServiceUtil
                                .getSalesEntry(emailDomain.getSalesEntryId());
                        int allowedLicenses = salesEntry.getUsersAllowed();
                        int alreadyUsedLicenses = registrationDelegator
                                .getCustomerCountByGroupId(salesEntry.getSalesEntryId());
                        log.info("alreadyUsedLicenses from DB for salesentryID: " + salesEntry.getSalesEntryId()
                                + " is: " + alreadyUsedLicenses);
                        log.info("allowedLicenses: " + allowedLicenses + "for salesentry company: "
                                + salesEntry.getCompanyName());
                        if (allowedLicenses <= alreadyUsedLicenses) {
                            SessionErrors.add(actionRequest, CUST_USER_EXCEEDED);
                            actionResponse.setRenderParameter(ACTION, CUST_USER_EXCEEDED);
                            return;
                        }
                    }
                } catch (NoSuchEmailDomainException e) {
                    log.info("No domain exist for provided email address.");
                    regBean.setUserType(STOXXConstants.STOXX_GENERAL_USER);
                }
                createActivationLink(actionRequest, regBean, themeDisplay);
                actionResponse.setRenderParameter(ACTION, EXISTING_USER);
                return;
            }
            if (registrationDelegator.checkIfUserExistsInLiferayDB(registrationBean)) {
                SessionErrors.add(actionRequest, USER_EXISTS_KEY);
                actionResponse.setRenderParameter(ACTION, USER_EXISTS);
                return;
            } else if (fetchActivationLinkCreateDateDiff(registrationBean.getBusinessEmailAddress())) {
                SessionErrors.add(actionRequest, RegistrationConstants.REGISTRATION_LINK_EXPIRED);
                actionResponse.setRenderParameter(ACTION, RegistrationConstants.REGISTRATION_LINK_ALREADY_SENT);
                return;
            } else if (registrationDelegator.checkIfUserExistsInLiferay(registrationBean)) {
                SessionErrors.add(actionRequest, "user-activation-link-already-sent");
                actionResponse.setRenderParameter(ACTION, RegistrationConstants.REGISTRATION_LINK_ALREADY_SENT);
                return;
            }
        } else if (null != businessEmailAddress) {
            log.info("Within else if : businessEmailAddress : " + businessEmailAddress);
            RegistrationBean regBean = registrationDelegator.fetchFromStoxxUser(registrationBean,
                    businessEmailAddress);
            if (Validator.isNotNull(regBean) && Validator.isNotNull(regBean.getStatus())
                    && regBean.getStatus() == 3) {
                log.info("the user with emailAddress id  is" + regBean.getBusinessEmailAddress()
                        + "is an existing user and needs to be migrated");
                actionResponse.setRenderParameter(ACTION, EXISTING_USER);
                return;
            }
            if (Validator.isNotNull(regBean) && Validator.isNotNull(regBean.getStatus())
                    && regBean.getStatus() == 4) {
                log.info("the user with emailAddress id  is" + regBean.getBusinessEmailAddress()
                        + "is an existing user and needs to be migrated");
                actionResponse.setRenderParameter(ACTION, DELETED_USER);
                return;
            }

            if (Validator.isNotNull(registrationBean.getIsDeletedUser())
                    && registrationBean.getIsDeletedUser()) {
                log.info("User email address is : " + businessEmailAddress
                        + ". User added as customer after delition");
                actionResponse.setRenderParameter(ACTION, DELETED_USER);
                return;
            }

            if (registrationDelegator.checkIfUserExistsInLiferayDB(registrationBean, businessEmailAddress)) {
                log.info("User exist in liferay DB");
                SessionErrors.add(actionRequest, USER_EXISTS_KEY);
                actionResponse.setRenderParameter(ACTION, USER_EXISTS);
                return;
            } else if (fetchActivationLinkCreateDateDiff(businessEmailAddress)) {
                log.info("The activation link is expired.");
                SessionErrors.add(actionRequest, LINK_EXPIRED);
                actionResponse.setRenderParameter(ACTION, RegistrationConstants.REGISTRATION_LINK_ALREADY_SENT);
                return;
            }
        }

        if (null != registrationBean.getBusinessEmailAddress()) {
            log.info("Within If " + registrationBean.getBusinessEmailAddress());
            if (registrationBean.getBusinessEmailAddress()
                    .substring(registrationBean.getBusinessEmailAddress().indexOf(StringPool.AT) + 1)
                    .equalsIgnoreCase(RegistrationConstants.STAFF_DOMAIN_PATTERN)) {
                registrationBean.setUserType(STOXXConstants.STOXX_STAFF_USER);
                createActivationLink(actionRequest, registrationBean, themeDisplay);
                actionResponseParameter = "setupProfileSTAFF";
            } else {
                try {
                    String emailDomainName = registrationBean.getBusinessEmailAddress()
                            .substring(registrationBean.getBusinessEmailAddress().lastIndexOf("@"));
                    EmailDomain emailDomain = EmailDomainLocalServiceUtil.getEmailDomain(emailDomainName);

                    registrationBean.setSalesEntryId(emailDomain.getSalesEntryId());
                    SalesEntry salesEntry = SalesEntryLocalServiceUtil
                            .getSalesEntry(emailDomain.getSalesEntryId());

                    int allowedLicenses = salesEntry.getUsersAllowed();

                    int alreadyUsedLicenses = registrationDelegator
                            .getCustomerCountByGroupId(salesEntry.getSalesEntryId());
                    log.info("alreadyUsedLicenses from DB for salesentryID: " + salesEntry.getSalesEntryId()
                            + "is: " + alreadyUsedLicenses);
                    log.info("allowedLicenses: " + allowedLicenses + "for salesentry company: "
                            + salesEntry.getCompanyName());
                    if (allowedLicenses <= alreadyUsedLicenses) {
                        SessionErrors.add(actionRequest, CUST_USER_EXCEEDED);
                        actionResponse.setRenderParameter(ACTION, CUST_USER_EXCEEDED);
                        return;
                    }
                    registrationBean.setUserType(STOXXConstants.STOXX_REGISTERED_USER);
                    registrationBean.setCompanyName(salesEntry.getCompanyName());
                    actionResponseParameter = "setupProfileGENERALLICENSED";
                } catch (NoSuchEmailDomainException e) {
                    log.info("No domain exist for provided email address.");
                    registrationBean.setUserType(STOXXConstants.STOXX_GENERAL_USER);
                    actionResponseParameter = "setupProfileGENERAL";
                }
                createActivationLink(actionRequest, registrationBean, themeDisplay);
            }
        } else {
            log.info("Within If " + businessEmailAddress);
            registrationBean = registrationDelegator.fetchFromStoxxUser(registrationBean, businessEmailAddress);
            if (Validator.isNotNull(registrationBean.getActivationLink())
                    && registrationBean.getActivationLink().indexOf(PropsUtil.get("INTRANET")) != -1
                    && registrationBean.getActivationLink().contains(StringPool.DOLLAR)) {
                if (registrationDelegator.checkIfUserExistsInLiferay(registrationBean, businessEmailAddress)) {
                    registrationBean.setBusinessEmailAddress(businessEmailAddress);
                    registrationDelegator.fetchFromStoxxUser(registrationBean);
                } else {
                    registrationBean.setCompanyName(RegistrationConstants.STAFF_COMPANY);
                    registrationBean.setUserType(STOXXConstants.STOXX_STAFF_USER);
                }
            } else if (Validator.isNotNull(registrationBean.getActivationLink())
                    && registrationBean.getActivationLink().indexOf(PropsUtil.get(INTERNET)) != -1) {
                if (registrationDelegator.checkIfUserExistsInLiferay(registrationBean, businessEmailAddress)) {
                    registrationBean.setBusinessEmailAddress(businessEmailAddress);
                    registrationDelegator.fetchFromStoxxUser(registrationBean);
                } else {
                    registrationBean.setUserType(STOXXConstants.STOXX_GENERAL_USER);
                }
            }
            actionResponseParameter = "setupProfileTRANSLATOR";
        }
        log.info("the action parameter is " + actionResponse.getRenderParameterMap());
        actionResponse.setRenderParameter(ACTION, actionResponseParameter);
    } catch (STOXXException e) {
        log.error("STOXXException in addUserRegistrationAction", e);
    } catch (Exception e) {
        log.error("Exception in addUserRegistrationAction ", e);
    }
}

From source file:com.stoxx.portlet.controller.RegistrationController.java

private void createActivationLink(ActionRequest actionRequest, RegistrationBean registrationBean,
        ThemeDisplay themeDisplay) {//from w  w w  . j av a2  s  . c o m
    try {
        String encryptedEmailId = STOXXEncrypter.encrypt(registrationBean.getBusinessEmailAddress(),
                ENCRYPTION_KEY);
        String encrypteduserType = STOXXEncrypter.encrypt(registrationBean.getUserType(), ENCRYPTION_KEY);
        String activationLink = null;
        if (registrationBean.getUserType().equalsIgnoreCase(STOXXConstants.STOXX_STAFF_USER)) {
            activationLink = themeDisplay.getPortalURL() + "/web/stoxxnet/registration?" + encryptedEmailId
                    + StringPool.DOLLAR + encrypteduserType;
        } else {
            activationLink = themeDisplay.getPortalURL() + "/web/stoxxcom/registration?" + encryptedEmailId
                    + StringPool.DOLLAR + encrypteduserType;
        }
        log.info("the activation link is" + activationLink);
        registrationBean.setActivationLink(activationLink);
        registrationBean.setActivationLinkCreatedDate(new Date());
        log.info("registrationBean.getLinkedinReg() is" + registrationBean.getLinkedinReg());
        if (Validator.isNull(registrationBean.getLinkedinReg())) {
            registrationBean.setLinkedinReg(Boolean.FALSE);
        }
        if (Validator.isNotNull(registrationBean) && !registrationBean.getLinkedinReg()) {
            sendEmailByTemplate(registrationBean, themeDisplay);
            SessionMessages.add(actionRequest, "mail-success-message");
        }
        registrationDelegator.addUserRegistration(registrationBean);
    } catch (STOXXException e) {
        log.error("STOXXException createActivationLink", e);
    } catch (Exception e) {
        log.info("registrationBean ", e);
    }
}

From source file:com.stoxx.portlet.manageusers.controller.ManageUsersController.java

@RenderMapping(params = "action=savePackageNames")
public String savePackageNamesToCompany(@ModelAttribute(MANAGEUSERSBEAN) ManageUsersBean manageUsersBean,
        RenderRequest renderRequest, RenderResponse renderResponse, Model model) {
    log.info("Inside savePackageNamesToCompany  method>>>> ");
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    try {/* w  w  w . j  a  va2  s.  co m*/
        log.info("The added packages are" + manageUsersBean.getAddedPackageNames());
        log.info("The deleted packages are" + manageUsersBean.getDeletedPackageNames());
        log.info("The sales entry id is" + manageUsersBean.getSalesEntryID());
        log.info("The updated packages are" + manageUsersBean.getNewPackageNames());
        List<String> newPackagesSubscribedList = new ArrayList<String>();
        List<String> alreadyPackagesSubscribedList = new ArrayList<String>();
        List<String> deletedUnscribedPackageNamesList = new ArrayList<String>();
        deletedUnscribedPackageNamesList = deleteUnscribedList(manageUsersBean,
                deletedUnscribedPackageNamesList);
        log.info("The deletedUnscribedPackageNamesList is" + deletedUnscribedPackageNamesList);
        newPackagesSubscribedList = getSubscribedPackages(manageUsersBean, newPackagesSubscribedList);
        log.info("The company name is " + manageUsersBean.getCompanyName());
        manageUsersBean.setAllPackageNames(manageUsersBean.getAllPackageNames());
        manageUsersBean.setCompanyName(manageUsersBean.getCompanyName());
        manageUsersBean.setPackagesSubscribedByCommaSeperation(
                manageUsersBean.getPackagesSubscribedByCommaSeperation());
        DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(SalesEntry.class,
                PortalClassLoaderUtil.getClassLoader());
        Criterion criterion = RestrictionsFactoryUtil.eq("companyName", manageUsersBean.getCompanyName());
        dynamicQuery.add(criterion);
        List<SalesEntry> salesEntryList = null;
        List<Long> liferrayUserIDsForCustomer = new ArrayList<Long>();
        salesEntryList = SalesEntryLocalServiceUtil.dynamicQuery(dynamicQuery);

        if (Validator.isNotNull(salesEntryList) && salesEntryList.size() > 0) {
            SalesEntry salesEntry = salesEntryList.get(0);
            if (!Validator.isBlank(salesEntry.getPackageNames())) {
                if (salesEntry.getPackageNames().contains(StringPool.COMMA)) {
                    alreadyPackagesSubscribedList = Arrays.asList(salesEntry.getPackageNames().split(","));
                } else {
                    alreadyPackagesSubscribedList.add(salesEntry.getPackageNames());
                }
            }
            salesEntry.setPackageNames(manageUsersBean.getNewPackageNames());
            SalesEntryLocalServiceUtil.updateSalesEntry(salesEntry);
            List<String> customerEmaiAddressList = userProfileService
                    .getLicensedUsersEmailAddress(manageUsersBean.getSalesEntryID());
            if (Validator.isNotNull(customerEmaiAddressList) && customerEmaiAddressList.size() > 0) {
                for (String emailAddress : customerEmaiAddressList) {
                    User user = UserLocalServiceUtil.fetchUserByEmailAddress(themeDisplay.getCompanyId(),
                            emailAddress);
                    if (Validator.isNotNull(user)) {
                        liferrayUserIDsForCustomer.add(user.getUserId());
                    }
                }
            }
            log.info("The new packagesSubscribedList is" + newPackagesSubscribedList);
            log.info("The already packagesSubscribedList is" + alreadyPackagesSubscribedList);
            log.info("The deletedUnscribedPackageNamesList is" + deletedUnscribedPackageNamesList);
            log.info("The no of users under this group is" + liferrayUserIDsForCustomer.size());
            addRole(themeDisplay, newPackagesSubscribedList, alreadyPackagesSubscribedList,
                    liferrayUserIDsForCustomer);
            removeRoles(themeDisplay, deletedUnscribedPackageNamesList, liferrayUserIDsForCustomer);
            SessionMessages.add(renderRequest, "packages-subscribed");
        }
    } catch (Exception e) {
        log.error(SYSTEM_EXCEPTION + e);
    } finally {
        List<String> allPackageNames;
        try {
            allPackageNames = manageUsersDeligate.getDistinctPackageNames();
            String packagesSubscribed = manageUsersDeligate
                    .getSubscibedpackagesForCompany(manageUsersBean.getCompanyName());
            manageUsersBean.setAllPackageNames(allPackageNames);
            manageUsersBean.setPackagesSubscribedByCommaSeperation(packagesSubscribed);
            model.addAttribute("manageUserVO", manageUsersBean);
        } catch (STOXXException e) {
            log.error(e.getMessage(), e);
        }
    }
    return SHOW_PACKAGES_SUBSCRIBED;

}

From source file:com.stoxx.portlet.manageusers.controller.ManageUsersController.java

@RenderMapping(params = "action=staffRoles")
public String updateRoleAssignmentForStaff(@ModelAttribute("staffRoleModel") UserModel userModel,
        RenderRequest renderRequest, RenderResponse renderResponse, Model model) {
    log.info("Inside user updateRoleAssignmentForStaff  method>>>> ");
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    try {/*w ww. j  a  v a2s.co  m*/
        log.info("the updated roles checked are" + userModel.getRolesAssigned());
        log.info("the User id " + userModel.getLiferayUserId());
        List<Role> rolelist = RoleLocalServiceUtil.getUserRelatedRoles(userModel.getLiferayUserId(),
                themeDisplay.getScopeGroupId());
        List<String> userRoles = new ArrayList<String>();
        for (Role role : rolelist) {
            userRoles.add(role.getName());
        }
        userModel.setUserRoles(userRoles);
        List<String> assignedUserRoleNames = new ArrayList<String>();
        List<String> assignedUnsetUserRoleNames = new ArrayList<String>();
        List<String> selectedUserRoles = new ArrayList<String>();
        assignedUserRoleNames = assignRoles(userModel, assignedUserRoleNames);
        assignedUnsetUserRoleNames = unsetRoles(userModel, assignedUnsetUserRoleNames);
        addRole(userModel, themeDisplay, assignedUserRoleNames);
        removeRole(userModel, themeDisplay, assignedUnsetUserRoleNames);
        List<Role> allRoleslist = RoleLocalServiceUtil.getTypeRoles(RoleConstants.TYPE_REGULAR);
        List<Role> rolelist1 = RoleLocalServiceUtil.getUserRelatedRoles(userModel.getLiferayUserId(),
                themeDisplay.getScopeGroupId());
        List<String> userRoles1 = new ArrayList<String>();
        List<String> allRoles = new ArrayList<String>();
        List<String> inheritedRoleNames = new ArrayList<String>();
        log.info("inheritedRoleNames size before is >>>>" + inheritedRoleNames.size());
        for (Role role : rolelist1) {
            userRoles1.add(role.getName());
        }
        for (Role role : allRoleslist) {
            if (GetterUtil
                    .getBoolean(role.getExpandoBridge().getAttribute(ROLE_CUSTOM_FIELD)) == Boolean.TRUE) {
                allRoles.add(role.getName());
            }
        }
        User user = UserLocalServiceUtil.fetchUser(userModel.getLiferayUserId());
        long[] userGroupIds = user.getUserGroupIds();
        log.info("the usergroupIds are  >> " + Arrays.toString(userGroupIds));
        for (long groupName : userGroupIds) {
            long groupId = GroupLocalServiceUtil
                    .getGroup(themeDisplay.getCompanyId(), String.valueOf(groupName)).getGroupId();
            List<Role> roles = RoleLocalServiceUtil.getGroupRoles(groupId);
            for (Role role : roles) {
                inheritedRoleNames.add(role.getName());
            }
        }
        log.info("inheritedRoleNames size after is >>>>" + inheritedRoleNames.size());
        List<String> roleNamesToIgnore = ListUtil.fromArray(RoleConstants.SYSTEM_ROLES);
        roleNamesToIgnore.addAll(ListUtil.fromArray(PropsUtil.getArray("stoxx.regular.roles.to.ignore")));
        allRoles.removeAll(roleNamesToIgnore);

        userModel.setUserRoles(userRoles1);
        userModel.setAllUserRoles(allRoles);
        userModel.setLiferayUserId(userModel.getLiferayUserId());
        userModel.setInheritedRoles(inheritedRoleNames);
        selectedUserRoles.addAll(userRoles1);
        selectedUserRoles.addAll(inheritedRoleNames);
        userModel.setSelectedUserRoles(selectedUserRoles);
        SessionMessages.add(renderRequest, "roles-updated");
    } catch (Exception e) {
        log.error(SYSTEM_EXCEPTION, e);
    }
    model.addAttribute("staffRoleModel", userModel);
    return SHOW_STAFF_ROLE;

}

From source file:com.viapost.stock.service.impl.ProductLocalServiceImpl.java

License:Open Source License

@Override
public void addProductFromRequest(final ActionRequest request) throws SystemException {

    final long primaryKey = CounterLocalServiceUtil.increment(Product.class.getName());
    final Product product = productPersistence.create(primaryKey);
    product.setArticleNumber(ParamUtil.getLong(request, "article"));
    product.setStock(ParamUtil.getLong(request, "stock"));
    product.setSeuil_stock(ParamUtil.getLong(request, "seuil"));

    if (ProductValidator.validateProduct(product)) {
        SessionMessages.add(request, "success");
        productPersistence.update(product);
    } else {//from  ww w .  jav a 2s . c o  m
        SessionErrors.add(request, "error");
    }
}

From source file:com.viapost.stock.service.impl.ProductLocalServiceImpl.java

License:Open Source License

@Override
public void editProductFromRequest(final ActionRequest request) throws SystemException, NoSuchProductException {
    final Product product = productPersistence.findByPrimaryKey(ParamUtil.getLong(request, "stockId"));
    product.setArticleNumber(ParamUtil.getLong(request, "articleNumber"));
    product.setStock(ParamUtil.getLong(request, "stock"));
    product.setSeuil_stock(ParamUtil.getLong(request, "seuil-stock"));

    if (ProductValidator.validateProduct(product)) {
        SessionMessages.add(request, "success");
        productPersistence.update(product);
    } else {//from  ww w . j a v  a2 s  .  c o  m
        SessionErrors.add(request, "error");
    }
}

From source file:com.vportal.portlet.edirectory.action.ManageEDirectory.java

License:Open Source License

/**
 * Xa n v/*from w  w w . j  a v  a  2s  .c  o  m*/
 * 
 * @param req
 * @param res
 * @throws PortalException
 * @throws SystemException
 */
public void deleteDepartment(ActionRequest req, ActionResponse res) throws PortalException, SystemException {
    long depId = ParamUtil.getLong(req, "resourcePrimKey");
    EDDepartment dep = EDDepartmentLocalServiceUtil.getEDDepartment(depId);
    List<EDDepartment> depList = EDDepartmentLocalServiceUtil.getByParent(dep.getId());
    List<EDEmployee> employeeList = EDEmployeeLocalServiceUtil.getByDepartmentId(dep.getId());
    if ((!depList.isEmpty()) || (!employeeList.isEmpty())) {
        SessionErrors.add(req, "do-not-delete-department");
    } else {
        EDDepartmentLocalServiceUtil.deleteDepartment(dep);
        SessionMessages.add(req, "Xa thnh cng");
    }
    res.setRenderParameter("jspPage", "/html/manage_edirectory/view.jsp?tab1=tab.danhba.donvi");
}

From source file:com.vportal.portlet.edirectory.action.ManageEDirectory.java

License:Open Source License

/**
 * Xa chc v/*from  w  w w .ja  v  a  2  s  .c om*/
 * 
 * @param req
 * @param res
 * @throws SystemException
 * @throws PortalException
 */
public void deleteFunction(ActionRequest req, ActionResponse res) throws SystemException, PortalException {
    long funcId = ParamUtil.getLong(req, "resourcePrimKey");
    EDFunction function = EDFunctionLocalServiceUtil.getEDFunction(funcId);
    List<EDFunctionEmployee> edFunctionEmployeeList = EDFunctionEmployeeLocalServiceUtil
            .getByFunctionId(funcId);
    if (!edFunctionEmployeeList.isEmpty()) {
        SessionErrors.add(req, "Khng xa c n v");
        return;
    } else {
        EDFunctionLocalServiceUtil.deleteFunction(function);
        SessionMessages.add(req, "Xa thnh cng");
    }
    res.setRenderParameter("jspPage", "/html/manage_edirectory/view.jsp?tab1=tab.danhba.chucvu");
}