%@ 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.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 = "Reassign all witness from a reading to a different reading.", name = "variant/reading/reassign")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "segment reading id to reassign", example = "8675309")
public Integer fromSegmentReadingID;
@NotNull
@Description(value = "new segment reading id for all witnesses currently assigned to {fromSegmentReadingID}", example = "8675310")
public Integer toSegmentReadingID;
@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.fromSegmentReadingID != null && params.toSegmentReadingID != null) {
int fromSegmentReadingID = -1; try {fromSegmentReadingID = Integer.parseInt(request.getParameter("fromSegmentReadingID"));} catch (Exception e){}
int toSegmentReadingID = -1; try {toSegmentReadingID = Integer.parseInt(request.getParameter("toSegmentReadingID"));} catch (Exception e){}
boolean permission = params.getUser().hasRole("VMR Administrator");
Apparatus.Segment seg = Apparatus.Segment.getSegmentFromSegmentReadingID(params.fromSegmentReadingID);
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());
if (permission) break;
}
}
}
// ---------------------------------------------
if (permission) {
Apparatus.reassignSegmentReading(params.fromSegmentReadingID, params.toSegmentReadingID);
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
params.getLogger().info("successfully reassigned all witnesses with reading id: " + params.fromSegmentReadingID + ", to reading id: " + params.toSegmentReadingID);
return;
}
else {
params.addError(-4, "User not a VMR Administrator.");
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>