%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.utils.Utils" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.HashSet" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.DocumentGroup" %>
<%@ page import="org.crosswire.webtools.RightsAndRoles" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.RightsAndRoles.UserGroup" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%!
@Description(value = "Retrieve Document Group data.", name = "documentgroup/get")
public static class MyParameters extends Parameters {
protected ProjectManagement.Project project = null;
protected long userID = -1;
protected boolean allGroups = false;
@Description(value = "Document Group ID data to retrieve", defaultValue = "required one of: documentGroupID, docID, userName", example = "1")
public Integer documentGroupID = -1;
@Description(value = "userName[+] for which to retrieve all document groups", example = "jsmith")
public String userName;
@Description(value = "docID of the manuscript for which to retrieve all document groups", example = "10046")
public Integer docID = -1;
@Description(value = "Project ID for which to retrieve document groups", example = "1")
public Integer projectID;
@Description(value = "Project Name for which to retrieve document groups", example = "ECM Matthew")
public String projectName;
@Description(value = "Detail of data to retrieve header, complete, extra", example = "header", defaultValue = "complete")
public String detail = "complete";
@Override
protected void customValidation() {
if (userName != null && userName.endsWith("+")) {
allGroups = true;
userName = userName.substring(0, userName.length()-1);
}
if ("undefined".equals(userName)) userName = "-1";
projectName = Transcription.assureUnicode(projectName);
if (projectID != null || projectName != null) {
project = projectID != null ? ProjectManagement.getProject(projectID) : ProjectManagement.getProject(projectName);
if (project == null) {
addError(-7, "Project not found.");
return;
}
}
userName = Transcription.assureUnicode(userName);
if (documentGroupID == -1 && docID == -1 && userName == null) {
addError(-1, "Must specify one of: documentGroupID, docID, or userName.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
int primaryDocumentGroupID = Integer.parseInt(Utils.getSysConfig(session).getProperty("PrimaryDocumentGroupID", "0"));
int detail = DocumentGroup.DETAIL_COMPLETE;
if ("header".equals(params.detail)) detail = DocumentGroup.DETAIL_HEADERONLY;
else if ("extra".equals(params.detail)) detail = DocumentGroup.DETAIL_EXTRA;
Set userGroups = null;
Set shownIDs = new HashSet();
response.setContentType("text/xml");
String role = "VMR Administrator";
// let's check to see if we're a privileged user
boolean manager = params.getUser() != null && params.getUser().hasRole(role);
// ---------------------------------------------
if (params.userName != null && !"-1".equals(params.userName) && params.docID == -1 && params.documentGroupID == -1) {
try {
//params.getLogger().info("params.userName: " + params.userName);
userGroups = (!params.allGroups) ? RightsAndRoles.getInstance().getUserGroups(params.userName)
: RightsAndRoles.getInstance().getUserGroups();
}
catch (Exception e) {
//params.getLogger().info("Failed! params.userName: " + params.userName);
}
}
DocumentGroup personalDocGroups[] = null;
if (params.documentGroupID > -1) {
DocumentGroup dg = DocumentGroup.getDocumentGroup(params.documentGroupID);
if (dg != null) {
personalDocGroups = new DocumentGroup[1];
personalDocGroups[0] = dg;
}
}
else if (params.docID > -1) {
personalDocGroups = DocumentGroup.getDocumentGroups(params.docID);
}
else if (params.userName != null) {
personalDocGroups = DocumentGroup.getDocumentGroups(params.userName);
}
if (personalDocGroups != null) {
String retVal = "";
if (userGroups != null) {
for (UserGroup ug : userGroups) {
DocumentGroup docGroups[] = DocumentGroup.getDocumentGroupsByGroup(ug.getUserGroupName());
if (docGroups.length > 0) {
retVal += "";
for (DocumentGroup si : docGroups) {
retVal += si.toFormattedXML(detail);
shownIDs.add(si.getDocumentGroupID());
}
retVal += "";
}
}
}
for (DocumentGroup si : personalDocGroups) {
if (!shownIDs.contains(si.getDocumentGroupID())) {
retVal += si.toFormattedXML(detail);
}
}
retVal += "";
XMLBlock result = XMLBlock.createXMLBlock(retVal.toString());
Serializer.output(response, out, params, result);
return;
}
else {
params.addError(-8, "documentGroupID: " + params.documentGroupID + " not found.");
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>