%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ 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.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%@ page import="org.crosswire.webtools.*" %>
<%!
@Description(value = "Deletes a segment and all data associated with the segment.", name = "variant/segment/delete")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "segment id to remove from a segment group", example = "8675310")
public Integer segmentID;
@Description(value = "internal")
public Integer groupID;
@Description(value = "internal")
public Integer segmentGroupID;
@Description(value = "whether or not to leave witness data added by other projects, e.g., versionists", defaultValue = "true", example = "false")
public Boolean leaveOrphans = true;
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getUser() != null && params.segmentID != null) {
boolean permission = params.getUser().hasRole("VMR Administrator");
Apparatus.Segment segment = Apparatus.Segment.getSegment(params.segmentID);
if (!permission && segment != null) {
// if user is admin of ANY segment group in which this segment belongs?
// Well, it's not a horrible check but likely not exactly right if we start assigning segments to multiple groups
for (Integer i : segment.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) {
params.addError(-4, "No permission to delete segment records. Must be a VMR or Site Administrator or Project Editor.");
}
else if (segment == null) {
params.addError(-5, "Couldn't find Segment ID: " + params.segmentID + ".");
}
else {
Segment.deleteSegment(segment.getSegmentID(), params.leaveOrphans);
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>