Search in sources :

Example 1 with Members

use of com.google.api.services.directory.model.Members in project perun by CESNET.

the class ExtSourceGoogleTest method setUp.

@Before
public void setUp() throws Exception {
    extSourceGoogle = new ExtSourceGoogle();
    Members members = fillInMemberList();
    domainName = "parker.sm";
    groupName = "spectacular";
    MockitoAnnotations.initMocks(this);
    // mock google connection
    Directory directory = mock(Directory.class, RETURNS_DEEP_STUBS);
    doReturn(directory).when(extSourceGoogle).getDirectoryService();
    when(directory.members().list(groupName).execute()).thenReturn(members);
}
Also used : Members(com.google.api.services.directory.model.Members) Directory(com.google.api.services.directory.Directory) Before(org.junit.Before)

Example 2 with Members

use of com.google.api.services.directory.model.Members in project perun by CESNET.

the class ExtSourceGoogle method executeQueryTypeContains.

/**
 * Searching for members in group specified by groupName class variable by
 * an email address. Email address doesn't have to be full, we are searching
 * for substrings, not exact match.
 *
 * When we find suitable members, we send their ID's one by one to
 * processGoogleMappingAttribute() method to create map from suitable
 * attributes. All these maps for each user (until maxResults number is
 * reached) are stored together in list, that is returned by method.
 *
 * @param value part of email address
 * @return List<Map<String, String>>, list of maps returned by
 * processGoogleMappingAttribute() method
 * @throws InternalErrorException
 */
private List<Map<String, String>> executeQueryTypeContains(String value) {
    List<Map<String, String>> subjects = new ArrayList<>();
    try {
        Members result = service.members().list(groupName).execute();
        List<Member> membersInGroup = result.getMembers();
        for (Member member : membersInGroup) {
            Map<String, String> map = new HashMap<>();
            if (member.getEmail().contains(value)) {
                map = processGoogleMappingAttribute(member.getId());
            }
            if (!map.isEmpty()) {
                subjects.add(map);
            }
        }
    } catch (IOException ex) {
        log.error("Problem with I/O operation while accesing Google Group API in ExtSourceGoogle class.", ex);
    }
    return subjects;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Member(com.google.api.services.directory.model.Member) Members(com.google.api.services.directory.model.Members)

Example 3 with Members

use of com.google.api.services.directory.model.Members in project perun by CESNET.

the class ExtSourceGoogle method executeQueryTypeID.

/**
 * Searching for member with ID specified in 'value' variable in group
 * specified by groupName class variable.
 *
 * When we reach that concrete member, we send his ID to
 * processGoogleMappingAttribute() method to create map from suitable
 * attributes. All these maps for each user (until maxResults number is
 * reached) are stored together in list, that is returned by method.
 *
 * @param value member's ID
 * @param maxResults max number of results for this query that should be
 * returned by this method
 * @return List<Map<String, String>>, list of maps returned by
 * processGoogleMappingAttribute() method
 * @throws InternalErrorException
 */
private List<Map<String, String>> executeQueryTypeID(String value, int maxResults) {
    List<Map<String, String>> subjects = new ArrayList<>();
    try {
        Members result = service.members().list(groupName).execute();
        List<Member> membersInGroup = result.getMembers();
        for (Member member : membersInGroup) {
            Map<String, String> map = new HashMap<>();
            if (member.getId().equals(value)) {
                map = processGoogleMappingAttribute(member.getId());
            }
            if (!map.isEmpty()) {
                subjects.add(map);
            }
            if (maxResults > 0) {
                if (subjects.size() >= maxResults) {
                    break;
                }
            }
        }
    } catch (IOException ex) {
        log.error("Problem with I/O operation while accesing Google Group API in ExtSourceGoogle class.", ex);
    }
    return subjects;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Member(com.google.api.services.directory.model.Member) Members(com.google.api.services.directory.model.Members)

Example 4 with Members

use of com.google.api.services.directory.model.Members in project perun by CESNET.

the class ExtSourceGoogle method executeQueryTypeEmail.

/**
 * Searching for member with email address specified in 'value' variable in
 * group specified by groupName class variable.
 *
 * When we find suitable member, we send his ID to
 * processGoogleMappingAttribute() method to create map from suitable
 * attributes. All these maps for each user (until maxResults number is
 * reached) are stored together in list, that is returned by method.
 *
 * @param value member's ID
 * @param maxResults max number of results for this query that should be
 * returned by this method
 * @return List<Map<String, String>>, list of maps returned by
 * processGoogleMappingAttribute() method
 * @throws InternalErrorException
 */
private List<Map<String, String>> executeQueryTypeEmail(String value, int maxResults) {
    List<Map<String, String>> subjects = new ArrayList<>();
    try {
        Members result = service.members().list(groupName).execute();
        List<Member> membersInGroup = result.getMembers();
        for (Member member : membersInGroup) {
            Map<String, String> map = new HashMap<>();
            if (member.getEmail().equals(value)) {
                map = processGoogleMappingAttribute(member.getId());
            }
            if (!map.isEmpty()) {
                subjects.add(map);
            }
            if (maxResults > 0) {
                if (subjects.size() >= maxResults) {
                    break;
                }
            }
        }
    } catch (IOException ex) {
        log.error("Problem with I/O operation while accesing Google Group API in ExtSourceGoogle class.", ex);
    }
    return subjects;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Member(com.google.api.services.directory.model.Member) Members(com.google.api.services.directory.model.Members)

Example 5 with Members

use of com.google.api.services.directory.model.Members in project perun by CESNET.

the class ExtSourceGoogle method executeQueryTypeGroupSubjects.

/**
 * Searching for members in group specified by 'value' variable.
 *
 * When we find these members, we their ID's one by one to
 * processGoogleMappingAttribute() method to create map from suitable
 * attributes. All these maps for each user (until maxResults number is
 * reached) are stored together in list, that is returned by method.
 *
 * @param value group email address, like groupname@domain.com, NOT only
 * groupname
 * @param maxResults max number of results for this query that should be
 * returned by this method
 * @return List<Map<String, String>>, list of maps returned by
 * processGoogleMappingAttribute() method
 * @throws InternalErrorException
 */
private List<Map<String, String>> executeQueryTypeGroupSubjects(String value, int maxResults) {
    List<Map<String, String>> subjects = new ArrayList<>();
    if (value.contains("@" + this.domainName)) {
        try {
            Members result = service.members().list(value).execute();
            List<Member> membersInGroup = result.getMembers();
            for (Member member : membersInGroup) {
                Map<String, String> map = processGoogleMappingAttribute(member.getId());
                if (!map.isEmpty()) {
                    subjects.add(map);
                }
                if (maxResults > 0) {
                    if (subjects.size() >= maxResults) {
                        break;
                    }
                }
            }
        } catch (IOException ex) {
            log.error("Problem with I/O operation while accesing Google Group API in ExtSourceGoogle class.", ex);
        }
    } else {
        throw new IllegalArgumentException("You are trying to get users from nonexistin group, please check name if your group name is something like 'groupname@domainname.com'.");
    }
    return subjects;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Member(com.google.api.services.directory.model.Member) Members(com.google.api.services.directory.model.Members)

Aggregations

Members (com.google.api.services.directory.model.Members)6 Member (com.google.api.services.directory.model.Member)5 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Directory (com.google.api.services.directory.Directory)1 Before (org.junit.Before)1