%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Document" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Page" %>
<%@ 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 = "Delete an image association for a manuscript page.", name = "image/delete")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "manuscript id for the image", example = "10046")
public Integer docID;
@NotNull
@Description(value = "page id for the image", example = "10")
public Integer pageID;
@NotNull
@Description(value = "surrogate id for the image. pages can have multiple images and each image of this page has a unique surrogate ID", example = "10")
public String surrID;
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
Document doc = Document.getDocument(params.docID);
if (doc == null) {
params.addError(-6, "Document docID: " + params.docID + " not found.");
}
else {
String role = "VMR Administrator";
boolean permission = params.getUser().hasRole(role) || (params.getUser().getUserName().equals(doc.getUserID()));
if (!permission) {
params.getUser().includeUserRoles();
XMLBlock ur = params.getUser().getBlock("userRoles");
if (ur != null) {
XMLBlock rs[] = ur.getBlocks("role");
for (XMLBlock r : rs) {
String roleName = r.getAttribute("roleName");
if (roleName.startsWith("Catalog Admin:")) {
try {
int min = Integer.parseInt(roleName.split(":")[1].split("-")[0].trim());
int max = Integer.parseInt(roleName.split("-")[1].trim());
if (params.docID >= min && params.docID <= max) permission = true;
}
catch(Exception e) {}
}
}
}
}
if (!permission) {
params.addError(-7, "User is not the owner of this document nor has the role: " + role + ".");
}
else {
Page p = Page.getPage(params.docID, params.pageID);
if (p == null) {
params.addError(-8, "Document docID: " + params.docID + "; pageID: " + params.pageID + " not found.");
}
else {
p.removeSurrogateImage(params.surrID);
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
}
}
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>