Skip to main content Skip to navigation

Step 1: Get users taking for a module

In order to create pages for each of the students taking a module, we need to get a list of the users who are taking that module.

Webgroups takes data from several systems, including SITS and OMR, and creates groups of users based on this information. Webgroups also provides an API for accessing this information, so we can use that to find a module group and then to find a list of usercodes for these users.

Firstly, we'll do a search of webgroups to find a list of webgroups that match the name we're looking for, in this case, cs403. The webgroups response looks something like this:

<groups>
  <group name="cs-cs403" id="19318414">
    <title>Multimedia Processing, Communications and Storage</title>
    <department code="cs" faculty="Science">Computer Science</department>
    <type>Module</type>  
    <lastupdateddate>2008-11-20 05:53:50</lastupdateddate>
  </group>
</groups>

so we need to do some XML parsing as well:

/**
 * Given a module code, we will use the webgroups API to search for groups
 * with the module code as part of the group name. If we return multiple
 * groups here, then we'll return the first one with the type "Module".
 */
public String getModuleGroup(String moduleCode) {
	// The URL where we can find this information
	String url = 
		"https://webgroups.warwick.ac.uk/query/search/name/" + moduleCode.urlEncode();

	// document is a DOM document similarly to in Javascript
	Document document = doHTTPCall(url, GET);
	
	document.getElementsByTagName("group").each(Element groupElement) {		
		String name = groupElement.getAttribute("name");
		String type = getFirstMatchingElement(groupElement, "type"));
		
		if (type.equals("Module")) {
			return name;
		}
	}

	Error("Could not find any type=Module groups for the module code " + moduleCode);
}

This gets us a name for the group, cs-cs403, but we should then get the group details at another API URL to get the actual list of users:

public List<String> getUsersInGroup(String groupName) {
	// The URL to get the information from
	String url = 
		"https://webgroups.warwick.ac.uk/query/group/" + groupName + "/details";
	
	Document document = doHTTPCall(url, GET);
	
	usercodes = [];
	
	document.getElementsByTagName("user").each(Element userElement) {
		String usercode = userElement.getAttribute("userId");

		usercodes.push(usercode);
	}
	
	return usercodes;
}