List of usage examples for org.springframework.web.context.request WebRequest getUserPrincipal
@Nullable Principal getUserPrincipal();
From source file:com.socklabs.whoisthat.twitter.CacheTwitterFriendsAfterConnectInterceptor.java
public void postConnect(Connection<Twitter> connection, WebRequest request) { logger.info("connection key {}", connection.getKey()); Account account = accountManager.getByEmail(request.getUserPrincipal().getName()); logger.info("account {}", account); TwitterProfile twitterProfile = connection.getApi().userOperations().getUserProfile(); accountManager.addMeta(account.getEmail(), "twitter/id", String.valueOf(twitterProfile.getId())); accountManager.addMeta(account.getEmail(), "twitter/username", twitterProfile.getScreenName()); accountManager.addMeta(account.getEmail(), "twitter/name", twitterProfile.getName()); List<TwitterProfile> friends = connection.getApi().friendOperations().getFriends(); logger.info("retrieved {} twitter profiles", friends.size()); List<String> friendIds = new ArrayList<String>(); for (TwitterProfile friend : friends) { friendIds.add(String.valueOf(friend.getId())); }// www. jav a 2 s. c o m String joinedFriendIds = join(friendIds, ","); accountManager.addMeta(account.getEmail(), "twitter/friends", joinedFriendIds); accountManager.addMeta(account.getEmail(), "twitter/count", String.valueOf(friendIds.size())); for (TwitterProfile friend : friends) { String entityId = entityManager.create(account.getEmail(), "twitter", String.valueOf(friend.getId())); entityManager.addMeta(entityId, "label", friend.getScreenName()); } }
From source file:com.socklabs.whoisthat.facebook.CacheFriendsAfterConnectInterceptor.java
public void postConnect(Connection<Facebook> connection, WebRequest request) { logger.info("connection key {}", connection.getKey()); Account account = accountManager.getByEmail(request.getUserPrincipal().getName()); logger.info("account {}", account); FacebookProfile facebookUserProfile = connection.getApi().userOperations().getUserProfile(); accountManager.addMeta(account.getEmail(), "facebook/id", facebookUserProfile.getId()); accountManager.addMeta(account.getEmail(), "facebook/username", facebookUserProfile.getUsername()); accountManager.addMeta(account.getEmail(), "facebook/name", facebookUserProfile.getName()); List<FacebookProfile> facebookProfiles = new ArrayList<FacebookProfile>(); int i = 100;//from ww w .j av a2 s. co m int offset = 0; while (i == 100) { final List<FacebookProfile> friends = connection.getApi().friendOperations().getFriendProfiles(offset, 100); i = friends.size(); if (i > 0) { facebookProfiles.addAll(friends); } offset += 100; } logger.info("retrieved {} facebook profiles", facebookProfiles.size()); List<String> friendIds = new ArrayList<String>(); for (FacebookProfile friend : facebookProfiles) { friendIds.add(friend.getId()); } String joinedFriendIds = join(friendIds, ","); accountManager.addMeta(account.getEmail(), "facebook/friends", joinedFriendIds); accountManager.addMeta(account.getEmail(), "facebook/count", String.valueOf(friendIds.size())); for (FacebookProfile friend : facebookProfiles) { String entityId = entityManager.create(account.getEmail(), "facebook", friend.getId()); entityManager.addMeta(entityId, "label", friend.getName()); } }
From source file:com.nixmash.springdata.mvc.controller.UserController.java
@RequestMapping(value = "/signup", method = RequestMethod.GET) public String signupForm(@ModelAttribute SocialUserDTO socialUserDTO, WebRequest request, Model model) { if (request.getUserPrincipal() != null) return "redirect:/"; else {//from w w w. j a v a 2 s . com Connection<?> connection = providerSignInUtils.getConnectionFromSession(request); request.setAttribute("connectionSubheader", webUI.parameterizedMessage(MESSAGE_KEY_SOCIAL_SIGNUP, StringUtils.capitalize(connection.getKey().getProviderId())), RequestAttributes.SCOPE_REQUEST); socialUserDTO = createSocialUserDTO(request, connection); ConnectionData connectionData = connection.createData(); SignInUtils.setUserConnection(request, connectionData); model.addAttribute(MODEL_ATTRIBUTE_SOCIALUSER, socialUserDTO); return SIGNUP_VIEW; } }
From source file:edu.jhuapl.openessence.controller.ReportController.java
@RequestMapping("/chartJson") public @ResponseBody Map<String, Object> chartJson(WebRequest request, HttpServletRequest servletRequest, @RequestParam("dsId") JdbcOeDataSource ds, ChartModel chartModel) throws ErrorMessageException { log.info(LogStatements.GRAPHING.getLoggingStmt() + request.getUserPrincipal().getName()); final List<Filter> filters = new Filters().getFilters(request.getParameterMap(), ds, null, 0, null, 0); final List<Dimension> results = ControllerUtils.getResultDimensionsByIds(ds, request.getParameterValues("results")); Dimension filterDimension = null; if (results.get(0).getFilterBeanId() != null && results.get(0).getFilterBeanId().length() > 0) { filterDimension = ds.getFilterDimension(results.get(0).getFilterBeanId()); }//from w w w. jav a2s . com // if not provided, use the result dimension // it means name and id columns are same... if (filterDimension != null) { results.add(results.size(), filterDimension); } // Subset of results, should check final List<Dimension> charts = ControllerUtils.getResultDimensionsByIds(ds, request.getParameterValues("charts")); final List<Dimension> accumulations = ControllerUtils.getAccumulationsByIds(ds, request.getParameterValues("accumId")); final List<OrderByFilter> sorts = new ArrayList<OrderByFilter>(); try { sorts.addAll(Sorters.getSorters(request.getParameterMap())); } catch (Exception e) { log.warn("Unable to get sorters, using default ordering"); } // TODO put this on ChartModel //default to white allows clean copy paste of charts from browser Color backgroundColor = Color.WHITE; String bgParam = request.getParameter("backgroundColor"); if (bgParam != null && !"".equals(bgParam)) { if ("transparent".equalsIgnoreCase(bgParam)) { backgroundColor = new Color(255, 255, 255, 0); } else { backgroundColor = ControllerUtils.getColorsFromHex(Color.WHITE, bgParam)[0]; } } String graphBarUrl = request.getContextPath() + servletRequest.getServletPath() + "/report/graphBar"; graphBarUrl = appendGraphFontParam(ds, graphBarUrl); String graphPieUrl = request.getContextPath() + servletRequest.getServletPath() + "/report/graphPie"; graphPieUrl = appendGraphFontParam(ds, graphPieUrl); // TODO eliminate all the nesting in response and just use accumulation and chartID properties Map<String, Object> response = new HashMap<String, Object>(); Map<String, Object> graphs = new HashMap<String, Object>(); response.put("graphs", graphs); String clientTimezone = null; String timezoneEnabledString = messageSource.getMessage(TIMEZONE_ENABLED, "false"); if (timezoneEnabledString.equalsIgnoreCase("true")) { clientTimezone = ControllerUtils.getRequestTimezoneAsHourMinuteString(request); } Collection<Record> records = new DetailsQuery().performDetailsQuery(ds, results, accumulations, filters, sorts, false, clientTimezone); final List<Filter> graphFilters = new Filters().getFilters(request.getParameterMap(), ds, null, 0, null, 0, false); //for each requested accumulation go through each requested result and create a chart for (Dimension accumulation : accumulations) { Map<String, Object> accumulationMap = new HashMap<String, Object>(); // Create charts for dimensions (subset of results) for (Dimension chart : charts) { DefaultGraphData data = new DefaultGraphData(); data.setGraphTitle(chartModel.getTitle()); data.setGraphHeight(chartModel.getHeight()); data.setGraphWidth(chartModel.getWidth()); data.setShowLegend(chartModel.isLegend()); data.setBackgroundColor(backgroundColor); data.setShowGraphLabels(chartModel.isShowGraphLabels()); data.setLabelBackgroundColor(backgroundColor); data.setPlotHorizontal(chartModel.isPlotHorizontal()); data.setNoDataMessage(chartModel.getNoDataMessage()); data.setTitleFont(new Font("Arial", Font.BOLD, 12)); GraphObject graph = createGraph(ds, request.getUserPrincipal().getName(), records, chart, filterDimension, accumulation, data, chartModel, graphFilters); String graphURL = ""; if (BAR.equalsIgnoreCase(chartModel.getType())) { graphURL = graphBarUrl; } else if (PIE.equalsIgnoreCase(chartModel.getType())) { graphURL = graphPieUrl; } graphURL = appendUrlParameter(graphURL, "graphDataId", graph.getGraphDataId()); chartModel.setImageUrl(graphURL); chartModel.setImageMap(graph.getImageMap()); chartModel.setImageMapName(graph.getImageMapName()); accumulationMap.put(chart.getId(), chartModel); } graphs.put(accumulation.getId(), accumulationMap); } log.info(String.format("Chart JSON Details query for %s", request.getUserPrincipal().getName())); return response; }
From source file:org.qcri.micromappers.config.social.CustomConnectController.java
/** * May be overridden to allow custom processing of DuplicateConnectionException. *///from www .j a v a 2 s . c o m protected Boolean addOrUpdateDuplicateConnection(Connection<?> connection, ConnectionFactory<?> connectionFactory, WebRequest request) { UserConnection userConnection = userConnectionService.getByProviderIdAndProviderUserId( connection.getKey().getProviderId(), connection.getKey().getProviderUserId()); if (userConnection != null) { if (userConnection.getUserId().equalsIgnoreCase(request.getUserPrincipal().getName())) { updateConnection(connection, connectionFactory, request); return false; } else { return true; } } else { addConnection(connection, connectionFactory, request); return false; } }