%@ 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.Apparatus.SegmentReading" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%@ page import="org.crosswire.webtools.*" %>
<%!
@Description(value = "Delete a segment reading and unassign all witnesses from this reading.", name = "variant/reading/delete")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "segment reading id to delete", example = "8675309")
public Integer segmentReadingID;
@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) {
boolean permission = params.getUser().hasRole("VMR Administrator");
Segment seg = Segment.getSegmentFromSegmentReadingID(params.segmentReadingID);
SegmentReading sr = SegmentReading.getSegmentReading(params.segmentReadingID);
if (!permission && seg != null) {
for (Integer i : seg.getSegmentGroups()) {
ProjectManagement.Project pr = ProjectManagement.getProject(i);
if (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) {
Integer pID = sr.getReadingProjectID();
if (pID != null && pID > 0) {
ProjectManagement.Project pr = (pID == null) ? null : ProjectManagement.getProject(pID);
if (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) {
params.addError(-4, "User not a VMR Administrator.");
}
else {
int count = Apparatus.deleteSegmentReading(params.segmentReadingID);
if (count > 0) {
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
}
params.addError(-5, "No data found with segmentReadingID: " + params.segmentReadingID);
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>