%@ 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.Document" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%!
@Description(value = "Submit a new or modified manuscript.", name = "manuscript/put")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "manuscript id to modify. if not found in database, a new manuscript will be created (-1 for next available user scoped docID)", example = "10046")
public Integer docID;
@Description(value = "human recognizable identifier for this manuscript", example = "P46")
public String gaNum;
@Description(value = "general overview of the contents of this manuscript", example = "eapr")
public String contentOverview;
@Description(value = "ISO 639 / ethnologue language codes for the content of this manuscript. separate multilingual manuscript codes with dash", example = "grc-lat")
public String lang;
@Description(value = "count of leaves", example = "2")
public Integer leavesCount;
@Description(value = "description of leaves", example = "5 fragments of 2 leaves")
public String leavesDesc;
@Description(value = "early threshold for the date of this manuscript", example = "150")
public Integer originYearEarly;
@Description(value = "late threshold for the date of this manuscript", example = "250")
public Integer originYearLate;
@Description(value = "manuscript date, in prose", example = "II/III")
public String originYearDesc;
@Description(value = "column count for this manuscript", example = "2")
public Integer columns;
@Description(value = "column count max, if column count varies throughout manuscript; if this is provided, use {columns} parameter for min", example = "3")
public Integer columnsMax;
@Description(value = "columns description that is displayed", example = "e:1, ap:2")
public String columnsDesc;
@Description(value = "line count for this manuscript", example = "17")
public Integer lineCount;
@Description(value = "line count max, if line count varies throughout manuscript; if this is provided, use {lineCount} parameter for min", example = "18")
public Integer lineCountMax;
@Description(value = "line count description that is displayed", example = "11r, 13v")
public String lineCountDesc;
@Description(value = "height for this manuscript, in millimeters", example = "for 19.0cm, 190")
public Integer height;
@Description(value = "height max in millimeters, if height varies throughout manuscript; if this is provided, use {height} parameter for min", example = "195")
public Integer heightMax;
@Description(value = "width for this manuscript, in millimeters", example = "for 27.5cm, 275")
public Integer width;
@Description(value = "width max in millimeters, if width varies throughout manuscript; if this is provided, use 'width' parameter for min", example = "280")
public Integer widthMax;
@Description(value = "any general comments about this manucript", example = "")
public String comment;
@Description(value = "versification of document if different from system default, DEFAULT to reset to default", example = "DEFAULT")
public String v11n;
@Description(value = "true, if this document should be \"user\" scoped, instead of global", defaultValue = "false", example = "true")
public Boolean isUserDocument = false;
@Description(value = "limit this manuscript to a user group, 'NONE' to unassign", example = "NONE")
public String userGroup;
@Override
protected void afterLoad() {
userGroup = Transcription.assureUnicode(userGroup);
gaNum = Transcription.assureUnicode(gaNum);
contentOverview = Transcription.assureUnicode(contentOverview);
lang = Transcription.assureUnicode(lang);
leavesDesc = Transcription.assureUnicode(leavesDesc);
originYearDesc = Transcription.assureUnicode(originYearDesc);
lineCountDesc = Transcription.assureUnicode(lineCountDesc);
columnsDesc = Transcription.assureUnicode(columnsDesc);
comment = Transcription.assureUnicode(comment);
v11n = Transcription.assureUnicode(v11n);
}
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
String role = "VMR Administrator";
boolean permission = params.getUser().hasRole(role);
if (!permission) {
params.getUser().includeUserRoles();
XMLBlock ur = params.getUser().getBlock("userRoles");
if (ur != null) {
XMLBlock rs[] = ur.getBlocks("role");
for (XMLBlock r : rs) {
String roleName = r.getAttribute("roleName");
if (roleName.startsWith("Catalog Admin:")) {
try {
int min = Integer.parseInt(roleName.split(":")[1].split("-")[0].trim());
int max = Integer.parseInt(roleName.split("-")[1].trim());
if (params.docID >= min && params.docID <= max) permission = true;
}
catch(Exception e) {}
}
}
}
}
do {
// assert we have permission
if (!params.isUserDocument && !permission) {
params.addError(-6, "No permission to edit global documents. Must have role: " + role);
break;
}
if (params.isUserDocument && params.docID > -1 && (params.docID < 9900000 || params.docID > 9999999)) {
if (params.docID > 9999999) params.docID %= 100000;
params.docID += 9900000;
}
Document orig = Document.getDocument(params.docID);
if (!permission && params.isUserDocument && orig != null && (!params.getUser().getUserName().equals(orig.getUserID()))) {
params.addError(-7, "You are not the owner of document ID: "+params.docID+".");
break;
}
Document doc = null;
if (orig == null) {
doc = new Document();
doc.setDocumentID(params.docID);
if (params.gaNum == null) {
params.addError(-8, "Must supply {gaNum} when creating a new manuscript.");
break;
}
}
else {
doc = (Document)orig.clone();
}
if (params.gaNum != null) doc.setGANumber(params.gaNum);
if (params.contentOverview != null) doc.setContentOverview(params.contentOverview);
if (params.lang != null) doc.setLanguage(params.lang);
if (params.leavesCount != null) doc.setLeaves(params.leavesCount);
if (params.leavesDesc != null) doc.setLeavesDescription(params.leavesDesc);
if (params.originYearDesc != null) doc.setOriginYearDescription(params.originYearDesc);
if (params.lineCountDesc != null) doc.setLineCountDescription(params.lineCountDesc);
if (params.columnsDesc != null) doc.setColumnsDescription(params.columnsDesc);
if (params.userGroup != null) doc.setGroupID("NONE".equals(params.userGroup)?null:params.userGroup);
if (params.comment != null) doc.setComment(params.comment);
if (params.v11n != null) doc.setV11n("DEFAULT".equals(params.v11n)?null:params.v11n);
if (params.originYearEarly != null) doc.setOriginYearEarly(params.originYearEarly);
if (params.originYearLate != null) doc.setOriginYearLate(params.originYearLate);
if (params.columns != null) doc.setColumns(params.columns);
if (params.columnsMax != null) doc.setColumnsMax(params.columnsMax);
if (params.lineCount != null) doc.setLineCount(params.lineCount);
if (params.lineCountMax != null) doc.setLineCountMax(params.lineCountMax);
if (params.height != null) doc.setHeight(params.height);
if (params.heightMax != null) doc.setHeightMax(params.heightMax);
if (params.width != null) doc.setWidth(params.width);
if (params.widthMax != null) doc.setWidthMax(params.widthMax);
params.getLogger().info("saving: " + doc);
if (orig != null) {
doc.save(orig);
}
else {
if (params.isUserDocument) {
doc.setUserID(params.getUser().getUserName());
}
doc = doc.saveNew();
}
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
} while (false);
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>