%@ 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.repo.VersionedRepo" %>
<%@ page import="org.crosswire.utils.Utils" %>
<%@ 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 transcription of a manuscript.", name = "transcription/delete")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "manuscript id from which to delete a transcript", example = "10046")
public Integer docID = null;
@NotNull
@Description(value = "manscript page id from which to delete a transcript", example = "10")
public Integer pageID = null;
@Description(value = "user's transcription to delete", defaultValue = "PUBLISHED", example = "psmith")
public String userName = null;
@Description(value = "should repository be pushed", defaultValue = "true", example = "false")
public Boolean push = true;
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in to edit transcriptions.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
boolean pushOnCommit = "true".equals(Utils.getSysConfig(session).getProperty("VersionedRepoPushOnCommit"));
boolean commitOnSave = "true".equals(Utils.getSysConfig(session).getProperty("VersionedRepoCommitOnSave"));
String role="VMR Administrator";
String role2="Transcription Manager";
// let's check to see if we're a privileged user
boolean isAdmin = params.getUser().hasRole(role) || params.getUser().hasRole(role2);
// check if we're saving a site transcription and we're an admin of that site
if (!isAdmin) isAdmin = params.getUser().hasRole("Site Administrator", params.userName);
if (params.getUser().getUserName() == null || params.getUser().getUserName().length() < 1) {
params.addError(-6, "Permission denied.");
}
else if (!isAdmin && (params.userName == null || params.userName.length() < 1) || "PUBLISHED".equals(params.userName)) {
params.addError(-7, "Must be a VMR Administrator or Transcription Manager to delete global transcriptions.");
}
else if (!isAdmin && !params.getUser().getUserName().equals(params.userName)) {
params.addError(-8, "Must be a VMR Administrator to delete another user's transcription.");
}
else {
Document doc = Document.getDocument(params.docID);
if (doc != null) {
params.getLogger().info("deleting transcription (docID: " + doc.getDocumentID() + "; pageID: " + params.pageID + "; saveAsUserName: " + params.userName + ")");
doc.removeTranscriptionPage(params.pageID, params.userName);
params.getLogger().debug("finished setting transcription (docID: " + doc.getDocumentID() + "; pageID: " + params.pageID + "; saveAsUserName: " + params.userName + ")");
if (params.push) {
if (pushOnCommit) {
params.getLogger().info("pushing transcription repo ");
VersionedRepo.push();
}
}
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
}
else {
params.addError(-9, "Could not find manuscript with docID: " + params.docID);
}
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>