%@ 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.repo.VersionedRepo" %>
<%@ 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 = "Move manuscript to a new docID.", name = "manuscript/move")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "current manuscript id of the document to move", example = "10046")
public Integer docID;
@NotNull
@Description(value = "destination manuscript id of the document to move", example = "10047")
public Integer toDocID;
@Description(value = "rename the manuscript primary name; leave blank to keep the same name", defaultValue = "(unchanged)", example = "P47")
public String newPrimaryName = null;
@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();
retVal.append("");
Document query = new Document();
query.setDocumentID(params.docID);
query.setIntValue("TODOCID", params.toDocID);
String sql = "update BIBLICALCONTENT set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
int n = query.executeSQL(sql);
sql = "update DOCUMENT set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
n = query.executeSQL(sql);
retVal.append("");
sql = "update DOCUMENTGROUPDOCUMENT set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
n = query.executeSQL(sql);
retVal.append("");
sql = "update FEATURE set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
n = query.executeSQL(sql);
retVal.append("");
sql = "update PAGE set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
n = query.executeSQL(sql);
retVal.append("");
sql = "update SEGMENTREADINGWITNESS set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
n = query.executeSQL(sql);
retVal.append("");
sql = "update SHELFINSTANCEPAGES set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
n = query.executeSQL(sql);
retVal.append("");
sql = "update SURROGATEIMAGE set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
n = query.executeSQL(sql);
retVal.append("");
sql = "update SURROGATETRANSCRIPTION set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
n = query.executeSQL(sql);
sql = "update TASK set OBJECTID={TODOCID} where OBJECTID={DOCUMENTID}";
n = query.executeSQL(sql);
retVal.append("");
sql = "update TRANSCRIPTIONPAGE set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
query.executeSQL(sql);
sql = "update TRANSCRIPTIONVERSE set DOCUMENTID={TODOCID} where DOCUMENTID={DOCUMENTID}";
query.executeSQL(sql);
String transcriptionPath = Integer.toString(params.docID);
String transcriptionPathNew = Integer.toString(params.toDocID);
VersionedRepo.moveFile(transcriptionPath, transcriptionPathNew, params.getUser().getUserName());
retVal.append("");
if (params.newPrimaryName != null && params.newPrimaryName.trim().length() > 0) {
Document orig = Document.getDocument(params.toDocID);
if (orig != null) {
Document newDoc = (Document)orig.clone();
newDoc.setPrimaryName(params.newPrimaryName);
newDoc.save(orig);
retVal.append("");
}
}
retVal.append("");
params.getLogger().info("manuscript/move: " + retVal);
Serializer.output(response, out, params, XMLBlock.createXMLBlock(retVal.toString()));
return;
} while (false);
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>