2010-01-29 22:13:57 +00:00
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
2010-03-15 15:35:35 +00:00
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
2010-01-29 22:13:57 +00:00
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash" %>
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %>
<%@ page import="java.util.HashMap" %>
2010-03-16 19:17:53 +00:00
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
2010-03-16 21:04:21 +00:00
2010-01-29 22:13:57 +00:00
<%
2010-03-16 19:17:53 +00:00
//org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch.jsp");
final Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.editDatapropStmtRequestDispatch.jsp");
2010-01-29 22:13:57 +00:00
%>
<%
// Decide which form to forward to, set subjectUri, subjectUriJson, predicateUri, predicateUriJson in request
// Also get the Individual for the subjectUri and put it in the request scope
// If a datapropKey is sent it as an http parameter, then set datapropKey and datapropKeyJson in request, and
// also get the DataPropertyStatement matching the key and put it in the request scope
/* *************************************
Parameters:
subjectUri
predicateUri
datapropKey (optional)
cmd (optional -- deletion)
formParam (optional)
************************************** */
final String DEFAULT_DATA_FORM = "defaultDatapropForm.jsp";
2010-03-24 21:41:33 +00:00
final String DEFAULT_VITRO_NS_FORM = "defaultVitroNsDataPropForm.jsp";
2010-03-15 18:48:31 +00:00
final String DEFAULT_ERROR_FORM = "error.jsp";
2010-03-15 15:35:35 +00:00
2010-01-29 22:13:57 +00:00
if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {
%> <c:redirect url="<%= Controllers.LOGIN %>" /> <%
}
VitroRequest vreq = new VitroRequest(request);
if( EditConfiguration.getEditKey( vreq ) == null ){
vreq.setAttribute("editKey",EditConfiguration.newEditKey(session));
}else{
vreq.setAttribute("editKey", EditConfiguration.getEditKey( vreq ));
}
String subjectUri = vreq.getParameter("subjectUri");
String predicateUri = vreq.getParameter("predicateUri");
String formParam = vreq.getParameter("editForm");
String command = vreq.getParameter("cmd");
2010-03-17 15:34:23 +00:00
2010-03-18 21:04:19 +00:00
String vitroNsProp = (String) vreq.getParameter("vitroNsProp");
2010-03-17 15:34:23 +00:00
boolean isVitroNsProp = (vitroNsProp != null && vitroNsProp.equals("true")) ? true : false;
2010-01-29 22:13:57 +00:00
if( subjectUri == null || subjectUri.trim().length() == 0 ) {
log.error("required subjectUri parameter missing");
throw new Error("subjectUri was empty, it is required by editDatapropStmtRequestDispatch");
}
if( predicateUri == null || predicateUri.trim().length() == 0) {
log.error("required subjectUri parameter missing");
throw new Error("predicateUri was empty, it is required by editDatapropStmtRequestDispatch");
}
2010-03-16 21:04:21 +00:00
2010-03-18 21:04:19 +00:00
// Since we have the URIs let's put the individual, data property, and optional data property statement in the request
2010-01-29 22:13:57 +00:00
vreq.setAttribute("subjectUri", subjectUri);
vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri));
vreq.setAttribute("predicateUri", predicateUri);
vreq.setAttribute("predicateUriJson", MiscWebUtils.escape(predicateUri));
2010-03-16 21:04:21 +00:00
2010-01-29 22:13:57 +00:00
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
if( subject == null ) {
log.error("Could not find subject Individual '"+subjectUri+"' in model");
2010-03-11 18:59:11 +00:00
throw new Error("editDatapropStmtRequestDispatch.jsp: Could not find subject Individual in model: '" + subjectUri + "'");
2010-01-29 22:13:57 +00:00
}
vreq.setAttribute("subject", subject);
DataProperty dataproperty = wdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
2010-03-11 18:59:11 +00:00
if( dataproperty == null) {
2010-03-16 21:04:21 +00:00
// No dataproperty will be returned for a vitro ns prop, but we shouldn't throw an error.
2010-03-19 21:37:09 +00:00
// RY This is not necessarily true...
2010-03-15 15:35:35 +00:00
if (!isVitroNsProp) {
2010-03-11 18:59:11 +00:00
log.error("Could not find data property '"+predicateUri+"' in model");
throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri);
}
}
else {
vreq.setAttribute("predicate", dataproperty);
2010-01-29 22:13:57 +00:00
}
String url= "/edit/editDatapropStmtRequestDispatch.jsp"; //I'd like to get this from the request but...
vreq.setAttribute("formUrl", url + "?" + vreq.getQueryString());
String datapropKeyStr = vreq.getParameter("datapropKey");
int dataHash = 0;
if( datapropKeyStr != null ){
try {
dataHash = Integer.parseInt(datapropKeyStr);
vreq.setAttribute("datahash", dataHash);
log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
} catch (NumberFormatException ex) {
throw new JspException("Cannot decode incoming datapropKey value "+datapropKeyStr+" as an integer hash in editDatapropStmtRequestDispatch.jsp");
}
}
DataPropertyStatement dps = null;
if( dataHash != 0) {
2010-03-16 19:17:53 +00:00
Model model = (Model)application.getAttribute("jenaOntModel");
2010-03-22 23:17:22 +00:00
dps = RdfLiteralHash.getPropertyStmtByHash(subject, predicateUri, dataHash, model, isVitroNsProp);
2010-03-15 15:35:35 +00:00
2010-01-29 22:13:57 +00:00
if (dps==null) {
log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr);
%><jsp:forward page="/edit/messages/dataPropertyStatementMissing.jsp"></jsp:forward> <%
return;
}
vreq.setAttribute("dataprop", dps );
}
if( log.isDebugEnabled() ){
2010-03-16 19:17:53 +00:00
if (dataproperty != null) {
log.debug("predicate for DataProperty from request is " + dataproperty.getURI() + " with rangeDatatypeUri of '" + dataproperty.getRangeDatatypeURI() + "'");
}
2010-01-29 22:13:57 +00:00
if( dps == null )
2010-03-16 21:04:21 +00:00
log.debug("no existing DataPropertyStatement statement was found, making a new statemet");
2010-01-29 22:13:57 +00:00
else{
log.debug("Found an existing DataPropertyStatement");
String msg = "existing datapropstmt: ";
msg += " subject uri: <"+dps.getIndividualURI() + ">\n";
msg += " prop uri: <"+dps.getDatapropURI() + ">\n";
msg += " prop data: \"" + dps.getData() + "\"\n";
msg += " datatype: <" + dps.getDatatypeURI() + ">\n";
2010-03-16 21:04:21 +00:00
msg += " hash of this stmt: " + RdfLiteralHash.makeRdfLiteralHash(dps);
2010-01-29 22:13:57 +00:00
log.debug(msg);
}
}
vreq.setAttribute("preForm", "/edit/formPrefix.jsp");
vreq.setAttribute("postForm", "/edit/formSuffix.jsp");
if( "delete".equals(command) ){ %>
<jsp:forward page="/edit/forms/datapropStmtDelete.jsp"/>
<% return;
}
2010-03-15 18:48:31 +00:00
String form = null;
if (formParam != null) {
form = formParam;
}
else if (isVitroNsProp) { // dataproperty is null here
form = DEFAULT_VITRO_NS_FORM;
}
else {
form = dataproperty.getCustomEntryForm();
2010-01-29 22:13:57 +00:00
if (form != null && form.length()>0) {
log.warn("have a custom form for this data property: "+form);
vreq.setAttribute("hasCustomForm","true");
} else {
form = DEFAULT_DATA_FORM;
}
}
2010-03-15 18:48:31 +00:00
vreq.setAttribute("form", form);
if( session.getAttribute("requestedFromEntity") == null ) {
2010-01-29 22:13:57 +00:00
session.setAttribute("requestedFromEntity", subjectUri );
2010-03-15 18:48:31 +00:00
}
2010-01-29 22:13:57 +00:00
%>
<jsp:forward page="/edit/forms/${form}" />