%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.ProjectManagement.Project" %>
<%@ 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 project record.", name = "projectmanagement/project/put")
public static class MyParameters extends Parameters {
@Description(value = "project id, supply to edit an existing project; otherwise, do not include when adding a new project", example = "146789")
public Integer projectID;
@Description(value = "project name", example = "ECM Matthew")
public String name;
@Description(value = "user group for this project; corresponds to a portal user group name", example = "")
public String userGroup;
@Description(value = "object part for this project; limits project to a portion of each object", example = "Matthew")
public String objectPart;
@Description(value = "document group id for this project; limits primary project activity (e.g., transcribing) to a list of documents", example = "7")
public Integer documentGroupID;
@Description(value = "secondary document group id for this project; limits secondary (e.g., editing) activity of a project to a list of documents", example = "7")
public Integer secondaryDocumentGroupID;
@Description(value = "tertiary document group id for this project; limits tertiary (e.g., indexing) activity of a project to a list of documents", example = "7")
public Integer tertiaryDocumentGroupID;
@Description(value = "primary task type id for this project (1-imaging; 2-indexing; 3-transcribing; 4-variant selection)", example = "3")
public Integer taskTypeID;
@Description(value = "project-specific configuration data; typically not required. this can be used for storing and passing on task tool-specific configuration", example = "")
public String configuration;
@Description(value = "credit to include with project transcription", example = "")
public String transcriptionAttribution;
@Description(value = "credit to include with project apparatus", example = "")
public String apparatusAttribution;
@Description(value = "basetext to use for transcribing. docID or 'CrossWire:ModuleName'", example = "CrossWire:MOTBTR")
public String transcriptionBaseDefault;
@Description(value = "edition text to use for collation and final display. docID or 'CrossWire:ModuleName", example = "1010100")
public String editionBaseDefault;
@Description(value = "query parameters to add to each document query request", example = "docID=10000-49999&featureCode=LiturgicalBookType%3DDaily")
public String documentRestrictQuery;
@Description(value = "custom project task stages defined", example = "")
public String taskStageDefinitions;
@Override
protected void afterLoad() {
name = Transcription.assureUnicode(name);
configuration = Transcription.assureUnicode(configuration);
taskStageDefinitions = Transcription.assureUnicode(taskStageDefinitions);
transcriptionAttribution = Transcription.assureUnicode(transcriptionAttribution);
apparatusAttribution = Transcription.assureUnicode(apparatusAttribution);
userGroup = Transcription.assureUnicode(userGroup);
objectPart = Transcription.assureUnicode(objectPart);
transcriptionBaseDefault = Transcription.assureUnicode(transcriptionBaseDefault);
editionBaseDefault = Transcription.assureUnicode(editionBaseDefault);
documentRestrictQuery = Transcription.assureUnicode(documentRestrictQuery);
}
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in.");
return;
}
if (projectID == null && name == null) {
addError(-7, "Must supply a name when creating a new project.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
do {
Project p = null;
if (params.projectID != null && params.projectID > -1) {
p = ProjectManagement.getProject(params.projectID);
}
String role = "VMR Administrator";
boolean permission = params.getUser().hasRole(role) || params.getUser().hasRole("Site Owner", (p != null) ? p.getProjectName() : params.name);
if (!permission) {
params.addError(-6, "No permission to edit project records. Must have role: " + role + ".");
break;
}
Project orig = null;
Project project = null;
if (params.projectID == null) {
project = new Project();
}
else {
orig = ProjectManagement.getProject(params.projectID);
if (orig == null) {
params.addError(-8, "Couldn't find Project ID: " + params.projectID + ".");
break;
}
project = (Project)orig.clone();
}
if (params.name != null) project.setProjectName(params.name);
if (params.userGroup != null) project.setUserGroup(params.userGroup);
if (params.objectPart != null) project.setObjectPart(params.objectPart);
if (params.documentGroupID != null) project.setDocumentGroupID(params.documentGroupID);
if (params.secondaryDocumentGroupID != null) project.setSecondaryDocumentGroupID(params.secondaryDocumentGroupID);
if (params.tertiaryDocumentGroupID != null) project.setTertiaryDocumentGroupID(params.tertiaryDocumentGroupID);
if (params.taskTypeID != null) project.setTaskTypeID(params.taskTypeID);
if (params.configuration != null) project.setConfiguration(params.configuration);
if (params.taskStageDefinitions != null) project.setTaskStageDefinitions(params.taskStageDefinitions);
if (params.transcriptionAttribution != null) project.setTranscriptionAttribution(params.transcriptionAttribution);
if (params.apparatusAttribution != null) project.setApparatusAttribution(params.apparatusAttribution);
if (params.transcriptionBaseDefault != null) project.setTranscriptionBaseDefault(params.transcriptionBaseDefault);
if (params.editionBaseDefault != null) project.setEditionBaseDefault(params.editionBaseDefault);
if (params.documentRestrictQuery != null) project.setDocumentRestrictQuery(params.documentRestrictQuery);
if (orig != null) {
project.save(orig);
}
else {
project = project.saveNew();
}
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
} while (false);
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>