%@ 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.Feature" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.awt.Rectangle" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%!
@Description(value = "Submit a new or modified feature for a manuscript or manuscript page.", name = "feature/put")
public static class MyParameters extends Parameters {
private Date dv1 = null;
private Date dv2 = null;
@Description(value = "feature ID to modify. if not provided, a new feature will be created.", example = "123")
public Integer featureID = null;
@Description(value = "manuscript ID of the feature", example = "10046")
public Integer docID = null;
@Description(value = "page ID of the feature", example = "10")
public Integer pageID = null;
@Description(value = "feature definition type of this feature tag instance", example = "IlluminatedLetters")
public String featureCode = null;
@Description(value = "feature tag author's prose regarding this feature.", example = "This is an extra special instance of an illuminated letter")
public String prose = null;
@Description(value = "location on page for this feature. left+upper+right+lower", example = "0+0+20+20")
public String regionBox = null;
@Description(value = "specialized field data defined in the feature definition associated with the {featureCode} of this feature, for this specific instance of feature tag")
public String stringVal1 = null;
@Description(value = "specialized field data defined in the feature definition associated with the {featureCode} of this feature, for this specific instance of feature tag")
public String stringVal2 = null;
@Description(value = "specialized field data defined in the feature definition associated with the {featureCode} of this feature, for this specific instance of feature tag")
public Integer intVal1 = null;
@Description(value = "specialized field data defined in the feature definition associated with the {featureCode} of this feature, for this specific instance of feature tag")
public Integer intVal2 = null;
@Description(value = "formatted yyyy-MM-dd; specialized field data defined in the feature definition associated with the {featureCode} of this feature, for this specific instance of feature tag", example = "2020-07-21")
public String dateVal1 = null;
@Description(value = "formatted yyyy-MM-dd; specialized field data defined in the feature definition associated with the {featureCode} of this feature, for this specific instance of feature tag", example = "2021-12-30")
public String dateVal2 = null;
@Override
protected void afterLoad() {
prose = Transcription.assureUnicode(prose);
stringVal1 = Transcription.assureUnicode(stringVal1);
stringVal2 = Transcription.assureUnicode(stringVal2);
}
private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
@Override
protected void customValidation() {
if (dateVal1 != null) {
try { dv1 = df.parse(dateVal1); } catch (Exception e) {
addError(-4, "Error parsing {dateVal1}");
}
}
if (dateVal2 != null) {
try { dv2 = df.parse(dateVal2); } catch (Exception e) {
addError(-4, "Error parsing {dateVal2}");
}
}
if (featureID == null) {
if (docID == null) {
addError(-4, "When creating a new feature tag, you must supply a {docID}.");
}
if (featureCode == null) {
addError(-4, "When creating a new feature tag, you must supply a {featureCode}.");
}
}
if (getUser() == null) {
addError(-5, "No permission. User not logged in.");
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
response.setContentType("text/xml");
String role = "Feature Manager";
// let's check to see if we're a privileged user
boolean manager = params.getUser().hasRole("VMR Administrator") || params.getUser().hasRole(role);
Feature orig = null;
Feature feature = null;
do {
if (params.featureID != null) {
orig = Feature.getFeature(params.featureID);
if (orig == null) {
params.addError(-6, "featureID: " + params.featureID + " not found.");
break;
}
feature = (Feature)orig.clone();
}
else feature = new Feature();
if (feature.getUserID() != null && feature.getUserID().length() > 0 && !feature.getUserID().equals(params.getUser().getUserName()) && !manager) {
String projectName = feature.getFeatureDefinition().getGroupID();
if (projectName != null && projectName.length() > 0) {
ProjectManagement.Project project = ProjectManagement.getProject(projectName);
if (project != null) {
manager = params.getUser().hasRole("Project Editor", project.getProjectName())
|| params.getUser().hasRole("Project Managing Editor", project.getProjectName())
|| params.getUser().hasRole("Project Feature Manager", project.getProjectName());
}
}
if (!manager) {
params.addError(-7, "User does not have the role: " + role + ". To request change to existing data, consider using the action to discussing this feature on the forum.");
break;
}
}
feature.setUserID(params.getUser().getUserName());
if (params.docID != null) feature.setDocumentID(params.docID);
if (params.pageID != null) feature.setPageID(params.pageID);
if (params.featureCode != null) feature.setFeatureCode(params.featureCode);
if (params.prose != null) feature.setProse(params.prose);
if (params.stringVal1 != null) feature.setStringVal1(params.stringVal1);
if (params.stringVal2 != null) feature.setStringVal2(params.stringVal2);
if (params.intVal1 != null) feature.setIntVal1(params.intVal1);
if (params.intVal2 != null) feature.setIntVal2(params.intVal2);
if (params.dv1 != null) feature.setDateVal1(params.dv1);
if (params.dv2 != null) feature.setDateVal2(params.dv2);
if (params.regionBox != null) {
boolean success = false;
try {
Rectangle r = new Rectangle();
int wordStart = 0;
int offset = params.regionBox.indexOf("+");
if (offset > -1) {
r.x = Integer.parseInt(params.regionBox.substring(wordStart,offset));
wordStart = offset + 1;
offset = params.regionBox.indexOf("+", wordStart);
if (offset > -1) {
r.y = Integer.parseInt(params.regionBox.substring(wordStart,offset));
wordStart = offset + 1;
offset = params.regionBox.indexOf("+", wordStart);
if (offset > -1) {
r.width = Integer.parseInt(params.regionBox.substring(wordStart,offset)) - r.x;
r.height = Integer.parseInt(params.regionBox.substring(offset+1)) - r.y;
feature.setRegionBox(r);
success = true;
}
}
}
}
catch (Exception e) {}
if (!success) {
feature.setRegionBox(null);
}
}
if (orig != null) {
feature.save(orig);
}
else {
feature = feature.saveNew();
}
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
} while (false);
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>