Example usage for org.springframework.util MultiValueMap isEmpty

List of usage examples for org.springframework.util MultiValueMap isEmpty

Introduction

In this page you can find the example usage for org.springframework.util MultiValueMap isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:com.faujnet.mongo.repository.MongoConnectionRepository.java

/**
 * Find the connections the current user has to the given provider users. 
 *///from   ww w .ja  va2  s  .c o  m
@Override
public MultiValueMap<String, Connection<?>> findConnectionsToUsers(
        MultiValueMap<String, String> providerUsers) {
    if (providerUsers == null || providerUsers.isEmpty()) {
        throw new IllegalArgumentException("Unable to execute find: no providerUsers provided");
    }

    List<Connection<?>> resultList = connService.getConnections(userId, providerUsers);

    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.naver.template.social.connect.DaoConnectionRepository.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  va 2 s  .c o  m*/
    //      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);
    List<Connection<?>> resultList = userConnectionDAO.selectConnections(userId, providerUsers);
    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:org.meruvian.yama.service.jpa.social.JpaSocialConnectionManager.java

@Override
public MultiValueMap<String, Connection<?>> findConnectionsToUsers(
        MultiValueMap<String, String> providerUserIds) {
    if (providerUserIds == null || providerUserIds.isEmpty()) {
        throw new IllegalArgumentException("Unable to execute find: no providerUsers provided");
    }//from  w w  w.  jav a2 s.com

    // TODO

    return null;
}

From source file:com.jiwhiz.domain.account.impl.ConnectionRepositoryImpl.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   www.j av a2  s .c om

    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 = 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: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  w  w . ja v a 2s . 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:com.seajas.search.codex.social.connection.InMemoryConnectionRepository.java

@Override
public MultiValueMap<String, Connection<?>> findConnectionsToUsers(
        final MultiValueMap<String, String> providerUsers) {
    if (providerUsers == null || providerUsers.isEmpty()) {
        throw new IllegalArgumentException("Unable to execute find: no providerUsers provided");
    }/*from  ww  w .  j  a  v  a2s. c o  m*/

    Map<String, List<String>> providerUserIdsByProviderId = new HashMap<String, List<String>>();
    for (Entry<String, List<String>> entry : providerUsers.entrySet()) {
        String providerId = entry.getKey();
        providerUserIdsByProviderId.put(providerId, entry.getValue());
    }

    List<ConnectionData> connectionDatas = new ArrayList<ConnectionData>();
    for (Map.Entry<String, List<String>> entry : providerUserIdsByProviderId.entrySet()) {
        connectionDatas.addAll(getInMemoryProviderConnectionRepository(entry.getKey())
                .findByProviderUserIdsOrderByProviderIdAndRank(entry.getValue()));
    }

    List<Connection<?>> resultList = createConnections(connectionDatas);
    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.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");
    }/* w  ww .java 2 s. c  om*/
    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:io.github.davejoyce.dao.composite.social.connect.jpa.JpaConnectionRepository.java

/**
 * {@inheritDoc}//  www.  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:ro.isdc.auth.social.connect.MongoConnectionService.java

/**
 * Get all the connections for an user.//from  w w  w  .j  a v  a  2 s . c  o m
 * 
 * @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.faujnet.mongo.repository.UserSocialConnectionService.java

/**
 * Get all the connections for an user.//from  w  ww  .j  av a2  s. c  om
 * 
 * @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);
}