%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Institution" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ 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 institution record.", name = "institute/put")
public static class MyParameters extends Parameters {
@Description(value = "Institution ID, supply to edit an existing institution; otherwise, do not include when adding a new institution", example = "47")
public Integer instID;
@Description(value = "Institution name", example = "XYZ Library")
public String name;
@Description(value = "Address line 1", example = "Tudor 21")
public String addr1;
@Description(value = "Address line 2", example = "Ste. 7")
public String addr2;
@Description(value = "Local region (city, ST)", example = "Münster")
public String place;
@Description(value = "Country", example = "Germany")
public String country;
@Description(value = "Postal code", example = "48149")
public String postCode;
@Description(value = "URL to institution logo", example = "https://xyzlibrary.org/images/logo.jpg")
public String logoURL;
@Description(value = "URL to institution's homepage", example = "https://xyzlibrary.org")
public String instURL;
@Description(value = "Contact Name", example = "Director John Jacob Jingleheimer Schmidt")
public String contactName;
@Description(value = "Contact Email", example = "jjjschmidt@xyzlibrary.org")
public String contactEmail;
@Description(value = "Contact Phone", example = "+44 123 4567")
public String contactPhone;
@Description(value = "Contact Fax", example = "+44 123 4568")
public String contactFax;
@Description(value = "Geo Locator for institute", example = "AXG+345")
public String geoLocator;
@Override
protected void afterLoad() {
name = Transcription.assureUnicode(name);
addr1 = Transcription.assureUnicode(addr1);
addr2 = Transcription.assureUnicode(addr2);
place = Transcription.assureUnicode(place);
country = Transcription.assureUnicode(country);
postCode = Transcription.assureUnicode(postCode);
logoURL = Transcription.assureUnicode(logoURL);
instURL = Transcription.assureUnicode(instURL);
contactName = Transcription.assureUnicode(contactName);
contactEmail = Transcription.assureUnicode(contactEmail);
contactPhone = Transcription.assureUnicode(contactPhone);
contactFax = Transcription.assureUnicode(contactFax);
}
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in to edit institute records.");
return;
}
if (instID == null && name == null && country == null) {
addError(-6, "Supply either the {instID} to edit or the data for a new institution, e.g., {name} and {country}.");
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
do {
String role = "VMR Administrator";
boolean permission = params.getUser().hasRole(role);
if (!permission) {
params.addError(-5, "No permission to edit institute records. Must have the role: " + role + ".");
break;
}
Institution orig = null;
Institution inst = null;
if (params.instID == null) {
inst = new Institution();
if (params.name == null) {
params.addError(-6, "Must supply a name when creating a new institute.");
break;
}
}
else {
orig = Institution.getInstitution(params.instID);
if (orig == null) {
params.addError(-7, "Couldn't find Institution ID: " + params.instID);
break;
}
inst = (Institution)orig.clone();
}
if (params.name != null) inst.setInstitutionName(params.name);
if (params.addr1 != null) inst.setAddress1(params.addr1);
if (params.addr2 != null) inst.setAddress2(params.addr2);
if (params.place != null) inst.setPlace(params.place);
//params.getLogger().info("place: " + params.place);
if (params.country != null) inst.setCountry(params.country);
if (params.postCode != null) inst.setPostCode(params.postCode);
if (params.logoURL != null) inst.setLogoURL(params.logoURL);
if (params.instURL != null) inst.setInstitutionURL(params.instURL);
if (params.contactName != null) inst.setContactName(params.contactName);
if (params.contactEmail != null) inst.setContactEmail(params.contactEmail);
if (params.contactPhone != null) inst.setContactPhone(params.contactPhone);
if (params.contactFax != null) inst.setContactFax(params.contactFax);
if (params.geoLocator != null) inst.setGeoLocator(params.geoLocator);
if (orig != null) {
//params.getLogger().info("place: " + orig.getPlace() + " : " + inst.getPlace());
inst.save(orig);
}
else {
inst = inst.saveNew();
}
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
} while (false);
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>