// Path: social-portlets/src/main/java/org/jboss/quickstarts/portal/social/oauth/AbstractSocialPortlet.java
// public abstract class AbstractSocialPortlet extends GenericPortlet {
// 
//     public static final String ACTION_OAUTH_REDIRECT = "actionOAuthRedirect";
//     public static final String PARAM_CUSTOM_SCOPE = "_oauthCustomScope";
// 
//     @Inject
//     private RequestContext requestContext;
// 
//     /**
//      * Perform redirection to OAuth workflow of given OAuth provider
//      *
//      * @param aReq action request
//      * @param aResp action response
//      * @throws IOException in case that OAuth workflow redirection failed
//      */
//     @ProcessAction(name = ACTION_OAUTH_REDIRECT)
//     public void actionRedirectToOAuthFlow(ActionRequest aReq, ActionResponse aResp) throws IOException {
//         String customScope = aReq.getParameter(PARAM_CUSTOM_SCOPE);
// 
//         getOAuthProvider().startOAuthWorkflow(customScope);
//     }
// 
//     // Needs to be implemented by Subclass. Subclass should return value of key (For example: "FACEBOOK" or "GOOGLE")
//     protected abstract String getOAuthProviderKey();
// 
//     // Intended to be used by subclasses
//     protected OAuthProvider getOAuthProvider() {
//         return requestContext.getOAuthProvider(getOAuthProviderKey());
//     }
// 
//     // Intended to be used by subclasses
//     protected AccessToken getAccessToken() {
//         return requestContext.getAccessToken(getOAuthProviderKey());
//     }
// 
//     // Helper method. Intended to be used by subclasses
//     protected String getParameterAndSaveItToSession(String paramName, PortletRequest req, PortletSession session) {
//         String paramValue = req.getParameter(paramName);
//         if (paramValue != null) {
//             session.setAttribute(paramName, paramValue);
//         } else {
//             paramValue = (String) session.getAttribute(paramName);
//         }
// 
//         return paramValue;
//     }
// }


import org.jboss.quickstarts.portal.social.oauth.AbstractSocialPortlet;
import java.io.IOException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.PortletRequestDispatcher;
import com.google.api.services.plus.Plus;
import com.google.api.services.plus.model.PeopleFeed;
import org.gatein.api.oauth.AccessToken;
import org.gatein.api.oauth.OAuthProvider;
            }
        }

        list.setPageToken(pgState.getTokenOfCurrentPage());

        PeopleFeed peopleFeed = new GooglePortletRequest<PeopleFeed>(request, response, getPortletContext(),
                getOAuthProvider(), REQUIRED_SCOPE) {

            @Override
            protected PeopleFeed invokeRequest() throws IOException {
                return list.execute();
            }

        }.executeRequest();

        if (peopleFeed != null) {
            request.setAttribute("googleFriendsList", peopleFeed);
            request.setAttribute("pgState", pgState);

            // Obtain next token to session if it's available
            String nextPageToken = peopleFeed.getNextPageToken();

            // Show link for next page
            if (nextPageToken != null) {
                pgState.setTokenForPage(pgState.getCurrentPage() + 1, nextPageToken);
            }

            session.setAttribute(ATTR_PAGINATION_CONTEXT, pgState);

            PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/jsp/google/friends.jsp");
// Path: social-portlets/src/main/java/org/jboss/quickstarts/portal/social/oauth/AbstractSocialPortlet.java
// public abstract class AbstractSocialPortlet extends GenericPortlet {
// 
//     public static final String ACTION_OAUTH_REDIRECT = "actionOAuthRedirect";
//     public static final String PARAM_CUSTOM_SCOPE = "_oauthCustomScope";
// 
//     @Inject
//     private RequestContext requestContext;
// 
//     /**
//      * Perform redirection to OAuth workflow of given OAuth provider
//      *
//      * @param aReq action request
//      * @param aResp action response
//      * @throws IOException in case that OAuth workflow redirection failed
//      */
//     @ProcessAction(name = ACTION_OAUTH_REDIRECT)
//     public void actionRedirectToOAuthFlow(ActionRequest aReq, ActionResponse aResp) throws IOException {
//         String customScope = aReq.getParameter(PARAM_CUSTOM_SCOPE);
// 
//         getOAuthProvider().startOAuthWorkflow(customScope);
//     }
// 
//     // Needs to be implemented by Subclass. Subclass should return value of key (For example: "FACEBOOK" or "GOOGLE")
//     protected abstract String getOAuthProviderKey();
// 
//     // Intended to be used by subclasses
//     protected OAuthProvider getOAuthProvider() {
//         return requestContext.getOAuthProvider(getOAuthProviderKey());
//     }
// 
//     // Intended to be used by subclasses
//     protected AccessToken getAccessToken() {
//         return requestContext.getAccessToken(getOAuthProviderKey());
//     }
// 
//     // Helper method. Intended to be used by subclasses
//     protected String getParameterAndSaveItToSession(String paramName, PortletRequest req, PortletSession session) {
//         String paramValue = req.getParameter(paramName);
//         if (paramValue != null) {
//             session.setAttribute(paramName, paramValue);
//         } else {
//             paramValue = (String) session.getAttribute(paramName);
//         }
// 
//         return paramValue;
//     }
// }


// Path: social-portlets/src/main/java/org/jboss/quickstarts/portal/social/oauth/google/GoogleFriendsPortlet.java
import org.jboss.quickstarts.portal.social.oauth.AbstractSocialPortlet;
import java.io.IOException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.PortletRequestDispatcher;
import com.google.api.services.plus.Plus;
import com.google.api.services.plus.model.PeopleFeed;
import org.gatein.api.oauth.AccessToken;
import org.gatein.api.oauth.OAuthProvider;

            }
        }

        list.setPageToken(pgState.getTokenOfCurrentPage());

        PeopleFeed peopleFeed = new GooglePortletRequest<PeopleFeed>(request, response, getPortletContext(),
                getOAuthProvider(), REQUIRED_SCOPE) {

            @Override
            protected PeopleFeed invokeRequest() throws IOException {
                return list.execute();
            }

        }.executeRequest();

        if (peopleFeed != null) {
            request.setAttribute("googleFriendsList", peopleFeed);
            request.setAttribute("pgState", pgState);

            // Obtain next token to session if it's available
            String nextPageToken = peopleFeed.getNextPageToken();

            // Show link for next page
            if (nextPageToken != null) {
                pgState.setTokenForPage(pgState.getCurrentPage() + 1, nextPageToken);
            }

            session.setAttribute(ATTR_PAGINATION_CONTEXT, pgState);

            PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/jsp/google/friends.jsp");
            prd.include(request, response);