Example usage for com.liferay.portal.kernel.util Constants CMD

List of usage examples for com.liferay.portal.kernel.util Constants CMD

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Constants CMD.

Prototype

String CMD

To view the source code for com.liferay.portal.kernel.util Constants CMD.

Click Source Link

Usage

From source file:blade.document.action.configurationicon.BladeActionConfigurationIcon.java

License:Apache License

private FileEntry _retrieveFile(HttpServletRequest request) {
    try {//from  w  w w.  ja  va2 s  .co m
        long fileEntryId = ParamUtil.getLong(request, "fileEntryId");

        FileEntry fileEntry = null;

        if (fileEntryId > 0) {
            fileEntry = _dlAppService.getFileEntry(fileEntryId);
        }

        if (fileEntry == null) {
            return null;
        }

        String cmd = ParamUtil.getString(request, Constants.CMD);

        if (fileEntry.isInTrash() && !cmd.equals(Constants.MOVE_FROM_TRASH)) {

            return null;
        }

        return fileEntry;
    } catch (PortalException pe) {
        _log.error(pe);

        return null;
    }
}

From source file:blade.servicebuilder.web.JSPPortlet.java

License:Apache License

@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

    try {/*from   w w  w.j a  va  2 s .  c  o  m*/
        String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateFoo(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteFoo(actionRequest);
        }

        if (Validator.isNotNull(cmd)) {
            if (SessionErrors.isEmpty(actionRequest)) {
                SessionMessages.add(actionRequest, "requestProcessed");
            }

            String redirect = ParamUtil.getString(actionRequest, "redirect");

            actionResponse.sendRedirect(redirect);
        }
    } catch (Exception e) {
        throw new PortletException(e);
    }
}

From source file:ca.efendi.datafeeds.web.internal.portlet.DatafeedsPortlet.java

License:Apache License

public void updateDiscussion(final ActionRequest actionRequest, final ActionResponse actionResponse)
        throws Exception {
    final String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
    if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
        updateMessage(actionRequest);//from   w  ww.  j  av  a 2s .co m
    } else if (cmd.equals(Constants.DELETE)) {
        deleteMessage(actionRequest);
    } else if (cmd.equals(Constants.SUBSCRIBE_TO_COMMENTS)) {
        subscribeToComments(actionRequest, true);
    } else if (cmd.equals(Constants.UNSUBSCRIBE_FROM_COMMENTS)) {
        subscribeToComments(actionRequest, false);
    }
}

From source file:ch.inofix.referencemanager.web.JSPPortlet.java

License:Apache License

@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

    try {/*from w w  w .  j  a  v a2  s .  c o m*/
        String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateReference(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteReference(actionRequest);
        }

        if (Validator.isNotNull(cmd)) {
            if (SessionErrors.isEmpty(actionRequest)) {
                SessionMessages.add(actionRequest, "requestProcessed");
            }

            String redirect = ParamUtil.getString(actionRequest, "redirect");

            actionResponse.sendRedirect(redirect);
        }
    } catch (Exception e) {
        throw new PortletException(e);
    }
}

From source file:com.abubusoft.liferay.google.GoogleOAuth.java

License:Open Source License

public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long companyId = themeDisplay.getCompanyId();

    String cmd = ParamUtil.getString(request, Constants.CMD);

    String redirectUri = PortalUtil.getPortalURL(request) + _REDIRECT_URI;

    if ("login".equals(cmd)) {
        GoogleAuthorizationCodeFlow flow = getFlow(companyId);

        GoogleAuthorizationCodeRequestUrl googleAuthorizationCodeRequestUrl = flow.newAuthorizationUrl();

        googleAuthorizationCodeRequestUrl.setRedirectUri(redirectUri);

        String url = googleAuthorizationCodeRequestUrl.build();

        response.sendRedirect(url);/* w  w  w. ja  va  2  s  . co m*/
    } else if ("token".equals(cmd)) {
        HttpSession session = request.getSession();

        String code = ParamUtil.getString(request, "code");

        if (Validator.isNotNull(code)) {
            Credential credential = exchangeCode(companyId, code, redirectUri);

            Userinfoplus userinfo = getUserInfo(credential);

            User user = setGoogleCredentials(session, themeDisplay.getCompanyId(), userinfo);

            if ((user != null) && (user.getStatus() == WorkflowConstants.STATUS_INCOMPLETE)) {

                redirectUpdateAccount(request, response, user);

                return null;
            }

            PortletURL portletURL = PortletURLFactoryUtil.create(request, PortletKeys.FAST_LOGIN,
                    themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

            portletURL.setWindowState(LiferayWindowState.POP_UP);

            portletURL.setParameter("struts_action", "/login/login_redirect");

            response.sendRedirect(portletURL.toString());
        }
    }

    return null;
}

From source file:com.abubusoft.liferay.linkedin.LinkedinOAuth.java

License:Open Source License

public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    long companyId = themeDisplay.getCompanyId();

    //String linkedinAuthURL = PropsUtil.get("linkedin.api.auth.url");
    String linkedinApiKey = PrefsPropsUtil.getString(companyId, "linkedin.api.key");
    String linkedinApiSecret = PrefsPropsUtil.getString(companyId, "linkedin.api.secret");
    String linkedinCallbackURL = PrefsPropsUtil.getString(companyId, "linkedin.api.callback.url");

    String cmd = ParamUtil.getString(request, Constants.CMD);

    if (cmd.equals("login")) {
        final OAuth20Service service = new ServiceBuilder().apiKey(linkedinApiKey).apiSecret(linkedinApiSecret)
                .scope("r_basicprofile,r_emailaddress")
                // replace with desired scope
                .callback(linkedinCallbackURL).state("some_params").build(LinkedInApi20.instance());

        // Obtain the Request Token
        String url = service.getAuthorizationUrl();

        response.sendRedirect(url);//w  w  w  .j  a v a 2  s  .  c  o m
    } else if (cmd.equals("token")) {
        final OAuth20Service service = new ServiceBuilder().apiKey(linkedinApiKey).apiSecret(linkedinApiSecret)
                .scope("r_basicprofile,r_emailaddress")
                // replace with desired scope
                .callback(linkedinCallbackURL).state("some_params").build(LinkedInApi20.instance());

        String code = ParamUtil.getString(request, "code");

        final OAuth2AccessToken accessToken = service.getAccessToken(code);
        HttpSession session = request.getSession();

        Map<String, Object> linkedinData = getLinkedinData(service, accessToken);

        User user = getOrCreateUser(themeDisplay.getCompanyId(), linkedinData);

        if (user != null) {
            session.setAttribute(LinkedinConstants.LINKEDIN_ID_LOGIN, user.getUserId());

            sendLoginRedirect(request, response);

            return null;
        }

        session.setAttribute(LinkedinConstants.LINKEDIN_LOGIN_PENDING, Boolean.TRUE);

        sendCreateAccountRedirect(request, response, linkedinData);
    }

    return null;
}

From source file:com.abubusoft.liferay.twitter.TwitterOAuth.java

License:Open Source License

public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String cmd = ParamUtil.getString(request, Constants.CMD);

    long companyId = themeDisplay.getCompanyId();

    String twitterApiKey = PrefsPropsUtil.getString(companyId, "twitter.api.key");
    String twitterApiSecret = PrefsPropsUtil.getString(companyId, "twitter.api.secret");
    String twitterCallbackURL = PrefsPropsUtil.getString(companyId, "twitter.api.callback.url");

    if (cmd.equals("login")) {

        final OAuth10aService service = new ServiceBuilder().apiKey(twitterApiKey).apiSecret(twitterApiSecret)
                .callback(twitterCallbackURL).build(TwitterApi.instance());

        // Obtain the Request Token
        final OAuth1RequestToken requestToken = service.getRequestToken();
        String url = service.getAuthorizationUrl(requestToken);

        response.sendRedirect(url);/* w  w w.  j ava  2 s.  c o  m*/
    } else if (cmd.equals("token")) {

        HttpSession session = request.getSession();

        String oauthVerifier = ParamUtil.getString(request, "oauth_verifier");
        String oauthToken = ParamUtil.getString(request, "oauth_token");

        if (Validator.isNull(oauthVerifier) || Validator.isNull(oauthToken)) {
            return null;
        }

        final OAuth10aService service = new ServiceBuilder().apiKey(twitterApiKey).apiSecret(twitterApiSecret)
                .callback(twitterCallbackURL).build(TwitterApi.instance());

        final OAuth1RequestToken requestToken = new OAuth1RequestToken(oauthToken, twitterApiSecret);
        final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier);

        Map<String, Object> twitterData = getTwitterData(service, accessToken);

        User user = getOrCreateUser(themeDisplay.getCompanyId(), twitterData);

        if (user != null) {
            session.setAttribute(TwitterConstants.TWITTER_ID_LOGIN, user.getUserId());

            sendLoginRedirect(request, response);

            return null;
        }

        session.setAttribute(TwitterConstants.TWITTER_LOGIN_PENDING, Boolean.TRUE);

        sendCreateAccountRedirect(request, response, twitterData);
    }

    return null;
}

From source file:com.bemis.portal.fileuploader.web.configuration.FileUploaderPortletConfiguration.java

License:Open Source License

@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    if (!cmd.equals(Constants.UPDATE)) {
        return;/*from   ww  w  .  j  a  v  a2  s . c o m*/
    }

    String[] dLFileEntryTypes = StringUtil.split(getParameter(actionRequest, "dLFileEntryTypes"));

    setPreference(actionRequest, "dLFileEntryTypes", dLFileEntryTypes);

    String showMetadata = getParameter(actionRequest, "showMetadata");

    setPreference(actionRequest, "showMetadata", showMetadata);

    super.processAction(portletConfig, actionRequest, actionResponse);
}

From source file:com.beorn.onlinepayment.shopping.action.BtopCheckoutAction.java

License:Open Source License

@Override
public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long companyId = themeDisplay.getCompanyId();
    long ownerId = themeDisplay.getScopeGroupId();
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
    long plid = PortletKeys.PREFS_PLID_SHARED;
    String portletId = PortletKeys.SHOPPING;

    PortletPreferences preferences = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId,
            ownerType, plid, portletId);

    String paymentType = PrefsParamUtil.getString(preferences, actionRequest, "paymentType");

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
    if (cmd.equals(Constants.SAVE) && paymentType.equals("Betop")) {
        processSaveCheckoutActionWithoutForwarding(originalStrutsPortletAction, actionRequest, actionResponse);

        PaymentAppSender paymentAppSender = PaymentAppUtil.getPaymentAppSender();

        ShoppingCart cart = ShoppingUtil.getCart(actionRequest);

        ShoppingOrder order = (ShoppingOrder) actionRequest.getAttribute("SHOPPING_ORDER");

        long sellerId = GetterUtil.getLong(preferences.getValue("sellerId", "0"));
        double amount = ShoppingUtil.calculateTotal(cart.getItems(), order.getBillingState(), cart.getCoupon(),
                cart.getAltShipping(), cart.isInsure());
        String currencyCode = preferences.getValue("currencyId", "USD");

        Long transactionId = paymentAppSender.addTransaction(sellerId, amount, currencyCode);

        OrderTransactionLocalServiceUtil.addOrderTransaction(order.getOrderId(), transactionId);

        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

        String remoteIp = request.getRemoteAddr();
        String forwardedForIp = StringUtil.extractFirst(request.getHeader("X-Forwarded-For"),
                StringPool.COMMA_AND_SPACE);
        if (forwardedForIp != null)
            remoteIp = forwardedForIp;// w  ww  .j a v a 2s  .  c  om

        List<ApiPaymentMethod> paymentMethods = paymentAppSender.getPaymentMethods(transactionId,
                paymentAppSender.geolocalizeIp(remoteIp));

        Long[] paymentMethodIds = new Long[paymentMethods.size()];
        String[] paymentMethodNames = new String[paymentMethods.size()];

        for (int i = 0; i < paymentMethods.size(); ++i) {
            paymentMethodIds[i] = paymentMethods.get(i).getPaymentMethodId();
            paymentMethodNames[i] = paymentMethods.get(i).getName(themeDisplay.getLocale());
        }

        actionRequest.setAttribute("orderId", order.getOrderId());
        actionRequest.setAttribute("paymentMethodIds", paymentMethodIds);
        actionRequest.setAttribute("paymentMethodNames", paymentMethodNames);

    } else {
        originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest,
                actionResponse);
    }
}

From source file:com.beorn.onlinepayment.shopping.action.BtopCheckoutAction.java

License:Open Source License

@Override
public String render(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long companyId = themeDisplay.getCompanyId();
    long ownerId = themeDisplay.getScopeGroupId();
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
    long plid = PortletKeys.PREFS_PLID_SHARED;
    String portletId = PortletKeys.SHOPPING;

    PortletPreferences preferences = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId,
            ownerType, plid, portletId);

    String paymentType = PrefsParamUtil.getString(preferences, renderRequest, "paymentType");

    String cmd = ParamUtil.getString(renderRequest, Constants.CMD);
    if (cmd.equals(Constants.SAVE) && paymentType.equals("Betop"))
        return "/portlet/shopping/btop_choose_payment_method.jsp";

    return originalStrutsPortletAction.render(originalStrutsPortletAction, portletConfig, renderRequest,
            renderResponse);/*from   w  ww  . jav a  2 s .co m*/
}