<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %> <%@ page import="org.crosswire.sword.keys.VerseKey" %> <%@ 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="org.crosswire.webtools.*" %> <%! @Description(value = "Create a new or update an existing text segment definition.", name = "variant/segment/put") public static class MyParameters extends Parameters { @Description(value = "segment group id (typicall a project id), required when adding a new segment", example = "8675309") public Integer segmentGroupID; @Description(value = "internal") public Integer groupID; @Description(value = "segment id, supply to edit an existing test segment; otherwise, do not include when adding a new segment", example = "18734") public Integer segmentID; @Description(value = "segment name. this can be used with TnT test passages to give a name to the test passage. see {contextDescription} for apparatus word range", example = "137") public String name; @Description(value = "verse where this segment starts", example = "Matt.1.1") public String verse; @Description(value = "Context to help the user know where exactly the segment is located", example = "2-8 or ειρηνη απο ... ο ων") public String contextDescription; @Override protected void afterLoad() { if (name != null) name = Transcription.assureUnicode(name); if (verse != null) verse = Transcription.assureUnicode(verse); if (contextDescription != null) contextDescription = Transcription.assureUnicode(contextDescription); if (segmentGroupID == null && groupID != null) segmentGroupID = groupID; } @Override protected void customValidation() { if (getUser() == null) { addError(-5, "Must be logged in."); return; } if (segmentGroupID == null && segmentID == null) { addError(-4, "Must supply either {segmentID} or {segmentGroupID}."); return; } } } %> <% MyParameters params = new MyParameters().loadFromRequest(request, response, false); if (params.getUser() != null && (params.segmentGroupID != null || params.segmentID != null)) { boolean permission = params.getUser().hasRole("VMR Administrator"); if (!permission) { ProjectManagement.Project p = ProjectManagement.getProject(params.segmentGroupID); if (!permission && p != null) permission = params.getUser().hasRole("Site Administrator", p.getProjectName()) || params.getUser().hasRole("Project Managing Editor", p.getProjectName()) || params.getUser().hasRole("Project Editor", p.getProjectName()); } if (!permission) { Segment seg = Segment.getSegment(params.segmentID); if (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; } } } } do { if (!permission) { params.addError(-4, "No permission to edit segment records."); break; } Segment orig = null; Segment segment = null; if (params.segmentID == null) { segment = new Segment(); if (params.verse == null || params.contextDescription == null || params.segmentGroupID == -1) { params.addError(-5, "Must supply a segmentGroupID, verse, and contextDescription when creating a new segment."); break; } } else { orig = Segment.getSegment(params.segmentID); if (orig == null) { params.addError(-6, "Couldn't find Segment ID: " + params.segmentID + "."); break; } segment = (Segment)orig.clone(); } if (params.name != null) segment.setSegmentName(params.name); if (params.verse != null) { VerseKey vk = new VerseKey(params.verse); segment.setVerseHash(vk.getHashNumber()); } if (params.contextDescription != null) segment.setContextDescription(params.contextDescription); if (orig != null) { segment.save(orig); } else { segment = segment.saveNew(params.segmentGroupID); } Serializer.output(response, out, params, XMLBlock.createXMLBlock("")); return; } while (false); } else params.format = "html"; Serializer.reportErrors(request, response, out, params, true); %>