List of usage examples for org.springframework.util MultiValueMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:com.jiwhiz.domain.account.impl.MongoConnectionRepositoryImpl.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }/*from w ww.j a va2 s. c o m*/ MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); List<String> providerUserIds = entry.getValue(); List<UserSocialConnection> userSocialConnections = this.userSocialConnectionRepository .findByProviderIdAndProviderUserIdIn(providerId, providerUserIds); List<Connection<?>> connections = new ArrayList<Connection<?>>(providerUserIds.size()); for (int i = 0; i < providerUserIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); for (UserSocialConnection userSocialConnection : userSocialConnections) { String providerUserId = userSocialConnection.getProviderUserId(); int connectionIndex = providerUserIds.indexOf(providerUserId); connections.set(connectionIndex, buildConnection(userSocialConnection)); } } return connectionsForUsers; }
From source file:ro.isdc.auth.social.connect.MongoConnectionService.java
/** * Get all the connections for an user./* w w w . j a v a 2 s . c om*/ * * @see org.springframework.social.connect.mongo.ConnectionService#getConnections(java.lang.String, * org.springframework.util.MultiValueMap) */ @Override public List<Connection<?>> getConnections(String userId, MultiValueMap<String, String> providerUsers) { // userId? and providerId = ? and providerUserId in (?, ?, ...) order by // providerId, rank if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); } List<Criteria> lc = new ArrayList<Criteria>(); for (Entry<String, List<String>> entry : providerUsers.entrySet()) { String providerId = entry.getKey(); lc.add(where("providerId").is(providerId).and("providerUserId").in(entry.getValue())); } Criteria criteria = where("userId").is(userId); criteria.orOperator(lc.toArray(new Criteria[lc.size()])); Query q = new Query(criteria); q.sort().on("providerId", Order.ASCENDING).on("rank", Order.ASCENDING); return runQuery(q); }
From source file:com.lixiaocong.social.MyJdbcConnection.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }/*from w w w . jav a2 s .com*/ StringBuilder providerUsersCriteriaSql = new StringBuilder(); MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("userId", userId); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); providerUsersCriteriaSql.append("providerId = :providerId_").append(providerId) .append(" and providerUserId in (:providerUserIds_").append(providerId).append(")"); parameters.addValue("providerId_" + providerId, providerId); parameters.addValue("providerUserIds_" + providerId, entry.getValue()); if (it.hasNext()) { providerUsersCriteriaSql.append(" or "); } } List<Connection<?>> resultList = new NamedParameterJdbcTemplate(jdbcTemplate) .query(selectFromUserConnection() + " where userId = :userId and " + providerUsersCriteriaSql + " order by providerId, rank", parameters, connectionMapper); MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Connection<?> connection : resultList) { String providerId = connection.getKey().getProviderId(); List<String> userIds = providerUsers.get(providerId); List<Connection<?>> connections = connectionsForUsers.get(providerId); if (connections == null) { connections = new ArrayList<Connection<?>>(userIds.size()); for (int i = 0; i < userIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); } String providerUserId = connection.getKey().getProviderUserId(); int connectionIndex = userIds.indexOf(providerUserId); connections.set(connectionIndex, connection); } return connectionsForUsers; }
From source file:com.faujnet.mongo.repository.UserSocialConnectionService.java
/** * Get all the connections for an user.//from www .ja va2 s . c o m * * @see org.springframework.social.connect.mongo.ConnectionService#getConnections(java.lang.String, org.springframework.util.MultiValueMap) */ @SuppressWarnings("deprecation") @Override public List<Connection<?>> getConnections(String userId, MultiValueMap<String, String> providerUsers) { // userId? and providerId = ? and providerUserId in (?, ?, ...) order by providerId, rank if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); } List<Criteria> lc = new ArrayList<Criteria>(); for (Entry<String, List<String>> entry : providerUsers.entrySet()) { String providerId = entry.getKey(); lc.add(where("providerId").is(providerId).and("providerUserId").in(entry.getValue())); } Criteria criteria = where("userId").is(userId); criteria.orOperator(lc.toArray(new Criteria[lc.size()])); Query q = new Query(criteria); q.sort().on("providerId", Order.ASCENDING).on("rank", Order.ASCENDING); return runQuery(q); }
From source file:io.github.davejoyce.dao.composite.social.connect.jpa.JpaConnectionRepository.java
/** * {@inheritDoc}/*from ww w . j av a 2 s .c om*/ */ public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); } StringBuilder providerUsersCriteriaJpaQl = new StringBuilder(QUERY_SELECT_FROM) .append("WHERE ausc.key.appUser.userId = :userId").append(" AND "); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); providerUsersCriteriaJpaQl.append("ausc.key.providerId = :providerId_").append(providerId) .append("AND ausc.key.providerUserId IN (:providerUserIds_").append(providerId).append(")"); if (it.hasNext()) { providerUsersCriteriaJpaQl.append(" OR "); } } providerUsersCriteriaJpaQl.append(" ORDER BY ausc.key.providerId, ausc.rank"); TypedQuery<AppUserSocialConnection> query = entityManager .createQuery(providerUsersCriteriaJpaQl.toString(), AppUserSocialConnection.class) .setParameter("userId", userId); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); query.setParameter(("providerId_" + providerId), providerId) .setParameter(("providerUserIds_" + providerId), entry.getValue()); } List<Connection<?>> resultList = appUserSocialConnectionsToConnections(query.getResultList()); MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Connection<?> connection : resultList) { String providerId = connection.getKey().getProviderId(); List<String> userIds = providerUsers.get(providerId); List<Connection<?>> connections = connectionsForUsers.get(providerId); if (connections == null) { connections = new ArrayList<Connection<?>>(userIds.size()); for (int i = 0; i < userIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); } String providerUserId = connection.getKey().getProviderUserId(); int connectionIndex = userIds.indexOf(providerUserId); connections.set(connectionIndex, connection); } return connectionsForUsers; }
From source file:de.zib.vold.userInterface.RESTController.java
/** * Handles Delete requests./*ww w. j a va 2 s. c o m*/ * * This method is used by clients to delete keys. * * @param clientIpAddress The ip of the sending client, it's extracted from the request itself. * @param args The URL arguments of the request. * @param request Request informations * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured. */ @RequestMapping(method = RequestMethod.DELETE) public ResponseEntity<Map<String, String>> delete(@ModelAttribute("clientIpAddress") String clientIpAddress, @RequestParam MultiValueMap<String, String> args, HttpServletRequest request) { // guard { logger.debug("DELETE: " + args.toString()); checkState(); } Map<String, String> invalidKeys = new HashMap<String, String>(); // get actual scope String scope; { scope = request.getRequestURI(); String removepath = removePrefix + request.getContextPath() + request.getServletPath(); scope = scope.substring(removepath.length(), scope.length()); } // process each key { for (Map.Entry<String, List<String>> entry : args.entrySet()) { URIKey urikey; String source; Key k; // build key { urikey = URIKey.fromURIString(entry.getKey(), enc); File path_correction = new File(scope + "/" + urikey.getKey().get_scope()); k = new Key(path_correction.getPath(), urikey.getKey().get_type(), urikey.getKey().get_keyname()); if (null == urikey.getSource()) { source = clientIpAddress; } else { source = urikey.getSource(); } } // handle write request for that key { try { frontend.delete(source, k); } catch (VoldException e) { logger.error("Could not handle write request for key " + entry.getKey() + ". ", e); invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage()); } } } } return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK); }
From source file:de.zib.vold.userInterface.RESTController.java
/** * Handles Post requests.//from www . j a v a 2s.c om * * This method is used by clients to submit new keys, refresh their registration or delete them. * * @param clientIpAddress The ip of the sending client, it's extracted from the request itself. * @param args The URL arguments of the request. * @param request Request informations * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured. */ @RequestMapping(method = RequestMethod.POST) public ResponseEntity<Map<String, String>> refresh(@ModelAttribute("clientIpAddress") String clientIpAddress, @RequestParam MultiValueMap<String, String> args, @RequestHeader(value = "TIMESTAMP", defaultValue = "unset") String timeStampHeader, HttpServletRequest request) { final long timeStamp; if (timeStampHeader.equals("unset")) timeStamp = DateTime.now().getMillis(); else timeStamp = Long.parseLong(timeStampHeader); // guard { logger.debug("POST: " + args.toString()); checkState(); } Map<String, String> invalidKeys = new HashMap<String, String>(); // get actual scope String scope; { scope = request.getRequestURI(); String removepath = removePrefix + request.getContextPath() + request.getServletPath(); scope = scope.substring(removepath.length(), scope.length()); } // process each key { for (Map.Entry<String, List<String>> entry : args.entrySet()) { URIKey urikey; String source; Key k; // build key { urikey = URIKey.fromURIString(entry.getKey(), enc); File path_correction = new File(scope + "/" + urikey.getKey().get_scope()); k = new Key(path_correction.getPath(), urikey.getKey().get_type(), urikey.getKey().get_keyname()); if (null == urikey.getSource()) { source = clientIpAddress; } else { source = urikey.getSource(); } } // handle write request for that key { try { frontend.refresh(source, k, timeStamp); } catch (VoldException e) { logger.error("Could not handle write request for key " + entry.getKey() + ". ", e); invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage()); } } } } return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK); }
From source file:de.zib.vold.userInterface.RESTController.java
/** * Handles Put requests.//from w ww .jav a 2 s . c o m * * This method is used by clients to submit new keys. * * @param clientIpAddress The ip of the sending client, it's extracted from the request itself. * @param args The URL arguments of the request. //* @param argsbody The PUT body arguments of the request. * @param request Request informations * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured. */ @RequestMapping(method = RequestMethod.PUT) public ResponseEntity<Map<String, String>> insert(@ModelAttribute("clientIpAddress") String clientIpAddress, @RequestParam MultiValueMap<String, String> args, //@RequestBody MultiValueMap< String, String > argsbody, @RequestHeader(value = "TIMESTAMP", defaultValue = "unset") String timeStampHeader, HttpServletRequest request) throws IOException { MultiValueMap<String, String> argsbody = getBody(); final long timeStamp; if (timeStampHeader.equals("unset")) timeStamp = DateTime.now().getMillis(); else timeStamp = Long.parseLong(timeStampHeader); // guard { if (argsbody != null) logger.debug("PUT: " + args.toString() + " AND " + argsbody.toString()); else logger.debug("PUT: " + args.toString()); checkState(); } Map<String, String> invalidKeys = new HashMap<String, String>(); // get actual scope String scope; { scope = request.getRequestURI(); String removepath = removePrefix + request.getContextPath() + request.getServletPath(); scope = scope.substring(removepath.length(), scope.length()); } // merge args to argsbody { if (null == argsbody) { if (null == args) { logger.warn("Got a totally empty request from " + clientIpAddress + "."); return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK); } argsbody = args; } else if (null != args) { argsbody.putAll(args); } } // process each key { for (Map.Entry<String, List<String>> entry : argsbody.entrySet()) { URIKey urikey; String source; Key k; // build key { urikey = URIKey.fromURIString(entry.getKey(), enc); File path_correction = new File(scope + "/" + urikey.getKey().get_scope()); k = new Key(path_correction.getPath(), urikey.getKey().get_type(), urikey.getKey().get_keyname()); if (null == urikey.getSource()) { source = clientIpAddress; } else { source = urikey.getSource(); } } // handle write request for that key { try { logger.debug( "Inserting " + entry.getValue().size() + " values for key " + urikey.toURIString()); frontend.insert(source, k, new HashSet<String>(entry.getValue()), timeStamp); } catch (VoldException e) { logger.error("Could not handle write request for key " + entry.getKey() + ". ", e); invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage()); } } } } return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK); }
From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.java
protected String getGlobalSecondaryIndexName() { // Lazy evaluate the globalSecondaryIndexName if not already set // We must have attribute conditions specified in order to use a global secondary index, otherwise return null for index name // Also this method only evaluates the if (globalSecondaryIndexName == null && attributeConditions != null && !attributeConditions.isEmpty()) { // Declare map of index names by attribute name which we will populate below - this will be used to determine which index to use if multiple indexes are applicable Map<String, String[]> indexNamesByAttributeName = new HashMap<String, String[]>(); // Declare map of attribute lists by index name which we will populate below - this will be used to determine whether we have an exact match index for specified attribute conditions MultiValueMap<String, String> attributeListsByIndexName = new LinkedMultiValueMap<String, String>(); // Populate the above maps for (Entry<String, String[]> indexNamesForPropertyNameEntry : entityInformation .getGlobalSecondaryIndexNamesByPropertyName().entrySet()) { String propertyName = indexNamesForPropertyNameEntry.getKey(); String attributeName = getAttributeName(propertyName); indexNamesByAttributeName.put(attributeName, indexNamesForPropertyNameEntry.getValue()); for (String indexNameForPropertyName : indexNamesForPropertyNameEntry.getValue()) { attributeListsByIndexName.add(indexNameForPropertyName, attributeName); }//from w w w . j a va 2 s.co m } // Declare lists to store matching index names List<String> exactMatchIndexNames = new ArrayList<String>(); List<String> partialMatchIndexNames = new ArrayList<String>(); // Populate matching index name lists - an index is either an exact match ( the index attributes match all the specified criteria exactly) // or a partial match ( the properties for the specified criteria are contained within the property set for an index ) for (Entry<String, List<String>> attributeListForIndexNameEntry : attributeListsByIndexName .entrySet()) { String indexNameForAttributeList = attributeListForIndexNameEntry.getKey(); List<String> attributeList = attributeListForIndexNameEntry.getValue(); if (attributeList.containsAll(attributeConditions.keySet())) { if (attributeConditions.keySet().containsAll(attributeList)) { exactMatchIndexNames.add(indexNameForAttributeList); } else { partialMatchIndexNames.add(indexNameForAttributeList); } } } if (exactMatchIndexNames.size() > 1) { throw new RuntimeException( "Multiple indexes defined on same attribute set:" + attributeConditions.keySet()); } else if (exactMatchIndexNames.size() == 1) { globalSecondaryIndexName = exactMatchIndexNames.get(0); } else if (partialMatchIndexNames.size() > 1) { if (attributeConditions.size() == 1) { globalSecondaryIndexName = getFirstDeclaredIndexNameForAttribute(indexNamesByAttributeName, partialMatchIndexNames, attributeConditions.keySet().iterator().next()); } if (globalSecondaryIndexName == null) { globalSecondaryIndexName = partialMatchIndexNames.get(0); } } else if (partialMatchIndexNames.size() == 1) { globalSecondaryIndexName = partialMatchIndexNames.get(0); } } return globalSecondaryIndexName; }
From source file:io.mandrel.data.filters.link.SanitizeParamsFilter.java
public boolean isValid(Link link) { Uri linkUri = link.getUri();/*from ww w .j av a 2 s. co m*/ if (linkUri != null && StringUtils.isNotBlank(linkUri.toString())) { String uri = linkUri.toString(); int pos = uri.indexOf('?'); if (pos > -1) { String uriWithoutParams = uri.substring(0, pos); if (CollectionUtils.isNotEmpty(exclusions)) { String query = uri.substring(pos + 1, uri.length()); if (StringUtils.isNotBlank(query)) { String[] paramPairs = QUERY.split(query); MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); if (paramPairs != null) { for (String pair : paramPairs) { String[] paramValue = PARAMS.split(pair); if (exclusions.contains(paramValue[0])) { params.add(paramValue[0], paramValue.length > 1 ? paramValue[1] : null); } } } StringBuilder builder = new StringBuilder(); params.entrySet().forEach(entry -> { entry.getValue().forEach(value -> { builder.append(entry.getKey()); if (StringUtils.isNotBlank(value)) { builder.append("=").append(value); } builder.append("&"); }); }); if (builder.length() > 0 && builder.charAt(builder.length() - 1) == '&') { builder.deleteCharAt(builder.length() - 1); } if (builder.length() > 0) { link.setUri(Uri.create(uriWithoutParams + "?" + builder.toString())); } else { link.setUri(Uri.create(uriWithoutParams)); } } else { link.setUri(Uri.create(uriWithoutParams)); } } else { link.setUri(Uri.create(uriWithoutParams)); } } } return true; }