<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page import="org.crosswire.community.projects.ntmss.data.ShelfInstance" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.webtools.annotation.*" %> <%@ page import="org.crosswire.webtools.*" %> <%@ page import="javax.validation.constraints.NotNull" %> <%! @Description(value = "Link a manuscript page with a shelf instance.", name = "shelfinstance/linkpage") public static class MyParameters extends Parameters { List pageIDs = new ArrayList(); List shelfFolioNumbers = new ArrayList(); @NotNull @Description(value = "shelf id of the shelf instance", example = "146789") public Integer shelfID; @NotNull @Description(value = "manuscript id for page to link", example = "10046") public Integer docID; @NotNull @Description(value = "page id for the page to link (can repeat) or separate multiple pageIDs by |", example = "10|20|30") public String pageID; @Description(value = "shelf folio number (can repeat) or separate multiple shelfFolioNumbers by |", example = "1r|2v|2r") public String shelfFolioNumber; @Override protected void customValidation() { if (getUser() == null) { addError(-5, "Must be logged in."); return; } String pageIDStrings[] = request.getParameterValues("pageID"); if (pageIDStrings != null) { for (String pgs : pageIDStrings) { try { for (String p : pgs.split("\\|")) pageIDs.add(Integer.parseInt(p)); } catch (Exception e) {} } } String folioNumberStrings[] = request.getParameterValues("shelfFolioNumber"); if (folioNumberStrings != null) { for (String fls : folioNumberStrings) { try { for (String f : fls.split("\\|")) shelfFolioNumbers.add(f); } catch (Exception e) {} } } if (shelfFolioNumbers.size() > 0 && shelfFolioNumbers.size() != pageIDs.size()) addError(-8, "if {shelfFolioNumber} parameters are provided, they must have the same count as the {pageID} parameters"); } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getErrors().size() == 0) { String role = "VMR Administrator"; boolean permission = params.getUser().hasRole(role); if (!permission) { params.addError(-6, "User does not have the role: " + role + "."); } else { ShelfInstance si = ShelfInstance.getShelfInstance(params.shelfID); if (si == null) { params.addError(-7, "Couldn't find shelf instance, shelfID: " + params.shelfID + "."); } else { int success = 0; for (int i = 0; i < params.pageIDs.size(); ++i) { Integer pageID = params.pageIDs.get(i); String shelfMarkFolioNumber = params.shelfFolioNumbers.size() > 0 ? params.shelfFolioNumbers.get(i) : null; si.unlinkPage(params.docID, pageID); success += si.linkPage(params.docID, pageID, shelfMarkFolioNumber); } Serializer.output(response, out, params, XMLBlock.createXMLBlock("")); return; } } } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>