<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.community.projects.ntmss.data.DocumentGroup" %> <%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %> <%@ page import="java.util.StringTokenizer" %> <%@ page import="org.crosswire.webtools.*" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="javax.validation.constraints.NotNull" %> <%! @Description(value = "Link a manuscript document with a document group.", name = "documentgroup/linkdocument") public static class MyParameters extends Parameters { @NotNull @Description(value = "Document Group ID of the document group", example = "1") public Integer documentGroupID = null; @NotNull @Description(value = "docID or list of docIDs (pipe | separated) to link", example = "10046|10047") public String docID = null; @Override protected void customValidation() { if (getUser() == null) { addError(-5, "Must be logged in to edit document groups."); } } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getErrors().size() == 0) { do { DocumentGroup dg = DocumentGroup.getDocumentGroup(params.documentGroupID); if (dg == null) { params.addError(-6, "Could not find document group, documentGroupID: " + params.documentGroupID); break; } String role = "VMR Administrator"; boolean permission = params.getUser().hasRole(role); if (!permission) { String groupID = dg.getGroupID(); if (groupID != null) { ProjectManagement.Project p = ProjectManagement.getProject(groupID); if (p != null) { permission = params.getUser().hasRole("Site Administrator", p.getProjectName()); } } } if (!permission && !params.getUser().getUserName().equals(dg.getUserID())) { params.addError(-7, "No permission to edit document groups for other users. Must have role: " + role + "."); break; } StringTokenizer pids = new StringTokenizer(params.docID, "|"); int success = 0; while (pids.hasMoreTokens()) { try { int docid = Integer.parseInt(pids.nextToken()); int result = dg.linkDocument(docid); if (result > 0) success += result; } catch (Exception e) { e.printStackTrace(); } } Serializer.output(response, out, params, XMLBlock.createXMLBlock( "" )); return; } while (false); } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>