%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.utils.Sessions" %>
<%@ page import="org.crosswire.webtools.RightsAndRoles" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Document" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Surrogate" %>
<%@ 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="java.util.List" %>
<%@ page import="java.lang.StringBuffer" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%!
@Description(value = "Move page data for a manuscript.", name = "manuscript/movepage")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "manuscript id of the source page", example = "10046")
public Integer docID;
@NotNull
@Description(value = "page id of the source page", example = "10")
public Integer pageID;
@Description(value = "if specifying a range, the last page id to move", example = "30")
public Integer pageIDEnd;
@Description(value = "destination doc id", example = "10001")
public Integer toDocID;
@NotNull
@Description(value = "destination page id", example = "70")
public Integer toPageID;
@Description(value = "(not yet supported) username of transcription to move; if not specified then move PUBLISHED", example = "jsmith")
public String transcriptionUserName;
@Description(value = "move indexing", defaultValue = "false", example = "true")
public Boolean indexing = false;
@Description(value = "move transcription", defaultValue = "false", example = "true")
public Boolean transcription = false;
@Description(value = "move folio numbering", defaultValue = "false", example = "true")
public Boolean folio = false;
@Description(value = "move images", defaultValue = "false", example = "true")
public Boolean images = false;
@Description(value = "leave source data in place after writing to destination", defaultValue = "false", example = "true")
public Boolean copy = false;
@Description(value = "show usage for this web service", defaultValue = "false", example = "true")
public Boolean usage = false;
@Override
protected void afterLoad() {
}
@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 && !params.usage) {
Document doc = Document.getDocument(params.docID);
do {
if (doc == null) {
params.addError(-5, "Document docID: " + params.docID + " not found.");
break;
}
String role = "VMR Administrator";
boolean permission = params.getUser().hasRole(role) || (params.getUser().getUserName().equals(doc.getUserID()));
// ---------------------------------------------
// we check permissions here instead of at the top because folio editing can be done by anyone logged in
if (!permission) {
params.addError(-6, "User is not the owner of this document nor has the role: " + role + ".");
break;
}
StringBuffer retVal = new StringBuffer();
try {
List results = Page.movePages(params.docID, params.pageID, params.pageIDEnd, params.toDocID, params.toPageID, params.copy, params.folio, params.indexing, params.transcription, params.images);
retVal.append("");
for (String r : results) {
retVal.append("");
}
}
catch (Exception e) {
retVal.append("");
}
retVal.append("");
Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString()));
return;
} while (false);
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>