%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.HashSet" %>
<%@ page import="org.crosswire.xml.XMLDataElement" %>
<%@ page import="org.crosswire.webtools.RightsAndRoles" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement.Project" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%!
@Description(value = "Retrieve usergroups", name = "projectmanagement/usergroup/get")
public static class MyParameters extends Parameters {
@Description(value = "user group id to retrieve", example = "32")
public Integer userGroupID;
@Description(value = "user group name to retrieve", example = "ECM Matthew")
public String userGroupName;
@Description(value = "get all group for a specific user id", example = "19763")
public Integer userID;
@Description(value = "get all group for a specific user name", example = "joe")
public String userName;
@Description(value = "header, users", defaultValue = "users", example = "header")
public String detail;
@Override
protected void customValidation() {
if (userID == null && userName == null && userGroupID == null && userGroupName == null) {
addError(-4, "Must supply one of {userID}, {userName}, {userGroupID}, or {userGroupName}.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
Set groups = new HashSet();
if (params.userGroupID != null) {
RightsAndRoles.UserGroup ug = RightsAndRoles.getInstance().getUserGroup(params.userGroupID);
if (ug != null) groups.add(ug);
}
else if (params.userGroupName != null) {
RightsAndRoles.UserGroup ug = RightsAndRoles.getInstance().getUserGroup(params.userGroupName);
if (ug != null) groups.add(ug);
}
else if (params.userID != null) {
groups = RightsAndRoles.getInstance().getUserGroups(params.userID);
}
else if (params.userName != null) {
groups = RightsAndRoles.getInstance().getUserGroups(params.userName);
}
StringBuffer retVal = new StringBuffer();
retVal.append("");
for (RightsAndRoles.UserGroup u : groups) {
if ("header".equals(params.detail)) {
retVal.append(new XMLDataElement(u).toString());
}
else {
Project p = ProjectManagement.getProject(u.getUserGroupName());
if (p != null) { u.addBlock(XMLBlock.createXMLBlock(p.toFormattedXML())); }
retVal.append(u.formattedString());
}
}
retVal.append("");
Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString()));
return;
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>