%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.webtools.RightsAndRoles" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus.Segment" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ 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 a segment reading witness attestation", name = "variant/delete")
public static class MyParameters extends Parameters {
protected ProjectManagement.Project project = null;
@NotNull
@Description(value = "segment id of the witness attestation", example = "18756")
public Integer segmentID = null;
@Description(value = "internal")
public Integer segID = null;
@NotNull
@Description(value = "manuscript id of the witness attestation", example = "10046")
public Integer docID = null;
@Description(value = "verse instance identifier to disambiguate documents which have multiple attestations to the same verse at this segment. This is used when a witness repeats the same verse multiple times, e.g., a commentary or lectionary may have multiple occurances of John 3:16 within the document. This field allows a designator to specify which occurance is being deleted.", example = "A")
public String verseInstance = null;
@Description(value = "witness hand to remove", example = "C")
public String hand = null;
@Description(value = "Project ID for which data should be deleted. Only delete this project's data", example = "1")
public Integer projectID = null;
@Description(value = "Project Name for which data should be deleted (i.e., lookup {projectID} by project name)", example = "ECM Matthew")
public String projectName;
@Override
protected void afterLoad() {
if (segmentID == null && segID != null) segmentID = segID;
verseInstance = Transcription.assureUnicode(verseInstance);
if (verseInstance == null) verseInstance = "";
verseInstance = verseInstance.trim();
hand = Transcription.assureUnicode(hand);
if (hand == null) hand = "";
hand = hand.trim();
}
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in.");
return;
}
projectName = Transcription.assureUnicode(projectName);
project = projectID != null ? ProjectManagement.getProject(projectID) : ProjectManagement.getProject(projectName);
if (projectID == null && project != null) projectID = project.getProjectID();
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().isEmpty()) {
response.setContentType("text/xml");
boolean permission = params.getUser().hasRole("VMR Administrator");
if (!permission) {
Segment seg = Apparatus.Segment.getSegment(params.segmentID);
if (seg != null) {
for (Integer i : seg.getSegmentGroups()) {
ProjectManagement.Project pr = ProjectManagement.getProject(i);
if (!permission && pr != null) permission = params.getUser().hasRole("Site Administrator", pr.getProjectName())
|| params.getUser().hasRole("Project Managing Editor", pr.getProjectName())
|| params.getUser().hasRole("Project Editor", pr.getProjectName());
if (permission) break;
}
}
}
if (!permission && params.projectID != null) {
ProjectManagement.Project pr = ProjectManagement.getProject(params.projectID);
if (pr != null) permission = params.getUser().hasRole("Project Editor", pr.getProjectName())
|| params.getUser().hasRole("Project Managing Editor", pr.getProjectName());
}
if (permission) {
params.getLogger().info("Apparatus.deleteWitnessSegmentReading(docID: " + params.docID + ", verseInstance: " + params.verseInstance + ", segmentID: " + params.segmentID + ", hand: " + params.hand + ", projectID: " + params.projectID + ");");
Apparatus.deleteWitnessSegmentReading(params.docID, params.verseInstance, params.segmentID, params.hand, params.projectID);
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
}
else {
params.addError(-4, "No permission to edit variant segment.");
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>