<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.utils.Sessions" %> <%@ page import="org.crosswire.webtools.RightsAndRoles" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %> <%@ 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 = "Submit a new or modified variant reading option for a text segment.", name = "variant/reading/put") public static class MyParameters extends Parameters { @NotNull @Description(value = "segment id of the text segment", example = "18734") public Integer segmentID; @Description(value = "reading id to modify, instead of adding a new reading", example = "8675309") public Integer segmentReadingID; @Description(value = "project id for the new reading", example = "1") public Integer projectID; @NotNull @Description(value = "reading for this variant segment", example = "τα εργα σου και") public String reading; @Description(value = "text to displayed with the reading", example = "[Mt.1,1]") public String readingSubtext; @Description(value = "reading name or label for this reading", example = "b") public String readingName; @Description(value = "internal") public Integer segID; @Override protected void afterLoad() { if (reading != null) reading = Transcription.assureUnicode(reading); if (readingName != null) readingName = Transcription.assureUnicode(readingName); if (readingSubtext != null) readingSubtext = Transcription.assureUnicode(readingSubtext); if (segmentID == null && segID != null) segmentID = segID; } @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 && params.reading != null) { boolean permission = params.getUser().hasRole("VMR Administrator"); Apparatus.Segment seg = Apparatus.Segment.getSegment(params.segmentID); 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 (params.segmentReadingID != null || params.projectID != null) { Integer pID = params.projectID; if (params.segmentReadingID != null) { SegmentReading sr = SegmentReading.getSegmentReading(params.segmentReadingID); pID = sr.getReadingProjectID(); } ProjectManagement.Project pr = (pID == null) ? null : ProjectManagement.getProject(pID); if (pr != null && !permission) { 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(-5, "No permission to edit readings."); } else if (seg == null) { params.addError(-6, "segment id: " + params.segmentID + " not found."); } else { if (params.segmentReadingID != null) { SegmentReading sr = SegmentReading.getSegmentReading(params.segmentReadingID); if (sr != null) { SegmentReading orig = (SegmentReading)sr.clone(); if (params.reading != null) sr.setReading(params.reading); if (params.readingName != null) sr.setReadingName(params.readingName); if (params.readingSubtext != null) sr.setReadingSubtext(params.readingSubtext); sr.save(orig); Serializer.output(response, out, params, XMLBlock.createXMLBlock("")); return; } else { params.addError(-7, "reading id: " + params.segmentReadingID + " not found."); } } else { int newReadingID = seg.addSegmentReading(params.reading, params.readingName, params.readingSubtext, params.projectID); Serializer.output(response, out, params, XMLBlock.createXMLBlock("")); return; } } } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>